@commercetools/nimbus 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/apca-check/index.ts +150 -0
- package/.storybook/main.ts +64 -0
- package/.storybook/preview.tsx +92 -0
- package/.storybook/vitest.setup.ts +13 -0
- package/README.md +13 -0
- package/docs/architecture-decisions/adr-0001-consumer-component-apis.md +177 -0
- package/docs/architecture-decisions/adr-0002-compound-component-extraction.md +82 -0
- package/package.json +64 -0
- package/src/components/accordion/accordion-context.tsx +17 -0
- package/src/components/accordion/accordion.mdx +172 -0
- package/src/components/accordion/accordion.recipe.tsx +98 -0
- package/src/components/accordion/accordion.slots.tsx +39 -0
- package/src/components/accordion/accordion.stories.tsx +188 -0
- package/src/components/accordion/accordion.tsx +16 -0
- package/src/components/accordion/accordion.types.tsx +54 -0
- package/src/components/accordion/components/accordion-content.tsx +28 -0
- package/src/components/accordion/components/accordion-group.tsx +27 -0
- package/src/components/accordion/components/accordion-header.tsx +63 -0
- package/src/components/accordion/components/accordion-item.tsx +87 -0
- package/src/components/accordion/index.ts +2 -0
- package/src/components/alert/alert.mdx +92 -0
- package/src/components/alert/alert.recipe.tsx +65 -0
- package/src/components/alert/alert.slots.tsx +46 -0
- package/src/components/alert/alert.stories.tsx +308 -0
- package/src/components/alert/alert.tsx +18 -0
- package/src/components/alert/alert.types.tsx +70 -0
- package/src/components/alert/components/alert.actions.tsx +27 -0
- package/src/components/alert/components/alert.description.tsx +27 -0
- package/src/components/alert/components/alert.dismiss-button.tsx +41 -0
- package/src/components/alert/components/alert.root.tsx +92 -0
- package/src/components/alert/components/alert.title.tsx +29 -0
- package/src/components/alert/index.ts +2 -0
- package/src/components/avatar/avatar.mdx +80 -0
- package/src/components/avatar/avatar.recipe.tsx +36 -0
- package/src/components/avatar/avatar.slots.tsx +16 -0
- package/src/components/avatar/avatar.stories.tsx +136 -0
- package/src/components/avatar/avatar.tsx +34 -0
- package/src/components/avatar/avatar.types.ts +33 -0
- package/src/components/avatar/index.ts +2 -0
- package/src/components/badge/badge.mdx +91 -0
- package/src/components/badge/badge.recipe.tsx +72 -0
- package/src/components/badge/badge.slots.tsx +8 -0
- package/src/components/badge/badge.stories.tsx +124 -0
- package/src/components/badge/badge.tsx +35 -0
- package/src/components/badge/badge.types.tsx +40 -0
- package/src/components/badge/index.ts +2 -0
- package/src/components/bleed/bleed.tsx +1 -0
- package/src/components/bleed/index.ts +1 -0
- package/src/components/box/box.mdx +115 -0
- package/src/components/box/box.stories.tsx +71 -0
- package/src/components/box/box.tsx +11 -0
- package/src/components/box/index.ts +1 -0
- package/src/components/button/button.mdx +169 -0
- package/src/components/button/button.recipe.ts +185 -0
- package/src/components/button/button.slots.tsx +45 -0
- package/src/components/button/button.stories.tsx +369 -0
- package/src/components/button/button.tsx +37 -0
- package/src/components/button/button.types.ts +14 -0
- package/src/components/button/index.ts +2 -0
- package/src/components/card/card.mdx +92 -0
- package/src/components/card/card.recipe.tsx +71 -0
- package/src/components/card/card.slots.tsx +50 -0
- package/src/components/card/card.stories.tsx +175 -0
- package/src/components/card/card.tsx +9 -0
- package/src/components/card/card.types.ts +22 -0
- package/src/components/card/components/card.content.tsx +29 -0
- package/src/components/card/components/card.header.tsx +28 -0
- package/src/components/card/components/card.root.tsx +62 -0
- package/src/components/card/index.ts +2 -0
- package/src/components/checkbox/checkbox.mdx +78 -0
- package/src/components/checkbox/checkbox.recipe.tsx +116 -0
- package/src/components/checkbox/checkbox.slots.tsx +33 -0
- package/src/components/checkbox/checkbox.stories.tsx +200 -0
- package/src/components/checkbox/checkbox.tsx +77 -0
- package/src/components/checkbox/checkbox.types.tsx +22 -0
- package/src/components/checkbox/index.ts +2 -0
- package/src/components/code/code.mdx +17 -0
- package/src/components/code/code.recipe.ts +63 -0
- package/src/components/code/code.tsx +1 -0
- package/src/components/code/index.ts +1 -0
- package/src/components/dialog/dialog.mdx +20 -0
- package/src/components/dialog/dialog.recipe.ts +254 -0
- package/src/components/dialog/dialog.tsx +61 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/em/em.mdx +17 -0
- package/src/components/em/em.tsx +1 -0
- package/src/components/em/index.ts +1 -0
- package/src/components/flex/flex.mdx +41 -0
- package/src/components/flex/flex.tsx +1 -0
- package/src/components/flex/index.ts +1 -0
- package/src/components/grid/grid.mdx +156 -0
- package/src/components/grid/grid.stories.tsx +151 -0
- package/src/components/grid/grid.tsx +29 -0
- package/src/components/grid/index.ts +1 -0
- package/src/components/heading/heading.mdx +23 -0
- package/src/components/heading/heading.recipe.ts +49 -0
- package/src/components/heading/heading.tsx +1 -0
- package/src/components/heading/index.ts +1 -0
- package/src/components/highlight/highlight.mdx +18 -0
- package/src/components/highlight/highlight.tsx +1 -0
- package/src/components/highlight/index.ts +1 -0
- package/src/components/icon-button/icon-button.mdx +98 -0
- package/src/components/icon-button/icon-button.stories.tsx +188 -0
- package/src/components/icon-button/icon-button.tsx +21 -0
- package/src/components/icon-button/icon-button.types.tsx +10 -0
- package/src/components/icon-button/index.ts +2 -0
- package/src/components/index.ts +33 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input/input.mdx +20 -0
- package/src/components/input/input.recipe.ts +95 -0
- package/src/components/input/input.tsx +1 -0
- package/src/components/input-group/index.ts +1 -0
- package/src/components/input-group/input-group.mdx +20 -0
- package/src/components/input-group/input-group.tsx +44 -0
- package/src/components/kbd/index.ts +1 -0
- package/src/components/kbd/kbd.mdx +18 -0
- package/src/components/kbd/kbd.recipe.ts +57 -0
- package/src/components/kbd/kbd.tsx +1 -0
- package/src/components/link/index.ts +2 -0
- package/src/components/link/link.mdx +77 -0
- package/src/components/link/link.recipe.ts +52 -0
- package/src/components/link/link.slots.tsx +29 -0
- package/src/components/link/link.stories.tsx +204 -0
- package/src/components/link/link.tsx +38 -0
- package/src/components/link/link.types.tsx +26 -0
- package/src/components/list/index.ts +1 -0
- package/src/components/list/list.mdx +18 -0
- package/src/components/list/list.recipe.ts +68 -0
- package/src/components/list/list.tsx +9 -0
- package/src/components/loading-spinner/index.ts +2 -0
- package/src/components/loading-spinner/loading-spinner.mdx +92 -0
- package/src/components/loading-spinner/loading-spinner.recipe.tsx +70 -0
- package/src/components/loading-spinner/loading-spinner.slots.tsx +38 -0
- package/src/components/loading-spinner/loading-spinner.stories.tsx +97 -0
- package/src/components/loading-spinner/loading-spinner.tsx +50 -0
- package/src/components/loading-spinner/loading-spinner.types.tsx +21 -0
- package/src/components/nimbus-provider/color-mode.tsx +32 -0
- package/src/components/nimbus-provider/index.ts +2 -0
- package/src/components/nimbus-provider/nimbus-provider.mdx +21 -0
- package/src/components/nimbus-provider/nimbus-provider.tsx +51 -0
- package/src/components/select/components/select.clear-button.tsx +31 -0
- package/src/components/select/components/select.option-group.tsx +48 -0
- package/src/components/select/components/select.option.tsx +21 -0
- package/src/components/select/components/select.options.tsx +23 -0
- package/src/components/select/components/select.root.tsx +81 -0
- package/src/components/select/index.ts +2 -0
- package/src/components/select/select.mdx +170 -0
- package/src/components/select/select.recipe.tsx +216 -0
- package/src/components/select/select.slots.tsx +58 -0
- package/src/components/select/select.stories.tsx +841 -0
- package/src/components/select/select.tsx +18 -0
- package/src/components/select/select.types.tsx +37 -0
- package/src/components/simple-grid/index.ts +1 -0
- package/src/components/simple-grid/simple-grid.mdx +133 -0
- package/src/components/simple-grid/simple-grid.stories.tsx +143 -0
- package/src/components/simple-grid/simple-grid.tsx +31 -0
- package/src/components/stack/index.ts +1 -0
- package/src/components/stack/stack.mdx +88 -0
- package/src/components/stack/stack.stories.tsx +82 -0
- package/src/components/stack/stack.tsx +15 -0
- package/src/components/table/index.ts +1 -0
- package/src/components/table/table.mdx +23 -0
- package/src/components/table/table.recipe.ts +170 -0
- package/src/components/table/table.tsx +43 -0
- package/src/components/text/index.ts +1 -0
- package/src/components/text/text.mdx +244 -0
- package/src/components/text/text.tsx +23 -0
- package/src/components/text-input/index.ts +2 -0
- package/src/components/text-input/text-input.mdx +118 -0
- package/src/components/text-input/text-input.recipe.tsx +68 -0
- package/src/components/text-input/text-input.slots.tsx +24 -0
- package/src/components/text-input/text-input.stories.tsx +282 -0
- package/src/components/text-input/text-input.tsx +39 -0
- package/src/components/text-input/text-input.types.ts +7 -0
- package/src/components/toggle-button-group/components/toggle-button-group.button.tsx +14 -0
- package/src/components/toggle-button-group/components/toggle-button-group.root.tsx +15 -0
- package/src/components/toggle-button-group/index.ts +2 -0
- package/src/components/toggle-button-group/toggle-button-group.mdx +94 -0
- package/src/components/toggle-button-group/toggle-button-group.recipe.tsx +64 -0
- package/src/components/toggle-button-group/toggle-button-group.slots.tsx +26 -0
- package/src/components/toggle-button-group/toggle-button-group.stories.tsx +311 -0
- package/src/components/toggle-button-group/toggle-button-group.tsx +12 -0
- package/src/components/toggle-button-group/toggle-button-group.types.tsx +62 -0
- package/src/components/tooltip/index.ts +4 -0
- package/src/components/tooltip/make-element-focusable.stories.tsx +56 -0
- package/src/components/tooltip/make-element-focusable.tsx +57 -0
- package/src/components/tooltip/tooltip-trigger.stories.tsx +157 -0
- package/src/components/tooltip/tooltip-trigger.tsx +15 -0
- package/src/components/tooltip/tooltip.mdx +48 -0
- package/src/components/tooltip/tooltip.recipe.ts +26 -0
- package/src/components/tooltip/tooltip.slots.ts +35 -0
- package/src/components/tooltip/tooltip.stories.tsx +139 -0
- package/src/components/tooltip/tooltip.tsx +31 -0
- package/src/components/tooltip/tooltip.types.ts +44 -0
- package/src/components/visually-hidden/index.ts +1 -0
- package/src/components/visually-hidden/visually-hidden.mdx +61 -0
- package/src/components/visually-hidden/visually-hidden.stories.tsx +124 -0
- package/src/components/visually-hidden/visually-hidden.tsx +18 -0
- package/src/docs/accessibility.mdx +21 -0
- package/src/docs/background.mdx +154 -0
- package/src/docs/border.mdx +226 -0
- package/src/docs/changelog.mdx +17 -0
- package/src/docs/components-layout.mdx +22 -0
- package/src/docs/components.mdx +17 -0
- package/src/docs/data-display.mdx +23 -0
- package/src/docs/display.mdx +55 -0
- package/src/docs/effects.mdx +73 -0
- package/src/docs/feedback.mdx +22 -0
- package/src/docs/filters.mdx +268 -0
- package/src/docs/flex-and-grid.mdx +445 -0
- package/src/docs/forms.mdx +22 -0
- package/src/docs/generated/index.mdx +16 -0
- package/src/docs/getting-started.mdx +17 -0
- package/src/docs/home.mdx +56 -0
- package/src/docs/hooks.mdx +16 -0
- package/src/docs/inputs.mdx +21 -0
- package/src/docs/installation.mdx +60 -0
- package/src/docs/interactivity.mdx +278 -0
- package/src/docs/known-issues.mdx +19 -0
- package/src/docs/layout.mdx +301 -0
- package/src/docs/list.mdx +82 -0
- package/src/docs/markdown.mdx +234 -0
- package/src/docs/media.mdx +22 -0
- package/src/docs/naivgation.mdx +22 -0
- package/src/docs/playground.mdx +16 -0
- package/src/docs/rfcs-component-structure-rfcs.mdx +17 -0
- package/src/docs/rfcs-component-structure.mdx +74 -0
- package/src/docs/rfcs-hook-structure.mdx +59 -0
- package/src/docs/sizing.mdx +210 -0
- package/src/docs/spacing.mdx +193 -0
- package/src/docs/style-props-typography.mdx +373 -0
- package/src/docs/style-props.mdx +15 -0
- package/src/docs/svg.mdx +58 -0
- package/src/docs/tables.mdx +95 -0
- package/src/docs/toc.mdx +39 -0
- package/src/docs/tokens/animations.mdx +68 -0
- package/src/docs/tokens/aspect-ratios.mdx +21 -0
- package/src/docs/tokens/blurs.mdx +20 -0
- package/src/docs/tokens/borders.mdx +25 -0
- package/src/docs/tokens/breakpoints.mdx +35 -0
- package/src/docs/tokens/colors.mdx +86 -0
- package/src/docs/tokens/cursors.mdx +21 -0
- package/src/docs/tokens/radii.mdx +23 -0
- package/src/docs/tokens/shadows.mdx +21 -0
- package/src/docs/tokens/sizes.mdx +54 -0
- package/src/docs/tokens/spacing.mdx +35 -0
- package/src/docs/tokens/typography.mdx +61 -0
- package/src/docs/tokens/z-indices.mdx +23 -0
- package/src/docs/tokens-other.mdx +17 -0
- package/src/docs/tokens.mdx +16 -0
- package/src/docs/transforms.mdx +150 -0
- package/src/docs/transitions.mdx +164 -0
- package/src/docs/typography.mdx +17 -0
- package/src/docs/utilities.mdx +17 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use-copy-to-clipboard/use-copy-to-clipboard.mdx +54 -0
- package/src/hooks/use-copy-to-clipboard/use-copy-to-clipboard.ts +1 -0
- package/src/hooks/use-hotkeys/use-hotkeys.mdx +48 -0
- package/src/hooks/use-hotkeys/use-hotkeys.stories.tsx +69 -0
- package/src/hooks/use-hotkeys/use-hotkeys.ts +1 -0
- package/src/index.ts +3 -0
- package/src/test/utils.tsx +20 -0
- package/src/theme/animation-styles.ts +52 -0
- package/src/theme/breakpoints.ts +32 -0
- package/src/theme/global-css.ts +53 -0
- package/src/theme/index.ts +35 -0
- package/src/theme/keyframes.ts +192 -0
- package/src/theme/layer-styles.ts +12 -0
- package/src/theme/recipes/index.ts +21 -0
- package/src/theme/semantic-tokens/colors.ts +55 -0
- package/src/theme/semantic-tokens/index.ts +9 -0
- package/src/theme/semantic-tokens/radii.ts +3 -0
- package/src/theme/semantic-tokens/shadows.ts +4 -0
- package/src/theme/slot-recipes/index.ts +15 -0
- package/src/theme/text-styles.ts +8 -0
- package/src/theme/tokens/animations.ts +4 -0
- package/src/theme/tokens/aspect-ratios.ts +5 -0
- package/src/theme/tokens/blurs.ts +5 -0
- package/src/theme/tokens/borders.ts +4 -0
- package/src/theme/tokens/colors.ts +8 -0
- package/src/theme/tokens/cursor.ts +4 -0
- package/src/theme/tokens/durations.ts +4 -0
- package/src/theme/tokens/easings.ts +4 -0
- package/src/theme/tokens/font-sizes.ts +4 -0
- package/src/theme/tokens/font-weights.ts +4 -0
- package/src/theme/tokens/fonts.ts +4 -0
- package/src/theme/tokens/index.ts +57 -0
- package/src/theme/tokens/letter-spacings.ts +24 -0
- package/src/theme/tokens/line-heights.ts +4 -0
- package/src/theme/tokens/radii.ts +4 -0
- package/src/theme/tokens/sizes.ts +120 -0
- package/src/theme/tokens/spacing.ts +4 -0
- package/src/theme/tokens/z-index.ts +4 -0
- package/src/utils/extractStyleProps.ts +26 -0
- package/src/utils/fixedForwardRef.ts +17 -0
- package/tsconfig.json +38 -0
- package/vite.config.ts +54 -0
- package/vitest.config.ts +50 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Components-Accordion
|
|
3
|
+
title: Accordion
|
|
4
|
+
description:
|
|
5
|
+
A component used for organizing contents. This allows users to toggle
|
|
6
|
+
visibility of the content sections in their individual panels when the
|
|
7
|
+
panel's header is clicked.
|
|
8
|
+
documentState: InitialDraft
|
|
9
|
+
order: 999
|
|
10
|
+
menu:
|
|
11
|
+
- Components
|
|
12
|
+
- Accordion
|
|
13
|
+
tags:
|
|
14
|
+
- component
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Accordion
|
|
18
|
+
|
|
19
|
+
A component used for organizing contents. This allows users to toggle visibility
|
|
20
|
+
of the content sections in their individual panels when the panel's header is
|
|
21
|
+
clicked.
|
|
22
|
+
|
|
23
|
+
## Basic Usage
|
|
24
|
+
|
|
25
|
+
```jsx-live
|
|
26
|
+
const App = () => (
|
|
27
|
+
<Accordion>
|
|
28
|
+
<Accordion.Header>Test Accordion</Accordion.Header>
|
|
29
|
+
<Accordion.Content>Test Accordion Content</Accordion.Content>
|
|
30
|
+
</Accordion>
|
|
31
|
+
)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Sizes
|
|
35
|
+
|
|
36
|
+
Accordion come in different sizes, sizing an accordion is done by setting the
|
|
37
|
+
`size` prop.
|
|
38
|
+
|
|
39
|
+
```jsx-live
|
|
40
|
+
const App = () => {
|
|
41
|
+
|
|
42
|
+
const accordionSizes = ["sm", "md"];;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<>
|
|
46
|
+
{accordionSizes.map((size, index) => (
|
|
47
|
+
<Accordion key={index} size={size}>
|
|
48
|
+
<Accordion.Header>{<>{size} size</>}</Accordion.Header>
|
|
49
|
+
<Accordion.Content>
|
|
50
|
+
<>{size} size text</>
|
|
51
|
+
</Accordion.Content>
|
|
52
|
+
</Accordion>
|
|
53
|
+
))}
|
|
54
|
+
</>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### With Additional Contents On The Accordion Trigger
|
|
60
|
+
|
|
61
|
+
The accordion can take in more properties at the trigger button level to allow
|
|
62
|
+
you add more features or actions on the trigger interface. You can add any
|
|
63
|
+
component or additional text of choice; Texts, buttons, toggle botton etc. Do
|
|
64
|
+
this by setting the `additionalTriggerComponent` prop.
|
|
65
|
+
|
|
66
|
+
```jsx-live
|
|
67
|
+
const App = () => {
|
|
68
|
+
const items = [
|
|
69
|
+
{ value: "a", title: "First Item", text: "Some value 1..." },
|
|
70
|
+
{ value: "b", title: "Second Item", text: "Some value 2..." },
|
|
71
|
+
{
|
|
72
|
+
value: "c",
|
|
73
|
+
title: "Third Item",
|
|
74
|
+
text: "Some value 3",
|
|
75
|
+
},
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
{items.map((item, index) => (
|
|
81
|
+
<Accordion key={index} size={"md"}>
|
|
82
|
+
<Accordion.Header
|
|
83
|
+
additionalTriggerComponent={
|
|
84
|
+
<div style={{ padding: "10px" }}>
|
|
85
|
+
<Button marginRight="100" tone="primary">
|
|
86
|
+
Click me
|
|
87
|
+
</Button>
|
|
88
|
+
<Button marginRight="100" tone="neutral">
|
|
89
|
+
Click me
|
|
90
|
+
</Button>
|
|
91
|
+
<Button marginRight="100" tone="critical">
|
|
92
|
+
Click me
|
|
93
|
+
</Button>
|
|
94
|
+
</div>
|
|
95
|
+
}
|
|
96
|
+
>
|
|
97
|
+
{item.title}
|
|
98
|
+
</Accordion.Header>
|
|
99
|
+
<Accordion.Content>
|
|
100
|
+
<Flex
|
|
101
|
+
justifyContent="space-between"
|
|
102
|
+
alignItems={"center"}
|
|
103
|
+
borderColor="neutral.4"
|
|
104
|
+
>
|
|
105
|
+
<div style={{ marginRight: "100" }}>{item.text}</div>
|
|
106
|
+
</Flex>
|
|
107
|
+
</Accordion.Content>
|
|
108
|
+
</Accordion>
|
|
109
|
+
))}
|
|
110
|
+
</>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### With A Custom Component In The Accordion Content
|
|
116
|
+
|
|
117
|
+
To render any component of choice, pass in the custom component as the child of
|
|
118
|
+
the accordion.
|
|
119
|
+
|
|
120
|
+
```jsx-live
|
|
121
|
+
const App = () => {
|
|
122
|
+
const items = [
|
|
123
|
+
{ value: "a", title: "First Item", text: "Some value 1..." },
|
|
124
|
+
{ value: "b", title: "Second Item", text: "Some value 2..." },
|
|
125
|
+
{
|
|
126
|
+
value: "c",
|
|
127
|
+
title: "Third Item",
|
|
128
|
+
text: "Some value 3",
|
|
129
|
+
},
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
const AccordionContent = () => {
|
|
133
|
+
const avatarImg = "https://thispersondoesnotexist.com/ ";
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<div style={{ display: "flex", alignItems: "center", padding: "10px" }}>
|
|
137
|
+
<Avatar src={avatarImg} firstName="Michael" lastName="Douglas" />
|
|
138
|
+
<Checkbox>Yes?</Checkbox>
|
|
139
|
+
<Checkbox>No?</Checkbox>
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<>
|
|
146
|
+
{items.map((item, index) => (
|
|
147
|
+
<Accordion key={index} size={"md"}>
|
|
148
|
+
<Accordion.Header
|
|
149
|
+
>
|
|
150
|
+
{item.title}
|
|
151
|
+
</Accordion.Header>
|
|
152
|
+
<Accordion.Content>
|
|
153
|
+
<Flex
|
|
154
|
+
justifyContent="space-between"
|
|
155
|
+
alignItems={"center"}
|
|
156
|
+
borderColor="neutral.4"
|
|
157
|
+
>
|
|
158
|
+
<div style={{ marginRight: "100" }}>{item.text}</div>
|
|
159
|
+
<AccordionContent />
|
|
160
|
+
</Flex>
|
|
161
|
+
</Accordion.Content>
|
|
162
|
+
</Accordion>
|
|
163
|
+
))}
|
|
164
|
+
</>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Props
|
|
171
|
+
|
|
172
|
+
<PropTable id="Accordion" />
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { defineSlotRecipe } from "@chakra-ui/react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Recipe configuration for the Accordion component.
|
|
5
|
+
* Defines the styling variants and base styles using Chakra UI's recipe system.
|
|
6
|
+
*/
|
|
7
|
+
export const accordionSlotRecipe = defineSlotRecipe({
|
|
8
|
+
slots: [
|
|
9
|
+
"root",
|
|
10
|
+
"disclosure",
|
|
11
|
+
"trigger",
|
|
12
|
+
"panel",
|
|
13
|
+
"accordionTitle",
|
|
14
|
+
"headerContentRight",
|
|
15
|
+
],
|
|
16
|
+
// Unique class name prefix for the component
|
|
17
|
+
className: "nimbus-accordion",
|
|
18
|
+
|
|
19
|
+
base: {
|
|
20
|
+
root: {
|
|
21
|
+
width: "100%",
|
|
22
|
+
},
|
|
23
|
+
disclosure: {
|
|
24
|
+
width: "100%",
|
|
25
|
+
},
|
|
26
|
+
trigger: {
|
|
27
|
+
fontSize: "var(--font-size)",
|
|
28
|
+
focusVisibleRing: "outside",
|
|
29
|
+
minHeight: "1200",
|
|
30
|
+
bg: "none",
|
|
31
|
+
flexGrow: 1,
|
|
32
|
+
display: "flex",
|
|
33
|
+
alignItems: "center",
|
|
34
|
+
gap: "8px",
|
|
35
|
+
width: "auto",
|
|
36
|
+
"& svg": {
|
|
37
|
+
width: "var(--width)",
|
|
38
|
+
height: "var(--height)",
|
|
39
|
+
rotate: "0deg",
|
|
40
|
+
transition: "rotate 200ms",
|
|
41
|
+
},
|
|
42
|
+
'&[aria-expanded="true"] svg': {
|
|
43
|
+
rotate: "90deg",
|
|
44
|
+
},
|
|
45
|
+
"&[disabled]": {
|
|
46
|
+
layerStyle: "disabled",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
panel: {
|
|
50
|
+
paddingTop: "var(--padding-top)",
|
|
51
|
+
paddingBottom: "var(--padding-bottom)",
|
|
52
|
+
paddingLeft: "var(--padding-left)",
|
|
53
|
+
'&[aria-hidden="true"]': {
|
|
54
|
+
display: "none",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
accordionTitle: {
|
|
58
|
+
fontWeight: "700",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
variants: {
|
|
63
|
+
size: {
|
|
64
|
+
md: {
|
|
65
|
+
trigger: {
|
|
66
|
+
"--font-size": "fontSizes.500",
|
|
67
|
+
"& svg": {
|
|
68
|
+
"--width": "sizes.600",
|
|
69
|
+
"--height": "sizes.600",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
panel: {
|
|
73
|
+
"--padding-top": "spacing.600",
|
|
74
|
+
"--padding-bottom": "spacing.800",
|
|
75
|
+
"--padding-left": "spacing.800",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
sm: {
|
|
79
|
+
trigger: {
|
|
80
|
+
"--font-size": "fontSizes.400",
|
|
81
|
+
"& svg": {
|
|
82
|
+
"--width": "sizes.500",
|
|
83
|
+
"--height": "sizes.500",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
panel: {
|
|
87
|
+
"--padding-top": "spacing.400",
|
|
88
|
+
"--padding-bottom": "spacing.600",
|
|
89
|
+
"--padding-left": "spacing.700",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
defaultVariants: {
|
|
96
|
+
size: "md",
|
|
97
|
+
},
|
|
98
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSlotRecipeContext,
|
|
3
|
+
type HTMLChakraProps,
|
|
4
|
+
} from "@chakra-ui/react";
|
|
5
|
+
import type { AccordionRootProps } from "./accordion.types";
|
|
6
|
+
|
|
7
|
+
const { withProvider, withContext } = createSlotRecipeContext({
|
|
8
|
+
key: "accordion",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const AccordionRoot = withProvider<HTMLDivElement, AccordionRootProps>(
|
|
12
|
+
"div",
|
|
13
|
+
"root"
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const AccordionDisclosure = withContext<
|
|
17
|
+
HTMLDivElement,
|
|
18
|
+
HTMLChakraProps<"div">
|
|
19
|
+
>("div", "disclosure");
|
|
20
|
+
|
|
21
|
+
export const AccordionTrigger = withContext<
|
|
22
|
+
HTMLButtonElement,
|
|
23
|
+
HTMLChakraProps<"button">
|
|
24
|
+
>("button", "trigger");
|
|
25
|
+
|
|
26
|
+
export const AccordionPanel = withContext<
|
|
27
|
+
HTMLDivElement,
|
|
28
|
+
HTMLChakraProps<"div">
|
|
29
|
+
>("div", "panel");
|
|
30
|
+
|
|
31
|
+
export const AccordionTitle = withContext<
|
|
32
|
+
HTMLButtonElement,
|
|
33
|
+
HTMLChakraProps<"div">
|
|
34
|
+
>("div", "accordionTitle");
|
|
35
|
+
|
|
36
|
+
export const HeaderRightContent = withContext<
|
|
37
|
+
HTMLDivElement,
|
|
38
|
+
HTMLChakraProps<"div">
|
|
39
|
+
>("div", "headerContentRight");
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import Accordion from "./accordion";
|
|
3
|
+
import type { AccordionProps } from "./accordion.types";
|
|
4
|
+
import { Avatar, Button, Checkbox, Flex } from "@/components";
|
|
5
|
+
import { expect, userEvent, waitFor } from "@storybook/test";
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Accordion.Root> = {
|
|
8
|
+
title: "components/Accordion",
|
|
9
|
+
component: Accordion.Root,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
|
|
14
|
+
type Story = StoryObj<typeof Accordion.Root>;
|
|
15
|
+
|
|
16
|
+
const items = [
|
|
17
|
+
{ value: "a", title: "First Item", text: "Some value 1..." },
|
|
18
|
+
{ value: "b", title: "Second Item", text: "Some value 2..." },
|
|
19
|
+
{ value: "c", title: "Third Item", text: "Some value 3..." },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const sizes: AccordionProps["size"][] = ["sm", "md"];
|
|
23
|
+
|
|
24
|
+
export const Basic: Story = {
|
|
25
|
+
render: () => (
|
|
26
|
+
<Accordion.Root>
|
|
27
|
+
<Accordion.Item>
|
|
28
|
+
<Accordion.Header>First Item</Accordion.Header>
|
|
29
|
+
<Accordion.Content>First item content</Accordion.Content>
|
|
30
|
+
</Accordion.Item>
|
|
31
|
+
</Accordion.Root>
|
|
32
|
+
),
|
|
33
|
+
play: async ({ canvasElement, step }) => {
|
|
34
|
+
const accordion = canvasElement.querySelector(
|
|
35
|
+
'[data-slot="root"]'
|
|
36
|
+
) as HTMLElement;
|
|
37
|
+
|
|
38
|
+
const trigger = accordion.querySelector(
|
|
39
|
+
'[data-slot="trigger"]'
|
|
40
|
+
) as HTMLButtonElement;
|
|
41
|
+
|
|
42
|
+
const panel = accordion.querySelector(
|
|
43
|
+
'[data-slot="panel"]'
|
|
44
|
+
) as HTMLDivElement;
|
|
45
|
+
|
|
46
|
+
await step("Can be focused with keyboard", async () => {
|
|
47
|
+
await userEvent.tab();
|
|
48
|
+
await waitFor(() => expect(trigger).toHaveFocus());
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await step("Panel is initially hidden", async () => {
|
|
52
|
+
await expect(panel).not.toBeVisible();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await step("Can be triggered with Enter key", async () => {
|
|
56
|
+
await userEvent.keyboard("{Enter}");
|
|
57
|
+
await expect(panel).toBeVisible();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
await step("Can be triggered with Space key", async () => {
|
|
61
|
+
await userEvent.keyboard(" ");
|
|
62
|
+
await expect(panel).not.toBeVisible();
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const WithHeaderItemsToRight: Story = {
|
|
68
|
+
render: () => (
|
|
69
|
+
<Accordion.Root>
|
|
70
|
+
<Accordion.Item value="a">
|
|
71
|
+
<Accordion.Header>First Item</Accordion.Header>
|
|
72
|
+
<Accordion.Content>First item content</Accordion.Content>
|
|
73
|
+
</Accordion.Item>
|
|
74
|
+
<Accordion.Item value="b">
|
|
75
|
+
<Accordion.Header>
|
|
76
|
+
Second Item
|
|
77
|
+
<Accordion.HeaderRightContent>
|
|
78
|
+
<Button tone="critical" m="100">
|
|
79
|
+
First action
|
|
80
|
+
</Button>
|
|
81
|
+
<Button tone="neutral" m="100">
|
|
82
|
+
Second Action
|
|
83
|
+
</Button>
|
|
84
|
+
</Accordion.HeaderRightContent>
|
|
85
|
+
</Accordion.Header>
|
|
86
|
+
<Accordion.Content>Second item content</Accordion.Content>
|
|
87
|
+
</Accordion.Item>
|
|
88
|
+
</Accordion.Root>
|
|
89
|
+
),
|
|
90
|
+
play: async ({ canvasElement, step }) => {
|
|
91
|
+
const accordion = canvasElement.querySelector(
|
|
92
|
+
'[data-slot="root"]'
|
|
93
|
+
) as HTMLElement;
|
|
94
|
+
const additionalButtons = accordion.querySelectorAll("button");
|
|
95
|
+
const trigger = accordion.querySelector(
|
|
96
|
+
'[data-slot="trigger"]'
|
|
97
|
+
) as HTMLButtonElement;
|
|
98
|
+
|
|
99
|
+
await step("Additional buttons don't trigger accordion", async () => {
|
|
100
|
+
const panel = accordion.querySelector(
|
|
101
|
+
'[data-slot="panel"]'
|
|
102
|
+
) as HTMLDivElement;
|
|
103
|
+
await expect(panel).not.toBeVisible();
|
|
104
|
+
|
|
105
|
+
// Click additional buttons
|
|
106
|
+
for (const button of Array.from(additionalButtons)) {
|
|
107
|
+
if (button !== trigger) {
|
|
108
|
+
await userEvent.click(button);
|
|
109
|
+
await expect(panel).not.toBeVisible();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
await step("Main trigger still works", async () => {
|
|
115
|
+
const panel = accordion.querySelector(
|
|
116
|
+
'[data-slot="panel"]'
|
|
117
|
+
) as HTMLDivElement;
|
|
118
|
+
await userEvent.click(trigger);
|
|
119
|
+
await expect(panel).toBeVisible();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
await step("Main trigger still works", async () => {
|
|
123
|
+
await userEvent.click(trigger);
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const AccordionContent = () => {
|
|
129
|
+
const avatarImg = "https://thispersondoesnotexist.com/ ";
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<div style={{ display: "flex", alignItems: "center", padding: "10px" }}>
|
|
133
|
+
<Avatar src={avatarImg} firstName="Michael" lastName="Douglas" />
|
|
134
|
+
<Checkbox marginLeft="100">Yes?</Checkbox>
|
|
135
|
+
<Checkbox marginLeft="100">No?</Checkbox>
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const Sizes: Story = {
|
|
141
|
+
render: () => (
|
|
142
|
+
<>
|
|
143
|
+
{sizes.map((size, index) => (
|
|
144
|
+
<Accordion.Root key={index} size={size}>
|
|
145
|
+
<Accordion.Item value={size}>
|
|
146
|
+
<Accordion.Header>{size} size</Accordion.Header>
|
|
147
|
+
<Accordion.Content>
|
|
148
|
+
<Flex
|
|
149
|
+
justifyContent="space-between"
|
|
150
|
+
alignItems={"center"}
|
|
151
|
+
borderColor="neutral.4"
|
|
152
|
+
>
|
|
153
|
+
<div style={{ marginRight: "100" }}>{size} size</div>
|
|
154
|
+
<AccordionContent />
|
|
155
|
+
</Flex>
|
|
156
|
+
</Accordion.Content>
|
|
157
|
+
</Accordion.Item>
|
|
158
|
+
</Accordion.Root>
|
|
159
|
+
))}
|
|
160
|
+
</>
|
|
161
|
+
),
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const AllowMultiple: Story = {
|
|
165
|
+
render: () => (
|
|
166
|
+
<Accordion.Root allowsMultipleExpanded>
|
|
167
|
+
{items.map((item, index) => (
|
|
168
|
+
<Accordion.Item key={index} value={item.value}>
|
|
169
|
+
<Accordion.Header>{item.title}</Accordion.Header>
|
|
170
|
+
<Accordion.Content>{item.text}</Accordion.Content>
|
|
171
|
+
</Accordion.Item>
|
|
172
|
+
))}
|
|
173
|
+
</Accordion.Root>
|
|
174
|
+
),
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export const Disabled: Story = {
|
|
178
|
+
render: () => (
|
|
179
|
+
<Accordion.Root isDisabled>
|
|
180
|
+
{items.map((item, index) => (
|
|
181
|
+
<Accordion.Item key={index} value={item.value}>
|
|
182
|
+
<Accordion.Header>{item.title}</Accordion.Header>
|
|
183
|
+
<Accordion.Content>{item.text}</Accordion.Content>
|
|
184
|
+
</Accordion.Item>
|
|
185
|
+
))}
|
|
186
|
+
</Accordion.Root>
|
|
187
|
+
),
|
|
188
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HeaderRightContent } from "./accordion.slots";
|
|
2
|
+
import { AccordionGroup } from "./components/accordion-group";
|
|
3
|
+
import { AccordionHeader } from "./components/accordion-header";
|
|
4
|
+
import { AccordionContent } from "./components/accordion-content";
|
|
5
|
+
import { AccordionItem } from "./components/accordion-item";
|
|
6
|
+
|
|
7
|
+
// Create the Accordion namespace object as an object literal
|
|
8
|
+
const Accordion = {
|
|
9
|
+
Root: AccordionGroup,
|
|
10
|
+
Item: AccordionItem,
|
|
11
|
+
Header: AccordionHeader,
|
|
12
|
+
Content: AccordionContent,
|
|
13
|
+
HeaderRightContent,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default Accordion;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { RecipeVariantProps, HTMLChakraProps } from "@chakra-ui/react";
|
|
2
|
+
import { accordionSlotRecipe } from "./accordion.recipe";
|
|
3
|
+
import { type DisclosureProps } from "react-aria-components";
|
|
4
|
+
import type { ReactNode, RefObject, RefAttributes } from "react";
|
|
5
|
+
import { useButton, useDisclosure } from "react-aria";
|
|
6
|
+
import type { useDisclosureState } from "react-stately";
|
|
7
|
+
|
|
8
|
+
export type AccordionRootProps = HTMLChakraProps<
|
|
9
|
+
"div",
|
|
10
|
+
RecipeVariantProps<typeof accordionSlotRecipe>
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
export type AccordionComposition = {
|
|
14
|
+
state: ReturnType<typeof useDisclosureState>;
|
|
15
|
+
buttonProps: ReturnType<typeof useButton>["buttonProps"];
|
|
16
|
+
panelProps: ReturnType<typeof useDisclosure>["panelProps"];
|
|
17
|
+
triggerRef: RefObject<HTMLButtonElement>;
|
|
18
|
+
panelRef: RefObject<HTMLDivElement>;
|
|
19
|
+
isFocusVisible: boolean;
|
|
20
|
+
};
|
|
21
|
+
export interface AccordionProps
|
|
22
|
+
extends Omit<DisclosureProps, "children" | "id"> {
|
|
23
|
+
additionalTriggerComponent?: ReactNode;
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
recipe?: string;
|
|
26
|
+
size?: "sm" | "md";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type AccordionItemProps = {
|
|
30
|
+
isDisabled?: boolean;
|
|
31
|
+
isExpanded?: boolean;
|
|
32
|
+
onExpandedChange?: (isExpanded: boolean) => void;
|
|
33
|
+
id?: string;
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
title?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type DisclosureGroupProps = AccordionProps & {
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
ref?: RefAttributes<HTMLButtonElement>;
|
|
41
|
+
allowsMultipleExpanded?: boolean;
|
|
42
|
+
onExpandedChange?: (isExpanded: boolean) => void;
|
|
43
|
+
isDisabled?: boolean;
|
|
44
|
+
isExpanded?: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type DisclosureItemProps = AccordionItemProps & {
|
|
48
|
+
children: ReactNode;
|
|
49
|
+
id?: string;
|
|
50
|
+
value?: string;
|
|
51
|
+
isDisabled?: boolean;
|
|
52
|
+
isExpanded?: boolean;
|
|
53
|
+
onExpandedChange?: (isExpanded: boolean) => void;
|
|
54
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { forwardRef, useContext } from "react";
|
|
2
|
+
import { AccordionPanel } from "../accordion.slots";
|
|
3
|
+
import { useObjectRef } from "react-aria";
|
|
4
|
+
import { mergeProps, mergeRefs } from "@chakra-ui/react";
|
|
5
|
+
import type { DisclosureGroupProps } from "../accordion.types";
|
|
6
|
+
import { ItemContext } from "../accordion-context";
|
|
7
|
+
|
|
8
|
+
// Create Content component
|
|
9
|
+
export const AccordionContent = forwardRef<
|
|
10
|
+
HTMLDivElement,
|
|
11
|
+
DisclosureGroupProps
|
|
12
|
+
>((props, forwardedRef) => {
|
|
13
|
+
const context = useContext(ItemContext);
|
|
14
|
+
const ref = useObjectRef<HTMLDivElement>(
|
|
15
|
+
mergeRefs(context?.panelRef, forwardedRef)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
// @ts-expect-error TODO - fix prop types merging conflict
|
|
20
|
+
<AccordionPanel
|
|
21
|
+
ref={ref}
|
|
22
|
+
{...mergeProps({ ...context?.panelProps, ...props })}
|
|
23
|
+
data-slot="panel"
|
|
24
|
+
>
|
|
25
|
+
{props.children}
|
|
26
|
+
</AccordionPanel>
|
|
27
|
+
);
|
|
28
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { forwardRef, type Key } from "react";
|
|
2
|
+
import { AccordionRoot as AccordionRootSlot } from "../accordion.slots";
|
|
3
|
+
import { useDisclosureGroupState } from "react-stately";
|
|
4
|
+
import { useSlotRecipe } from "@chakra-ui/react";
|
|
5
|
+
import type { DisclosureGroupProps } from "../accordion.types";
|
|
6
|
+
import { DisclosureGroupStateContext } from "../accordion-context";
|
|
7
|
+
|
|
8
|
+
export const AccordionGroup = forwardRef<HTMLDivElement, DisclosureGroupProps>(
|
|
9
|
+
({ children, onExpandedChange, ...props }, forwardedRef) => {
|
|
10
|
+
const state = useDisclosureGroupState({
|
|
11
|
+
...props,
|
|
12
|
+
onExpandedChange: (keys: Set<Key>) => {
|
|
13
|
+
onExpandedChange?.(keys.size > 0);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const recipe = useSlotRecipe({ key: "accordion" });
|
|
17
|
+
const [recipeProps] = recipe.splitVariantProps(props);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<DisclosureGroupStateContext.Provider value={state}>
|
|
21
|
+
<AccordionRootSlot data-slot="root" ref={forwardedRef} {...recipeProps}>
|
|
22
|
+
{children}
|
|
23
|
+
</AccordionRootSlot>
|
|
24
|
+
</DisclosureGroupStateContext.Provider>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { forwardRef, useContext } from "react";
|
|
2
|
+
import {
|
|
3
|
+
AccordionTrigger,
|
|
4
|
+
AccordionTitle,
|
|
5
|
+
HeaderRightContent,
|
|
6
|
+
} from "../accordion.slots";
|
|
7
|
+
import { mergeRefs } from "@chakra-ui/react";
|
|
8
|
+
import { Flex } from "@/components";
|
|
9
|
+
import { KeyboardArrowRight } from "@commercetools/nimbus-icons";
|
|
10
|
+
import type { DisclosureGroupProps } from "../accordion.types";
|
|
11
|
+
import { ItemContext } from "../accordion-context";
|
|
12
|
+
|
|
13
|
+
export const AccordionHeader = forwardRef<
|
|
14
|
+
HTMLButtonElement,
|
|
15
|
+
DisclosureGroupProps
|
|
16
|
+
>(({ children }, ref) => {
|
|
17
|
+
const context = useContext(ItemContext);
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error("Accordion.Header must be used within Accordion.Item");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Extract HeaderRightContent if present
|
|
23
|
+
const headerContent = React.Children.toArray(children).reduce<{
|
|
24
|
+
main: React.ReactNode[];
|
|
25
|
+
rightContent: React.ReactNode[];
|
|
26
|
+
}>(
|
|
27
|
+
(acc, child) => {
|
|
28
|
+
if (React.isValidElement(child) && child.type === HeaderRightContent) {
|
|
29
|
+
acc.rightContent.push(child);
|
|
30
|
+
} else {
|
|
31
|
+
acc.main.push(child);
|
|
32
|
+
}
|
|
33
|
+
return acc;
|
|
34
|
+
},
|
|
35
|
+
{ main: [], rightContent: [] }
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Flex
|
|
40
|
+
justifyContent="space-between"
|
|
41
|
+
alignItems="center"
|
|
42
|
+
borderBottom="solid-25"
|
|
43
|
+
borderColor="neutral.4"
|
|
44
|
+
>
|
|
45
|
+
<AccordionTrigger
|
|
46
|
+
ref={mergeRefs(context.triggerRef, ref)}
|
|
47
|
+
{...context.buttonProps}
|
|
48
|
+
data-slot="trigger"
|
|
49
|
+
outline={context.isFocusVisible ? undefined : "none"}
|
|
50
|
+
>
|
|
51
|
+
<KeyboardArrowRight />
|
|
52
|
+
<AccordionTitle data-slot="accordionTitle">
|
|
53
|
+
{headerContent.main}
|
|
54
|
+
</AccordionTitle>
|
|
55
|
+
</AccordionTrigger>
|
|
56
|
+
{headerContent.rightContent.length > 0 && (
|
|
57
|
+
<HeaderRightContent data-slot="headerContentRight">
|
|
58
|
+
{headerContent.rightContent}
|
|
59
|
+
</HeaderRightContent>
|
|
60
|
+
)}
|
|
61
|
+
</Flex>
|
|
62
|
+
);
|
|
63
|
+
});
|