Skip to content

Commit

Permalink
new(Card): Adding two props 'noShadow' and 'selected' for Card (#396)
Browse files Browse the repository at this point in the history
* add noShadow and selected

* comments resolved

* fix lint

Co-authored-by: Monica Ma <monica.ma@airbnb.com>
  • Loading branch information
monicapharm and Monica Ma authored Aug 4, 2020
1 parent d1cda9f commit a57ae8e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
19 changes: 17 additions & 2 deletions packages/core/src/components/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,32 @@ export { Content };
export type CardProps = {
/** List of `Content`s blocks to contain content. */
children: NonNullable<React.ReactNode>;
/** Hide shadow. */
noShadow?: boolean;
/** Set overflow to be visible. */
overflow?: boolean;
/** Whether the card is selected or not. */
selected?: boolean;
/** Custom style sheet. */
styleSheet?: StyleSheet;
};

/**
* An abstract layout to use as a base for cards.
*/
export default function Card({ children, overflow, styleSheet }: CardProps) {
export default function Card({ children, noShadow, overflow, selected, styleSheet }: CardProps) {
const [styles, cx] = useStyles(styleSheet ?? styleSheetCard);

return <div className={cx(styles.card, overflow && styles.card_overflow)}>{children}</div>;
return (
<div
className={cx(
styles.card,
overflow && styles.card_overflow,
noShadow && styles.card_noShadow,
selected && styles.card_selected,
)}
>
{children}
</div>
);
}
32 changes: 32 additions & 0 deletions packages/core/src/components/Card/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,38 @@ asCompact.story = {
name: 'As compact.',
};

export function noShadow() {
return (
<Card noShadow>
<Content>
<Text>
<LoremIpsum />
</Text>
</Content>
</Card>
);
}

noShadow.story = {
name: 'No shadow.',
};

export function selected() {
return (
<Card selected>
<Content>
<Text>
<LoremIpsum />
</Text>
</Content>
</Card>
);
}

selected.story = {
name: 'Selected.',
};

export function cardAsAButtonWithMiddleAlignment() {
return (
<Card>
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/components/Card/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StyleSheet } from '../../hooks/useStyles';

export const styleSheetCard: StyleSheet = ({ color, pattern }) => ({
export const styleSheetCard: StyleSheet = ({ color, pattern, ui }) => ({
card: {
...pattern.box,
background: color.accent.bg,
Expand All @@ -10,6 +10,15 @@ export const styleSheetCard: StyleSheet = ({ color, pattern }) => ({
card_overflow: {
overflow: 'visible',
},

card_noShadow: {
boxShadow: 'none',
},

card_selected: {
border: ui.borderThick,
borderColor: color.core.primary[3],
},
});

export const styleSheetContent: StyleSheet = ({ color, pattern, ui, unit }) => ({
Expand Down
32 changes: 32 additions & 0 deletions packages/core/test/components/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,36 @@ describe('<Card />', () => {

expect(withoutOverflow.prop('className')).not.toBe(withOverflow.prop('className'));
});

it('renders different styles for `noShadow`', () => {
const withoutNoShadow = shallow(
<Card>
<Content>Foo</Content>
</Card>,
);

const withNoShadow = shallow(
<Card noShadow>
<Content>Foo</Content>
</Card>,
);

expect(withoutNoShadow.prop('className')).not.toBe(withNoShadow.prop('className'));
});

it('renders different styles for `selected`', () => {
const withoutSelected = shallow(
<Card>
<Content>Foo</Content>
</Card>,
);

const withSelected = shallow(
<Card selected>
<Content>Foo</Content>
</Card>,
);

expect(withoutSelected.prop('className')).not.toBe(withSelected.prop('className'));
});
});

0 comments on commit a57ae8e

Please sign in to comment.