Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZStack: support RTL layouts when applying offset #36769

Merged
merged 3 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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