Skip to content

Commit

Permalink
Refactor Inset components vertical space usage (#2635)
Browse files Browse the repository at this point in the history
* refactor: refactor inset components changes to be more retrocompatible

* chore: add changesets

* docs: update readmes

* docs: fix readmes

* refactor(spacings): rename components property

* refactor: update readme

* refactor(spacings): change property available values

* refactor(spacings): change property available values
  • Loading branch information
CarlosCortizasCT authored Nov 6, 2023
1 parent 968845c commit a743bcf
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-pugs-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-uikit/card': minor
---

Make card content to always use all available vertical space.
8 changes: 8 additions & 0 deletions .changeset/stale-radios-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@commercetools-uikit/spacings-inset-squish': minor
'@commercetools-uikit/spacings-inset': minor
---

Refactor vertical space usage so consumers can control it.

There's a new property named `height` (available values: `auto` and `100%`; the former is the default) that will allow consumers to control the vertical space usage of the component.
4 changes: 3 additions & 1 deletion packages/components/card/src/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ const Card = (props: TCardProps) => (
// This is mostly useful in case custom styles are targeting this element.
<div>{props.children}</div>
) : (
<Inset scale={props.insetScale}>{props.children}</Inset>
<Inset scale={props.insetScale} height="100%">
{props.children}
</Inset>
)}
</div>
);
Expand Down
51 changes: 36 additions & 15 deletions packages/components/card/src/card.visualroute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,85 +17,106 @@ const WrappedCard = (props) => (
css={css`
margin: 16px;
width: 300px;
height: ${props.height || 'auto'};
`}
{...props}
>
<Text.Body>{props.children}</Text.Body>
{props.children}
</Card>
);

export const component = () => (
<Suite>
<Spec label="Type - Raised, Theme - Light, InsetScale - None">
<WrappedCard type="raised" theme="light" insetScale="none">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Raised, Theme - Dark, InsetScale - None">
<WrappedCard type="raised" theme="dark" insetScale="none">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Flat, Theme - Light, InsetScale - None">
<WrappedCard type="flat" theme="light" insetScale="none">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Flat, Theme - Dark, InsetScale - None">
<WrappedCard type="flat" theme="dark" insetScale="none">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>

<Spec label="Type - Raised, Theme - Light, InsetScale - S">
<WrappedCard type="raised" theme="light" insetScale="s">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Raised, Theme - Dark, InsetScale - S">
<WrappedCard type="raised" theme="dark" insetScale="s">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Flat, Theme - Light, InsetScale - S">
<WrappedCard type="flat" theme="light" insetScale="s">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Flat, Theme - Dark, InsetScale - S">
<WrappedCard type="flat" theme="dark" insetScale="s">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>

<Spec label="Type - Raised, Theme - Light, InsetScale - M">
<WrappedCard type="raised" theme="light" insetScale="m">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Raised, Theme - Dark, InsetScale - M">
<WrappedCard type="raised" theme="dark" insetScale="m">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Flat, Theme - Light, InsetScale - M">
<WrappedCard type="flat" theme="light" insetScale="m">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Flat, Theme - Dark, InsetScale - M">
<WrappedCard type="flat" theme="dark" insetScale="m">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Raised, Theme - Light, InsetScale - L">
<WrappedCard type="raised" theme="light" insetScale="l">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>
<Spec label="Type - Raised, Theme - Light, InsetScale - XL">
<WrappedCard type="raised" theme="light" insetScale="xl">
{text}
<Text.Body>{text}</Text.Body>
</WrappedCard>
</Spec>

<Spec label="Content using all vertical space from the parent">
<WrappedCard type="raised" theme="light" insetScale="m" height="400px">
<div
css={css`
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
`}
>
<div>
{text}
</div>
<div>
{text}
</div>
</div>
</WrappedCard>
</Spec>
</Suite>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import Spacings from '@commercetools-uikit/spacings';
| Props | Type | Required | Values | Default |
| ---------- | ---------------- | :------: | ----------------- | ------- |
| `scale` | `String` | - | `['s', 'm', 'l']` | `m` |
| `height` | `String` | - | `auto`, `100%` | `auto` |
| `children` | `PropTypes.node` | - | - | - |

## Scales
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { filterDataAttributes } from '@commercetools-uikit/utils';
export type TScale = 's' | 'm' | 'l';
export type TInsetSquishProps = {
scale: TScale;
height: 'auto' | '100%';
children: ReactNode;
};

Expand All @@ -26,15 +27,16 @@ const InsetSquish = (props: TInsetSquishProps) => (
<div
css={css`
padding: ${getPadding(props.scale)};
height: 100%;
height: ${props.height};
`}
{...filterDataAttributes(props)}
>
{props.children}
</div>
);
const defaultProps: Pick<TInsetSquishProps, 'scale'> = {
const defaultProps: Pick<TInsetSquishProps, 'scale' | 'height'> = {
scale: 'm',
height: 'auto',
};
InsetSquish.displayName = 'InsetSquish';
InsetSquish.defaultProps = defaultProps;
Expand Down
1 change: 1 addition & 0 deletions packages/components/spacings/spacings-inset/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Spacings from '@commercetools-uikit/spacings';
| Props | Type | Required | Values | Default |
| ---------- | ---------------- | :------: | ----------------------------- | ------- |
| `scale` | `String` | - | `['xs', 's', 'm', 'l', 'xl']` | `x` |
| `height` | `String` | - | `auto`, `100%` | `auto` |
| `children` | `PropTypes.node` | - | - | - |

## Scales
Expand Down
6 changes: 4 additions & 2 deletions packages/components/spacings/spacings-inset/src/inset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ const getPadding = (scale?: TScale) => {

export type TInsetProps = {
scale: TScale;
height: 'auto' | '100%';
children?: ReactNode;
};

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

1 comment on commit a743bcf

@vercel
Copy link

@vercel vercel bot commented on a743bcf Nov 6, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.