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: update to g2 implementation #32566

Merged
merged 24 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8242794
`<CardDivider />`: replace with new implementation
ciampo Jun 9, 2021
7d06111
`<CardMedia />`: replace with new implementation
ciampo Jun 9, 2021
ffb4edd
`<CardHeader />`: replace with new implementation
ciampo Jun 9, 2021
e82105b
`<CardFooter />`: replace with new implementation
ciampo Jun 9, 2021
2f7e68a
`<CardBody />`: replace with new implementation
ciampo Jun 9, 2021
11fb746
`<Card />`: replace with new implementation
ciampo Jun 9, 2021
70a2ae6
Add `none` as a value for the `size` props
ciampo Jun 9, 2021
ab3a011
Tweak card new padding configuration (spacing) to be same as previous…
ciampo Jun 9, 2021
05846b0
Update tests: use snapshots instead of query the DOM by classname
ciampo Jun 9, 2021
6235883
Change default value of `elevation` prop to `0` to mach old card s de…
ciampo Jun 14, 2021
31c9606
Update CHANGELOG
ciampo Jun 14, 2021
481b68e
CardMedia: remove MediaProps type in favour on inline declaration
ciampo Jun 14, 2021
2109a3e
Update Markdown paths from relative to absolute
ciampo Jun 14, 2021
1679b65
Add inline comment to mark the legacy classnames
ciampo Jun 14, 2021
13fcd78
CardDivider: remove unnecessary children null override
ciampo Jun 14, 2021
888adb7
Card: no need to return deprecated `isElevated` prop
ciampo Jun 14, 2021
459c019
Fix typo: contex => context
ciampo Jun 14, 2021
8197a1c
Update Card context explainer in Markdown files
ciampo Jun 14, 2021
f0a634f
Fix typo: `componnents` => `components`
ciampo Jun 15, 2021
2b12590
Card `SizeOptions`: Rename `none` value to `minimal`
ciampo Jun 15, 2021
eeecf93
Revert adding a new value of `none` (or `minimal`) to the allowed val…
ciampo Jun 16, 2021
5f3f888
Auto-format JSDocs
ciampo Jun 17, 2021
5bd2875
`Card`: do not return `elevation` if its value is `undefined` when co…
ciampo Jun 18, 2021
b6af6ee
Update snapshots
ciampo Jun 22, 2021
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
9 changes: 9 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

## Unreleased

### New Feature

