diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 1d8ebd35885a38..b9aa096b9a29a9 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -13,6 +13,7 @@ - `BorderBoxControl`, `BorderControl` ([#80437](https://github.com/WordPress/gutenberg/pull/80437)) - `ProgressBar` ([#80512](https://github.com/WordPress/gutenberg/pull/80512)) - `TextareaControl` ([#81353](https://github.com/WordPress/gutenberg/pull/81353)) + - `ZStack` ([#80514](https://github.com/WordPress/gutenberg/pull/80514)) ### Enhancements diff --git a/packages/components/src/z-stack/component.tsx b/packages/components/src/z-stack/component.tsx index 824555b61bee3e..409191136b156a 100644 --- a/packages/components/src/z-stack/component.tsx +++ b/packages/components/src/z-stack/component.tsx @@ -1,8 +1,10 @@ +import clsx from 'clsx'; import type { ForwardedRef } from 'react'; 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'; @@ -31,25 +33,31 @@ function UnconnectedZStack( const key = isValidElement( child ) ? child.key : index; return ( - { child } - + ); } ); return ( - { clonedChildren } - + ); } diff --git a/packages/components/src/z-stack/style.module.scss b/packages/components/src/z-stack/style.module.scss new file mode 100644 index 00000000000000..7aac3a4c3af844 --- /dev/null +++ b/packages/components/src/z-stack/style.module.scss @@ -0,0 +1,26 @@ +.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. +// Kept at the top level so that the selector retains the same specificity +// as `.z-stack > .child` above, matching the original Emotion styles. +.layered > .child { + grid-row-start: 1; + grid-column-start: 1; +} + +.child { + z-index: var(--z-stack-z-index, auto); + + &:not(:first-of-type) { + margin-inline-start: var(--z-stack-offset, 0); + } +} diff --git a/packages/components/src/z-stack/styles.ts b/packages/components/src/z-stack/styles.ts deleted file mode 100644 index a35de1bce299c0..00000000000000 --- a/packages/components/src/z-stack/styles.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { css } from '@emotion/react'; -import styled from '@emotion/styled'; - -export const ZStackChildView = styled.div< { - offsetAmount: number; - zIndex: number; -} >` - &:not( :first-of-type ) { - ${ ( { offsetAmount } ) => - css( { - marginInlineStart: offsetAmount, - } ) }; - } - - ${ ( { zIndex } ) => css( { zIndex } ) }; -`; - -export const ZStackView = styled.div< { - isLayered: boolean; -} >` - display: inline-grid; - grid-auto-flow: column; - position: relative; - - & > ${ ZStackChildView } { - position: relative; - justify-self: start; - - ${ ( { isLayered } ) => - isLayered - ? // When `isLayered` is true, all items overlap in the same grid cell - css( { gridRowStart: 1, gridColumnStart: 1 } ) - : undefined }; - } -`; diff --git a/tools/eslint/suppressions.json b/tools/eslint/suppressions.json index 4a5535e7a59b6c..cc94a492b37c74 100644 --- a/tools/eslint/suppressions.json +++ b/tools/eslint/suppressions.json @@ -946,11 +946,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