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

feat(card): initial card implementation #145

Merged
merged 31 commits into from Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2595fb9
feat(card): initial card implementation
GiantRobots Oct 18, 2019
fb615d6
feat(card): new utilities
GiantRobots Oct 18, 2019
8ada1c1
feat(card): fixed box dependency and paste-type dependencies
GiantRobots Oct 18, 2019
0541dd9
feat(card): fix lint errors, make types a little nicer
GiantRobots Oct 21, 2019
8712f09
feat(card): dropped lint rules that weren't working right
GiantRobots Oct 21, 2019
cd91fbb
feat(card): added documentation portion of the card
GiantRobots Oct 22, 2019
684d3be
feat(card): add in body color
GiantRobots Oct 23, 2019
32e2f68
feat(card): fixed package.json
GiantRobots Oct 23, 2019
31a3fa9
feat(card): throw errors on bad attribute pass through
GiantRobots Nov 13, 2019
86afcbc
feat(card): drop a comment
GiantRobots Nov 13, 2019
278822f
feat(card): fixed prop error to allow data props through
GiantRobots Nov 13, 2019
4c627d9
feat(card): some fix
GiantRobots Nov 13, 2019
71ccd47
feat(card): fix snaps
GiantRobots Nov 13, 2019
de55726
feat(card): some fix
GiantRobots Nov 13, 2019
379ad39
Merge branch 'master' into Card
GiantRobots Nov 14, 2019
74a47cc
feat(card): some fix
GiantRobots Nov 13, 2019
c86235f
Merge remote-tracking branch 'origin/master'
GiantRobots Nov 14, 2019
553f7fc
Merge branch 'master' into Card
GiantRobots Nov 14, 2019
1a8d31c
feat(card): fix test verbiage
GiantRobots Nov 14, 2019
faf3dd1
feat(card): update snaps, fix linting errors
GiantRobots Nov 14, 2019
5fe8971
feat(card): resolve lint issues by moving files,
GiantRobots Nov 14, 2019
1fcc7c4
feat(card): move snapshots
GiantRobots Nov 14, 2019
113e879
feat(card): fix paste types dependency
GiantRobots Nov 14, 2019
06faf4c
feat(card): fix weird typeness
GiantRobots Nov 14, 2019
b8b5104
feat(card): drop id to allow build move @types react down to devdeps
GiantRobots Nov 14, 2019
b0ebdee
feat(card): update based on simon's recommendations
GiantRobots Nov 14, 2019
e17df9d
feat(card): drop border passsthrough
GiantRobots Nov 14, 2019
842ba24
feat(card): global html attrs
GiantRobots Nov 14, 2019
c729ab6
feat(card): no stale properties
GiantRobots Nov 14, 2019
e89c8df
feat(card): drop unused utilities, fixed eslint sort order
GiantRobots Nov 14, 2019
eba4d55
feat(card): update snaps
GiantRobots Nov 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions packages/paste-core/components/card/src/index.tsx
@@ -1,26 +1,31 @@
import * as React from 'react';
import {Box} from '@twilio-paste/box';
import {SpaceProps} from '@twilio-paste/types';
import {PaddingProps, BorderWidthProps, BorderColorProps, BorderStyleProps} from '@twilio-paste/types';
import {StaticDiv} from '@twilio-paste/types/src/DomTypes';
import {errorOnBadProps, spacingProps} from './utilities';

interface CardFooterProps extends SpaceProps, StaticDiv {}

const cardProps = spacingProps;
const cardFooterProps = spacingProps;
import {
errorOnBadProps,
spacingProps,
borderWidthProps,
borderStyleProps,
borderColorProps,
paddingProps,
} from './utilities';

interface CardFooterProps extends PaddingProps, StaticDiv {}
const cardFooterProps = paddingProps;

