Skip to content

Commit

Permalink
refactor(design-system): migrate spacings components
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosCortizasCT committed Dec 17, 2024
1 parent 4a1cf34 commit 45288e9
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 45 deletions.
37 changes: 23 additions & 14 deletions packages/components/spacings/spacings-inline/src/inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,41 @@ export type TScale = 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl' | 'xxxl';

export type TInlineProps = {
/** sets the amount of spacing between individual items */
scale: TScale;
scale?: TScale;
/**
* sets the `align-self` value on all direct children.
* https://developer.mozilla.org/en-US/docs/Web/CSS/align-items */
alignItems: TAlignItem;
alignItems?: TAlignItem;
/**
* defines how the browser distributes space between and around content items along the main-axis.
* https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content */
justifyContent: TJustifyContent;
justifyContent?: TJustifyContent;
children: ReactNode;
};

const Inline = (props: TInlineProps) => (
<span css={getStyles(props)} {...filterDataAttributes(props)}>
const Inline = ({
scale = 's',
alignItems = 'flex-start',
justifyContent = 'flex-start',
...props
}: TInlineProps) => (
<span
css={getStyles({
scale,
alignItems,
justifyContent,
...props,
})}
{...filterDataAttributes({
scale,
alignItems,
justifyContent,
...props,
})}
>
{props.children}
</span>
);
const defaultProps: Pick<
TInlineProps,
'scale' | 'alignItems' | 'justifyContent'
> = {
scale: 's',
alignItems: 'flex-start',
justifyContent: 'flex-start',
};
Inline.defaultProps = defaultProps;
Inline.displayName = 'Inline';

export default Inline;
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { filterDataAttributes } from '@commercetools-uikit/utils';
export type TScale = 's' | 'm' | 'l';
export type TInsetSquishProps = {
/** sets the amount of `padding` applied around the children */
scale: TScale;
scale?: TScale;
/** sets the height of the component to 100% of the available width ('expanded') or 'auto' */
height: 'collapsed' | 'expanded';
height?: 'collapsed' | 'expanded';
children: ReactNode;
};

Expand All @@ -25,22 +25,25 @@ const getPadding = (scale?: TScale) => {
}
};

const InsetSquish = (props: TInsetSquishProps) => (
const InsetSquish = ({
scale = 'm',
height = 'collapsed',
...props
}: TInsetSquishProps) => (
<div
css={css`
padding: ${getPadding(props.scale)};
height: ${props.height === 'expanded' ? '100%' : 'auto'};
padding: ${getPadding(scale)};
height: ${height === 'expanded' ? '100%' : 'auto'};
`}
{...filterDataAttributes(props)}
{...filterDataAttributes({
scale,
height,
...props,
})}
>
{props.children}
</div>
);
const defaultProps: Pick<TInsetSquishProps, 'scale' | 'height'> = {
scale: 'm',
height: 'collapsed',
};
InsetSquish.displayName = 'InsetSquish';
InsetSquish.defaultProps = defaultProps;

export default InsetSquish;
25 changes: 14 additions & 11 deletions packages/components/spacings/spacings-inset/src/inset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,31 @@ const getPadding = (scale?: TScale) => {

export type TInsetProps = {
/** sets the amount of `padding` applied around the children */
scale: TScale;
scale?: TScale;
/** sets the height of the component to 100% of the available width ('expanded') or 'auto' */
height: 'collapsed' | 'expanded';
height?: 'collapsed' | 'expanded';
children?: ReactNode;
};

const Inset = (props: TInsetProps) => (
const Inset = ({
scale = 'm',
height = 'collapsed',
...props
}: TInsetProps) => (
<div
css={css`
padding: ${getPadding(props.scale)};
height: ${props.height === 'expanded' ? '100%' : 'auto'};
padding: ${getPadding(scale)};
height: ${height === 'expanded' ? '100%' : 'auto'};
`}
{...filterDataAttributes(props)}
{...filterDataAttributes({
scale,
height,
...props,
})}
>
{props.children}
</div>
);
const defaultProps: Pick<TInsetProps, 'scale' | 'height'> = {
scale: 'm',
height: 'collapsed',
};
Inset.displayName = 'Inset';
Inset.defaultProps = defaultProps;

export default Inset;
28 changes: 19 additions & 9 deletions packages/components/spacings/spacings-stack/src/stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,34 @@ export type TScale = 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl' | 'xxxl';

export type TStackProps = {
/** specifies the spacing between individual items */
scale: TScale;
scale?: TScale;
/**
* sets the `align-self` value on all direct children.
* https://developer.mozilla.org/en-US/docs/Web/CSS/align-items */
alignItems: TAlignItem;
alignItems?: TAlignItem;
children: ReactNode;
};

const Stack = (props: TStackProps) => (
<div css={getStyles(props)} {...filterDataAttributes(props)}>
const Stack = ({
scale = 's',
alignItems = 'stretch',
...props
}: TStackProps) => (
<div
css={getStyles({
scale,
alignItems,
...props,
})}
{...filterDataAttributes({
scale,
alignItems,
...props,
})}
>
{props.children}
</div>
);
const defaultProps: Pick<TStackProps, 'scale' | 'alignItems'> = {
scale: 's',
alignItems: 'stretch',
};
Stack.displayName = 'Stack';
Stack.defaultProps = defaultProps;

export default Stack;

0 comments on commit 45288e9

Please sign in to comment.