@commercetools/nimbus 0.0.2 → 0.0.3

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.
Files changed (302) hide show
  1. package/dist/index.d.ts +1412 -0
  2. package/dist/index.js +11183 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/index.umd.cjs +27 -0
  5. package/dist/index.umd.cjs.map +1 -0
  6. package/package.json +63 -39
  7. package/.storybook/apca-check/index.ts +0 -150
  8. package/.storybook/main.ts +0 -64
  9. package/.storybook/preview.tsx +0 -92
  10. package/.storybook/vitest.setup.ts +0 -13
  11. package/docs/architecture-decisions/adr-0001-consumer-component-apis.md +0 -177
  12. package/docs/architecture-decisions/adr-0002-compound-component-extraction.md +0 -82
  13. package/src/components/accordion/accordion-context.tsx +0 -17
  14. package/src/components/accordion/accordion.mdx +0 -172
  15. package/src/components/accordion/accordion.recipe.tsx +0 -98
  16. package/src/components/accordion/accordion.slots.tsx +0 -39
  17. package/src/components/accordion/accordion.stories.tsx +0 -188
  18. package/src/components/accordion/accordion.tsx +0 -16
  19. package/src/components/accordion/accordion.types.tsx +0 -54
  20. package/src/components/accordion/components/accordion-content.tsx +0 -28
  21. package/src/components/accordion/components/accordion-group.tsx +0 -27
  22. package/src/components/accordion/components/accordion-header.tsx +0 -63
  23. package/src/components/accordion/components/accordion-item.tsx +0 -87
  24. package/src/components/accordion/index.ts +0 -2
  25. package/src/components/alert/alert.mdx +0 -92
  26. package/src/components/alert/alert.recipe.tsx +0 -65
  27. package/src/components/alert/alert.slots.tsx +0 -46
  28. package/src/components/alert/alert.stories.tsx +0 -308
  29. package/src/components/alert/alert.tsx +0 -18
  30. package/src/components/alert/alert.types.tsx +0 -70
  31. package/src/components/alert/components/alert.actions.tsx +0 -27
  32. package/src/components/alert/components/alert.description.tsx +0 -27
  33. package/src/components/alert/components/alert.dismiss-button.tsx +0 -41
  34. package/src/components/alert/components/alert.root.tsx +0 -92
  35. package/src/components/alert/components/alert.title.tsx +0 -29
  36. package/src/components/alert/index.ts +0 -2
  37. package/src/components/avatar/avatar.mdx +0 -80
  38. package/src/components/avatar/avatar.recipe.tsx +0 -36
  39. package/src/components/avatar/avatar.slots.tsx +0 -16
  40. package/src/components/avatar/avatar.stories.tsx +0 -136
  41. package/src/components/avatar/avatar.tsx +0 -34
  42. package/src/components/avatar/avatar.types.ts +0 -33
  43. package/src/components/avatar/index.ts +0 -2
  44. package/src/components/badge/badge.mdx +0 -91
  45. package/src/components/badge/badge.recipe.tsx +0 -72
  46. package/src/components/badge/badge.slots.tsx +0 -8
  47. package/src/components/badge/badge.stories.tsx +0 -124
  48. package/src/components/badge/badge.tsx +0 -35
  49. package/src/components/badge/badge.types.tsx +0 -40
  50. package/src/components/badge/index.ts +0 -2
  51. package/src/components/bleed/bleed.tsx +0 -1
  52. package/src/components/bleed/index.ts +0 -1
  53. package/src/components/box/box.mdx +0 -115
  54. package/src/components/box/box.stories.tsx +0 -71
  55. package/src/components/box/box.tsx +0 -11
  56. package/src/components/box/index.ts +0 -1
  57. package/src/components/button/button.mdx +0 -169
  58. package/src/components/button/button.recipe.ts +0 -185
  59. package/src/components/button/button.slots.tsx +0 -45
  60. package/src/components/button/button.stories.tsx +0 -369
  61. package/src/components/button/button.tsx +0 -37
  62. package/src/components/button/button.types.ts +0 -14
  63. package/src/components/button/index.ts +0 -2
  64. package/src/components/card/card.mdx +0 -92
  65. package/src/components/card/card.recipe.tsx +0 -71
  66. package/src/components/card/card.slots.tsx +0 -50
  67. package/src/components/card/card.stories.tsx +0 -175
  68. package/src/components/card/card.tsx +0 -9
  69. package/src/components/card/card.types.ts +0 -22
  70. package/src/components/card/components/card.content.tsx +0 -29
  71. package/src/components/card/components/card.header.tsx +0 -28
  72. package/src/components/card/components/card.root.tsx +0 -62
  73. package/src/components/card/index.ts +0 -2
  74. package/src/components/checkbox/checkbox.mdx +0 -78
  75. package/src/components/checkbox/checkbox.recipe.tsx +0 -116
  76. package/src/components/checkbox/checkbox.slots.tsx +0 -33
  77. package/src/components/checkbox/checkbox.stories.tsx +0 -200
  78. package/src/components/checkbox/checkbox.tsx +0 -77
  79. package/src/components/checkbox/checkbox.types.tsx +0 -22
  80. package/src/components/checkbox/index.ts +0 -2
  81. package/src/components/code/code.mdx +0 -17
  82. package/src/components/code/code.recipe.ts +0 -63
  83. package/src/components/code/code.tsx +0 -1
  84. package/src/components/code/index.ts +0 -1
  85. package/src/components/dialog/dialog.mdx +0 -20
  86. package/src/components/dialog/dialog.recipe.ts +0 -254
  87. package/src/components/dialog/dialog.tsx +0 -61
  88. package/src/components/dialog/index.ts +0 -1
  89. package/src/components/em/em.mdx +0 -17
  90. package/src/components/em/em.tsx +0 -1
  91. package/src/components/em/index.ts +0 -1
  92. package/src/components/flex/flex.mdx +0 -41
  93. package/src/components/flex/flex.tsx +0 -1
  94. package/src/components/flex/index.ts +0 -1
  95. package/src/components/grid/grid.mdx +0 -156
  96. package/src/components/grid/grid.stories.tsx +0 -151
  97. package/src/components/grid/grid.tsx +0 -29
  98. package/src/components/grid/index.ts +0 -1
  99. package/src/components/heading/heading.mdx +0 -23
  100. package/src/components/heading/heading.recipe.ts +0 -49
  101. package/src/components/heading/heading.tsx +0 -1
  102. package/src/components/heading/index.ts +0 -1
  103. package/src/components/highlight/highlight.mdx +0 -18
  104. package/src/components/highlight/highlight.tsx +0 -1
  105. package/src/components/highlight/index.ts +0 -1
  106. package/src/components/icon-button/icon-button.mdx +0 -98
  107. package/src/components/icon-button/icon-button.stories.tsx +0 -188
  108. package/src/components/icon-button/icon-button.tsx +0 -21
  109. package/src/components/icon-button/icon-button.types.tsx +0 -10
  110. package/src/components/icon-button/index.ts +0 -2
  111. package/src/components/index.ts +0 -33
  112. package/src/components/input/index.ts +0 -1
  113. package/src/components/input/input.mdx +0 -20
  114. package/src/components/input/input.recipe.ts +0 -95
  115. package/src/components/input/input.tsx +0 -1
  116. package/src/components/input-group/index.ts +0 -1
  117. package/src/components/input-group/input-group.mdx +0 -20
  118. package/src/components/input-group/input-group.tsx +0 -44
  119. package/src/components/kbd/index.ts +0 -1
  120. package/src/components/kbd/kbd.mdx +0 -18
  121. package/src/components/kbd/kbd.recipe.ts +0 -57
  122. package/src/components/kbd/kbd.tsx +0 -1
  123. package/src/components/link/index.ts +0 -2
  124. package/src/components/link/link.mdx +0 -77
  125. package/src/components/link/link.recipe.ts +0 -52
  126. package/src/components/link/link.slots.tsx +0 -29
  127. package/src/components/link/link.stories.tsx +0 -204
  128. package/src/components/link/link.tsx +0 -38
  129. package/src/components/link/link.types.tsx +0 -26
  130. package/src/components/list/index.ts +0 -1
  131. package/src/components/list/list.mdx +0 -18
  132. package/src/components/list/list.recipe.ts +0 -68
  133. package/src/components/list/list.tsx +0 -9
  134. package/src/components/loading-spinner/index.ts +0 -2
  135. package/src/components/loading-spinner/loading-spinner.mdx +0 -92
  136. package/src/components/loading-spinner/loading-spinner.recipe.tsx +0 -70
  137. package/src/components/loading-spinner/loading-spinner.slots.tsx +0 -38
  138. package/src/components/loading-spinner/loading-spinner.stories.tsx +0 -97
  139. package/src/components/loading-spinner/loading-spinner.tsx +0 -50
  140. package/src/components/loading-spinner/loading-spinner.types.tsx +0 -21
  141. package/src/components/nimbus-provider/color-mode.tsx +0 -32
  142. package/src/components/nimbus-provider/index.ts +0 -2
  143. package/src/components/nimbus-provider/nimbus-provider.mdx +0 -21
  144. package/src/components/nimbus-provider/nimbus-provider.tsx +0 -51
  145. package/src/components/select/components/select.clear-button.tsx +0 -31
  146. package/src/components/select/components/select.option-group.tsx +0 -48
  147. package/src/components/select/components/select.option.tsx +0 -21
  148. package/src/components/select/components/select.options.tsx +0 -23
  149. package/src/components/select/components/select.root.tsx +0 -81
  150. package/src/components/select/index.ts +0 -2
  151. package/src/components/select/select.mdx +0 -170
  152. package/src/components/select/select.recipe.tsx +0 -216
  153. package/src/components/select/select.slots.tsx +0 -58
  154. package/src/components/select/select.stories.tsx +0 -841
  155. package/src/components/select/select.tsx +0 -18
  156. package/src/components/select/select.types.tsx +0 -37
  157. package/src/components/simple-grid/index.ts +0 -1
  158. package/src/components/simple-grid/simple-grid.mdx +0 -133
  159. package/src/components/simple-grid/simple-grid.stories.tsx +0 -143
  160. package/src/components/simple-grid/simple-grid.tsx +0 -31
  161. package/src/components/stack/index.ts +0 -1
  162. package/src/components/stack/stack.mdx +0 -88
  163. package/src/components/stack/stack.stories.tsx +0 -82
  164. package/src/components/stack/stack.tsx +0 -15
  165. package/src/components/table/index.ts +0 -1
  166. package/src/components/table/table.mdx +0 -23
  167. package/src/components/table/table.recipe.ts +0 -170
  168. package/src/components/table/table.tsx +0 -43
  169. package/src/components/text/index.ts +0 -1
  170. package/src/components/text/text.mdx +0 -244
  171. package/src/components/text/text.tsx +0 -23
  172. package/src/components/text-input/index.ts +0 -2
  173. package/src/components/text-input/text-input.mdx +0 -118
  174. package/src/components/text-input/text-input.recipe.tsx +0 -68
  175. package/src/components/text-input/text-input.slots.tsx +0 -24
  176. package/src/components/text-input/text-input.stories.tsx +0 -282
  177. package/src/components/text-input/text-input.tsx +0 -39
  178. package/src/components/text-input/text-input.types.ts +0 -7
  179. package/src/components/toggle-button-group/components/toggle-button-group.button.tsx +0 -14
  180. package/src/components/toggle-button-group/components/toggle-button-group.root.tsx +0 -15
  181. package/src/components/toggle-button-group/index.ts +0 -2
  182. package/src/components/toggle-button-group/toggle-button-group.mdx +0 -94
  183. package/src/components/toggle-button-group/toggle-button-group.recipe.tsx +0 -64
  184. package/src/components/toggle-button-group/toggle-button-group.slots.tsx +0 -26
  185. package/src/components/toggle-button-group/toggle-button-group.stories.tsx +0 -311
  186. package/src/components/toggle-button-group/toggle-button-group.tsx +0 -12
  187. package/src/components/toggle-button-group/toggle-button-group.types.tsx +0 -62
  188. package/src/components/tooltip/index.ts +0 -4
  189. package/src/components/tooltip/make-element-focusable.stories.tsx +0 -56
  190. package/src/components/tooltip/make-element-focusable.tsx +0 -57
  191. package/src/components/tooltip/tooltip-trigger.stories.tsx +0 -157
  192. package/src/components/tooltip/tooltip-trigger.tsx +0 -15
  193. package/src/components/tooltip/tooltip.mdx +0 -48
  194. package/src/components/tooltip/tooltip.recipe.ts +0 -26
  195. package/src/components/tooltip/tooltip.slots.ts +0 -35
  196. package/src/components/tooltip/tooltip.stories.tsx +0 -139
  197. package/src/components/tooltip/tooltip.tsx +0 -31
  198. package/src/components/tooltip/tooltip.types.ts +0 -44
  199. package/src/components/visually-hidden/index.ts +0 -1
  200. package/src/components/visually-hidden/visually-hidden.mdx +0 -61
  201. package/src/components/visually-hidden/visually-hidden.stories.tsx +0 -124
  202. package/src/components/visually-hidden/visually-hidden.tsx +0 -18
  203. package/src/docs/accessibility.mdx +0 -21
  204. package/src/docs/background.mdx +0 -154
  205. package/src/docs/border.mdx +0 -226
  206. package/src/docs/changelog.mdx +0 -17
  207. package/src/docs/components-layout.mdx +0 -22
  208. package/src/docs/components.mdx +0 -17
  209. package/src/docs/data-display.mdx +0 -23
  210. package/src/docs/display.mdx +0 -55
  211. package/src/docs/effects.mdx +0 -73
  212. package/src/docs/feedback.mdx +0 -22
  213. package/src/docs/filters.mdx +0 -268
  214. package/src/docs/flex-and-grid.mdx +0 -445
  215. package/src/docs/forms.mdx +0 -22
  216. package/src/docs/generated/index.mdx +0 -16
  217. package/src/docs/getting-started.mdx +0 -17
  218. package/src/docs/home.mdx +0 -56
  219. package/src/docs/hooks.mdx +0 -16
  220. package/src/docs/inputs.mdx +0 -21
  221. package/src/docs/installation.mdx +0 -60
  222. package/src/docs/interactivity.mdx +0 -278
  223. package/src/docs/known-issues.mdx +0 -19
  224. package/src/docs/layout.mdx +0 -301
  225. package/src/docs/list.mdx +0 -82
  226. package/src/docs/markdown.mdx +0 -234
  227. package/src/docs/media.mdx +0 -22
  228. package/src/docs/naivgation.mdx +0 -22
  229. package/src/docs/playground.mdx +0 -16
  230. package/src/docs/rfcs-component-structure-rfcs.mdx +0 -17
  231. package/src/docs/rfcs-component-structure.mdx +0 -74
  232. package/src/docs/rfcs-hook-structure.mdx +0 -59
  233. package/src/docs/sizing.mdx +0 -210
  234. package/src/docs/spacing.mdx +0 -193
  235. package/src/docs/style-props-typography.mdx +0 -373
  236. package/src/docs/style-props.mdx +0 -15
  237. package/src/docs/svg.mdx +0 -58
  238. package/src/docs/tables.mdx +0 -95
  239. package/src/docs/toc.mdx +0 -39
  240. package/src/docs/tokens/animations.mdx +0 -68
  241. package/src/docs/tokens/aspect-ratios.mdx +0 -21
  242. package/src/docs/tokens/blurs.mdx +0 -20
  243. package/src/docs/tokens/borders.mdx +0 -25
  244. package/src/docs/tokens/breakpoints.mdx +0 -35
  245. package/src/docs/tokens/colors.mdx +0 -86
  246. package/src/docs/tokens/cursors.mdx +0 -21
  247. package/src/docs/tokens/radii.mdx +0 -23
  248. package/src/docs/tokens/shadows.mdx +0 -21
  249. package/src/docs/tokens/sizes.mdx +0 -54
  250. package/src/docs/tokens/spacing.mdx +0 -35
  251. package/src/docs/tokens/typography.mdx +0 -61
  252. package/src/docs/tokens/z-indices.mdx +0 -23
  253. package/src/docs/tokens-other.mdx +0 -17
  254. package/src/docs/tokens.mdx +0 -16
  255. package/src/docs/transforms.mdx +0 -150
  256. package/src/docs/transitions.mdx +0 -164
  257. package/src/docs/typography.mdx +0 -17
  258. package/src/docs/utilities.mdx +0 -17
  259. package/src/hooks/index.ts +0 -2
  260. package/src/hooks/use-copy-to-clipboard/use-copy-to-clipboard.mdx +0 -54
  261. package/src/hooks/use-copy-to-clipboard/use-copy-to-clipboard.ts +0 -1
  262. package/src/hooks/use-hotkeys/use-hotkeys.mdx +0 -48
  263. package/src/hooks/use-hotkeys/use-hotkeys.stories.tsx +0 -69
  264. package/src/hooks/use-hotkeys/use-hotkeys.ts +0 -1
  265. package/src/index.ts +0 -3
  266. package/src/test/utils.tsx +0 -20
  267. package/src/theme/animation-styles.ts +0 -52
  268. package/src/theme/breakpoints.ts +0 -32
  269. package/src/theme/global-css.ts +0 -53
  270. package/src/theme/index.ts +0 -35
  271. package/src/theme/keyframes.ts +0 -192
  272. package/src/theme/layer-styles.ts +0 -12
  273. package/src/theme/recipes/index.ts +0 -21
  274. package/src/theme/semantic-tokens/colors.ts +0 -55
  275. package/src/theme/semantic-tokens/index.ts +0 -9
  276. package/src/theme/semantic-tokens/radii.ts +0 -3
  277. package/src/theme/semantic-tokens/shadows.ts +0 -4
  278. package/src/theme/slot-recipes/index.ts +0 -15
  279. package/src/theme/text-styles.ts +0 -8
  280. package/src/theme/tokens/animations.ts +0 -4
  281. package/src/theme/tokens/aspect-ratios.ts +0 -5
  282. package/src/theme/tokens/blurs.ts +0 -5
  283. package/src/theme/tokens/borders.ts +0 -4
  284. package/src/theme/tokens/colors.ts +0 -8
  285. package/src/theme/tokens/cursor.ts +0 -4
  286. package/src/theme/tokens/durations.ts +0 -4
  287. package/src/theme/tokens/easings.ts +0 -4
  288. package/src/theme/tokens/font-sizes.ts +0 -4
  289. package/src/theme/tokens/font-weights.ts +0 -4
  290. package/src/theme/tokens/fonts.ts +0 -4
  291. package/src/theme/tokens/index.ts +0 -57
  292. package/src/theme/tokens/letter-spacings.ts +0 -24
  293. package/src/theme/tokens/line-heights.ts +0 -4
  294. package/src/theme/tokens/radii.ts +0 -4
  295. package/src/theme/tokens/sizes.ts +0 -120
  296. package/src/theme/tokens/spacing.ts +0 -4
  297. package/src/theme/tokens/z-index.ts +0 -4
  298. package/src/utils/extractStyleProps.ts +0 -26
  299. package/src/utils/fixedForwardRef.ts +0 -17
  300. package/tsconfig.json +0 -38
  301. package/vite.config.ts +0 -54
  302. package/vitest.config.ts +0 -50
