Skip to content

Commit a57ae8e

Browse files
monicapharmMonica Ma
andauthored
new(Card): Adding two props 'noShadow' and 'selected' for Card (#396)
* add noShadow and selected * comments resolved * fix lint Co-authored-by: Monica Ma <monica.ma@airbnb.com>
1 parent d1cda9f commit a57ae8e

File tree

4 files changed

+91
-3
lines changed

4 files changed

+91
-3
lines changed

packages/core/src/components/Card/index.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,32 @@ export { Content };
88
export type CardProps = {
99
/** List of `Content`s blocks to contain content. */
1010
children: NonNullable<React.ReactNode>;
11+
/** Hide shadow. */
12+
noShadow?: boolean;
1113
/** Set overflow to be visible. */
1214
overflow?: boolean;
15+
/** Whether the card is selected or not. */
16+
selected?: boolean;
1317
/** Custom style sheet. */
1418
styleSheet?: StyleSheet;
1519
};
1620

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

23-
return <div className={cx(styles.card, overflow && styles.card_overflow)}>{children}</div>;
27+
return (
28+
<div
29+
className={cx(
30+
styles.card,
31+
overflow && styles.card_overflow,
32+
noShadow && styles.card_noShadow,
33+
selected && styles.card_selected,
34+
)}
35+
>
36+
{children}
37+
</div>
38+
);
2439
}

packages/core/src/components/Card/story.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,38 @@ asCompact.story = {
326326
name: 'As compact.',
327327
};
328328

329+
export function noShadow() {
330+
return (
331+
<Card noShadow>
332+
<Content>
333+
<Text>
334+
<LoremIpsum />
335+
</Text>
336+
</Content>
337+
</Card>
338+
);
339+
}
340+
341+
noShadow.story = {
342+
name: 'No shadow.',
343+
};
344+
345+
export function selected() {
346+
return (
347+
<Card selected>
348+
<Content>
349+
<Text>
350+
<LoremIpsum />
351+
</Text>
352+
</Content>
353+
</Card>
354+
);
355+
}
356+
357+
selected.story = {
358+
name: 'Selected.',
359+
};
360+
329361
export function cardAsAButtonWithMiddleAlignment() {
330362
return (
331363
<Card>

packages/core/src/components/Card/styles.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StyleSheet } from '../../hooks/useStyles';
22

3-
export const styleSheetCard: StyleSheet = ({ color, pattern }) => ({
3+
export const styleSheetCard: StyleSheet = ({ color, pattern, ui }) => ({
44
card: {
55
...pattern.box,
66
background: color.accent.bg,
@@ -10,6 +10,15 @@ export const styleSheetCard: StyleSheet = ({ color, pattern }) => ({
1010
card_overflow: {
1111
overflow: 'visible',
1212
},
13+
14+
card_noShadow: {
15+
boxShadow: 'none',
16+
},
17+
18+
card_selected: {
19+
border: ui.borderThick,
20+
borderColor: color.core.primary[3],
21+
},
1322
});
1423

1524
export const styleSheetContent: StyleSheet = ({ color, pattern, ui, unit }) => ({

packages/core/test/components/Card.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,36 @@ describe('<Card />', () => {
1818

1919
expect(withoutOverflow.prop('className')).not.toBe(withOverflow.prop('className'));
2020
});
21+
22+
it('renders different styles for `noShadow`', () => {
23+
const withoutNoShadow = shallow(
24+
<Card>
25+
<Content>Foo</Content>
26+
</Card>,
27+
);
28+
29+
const withNoShadow = shallow(
30+
<Card noShadow>
31+
<Content>Foo</Content>
32+
</Card>,
33+
);
34+
35+
expect(withoutNoShadow.prop('className')).not.toBe(withNoShadow.prop('className'));
36+
});
37+
38+
it('renders different styles for `selected`', () => {
39+
const withoutSelected = shallow(
40+
<Card>
41+
<Content>Foo</Content>
42+
</Card>,
43+
);
44+
45+
const withSelected = shallow(
46+
<Card selected>
47+
<Content>Foo</Content>
48+
</Card>,
49+
);
50+
51+
expect(withoutSelected.prop('className')).not.toBe(withSelected.prop('className'));
52+
});
2153
});

0 commit comments

Comments
 (0)