@stack-spot/citric-react 0.22.0 → 0.23.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 (258) hide show
  1. package/dist/citric.css +17 -4
  2. package/dist/components/Accordion.d.ts +34 -0
  3. package/dist/components/Accordion.d.ts.map +1 -1
  4. package/dist/components/Accordion.js +34 -0
  5. package/dist/components/Accordion.js.map +1 -1
  6. package/dist/components/Alert.d.ts +8 -0
  7. package/dist/components/Alert.d.ts.map +1 -1
  8. package/dist/components/Alert.js +8 -0
  9. package/dist/components/Alert.js.map +1 -1
  10. package/dist/components/AsyncContent.d.ts +18 -4
  11. package/dist/components/AsyncContent.d.ts.map +1 -1
  12. package/dist/components/AsyncContent.js +18 -4
  13. package/dist/components/AsyncContent.js.map +1 -1
  14. package/dist/components/Avatar.d.ts +9 -0
  15. package/dist/components/Avatar.d.ts.map +1 -1
  16. package/dist/components/Avatar.js +11 -1
  17. package/dist/components/Avatar.js.map +1 -1
  18. package/dist/components/AvatarGroup.d.ts +8 -0
  19. package/dist/components/AvatarGroup.d.ts.map +1 -1
  20. package/dist/components/AvatarGroup.js +8 -0
  21. package/dist/components/AvatarGroup.js.map +1 -1
  22. package/dist/components/Badge.d.ts +13 -2
  23. package/dist/components/Badge.d.ts.map +1 -1
  24. package/dist/components/Badge.js +14 -3
  25. package/dist/components/Badge.js.map +1 -1
  26. package/dist/components/Blockquote.d.ts +8 -0
  27. package/dist/components/Blockquote.d.ts.map +1 -1
  28. package/dist/components/Blockquote.js +8 -0
  29. package/dist/components/Blockquote.js.map +1 -1
  30. package/dist/components/Breadcrumb.d.ts +8 -0
  31. package/dist/components/Breadcrumb.d.ts.map +1 -1
  32. package/dist/components/Breadcrumb.js +10 -1
  33. package/dist/components/Breadcrumb.js.map +1 -1
  34. package/dist/components/Button.d.ts +11 -0
  35. package/dist/components/Button.d.ts.map +1 -1
  36. package/dist/components/Button.js +14 -2
  37. package/dist/components/Button.js.map +1 -1
  38. package/dist/components/Card.d.ts +15 -4
  39. package/dist/components/Card.d.ts.map +1 -1
  40. package/dist/components/Card.js +13 -1
  41. package/dist/components/Card.js.map +1 -1
  42. package/dist/components/Checkbox.d.ts +14 -0
  43. package/dist/components/Checkbox.d.ts.map +1 -1
  44. package/dist/components/Checkbox.js +14 -0
  45. package/dist/components/Checkbox.js.map +1 -1
  46. package/dist/components/CheckboxGroup.d.ts +22 -3
  47. package/dist/components/CheckboxGroup.d.ts.map +1 -1
  48. package/dist/components/CheckboxGroup.js +23 -3
  49. package/dist/components/CheckboxGroup.js.map +1 -1
  50. package/dist/components/Circle.d.ts +16 -0
  51. package/dist/components/Circle.d.ts.map +1 -1
  52. package/dist/components/Circle.js +8 -0
  53. package/dist/components/Circle.js.map +1 -1
  54. package/dist/components/CitricComponent.d.ts +14 -0
  55. package/dist/components/CitricComponent.d.ts.map +1 -1
  56. package/dist/components/CitricComponent.js +14 -0
  57. package/dist/components/CitricComponent.js.map +1 -1
  58. package/dist/components/Divider.d.ts +4 -1
  59. package/dist/components/Divider.d.ts.map +1 -1
  60. package/dist/components/Divider.js +4 -1
  61. package/dist/components/Divider.js.map +1 -1
  62. package/dist/components/ErrorBoundary.d.ts +13 -0
  63. package/dist/components/ErrorBoundary.d.ts.map +1 -1
  64. package/dist/components/ErrorBoundary.js +13 -0
  65. package/dist/components/ErrorBoundary.js.map +1 -1
  66. package/dist/components/ErrorMessage.js +1 -1
  67. package/dist/components/ErrorMessage.js.map +1 -1
  68. package/dist/components/FallbackBoundary.d.ts +12 -1
  69. package/dist/components/FallbackBoundary.d.ts.map +1 -1
  70. package/dist/components/FallbackBoundary.js +12 -1
  71. package/dist/components/FallbackBoundary.js.map +1 -1
  72. package/dist/components/Favorite.d.ts +12 -0
  73. package/dist/components/Favorite.d.ts.map +1 -1
  74. package/dist/components/Favorite.js +12 -0
  75. package/dist/components/Favorite.js.map +1 -1
  76. package/dist/components/FieldGroup.d.ts +13 -0
  77. package/dist/components/FieldGroup.d.ts.map +1 -1
  78. package/dist/components/FieldGroup.js +13 -0
  79. package/dist/components/FieldGroup.js.map +1 -1
  80. package/dist/components/Form.d.ts +18 -0
  81. package/dist/components/Form.d.ts.map +1 -1
  82. package/dist/components/Form.js +18 -0
  83. package/dist/components/Form.js.map +1 -1
  84. package/dist/components/FormGroup.d.ts +12 -0
  85. package/dist/components/FormGroup.d.ts.map +1 -1
  86. package/dist/components/FormGroup.js +12 -0
  87. package/dist/components/FormGroup.js.map +1 -1
  88. package/dist/components/IconBox.d.ts +33 -8
  89. package/dist/components/IconBox.d.ts.map +1 -1
  90. package/dist/components/IconBox.js +37 -11
  91. package/dist/components/IconBox.js.map +1 -1
  92. package/dist/components/ImageBox.d.ts +32 -8
  93. package/dist/components/ImageBox.d.ts.map +1 -1
  94. package/dist/components/ImageBox.js +36 -11
  95. package/dist/components/ImageBox.js.map +1 -1
  96. package/dist/components/ImageWithFallback.d.ts +18 -0
  97. package/dist/components/ImageWithFallback.d.ts.map +1 -1
  98. package/dist/components/ImageWithFallback.js +11 -0
  99. package/dist/components/ImageWithFallback.js.map +1 -1
  100. package/dist/components/Input.d.ts +15 -3
  101. package/dist/components/Input.d.ts.map +1 -1
  102. package/dist/components/Input.js +16 -3
  103. package/dist/components/Input.js.map +1 -1
  104. package/dist/components/Link.d.ts +6 -0
  105. package/dist/components/Link.d.ts.map +1 -1
  106. package/dist/components/Link.js +6 -0
  107. package/dist/components/Link.js.map +1 -1
  108. package/dist/components/MenuOverlay/index.d.ts +20 -0
  109. package/dist/components/MenuOverlay/index.d.ts.map +1 -1
  110. package/dist/components/MenuOverlay/index.js +20 -0
  111. package/dist/components/MenuOverlay/index.js.map +1 -1
  112. package/dist/components/Overlay/index.d.ts +16 -0
  113. package/dist/components/Overlay/index.d.ts.map +1 -1
  114. package/dist/components/Overlay/index.js +16 -0
  115. package/dist/components/Overlay/index.js.map +1 -1
  116. package/dist/components/Pagination.d.ts +27 -8
  117. package/dist/components/Pagination.d.ts.map +1 -1
  118. package/dist/components/Pagination.js +18 -5
  119. package/dist/components/Pagination.js.map +1 -1
  120. package/dist/components/ProgressBar.d.ts +14 -0
  121. package/dist/components/ProgressBar.d.ts.map +1 -1
  122. package/dist/components/ProgressBar.js +14 -0
  123. package/dist/components/ProgressBar.js.map +1 -1
  124. package/dist/components/ProgressCircular.d.ts +14 -0
  125. package/dist/components/ProgressCircular.d.ts.map +1 -1
  126. package/dist/components/ProgressCircular.js +14 -0
  127. package/dist/components/ProgressCircular.js.map +1 -1
  128. package/dist/components/RadioGroup.d.ts +24 -3
  129. package/dist/components/RadioGroup.d.ts.map +1 -1
  130. package/dist/components/RadioGroup.js +25 -3
  131. package/dist/components/RadioGroup.js.map +1 -1
  132. package/dist/components/Rating.d.ts +10 -0
  133. package/dist/components/Rating.d.ts.map +1 -1
  134. package/dist/components/Rating.js +10 -0
  135. package/dist/components/Rating.js.map +1 -1
  136. package/dist/components/Select/RichSelect.d.ts +3 -5
  137. package/dist/components/Select/RichSelect.d.ts.map +1 -1
  138. package/dist/components/Select/RichSelect.js +4 -4
  139. package/dist/components/Select/RichSelect.js.map +1 -1
  140. package/dist/components/Select/SimpleSelect.d.ts +2 -3
  141. package/dist/components/Select/SimpleSelect.d.ts.map +1 -1
  142. package/dist/components/Select/SimpleSelect.js +2 -3
  143. package/dist/components/Select/SimpleSelect.js.map +1 -1
  144. package/dist/components/Select/index.d.ts +25 -2
  145. package/dist/components/Select/index.d.ts.map +1 -1
  146. package/dist/components/Select/index.js +26 -3
  147. package/dist/components/Select/index.js.map +1 -1
  148. package/dist/components/Select/types.d.ts +1 -2
  149. package/dist/components/Select/types.d.ts.map +1 -1
  150. package/dist/components/SelectBox.d.ts +31 -2
  151. package/dist/components/SelectBox.d.ts.map +1 -1
  152. package/dist/components/SelectBox.js +32 -3
  153. package/dist/components/SelectBox.js.map +1 -1
  154. package/dist/components/Skeleton.d.ts +11 -0
  155. package/dist/components/Skeleton.d.ts.map +1 -1
  156. package/dist/components/Skeleton.js +11 -0
  157. package/dist/components/Skeleton.js.map +1 -1
  158. package/dist/components/Slider.d.ts +12 -0
  159. package/dist/components/Slider.d.ts.map +1 -1
  160. package/dist/components/Slider.js +12 -0
  161. package/dist/components/Slider.js.map +1 -1
  162. package/dist/components/SmartTable.d.ts +36 -2
  163. package/dist/components/SmartTable.d.ts.map +1 -1
  164. package/dist/components/SmartTable.js +37 -3
  165. package/dist/components/SmartTable.js.map +1 -1
  166. package/dist/components/Stepper.d.ts +20 -3
  167. package/dist/components/Stepper.d.ts.map +1 -1
  168. package/dist/components/Stepper.js +21 -3
  169. package/dist/components/Stepper.js.map +1 -1
  170. package/dist/components/Table.d.ts +10 -0
  171. package/dist/components/Table.d.ts.map +1 -1
  172. package/dist/components/Table.js +10 -0
  173. package/dist/components/Table.js.map +1 -1
  174. package/dist/components/Tabs/TabController.d.ts +14 -0
  175. package/dist/components/Tabs/TabController.d.ts.map +1 -1
  176. package/dist/components/Tabs/TabController.js +14 -0
  177. package/dist/components/Tabs/TabController.js.map +1 -1
  178. package/dist/components/Tabs/index.d.ts +20 -3
  179. package/dist/components/Tabs/index.d.ts.map +1 -1
  180. package/dist/components/Tabs/index.js +21 -3
  181. package/dist/components/Tabs/index.js.map +1 -1
  182. package/dist/components/Text.d.ts +16 -2
  183. package/dist/components/Text.d.ts.map +1 -1
  184. package/dist/components/Text.js +17 -3
  185. package/dist/components/Text.js.map +1 -1
  186. package/dist/components/Textarea.d.ts +11 -1
  187. package/dist/components/Textarea.d.ts.map +1 -1
  188. package/dist/components/Textarea.js +12 -2
  189. package/dist/components/Textarea.js.map +1 -1
  190. package/dist/components/Tooltip.d.ts +14 -1
  191. package/dist/components/Tooltip.d.ts.map +1 -1
  192. package/dist/components/Tooltip.js +13 -0
  193. package/dist/components/Tooltip.js.map +1 -1
  194. package/dist/components/layout.d.ts +41 -7
  195. package/dist/components/layout.d.ts.map +1 -1
  196. package/dist/components/layout.js +44 -9
  197. package/dist/components/layout.js.map +1 -1
  198. package/dist/index.d.ts +0 -1
  199. package/dist/index.d.ts.map +1 -1
  200. package/dist/index.js +0 -1
  201. package/dist/index.js.map +1 -1
  202. package/package.json +2 -2
  203. package/src/components/Accordion.tsx +34 -0
  204. package/src/components/Alert.tsx +8 -0
  205. package/src/components/AsyncContent.tsx +18 -4
  206. package/src/components/Avatar.tsx +11 -1
  207. package/src/components/AvatarGroup.tsx +8 -0
  208. package/src/components/Badge.tsx +24 -8
  209. package/src/components/Blockquote.tsx +8 -0
  210. package/src/components/Breadcrumb.tsx +10 -1
  211. package/src/components/Button.tsx +17 -2
  212. package/src/components/Card.tsx +34 -14
  213. package/src/components/Checkbox.tsx +14 -0
  214. package/src/components/CheckboxGroup.tsx +61 -40
  215. package/src/components/Circle.tsx +16 -0
  216. package/src/components/CitricComponent.ts +14 -0
  217. package/src/components/Divider.tsx +6 -5
  218. package/src/components/ErrorBoundary.tsx +13 -0
  219. package/src/components/ErrorMessage.tsx +1 -1
  220. package/src/components/FallbackBoundary.tsx +12 -1
  221. package/src/components/Favorite.tsx +12 -0
  222. package/src/components/FieldGroup.tsx +13 -0
  223. package/src/components/Form.tsx +18 -0
  224. package/src/components/FormGroup.tsx +12 -0
  225. package/src/components/IconBox.tsx +61 -30
  226. package/src/components/ImageBox.tsx +60 -30
  227. package/src/components/ImageWithFallback.tsx +18 -0
  228. package/src/components/Input.tsx +28 -14
  229. package/src/components/Link.tsx +6 -0
  230. package/src/components/MenuOverlay/index.tsx +20 -0
  231. package/src/components/Overlay/index.tsx +17 -0
  232. package/src/components/Pagination.tsx +40 -17
  233. package/src/components/ProgressBar.tsx +14 -0
  234. package/src/components/ProgressCircular.tsx +14 -0
  235. package/src/components/RadioGroup.tsx +62 -39
  236. package/src/components/Rating.tsx +10 -0
  237. package/src/components/Select/RichSelect.tsx +183 -182
  238. package/src/components/Select/SimpleSelect.tsx +57 -57
  239. package/src/components/Select/index.tsx +29 -5
  240. package/src/components/Select/types.ts +1 -1
  241. package/src/components/SelectBox.tsx +92 -62
  242. package/src/components/Skeleton.tsx +11 -0
  243. package/src/components/Slider.tsx +12 -0
  244. package/src/components/SmartTable.tsx +91 -56
  245. package/src/components/Stepper.tsx +76 -57
  246. package/src/components/Table.tsx +10 -0
  247. package/src/components/Tabs/TabController.ts +14 -0
  248. package/src/components/Tabs/index.tsx +56 -37
  249. package/src/components/Text.ts +36 -21
  250. package/src/components/Textarea.tsx +14 -4
  251. package/src/components/Tooltip.tsx +14 -1
  252. package/src/components/layout.tsx +56 -13
  253. package/src/index.ts +0 -1
  254. package/dist/components/Switch.d.ts +0 -10
  255. package/dist/components/Switch.d.ts.map +0 -1
  256. package/dist/components/Switch.js +0 -8
  257. package/dist/components/Switch.js.map +0 -1
  258. package/src/components/Switch.tsx +0 -30
