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: refactor subcomponents folder structure #32557

Merged
merged 9 commits into from
Jun 10, 2021
32 changes: 31 additions & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,40 @@
"markdown_source": "../packages/components/src/button/README.md",
"parent": "components"
},
{
"title": "CardBody",
"slug": "card-body",
"markdown_source": "../packages/components/src/card/card-body/README.md",
"parent": "components"
},
{
"title": "CardDivider",
"slug": "card-divider",
"markdown_source": "../packages/components/src/card/card-divider/README.md",
"parent": "components"
},
{
"title": "CardFooter",
"slug": "card-footer",
"markdown_source": "../packages/components/src/card/card-footer/README.md",
"parent": "components"
},
{
"title": "CardHeader",
"slug": "card-header",
"markdown_source": "../packages/components/src/card/card-header/README.md",
"parent": "components"
},
{
"title": "CardMedia",
"slug": "card-media",
"markdown_source": "../packages/components/src/card/card-media/README.md",
"parent": "components"
},
{
"title": "Card",
"slug": "card",
"markdown_source": "../packages/components/src/card/README.md",
"markdown_source": "../packages/components/src/card/card/README.md",
"parent": "components"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Determines the amount of padding within the component.
- Required: No
- Default: `medium`

Note: This component is connected to [`<Card />`'s Context](../README.md#context). Passing props directly to this component will override the props derived from context.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import classnames from 'classnames';
/**
* Internal dependencies
*/
import { BodyUI } from './styles/card-styles';
import { useCardContext } from './context';
import { BodyUI } from '../styles';
import { useCardContext } from '../context';

export const defaultProps = {
isShady: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CardDivider

CardDivider renders an optional divider within a [`<Card />`](../).
CardDivider renders an optional divider within a [`<Card />`](../card/README.md).

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* Internal dependencies
*/
import { DividerUI } from './styles/card-styles';
import { DividerUI } from '../styles';

export function CardDivider( props ) {
const { className, ...additionalProps } = props;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CardFooter

CardFooter renders an optional footer within a [`<Card />`](../).
CardFooter renders an optional footer within a [`<Card />`](../card/README.md).

## Usage

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

### Flex

Underneath, CardFooter uses the layout component [`<Flex/>`](../../flex/README.md). This improves the alignment of child items within the component.
Underneath, CardFooter uses the layout component [`<Flex/>`](../../flex/flex/README.md). This improves the alignment of child items within the component.

```jsx
import {
Expand All @@ -39,7 +39,7 @@ const Example = () => (
);
```

Check out [the documentation](../../flex/README.md) on `<Flex/>` for more details on layout composition.
Check out [the documentation](../../flex/flex/README.md) on `<Flex/>` for more details on layout composition.

## Props

Expand Down Expand Up @@ -75,4 +75,4 @@ Determines the amount of padding within the component.
- Required: No
- Default: `medium`

Note: This component is connected to [`<Card />`'s Context](../README.md#context). Passing props directly to this component will override the props derived from context.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import classnames from 'classnames';
/**
* Internal dependencies
*/
import { FooterUI } from './styles/card-styles';
import { useCardContext } from './context';
import { FooterUI } from '../styles';
import { useCardContext } from '../context';

export const defaultProps = {
isBorderless: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CardHeader

CardHeader renders an optional header within a [`<Card />`](../).
CardHeader renders an optional header within a [`<Card />`](../card/README.md).

## Usage

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

### Flex

Underneath, CardHeader uses the layout component [`<Flex/>`](../../flex/README.md). This improves the alignment of child items within the component.
Underneath, CardHeader uses the layout component [`<Flex/>`](../../flex/flex/README.md). This improves the alignment of child items within the component.

```jsx
import {
Expand All @@ -39,7 +39,7 @@ const Example = () => (
);
```

Check out [the documentation](../../flex/README.md) on `<Flex/>` for more details on layout composition.
Check out [the documentation](../../flex/flex/README.md) on `<Flex/>` for more details on layout composition.

## Props

Expand Down Expand Up @@ -75,4 +75,4 @@ Determines the amount of padding within the component.
- Required: No
- Default: `medium`

Note: This component is connected to [`<Card />`'s Context](../README.md#context). Passing props directly to this component will override the props derived from context.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import classnames from 'classnames';
/**
* Internal dependencies
*/
import { HeaderUI } from './styles/card-styles';
import { useCardContext } from './context';
import { HeaderUI } from '../styles';
import { useCardContext } from '../context';

export const defaultProps = {
isBorderless: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CardMedia

CardMedia provides a container for media elements, and renders within a [`<Card />`](../).
CardMedia provides a container for media elements, and renders within a [`<Card />`](../card/README.md).

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* Internal dependencies
*/
import { MediaUI } from './styles/card-styles';
import { MediaUI } from '../styles';

export function CardMedia( props ) {
const { className, ...additionalProps } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Determines the amount of padding within the component.

This component provides a collection of sub-component that can be used to compose various interfaces.

- [`<CardBody />`](./docs/body.md)
- [`<CardDivider />`](./docs/divider.md)
- [`<CardFooter />`](./docs/footer.md)
- [`<CardHeader />`](./docs/header.md)
- [`<CardMedia />`](./docs/media.md)
- [`<CardBody />`](../card-body/README.md)
- [`<CardDivider />`](../card-divider/README.md)
- [`<CardFooter />`](../card-footer/README.md)
- [`<CardHeader />`](../card-header/README.md)
- [`<CardMedia />`](../card-media/README.md)

### Sub-Components Example

Expand Down
51 changes: 51 additions & 0 deletions packages/components/src/card/card/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
ciampo marked this conversation as resolved.
Show resolved Hide resolved
* External dependencies
*/
import classnames from 'classnames';

/**
* Internal dependencies
*/
import { CardContext } from '../context';
import { CardUI } from '../styles';

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

export function Card( props ) {
const {
className,
isBorderless,
isElevated,
size,
...additionalProps
} = props;
const { Provider } = CardContext;

const contextProps = {
isBorderless,
isElevated,
size,
};

const classes = classnames(
'components-card',
isBorderless && 'is-borderless',
isElevated && 'is-elevated',
size && `is-size-${ size }`,
className
);

return (
<Provider value={ contextProps }>
<CardUI { ...additionalProps } className={ classes } />
</Provider>
);
}

Card.defaultProps = defaultProps;

export default Card;
57 changes: 6 additions & 51 deletions packages/components/src/card/index.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* Internal dependencies
*/
import { CardContext } from './context';
import { CardUI } from './styles/card-styles';

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

export function Card( props ) {
const {
className,
isBorderless,
isElevated,
size,
...additionalProps
} = props;
const { Provider } = CardContext;

const contextProps = {
isBorderless,
isElevated,
size,
};

const classes = classnames(
'components-card',
isBorderless && 'is-borderless',
isElevated && 'is-elevated',
size && `is-size-${ size }`,
className
);

return (
<Provider value={ contextProps }>
<CardUI { ...additionalProps } className={ classes } />
</Provider>
);
}

Card.defaultProps = defaultProps;

export default Card;
export { default as Card } from './card';
export { default as CardBody } from './card-body';
export { default as CardDivider } from './card-divider';
export { default as CardFooter } from './card-footer';
export { default as CardHeader } from './card-header';
export { default as CardMedia } from './card-media';
5 changes: 1 addition & 4 deletions packages/components/src/card/stories/_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { text, boolean } from '@storybook/addon-knobs';
/**
* Internal dependencies
*/
import Card from '../index';
import CardBody from '../body';
import CardFooter from '../footer';
import CardHeader from '../header';
import { Card, CardBody, CardFooter, CardHeader } from '../';
import { getCardStoryProps } from './_utils';

export default { title: 'Components/Card', component: Card };
Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/card/stories/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { boolean, text } from '@storybook/addon-knobs';
/**
* Internal dependencies
*/
import Card from '../index';
import CardBody from '../body';
import { Card, CardBody } from '../';
import { getCardStoryProps } from './_utils';

export default { title: 'Components/Card/Body', component: CardBody };
Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/card/stories/divider.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* Internal dependencies
*/
import Card from '../index';
import CardBody from '../body';
import CardDivider from '../divider';
import { Card, CardBody, CardDivider } from '../';
import { getCardStoryProps } from './_utils';

export default { title: 'Components/Card/Divider', component: CardDivider };
Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/card/stories/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { boolean, text } from '@storybook/addon-knobs';
/**
* Internal dependencies
*/
import Card from '../index';
import CardFooter from '../footer';
import { Card, CardFooter } from '../';
import Button from '../../button';
import { FlexBlock, FlexItem } from '../../flex';
import { getCardStoryProps } from './_utils';
Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/card/stories/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { boolean, text } from '@storybook/addon-knobs';
/**
* Internal dependencies
*/
import Card from '../index';
import CardHeader from '../header';
import { Card, CardHeader } from '../';
import Button from '../../button';
import { FlexBlock, FlexItem } from '../../flex';
import { getCardStoryProps } from './_utils';
Expand Down
6 changes: 1 addition & 5 deletions packages/components/src/card/stories/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import styled from '@emotion/styled';
/**
* Internal dependencies
*/
import Card from '../index';
import CardBody from '../body';
import CardFooter from '../footer';
import CardHeader from '../header';
import CardMedia from '../media';
import { Card, CardBody, CardFooter, CardHeader, CardMedia } from '../';
import { getCardStoryProps } from './_utils';

export default { title: 'Components/Card/Media', component: CardMedia };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { HorizontalRule } from '@wordpress/primitives';
/**
* Internal dependencies
*/
import { Flex } from '../../flex';
import { COLORS, space } from '../../utils';
import { Flex } from '../flex';
import { COLORS, space } from '../utils';

export const styleProps = {
borderColor: COLORS.lightGray[ 500 ],
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/card/test/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { shallow } from 'enzyme';
/**
* Internal dependencies
*/
import CardBody from '../body';
import { CardBody } from '../';

describe( 'CardBody', () => {
describe( 'basic rendering', () => {
Expand Down
Loading