Skip to content

Commit 607da9d

Browse files
feat(@clayui/card): add active state for card when it is selected
1 parent 608c81a commit 607da9d

File tree

8 files changed

+261
-132
lines changed

8 files changed

+261
-132
lines changed

packages/clay-card/src/Card.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import Group from './Group';
1717
import Row from './Row';
1818

1919
export interface ICardProps extends IContext {
20+
/**
21+
* Flag that indicates if `active` class is applied
22+
*/
23+
active?: boolean;
24+
2025
/**
2126
* Determines the style of the card
2227
*/
@@ -35,6 +40,7 @@ interface IProps
3540
> {}
3641

3742
const ClayCard: React.FunctionComponent<IProps> = ({
43+
active,
3844
children,
3945
className,
4046
displayType,
@@ -53,6 +59,7 @@ const ClayCard: React.FunctionComponent<IProps> = ({
5359
className={classNames(
5460
className,
5561
{
62+
active,
5663
card: !selectable,
5764
'file-card': isCardType.file,
5865
'form-check-card form-check form-check-top-left': selectable,

packages/clay-card/src/CardHorizontal.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import React from 'react';
99
import Context from './Context';
1010

1111
interface IProps extends React.BaseHTMLAttributes<HTMLDivElement> {
12+
/**
13+
* Flag that indicates if `active` class is applied
14+
*/
15+
active?: boolean;
16+
1217
/**
1318
* Flag that indicates if the card can be selectable.
1419
*/
@@ -28,12 +33,13 @@ const ClayCardHorizontalBody: React.FunctionComponent<React.HTMLAttributes<
2833

2934
export const ClayCardHorizontal: React.FunctionComponent<IProps> & {
3035
Body: typeof ClayCardHorizontalBody;
31-
} = ({children, className, selectable, ...otherProps}) => (
36+
} = ({active, children, className, selectable, ...otherProps}) => (
3237
<Context.Provider value={{horizontal: true, interactive: false}}>
3338
<div
3439
className={classNames(
3540
className,
3641
{
42+
active,
3743
'card card-horizontal': !selectable,
3844
'form-check-card form-check form-check-middle-left': selectable,
3945
},

packages/clay-card/src/CardWithHorizontal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ export const ClayCardWithHorizontal: React.FunctionComponent<IProps> = ({
118118
);
119119

120120
return (
121-
<ClayCardHorizontal {...otherProps} selectable={!!onSelectChange}>
121+
<ClayCardHorizontal
122+
{...otherProps}
123+
active={selected}
124+
selectable={!!onSelectChange}
125+
>
122126
{onSelectChange && (
123127
<ClayCheckbox
124128
{...checkboxProps}

packages/clay-card/src/CardWithInfo.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export const ClayCardWithInfo: React.FunctionComponent<IProps> = ({
199199
return (
200200
<ClayCard
201201
{...otherProps}
202+
active={selected}
202203
displayType={isCardType.image ? 'image' : 'file'}
203204
selectable={!!onSelectChange}
204205
>

packages/clay-card/src/CardWithUser.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export const ClayCardWithUser: React.FunctionComponent<IProps> = ({
122122
return (
123123
<ClayCard
124124
{...otherProps}
125+
active={selected}
125126
displayType="user"
126127
selectable={!!onSelectChange}
127128
>

packages/clay-card/src/__tests__/__snapshots__/index.tsx.snap

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,78 @@ exports[`ClayCard renders a ClayCard as user selectable card 1`] = `
918918
</div>
919919
`;
920920

921+
exports[`ClayCard renders a ClayCard with an active selected state 1`] = `
922+
<div>
923+
<div
924+
class="active form-check-card form-check form-check-top-left card-type-asset"
925+
>
926+
<div
927+
class="card"
928+
>
929+
<div
930+
class="custom-control custom-checkbox"
931+
>
932+
<label>
933+
<input
934+
class="custom-control-input"
935+
type="checkbox"
936+
/>
937+
<span
938+
class="custom-control-label"
939+
/>
940+
<div
941+
class="card-body"
942+
>
943+
<div
944+
class="card-row"
945+
>
946+
<div
947+
class="autofit-col"
948+
>
949+
<span
950+
class="sticker sticker-secondary"
951+
>
952+
<span
953+
class="sticker-overlay inline-item"
954+
>
955+
<svg
956+
class="lexicon-icon lexicon-icon-folder"
957+
role="presentation"
958+
>
959+
<use
960+
xlink:href="/path/to/some/resource.svg#folder"
961+
/>
962+
</svg>
963+
</span>
964+
</span>
965+
</div>
966+
<div
967+
class="autofit-col autofit-col-expand autofit-col-gutters"
968+
>
969+
<p
970+
class="card-title"
971+
title="Very Large Folder"
972+
>
973+
<span
974+
class="text-truncate-inline"
975+
>
976+
<span
977+
class="text-truncate"
978+
>
979+
Very Large Folder
980+
</span>
981+
</span>
982+
</p>
983+
</div>
984+
</div>
985+
</div>
986+
</label>
987+
</div>
988+
</div>
989+
</div>
990+
</div>
991+
`;
992+
921993
exports[`ClayCard renders a group of ClayCards 1`] = `
922994
<div>
923995
<ul

packages/clay-card/src/__tests__/index.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,34 @@ describe('ClayCard', () => {
9090
expect(container).toMatchSnapshot();
9191
});
9292

93+
it('renders a ClayCard with an active selected state', () => {
94+
const {container} = render(
95+
<ClayCard active selectable>
96+
<ClayCheckboxWithState>
97+
<ClayCard.Body>
98+
<ClayCard.Row>
99+
<div className="autofit-col">
100+
<ClaySticker displayType="secondary" inline>
101+
<ClayIcon
102+
spritemap="/path/to/some/resource.svg"
103+
symbol="folder"
104+
/>
105+
</ClaySticker>
106+
</div>
107+
<div className="autofit-col autofit-col-expand autofit-col-gutters">
108+
<ClayCard.Description displayType="title">
109+
{'Very Large Folder'}
110+
</ClayCard.Description>
111+
</div>
112+
</ClayCard.Row>
113+
</ClayCard.Body>
114+
</ClayCheckboxWithState>
115+
</ClayCard>
116+
);
117+
118+
expect(container).toMatchSnapshot();
119+
});
120+
93121
it('renders a ClayCard as image card', () => {
94122
const {container} = render(
95123
<ClayCard displayType="image">

0 commit comments

Comments
 (0)