diff --git a/packages/card/components/Card.tsx b/packages/card/components/Card.tsx index 79177800c..201c960e5 100644 --- a/packages/card/components/Card.tsx +++ b/packages/card/components/Card.tsx @@ -2,25 +2,34 @@ import * as React from "react"; import { style } from "../style"; import { cx } from "emotion"; import { preserveAspectRatio, padding } from "../../shared/styles/styleUtils"; +import { SpaceSize } from "../../shared/styles/styleUtils/modifiers/modifierUtils"; export interface CardProps { /** * `[width, height]` Keeps the card's width and height at a specific proportion. e.g.: 2:1 would be [2, 1] */ aspectRatio?: [number, number]; + /** + * The padding between the border and the content. Can be set for all viewport sizes, or configured to have different values at different viewport width breakpoints + */ + paddingSize?: SpaceSize; children?: React.ReactNode | string; } class Card extends React.PureComponent { + public static defaultProps: Partial = { + paddingSize: "m" + }; + public render() { - const { children, aspectRatio } = this.props; + const { children, aspectRatio, paddingSize } = this.props; const aspectRatioStyle = aspectRatio ? preserveAspectRatio(aspectRatio[0], aspectRatio[1]) : null; return (
-
{children}
+
{children}
); } diff --git a/packages/card/stories/Card.stories.tsx b/packages/card/stories/Card.stories.tsx index 78bb6fa8f..7e8f721af 100644 --- a/packages/card/stories/Card.stories.tsx +++ b/packages/card/stories/Card.stories.tsx @@ -1,17 +1,46 @@ import * as React from "react"; import { storiesOf } from "@storybook/react"; import { withReadme } from "storybook-readme"; +import { withKnobs, select } from "@storybook/addon-knobs"; import { Card } from "../index"; +import { SpaceSize } from "../../shared/styles/styleUtils/modifiers/modifierUtils"; const readme = require("../README.md"); storiesOf("Card", module) .addDecorator(withReadme([readme])) + .addDecorator(withKnobs) .add("default", () => default) - .add("2:1 aspect ratio", () => { + .add("paddingSize", () => { + const sizes = { + s: "s", + m: "m", + l: "l", + xl: "xl" + }; + const size = select("paddingSize", sizes, "m"); + return ( -
- I stay at a 2:1 aspect ratio -
+ + Use the Knobs panel to change the padding + ); - }); + }) + .add("responsive paddingSize", () => ( + + Resize the viewport to see the padding change + + )) + .add("2:1 aspect ratio", () => ( +
+ I stay at a 2:1 aspect ratio +
+ )); diff --git a/packages/card/tests/Card.test.tsx b/packages/card/tests/Card.test.tsx index 0b7457bf6..64a95c569 100644 --- a/packages/card/tests/Card.test.tsx +++ b/packages/card/tests/Card.test.tsx @@ -8,6 +8,11 @@ describe("Card", () => { it("default", () => { expect(toJSON(render(Example Content))).toMatchSnapshot(); }); + it("with paddingSize set", () => { + expect( + toJSON(render(Example Content)) + ).toMatchSnapshot(); + }); it("with aspectRatio set", () => { expect( toJSON(render(Example Content)) diff --git a/packages/card/tests/__snapshots__/Card.test.tsx.snap b/packages/card/tests/__snapshots__/Card.test.tsx.snap index af0546036..a5d71a9b2 100644 --- a/packages/card/tests/__snapshots__/Card.test.tsx.snap +++ b/packages/card/tests/__snapshots__/Card.test.tsx.snap @@ -23,3 +23,15 @@ exports[`Card with aspectRatio set 1`] = ` `; + +exports[`Card with paddingSize set 1`] = ` +
+
+ Example Content +
+
+`;