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

Card: support the extraSmall option for the size prop #37097

Merged
merged 4 commits into from
Dec 6, 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 @@ -9,6 +9,7 @@
- Updated readme to include default value introduced in fix for unexpected movements in the `ColorPicker` ([#35670](https://github.com/WordPress/gutenberg/pull/35670)).
- Replaced hardcoded blue in `ColorPicker` with UI theme color ([#36153](https://github.com/WordPress/gutenberg/pull/36153)).
- Fixed empty `ToolsPanel` height by correcting menu button line-height ([#36895](https://github.com/WordPress/gutenberg/pull/36895)).
- Added support for the legacy `extraSmall` value for the `size` prop in the `Card` component ([#37097](https://github.com/WordPress/gutenberg/pull/37097)).

### Experimental

Expand Down
11 changes: 8 additions & 3 deletions packages/components/src/card/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export const rounded = css`
border-radius: ${ CONFIG.cardBorderRadius };
`;

const xSmallCardPadding = css`
padding: ${ CONFIG.cardPaddingXSmall };
`;

export const cardPaddings = {
large: css`
padding: ${ CONFIG.cardPaddingLarge };
Expand All @@ -98,9 +102,10 @@ export const cardPaddings = {
small: css`
padding: ${ CONFIG.cardPaddingSmall };
`,
xSmall: css`
padding: ${ CONFIG.cardPaddingXSmall };
`,
xSmall: xSmallCardPadding,
// The `extraSmall` size is not officially documented, but the following styles
// are kept for legacy reasons to support older values of the `size` prop.
extraSmall: xSmallCardPadding,
};

export const shady = css`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Snapshot Diff:
</div>
<div
- class="components-flex components-card__footer components-card-footer css-c7cteg-View-Flex-sx-Base-sx-Items-ItemsRow-Footer-borderRadius-borderColor-large-borderless em57xhy0"
+ class="components-flex components-card__footer components-card-footer css-1mzdgj0-View-Flex-sx-Base-sx-Items-ItemsRow-Footer-borderRadius-borderColor-xSmall em57xhy0"
+ class="components-flex components-card__footer components-card-footer css-1t7s584-View-Flex-sx-Base-sx-Items-ItemsRow-Footer-borderRadius-borderColor-xSmallCardPadding em57xhy0"
data-wp-c16t="true"
data-wp-component="CardFooter"
>
Expand Down Expand Up @@ -784,6 +784,11 @@ Snapshot Diff:
</div>
`;

exports[`Card Card component should support the legacy extraSmall value for the size prop as an alias for the xSmall value 1`] = `
Snapshot Diff:
Compared values have no visual difference.
`;

exports[`Card Card component should warn when the isElevated prop is passed 1`] = `
.emotion-0 {
background-color: #fff;
Expand Down
20 changes: 20 additions & 0 deletions packages/components/src/card/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ describe( 'Card', () => {
expect( withoutBorder ).toMatchDiffSnapshot( withBorder );
} );

it( 'should support the legacy extraSmall value for the size prop as an alias for the xSmall value', () => {
const { container: containerXSmall } = render(
<Card size="xSmall">
<CardHeader>Header</CardHeader>
<CardBody>Body</CardBody>
<CardFooter>Footer</CardFooter>
</Card>
);
const { container: containerExtraSmall } = render(
<Card size="extraSmall">
<CardHeader>Header</CardHeader>
<CardBody>Body</CardBody>
<CardFooter>Footer</CardFooter>
</Card>
);
expect( containerXSmall ).toMatchDiffSnapshot(
containerExtraSmall
);
} );

describe( 'CardHeader', () => {
it( 'should render with a darker background color when isShady is true', () => {
const { container } = render( <CardHeader>Header</CardHeader> );
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/card/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { CSSProperties } from 'react';
*/
import type { Props as SurfaceProps } from '../surface/types';

type DeprecatedSizeOptions = 'extraSmall';
export type SizeOptions = 'xSmall' | 'small' | 'medium' | 'large';

type SizeableProps = {
Expand All @@ -17,7 +18,7 @@ type SizeableProps = {
*
* @default 'medium'
*/
size?: SizeOptions;
size?: SizeOptions | DeprecatedSizeOptions;
};

export type Props = SurfaceProps &
Expand Down