Skip to content

Commit

Permalink
Remove @emotion/css from ZStack
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Jun 28, 2021
1 parent 779fdaa commit 69b41d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
25 changes: 6 additions & 19 deletions packages/components/src/z-stack/component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { css, cx } from '@emotion/css';
// eslint-disable-next-line no-restricted-imports
import type { Ref, ReactNode } from 'react';

Expand All @@ -17,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';
import * as styles from './styles';
const { ZStackView } = styles;
import { ZStackView, ZStackChild } from './styles';

export interface ZStackProps {
/**
Expand Down Expand Up @@ -66,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 }
<ZStackChild
isLayered={ isLayered }
offsetAmount={ offsetAmount }
zIndex={ zIndex }
key={ key }
style={ {
zIndex,
} }
>
{ child }
</View>
</ZStackChild>
);
} );

Expand Down
22 changes: 19 additions & 3 deletions packages/components/src/z-stack/styles.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
/**
* External dependencies
*/
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 ZStackChild = 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;
`;

0 comments on commit 69b41d2

Please sign in to comment.