Skip to content

Commit 1666338

Browse files
committed
wip segmented control
1 parent 414105b commit 1666338

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/SegmentedControl.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { CSSProperties, forwardRef, memo } from "react";
2+
import { assert, Equals } from "tsafe";
3+
import { fr } from "./fr";
4+
import React from "react";
5+
import { CxArg } from "tss-react";
6+
import { cx } from "./tools/cx";
7+
import { useAnalyticsId } from "./tools/useAnalyticsId";
8+
9+
export type SegmentedControlProps = {
10+
id?: string;
11+
className?: string;
12+
classes?: Partial<
13+
Record<
14+
| "root"
15+
| "container"
16+
| "row"
17+
| "newsletter-col"
18+
| "newsletter"
19+
| "newsletter-title"
20+
| "newsletter-desc"
21+
| "newsletter-form-wrapper"
22+
| "newsletter-form-hint"
23+
| "social-col"
24+
| "social"
25+
| "social-title"
26+
| "social-buttons"
27+
| "social-buttons-each",
28+
CxArg
29+
>
30+
>;
31+
style?: CSSProperties;
32+
};
33+
34+
//https://main--ds-gouv.netlify.app/example/component/segmented/
35+
export namespace SegmentedControlProps {}
36+
37+
/** @see <https://components.react-dsfr.codegouv.studio/?path=/docs/components-segmented-control> */
38+
export const SegmentedControl = memo(
39+
forwardRef<HTMLFieldSetElement, SegmentedControlProps>((props, ref) => {
40+
const { id: props_id, className, classes = {}, style, ...rest } = props;
41+
42+
assert<Equals<keyof typeof rest, never>>();
43+
44+
const id = useAnalyticsId({
45+
"defaultIdPrefix": "fr-follow",
46+
"explicitlyProvidedId": props_id
47+
});
48+
49+
return (
50+
<fieldset
51+
id={id}
52+
className={cx(fr.cx("fr-segmented"), classes.root, className)}
53+
ref={ref}
54+
style={style}
55+
{...rest}
56+
></fieldset>
57+
);
58+
})
59+
);

0 commit comments

Comments
 (0)