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

components: Remove @emotion/css from ZStack #33053

Merged
merged 2 commits into from
Jun 30, 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
28 changes: 6 additions & 22 deletions packages/components/src/z-stack/component.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/**
* External dependencies
*/
// Disable reason: Temporarily disable for existing usages
// until we remove them as part of https://github.com/WordPress/gutenberg/issues/30503#deprecating-emotion-css
// eslint-disable-next-line no-restricted-imports
import { css, cx } from '@emotion/css';
// eslint-disable-next-line no-restricted-imports
import type { Ref, ReactNode } from 'react';

Expand All @@ -20,9 +16,7 @@ import { getValidChildren } from '../ui/utils/get-valid-children';
import { contextConnect, useContextSystem } from '../ui/context';
// eslint-disable-next-line no-duplicate-imports
import type { PolymorphicComponentProps } from '../ui/context';
import { View } from '../view';
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we tracking the removal of the View component (and the createComponent function) anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it will be removed as just a side effect of this work, I'm not sure it's necessary to track it separately.

import * as styles from './styles';
const { ZStackView } = styles;
import { ZStackView, ZStackChildView } from './styles';

export interface ZStackProps {
/**
Expand Down Expand Up @@ -69,27 +63,17 @@ function ZStack(
const zIndex = isReversed ? childrenLastIndex - index : index;
const offsetAmount = offset * index;

const classes = cx(
isLayered ? styles.positionAbsolute : styles.positionRelative,
css( {
...( isLayered
? { marginLeft: offsetAmount }
: { right: offsetAmount * -1 } ),
} )
);

const key = isValidElement( child ) ? child.key : index;

return (
<View
className={ classes }
<ZStackChildView
isLayered={ isLayered }
offsetAmount={ offsetAmount }
zIndex={ zIndex }
key={ key }
style={ {
zIndex,
} }
>
{ child }
</View>
</ZStackChildView>
);
} );

Expand Down
25 changes: 19 additions & 6 deletions packages/components/src/z-stack/styles.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
/**
* External dependencies
*/
// Disable reason: Temporarily disable for existing usages
// until we remove them as part of https://github.com/WordPress/gutenberg/issues/30503#deprecating-emotion-css
// eslint-disable-next-line no-restricted-imports
import { css } from '@emotion/css';
import { css } from '@emotion/react';
import styled from '@emotion/styled';

export const ZStackView = styled.div`
display: flex;
position: relative;
`;

export const positionAbsolute = css`
export const ZStackChildView = styled.div< {
isLayered: boolean;
offsetAmount: number;
zIndex: number;
} >`
${ ( { isLayered, offsetAmount } ) =>
isLayered
? css( { marginLeft: offsetAmount } )
: css( { right: offsetAmount * -1 } ) }

${ ( { isLayered } ) =>
isLayered ? positionAbsolute : positionRelative }

${ ( { zIndex } ) => css( { zIndex } ) }
`;

const positionAbsolute = css`
position: absolute;
`;

export const positionRelative = css`
const positionRelative = css`
position: relative;
`;