Skip to content

Commit

Permalink
ZStack: support RTL layouts when applying offset (#36769)
Browse files Browse the repository at this point in the history
* `ZStack`: support RTL layouts when applying `offset`

* Update `offset` prop documentation

* CHANGELOG
  • Loading branch information
ciampo authored Nov 23, 2021
1 parent 85a6b87 commit ab9ad83
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Reinstated the ability to pass additional props to the `ToolsPanel` ([36428](https://github.com/WordPress/gutenberg/pull/36428)).
- Added an `__unstable-large` size variant to `InputControl`, `SelectControl`, and `UnitControl` for selective migration to the larger 40px heights. ([#35646](https://github.com/WordPress/gutenberg/pull/35646)).
- Fixed inconsistent padding in `UnitControl` ([#35646](https://github.com/WordPress/gutenberg/pull/35646)).
- Added support for RTL behavior for the `ZStack`'s `offset` prop ([#36769](https://github.com/WordPress/gutenberg/pull/36769))

### Bug Fix

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/z-stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Reverse the layer ordering. When `true`, the first child has the lowest `z-index

### `offset`: `number`

The amount of space between each child element. Defaults to `0`.
The amount of space between each child element. Defaults to `0`. Its value is automatically inverted (i.e. from positive to negative, and viceversa) when switching from LTR to RTL.

### `children`: `ReactNode`

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/z-stack/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ZStackProps {
*/
isReversed?: boolean;
/**
* The amount of offset between each child element.
* The amount of offset between each child element. The amount of space between each child element. Defaults to `0`. Its value is automatically inverted (i.e. from positive to negative, and viceversa) when switching from LTR to RTL.
*
* @default 0
*/
Expand Down
9 changes: 7 additions & 2 deletions packages/components/src/z-stack/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';

/**
* Internal dependencies
*/
import { rtl } from '../utils';

export const ZStackView = styled.div`
display: flex;
position: relative;
Expand All @@ -16,8 +21,8 @@ export const ZStackChildView = styled.div< {
} >`
${ ( { isLayered, offsetAmount } ) =>
isLayered
? css( { marginLeft: offsetAmount } )
: css( { right: offsetAmount * -1 } ) }
? css( rtl( { marginLeft: offsetAmount } )() )
: css( rtl( { right: offsetAmount * -1 } )() ) }
${ ( { isLayered } ) =>
isLayered ? positionAbsolute : positionRelative }
Expand Down

0 comments on commit ab9ad83

Please sign in to comment.