@@ -1,82 +0,0 @@
1
- # ADR: Standardizing Compound Component Extraction to a `components` Directory
2
-
3
- ## Context
4
-
5
- To enhance the organization, maintainability, and scalability of our components
6
- that utilize the compound component pattern, we are establishing a consistent
7
- directory structure for their implementation. This ADR outlines the principle of
8
- extracting the core root component and its associated compound sub-components
9
- into a dedicated `components` subdirectory.
10
-
11
- ## Decision
12
-
13
- For any component (`<ComponentName>`) that follows the compound component
14
- pattern (where sub-components like `<ComponentName.Part>`,
15
- `<ComponentName.Control>`, etc., are defined as properties of the main
16
- component), we will adopt the following directory structure:
17
-
18
- - The main component's directory will be
19
- `packages/nimbus/src/components/<component-name>/`.
20
- - A subdirectory named `components` will be created within the main component's
21
- directory: `packages/nimbus/src/components/<component-name>/components/`.
22
- - The implementation files for the root component (`<ComponentName.Root>`) and
23
- all its compound sub-components (`<ComponentName.Part>`,
24
- `<ComponentName.Control>`, etc.) will reside within this `components`
25
- subdirectory.
26
- - The main `<component-name>.tsx` file within the `<component-name>` directory
27
- will be responsible for:
28
- - Importing the root component and all sub-components from the `components`
29
- subdirectory.
30
- - Re-exporting them as properties of the main `ComponentName` object.
31
-
32
- Storybook files (`<component-name>.stories.tsx`) will be updated to reflect this
33
- structure, primarily by referencing the appropriate root component (e.g.,
34
- `ComponentName.Root` or `ComponentName`) in the `Meta` configuration.
35
-
36
- ## Why this is better:
37
-
38
- - **Consistent Code Organization:** This standardized structure will make it
39
- easier for developers to locate the implementation files for any component
40
- utilizing the compound pattern.
41
- - **Improved Maintainability:** Isolating the implementation of each part of a
42
- compound component within its own file reduces the complexity of individual
43
- files and minimizes the risk of unintended side effects during modifications.
44
- - **Enhanced Scalability:** As components grow and incorporate more
45
- sub-components, this structure provides a clear and manageable way to organize
46
- the increasing number of files.
47
- - **Clear Separation of Concerns:** Each file within the `components` directory
48
- will focus on the implementation details of a specific part of the compound
49
- component.
50
-
51
- ## Consequences
52
-
53
- - **New Directory Structure:** Developers will need to be aware of this new
54
- directory structure for all future and refactored compound components.
55
- - **Import Path Updates:** When working directly with the individual root or
56
- sub-component implementations, import paths will need to reflect their
57
- location within the `components` subdirectory. However, the main `index.tsx`
58
- re-export should abstract this for most consumers using the compound component
59
- API.
60
- - **Storybook Updates:** The `Meta` configuration in Storybook files for
61
- compound components will need to point to the appropriate root component.
62
-
63
- ## Examples
64
-
65
- **With `components` Subdirectory:**
66
-
67
- ```
68
- packages/nimbus/src/components/component-name/index.tsx
69
- packages/nimbus/src/components/component-name/component-name.tsx
70
- packages/nimbus/src/components/component-name/components/component-name.root.tsx
71
- packages/nimbus/src/components/component-name/components/component-name.part.tsx
72
- packages/nimbus/src/components/component-name/components/component-name.control.tsx
73
- packages/nimbus/src/components/component-name/component-name.stories.tsx
74
- ```
75
-
76
- ## Summary
77
-
78
- Adopting this standardized directory structure for compound components will lead
79
- to a more organized, maintainable, and scalable UI Kit. By consistently
80
- separating the implementation details of the root and sub-components into a
81
- dedicated `components` subdirectory, we establish a clear pattern for future
82
- development and refactoring efforts.
@@ -1,17 +0,0 @@
1
- import React, { createContext } from "react";
2
- import type { DisclosureGroupState } from "react-stately";
3
-
4
- // Define types for the item context
5
- export interface ItemContextType {
6
- isExpanded: boolean;
7
- triggerRef: React.RefObject<HTMLButtonElement>;
8
- panelRef: React.RefObject<HTMLDivElement>;
9
- buttonProps: React.ButtonHTMLAttributes<HTMLButtonElement>;
10
- panelProps: React.ButtonHTMLAttributes<HTMLButtonElement>;
11
- isFocusVisible: boolean;
12
- }
13
-
14
- // Create and export the contexts
15
- export const ItemContext = createContext<ItemContextType | null>(null);
16
- export const DisclosureGroupStateContext =
17
- createContext<DisclosureGroupState | null>(null);
@@ -1,172 +0,0 @@
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&#39;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" />
@@ -1,98 +0,0 @@
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
- });
@@ -1,39 +0,0 @@
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");
@@ -1,188 +0,0 @@
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
- };
@@ -1,16 +0,0 @@
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;
@@ -1,54 +0,0 @@
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
- };
@@ -1,28 +0,0 @@
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
- });