@stack-spot/citric-react 0.42.0-beta.0 → 0.42.0

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 (208) hide show
  1. package/CHANGELOG.md +13 -13
  2. package/dist/citric.css +2849 -3081
  3. package/dist/components/Accordion.d.ts +1 -1
  4. package/dist/components/Accordion.js +1 -1
  5. package/dist/components/Alert.d.ts +1 -1
  6. package/dist/components/Alert.js +1 -1
  7. package/dist/components/AsyncContent.d.ts +1 -1
  8. package/dist/components/AsyncContent.js +1 -1
  9. package/dist/components/Avatar.d.ts +1 -1
  10. package/dist/components/Avatar.js +1 -1
  11. package/dist/components/AvatarGroup.d.ts +1 -1
  12. package/dist/components/AvatarGroup.js +1 -1
  13. package/dist/components/Badge.d.ts +1 -1
  14. package/dist/components/Badge.js +1 -1
  15. package/dist/components/Blockquote.d.ts +1 -1
  16. package/dist/components/Blockquote.js +1 -1
  17. package/dist/components/Breadcrumb.d.ts +1 -1
  18. package/dist/components/Breadcrumb.js +1 -1
  19. package/dist/components/Button.d.ts +1 -1
  20. package/dist/components/Button.js +1 -1
  21. package/dist/components/ButtonLink.d.ts +1 -1
  22. package/dist/components/ButtonLink.js +1 -1
  23. package/dist/components/Card.d.ts +1 -1
  24. package/dist/components/Card.js +1 -1
  25. package/dist/components/Checkbox.d.ts +1 -1
  26. package/dist/components/Checkbox.d.ts.map +1 -1
  27. package/dist/components/Checkbox.js +2 -2
  28. package/dist/components/Checkbox.js.map +1 -1
  29. package/dist/components/CheckboxGroup.d.ts +1 -1
  30. package/dist/components/CheckboxGroup.js +1 -1
  31. package/dist/components/Circle.d.ts +1 -1
  32. package/dist/components/Circle.js +1 -1
  33. package/dist/components/CitricComponent.d.ts +1 -1
  34. package/dist/components/CitricComponent.d.ts.map +1 -1
  35. package/dist/components/Divider.d.ts +1 -1
  36. package/dist/components/Divider.js +1 -1
  37. package/dist/components/ErrorBoundary.d.ts +1 -1
  38. package/dist/components/ErrorBoundary.js +1 -1
  39. package/dist/components/ErrorMessage.d.ts +1 -1
  40. package/dist/components/ErrorMessage.js +1 -1
  41. package/dist/components/FallbackBoundary.d.ts +1 -1
  42. package/dist/components/FallbackBoundary.js +1 -1
  43. package/dist/components/Favorite.d.ts +1 -1
  44. package/dist/components/Favorite.js +1 -1
  45. package/dist/components/FieldGroup.d.ts +1 -1
  46. package/dist/components/FieldGroup.js +1 -1
  47. package/dist/components/Form.d.ts +2 -2
  48. package/dist/components/Form.js +1 -1
  49. package/dist/components/FormGroup.d.ts +1 -1
  50. package/dist/components/FormGroup.js +1 -1
  51. package/dist/components/Icon.d.ts +1 -1
  52. package/dist/components/Icon.js +1 -1
  53. package/dist/components/IconBox.d.ts +3 -3
  54. package/dist/components/IconBox.js +1 -1
  55. package/dist/components/ImageBox.d.ts +3 -3
  56. package/dist/components/ImageBox.js +1 -1
  57. package/dist/components/ImageWithFallback.d.ts +1 -1
  58. package/dist/components/ImageWithFallback.js +1 -1
  59. package/dist/components/Input.d.ts +1 -1
  60. package/dist/components/Input.js +1 -1
  61. package/dist/components/Link.d.ts +1 -1
  62. package/dist/components/Link.js +1 -1
  63. package/dist/components/LoadingPanel.d.ts +1 -1
  64. package/dist/components/LoadingPanel.js +1 -1
  65. package/dist/components/MenuOverlay/Menu.d.ts +1 -1
  66. package/dist/components/MenuOverlay/Menu.js +1 -1
  67. package/dist/components/MenuOverlay/index.d.ts +1 -1
  68. package/dist/components/MenuOverlay/index.js +1 -1
  69. package/dist/components/Overlay/index.d.ts +1 -1
  70. package/dist/components/Overlay/index.js +1 -1
  71. package/dist/components/Pagination.d.ts +1 -1
  72. package/dist/components/Pagination.js +1 -1
  73. package/dist/components/ProgressBar.d.ts +1 -1
  74. package/dist/components/ProgressBar.js +1 -1
  75. package/dist/components/ProgressCircular.d.ts +1 -1
  76. package/dist/components/ProgressCircular.js +1 -1
  77. package/dist/components/RadioGroup.d.ts +1 -1
  78. package/dist/components/RadioGroup.js +1 -1
  79. package/dist/components/Rating.d.ts +1 -1
  80. package/dist/components/Rating.js +1 -1
  81. package/dist/components/Select/MultiSelect.d.ts +1 -1
  82. package/dist/components/Select/MultiSelect.js +1 -1
  83. package/dist/components/Select/RichSelect.d.ts +1 -1
  84. package/dist/components/Select/RichSelect.js +1 -1
  85. package/dist/components/Select/SimpleSelect.d.ts +1 -1
  86. package/dist/components/Select/SimpleSelect.js +1 -1
  87. package/dist/components/Select/index.d.ts +1 -1
  88. package/dist/components/Select/index.js +1 -1
  89. package/dist/components/SelectBox.d.ts +9 -1
  90. package/dist/components/SelectBox.d.ts.map +1 -1
  91. package/dist/components/SelectBox.js +6 -5
  92. package/dist/components/SelectBox.js.map +1 -1
  93. package/dist/components/Skeleton.d.ts +1 -1
  94. package/dist/components/Skeleton.js +1 -1
  95. package/dist/components/Slider.d.ts +1 -1
  96. package/dist/components/Slider.js +1 -1
  97. package/dist/components/SmartTable.d.ts +1 -1
  98. package/dist/components/SmartTable.js +1 -1
  99. package/dist/components/Stepper.d.ts +1 -1
  100. package/dist/components/Stepper.js +1 -1
  101. package/dist/components/Table.d.ts +3 -3
  102. package/dist/components/Table.js +1 -1
  103. package/dist/components/Tabs/index.d.ts +1 -1
  104. package/dist/components/Tabs/index.js +1 -1
  105. package/dist/components/Textarea.d.ts +1 -1
  106. package/dist/components/Textarea.js +1 -1
  107. package/dist/components/Tooltip.d.ts +1 -1
  108. package/dist/components/Tooltip.js +1 -1
  109. package/dist/context/CitricProvider.d.ts +1 -1
  110. package/dist/context/CitricProvider.js +1 -1
  111. package/dist/index.d.ts +1 -1
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +1 -1
  114. package/dist/index.js.map +1 -1
  115. package/dist/overlay.js +1 -1
  116. package/dist/theme.css +415 -415
  117. package/dist/utils/css.js +1 -1
  118. package/dist/utils/css.js.map +1 -1
  119. package/package.json +1 -1
  120. package/scripts/build-css.ts +49 -49
  121. package/src/components/Accordion.tsx +130 -130
  122. package/src/components/Alert.tsx +24 -24
  123. package/src/components/AsyncContent.tsx +75 -75
  124. package/src/components/Avatar.tsx +45 -45
  125. package/src/components/AvatarGroup.tsx +49 -49
  126. package/src/components/Badge.tsx +47 -47
  127. package/src/components/Blockquote.tsx +18 -18
  128. package/src/components/Breadcrumb.tsx +33 -33
  129. package/src/components/Button.tsx +105 -105
  130. package/src/components/ButtonLink.tsx +45 -45
  131. package/src/components/Card.tsx +68 -68
  132. package/src/components/Checkbox.tsx +51 -52
  133. package/src/components/CheckboxGroup.tsx +153 -153
  134. package/src/components/Circle.tsx +43 -43
  135. package/src/components/CitricComponent.ts +47 -47
  136. package/src/components/Divider.tsx +24 -24
  137. package/src/components/ErrorBoundary.tsx +75 -75
  138. package/src/components/ErrorMessage.tsx +11 -11
  139. package/src/components/FallbackBoundary.tsx +40 -40
  140. package/src/components/Favorite.tsx +57 -57
  141. package/src/components/FieldGroup.tsx +46 -46
  142. package/src/components/Form.tsx +36 -36
  143. package/src/components/FormGroup.tsx +57 -57
  144. package/src/components/Icon.tsx +35 -35
  145. package/src/components/IconBox.tsx +134 -134
  146. package/src/components/ImageBox.tsx +125 -125
  147. package/src/components/ImageWithFallback.tsx +65 -65
  148. package/src/components/Input.tsx +49 -49
  149. package/src/components/Link.tsx +55 -55
  150. package/src/components/LoadingPanel.tsx +12 -12
  151. package/src/components/MenuOverlay/Menu.tsx +158 -158
  152. package/src/components/MenuOverlay/context.ts +20 -20
  153. package/src/components/MenuOverlay/index.tsx +55 -55
  154. package/src/components/MenuOverlay/keyboard.ts +60 -60
  155. package/src/components/MenuOverlay/types.ts +171 -171
  156. package/src/components/Overlay/context.ts +10 -10
  157. package/src/components/Overlay/index.tsx +182 -182
  158. package/src/components/Overlay/types.ts +75 -75
  159. package/src/components/Pagination.tsx +133 -133
  160. package/src/components/ProgressBar.tsx +45 -45
  161. package/src/components/ProgressCircular.tsx +45 -45
  162. package/src/components/RadioGroup.tsx +147 -147
  163. package/src/components/Rating.tsx +98 -98
  164. package/src/components/Select/MultiSelect.tsx +217 -217
  165. package/src/components/Select/RichSelect.tsx +128 -128
  166. package/src/components/Select/SimpleSelect.tsx +73 -73
  167. package/src/components/Select/hooks.ts +133 -133
  168. package/src/components/Select/index.tsx +35 -35
  169. package/src/components/Select/types.ts +134 -134
  170. package/src/components/SelectBox.tsx +181 -167
  171. package/src/components/Skeleton.tsx +53 -53
  172. package/src/components/Slider.tsx +89 -89
  173. package/src/components/SmartTable.tsx +227 -227
  174. package/src/components/Stepper.tsx +163 -163
  175. package/src/components/Table.tsx +234 -234
  176. package/src/components/Tabs/TabController.ts +54 -54
  177. package/src/components/Tabs/index.tsx +106 -106
  178. package/src/components/Tabs/types.ts +67 -67
  179. package/src/components/Tabs/utils.ts +6 -6
  180. package/src/components/Text.ts +111 -111
  181. package/src/components/Textarea.tsx +27 -27
  182. package/src/components/Tooltip.tsx +83 -83
  183. package/src/components/layout.tsx +101 -101
  184. package/src/context/CitricContext.tsx +4 -4
  185. package/src/context/CitricProvider.tsx +14 -14
  186. package/src/context/hooks.ts +6 -6
  187. package/src/index.ts +58 -59
  188. package/src/overlay.ts +348 -348
  189. package/src/types.ts +235 -235
  190. package/src/utils/ValueController.ts +28 -28
  191. package/src/utils/acessibility.ts +92 -92
  192. package/src/utils/checkbox.ts +121 -121
  193. package/src/utils/css.ts +119 -119
  194. package/src/utils/options.ts +9 -9
  195. package/src/utils/radio.ts +93 -93
  196. package/src/utils/react.ts +6 -6
  197. package/src/utils/time.ts +5 -5
  198. package/tsconfig.json +10 -10
  199. package/dist/components/Autocomplete/Autocomplete.d.ts +0 -211
  200. package/dist/components/Autocomplete/Autocomplete.d.ts.map +0 -1
  201. package/dist/components/Autocomplete/Autocomplete.js +0 -409
  202. package/dist/components/Autocomplete/Autocomplete.js.map +0 -1
  203. package/dist/components/Autocomplete/index.d.ts +0 -3
  204. package/dist/components/Autocomplete/index.d.ts.map +0 -1
  205. package/dist/components/Autocomplete/index.js +0 -2
  206. package/dist/components/Autocomplete/index.js.map +0 -1
  207. package/src/components/Autocomplete/Autocomplete.tsx +0 -794
  208. package/src/components/Autocomplete/index.ts +0 -3
