Skip to content

Commit 7429402

Browse files
committed
feat(TagsGroup): use group sm and add story
1 parent b303bc1 commit 7429402

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

src/TagsGroup.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { symToStr } from "tsafe/symToStr";
44
import Tag, { TagProps } from "./Tag";
55
import { useAnalyticsId } from "./tools/useAnalyticsId";
66
import { cx } from "./tools/cx";
7+
import { fr } from "./fr";
78

89
export type TagsGroupProps = TagsGroupProps.Common;
910

@@ -30,11 +31,16 @@ export const TagsGroup = memo(
3031
"explicitlyProvidedId": props_id
3132
});
3233

34+
const tagsGroupClassName = cx(
35+
fr.cx("fr-tags-group", smallTags && "fr-tags-group--sm"),
36+
className
37+
);
38+
3339
return (
34-
<ul className={cx("fr-tags-group", className)} style={style} id={id} ref={ref}>
40+
<ul className={tagsGroupClassName} style={style} id={id} ref={ref}>
3541
{tags.map((tagProps, i) => (
3642
<li key={i}>
37-
<Tag small={smallTags} {...tagProps} />
43+
<Tag {...tagProps} />
3844
</li>
3945
))}
4046
</ul>

stories/TagsGroup.stories.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { TagsGroup, TagsGroupProps } from "../dist/TagsGroup";
2+
import { sectionName } from "./sectionName";
3+
import { getStoryFactory } from "./getStory";
4+
import { TagProps } from "../dist/Tag";
5+
6+
const { meta, getStory } = getStoryFactory({
7+
sectionName,
8+
"wrappedComponent": { TagsGroup },
9+
"description": `
10+
- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/composants-et-modeles/composants/tag)
11+
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/TagsGroup.tsx)`,
12+
"argTypes": {
13+
"smallTags": {
14+
"description": `
15+
Default: false, if true, the tags will be smaller.
16+
`,
17+
"control": { "type": "boolean" }
18+
},
19+
"tags": {
20+
"description": `An array of TagProps (at least 1, max recommended: 6).`,
21+
"control": { "type": null }
22+
}
23+
},
24+
"disabledProps": ["lang"],
25+
"defaultContainerWidth": 800
26+
});
27+
28+
export default meta;
29+
30+
const tagsWithProps = (props?: Omit<TagProps, "children">) =>
31+
Array.from(
32+
{ "length": 6 },
33+
(_, i) =>
34+
({
35+
...props,
36+
"children": `Libellé tag ${i + 1}`
37+
} as TagProps)
38+
) as TagsGroupProps["tags"];
39+
40+
export const Default = getStory({
41+
"tags": tagsWithProps()
42+
});
43+
44+
export const SmallTags = getStory({
45+
"tags": tagsWithProps(),
46+
"smallTags": true
47+
});
48+
49+
export const TagsAsAnchor = getStory({
50+
"tags": tagsWithProps({ "linkProps": { "href": "#" } })
51+
});
52+
53+
export const SmallTagsAsAnchor = getStory({
54+
"tags": tagsWithProps({ "linkProps": { "href": "#" } }),
55+
"smallTags": true
56+
});
57+
58+
export const TagsPressed = getStory({
59+
"tags": tagsWithProps({ "pressed": true })
60+
});
61+
62+
export const SmallTagsPressed = getStory({
63+
"tags": tagsWithProps({ "pressed": true }),
64+
"smallTags": true
65+
});
66+
67+
export const TagsDismissable = getStory({
68+
"tags": tagsWithProps({ "dismissible": true })
69+
});
70+
71+
export const SmallTagsDismissable = getStory({
72+
"tags": tagsWithProps({ "dismissible": true }),
73+
"smallTags": true
74+
});

0 commit comments

Comments
 (0)