- Update the border color used in `CardBody`, `CardHeader`, `CardFooter`, and `CardDivider` to a different shade of gray, in order to match the color used in other components ([#32566](https://github.com/WordPress/gutenberg/pull/32566)).

### Deprecation

- `isPrimary`, `isSecondary`, `isTertiary` and `isLink` props in `Button` have been deprecated. Use `variant` instead ([#31713](https://github.com/WordPress/gutenberg/pull/31713)).
- `isElevated` prop in `Card` has been deprecated. Use `elevation` instead ([#32566](https://github.com/WordPress/gutenberg/pull/32566)).

### Internal

- `Card`, `CardBody`, `CardHeader`, `CardFooter`, `CardMedia`, and `CardDivider` components have been re-written from the ground up ([#32566](https://github.com/WordPress/gutenberg/pull/32566)).

## 14.1.0 (2021-05-20)

Expand Down
24 changes: 15 additions & 9 deletions packages/components/src/card/card-body/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CardBody

CardBody renders an optional content area for a [`<Card />`](../).
`CardBody` renders an optional content area for a [`Card`](/packages/components/src/card/card/README.md). Multiple `CardBody` components can be used within `Card` if needed.

## Usage

Expand All @@ -16,20 +16,26 @@ const Example = () => (

## Props

### isShady
Note: This component is connected to [`Card`'s Context](/packages/components/src/card/card/README.md#context). The value of the `size` prop is derived from the `Card` parent component (if there is one). Setting this prop directly on this component will override any derived values.

### `isScrollable`: `boolean`

Determines if the component is scrollable.

- Required: No
- Default: `true`

### `isShady`: `boolean`

Renders with a light gray background color.

- Type: `Boolean`
- Required: No
- Default: `false`

### size
### `size`: `string`

Determines the amount of padding within the component.

- Type: `String`
- Required: No
- Default: `medium`

Note: This component is connected to [`<Card />`'s Context](../card/README.md#context). Passing props directly to this component will override the props derived from context.
- Required: No
- Default: `medium`
- Allowed values: `xSmall`, `small`, `medium`, `large`
40 changes: 40 additions & 0 deletions packages/components/src/card/card-body/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Internal dependencies
*/
import { contextConnect } from '../../ui/context';
import { Scrollable } from '../../scrollable';
import { View } from '../../view';
import { useCardBody } from './hook';

/**
* @param {import('../../ui/context').PolymorphicComponentProps<import('../types').BodyProps, 'div'>} props
* @param {import('react').Ref<any>} forwardedRef
*/
function CardBody( props, forwardedRef ) {
const { isScrollable, ...otherProps } = useCardBody( props );

if ( isScrollable ) {
return <Scrollable { ...otherProps } ref={ forwardedRef } />;
}

return <View { ...otherProps } ref={ forwardedRef } />;
}

/**
* `CardBody` renders an optional content area for a `Card`.
* Multiple `CardBody` components can be used within `Card` if needed.
*
* @example
* ```jsx
* import { Card, CardBody } from `@wordpress/components`;
*
* <Card>
* <CardBody>
* ...
* </CardBody>
* </Card>
* ```
*/
const ConnectedCardBody = contextConnect( CardBody, 'CardBody' );

export default ConnectedCardBody;
48 changes: 48 additions & 0 deletions packages/components/src/card/card-body/hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* External dependencies
*/
import { cx } from 'emotion';

/**
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
*/
import { useContextSystem } from '../../ui/context';
import * as styles from '../styles';

/**
* @param {import('../../ui/context').PolymorphicComponentProps<import('../types').BodyProps, 'div'>} props
*/
export function useCardBody( props ) {
const {
className,
isScrollable = true,
isShady = false,
size = 'medium',
...otherProps
} = useContextSystem( props, 'CardBody' );

const classes = useMemo(
() =>
cx(
styles.Body,
styles.borderRadius,
styles.cardPaddings[ size ],
isShady && styles.shady,
// This classname is added for legacy compatibility reasons.
'components-card__body',
className
),
[ className, isShady, size ]
);

return {
...otherProps,
className: classes,
isScrollable,
};
}
39 changes: 2 additions & 37 deletions packages/components/src/card/card-body/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,2 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* Internal dependencies
*/
import { BodyUI } from '../styles';
import { useCardContext } from '../context';

export const defaultProps = {
isShady: false,
size: 'medium',
};

/* eslint-disable jsdoc/valid-types */
/**
* @param { import('../types').BodyProps & JSX.IntrinsicElements['div'] } props
*/
export function CardBody( props ) {
/* eslint-enable jsdoc/valid-types */
const { className, isShady, ...additionalProps } = props;
const mergedProps = { ...defaultProps, ...useCardContext(), ...props };
const { size } = mergedProps;

const classes = classnames(
'components-card__body',
isShady && 'is-shady',
size && `is-size-${ size }`,
className
);

return <BodyUI { ...additionalProps } className={ classes } />;
}

export default CardBody;
export { default } from './component';
export { useCardBody } from './hook';
8 changes: 7 additions & 1 deletion packages/components/src/card/card-divider/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CardDivider

CardDivider renders an optional divider within a [`<Card />`](../card/README.md).
`CardDivider` renders an optional divider within a [`Card`](/packages/components/src/card/card/README.md). It is typically used to divide multiple `CardBody` components from each other.

## Usage

Expand All @@ -15,3 +15,9 @@ const Example = () => (
</Card>
);
```

## Props

### Inherited props

`CardDivider` inherits all of the [`Divider` props](/packages/components/src/divider/README.md#props).
35 changes: 35 additions & 0 deletions packages/components/src/card/card-divider/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Internal dependencies
*/
import { contextConnect } from '../../ui/context';
import { Divider } from '../../divider';
import { useCardDivider } from './hook';

/**
* @param {import('../../ui/context').PolymorphicComponentProps<import('../../divider').DividerProps, 'hr'>} props
* @param {import('react').Ref<any>} forwardedRef
*/
function CardDivider( props, forwardedRef ) {
const dividerProps = useCardDivider( props );

return <Divider { ...dividerProps } ref={ forwardedRef } />;
}

/**
* `CardDivider` renders an optional divider within a `Card`.
* It is typically used to divide multiple `CardBody` components from each other.
*
* @example
* ```jsx
* import { Card, CardBody, CardDivider } from `@wordpress/components`;
*
* <Card>
* <CardBody>...</CardBody>
* <CardDivider />
* <CardBody>...</CardBody>
* </Card>
* ```
*/
const ConnectedCardDivider = contextConnect( CardDivider, 'CardDivider' );

export default ConnectedCardDivider;
42 changes: 42 additions & 0 deletions packages/components/src/card/card-divider/hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* External dependencies
*/
import { cx } from 'emotion';

/**
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
*/
import { useContextSystem } from '../../ui/context';
import * as styles from '../styles';

/**
* @param {import('../../ui/context').PolymorphicComponentProps<import('../../divider').DividerProps, 'hr'>} props
*/
export function useCardDivider( props ) {
const { className, ...otherProps } = useContextSystem(
props,
'CardDivider'
);

const classes = useMemo(
() =>
cx(
styles.Divider,
styles.borderColor,
// This classname is added for legacy compatibility reasons.
'components-card__divider',
ciampo marked this conversation as resolved.
Show resolved Hide resolved
className
),
[ className ]
);

return {
...otherProps,
className: classes,
};
}
33 changes: 2 additions & 31 deletions packages/components/src/card/card-divider/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,2 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* Internal dependencies
*/
import { DividerUI } from '../styles';

/* eslint-disable jsdoc/valid-types */
/**
* @param { JSX.IntrinsicElements['hr'] } props
*/
export function CardDivider( props ) {
/* eslint-enable jsdoc/valid-types */
const { className, ...additionalProps } = props;

const classes = classnames( 'components-card__divider', className );

return (
<DividerUI
{ ...additionalProps }
children={ null }
className={ classes }
role="separator"
/>
);
}

export default CardDivider;
export { default } from './component';
export { useCardDivider } from './hook';
Loading