Skip to content

Commit

Permalink
feat: rid of the .Plate suffix in components
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed Dec 25, 2018
1 parent 1d88416 commit 18bc78b
Show file tree
Hide file tree
Showing 42 changed files with 662 additions and 714 deletions.
24 changes: 21 additions & 3 deletions src/components/Card/CardPlate.js → src/components/Card/Card.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// @flow
import React from 'react';

import { CardHeader, cardHeaderTheme } from './CardHeader';
import { CardBody, cardBodyTheme } from './CardBody';
import { CardSection, cardSectionTheme } from './CardSection';
import { CardFooter, cardFooterTheme } from './CardFooter';

import { Paper } from '../Paper';
import type { PropSizes } from '../../types';

Expand All @@ -12,7 +18,14 @@ type CardPlateProps = {
borderRadius?: 'top' | 'bottom' | 'all',
};

const CardPlate = ({ children, paddingOuter, padding, ...rest }: CardPlateProps) => (
const theme = {
...cardHeaderTheme,
...cardBodyTheme,
...cardSectionTheme,
...cardFooterTheme,
};

const Card = ({ children, paddingOuter, padding, ...rest }: CardPlateProps) => (
<Paper { ...rest } padding={ paddingOuter }>
{
typeof children === 'function'
Expand All @@ -26,8 +39,13 @@ const CardPlate = ({ children, paddingOuter, padding, ...rest }: CardPlateProps)
</Paper>
);

CardPlate.defaultProps = {
Card.defaultProps = {
padding: 'md',
};

export { CardPlate };
Card.Header = CardHeader;
Card.Body = CardBody;
Card.Section = CardSection;
Card.Footer = CardFooter;

export { Card, theme };
34 changes: 17 additions & 17 deletions src/components/Card/Card.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,53 @@ export default (asStory) => {
asStory('Components/Card', module, (story, { Card }) => {
story
.add('default', () => (
<Card.Plate>
<Card>
<Card.Header>Header</Card.Header>
<Card.Body>Body<br /><br /><br /><br /></Card.Body>
<Card.Footer>Footer </Card.Footer>
</Card.Plate>
<Card.Footer>Footer</Card.Footer>
</Card>
))
.add('with custom offsets', () => (
<Card.Plate offset="xl">
<Card offset="xl">
<Card.Header>Header</Card.Header>
<Card.Body >Body<br /><br /><br /><br /></Card.Body>
<Card.Footer>Footer </Card.Footer>
</Card.Plate>
<Card.Footer>Footer</Card.Footer>
</Card>
))
.add('without footer', () => (
<Card.Plate>
<Card>
<Card.Header>Header</Card.Header>
<Card.Body>Body<br /><br /><br /><br /></Card.Body>
</Card.Plate>
</Card>
))
.add('without multiple sections', () => (
<Card.Plate>
<Card>
<Card.Header>Header</Card.Header>
<Card.Body padding="none">
<Card.Section>Section<br /><br /><br /><br /></Card.Section>
<Card.Section>Section<br /><br /><br /><br /></Card.Section>
<Card.Section>Section<br /><br /><br /><br /></Card.Section>
</Card.Body>
<Card.Footer>Footer </Card.Footer>
</Card.Plate>
<Card.Footer>Footer</Card.Footer>
</Card>
))
.add('without header', () => (
<Card.Plate>
<Card>
<Card.Body>Body<br /><br /><br /><br /></Card.Body>
<Card.Footer>Footer </Card.Footer>
</Card.Plate>
<Card.Footer>Footer</Card.Footer>
</Card>
))
.add('with scrollable body', () => (
<ShortDiv>
<Card.Plate>
<Card>
<Card.Header>Header</Card.Header>
<Card.Body padding="none" scrollable>
<Card.Section>Section<br /><br /><br /><br /><br /><br /><br /><br /></Card.Section>
<Card.Section>Section<br /><br /><br /><br /><br /><br /><br /><br /></Card.Section>
<Card.Section>Section<br /><br /><br /><br /><br /><br /><br /><br /></Card.Section>
</Card.Body>
<Card.Footer>Footer </Card.Footer>
</Card.Plate>
<Card.Footer>Footer</Card.Footer>
</Card>
</ShortDiv>
));
});
Expand Down
8 changes: 4 additions & 4 deletions src/components/Card/Card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ describe('<Card />', () => {
it('should render Card components', () => {
const wrapper = mount(
<EightBaseBoostProvider>
<Card.Plate>
<Card>
<Card.Header>Header</Card.Header>
<Card.Body>
<Card.Section>
Body
</Card.Section>
</Card.Body>
<Card.Footer>Footer</Card.Footer>
</Card.Plate>
</Card>
</EightBaseBoostProvider>,
);

Expand All @@ -26,7 +26,7 @@ describe('<Card />', () => {
it('should render Card components with render prop', () => {
const wrapper = mount(
<EightBaseBoostProvider>
<Card.Plate someArg={ 42 } padding="xl">
<Card someArg={ 42 } padding="xl">
{ ({ someArg }: *) => (
<React.Fragment>
<Card.Header>Header</Card.Header>
Expand All @@ -36,7 +36,7 @@ describe('<Card />', () => {
<Card.Footer>Footer</Card.Footer>
</React.Fragment>
) }
</Card.Plate>
</Card>
</EightBaseBoostProvider>,
);

Expand Down
23 changes: 1 addition & 22 deletions src/components/Card/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
// @flow

import { CardPlate } from './CardPlate';
import { CardHeader, cardHeaderTheme } from './CardHeader';
import { CardBody, cardBodyTheme } from './CardBody';
import { CardSection, cardSectionTheme } from './CardSection';
import { CardFooter, cardFooterTheme } from './CardFooter';

const Card = {
Plate: CardPlate,
Header: CardHeader,
Body: CardBody,
Section: CardSection,
Footer: CardFooter,
};

const theme = {
...cardHeaderTheme,
...cardBodyTheme,
...cardSectionTheme,
...cardFooterTheme,
};

export { Card, theme };
export { Card, theme } from './Card';
4 changes: 2 additions & 2 deletions src/components/DateInput/DateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class DateInput extends React.Component<DateInputProps, DateInputState> {
const mask = withTime ? utils.DATETIME_MASK : utils.DATE_MASK;

return (
<Dropdown.Plate
<Dropdown
isOpen={ isOpen }
stretch={ stretch }
onCloseDropdown={ this.close }
Expand All @@ -144,7 +144,7 @@ class DateInput extends React.Component<DateInputProps, DateInputState> {
<Dropdown.Body withPortal preventOverflow>
<DatePicker { ...collectedProps } />
</Dropdown.Body>
</Dropdown.Plate>
</Dropdown>
);
}
}
Expand Down
118 changes: 103 additions & 15 deletions src/components/Dialog/Dialog.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,111 @@
import { DialogBody as Body, theme as dialogBodyTheme } from './DialogBody';
import { DialogFooter as Footer, theme as dialogFooterTheme } from './DialogFooter';
import { DialogHeader as Header, theme as dialogHeaderTheme } from './DialogHeader';
import { DialogPlate as Plate, theme as dialogPlateTheme } from './DialogPlate';

const Dialog = {
Body,
Footer,
Header,
Plate,
};
import React from 'react';

import { createStyledTag, createComponentTheme } from '../../utils';
import { Modal } from '../Modal';
import { Card } from '../Card';
import type { PropSizes } from '../../types';

import { DialogBody, theme as dialogBodyTheme } from './DialogBody';
import { DialogFooter, theme as dialogFooterTheme } from './DialogFooter';
import { DialogHeader, theme as dialogHeaderTheme } from './DialogHeader';

type DialogPlateProps = {|
children?: React$Node,
isOpen?: boolean,
onClose?: (any) => void,
onOpen?: (any) => void,
shouldCloseOnOverlayClick?: boolean,
shouldCloseOnEscPress ?: boolean,
padding?: PropSizes,
tagName?: string,
|};

const name = 'dialog';

const dialogTheme = createComponentTheme(name, {
modifiers: {
size: {
xs: {
width: '300px',
},
sm: {
width: '400px',
},
md: {
width: '500px',
},
lg: {
width: '600px',
},
xl: {
width: '800px',
},
},
},
defaults: {
size: 'md',
padding: 'md',
},
});

const theme = {
...dialogTheme,
...dialogBodyTheme,
...dialogFooterTheme,
...dialogHeaderTheme,
...dialogPlateTheme,
};

export {
Dialog,
theme,
const DialogTag = createStyledTag(name, {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
maxHeight: '90%',
flex: '0 1 90%',
});

const Dialog = ({
children,
id,
isOpen,
onOpen,
onClose,
shouldCloseOnOverlayClick,
shouldCloseOnEscPress,
size,
args,
tagName,
...rest
}: DialogPlateProps) => {
return (
<Modal
id={ id }
isOpen={ isOpen }
onOpen={ onOpen }
onClose={ onClose }
args={ args }
shouldCloseOnOverlayClick={ shouldCloseOnOverlayClick }
shouldCloseOnEscPress={ shouldCloseOnEscPress }
>
{
({ args, onClose }) => (
<DialogTag tagName={ tagName } size={ size }>
<Card { ...rest } args={ args } onClose={ onClose }>
{ children }
</Card>
</DialogTag>
)
}
</Modal>
);
};

Dialog.defaultProps = {
...dialogTheme[name].defaults,
tagName: 'div',
};

Dialog.Body = DialogBody;
Dialog.Header = DialogHeader;
Dialog.Footer = DialogFooter;

export { Dialog, theme };
8 changes: 4 additions & 4 deletions src/components/Dialog/Dialog.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default (asStory) => {
asStory('Components/Dialog', module, (story, { ModalContext, Dialog, Paragraph, Button }) => {
story
.add('with default header, body, actions and footer', () => (
<Dialog.Plate size="sm" isOpen>
<Dialog size="sm" isOpen>
<Dialog.Header title="Mark Job as Completed" />
<Dialog.Body>
<Paragraph>
Expand All @@ -15,14 +15,14 @@ export default (asStory) => {
<Button color="neutral" variant="outlined">Cancel</Button>
<Button type="submit">Apply</Button>
</Dialog.Footer>
</Dialog.Plate>
</Dialog>
))
.add('with state', () => (
<ModalContext.Consumer>
{
({ openModal, closeModal }) => (
<React.Fragment>
<Dialog.Plate id="ID" size="sm" onClose={ () => closeModal('ID') }>
<Dialog id="ID" size="sm" onClose={ () => closeModal('ID') }>
{
({ args, onClose }) => (
<React.Fragment>
Expand All @@ -39,7 +39,7 @@ export default (asStory) => {
</React.Fragment>
)
}
</Dialog.Plate>
</Dialog>
<Button onClick={ () => openModal('ID', { foo: '00', bar: '00' }) }>Open</Button>
</React.Fragment>
)
Expand Down
Loading

0 comments on commit 18bc78b

Please sign in to comment.