Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `Disabled` ([#80643](https://github.com/WordPress/gutenberg/pull/80643))
- `ToolsPanel` ([#80445](https://github.com/WordPress/gutenberg/pull/80445))
- `ItemGroup` ([#80797](https://github.com/WordPress/gutenberg/pull/80797))
- `ZStack` ([#80514](https://github.com/WordPress/gutenberg/pull/80514))
- Remove the private `Theme` component ([#80691](https://github.com/WordPress/gutenberg/pull/80691)).

### Deprecations
Expand Down
26 changes: 17 additions & 9 deletions packages/components/src/z-stack/component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import clsx from 'clsx';
import type { ForwardedRef } from 'react';

/**
Expand All @@ -13,7 +14,8 @@ import { isValidElement } from '@wordpress/element';
*/
import { getValidChildren } from '../utils/get-valid-children';
import { contextConnect, useContextSystem } from '../context';
import { ZStackView, ZStackChildView } from './styles';
import { PolymorphicElement } from '../utils/polymorphic-element';
import styles from './style.module.scss';
import type { ZStackProps } from './types';
import type { WordPressComponentProps } from '../context';

Expand Down Expand Up @@ -42,25 +44,31 @@ function UnconnectedZStack(
const key = isValidElement( child ) ? child.key : index;

return (
<ZStackChildView
offsetAmount={ offsetAmount }
zIndex={ zIndex }
<div
className={ styles.child }
style={ {
'--z-stack-offset': `${ offsetAmount }px`,
zIndex,
} }
Comment on lines +38 to +41

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moves z-index from a CSS rule to an inline style. Inline styles win over consumer CSS, so styles that previously changed the child stacking order will stop working.

Could we pass the value through a custom property and set z-index in the .child rule? This keeps the value dynamic without changing the cascade.

key={ key }
>
{ child }
</ZStackChildView>
</div>
);
} );

return (
<ZStackView
<PolymorphicElement
{ ...otherProps }
className={ className }
isLayered={ isLayered }
className={ clsx(
styles[ 'z-stack' ],
isLayered && styles.layered,
className
) }
ref={ forwardedRef }
>
{ clonedChildren }
</ZStackView>
</PolymorphicElement>
);
}

Expand Down
20 changes: 20 additions & 0 deletions packages/components/src/z-stack/style.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.z-stack {
display: inline-grid;
grid-auto-flow: column;
position: relative;

> .child {
position: relative;
justify-self: start;
}

// When the ZStack is layered, all items overlap in the same grid cell.
&.layered > .child {
grid-row-start: 1;
grid-column-start: 1;
}
Comment thread
im3dabasia marked this conversation as resolved.
Resolved
}

.child:not(:first-of-type) {
margin-inline-start: var(--z-stack-offset, 0);
}
38 changes: 0 additions & 38 deletions packages/components/src/z-stack/styles.ts

This file was deleted.

5 changes: 0 additions & 5 deletions tools/eslint/suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -949,11 +949,6 @@
"count": 1
}
},
"packages/components/src/z-stack/styles.ts": {
"no-restricted-imports": {
"count": 2
}
},
"packages/compose/src/hooks/use-dialog/index.ts": {
"react-hooks/immutability": {
"count": 1
Expand Down
Loading