@@ -12,46 +12,67 @@ import { findSelectedIndex } from './utils'
12
12
 
13
13
  const ctx = createContext<TabController<any> | undefined>(undefined)
14
14
 
15
- function _Tabs<Key extends string>({ tabs, value, equallySized, onChange, controller: ctrl, className, ...props }: TabsProps<Key>) {
16
- const controller = useMemo(() => ctrl ?? new TabController<Key>(tabs.map(t => t.key), value || tabs[0]?.key), [])
17
- const t = useTranslate(dictionary)
18
- const [selectedIndex, setSelectedIndex] = useState(findSelectedIndex(tabs, controller.getValue()))
15
+ /**
16
+ * Builds a Tab selector. The content of a tab is a React component and it can suspend, i.e. tabs can be asynchronously loaded.
17
+ *
18
+ * @example
19
+ *
20
+ * ```
21
+ * const tabs: Tab[] = useMemo(() => [
22
+ * { key: 'tab1', label: 'Tab 1', content: <><h1>First tab</h1><p>Content of the first tab</p></> },
23
+ * { key: 'tab2', label: 'Tab 2', content: <><h1>Second tab</h1><p>Content of the second tab</p></> },
24
+ * { key: 'tab3', label: 'Tab 3', content: <><h1>Third tab</h1><p>Content of the third tab</p></> },
25
+ * ], [])
26
+ *
27
+ * return <Tabs tabs={tabs} />
28
+ * ```
29
+ */
30
+ export const Tabs = withRef(
31
+ function Tabs<Key extends string>({ tabs, value, equallySized, onChange, controller: ctrl, className, ...props }: TabsProps<Key>) {
32
+ const controller = useMemo(() => ctrl ?? new TabController<Key>(tabs.map(t => t.key), value || tabs[0]?.key), [])
33
+ const t = useTranslate(dictionary)
34
+ const [selectedIndex, setSelectedIndex] = useState(findSelectedIndex(tabs, controller.getValue()))
19
35
 
20
- useEffect(() => {
21
- if (value) controller.setValue(value)
22
- }, [value])
36
+ useEffect(() => {
37
+ if (value) controller.setValue(value)
38
+ }, [value])
23
39
 
24
- useEffect(() => controller.onChange((v) => {
25
- setSelectedIndex(findSelectedIndex(tabs, v))
26
- onChange?.(v)
27
- }), [tabs])
40
+ useEffect(() => controller.onChange((v) => {
41
+ setSelectedIndex(findSelectedIndex(tabs, v))
42
+ onChange?.(v)
43
+ }), [tabs])
28
44
 
29
- const nav = useMemo(
30
- () => tabs.map(({ key, label, disabled }, index) => (
31
- <label key={key}>
32
- <input type="radio" role="tab" checked={index === selectedIndex} onChange={() => controller.setValue(key)} disabled={disabled} />
33
- {label || key}
34
- </label>
35
- )),
36
- [tabs, selectedIndex],
37
- )
45
+ const nav = useMemo(
46
+ () => tabs.map(({ key, label, disabled }, index) => (
47
+ <label key={key}>
48
+ <input type="radio" role="tab" checked={index === selectedIndex} onChange={() => controller.setValue(key)} disabled={disabled} />
49
+ {label || key}
50
+ </label>
51
+ )),
52
+ [tabs, selectedIndex],
53
+ )
38
54
 
39
- return (
40
- <ctx.Provider value={controller}>
41
- <CitricComponent tag="div" component="tabs" className={listToClass([className, equallySized && 'equally-sized'])} {...props}>
42
- <nav>{nav}</nav>
43
- <section>
44
- <ErrorBoundary key={selectedIndex} message={t.error}>
45
- <Suspense fallback={<Center style={{ padding: '20px' }}><ProgressCircular /></Center>}>
46
- {selectedIndex === -1 ? null : tabs[selectedIndex]?.content}
47
- </Suspense>
48
- </ErrorBoundary>
49
- </section>
50
- </CitricComponent>
51
- </ctx.Provider>
52
- )
53
- }
55
+ return (
56
+ <ctx.Provider value={controller}>
57
+ <CitricComponent tag="div" component="tabs" className={listToClass([className, equallySized && 'equally-sized'])} {...props}>
58
+ <nav>{nav}</nav>
59
+ <section>
60
+ <ErrorBoundary key={selectedIndex} message={t.error}>
61
+ <Suspense fallback={<Center style={{ padding: '20px' }}><ProgressCircular /></Center>}>
62
+ {selectedIndex === -1 ? null : tabs[selectedIndex]?.content}
63
+ </Suspense>
64
+ </ErrorBoundary>
65
+ </section>
66
+ </CitricComponent>
67
+ </ctx.Provider>
68
+ )
69
+ },
70
+ )
54
71
 
