Skip to content

Commit 2bc67d8

Browse files
committed
delete accordionGroup and make changes mentionned in review
1 parent d571d8b commit 2bc67d8

File tree

6 files changed

+37
-117
lines changed

6 files changed

+37
-117
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@
127127
"./Header": "./dist/Header.js",
128128
"./DarkModeSwitch": "./dist/DarkModeSwitch.js",
129129
"./Alert": "./dist/Alert.js",
130-
"./AccordionGroup": "./dist/AccordionGroup.js",
131130
"./Accordion": "./dist/Accordion.js"
132131
}
133132
}

src/Accordion.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,24 @@ export namespace AccordionProps {
1717
label: ReactNode;
1818
classes?: Partial<Record<"root" | "accordion" | "title" | "collapse", string>>;
1919
content: NonNullable<ReactNode>;
20-
defaultExpanded?: boolean;
2120
};
2221

2322
export type Uncontrolled = Common & {
23+
defaultExpanded?: boolean;
2424
expanded?: undefined;
25-
onChange?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, expanded: boolean) => void;
25+
onExpandedChange?: (
26+
expanded: boolean,
27+
e: React.MouseEvent<HTMLButtonElement, MouseEvent>
28+
) => void;
2629
};
2730

2831
export type Controlled = Common & {
32+
defaultExpanded?: undefined;
2933
expanded: boolean;
30-
onChange: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, expanded: boolean) => void;
34+
onExpandedChange: (
35+
expanded: boolean,
36+
e: React.MouseEvent<HTMLButtonElement, MouseEvent>
37+
) => void;
3138
};
3239
}
3340

@@ -42,7 +49,7 @@ export const Accordion = memo(
4249
content,
4350
expanded: expandedProp,
4451
defaultExpanded = false,
45-
onChange,
52+
onExpandedChange,
4653
...rest
4754
} = props;
4855

@@ -57,8 +64,8 @@ export const Accordion = memo(
5764
const handleChange = useConstCallback(
5865
(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
5966
setExpandedState(!value);
60-
if (onChange) {
61-
onChange(event, !value);
67+
if (onExpandedChange) {
68+
onExpandedChange(!value, event);
6269
}
6370
}
6471
);

src/AccordionGroup.tsx

Lines changed: 0 additions & 46 deletions
This file was deleted.

stories/Accordion.stories.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
import { Accordion } from "../dist/Accordion";
2-
import { getStoryFactory } from "./getStory";
3-
//import { sectionName } from "./sectionName";
2+
import { getStoryFactory, logCallbacks } from "./getStory";
3+
import { sectionName } from "./sectionName";
44

55
const { meta, getStory } = getStoryFactory({
6-
"sectionName": "wip",
6+
"sectionName": sectionName,
77
"wrappedComponent": { Accordion },
88
"description": `- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/accordeon)
99
- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/Accordion.tsx)
1010
11-
## Controlled
11+
## Accordion group
12+
13+
If you want to use a group of accordion, you juste have to wrap your acordions in a div with a class \`fr-accordions-group\` as bellow :
14+
15+
\`\`\`tsx
16+
<div className={fr.cx("fr-accordions-group")}>
17+
<Accordion label="Name of the Accordion 1" content="Content of the Accordion 1" />
18+
<Accordion label="Name of the Accordion 2" content="Content of the Accordion 2" />
19+
</div>
20+
\`\`\`
21+
22+
## Controlled
1223
1324
In this mode you are in charge of the behavior of the Accordion.
1425
_NOTE: In controlled mode there is no animation transition when expanding or colapsing the accordion._
1526
1627
\`\`\`tsx
1728
function ControlledAccordion() {
18-
const [expanded,setExpanded] = useState(true)
29+
const [expanded,setExpanded] = useState(false)
1930
return (
20-
<Accordion label="Name of the Accordion" content="Content of the Accordion" onChange={(e,value) => setExpanded(!value)} expanded={expanded}/>
31+
<Accordion label="Name of the Accordion" content="Content of the Accordion" onChange={(value,) => setExpanded(!value)} expanded={expanded}/>
2132
);
2233
2334
}
@@ -30,5 +41,6 @@ export default meta;
3041
export const Default = getStory({
3142
"label": "Name of the Accordion",
3243
"content": "Content of the Accordion",
33-
"defaultExpanded": false
44+
"defaultExpanded": false,
45+
...logCallbacks(["onExpandedChange"])
3446
});

stories/AccordionGroup.stories.tsx

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React, { useState } from "react"
22
import { Accordion } from "@codegouvfr/react-dsfr/Accordion";
3+
import { fr } from "@codegouvfr/react-dsfr";
34

45

56
export default function Test() {
6-
const [expanded, setExpanded] = useState<boolean>();
7+
const [expanded, setExpanded] = useState<boolean>(true);
78
return (
8-
<>
9+
<div className={fr.cx("fr-accordions-group")}>
910
<Accordion label="Accordion Uncontrolled" content="Content of the Uncontrolled Accordion" />
10-
<Accordion label="Accordion Controlled" content="Content of the controlled Accordion" defaultExpanded={true} expanded={expanded} onChange={(e, expanded) => { console.log(e); setExpanded(!expanded); }} />
11-
</>
11+
<Accordion label="Accordion Controlled" content="Content of the controlled Accordion" expanded={expanded} onChange={(expanded, e) => { console.log("event", e); setExpanded(!expanded); }} />
12+
</div>
1213
)
1314
}

0 commit comments

Comments
 (0)