|
| 1 | +import React from "react"; |
| 2 | +import { Tabs } from "../dist/Tabs"; |
| 3 | +import { sectionName } from "./sectionName"; |
| 4 | +import { getStoryFactory, logCallbacks } from "./getStory"; |
| 5 | + |
| 6 | +const { meta, getStory } = getStoryFactory({ |
| 7 | + sectionName, |
| 8 | + "wrappedComponent": { Tabs }, |
| 9 | + "description": `- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/onglets) |
| 10 | +- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/Tabs.tsx) |
| 11 | +
|
| 12 | +## Uncontrolled |
| 13 | +
|
| 14 | +In this mode the \`Tab\` component is in charge for swapping the panel content. |
| 15 | +
|
| 16 | +\`\`\`tsx |
| 17 | +<Tabs |
| 18 | + tabs={[ |
| 19 | + { "label": "Tab 1", "iconId": "fr-icon-add-line", "content": <p>Content of tab1</p> }, |
| 20 | + { "label": "Tab 2", "iconId": "fr-icon-ball-pen-fill", "content": <p>Content of tab2</p> }, |
| 21 | + { "label": "Tab 3", "content": <p>Content of tab3</p> } |
| 22 | + ]} |
| 23 | +/> |
| 24 | +\`\`\` |
| 25 | +
|
| 26 | +## Controlled |
| 27 | +
|
| 28 | +In this mode you are in change of the behavior of the tabs. |
| 29 | +_NOTE: In controlled mode there is no animation transition when switching between tabs._ |
| 30 | +
|
| 31 | +\`\`\`tsx |
| 32 | +function ControlledTabs() { |
| 33 | +
|
| 34 | + const [selectedTabId, setSelectedTabId] = useState("tab1"); |
| 35 | +
|
| 36 | + return ( |
| 37 | + <Tabs |
| 38 | + selectedTabId={selectedTabId} |
| 39 | + tabs={[ |
| 40 | + { "tabId": "tab1", "label": "Tab 1", "iconId": "fr-icon-add-line" }, |
| 41 | + { "tabId": "tab2", "label": "Tab 2", "iconId": "fr-icon-ball-pen-fill" }, |
| 42 | + { "tabId": "tab3", "label": "Tab 3" }, |
| 43 | + ]} |
| 44 | + onTabChange={setSelectedTabId} |
| 45 | + > |
| 46 | + <p>Content of {selectedTabId}</p> |
| 47 | + </Tabs> |
| 48 | + ); |
| 49 | +
|
| 50 | +} |
| 51 | +\`\`\``, |
| 52 | + "disabledProps": ["lang"] |
| 53 | +}); |
| 54 | + |
| 55 | +export default meta; |
| 56 | + |
| 57 | +export const Default = getStory({ |
| 58 | + "tabs": [ |
| 59 | + { "label": "Tab 1", "iconId": "fr-icon-add-line", "content": <p>Content of tab1</p> }, |
| 60 | + { "label": "Tab 2", "iconId": "fr-icon-ball-pen-fill", "content": <p>Content of tab2</p> }, |
| 61 | + { "label": "Tab 3", "content": <p>Content of tab3</p> } |
| 62 | + ], |
| 63 | + "label": "Name of the tabs system", |
| 64 | + ...logCallbacks(["onTabChange"]) |
| 65 | +}); |
0 commit comments