Skip to content

Commit 4089d16

Browse files
feat(card): create CardWithFolder high-level component
1 parent 28b719a commit 4089d16

File tree

7 files changed

+1554
-944
lines changed

7 files changed

+1554
-944
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* © 2019 Liferay, Inc. <https://liferay.com>
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
import ClayCard from './Card';
8+
import ClayForm from '@clayui/form';
9+
import ClayIcon from '@clayui/icon';
10+
import ClaySticker from '@clayui/sticker';
11+
import React from 'react';
12+
import {ClayDropDownWithBasicItems} from '@clayui/drop-down';
13+
14+
interface IProps {
15+
actions?: React.ComponentProps<typeof ClayDropDownWithBasicItems>['items'];
16+
/**
17+
* Path or URL to folder
18+
*/
19+
href?: string;
20+
21+
/**
22+
* Name of the folder
23+
*/
24+
name: string;
25+
26+
/**
27+
* Callback for when item is selected
28+
*/
29+
onSelectChange?: (val: boolean) => void;
30+
31+
/**
32+
* Flag to indicate if card is selected
33+
*/
34+
selected?: boolean;
35+
36+
/**
37+
* Path to clay icon spritemap
38+
*/
39+
spritemap: string;
40+
}
41+
42+
export const ClayCardWithFolder: React.FunctionComponent<IProps> = ({
43+
actions,
44+
href,
45+
name,
46+
onSelectChange,
47+
selected = false,
48+
spritemap,
49+
}) => {
50+
const content = (
51+
<ClayCard.Body>
52+
<div className="autofit-col">
53+
<ClaySticker inline>
54+
<ClayIcon spritemap={spritemap} symbol="folder" />
55+
</ClaySticker>
56+
</div>
57+
58+
<div className="autofit-col autofit-col-expand autofit-col-gutters">
59+
<ClayCard.Description displayType="title" href={href}>
60+
{name}
61+
</ClayCard.Description>
62+
</div>
63+
64+
{actions && (
65+
<div className="autofit-col">
66+
<ClayDropDownWithBasicItems
67+
items={actions}
68+
spritemap={spritemap}
69+
trigger={
70+
<button className="component-action">
71+
<ClayIcon
72+
spritemap={spritemap}
73+
symbol="ellipsis-v"
74+
/>
75+
</button>
76+
}
77+
/>
78+
</div>
79+
)}
80+
</ClayCard.Body>
81+
);
82+
83+
return (
84+
<ClayCard horizontal selectable={!!onSelectChange}>
85+
{onSelectChange && (
86+
<ClayForm.Checkbox
87+
checked={selected}
88+
disabled={false}
89+
indeterminate={false}
90+
onChange={() => onSelectChange(!selected)}
91+
>
92+
{content}
93+
</ClayForm.Checkbox>
94+
)}
95+
96+
{!onSelectChange && content}
97+
</ClayCard>
98+
);
99+
};

packages/clay-card/src/Description.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
*/
66

77
import classNames from 'classnames';
8-
import Context from './Context';
98
import React from 'react';
109

1110
type CardDescriptionDisplayType = 'text' | 'title' | 'subtitle';
1211

1312
interface ICardDescriptionProps
1413
extends React.HTMLAttributes<
15-
HTMLAnchorElement | HTMLDivElement | HTMLSpanElement
14+
HTMLHeadingElement | HTMLDivElement | HTMLSpanElement
1615
> {
1716
/**
1817
* Type of description that can be applied for a text.
@@ -30,6 +29,12 @@ interface ICardDescriptionProps
3029
truncate?: boolean;
3130
}
3231

32+
const CARD_TYPE_ELEMENTS = {
33+
subtitle: 'span',
34+
text: 'div',
35+
title: 'h3',
36+
};
37+
3338
const ClayCardDescription: React.FunctionComponent<ICardDescriptionProps> = ({
3439
children,
3540
className,
@@ -38,22 +43,24 @@ const ClayCardDescription: React.FunctionComponent<ICardDescriptionProps> = ({
3843
truncate = true,
3944
...otherProps
4045
}: ICardDescriptionProps) => {
41-
const {interactive} = React.useContext(Context);
42-
43-
const interactiveTag = interactive ? 'span' : 'div';
44-
45-
const TagName = href ? 'a' : interactiveTag;
46+
const OuterTag = CARD_TYPE_ELEMENTS[displayType] as ('span' | 'div' | 'h3');
47+
const InnerTag = href ? 'a' : 'span';
4648

4749
return (
48-
<TagName
49-
className={classNames(className, `card-${displayType}`, {
50-
'text-truncate': truncate,
51-
})}
52-
href={href}
50+
<OuterTag
51+
className={classNames(className, `card-${displayType}`)}
52+
title={children ? children.toString() : undefined}
5353
{...otherProps}
5454
>
55-
{children}
56-
</TagName>
55+
<span className={truncate ? 'text-truncate-inline' : ''}>
56+
<InnerTag
57+
className={truncate ? 'text-truncate' : ''}
58+
href={href}
59+
>
60+
{children}
61+
</InnerTag>
62+
</span>
63+
</OuterTag>
5764
);
5865
};
5966

0 commit comments

Comments
 (0)