@stack-spot/citric-react 0.1.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 (345) hide show
  1. package/dist/citric.css +2580 -0
  2. package/dist/components/Accordion.d.ts +33 -0
  3. package/dist/components/Accordion.d.ts.map +1 -0
  4. package/dist/components/Accordion.js +19 -0
  5. package/dist/components/Accordion.js.map +1 -0
  6. package/dist/components/Alert.d.ts +11 -0
  7. package/dist/components/Alert.d.ts.map +1 -0
  8. package/dist/components/Alert.js +5 -0
  9. package/dist/components/Alert.js.map +1 -0
  10. package/dist/components/AsyncContent.d.ts +30 -0
  11. package/dist/components/AsyncContent.d.ts.map +1 -0
  12. package/dist/components/AsyncContent.js +33 -0
  13. package/dist/components/AsyncContent.js.map +1 -0
  14. package/dist/components/Avatar.d.ts +22 -0
  15. package/dist/components/Avatar.d.ts.map +1 -0
  16. package/dist/components/Avatar.js +9 -0
  17. package/dist/components/Avatar.js.map +1 -0
  18. package/dist/components/AvatarGroup.d.ts +25 -0
  19. package/dist/components/AvatarGroup.d.ts.map +1 -0
  20. package/dist/components/AvatarGroup.js +9 -0
  21. package/dist/components/AvatarGroup.js.map +1 -0
  22. package/dist/components/Badge.d.ts +18 -0
  23. package/dist/components/Badge.d.ts.map +1 -0
  24. package/dist/components/Badge.js +7 -0
  25. package/dist/components/Badge.js.map +1 -0
  26. package/dist/components/Blockquote.d.ts +5 -0
  27. package/dist/components/Blockquote.d.ts.map +1 -0
  28. package/dist/components/Blockquote.js +4 -0
  29. package/dist/components/Blockquote.js.map +1 -0
  30. package/dist/components/Breadcrumb.d.ts +12 -0
  31. package/dist/components/Breadcrumb.d.ts.map +1 -0
  32. package/dist/components/Breadcrumb.js +8 -0
  33. package/dist/components/Breadcrumb.js.map +1 -0
  34. package/dist/components/Button.d.ts +42 -0
  35. package/dist/components/Button.d.ts.map +1 -0
  36. package/dist/components/Button.js +25 -0
  37. package/dist/components/Button.js.map +1 -0
  38. package/dist/components/Card.d.ts +19 -0
  39. package/dist/components/Card.d.ts.map +1 -0
  40. package/dist/components/Card.js +5 -0
  41. package/dist/components/Card.js.map +1 -0
  42. package/dist/components/Checkbox.d.ts +14 -0
  43. package/dist/components/Checkbox.d.ts.map +1 -0
  44. package/dist/components/Checkbox.js +7 -0
  45. package/dist/components/Checkbox.js.map +1 -0
  46. package/dist/components/CheckboxGroup.d.ts +53 -0
  47. package/dist/components/CheckboxGroup.d.ts.map +1 -0
  48. package/dist/components/CheckboxGroup.js +17 -0
  49. package/dist/components/CheckboxGroup.js.map +1 -0
  50. package/dist/components/Circle.d.ts +18 -0
  51. package/dist/components/Circle.d.ts.map +1 -0
  52. package/dist/components/Circle.js +5 -0
  53. package/dist/components/Circle.js.map +1 -0
  54. package/dist/components/CitricComponent.d.ts +14 -0
  55. package/dist/components/CitricComponent.d.ts.map +1 -0
  56. package/dist/components/CitricComponent.js +15 -0
  57. package/dist/components/CitricComponent.js.map +1 -0
  58. package/dist/components/Divider.d.ts +14 -0
  59. package/dist/components/Divider.d.ts.map +1 -0
  60. package/dist/components/Divider.js +5 -0
  61. package/dist/components/Divider.js.map +1 -0
  62. package/dist/components/ErrorBoundary.d.ts +32 -0
  63. package/dist/components/ErrorBoundary.d.ts.map +1 -0
  64. package/dist/components/ErrorBoundary.js +46 -0
  65. package/dist/components/ErrorBoundary.js.map +1 -0
  66. package/dist/components/ErrorMessage.d.ts +4 -0
  67. package/dist/components/ErrorMessage.d.ts.map +1 -0
  68. package/dist/components/ErrorMessage.js +7 -0
  69. package/dist/components/ErrorMessage.js.map +1 -0
  70. package/dist/components/FallbackBoundary.d.ts +13 -0
  71. package/dist/components/FallbackBoundary.d.ts.map +1 -0
  72. package/dist/components/FallbackBoundary.js +11 -0
  73. package/dist/components/FallbackBoundary.js.map +1 -0
  74. package/dist/components/Favorite.d.ts +23 -0
  75. package/dist/components/Favorite.d.ts.map +1 -0
  76. package/dist/components/Favorite.js +5 -0
  77. package/dist/components/Favorite.js.map +1 -0
  78. package/dist/components/FieldGroup.d.ts +14 -0
  79. package/dist/components/FieldGroup.d.ts.map +1 -0
  80. package/dist/components/FieldGroup.js +5 -0
  81. package/dist/components/FieldGroup.js.map +1 -0
  82. package/dist/components/Form.d.ts +5 -0
  83. package/dist/components/Form.d.ts.map +1 -0
  84. package/dist/components/Form.js +6 -0
  85. package/dist/components/Form.js.map +1 -0
  86. package/dist/components/FormGroup.d.ts +22 -0
  87. package/dist/components/FormGroup.d.ts.map +1 -0
  88. package/dist/components/FormGroup.js +8 -0
  89. package/dist/components/FormGroup.js.map +1 -0
  90. package/dist/components/IconBox.d.ts +46 -0
  91. package/dist/components/IconBox.d.ts.map +1 -0
  92. package/dist/components/IconBox.js +29 -0
  93. package/dist/components/IconBox.js.map +1 -0
  94. package/dist/components/Input.d.ts +15 -0
  95. package/dist/components/Input.d.ts.map +1 -0
  96. package/dist/components/Input.js +18 -0
  97. package/dist/components/Input.js.map +1 -0
  98. package/dist/components/Link.d.ts +20 -0
  99. package/dist/components/Link.d.ts.map +1 -0
  100. package/dist/components/Link.js +21 -0
  101. package/dist/components/Link.js.map +1 -0
  102. package/dist/components/LoadingPanel.d.ts +2 -0
  103. package/dist/components/LoadingPanel.d.ts.map +1 -0
  104. package/dist/components/LoadingPanel.js +5 -0
  105. package/dist/components/LoadingPanel.js.map +1 -0
  106. package/dist/components/MenuOverlay/Menu.d.ts +6 -0
  107. package/dist/components/MenuOverlay/Menu.d.ts.map +1 -0
  108. package/dist/components/MenuOverlay/Menu.js +100 -0
  109. package/dist/components/MenuOverlay/Menu.js.map +1 -0
  110. package/dist/components/MenuOverlay/context.d.ts +6 -0
  111. package/dist/components/MenuOverlay/context.d.ts.map +1 -0
  112. package/dist/components/MenuOverlay/context.js +16 -0
  113. package/dist/components/MenuOverlay/context.js.map +1 -0
  114. package/dist/components/MenuOverlay/index.d.ts +3 -0
  115. package/dist/components/MenuOverlay/index.d.ts.map +1 -0
  116. package/dist/components/MenuOverlay/index.js +23 -0
  117. package/dist/components/MenuOverlay/index.js.map +1 -0
  118. package/dist/components/MenuOverlay/keyboard.d.ts +2 -0
  119. package/dist/components/MenuOverlay/keyboard.d.ts.map +1 -0
  120. package/dist/components/MenuOverlay/keyboard.js +66 -0
  121. package/dist/components/MenuOverlay/keyboard.js.map +1 -0
  122. package/dist/components/MenuOverlay/types.d.ts +166 -0
  123. package/dist/components/MenuOverlay/types.d.ts.map +1 -0
  124. package/dist/components/MenuOverlay/types.js +2 -0
  125. package/dist/components/MenuOverlay/types.js.map +1 -0
  126. package/dist/components/Overlay/context.d.ts +4 -0
  127. package/dist/components/Overlay/context.d.ts.map +1 -0
  128. package/dist/components/Overlay/context.js +7 -0
  129. package/dist/components/Overlay/context.js.map +1 -0
  130. package/dist/components/Overlay/index.d.ts +14 -0
  131. package/dist/components/Overlay/index.d.ts.map +1 -0
  132. package/dist/components/Overlay/index.js +120 -0
  133. package/dist/components/Overlay/index.js.map +1 -0
  134. package/dist/components/Overlay/types.d.ts +67 -0
  135. package/dist/components/Overlay/types.d.ts.map +1 -0
  136. package/dist/components/Overlay/types.js +2 -0
  137. package/dist/components/Overlay/types.js.map +1 -0
  138. package/dist/components/Pagination.d.ts +28 -0
  139. package/dist/components/Pagination.d.ts.map +1 -0
  140. package/dist/components/Pagination.js +30 -0
  141. package/dist/components/Pagination.js.map +1 -0
  142. package/dist/components/ProgressBar.d.ts +12 -0
  143. package/dist/components/ProgressBar.d.ts.map +1 -0
  144. package/dist/components/ProgressBar.js +7 -0
  145. package/dist/components/ProgressBar.js.map +1 -0
  146. package/dist/components/ProgressCircular.d.ts +16 -0
  147. package/dist/components/ProgressCircular.d.ts.map +1 -0
  148. package/dist/components/ProgressCircular.js +7 -0
  149. package/dist/components/ProgressCircular.js.map +1 -0
  150. package/dist/components/RadioGroup.d.ts +48 -0
  151. package/dist/components/RadioGroup.d.ts.map +1 -0
  152. package/dist/components/RadioGroup.js +17 -0
  153. package/dist/components/RadioGroup.js.map +1 -0
  154. package/dist/components/Rating.d.ts +13 -0
  155. package/dist/components/Rating.d.ts.map +1 -0
  156. package/dist/components/Rating.js +4 -0
  157. package/dist/components/Rating.js.map +1 -0
  158. package/dist/components/Select/RichSelect.d.ts +5 -0
  159. package/dist/components/Select/RichSelect.d.ts.map +1 -0
  160. package/dist/components/Select/RichSelect.js +152 -0
  161. package/dist/components/Select/RichSelect.js.map +1 -0
  162. package/dist/components/Select/SimpleSelect.d.ts +5 -0
  163. package/dist/components/Select/SimpleSelect.d.ts.map +1 -0
  164. package/dist/components/Select/SimpleSelect.js +24 -0
  165. package/dist/components/Select/SimpleSelect.js.map +1 -0
  166. package/dist/components/Select/index.d.ts +4 -0
  167. package/dist/components/Select/index.d.ts.map +1 -0
  168. package/dist/components/Select/index.js +7 -0
  169. package/dist/components/Select/index.js.map +1 -0
  170. package/dist/components/Select/types.d.ts +118 -0
  171. package/dist/components/Select/types.d.ts.map +1 -0
  172. package/dist/components/Select/types.js +2 -0
  173. package/dist/components/Select/types.js.map +1 -0
  174. package/dist/components/SelectBox.d.ts +65 -0
  175. package/dist/components/SelectBox.d.ts.map +1 -0
  176. package/dist/components/SelectBox.js +26 -0
  177. package/dist/components/SelectBox.js.map +1 -0
  178. package/dist/components/Skeleton.d.ts +30 -0
  179. package/dist/components/Skeleton.d.ts.map +1 -0
  180. package/dist/components/Skeleton.js +5 -0
  181. package/dist/components/Skeleton.js.map +1 -0
  182. package/dist/components/Slider.d.ts +32 -0
  183. package/dist/components/Slider.d.ts.map +1 -0
  184. package/dist/components/Slider.js +19 -0
  185. package/dist/components/Slider.js.map +1 -0
  186. package/dist/components/SmartTable.d.ts +87 -0
  187. package/dist/components/SmartTable.d.ts.map +1 -0
  188. package/dist/components/SmartTable.js +16 -0
  189. package/dist/components/SmartTable.js.map +1 -0
  190. package/dist/components/Stepper.d.ts +52 -0
  191. package/dist/components/Stepper.d.ts.map +1 -0
  192. package/dist/components/Stepper.js +53 -0
  193. package/dist/components/Stepper.js.map +1 -0
  194. package/dist/components/Switch.d.ts +10 -0
  195. package/dist/components/Switch.d.ts.map +1 -0
  196. package/dist/components/Switch.js +7 -0
  197. package/dist/components/Switch.js.map +1 -0
  198. package/dist/components/Table.d.ts +106 -0
  199. package/dist/components/Table.d.ts.map +1 -0
  200. package/dist/components/Table.js +86 -0
  201. package/dist/components/Table.js.map +1 -0
  202. package/dist/components/Tabs/TabController.d.ts +11 -0
  203. package/dist/components/Tabs/TabController.d.ts.map +1 -0
  204. package/dist/components/Tabs/TabController.js +39 -0
  205. package/dist/components/Tabs/TabController.js.map +1 -0
  206. package/dist/components/Tabs/index.d.ts +5 -0
  207. package/dist/components/Tabs/index.d.ts.map +1 -0
  208. package/dist/components/Tabs/index.js +37 -0
  209. package/dist/components/Tabs/index.js.map +1 -0
  210. package/dist/components/Tabs/types.d.ts +46 -0
  211. package/dist/components/Tabs/types.d.ts.map +1 -0
  212. package/dist/components/Tabs/types.js +2 -0
  213. package/dist/components/Tabs/types.js.map +1 -0
  214. package/dist/components/Tabs/utils.d.ts +3 -0
  215. package/dist/components/Tabs/utils.d.ts.map +1 -0
  216. package/dist/components/Tabs/utils.js +5 -0
  217. package/dist/components/Tabs/utils.js.map +1 -0
  218. package/dist/components/Text.d.ts +27 -0
  219. package/dist/components/Text.d.ts.map +1 -0
  220. package/dist/components/Text.js +45 -0
  221. package/dist/components/Text.js.map +1 -0
  222. package/dist/components/Textarea.d.ts +8 -0
  223. package/dist/components/Textarea.d.ts.map +1 -0
  224. package/dist/components/Textarea.js +4 -0
  225. package/dist/components/Textarea.js.map +1 -0
  226. package/dist/components/Tooltip.d.ts +25 -0
  227. package/dist/components/Tooltip.d.ts.map +1 -0
  228. package/dist/components/Tooltip.js +18 -0
  229. package/dist/components/Tooltip.js.map +1 -0
  230. package/dist/components/layout.d.ts +46 -0
  231. package/dist/components/layout.d.ts.map +1 -0
  232. package/dist/components/layout.js +18 -0
  233. package/dist/components/layout.js.map +1 -0
  234. package/dist/context/CitricContext.d.ts +3 -0
  235. package/dist/context/CitricContext.d.ts.map +1 -0
  236. package/dist/context/CitricContext.js +3 -0
  237. package/dist/context/CitricContext.js.map +1 -0
  238. package/dist/context/CitricProvider.d.ts +9 -0
  239. package/dist/context/CitricProvider.d.ts.map +1 -0
  240. package/dist/context/CitricProvider.js +8 -0
  241. package/dist/context/CitricProvider.js.map +1 -0
  242. package/dist/context/hooks.d.ts +2 -0
  243. package/dist/context/hooks.d.ts.map +1 -0
  244. package/dist/context/hooks.js +6 -0
  245. package/dist/context/hooks.js.map +1 -0
  246. package/dist/index.d.ts +48 -0
  247. package/dist/index.d.ts.map +1 -0
  248. package/dist/index.js +48 -0
  249. package/dist/index.js.map +1 -0
  250. package/dist/overlay.d.ts +83 -0
  251. package/dist/overlay.d.ts.map +1 -0
  252. package/dist/overlay.js +199 -0
  253. package/dist/overlay.js.map +1 -0
  254. package/dist/theme.css +419 -0
  255. package/dist/types.d.ts +175 -0
  256. package/dist/types.d.ts.map +1 -0
  257. package/dist/types.js +2 -0
  258. package/dist/types.js.map +1 -0
  259. package/dist/utils/ValueController.d.ts +10 -0
  260. package/dist/utils/ValueController.d.ts.map +1 -0
  261. package/dist/utils/ValueController.js +32 -0
  262. package/dist/utils/ValueController.js.map +1 -0
  263. package/dist/utils/acessibility.d.ts +52 -0
  264. package/dist/utils/acessibility.d.ts.map +1 -0
  265. package/dist/utils/acessibility.js +80 -0
  266. package/dist/utils/acessibility.js.map +1 -0
  267. package/dist/utils/css.d.ts +12 -0
  268. package/dist/utils/css.d.ts.map +1 -0
  269. package/dist/utils/css.js +72 -0
  270. package/dist/utils/css.js.map +1 -0
  271. package/dist/utils/options.d.ts +3 -0
  272. package/dist/utils/options.d.ts.map +1 -0
  273. package/dist/utils/options.js +7 -0
  274. package/dist/utils/options.js.map +1 -0
  275. package/package.json +51 -0
  276. package/scripts/build-css.ts +49 -0
  277. package/src/components/Accordion.tsx +74 -0
  278. package/src/components/Alert.tsx +16 -0
  279. package/src/components/AsyncContent.tsx +54 -0
  280. package/src/components/Avatar.tsx +34 -0
  281. package/src/components/AvatarGroup.tsx +40 -0
  282. package/src/components/Badge.tsx +28 -0
  283. package/src/components/Blockquote.tsx +9 -0
  284. package/src/components/Breadcrumb.tsx +24 -0
  285. package/src/components/Button.tsx +88 -0
  286. package/src/components/Card.tsx +32 -0
  287. package/src/components/Checkbox.tsx +36 -0
  288. package/src/components/CheckboxGroup.tsx +93 -0
  289. package/src/components/Circle.tsx +26 -0
  290. package/src/components/CitricComponent.ts +34 -0
  291. package/src/components/Divider.tsx +22 -0
  292. package/src/components/ErrorBoundary.tsx +62 -0
  293. package/src/components/ErrorMessage.tsx +11 -0
  294. package/src/components/FallbackBoundary.tsx +29 -0
  295. package/src/components/Favorite.tsx +37 -0
  296. package/src/components/FieldGroup.tsx +22 -0
  297. package/src/components/Form.tsx +17 -0
  298. package/src/components/FormGroup.tsx +45 -0
  299. package/src/components/IconBox.tsx +78 -0
  300. package/src/components/Input.tsx +32 -0
  301. package/src/components/Link.tsx +40 -0
  302. package/src/components/LoadingPanel.tsx +8 -0
  303. package/src/components/MenuOverlay/Menu.tsx +157 -0
  304. package/src/components/MenuOverlay/context.ts +20 -0
  305. package/src/components/MenuOverlay/index.tsx +35 -0
  306. package/src/components/MenuOverlay/keyboard.ts +60 -0
  307. package/src/components/MenuOverlay/types.ts +178 -0
  308. package/src/components/Overlay/context.ts +10 -0
  309. package/src/components/Overlay/index.tsx +137 -0
  310. package/src/components/Overlay/types.ts +71 -0
  311. package/src/components/Pagination.tsx +90 -0
  312. package/src/components/ProgressBar.tsx +25 -0
  313. package/src/components/ProgressCircular.tsx +29 -0
  314. package/src/components/RadioGroup.tsx +87 -0
  315. package/src/components/Rating.tsx +25 -0
  316. package/src/components/Select/RichSelect.tsx +214 -0
  317. package/src/components/Select/SimpleSelect.tsx +66 -0
  318. package/src/components/Select/index.tsx +8 -0
  319. package/src/components/Select/types.ts +121 -0
  320. package/src/components/SelectBox.tsx +134 -0
  321. package/src/components/Skeleton.tsx +41 -0
  322. package/src/components/Slider.tsx +77 -0
  323. package/src/components/SmartTable.tsx +148 -0
  324. package/src/components/Stepper.tsx +142 -0
  325. package/src/components/Switch.tsx +29 -0
  326. package/src/components/Table.tsx +219 -0
  327. package/src/components/Tabs/TabController.ts +40 -0
  328. package/src/components/Tabs/index.tsx +64 -0
  329. package/src/components/Tabs/types.ts +48 -0
  330. package/src/components/Tabs/utils.ts +6 -0
  331. package/src/components/Text.ts +75 -0
  332. package/src/components/Textarea.tsx +12 -0
  333. package/src/components/Tooltip.tsx +53 -0
  334. package/src/components/layout.tsx +53 -0
  335. package/src/context/CitricContext.tsx +4 -0
  336. package/src/context/CitricProvider.tsx +14 -0
  337. package/src/context/hooks.ts +6 -0
  338. package/src/index.ts +47 -0
  339. package/src/overlay.ts +276 -0
  340. package/src/types.ts +226 -0
  341. package/src/utils/ValueController.ts +28 -0
  342. package/src/utils/acessibility.ts +92 -0
  343. package/src/utils/css.ts +106 -0
  344. package/src/utils/options.ts +7 -0
  345. package/tsconfig.json +10 -0