72
+ /**
73
+ * Request the tab controller of the current context. Use this to control the tabs in the parent components. This returns undefined when
74
+ * no tab context is found.
75
+ */
55
76
  export function useTabController<Key extends string = string>(): TabController<Key> | undefined {
56
77
  return useContext(ctx)
57
78
  }
@@ -64,5 +85,3 @@ const dictionary = {
64
85
  error: 'Ocorreu um erro ao carregar a aba.',
65
86
  },
66
87
  } satisfies Dictionary
67
-
68
- export const Tabs = withRef(_Tabs)
@@ -73,24 +73,39 @@ const appearanceToTag: Record<TextAppearance, SupportedTags> = {
73
73
  subtitle4: 'p',
74
74
  }
75
75
 
76
- function _Text<T extends SupportedTags>(
77
- { tag, appearance, color, showMargins, weight, align, nowrapEllipsis, style, className, children, ...props }: TextProps<T>,
78
- ) {
79
- const renderedTag = tag || appearanceToTag[appearance || 'body2']
80
- const renderedAppearance = appearance || (tag ? tagToAppearance[tag] : undefined)
81
- if (!appearance && !showMargins) style = { margin: 0, ...style }
82
- if (weight) style = { fontWeight: weight, ...style }
83
- if (align) style = { textAlign: align, ...style }
84
- if (nowrapEllipsis) style = { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', ...style }
85
- return createElement(
86
- renderedTag,
87
- {
88
- className: applyTextAppearance(listToClass([className, showMargins && 'text-with-margins']), renderedAppearance),
89
- style: applyColor(style, color),
90
- ...props,
91
- },
92
- children,
93
- )
94
- }
95
-
96
- export const Text = withRef(_Text)
76
+ /**
77
+ * Renders a text. The tag can be set by the property "tag". If unset, the tag rendered will be based on the property "appearance". If
78
+ * "appearance" is also unset, the tag "p" is rendered.
79
+ *
80
+ * Texts have no margin by default, to enable margins, use `showMargins = true`.
81
+ *
82
+ * If the appearance is not set, it will be inherited from the parent.
83
+ *
84
+ * A font can be applied to a text without this component, just use `{ font: theme.font.$textAppearance }` in your style.
85
+ *
86
+ * @example
87
+ * ```
88
+ * <Text appearance="body2">Hello World!</Text>
89
+ * ```
90
+ */
91
+ export const Text = withRef(
92
+ function Text<T extends SupportedTags>(
93
+ { tag, appearance, color, showMargins, weight, align, nowrapEllipsis, style, className, children, ...props }: TextProps<T>,
94
+ ) {
95
+ const renderedTag = tag || appearanceToTag[appearance || 'body2']
96
+ const renderedAppearance = appearance || (tag ? tagToAppearance[tag] : undefined)
97
+ if (!appearance && !showMargins) style = { margin: 0, ...style }
98
+ if (weight) style = { fontWeight: weight, ...style }
99
+ if (align) style = { textAlign: align, ...style }
100
+ if (nowrapEllipsis) style = { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', ...style }
101
+ return createElement(
102
+ renderedTag,
103
+ {
104
+ className: applyTextAppearance(listToClass([className, showMargins && 'text-with-margins']), renderedAppearance),
105
+ style: applyColor(style, color),
106
+ ...props,
107
+ },
108
+ children,
109
+ )
110
+ },
111
+ )
@@ -11,7 +11,17 @@ export interface BaseTextareaProps extends WithColorScheme {
11
11
 
12
12
  export type TextareaProps = ControlledTextarea & BaseTextareaProps
13
13
 
14
- export const _Textarea = ({ value, onChange, ...props }: TextareaProps) =>
15
- <CitricComponent tag="textarea" component="textarea" value={value} onChange={e => onChange?.(e.target.value)} {...props} />
16
-
17
- export const Textarea = withRef(_Textarea)
14
+ /**
15
+ * Renders a textarea HTML element. With the difference that the value is not determined by the children, but the property "value" instead.
16
+ *
17
+ * Attention: "onChange" receives the new value, not the event.
18
+ *
19
+ * @example
20
+ * ```
21
+ * const [value, setValue] = useState('')
22
+ * return <Textarea value={value} onChange={setValue} />
23
+ * ```
24
+ */
25
+ export const Textarea = withRef(({ value, onChange, ...props }: TextareaProps) =>
26
+ <CitricComponent tag="textarea" component="textarea" value={value} onChange={e => onChange?.(e.target.value)} {...props} />,
27
+ )
@@ -32,8 +32,21 @@ export interface BaseTooltipProps extends
32
32
  disabled?: boolean,
33
33
  }
34
34
 
35
- export type TooltipProps = React.JSX.IntrinsicElements['div'] & BaseTooltipProps
35
+ export type TooltipProps = Omit<React.JSX.IntrinsicElements['div'], 'content'> & BaseTooltipProps
36
36
 
37
+ /**
38
+ * Renders a tooltip overlay for its child. By default, the tooltip is rendered on hover, but this can be changed through the property
39
+ * "triggerOn".
40
+ *
41
+ * The content of the tooltip can be any React element.
42
+ *
43
+ * @example
44
+ * ```
45
+ * <Tooltip content="This is some help for you">
46
+ * <IconButton icon="Question" />
47
+ * </Tooltip>
48
+ * ```
49
+ */
37
50
  export const Tooltip = (
38
51
  { tooltipId, children, showArrow = true, compact = true, attributes, colorScheme, colorPalette, disabled, ...props }: TooltipProps,
39
52
  ) => {
@@ -41,18 +41,61 @@ export type CenterProps<T extends keyof HTMLTag> = HTMLTag[T] & BaseLayoutProps<
41
41
  export type RowProps<T extends keyof HTMLTag> = HTMLTag[T] & BaseRowProps<T>
42
42
  export type ColumnProps<T extends keyof HTMLTag> = HTMLTag[T] & BaseColumnProps<T>
43
43
 
44
- function _Center<T extends keyof HTMLTag = 'div'>({ tag, className, ...props }: CenterProps<T>) {
45
- return createElement(tag || 'div', { className: listToClass(['center', className]), ...applyStyles(props) })
46
- }
47
-
48
- function _Row<T extends keyof HTMLTag = 'div'>({ tag, className, center, ...props }: RowProps<T>) {
49
- return createElement(tag || 'div', { className: listToClass(['row', center === false && 'no-center', className]), ...applyStyles(props) })
50
- }
44
+ /**
45
+ * Centers the content both vertically and horizontally. Elements are placed in a column (flex).
46
+ *
47
+ * This element accepts many style shortcuts as attributes: bg, fg, border, radius, justifyContent, alignItems, flex, gap, m, mt, mb, ml,
48
+ * mr, p, pt, pb, pl, pr, w, h.
49
+ *
50
+ * @example
51
+ * ```
52
+ * <Center w="200px" h="200px" gap="10px">
53
+ * <img src="/an-image.png" />
54
+ * <Text>This content is centered!</Text>
55
+ * </Center>
56
+ * ```
57
+ */
58
+ export const Center = withRef(
59
+ function Center<T extends keyof HTMLTag = 'div'>({ tag, className, ...props }: CenterProps<T>) {
60
+ return createElement(tag || 'div', { className: listToClass(['center', className]), ...applyStyles(props) })
61
+ },
62
+ )
51
63
 
52
- function _Column<T extends keyof HTMLTag = 'div'>({ tag, className, center, ...props }: ColumnProps<T>) {
53
- return createElement(tag || 'div', { className: listToClass(['column', center && 'center', className]), ...applyStyles(props) })
54
- }
64
+ /**
65
+ * Creates a row (flex). The elements in this row are horizontally centered unless `center = false`.
66
+ *
67
+ * @example
68
+ * ```
69
+ * <Row gap={3}>
70
+ * <Icon icon="Stack" />
71
+ * <Text>Stacks</Text>
72
+ * </Row>
73
+ * ```
74
+ */
75
+ export const Row = withRef(
76
+ function Row<T extends keyof HTMLTag = 'div'>({ tag, className, center, ...props }: RowProps<T>) {
77
+ return createElement(
78
+ tag || 'div',
79
+ { className: listToClass(['row', center === false && 'no-center', className]), ...applyStyles(props) },
80
+ )
81
+ },
82
+ )
55
83
 
56
- export const Center = withRef(_Center)
57
- export const Row = withRef(_Row)
58
- export const Column = withRef(_Column)
84
+ /**
85
+ * Creates a column (flex). The elements in this row are placed at the start of the horizontal axis, unless `center = true`, in this case,
86
+ * they're centered.
87
+ *
88
+ * @example
89
+ * ```
90
+ * <Column gap={5}>
91
+ * <Text>Item 1</Text>
92
+ * <Text>Item 2</Text>
93
+ * <Text>Item 3</Text>
94
+ * </Row>
95
+ * ```
96
+ */
97
+ export const Column = withRef(
98
+ function Column<T extends keyof HTMLTag = 'div'>({ tag, className, center, ...props }: ColumnProps<T>) {
99
+ return createElement(tag || 'div', { className: listToClass(['column', center && 'center', className]), ...applyStyles(props) })
100
+ },
101
+ )
package/src/index.ts CHANGED
@@ -40,7 +40,6 @@ export * from './components/Skeleton'
40
40
  export * from './components/Slider'
41
41
  export * from './components/SmartTable'
42
42
  export * from './components/Stepper'
43
- export * from './components/Switch'
44
43
  export * from './components/Table'
45
44
  export * from './components/Tabs'
46
45
  export * from './components/Tabs/TabController'
@@ -1,10 +0,0 @@
1
- import { ControlledInput, WithColorScheme } from '../types.js';
2
- interface Props extends WithColorScheme {
3
- value?: boolean;
4
- onChange?: (value: boolean) => void;
5
- children?: React.ReactNode;
6
- }
7
- export type SwitchProps = ControlledInput & Props;
8
- export declare const Switch: ({ value, onChange, children, className, style, ...props }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
9
- export {};
10
- //# sourceMappingURL=Switch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../src/components/Switch.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAI3D,UAAU,KAAM,SAAQ,eAAe;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,KAAK,CAAA;AAEjD,eAAO,MAAM,MAAM,8DAAuE,WAAW,4CAiBnG,CAAA"}
@@ -1,8 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { withRef } from '../utils/react.js';
3
- import { CitricComponent } from './CitricComponent.js';
4
- export const Switch = withRef(({ value, onChange, children, className, style, ...props }) => {
5
- const handleChange = onChange ? () => onChange(!value) : undefined;
6
- return children ? (_jsxs(CitricComponent, { tag: "label", component: "switch-row", style: style, className: className, children: [_jsx("input", { type: "checkbox", checked: value, onChange: handleChange, ...props }), children] })) : _jsx(CitricComponent, { tag: "input", type: "checkbox", component: "switch", checked: value, onChange: handleChange, className: className, style: style, ...props });
7
- });
8
- //# sourceMappingURL=Switch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Switch.js","sourceRoot":"","sources":["../../src/components/Switch.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAUnD,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,KAAK,EAAe,EAAE,EAAE;IACvG,MAAM,YAAY,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAClE,OAAO,QAAQ,CAAC,CAAC,CAAC,CAChB,MAAC,eAAe,IAAC,GAAG,EAAC,OAAO,EAAC,SAAS,EAAC,YAAY,EAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,aACpF,gBAAO,IAAI,EAAC,UAAU,EAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,KAAM,KAAK,GAAI,EAC3E,QAAQ,IACO,CACnB,CAAC,CAAC,CAAC,KAAC,eAAe,IAClB,GAAG,EAAC,OAAO,EACX,IAAI,EAAC,UAAU,EACf,SAAS,EAAC,QAAQ,EAClB,OAAO,EAAE,KAAK,EACd,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,KACR,KAAK,GACT,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,30 +0,0 @@
1
- import { ControlledInput, WithColorScheme } from '../types'
2
- import { withRef } from '../utils/react'
3
- import { CitricComponent } from './CitricComponent'
4
-
5
- interface Props extends WithColorScheme {
6
- value?: boolean,
7
- onChange?: (value: boolean) => void,
8
- children?: React.ReactNode,
9
- }
10
-
11
- export type SwitchProps = ControlledInput & Props
12
-
13
- export const Switch = withRef(({ value, onChange, children, className, style, ...props }: SwitchProps) => {
14
- const handleChange = onChange ? () => onChange(!value) : undefined
15
- return children ? (
16
- <CitricComponent tag="label" component="switch-row" style={style} className={className}>
17
- <input type="checkbox" checked={value} onChange={handleChange} {...props} />
18
- {children}
19
- </CitricComponent>
20
- ) : <CitricComponent
21
- tag="input"
22
- type="checkbox"
23
- component="switch"
24
- checked={value}
25
- onChange={handleChange}
26
- className={className}
27
- style={style}
28
- {...props}
29
- />
30
- })