const CardFooter: React.FunctionComponent<CardFooterProps> = ({children, ...attributes}) => {
errorOnBadProps(attributes, cardFooterProps);

return (
<Box
as="article"
borderTopWidth="borderWidth10"
borderBottomWidth="borderWidth0"
borderLeftWidth="borderWidth0"
borderRightWidth="borderWidth0"
marginTop="space40"
paddingTop="space40"
borderColor="colorBorder"
borderStyle="solid"
{...attributes}
>
Expand All @@ -29,18 +34,21 @@ const CardFooter: React.FunctionComponent<CardFooterProps> = ({children, ...attr
);
};

interface CardProps extends SpaceProps, StaticDiv {}
interface CardProps extends PaddingProps, BorderStyleProps, BorderColorProps, BorderWidthProps, StaticDiv {}
const cardProps = [...paddingProps, ...borderWidthProps, ...borderColorProps, ...borderStyleProps];

const Card: React.FunctionComponent<CardProps> = ({children, ...attributes}) => {
errorOnBadProps(attributes, cardProps);

return (
<Box
as="article"
borderWidth="borderWidth20"
GiantRobots marked this conversation as resolved.
Show resolved Hide resolved
borderColor="colorBorder"
borderStyle="solid"
borderRadius="borderRadius20"
padding="space60"
backgroundColor="colorBackgroundBody"
{...attributes}
>
{children}
Expand Down
5 changes: 4 additions & 1 deletion packages/paste-core/components/card/src/utilities.tsx
@@ -1,6 +1,9 @@
const marginProps = ['margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft'];
const paddingProps = ['padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'];
GiantRobots marked this conversation as resolved.
Show resolved Hide resolved
const spacingProps = [...marginProps, ...paddingProps];
const borderWidthProps = ['borderWidth', 'borderBottomWidth', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth'];
const borderColorProps = ['borderColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor'];
const borderStyleProps = ['borderStyle', 'borderTopStyle', 'borderRightStyle', 'borderBottomStyle', 'borderLeftStyle'];

const errorOnBadProps = (props: {[key: string]: any}, propWhitelist: string[]): void => {
// Object.keys might be slow in the hot path
Expand All @@ -13,4 +16,4 @@ const errorOnBadProps = (props: {[key: string]: any}, propWhitelist: string[]):
}
};

export {marginProps, paddingProps, spacingProps, errorOnBadProps};
export {marginProps, paddingProps, spacingProps, borderWidthProps, borderColorProps, borderStyleProps, errorOnBadProps};
32 changes: 30 additions & 2 deletions packages/paste-core/components/card/stories/index.stories.tsx
@@ -1,12 +1,40 @@
import * as React from 'react';
import {storiesOf} from '@storybook/react';
import {Heading} from '@twilio-paste/heading';
import {withKnobs, select} from '@storybook/addon-knobs';
import {Text} from '@twilio-paste/text';
import {Card, CardFooter} from '../src';

import {Padding, Space} from '@twilio-paste/types';

const space = [
GiantRobots marked this conversation as resolved.
Show resolved Hide resolved
'space0',
'space10',
'space100',
'space110',
'space120',
'space130',
'space140',
'space150',
'space160',
'space170',
'space180',
'space190',
'space20',
'space200',
'space30',
'space40',
'space50',
'space60',
'space70',
'space80',
'space90',
];

storiesOf('Components|Card', module)
.addDecorator(withKnobs)
.add('Default', () => (
<Card>
<Card padding={select('padding', space, 'space10') as Padding}>
<Heading as="h2">With a heading</Heading>
<Text>Body</Text>
<CardFooter>
Expand All @@ -27,7 +55,7 @@ storiesOf('Components|Card', module)
</Card>
))
.add('Prop Passthrough', () => (
<Card aria-busy aria-atomic data-qahook="ZeCard!" id="12">
<Card aria-busy aria-atomic data-qahook="ZeCard!">
<Heading as="h2">With a heading</Heading>
<Text>Body</Text>
</Card>
Expand Down
51 changes: 26 additions & 25 deletions packages/paste-website/src/pages/components/card/index.mdx
Expand Up @@ -66,7 +66,7 @@ though children composed inside of it may commonly have event handlers.
Acknowledging the flexibility of Card component, there are several non-negotiable
properties of a Card that differentiate it from a more basic page-layout element, such as Box:

* A background color of $background-color-body.
* A background color of $color-background-body.
* A border width of $border-width-20.
* A border radius of $border-radius-20.
* A border color of $color-border.
Expand All @@ -79,30 +79,6 @@ properties of a Card that differentiate it from a more basic page-layout element
A card is a box with default attributes defined above. The purpose of the card is to provide a consistent experience to use across the website the design team can


## Usage Guide


### Installation

```bash
yarn add @twilio-paste/card

or

npm i @twilio-paste/card
```

### API

| Prop | Type | Description | Default |
|-------------- |------------------ |------------------------------------------ |---------------- |
| children? | React.ReactNode | Child components to render into the card | undefined |
| borderWidth | borderWidths | Width of the border | borderWidth20 |
| borderColor | BorderColors | Color of the border | colorBorder |
| borderStyle | BorderStyleProps | Style of the border | solid |
| borderRadius | Radii | Radius of the border | borderRadius20 |
| padding | Spacing | Internal spacing of the card | space60 |

### Examples
GiantRobots marked this conversation as resolved.
Show resolved Hide resolved

<LivePreview scope={{Card, Text, CardFooter, Heading}} language="jsx">
Expand Down Expand Up @@ -154,6 +130,31 @@ npm i @twilio-paste/card
</LivePreview>


## Usage Guide


### Installation

```bash
yarn add @twilio-paste/card

or

npm i @twilio-paste/card
```

### API

| Prop | Type | Description | Default |
|-------------- |------------------ |------------------------------------------ |---------------- |
| children? | React.ReactNode | Child components to render into the card | undefined |
| borderWidth | borderWidths | Width of the border | borderWidth20 |
| borderColor | BorderColors | Color of the border | colorBorder |
| borderStyle | BorderStyleProps | Style of the border | solid |
| borderRadius | Radii | Radius of the border | borderRadius20 |
| padding | Spacing | Internal spacing of the card | space60 |



</content>

Expand Down