@@ -0,0 +1,121 @@
1
+ import { HTMLExtension, WithColorScheme } from '../../types'
2
+
3
+ interface CommonSelectProps<T> extends WithColorScheme {
4
+ /**
5
+ * All the items (options) to render.
6
+ */
7
+ options: T[],
8
+ /**
9
+ * If the value is undefined or "", an empty option is rendered. This option will disappear as soon as a valid option is selected, unless
10
+ * "required" is set to false.
11
+ */
12
+ value?: T,
13
+ /**
14
+ * Called whenever the selected option changes.
15
+ * @param value the currently selected item.
16
+ */
17
+ onChange?: (value: T | undefined) => void,
18
+ /**
19
+ * A function to render the item label.
20
+ * @example
21
+ * `(option) => option.name`
22
+ * @default "the item's toString() result."
23
+ * @param option the item to render.
24
+ * @returns a React Node to render.
25
+ */
26
+ renderLabel?: (value: T) => string,
27
+ /**
28
+ * A function to render the item value, a unique identifier for the option.
29
+ * @example
30
+ * `(option) => option.id`
31
+ * @default "if the item is a string or a number, the stringified item. Otherwise, undefined."
32
+ * @param option the item to compute a key for.
33
+ * @returns a string key.
34
+ */
35
+ renderKey?: (value: T) => string | number | undefined,
36
+ /**
37
+ * Whether or not this input is required. This is also used to figure out if an empty option should be rendered or not.
38
+ *
39
+ * An empty option is rendered whenever "required" is false or "value" is "" or undefined.
40
+ * @default true
41
+ */
42
+ required?: boolean,
43
+ /**
44
+ * Whether or not to show a loading feedback to the user.
45
+ *
46
+ * Attention: selects that are loading should normally also be disabled.
47
+ */
48
+ loading?: boolean,
49
+ /**
50
+ * Whether or not this field is disabled.
51
+ * @default false
52
+ */
53
+ disabled?: boolean,
54
+ /**
55
+ * Function to run when the element receives focus. If the native select element received focus, a Select element is the target, otherwise
56
+ * the wrapping div element is.
57
+ *
58
+ * If `rich` is false, the target will always be a select element.
59
+ */
60
+ onFocus?: React.EventHandler<React.FocusEvent<HTMLDivElement | HTMLSelectElement>>,
61
+ /**
62
+ * Function to run when the element loses focus. If the native select element received focus, a Select element is the target, otherwise
63
+ * the wrapping div element is.
64
+ *
65
+ * If `rich` is false, the target will always be a select element.
66
+ */
67
+ onBlur?: React.EventHandler<React.FocusEvent<HTMLDivElement | HTMLSelectElement>>,
68
+ /**
69
+ * If the type is "simple", the native select element is rendered.
70
+ *
71
+ * If the type is "rich", a custom select is rendered and more options are enabled, like "searchable".
72
+ *
73
+ * @default 'rich'
74
+ */
75
+ type?: 'simple' | 'rich',
76
+ }
77
+
78
+ export interface SimpleSelectProps<T> extends CommonSelectProps<T> {
79
+ type: 'simple',
80
+ }
81
+
82
+ export interface RichSelectProps<T> extends CommonSelectProps<T> {
83
+ type?: 'rich',
84
+ /**
85
+ * Whether or not to render a search field. The search is based on the value returned by `renderLabel`.
86
+ *
87
+ * @default false
88
+ */
89
+ searchable?: boolean,
90
+ /**
91
+ * A function to render the option in the selectable list.
92
+ *
93
+ * The `renderLabel` function is used if this is not provided.
94
+ * @param value the option.
95
+ * @returns the React Node.
96
+ */
97
+ renderOption?: (value: T) => React.ReactNode,
98
+ /**
99
+ * A function to render the selected option in the header.
100
+ *
101
+ * The `renderOption` function is used if this is not provided.
102
+ * @param value the option.
103
+ * @returns the React Node.
104
+ */
105
+ renderHeader?: (value: T | undefined) => React.ReactNode,
106
+ /**
107
+ * The maximum height of the options list in pixels.
108
+ *
109
+ * @default 300
110
+ */
111
+ maxHeight?: number,
112
+ /**
113
+ * Whether or not to show the arrow inside the select's header.
114
+ * @default true
115
+ */
116
+ showArrow?: boolean,
117
+ }
118
+
119
+ export type BaseSelectProps<T> = SimpleSelectProps<T> | RichSelectProps<T>
120
+
121
+ export type SelectProps<T> = HTMLExtension<'div', BaseSelectProps<T>, 'onChange' | 'children'>
@@ -0,0 +1,134 @@
1
+ import { listToClass } from '@stack-spot/portal-theme'
2
+ import { useMemo } from 'react'
3
+ import { HTMLExtension, WithColorPalette, WithColorScheme } from '../types'
4
+ import { defaultRenderKey, defaultRenderLabel } from '../utils/options'
5
+ import { CitricComponent } from './CitricComponent'
6
+ import { layout } from './layout'
7
+
8
+ export interface SelectBoxLabel {
9
+ icon?: React.ReactElement,
10
+ title: string,
11
+ description?: string,
12
+ }
13
+
14
+ export interface CommonSelectBoxProps<T> extends WithColorPalette, WithColorScheme {
15
+ /**
16
+ * If multiple is true, checkboxes will be rendered instead of radio buttons.
17
+ *
18
+ * @default false
19
+ */
20
+ multiple?: boolean,
21
+ /**
22
+ * The name for all checkboxes or radio buttons.
23
+ */
24
+ name?: string,
25
+ /**
26
+ * The options to show as select boxes.
27
+ */
28
+ options: T[],
29
+ /**
30
+ * A function that returns the data to render a select box for an option.
31
+ *
32
+ * @default "extracts the title by converting the option to a string"
33
+ */
34
+ renderLabel?: (option: T) => SelectBoxLabel,
35
+ /**
36
+ * A function that returns a unique identifier for an option.
37
+ *
38
+ * @default "if the option is a string, uses it as the key. Otherwise, the key won't be specified."
39
+ */
40
+ renderKey?: (option: T) => string | number | undefined,
41
+ /**
42
+ * A function that receives an option and decides if it's disabled or not.
43
+ */
44
+ isDisabled?: (option: T) => boolean,
45
+ /**
46
+ * Whether to render a row (horizontal) or a column (vertical).
47
+ *
48
+ * @default 'horizontal'
49
+ */
50
+ direction?: 'horizontal' | 'vertical',
51
+ /**
52
+ * The background color level.
53
+ *
54
+ * @default 300
55
+ */
56
+ bgLevel?: 300 | 400 | 500 | 600 | 700,
57
+ }
58
+
59
+ interface CheckboxProps<T> extends CommonSelectBoxProps<T> {
60
+ multiple: true,
61
+ value?: T[],
62
+ onChange?: (value: T[]) => void,
63
+ }
64
+
65
+ interface RadioProps<T> extends CommonSelectBoxProps<T> {
66
+ multiple?: false,
67
+ value?: T,
68
+ onChange?: (value: T) => void,
69
+ }
70
+
71
+ export type BaseSelectBoxProps<T> = RadioProps<T> | CheckboxProps<T>
72
+
73
+ export type SelectBoxProps<T> = HTMLExtension<'div', BaseSelectBoxProps<T>, 'onChange'>
74
+
75
+ export function SelectBox<T>({
76
+ multiple,
77
+ name,
78
+ value,
79
+ options,
80
+ onChange,
81
+ renderLabel = o => ({ title: defaultRenderLabel(o) }),
82
+ renderKey = defaultRenderKey,
83
+ isDisabled,
84
+ className,
85
+ style,
86
+ direction,
87
+ bgLevel,
88
+ colorPalette,
89
+ colorScheme,
90
+ ...props
91
+ }: SelectBoxProps<T>) {
92
+ const items = useMemo(() => {
93
+ const valueAsArray = value ? (Array.isArray(value) ? value : [value]) : []
94
+ const valueKeys = valueAsArray.map(renderKey)
95
+ return options.map((o) => {
96
+ const key = renderKey(o)
97
+ const label = renderLabel(o)
98
+ return (
99
+ <CitricComponent key={key} tag="label" component="select-box" className={bgLevel ? `bg-${bgLevel}` : undefined}>
100
+ <input
101
+ type={multiple ? 'checkbox' : 'radio'}
102
+ name={name}
103
+ value={key}
104
+ checked={value ? valueKeys.includes(key) : undefined}
105
+ disabled={isDisabled?.(o)}
106
+ onChange={onChange ? (e) => {
107
+ if (multiple) {
108
+ onChange(e.target.checked ? [...valueAsArray, o] : valueAsArray.filter(v => renderKey(v) !== key))
109
+ } else {
110
+ onChange(o)
111
+ }
112
+ } : undefined}
113
+ />
114
+ <div className="option">
115
+ {label.icon}
116
+ <p className="title">{label.title}</p>
117
+ {label.description && <p className="description">{label.description}</p>}
118
+ </div>
119
+ </CitricComponent>
120
+ )
121
+ })
122
+ }, [options, value, name, multiple, bgLevel])
123
+ return (
124
+ <div
125
+ data-color-palette={colorPalette}
126
+ data-color-scheme={colorScheme}
127
+ className={listToClass([className, direction === 'vertical' ? layout.column : layout.row])}
128
+ style={{ gap: '5px', ...style }}
129
+ {...props}
130
+ >
131
+ {items}
132
+ </div>
133
+ )
134
+ }
@@ -0,0 +1,41 @@
1
+ import { listToClass } from '@stack-spot/portal-theme'
2
+ import { HTMLExtension } from '../types'
3
+ import { CitricComponent } from './CitricComponent'
4
+
5
+ export interface BaseSkeletonProps {
6
+ /**
7
+ * The skeleton's appearance.
8
+ *
9
+ * @default 'square'
10
+ */
11
+ appearance?: 'square' | 'circle',
12
+ /**
13
+ * The skeleton's width.
14
+ *
15
+ * @default "the available width if 'square', 50px if 'circle'".
16
+ */
17
+ width?: string,
18
+ /**
19
+ * The skeleton's width.
20
+ *
21
+ * @default "32px if 'square', 50px if 'circle'".
22
+ */
23
+ height?: string,
24
+ /**
25
+ * The background color level.
26
+ *
27
+ * @default 500
28
+ */
29
+ bgLevel?: 400 | 500 | 600,
30
+ }
31
+
32
+ export type SkeletonProps = HTMLExtension<'div', BaseSkeletonProps, 'children'>
33
+
34
+ export const Skeleton = ({ appearance, className, style, width, height, bgLevel, ...props }: SkeletonProps) =>
35
+ <CitricComponent
36
+ tag="div"
37
+ component="skeleton"
38
+ className={listToClass([appearance, bgLevel && `bg-${bgLevel}`, className])}
39
+ style={{ width, height, ...style }}
40
+ {...props}
41
+ />
@@ -0,0 +1,77 @@
1
+ import { listToClass } from '@stack-spot/portal-theme'
2
+ import { HTMLExtension, WithColorPalette, WithColorScheme } from '../types'
3
+ import { applyCSSVariable } from '../utils/css'
4
+ import { CitricComponent } from './CitricComponent'
5
+
6
+ export interface BaseSliderProps extends WithColorScheme, WithColorPalette {
7
+ value: number,
8
+ /**
9
+ * The minimum value in the numeric range.
10
+ *
11
+ * @default 0
12
+ */
13
+ min?: number,
14
+ /**
15
+ * The maximum value in the numeric range.
16
+ *
17
+ * @default 100
18
+ */
19
+ max?: number,
20
+ onChange: (value: number) => void,
21
+ /**
22
+ * When should we render the current value of the input?
23
+ *
24
+ * @default 'always'
25
+ */
26
+ showValue?: 'always' | 'hover' | 'never',
27
+ /**
28
+ * A function to customize how the value of the input is rendered.
29
+ *
30
+ * @default "{value}% if 'min' and 'max' are not provided. {value} otherwise."
31
+ */
32
+ renderValue?: (value: number) => string,
33
+ }
34
+
35
+ export type SliderProps = HTMLExtension<'input', BaseSliderProps, 'children' | 'type' | 'value' | 'onChange'>
36
+
37
+ export const Slider = (
38
+ { value, onChange, min, max, style, showValue, renderValue, colorPalette, colorScheme, className, ...props }: SliderProps,
39
+ ) => {
40
+ const percent = Math.floor((value / ((max ?? 100) - (min ?? 0))) * 100)
41
+ style = applyCSSVariable(style, 'percent', percent)
42
+ const rangeProps = {
43
+ value,
44
+ min,
45
+ max,
46
+ onChange: (e: React.ChangeEvent<HTMLInputElement>) => onChange(parseInt(e.target.value)),
47
+ ...props,
48
+ }
49
+
50
+ return showValue === 'never'
51
+ ? <CitricComponent
52
+ tag="input"
53
+ type="range"
54
+ component="slider"
55
+ style={style}
56
+ className={className}
57
+ colorPalette={colorPalette}
58
+ colorScheme={colorScheme}
59
+ {...rangeProps}
60
+ />
61
+ : (
62
+ <CitricComponent
63
+ tag="div"
64
+ component="labeled-slider"
65
+ style={style}
66
+ colorPalette={colorPalette}
67
+ colorScheme={colorScheme}
68
+ className={listToClass([className, showValue === 'hover' && 'value-on-hover'])}
69
+ >
70
+ <input type="range" {...rangeProps} />
71
+ <div className="value">
72
+ {renderValue ? renderValue(value) : `${value}${min === undefined && max === undefined ? '%' : ''}`}
73
+ </div>
74
+ </CitricComponent>
75
+ )
76
+ }
77
+
@@ -0,0 +1,148 @@
1
+ import { useMemo } from 'react'
2
+ import { BaseTableProps, SortingDirection, Table, TableProps, Th, Tr } from './Table'
3
+
4
+ export type TableColumn<T> = {
5
+ /**
6
+ * A unique identifier for the column.
7
+ */
8
+ key: string,
9
+ /**
10
+ * A label to use as the column's header.
11
+ *
12
+ * If not provided, the key will be used.
13
+ */
14
+ label?: React.ReactNode,
15
+ /**
16
+ * A custom render function. It receives the item (row) and must return a React node.
17
+ *
18
+ * If not provided, the value of `item[key]` will be converted to a string and used. If it's undefined, an empty string is rendered.
19
+ *
20
+ * @param item the current item.
21
+ * @returns the React Node to render.
22
+ */
23
+ render?: (item: T) => React.ReactNode,
24
+ /**
25
+ * What to do when the header is clicked (sorting)
26
+ */
27
+ onSort?: (value: SortingDirection | undefined) => void,
28
+ /**
29
+ * Which is the current direction of the sorting? Only relevant if 'onSort' is set.
30
+ *
31
+ * @default 'desc'
32
+ */
33
+ direction?: SortingDirection,
34
+ /**
35
+ * Additional properties for the "th" corresponding to this column.
36
+ */
37
+ th?: Omit<JSX.IntrinsicElements['th'], 'children'>,
38
+ /**
39
+ * Additional properties for the "td" corresponding to this column.
40
+ */
41
+ td?: Omit<JSX.IntrinsicElements['td'], 'children'>,
42
+ }
43
+
44
+ interface ExtraSmartTableProps<T extends Record<string, any>> {
45
+ /**
46
+ * An array where each item is a row in the table.
47
+ */
48
+ data: T[],
49
+ /**
50
+ * A function to generate a unique key for each item. If not provided, the item's index will be used.
51
+ * @param item
52
+ * @returns a unique key
53
+ */
54
+ keygen?: (item: T) => React.Key,
55
+ /**
56
+ * The columns to display in the table.
57
+ *
58
+ * Attention: always save your columns with `useMemo` to avoid unnecessary rerenders.
59
+ */
60
+ columns: TableColumn<T>[],
61
+ /**
62
+ * If set, an extra row and column for each item is rendered. The extra row is collapsed by default and can be expanded through a button
63
+ * that is placed in the extra column.
64
+ *
65
+ * The extra row is, effectively, an accordion. The content of this accordion is defined by whatever this function returns.
66
+ *
67
+ * @param item the current item.
68
+ * @returns the React Node to render.
69
+ */
70
+ renderAccordion?: (item: T) => React.ReactNode,
71
+ /**
72
+ * What should make the accordions expand or contract? A click on a button in the last column or a click anywhere in the row?
73
+ *
74
+ * Only valid if `renderAccordion` is set.
75
+ *
76
+ * @default 'button'
77
+ */
78
+ accordionTrigger?: 'button' | 'row',
79
+ /**
80
+ * The maximum height for accordion rows.
81
+ *
82
+ * @default '200px'
83
+ */
84
+ accordionMaxHeight?: string,
85
+ }
86
+
87
+ export type BaseSmartTableProps<T extends Record<string, any>> = BaseTableProps & ExtraSmartTableProps<T>
88
+
89
+ export type SmartTableProps<T extends Record<string, any>> = Omit<TableProps, 'children'> & ExtraSmartTableProps<T>
90
+
91
+ export function SmartTable<T extends Record<string, any>>(
92
+ { data, keygen, columns, renderAccordion, accordionTrigger, accordionMaxHeight, id, ...props }: SmartTableProps<T>,
93
+ ) {
94
+ id = useMemo(() => id || `${Math.random()}`, [id])
95
+
96
+ const headers = useMemo(
97
+ () => columns.map((c) => (
98
+ <Th {...c.th} key={c.key} onSort={c.onSort} direction={c.direction} tabIndex={c.onSort ? 0 : undefined}>
99
+ {c.label ?? c.key}
100
+ </Th>
101
+ )),
102
+ [columns],
103
+ )
104
+
105
+ const rows = useMemo(
106
+ () => data.map((item, index) => {
107
+ const key = keygen ? keygen(item) : index
108
+ const accordionContent = renderAccordion?.(item)
109
+ const row = (
110
+ <Tr key={key} accordionTrigger={accordionContent ? accordionTrigger : undefined}>
111
+ {columns.map(c => <td {...c.td} key={c.key}>{c.render ? c.render(item) : (item[c.key] || '')}</td>)}
112
+ {renderAccordion && (
113
+ <td>
114
+ {accordionContent && (
115
+ <input
116
+ type="checkbox"
117
+ aria-controls={`${id}-${key}`}
118
+ onKeyDown={e => e.key === 'Enter' && e.target instanceof HTMLElement && e.target.click()}
119
+ />
120
+ )}
121
+ </td>
122
+ )}
123
+ </Tr>
124
+ )
125
+ return renderAccordion ? (
126
+ <tbody key={`${key}-group`}>
127
+ {row}
128
+ <Tr id={`${id}-${key}`} accordion accordionMaxHeight={accordionMaxHeight}>
129
+ <td colSpan={columns.length + 1}><div>{accordionContent}</div></td>
130
+ </Tr>
131
+ </tbody>
132
+ ) : row
133
+ }),
134
+ [columns, data, !!renderAccordion, accordionTrigger],
135
+ )
136
+
137
+ return (
138
+ <Table id={id} accordionRows={!!renderAccordion} {...props}>
139
+ <thead>
140
+ <tr>
141
+ {headers}
142
+ {renderAccordion && <th></th>}
143
+ </tr>
144
+ </thead>
145
+ {renderAccordion ? rows : <tbody>{rows}</tbody>}
146
+ </Table>
147
+ )
148
+ }
@@ -0,0 +1,142 @@
1
+ import { listToClass } from '@stack-spot/portal-theme'
2
+ import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
3
+ import { useCallback, useEffect, useMemo, useState } from 'react'
4
+ import { HTMLExtension } from '../types'
5
+ import { Button } from './Button'
6
+ import { Column, Row } from './layout'
7
+ import { Tabs } from './Tabs'
8
+ import { TabController } from './Tabs/TabController'
9
+ import { BaseTabsProps, Tab } from './Tabs/types'
10
+ import { findSelectedIndex } from './Tabs/utils'
11
+
12
+ export interface BaseStepperProps<Key extends string> extends BaseTabsProps<Key> {
13
+ /**
14
+ * Should we show buttons to control the step we are in?
15
+ *
16
+ * Set it to false to not show any buttons, set it to true to show a default set of buttons, set it to an object to customize the buttons.
17
+ *
18
+ * @default true
19
+ */
20
+ buttons?: boolean | {
21
+ /**
22
+ * The text for the previous button.
23
+ */
24
+ previous?: string,
25
+ /**
26
+ * The text for the next button.
27
+ */
28
+ next?: string,
29
+ /**
30
+ * The text for the finish button.
31
+ */
32
+ finish?: string,
33
+ /**
34
+ * The text for the cancel button.
35
+ */
36
+ cancel?: string,
37
+ /**
38
+ * When set, instead of not showing a previous button in the first step, it shows a cancel button. This function is run whenever the
39
+ * cancel button is clicked.
40
+ */
41
+ onCancel?: () => void,
42
+ /**
43
+ * An additional function to run whenever the previous button is clicked. Return false to prevent the default action (going to the
44
+ * previous step).
45
+ */
46
+ onPrevious?: (tab: Key) => void | boolean,
47
+ /**
48
+ * An additional function to run whenever the next button is clicked. Return false to prevent the default action (going to the
49
+ * next step).
50
+ */
51
+ onNext?: (tab: Key) => void | boolean,
52
+ /**
53
+ * When set, instead of not showing a next button in the final step, it shows a finish button. This function is run whenever the
54
+ * finish button is clicked.
55
+ */
56
+ onFinish?: () => void,
57
+ },
58
+ }
59
+
60
+ export type StepperProps<Key extends string> = HTMLExtension<'div', BaseStepperProps<Key>, 'children' | 'value' | 'onChange'>
61
+
62
+ function getTabsWithDisabled<Key extends string>(tabs: Tab<Key>[], value: Key | undefined) {
63
+ let index = findSelectedIndex(tabs, value ?? '')
64
+ if (index < 0) index = 0
65
+ return tabs.map((t, i) => ({ ...t, disabled: i > index }))
66
+ }
67
+
68
+ export function Stepper<Key extends string>(
69
+ { tabs: initialTabs, controller: ctrl, value, onChange, buttons = true, className, ...props }: StepperProps<Key>,
70
+ ) {
71
+ const controller = useMemo(
72
+ () => ctrl ?? new TabController<Key>(initialTabs.map(t => t.key), value || initialTabs[0]?.key),
73
+ [],
74
+ )
75
+ const [tabs, setTabs] = useState(getTabsWithDisabled(initialTabs, value))
76
+ const [selectedIndex, setSelectedIndex] = useState(findSelectedIndex(tabs, controller.getValue()))
77
+ const t = useTranslate(dictionary)
78
+
79
+ useEffect(() => controller.onChange((v) => {
80
+ setSelectedIndex(findSelectedIndex(tabs, v))
81
+ }), [tabs])
82
+
83
+ useEffect(() => controller.onChange((value) => {
84
+ setTabs(getTabsWithDisabled(initialTabs, value))
85
+ }), [])
86
+
87
+ const onPrevious = useCallback(() => {
88
+ controller.previous()
89
+ if (typeof buttons === 'object') buttons.onPrevious?.(controller.getValue())
90
+ }, [])
91
+
92
+ const onNext = useCallback(() => {
93
+ controller.next()
94
+ if (typeof buttons === 'object') buttons.onNext?.(controller.getValue())
95
+ }, [])
96
+
97
+ return buttons ? (
98
+ <Column {...props} className={className} gap="20px">
99
+ <Tabs tabs={tabs} controller={controller} value={value} onChange={onChange} className="stepper" />
100
+ <Row justifyContent={(typeof buttons !== 'object' || !buttons.onCancel) && selectedIndex === 0 ? 'end' : 'space-between'}>
101
+ {selectedIndex === 0 && typeof buttons === 'object' && buttons.onCancel && (
102
+ <Button onClick={buttons.onCancel} colorScheme="inverse" appearance="outlined">{buttons.cancel || t.cancel}</Button>
103
+ )}
104
+ {selectedIndex > 0 && buttons && (
105
+ <Button onClick={onPrevious} colorScheme="inverse" appearance="outlined">
106
+ {(typeof buttons === 'object' && buttons.previous) || t.previous}
107
+ </Button>
108
+ )}
109
+ {selectedIndex < tabs.length - 1 && buttons && (
110
+ <Button onClick={onNext}>
111
+ {(typeof buttons === 'object' && buttons.next) || t.next}
112
+ </Button>
113
+ )}
114
+ {selectedIndex === tabs.length - 1 && typeof buttons === 'object' && buttons.onFinish && (
115
+ <Button onClick={buttons.onFinish}>{buttons.finish || t.finish}</Button>
116
+ )}
117
+ </Row>
118
+ </Column>
119
+ ) : <Tabs
120
+ tabs={tabs}
121
+ controller={controller}
122
+ value={value}
123
+ onChange={onChange}
124
+ className={listToClass([className, 'stepper'])}
125
+ {...props}
126
+ />
127
+ }
128
+
129
+ const dictionary = {
130
+ en: {
131
+ cancel: 'Cancel',
132
+ previous: 'Previous',
133
+ next: 'Next',
134
+ finish: 'Finish',
135
+ },
136
+ pt: {
137
+ cancel: 'Cancelar',
138
+ previous: 'Anterior',
139
+ next: 'Próximo',
140
+ finish: 'Finalizar',
141
+ },
142
+ } satisfies Dictionary
@@ -0,0 +1,29 @@
1
+ import { HTMLExtension, WithColorScheme } from '../types'
2
+ import { CitricComponent } from './CitricComponent'
3
+
4
+ interface Props extends WithColorScheme {
5
+ value?: boolean,
6
+ onChange?: (value: boolean) => void,
7
+ children?: React.ReactNode,
8
+ }
9
+
10
+ export type SwitchProps = HTMLExtension<'input', Props, 'type'>
11
+
12
+ export const Switch = ({ value, onChange, children, className, style, ...props }: SwitchProps) => {
13
+ const handleChange = onChange ? () => onChange(!value) : undefined
14
+ return children ? (
15
+ <CitricComponent tag="label" component="switch-row" style={style} className={className}>
16
+ <input type="checkbox" checked={value} onChange={handleChange} {...props} />
17
+ {children}
18
+ </CitricComponent>
19
+ ) : <CitricComponent
20
+ tag="input"
21
+ type="checkbox"
22
+ component="switch"
23
+ checked={value}
24
+ onChange={handleChange}
25
+ className={className}
26
+ style={style}
27
+ {...props}
28
+ />
29
+ }