package/dist/utils/css.js CHANGED
@@ -78,7 +78,7 @@ export function styleObjectToCssString(styleObject = {}) {
78
78
  const cssProperty = property.replace(/([A-Z])/g, '-$1').toLowerCase();
79
79
  // Append 'px' to numeric values for common dimension properties
80
80
  const cssValue = typeof value === 'number' &&
81
- !['zIndex', 'opacity', 'fontWeight'].includes(property)
81
+ !['zIndex', 'opacity', 'fontWeight', 'flex', 'flexGrow', 'flexShrink', 'flexBasis'].includes(property)
82
82
  ? `${value}px`
83
83
  : value;
84
84
  return `${cssProperty}: ${cssValue}`;
@@ -1 +1 @@
1
- {"version":3,"file":"css.js","sourceRoot":"","sources":["../../src/utils/css.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,WAAW,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAA;AAEvE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG5C,MAAM,UAAU,wBAAwB,CAAC,IAAc;IACrD,OAAO,SAAS,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAA;AAC9C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAsC,EAAE,KAA2B;IAC5F,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,wBAAwB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;AAC7E,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,UAA0B;IAC9D,OAAO,QAAQ,UAAU,EAAE,CAAA;AAC7B,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,SAA6B,EAAE,UAAsC;IACvG,OAAO,WAAW,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;AAC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,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;QACjI,IAAI,EAAE,GAAG,EAAE,GAAG;KACf,CAAA;IACD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA;IACzC,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,EAAE,CAAA;AAChF,CAAC;AAED,eAAe;AACf,MAAM,UAAU,sBAAsB,CAAC,cAAmC,EAAE;IAC1E,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;SAC/B,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE;QACzB,kCAAkC;QAClC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAA;QAErE,gEAAgE;QAChE,MAAM,QAAQ,GACZ,OAAO,KAAK,KAAK,QAAQ;YACzB,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACpG,CAAC,CAAC,GAAG,KAAK,IAAI;YACd,CAAC,CAAC,KAAK,CAAA;QAEX,OAAO,GAAG,WAAW,KAAK,QAAQ,EAAE,CAAA;IACtC,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stack-spot/citric-react",
3
- "version": "0.42.0-beta.0",
3
+ "version": "0.42.0",
4
4
  "author": "StackSpot",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,49 +1,49 @@
1
- import { readFile, writeFile } from 'fs/promises'
2
- import { glob } from 'glob'
3
- import yargs from 'yargs'
4
- import { hideBin } from 'yargs/helpers'
5
-
6
- interface Argv {
7
- o?: string,
8
- output?: string,
9
- }
10
-
11
- function getArguments() {
12
- const argv = yargs(hideBin(process.argv)).parse() as Argv
13
- const output = argv.o || argv.output || './dist'
14
- return { output }
15
- }
16
-
17
- async function readInput() {
18
- const themeFiles = await glob('../css/theme/**.css')
19
- const otherFiles = await glob('../css/**/**.css', { ignore: '../css/theme/**' })
20
- const themeCss: string[] = []
21
- const otherCss: string[] = []
22
- for (const f of themeFiles) {
23
- themeCss.push(await readFile(f, { encoding: 'utf8' }))
24
- }
25
- for (const f of otherFiles) {
26
- otherCss.push(await readFile(f, { encoding: 'utf8' }))
27
- }
28
- return { theme: themeCss.join('\n\n'), citric: otherCss.join('\n\n') }
29
- }
30
-
31
- async function start() {
32
- try {
33
- const { output } = getArguments()
34
- const { theme, citric } = await readInput()
35
- await Promise.all([
36
- writeFile(`${output}/theme.css`, theme, { encoding: 'utf8' }),
37
- writeFile(`${output}/citric.css`, citric, { encoding: 'utf8' }),
38
- ])
39
- // eslint-disable-next-line no-console
40
- console.log(`CSS built at ${output}`)
41
- process.exit(0)
42
- } catch (error) {
43
- // eslint-disable-next-line no-console
44
- console.error(error)
45
- process.exit(1)
46
- }
47
- }
48
-
49
- start()
1
+ import { readFile, writeFile } from 'fs/promises'
2
+ import { glob } from 'glob'
3
+ import yargs from 'yargs'
4
+ import { hideBin } from 'yargs/helpers'
5
+
6
+ interface Argv {
7
+ o?: string,
8
+ output?: string,
9
+ }
10
+
11
+ function getArguments() {
12
+ const argv = yargs(hideBin(process.argv)).parse() as Argv
13
+ const output = argv.o || argv.output || './dist'
14
+ return { output }
15
+ }
16
+
17
+ async function readInput() {
18
+ const themeFiles = await glob('../css/theme/**.css')
19
+ const otherFiles = await glob('../css/**/**.css', { ignore: '../css/theme/**' })
20
+ const themeCss: string[] = []
21
+ const otherCss: string[] = []
22
+ for (const f of themeFiles) {
23
+ themeCss.push(await readFile(f, { encoding: 'utf8' }))
24
+ }
25
+ for (const f of otherFiles) {
26
+ otherCss.push(await readFile(f, { encoding: 'utf8' }))
27
+ }
28
+ return { theme: themeCss.join('\n\n'), citric: otherCss.join('\n\n') }
29
+ }
30
+
31
+ async function start() {
32
+ try {
33
+ const { output } = getArguments()
34
+ const { theme, citric } = await readInput()
35
+ await Promise.all([
36
+ writeFile(`${output}/theme.css`, theme, { encoding: 'utf8' }),
37
+ writeFile(`${output}/citric.css`, citric, { encoding: 'utf8' }),
38
+ ])
39
+ // eslint-disable-next-line no-console
40
+ console.log(`CSS built at ${output}`)
41
+ process.exit(0)
42
+ } catch (error) {
43
+ // eslint-disable-next-line no-console
44
+ console.error(error)
45
+ process.exit(1)
46
+ }
47
+ }
48
+
49
+ start()
@@ -1,130 +1,130 @@
1
- import { listToClass } from '@stack-spot/portal-theme'
2
- import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
3
- import { useEffect, useMemo, useState } from 'react'
4
- import { applyCSSVariable } from '../utils/css'
5
- import { withRef } from '../utils/react'
6
- import { CitricComponent } from './CitricComponent'
7
-
8
- export interface BaseAccordionProps {
9
- /**
10
- * A unique id for this accordion.
11
- */
12
- id?: string,
13
- /**
14
- * The Accordion's appearance. If unset, the appearance is customizable.
15
- */
16
- appearance?: 'card',
17
- /**
18
- * Controls the expansion state of the accordion.
19
- */
20
- expanded?: boolean,
21
- /**
22
- * If the expansion is not controlled externally (expanded/onChange), this tells if the Accordion should start opened.
23
- * @default false
24
- */
25
- startExpanded?: boolean,
26
- /**
27
- * Controls the expansion state of the accordion. Called when the accordion is expanded or collapsed.
28
- */
29
- onChange?: (expanded: boolean) => void,
30
- /**
31
- * The header for the accordion, i.e. the part that is always rendered. You can use either a simple title or a custom set of components,
32
- * in the second case, you may pass a function that receives the "expand/collapse" button as parameter.
33
- */
34
- header: React.ReactNode | ((expandButton: React.ReactElement) => React.ReactNode),
35
- /**
36
- * The maximum height for the accordion.
37
- *
38
- * @default 300
39
- */
40
- maxHeight?: number,
41
- }
42
-
43
- export type AccordionProps = Omit<React.JSX.IntrinsicElements['div'], 'onChange'> & BaseAccordionProps
44
-
45
- /**
46
- * Creates an accordion, showing/hiding the children according to the state of the expand/collapse checkbox.
47
- *
48
- * The accordion must define a max height, which is 300 by default (measured in pixels). Whenever the content surpasses "maxHeight", a
49
- * vertical scroll is created. If your content is much shorter than "maxHeight", consider reducing its value for a better animation.
50
- *
51
- * @example
52
- * A simple accordion, styled like a card:
53
- * ```
54
- * <Accordion appearance="card" header="This is the title of the accordion" maxHeight={80}>
55
- * <p>This is the content of the accordion</p>
56
- * </Accordion>
57
- * ```
58
- *
59
- * A more complex accordion:
60
- * ```
61
- * const header = (toggle: React.ReactElement) => (
62
- * <Row justifyContent="space-between" bg="cyan.500" border="cyan.700" radius="sm">
63
- * <ImageBox><img src="/my-image.png" /></ImageBox>
64
- * <Text>Joseph Clinton</Text>
65
- * <Text>40 years old</Text>
66
- * {toggle}
67
- * </Row>
68
- * )
69
- * return (
70
- * <Accordion header={header}>
71
- * <Center>
72
- * <img src="/an-image.png" />
73
- * <p>This is the content of the accordion</p>
74
- * </Center>
75
- * </Accordion>
76
- * )
77
- * ```
78
- */
79
- export const Accordion = withRef((
80
- { id, appearance, expanded, onChange, header, maxHeight = 300, startExpanded, className, style, children, ...props }: AccordionProps,
81
- ) => {
82
- const t = useTranslate(dictionary)
83
- const initialExpanded = expanded ?? startExpanded ?? false
84
- const [ariaHidden, setAriaHidden] = useState(!initialExpanded)
85
- const accordionId = useMemo(() => id || `${Math.random()}`, [id])
86
-
87
- useEffect(() => {
88
- if (expanded !== undefined) setAriaHidden(!expanded)
89
- }, [expanded])
90
-
91
- const expandBtn = <input
92
- type="checkbox"
93
- defaultChecked={initialExpanded}
94
- checked={expanded}
95
- onChange={() => {
96
- setAriaHidden(!ariaHidden)
97
- onChange?.(!expanded)
98
- }}
99
- aria-label={ariaHidden ? t.open : t.close}
100
- title={ariaHidden ? t.open : t.close}
101
- onKeyDown={e => e.key === 'Enter' && (e.target as HTMLElement).click?.()}
102
- aria-controls={accordionId}
103
- />
104
- const headerContent = typeof header === 'function' ? header(expandBtn) : <label>{header}{expandBtn}</label>
105
- return (
106
- <CitricComponent
107
- tag="div"
108
- component="accordion"
109
- className={listToClass([appearance, className])}
110
- style={applyCSSVariable(style, 'max-height', `${maxHeight}px`)}
111
- {...props}
112
- >
113
- <header>{headerContent}</header>
114
- <section id={accordionId} aria-hidden={ariaHidden} {...(ariaHidden ? { inert: 'true' } : {})}>
115
- {appearance === 'card' ? <div className="content">{children}</div> : children}
116
- </section>
117
- </CitricComponent>
118
- )
119
- })
120
-
121
- const dictionary = {
122
- en: {
123
- open: 'Open',
124
- close: 'Close',
125
- },
126
- pt: {
127
- open: 'Abrir',
128
- close: 'Fechar',
129
- },
130
- } satisfies Dictionary
1
+ import { listToClass } from '@stack-spot/portal-theme'
2
+ import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
3
+ import { useEffect, useMemo, useState } from 'react'
4
+ import { applyCSSVariable } from '../utils/css'
5
+ import { withRef } from '../utils/react'
6
+ import { CitricComponent } from './CitricComponent'
7
+
8
+ export interface BaseAccordionProps {
9
+ /**
10
+ * A unique id for this accordion.
11
+ */
12
+ id?: string,
13
+ /**
14
+ * The Accordion's appearance. If unset, the appearance is customizable.
15
+ */
16
+ appearance?: 'card',
17
+ /**
18
+ * Controls the expansion state of the accordion.
19
+ */
20
+ expanded?: boolean,
21
+ /**
22
+ * If the expansion is not controlled externally (expanded/onChange), this tells if the Accordion should start opened.
23
+ * @default false
24
+ */
25
+ startExpanded?: boolean,
26
+ /**
27
+ * Controls the expansion state of the accordion. Called when the accordion is expanded or collapsed.
28
+ */
29
+ onChange?: (expanded: boolean) => void,
30
+ /**
31
+ * The header for the accordion, i.e. the part that is always rendered. You can use either a simple title or a custom set of components,
32
+ * in the second case, you may pass a function that receives the "expand/collapse" button as parameter.
33
+ */
34
+ header: React.ReactNode | ((expandButton: React.ReactElement) => React.ReactNode),
35
+ /**
36
+ * The maximum height for the accordion.
37
+ *
38
+ * @default 300
39
+ */
40
+ maxHeight?: number,
41
+ }
42
+
43
+ export type AccordionProps = Omit<React.JSX.IntrinsicElements['div'], 'onChange'> & BaseAccordionProps
44
+
45
+ /**
46
+ * Creates an accordion, showing/hiding the children according to the state of the expand/collapse checkbox.
47
+ *
48
+ * The accordion must define a max height, which is 300 by default (measured in pixels). Whenever the content surpasses "maxHeight", a
49
+ * vertical scroll is created. If your content is much shorter than "maxHeight", consider reducing its value for a better animation.
50
+ *
51
+ * @example
52
+ * A simple accordion, styled like a card:
53
+ * ```
54
+ * <Accordion appearance="card" header="This is the title of the accordion" maxHeight={80}>
55
+ * <p>This is the content of the accordion</p>
56
+ * </Accordion>
57
+ * ```
58
+ *
59
+ * A more complex accordion:
60
+ * ```
61
+ * const header = (toggle: React.ReactElement) => (
62
+ * <Row justifyContent="space-between" bg="cyan.500" border="cyan.700" radius="sm">
63
+ * <ImageBox><img src="/my-image.png" /></ImageBox>
64
+ * <Text>Joseph Clinton</Text>
65
+ * <Text>40 years old</Text>
66
+ * {toggle}
67
+ * </Row>
68
+ * )
69
+ * return (
70
+ * <Accordion header={header}>
71
+ * <Center>
72
+ * <img src="/an-image.png" />
73
+ * <p>This is the content of the accordion</p>
74
+ * </Center>
75
+ * </Accordion>
76
+ * )
77
+ * ```
78
+ */
79
+ export const Accordion = withRef((
80
+ { id, appearance, expanded, onChange, header, maxHeight = 300, startExpanded, className, style, children, ...props }: AccordionProps,
81
+ ) => {
82
+ const t = useTranslate(dictionary)
83
+ const initialExpanded = expanded ?? startExpanded ?? false
84
+ const [ariaHidden, setAriaHidden] = useState(!initialExpanded)
85
+ const accordionId = useMemo(() => id || `${Math.random()}`, [id])
86
+
87
+ useEffect(() => {
88
+ if (expanded !== undefined) setAriaHidden(!expanded)
89
+ }, [expanded])
90
+
91
+ const expandBtn = <input
92
+ type="checkbox"
93
+ defaultChecked={initialExpanded}
94
+ checked={expanded}
95
+ onChange={() => {
96
+ setAriaHidden(!ariaHidden)
97
+ onChange?.(!expanded)
98
+ }}
99
+ aria-label={ariaHidden ? t.open : t.close}
100
+ title={ariaHidden ? t.open : t.close}
101
+ onKeyDown={e => e.key === 'Enter' && (e.target as HTMLElement).click?.()}
102
+ aria-controls={accordionId}
103
+ />
104
+ const headerContent = typeof header === 'function' ? header(expandBtn) : <label>{header}{expandBtn}</label>
105
+ return (
106
+ <CitricComponent
107
+ tag="div"
108
+ component="accordion"
109
+ className={listToClass([appearance, className])}
110
+ style={applyCSSVariable(style, 'max-height', `${maxHeight}px`)}
111
+ {...props}
112
+ >
113
+ <header>{headerContent}</header>
114
+ <section id={accordionId} aria-hidden={ariaHidden} {...(ariaHidden ? { inert: 'true' } : {})}>
115
+ {appearance === 'card' ? <div className="content">{children}</div> : children}
116
+ </section>
117
+ </CitricComponent>
118
+ )
119
+ })
120
+
121
+ const dictionary = {
122
+ en: {
123
+ open: 'Open',
124
+ close: 'Close',
125
+ },
126
+ pt: {
127
+ open: 'Abrir',
128
+ close: 'Fechar',
129
+ },
130
+ } satisfies Dictionary
@@ -1,24 +1,24 @@
1
- import { listToClass } from '@stack-spot/portal-theme'
2
- import { withRef } from '../utils/react'
3
- import { CitricComponent } from './CitricComponent'
4
-
5
- export interface BaseAlertProps {
6
- /**
7
- * Type of the message.
8
- * @default 'warning'
9
- */
10
- type?: 'error' | 'info' | 'warning',
11
- }
12
-
13
- export type AlertProps = React.JSX.IntrinsicElements['div'] & BaseAlertProps
14
-
15
- /**
16
- * Renders an alert message with an icon and a background. This may be an error, warning or a success feedback.
17
- *
18
- * @example
19
- * ```
20
- * <Alert type="warning">My warning!</Alert>
21
- * ```
22
- */
23
- export const Alert = withRef(({ type, className, children, ...props }: AlertProps) =>
24
- <CitricComponent tag="div" component="alert" className={listToClass([type, className])} {...props}>{children}</CitricComponent>)
1
+ import { listToClass } from '@stack-spot/portal-theme'
2
+ import { withRef } from '../utils/react'
3
+ import { CitricComponent } from './CitricComponent'
4
+
5
+ export interface BaseAlertProps {
6
+ /**
7
+ * Type of the message.
8
+ * @default 'warning'
9
+ */
10
+ type?: 'error' | 'info' | 'warning',
11
+ }
12
+
13
+ export type AlertProps = React.JSX.IntrinsicElements['div'] & BaseAlertProps
14
+
15
+ /**
16
+ * Renders an alert message with an icon and a background. This may be an error, warning or a success feedback.
17
+ *
18
+ * @example
19
+ * ```
20
+ * <Alert type="warning">My warning!</Alert>
21
+ * ```
22
+ */
23
+ export const Alert = withRef(({ type, className, children, ...props }: AlertProps) =>
24
+ <CitricComponent tag="div" component="alert" className={listToClass([type, className])} {...props}>{children}</CitricComponent>)
@@ -1,75 +1,75 @@
1
- import { MutableRefObject, useEffect, useLayoutEffect } from 'react'
2
- import { useCitricController } from '../context/hooks'
3
- import { LoadingStyle } from '../types'
4
- import { withRef } from '../utils/react'
5
- import { ErrorMessage } from './ErrorMessage'
6
- import { LoadingPanel } from './LoadingPanel'
7
-
8
- interface Props {
9
- /**
10
- * Whether or not to show the loading feedback.
11
- */
12
- loading: boolean,
13
- /**
14
- * A javascript error. Used to show error feedbacks.
15
- */
16
- error?: any,
17
- /**
18
- * If provided, this element will receive focus as soon as the content is loaded and has no errors.
19
- * Can be either a React Ref Object or a query selector.
20
- */
21
- autofocus?: string | MutableRefObject<HTMLElement>,
22
- /**
23
- * The content to show if it's not loading or has errors.
24
- */
25
- children: React.ReactNode,
26
- /**
27
- * Customizes the loading component.
28
- */
29
- loadingStyle?: LoadingStyle,
30
- }
31
-
32
- /**
33
- * Renders a component that provides user feedback on async requests. It renders either a loading component, an error component or its
34
- * children.
35
- *
36
- * The loading and error views can be customized through a CitricController.
37
- *
38
- * Errors can be watched through the function `onError` of a CitricController.
39
- *
40
- * Attention: for React Suspense, use the component "FallbackBoundary" instead.
41
- *
42
- * @example
43
- *
44
- * ```
45
- * const [data, isLoading, error] = useRemoteData()
46
- *
47
- * return (
48
- * <AsyncContent loading={isLoading} error={error}>
49
- * {data}
50
- * </AsyncContent>
51
- * )
52
- * ```
53
- */
54
-
55
- export const AsyncContent = withRef(({ loading, error, autofocus, children, loadingStyle }: Props) => {
56
- const citric = useCitricController()
57
-
58
- useEffect(() => {
59
- if (error) {
60
- citric?.onError?.(error)
61
- // eslint-disable-next-line no-console
62
- console.error(error)
63
- }
64
- }, [error])
65
-
66
- useLayoutEffect(() => {
67
- if (!loading && !error) {
68
- typeof autofocus === 'string' ? (document.querySelector(autofocus) as HTMLElement)?.focus?.() : autofocus?.current?.focus()
69
- }
70
- }, [loading, error])
71
-
72
- if (loading) return citric?.renderLoading ? citric.renderLoading(loadingStyle) : <LoadingPanel {...loadingStyle} />
73
- if (error) return citric?.renderError ? citric.renderError(error) : <ErrorMessage error={error} />
74
- return children
75
- })
1
+ import { MutableRefObject, useEffect, useLayoutEffect } from 'react'
2
+ import { useCitricController } from '../context/hooks'
3
+ import { LoadingStyle } from '../types'
4
+ import { withRef } from '../utils/react'
5
+ import { ErrorMessage } from './ErrorMessage'
6
+ import { LoadingPanel } from './LoadingPanel'
7
+
8
+ interface Props {
9
+ /**
10
+ * Whether or not to show the loading feedback.
11
+ */
12
+ loading: boolean,
13
+ /**
14
+ * A javascript error. Used to show error feedbacks.
15
+ */
16
+ error?: any,
17
+ /**
18
+ * If provided, this element will receive focus as soon as the content is loaded and has no errors.
19
+ * Can be either a React Ref Object or a query selector.
20
+ */
21
+ autofocus?: string | MutableRefObject<HTMLElement>,
22
+ /**
23
+ * The content to show if it's not loading or has errors.
24
+ */
25
+ children: React.ReactNode,
26
+ /**
27
+ * Customizes the loading component.
28
+ */
29
+ loadingStyle?: LoadingStyle,
30
+ }
31
+
32
+ /**
33
+ * Renders a component that provides user feedback on async requests. It renders either a loading component, an error component or its
34
+ * children.
35
+ *
36
+ * The loading and error views can be customized through a CitricController.
37
+ *
38
+ * Errors can be watched through the function `onError` of a CitricController.
39
+ *
40
+ * Attention: for React Suspense, use the component "FallbackBoundary" instead.
41
+ *
42
+ * @example
43
+ *
44
+ * ```
45
+ * const [data, isLoading, error] = useRemoteData()
46
+ *
47
+ * return (
48
+ * <AsyncContent loading={isLoading} error={error}>
49
+ * {data}
50
+ * </AsyncContent>
51
+ * )
52
+ * ```
53
+ */
54
+
55
+ export const AsyncContent = withRef(({ loading, error, autofocus, children, loadingStyle }: Props) => {
56
+ const citric = useCitricController()
57
+
58
+ useEffect(() => {
59
+ if (error) {
60
+ citric?.onError?.(error)
61
+ // eslint-disable-next-line no-console
62
+ console.error(error)
63
+ }
64
+ }, [error])
65
+
66
+ useLayoutEffect(() => {
67
+ if (!loading && !error) {
68
+ typeof autofocus === 'string' ? (document.querySelector(autofocus) as HTMLElement)?.focus?.() : autofocus?.current?.focus()
69
+ }
70
+ }, [loading, error])
71
+
72
+ if (loading) return citric?.renderLoading ? citric.renderLoading(loadingStyle) : <LoadingPanel {...loadingStyle} />
73
+ if (error) return citric?.renderError ? citric.renderError(error) : <ErrorMessage error={error} />
74
+ return children
75
+ })