@chotot/clad-ui 1.2.5 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/README.md +3 -3
  2. package/components/Announcer/Announcer.d.ts +9 -4
  3. package/components/Announcer/Announcer.stories.d.ts +142 -0
  4. package/components/Announcer/{Announcer.stories.js → Announcer.stories.tsx} +36 -31
  5. package/components/Announcer/Announcer.styles.d.ts +24 -12
  6. package/components/Announcer/{Announcer.styles.js → Announcer.styles.ts} +43 -18
  7. package/components/Announcer/Announcer.tsx +62 -47
  8. package/components/Badge/Badge.d.ts +4 -2
  9. package/components/Badge/Badge.stories.d.ts +61 -0
  10. package/components/Badge/{Badge.stories.js → Badge.stories.tsx} +5 -5
  11. package/components/Badge/Badge.styles.d.ts +20 -5
  12. package/components/Badge/{Badge.styles.js → Badge.styles.ts} +14 -1
  13. package/components/Badge/Badge.tsx +8 -4
  14. package/components/Box/Box.d.ts +3 -3
  15. package/components/Box/Box.stories.d.ts +240 -0
  16. package/components/Box/{Box.stories.js → Box.stories.tsx} +2 -2
  17. package/components/Box/Box.styles.d.ts +19 -4
  18. package/components/Box/{Box.styles.js → Box.styles.ts} +17 -4
  19. package/components/Box/Box.tsx +4 -4
  20. package/components/Breadcrumbs/Breadcrumbs.d.ts +2 -2
  21. package/components/Breadcrumbs/Breadcrumbs.stories.d.ts +52 -0
  22. package/components/Breadcrumbs/{Breadcrumbs.stories.js → Breadcrumbs.stories.tsx} +17 -15
  23. package/components/Breadcrumbs/Breadcrumbs.styles.d.ts +5 -4
  24. package/components/Breadcrumbs/Breadcrumbs.tsx +2 -2
  25. package/components/Button/Button.d.ts +21 -6
  26. package/components/Button/Button.stories.d.ts +103 -0
  27. package/components/Button/{Button.stories.js → Button.stories.tsx} +5 -1
  28. package/components/Button/Button.styles.d.ts +1 -1
  29. package/components/Button/{Button.styles.js → Button.styles.ts} +100 -6
  30. package/components/Button/Button.tsx +51 -18
  31. package/components/Button/ButtonLink.d.ts +4 -4
  32. package/components/Button/ButtonLink.stories.d.ts +30 -0
  33. package/components/Button/ButtonLink.styles.d.ts +1 -1
  34. package/components/Button/ButtonLink.tsx +5 -5
  35. package/components/Button/IconButton.d.ts +3 -29
  36. package/components/Button/IconButton.stories.d.ts +60 -0
  37. package/components/Button/{IconButton.stories.js → IconButton.stories.tsx} +27 -0
  38. package/components/Button/IconButton.tsx +2 -42
  39. package/components/Checkbox/Checkbox.d.ts +3 -3
  40. package/components/Checkbox/Checkbox.stories.d.ts +88 -0
  41. package/components/Checkbox/Checkbox.styles.d.ts +2 -2
  42. package/components/Checkbox/Checkbox.tsx +3 -6
  43. package/components/Chip/Chip.d.ts +5 -4
  44. package/components/Chip/Chip.stories.d.ts +153 -0
  45. package/components/Chip/{Chip.stories.js → Chip.stories.tsx} +4 -5
  46. package/components/Chip/Chip.styles.d.ts +11 -8
  47. package/components/Chip/{Chip.styles.js → Chip.styles.ts} +4 -4
  48. package/components/Chip/Chip.tsx +19 -12
  49. package/components/CurrencyInput/CurrencyInput.d.ts +3 -56
  50. package/components/CurrencyInput/CurrencyInput.stories.d.ts +104 -0
  51. package/components/CurrencyInput/{CurrencyInput.stories.js → CurrencyInput.stories.tsx} +2 -2
  52. package/components/CurrencyInput/CurrencyInput.styles.d.ts +16 -10
  53. package/components/CurrencyInput/{CurrencyInput.styles.js → CurrencyInput.styles.ts} +23 -9
  54. package/components/CurrencyInput/CurrencyInput.tsx +7 -61
  55. package/components/Dropdown/Dropdown.d.ts +22 -7
  56. package/components/Dropdown/Dropdown.stories.d.ts +148 -0
  57. package/components/Dropdown/{Dropdown.stories.js → Dropdown.stories.tsx} +115 -1
  58. package/components/Dropdown/Dropdown.styles.d.ts +10 -0
  59. package/components/Dropdown/Dropdown.styles.ts +42 -0
  60. package/components/Dropdown/Dropdown.tsx +120 -24
  61. package/components/Grid/Col.d.ts +2 -2
  62. package/components/Grid/Col.tsx +6 -3
  63. package/components/Grid/Grid.styles.d.ts +25 -5
  64. package/components/Grid/{Grid.styles.js → Grid.styles.ts} +16 -3
  65. package/components/Grid/aGrid.stories.d.ts +127 -0
  66. package/components/Grid/bCol.stories.d.ts +74 -0
  67. package/components/Input/Input.d.ts +14 -10
  68. package/components/Input/Input.stories.d.ts +226 -0
  69. package/components/Input/{Input.stories.js → Input.stories.tsx} +20 -16
  70. package/components/Input/Input.styles.d.ts +22 -11
  71. package/components/Input/{Input.styles.js → Input.styles.ts} +29 -7
  72. package/components/Input/Input.tsx +22 -20
  73. package/components/Popover/Popover.d.ts +44 -0
  74. package/components/Popover/Popover.stories.d.ts +53 -0
  75. package/components/Popover/Popover.stories.tsx +133 -0
  76. package/components/Popover/Popover.tsx +121 -0
  77. package/components/RadioButton/RadioButton.d.ts +5 -6
  78. package/components/RadioButton/RadioButton.stories.d.ts +94 -0
  79. package/components/RadioButton/RadioButton.styles.d.ts +7 -3
  80. package/components/RadioButton/{RadioButton.styles.js → RadioButton.styles.ts} +1 -1
  81. package/components/RadioButton/RadioButton.tsx +5 -11
  82. package/components/RowItem/RowItem.d.ts +27 -9
  83. package/components/RowItem/RowItem.stories.d.ts +131 -0
  84. package/components/RowItem/RowItem.stories.tsx +710 -0
  85. package/components/RowItem/RowItem.styles.d.ts +31 -10
  86. package/components/RowItem/{RowItem.styles.js → RowItem.styles.ts} +41 -13
  87. package/components/RowItem/RowItem.tsx +106 -42
  88. package/components/ShapeIcon/ShapeIcon.d.ts +23 -16
  89. package/components/ShapeIcon/ShapeIcon.stories.d.ts +91 -0
  90. package/components/ShapeIcon/{ShapeIcon.stories.js → ShapeIcon.stories.tsx} +21 -8
  91. package/components/ShapeIcon/ShapeIcon.styles.d.ts +8 -3
  92. package/components/ShapeIcon/{ShapeIcon.styles.js → ShapeIcon.styles.ts} +6 -3
  93. package/components/ShapeIcon/ShapeIcon.tsx +25 -21
  94. package/components/Slider/Slider.d.ts +9 -7
  95. package/components/Slider/Slider.stories.d.ts +81 -0
  96. package/components/Slider/{Slider.stories.js → Slider.stories.tsx} +7 -7
  97. package/components/Slider/Slider.styles.d.ts +15 -11
  98. package/components/Slider/{Slider.styles.js → Slider.styles.ts} +1 -1
  99. package/components/Slider/Slider.tsx +21 -16
  100. package/components/Snack/Snack.d.ts +4 -5
  101. package/components/Snack/Snack.stories.d.ts +87 -0
  102. package/components/Snack/Snack.styles.d.ts +9 -8
  103. package/components/Snack/{Snack.styles.js → Snack.styles.ts} +4 -4
  104. package/components/Snack/Snack.tsx +14 -11
  105. package/components/Tabs/Tab.d.ts +6 -6
  106. package/components/Tabs/Tab.tsx +6 -7
  107. package/components/Tabs/Tabs.d.ts +7 -4
  108. package/components/Tabs/Tabs.stories.d.ts +64 -0
  109. package/components/Tabs/{Tabs.stories.js → Tabs.stories.tsx} +2 -2
  110. package/components/Tabs/Tabs.styles.d.ts +30 -12
  111. package/components/Tabs/{Tabs.styles.js → Tabs.styles.ts} +4 -4
  112. package/components/Tabs/Tabs.tsx +11 -7
  113. package/components/TextArea/TextArea.d.ts +24 -11
  114. package/components/TextArea/TextArea.stories.d.ts +151 -0
  115. package/components/TextArea/{TextArea.stories.js → TextArea.stories.tsx} +5 -96
  116. package/components/TextArea/TextArea.styles.d.ts +18 -16
  117. package/components/TextArea/{TextArea.styles.js → TextArea.styles.ts} +39 -19
  118. package/components/TextArea/TextArea.tsx +85 -31
  119. package/components/TextLabel/TextLabel.d.ts +35 -0
  120. package/components/TextLabel/TextLabel.stories.d.ts +40 -0
  121. package/components/TextLabel/TextLabel.stories.tsx +177 -0
  122. package/components/TextLabel/TextLabel.styles.d.ts +9 -0
  123. package/components/TextLabel/TextLabel.styles.ts +24 -0
  124. package/components/TextLabel/TextLabel.tsx +112 -0
  125. package/components/ToggleSwitch/ToggleSwitch.d.ts +2 -2
  126. package/components/ToggleSwitch/ToggleSwitch.stories.d.ts +38 -0
  127. package/components/ToggleSwitch/ToggleSwitch.styles.d.ts +21 -14
  128. package/components/ToggleSwitch/{ToggleSwitch.styles.js → ToggleSwitch.styles.ts} +8 -12
  129. package/components/ToggleSwitch/ToggleSwitch.tsx +12 -6
  130. package/components/Tooltip/Tooltip.d.ts +9 -3
  131. package/components/Tooltip/Tooltip.spec.js +5 -3
  132. package/components/Tooltip/Tooltip.styles.d.ts +7 -8
  133. package/components/Tooltip/Tooltip.tsx +10 -3
  134. package/components/index.d.ts +2 -0
  135. package/components/index.ts +2 -0
  136. package/icons/PrivateSellerAvatar.d.ts +3 -0
  137. package/icons/PrivateSellerAvatar.js +3 -0
  138. package/icons/Sda.d.ts +5 -2
  139. package/icons/Sda.js +7 -7
  140. package/icons/VerifiedShop.d.ts +3 -0
  141. package/icons/VerifiedShop.js +3 -0
  142. package/package.json +6 -6
  143. package/patterns/Drawer/Drawer.d.ts +13 -13
  144. package/patterns/Drawer/Drawer.stories.d.ts +90 -0
  145. package/patterns/Drawer/{Drawer.stories.js → Drawer.stories.tsx} +25 -0
  146. package/patterns/Drawer/Drawer.styles.d.ts +30 -26
  147. package/patterns/Drawer/{Drawer.styles.js → Drawer.styles.ts} +2 -5
  148. package/patterns/Drawer/Drawer.tsx +20 -41
  149. package/patterns/EmptyState/EmptyState.d.ts +5 -4
  150. package/patterns/EmptyState/EmptyState.stories.d.ts +40 -0
  151. package/patterns/EmptyState/EmptyState.styles.d.ts +10 -10
  152. package/patterns/EmptyState/{EmptyState.styles.js → EmptyState.styles.ts} +5 -4
  153. package/patterns/EmptyState/EmptyState.tsx +14 -12
  154. package/patterns/InputGroup/InputGroup.d.ts +4 -0
  155. package/patterns/InputGroup/InputGroup.styles.d.ts +5 -4
  156. package/patterns/InputGroup/InputGroup.tsx +11 -5
  157. package/patterns/LegacyDialog/DialogMainIcon.d.ts +1 -0
  158. package/patterns/LegacyDialog/DialogMainIcon.js +51 -0
  159. package/patterns/LegacyDialog/LegacyDialog.d.ts +3 -3
  160. package/patterns/LegacyDialog/LegacyDialog.styles.d.ts +8 -10
  161. package/patterns/LegacyDialog/LegacyDialog.styles.js +1 -46
  162. package/patterns/LegacyDialog/LegacyDialog.tsx +5 -11
  163. package/patterns/LegacyPopup/LegacyPopup.d.ts +4 -4
  164. package/patterns/LegacyPopup/LegacyPopup.styles.d.ts +18 -13
  165. package/patterns/LegacyPopup/{LegacyPopup.styles.js → LegacyPopup.styles.ts} +3 -1
  166. package/patterns/LegacyPopup/LegacyPopup.tsx +4 -6
  167. package/patterns/MultiSearchDropdown/MultiSearchDropdown.d.ts +20 -17
  168. package/patterns/MultiSearchDropdown/MultiSearchDropdown.stories.d.ts +125 -0
  169. package/patterns/MultiSearchDropdown/{MultiSearchDropdown.stories.js → MultiSearchDropdown.stories.tsx} +31 -30
  170. package/patterns/MultiSearchDropdown/MultiSearchDropdown.styles.d.ts +22 -21
  171. package/patterns/MultiSearchDropdown/{MultiSearchDropdown.styles.js → MultiSearchDropdown.styles.ts} +1 -7
  172. package/patterns/MultiSearchDropdown/MultiSearchDropdown.tsx +33 -32
  173. package/patterns/Popup/Popup.d.ts +8 -7
  174. package/patterns/Popup/Popup.stories.d.ts +102 -0
  175. package/patterns/Popup/Popup.styles.d.ts +41 -30
  176. package/patterns/Popup/{Popup.styles.js → Popup.styles.ts} +26 -33
  177. package/patterns/Popup/Popup.tsx +14 -33
  178. package/patterns/SearchInput/SearchInput.d.ts +38 -21
  179. package/patterns/SearchInput/SearchInput.stories.d.ts +186 -0
  180. package/patterns/SearchInput/{SearchInput.stories.js → SearchInput.stories.tsx} +78 -45
  181. package/patterns/SearchInput/SearchInput.styles.d.ts +6 -5
  182. package/patterns/SearchInput/{SearchInput.styles.js → SearchInput.styles.ts} +7 -4
  183. package/patterns/SearchInput/SearchInput.tsx +53 -34
  184. package/patterns/TagCloud/TagCloud.d.ts +19 -6
  185. package/patterns/TagCloud/TagCloud.stories.d.ts +159 -0
  186. package/patterns/TagCloud/{TagCloud.stories.js → TagCloud.stories.tsx} +59 -14
  187. package/patterns/TagCloud/TagCloud.styles.d.ts +12 -8
  188. package/patterns/TagCloud/{TagCloud.styles.js → TagCloud.styles.ts} +6 -7
  189. package/patterns/TagCloud/TagCloud.tsx +24 -8
  190. package/patterns/TagCloud/TagCloudMultiActive.d.ts +6 -4
  191. package/patterns/TagCloud/TagCloudMultiActive.tsx +5 -5
  192. package/patterns/TagCloud/TagCloudSingleActive.d.ts +5 -2
  193. package/patterns/TagCloud/TagCloudSingleActive.tsx +18 -5
  194. package/patterns/patterns-index.spec.js +1 -1
  195. package/storybook/GuideImage.d.ts +2 -2
  196. package/storybook/Swatch.d.ts +2 -2
  197. package/theme/__snapshots__/chotot.spec.js.snap +2 -2
  198. package/theme/chotot-color1.d.ts +7 -14
  199. package/theme/chotot.d.ts +32 -32
  200. package/theme/chotot.js +4 -4
  201. package/theme/ct-job.d.ts +6 -14
  202. package/theme/ct-pty.d.ts +6 -8
  203. package/theme/mudah.d.ts +14 -13
  204. package/types.d.ts +0 -9
  205. package/utils/_simulateChangeEvent.d.ts +18 -3
  206. package/utils/_simulateChangeEvent.js +13 -6
  207. package/utils/_simulateChangeEvent.spec.js +1 -1
  208. package/utils/cx.d.ts +8 -4
  209. package/utils/cx.js +8 -4
  210. package/utils/sx.d.ts +12 -4192
  211. package/components/RowItem/RowItem.stories.js +0 -560
  212. /package/components/Breadcrumbs/{Breadcrumbs.styles.js → Breadcrumbs.styles.ts} +0 -0
  213. /package/components/Button/{ButtonLink.stories.js → ButtonLink.stories.tsx} +0 -0
  214. /package/components/Button/{ButtonLink.styles.js → ButtonLink.styles.ts} +0 -0
  215. /package/components/Checkbox/{Checkbox.stories.js → Checkbox.stories.tsx} +0 -0
  216. /package/components/Checkbox/{Checkbox.styles.js → Checkbox.styles.ts} +0 -0
  217. /package/components/Grid/{aGrid.stories.js → aGrid.stories.tsx} +0 -0
  218. /package/components/Grid/{bCol.stories.js → bCol.stories.tsx} +0 -0
  219. /package/components/RadioButton/{RadioButton.stories.js → RadioButton.stories.tsx} +0 -0
  220. /package/components/Snack/{Snack.stories.js → Snack.stories.tsx} +0 -0
  221. /package/components/ToggleSwitch/{ToggleSwitch.stories.js → ToggleSwitch.stories.tsx} +0 -0
  222. /package/patterns/EmptyState/{EmptyState.stories.js → EmptyState.stories.tsx} +0 -0
  223. /package/patterns/InputGroup/{InputGroup.styles.js → InputGroup.styles.ts} +0 -0
  224. /package/patterns/Popup/{Popup.stories.js → Popup.stories.tsx} +0 -0
@@ -1,6 +1,5 @@
1
- import React, { useState, useRef, useCallback } from 'react';
1
+ import React, { useState } from 'react';
2
2
  import theme from '@clad-ui/theme';
3
- import debounce from 'lodash/debounce';
4
3
  import TextArea from './TextArea';
5
4
  import Grid from '../Grid/Grid';
6
5
  import Col from '../Grid/Col';
@@ -350,118 +349,28 @@ export const ErrorStatus = {
350
349
  },
351
350
  };
352
351
 
353
- export const Disabled = {
354
- render: () => (
355
- <Grid rowCols={[1, 2]}>
356
- <Col>
357
- <TextArea id="disabled" label="Read only" disabled />
358
- </Col>
359
- </Grid>
360
- ),
361
-
362
- name: 'With disabled',
363
-
364
- parameters: {
365
- docs: {
366
- description: {
367
- story:
368
- 'Enable `disabled` will set attribute `disabled` to the HTML textarea. Effectively, TextArea is read-only.',
369
- },
370
- },
371
- },
372
- };
373
-
374
- export const WithCharacterLimit = {
352
+ export const AllowClear = {
375
353
  render: () => {
376
354
  const [value, setValue] = useState('');
377
355
  return (
378
356
  <Grid rowCols={[1, 2]}>
379
357
  <Col>
380
358
  <TextArea
381
- id="character-limit"
382
- label="Limited to 20 characters"
383
- characterLimit={20}
384
- value={value}
359
+ allowClear
360
+ label="Label cum placeholder..."
385
361
  onChange={(e) => setValue(e.target.value)}
386
- />
387
- </Col>
388
- </Grid>
389
- );
390
- },
391
-
392
- name: 'With characterLimit',
393
-
394
- parameters: {
395
- docs: {
396
- description: {
397
- story: 'Use `characterLimit` to limit number of character of TextArea',
398
- },
399
- },
400
- },
401
- };
402
-
403
- export const WithResizeableOnFocus = {
404
- render: () => {
405
- const [value, setValue] = useState('');
406
- return (
407
- <Grid rowCols={[1, 2]}>
408
- <Col>
409
- <TextArea
410
- id="resizeable-on-focus"
411
- label="Resizeable on focus"
412
362
  value={value}
413
- onChange={(e) => setValue(e.target.value)}
414
- isResizeableOnFocus
415
363
  />
416
364
  </Col>
417
365
  </Grid>
418
366
  );
419
367
  },
420
368
 
421
- name: 'With isResizeableOnFocus',
422
-
423
369
  parameters: {
424
370
  docs: {
425
371
  description: {
426
- story: 'Use `isResizeableOnFocus` to increase Height of textarea on focus event',
372
+ story: '`allowClear` enable a clear icon when input has value',
427
373
  },
428
374
  },
429
375
  },
430
376
  };
431
-
432
- export const DebounceExample = {
433
- render: () => {
434
- const inputRef = useRef(null);
435
- const [text, setText] = useState('');
436
-
437
- const handleFetch = useCallback(
438
- debounce(() => {
439
- const { value } = inputRef.current;
440
- // eslint-disable-next-line no-alert
441
- if (value) alert('Searching for: ' + value);
442
- }, 1000),
443
- []
444
- );
445
- const handleInputChange = (e) => {
446
- const { value } = e.target;
447
- setText(value);
448
- handleFetch();
449
- };
450
-
451
- return (
452
- <Grid rowCols={[1, 2]}>
453
- <Col>
454
- <TextArea
455
- id="debounce"
456
- value={text}
457
- onChange={handleInputChange}
458
- label="Search input example"
459
- inputRef={inputRef}
460
- />
461
- </Col>
462
- </Grid>
463
- );
464
- },
465
-
466
- name: 'Ex: Debounce onChange',
467
- };
@@ -1,16 +1,18 @@
1
- /**
2
- * @type {React.FC<any>}
3
- */
4
- export const Container: React.FC<any>;
5
- /**
6
- * @type {React.FC<any>}
7
- */
8
- export const TextAreaWrapper: React.FC<any>;
9
- /**
10
- * @type {React.FC<any>}
11
- */
12
- export const StyledTextArea: React.FC<any>;
13
- /**
14
- * @type {React.FC<any>}
15
- */
16
- export const Paragraph: React.FC<any>;
1
+ declare const Container: import("@linaria/react").StyledMeta & import("react").FunctionComponent<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
2
+ containerWidth: string;
3
+ } & {
4
+ as?: import("react").ElementType;
5
+ }>;
6
+ declare const TextAreaWrapper: import("@linaria/react").StyledMeta & import("react").FunctionComponent<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
7
+ wrapperHeight: string;
8
+ autoSize: boolean;
9
+ } & {
10
+ as?: import("react").ElementType;
11
+ }>;
12
+ declare const StyledTextArea: import("@linaria/react").StyledMeta & import("react").FunctionComponent<import("react").ClassAttributes<HTMLTextAreaElement> & import("react").TextareaHTMLAttributes<HTMLTextAreaElement> & Record<never, unknown> & {
13
+ as?: import("react").ElementType;
14
+ }>;
15
+ declare const Paragraph: import("@linaria/react").StyledMeta & import("react").FunctionComponent<import("react").ClassAttributes<HTMLParagraphElement> & import("react").HTMLAttributes<HTMLParagraphElement> & Record<never, unknown> & {
16
+ as?: import("react").ElementType;
17
+ }>;
18
+ export { Container, TextAreaWrapper, StyledTextArea, Paragraph };
@@ -13,25 +13,20 @@ const {
13
13
  borderStyles,
14
14
  } = theme;
15
15
 
16
- /**
17
- * @type {React.FC<any>}
18
- */
19
- const Container = styled.div`
16
+ const Container = styled.div<{ containerWidth: string }>`
20
17
  display: table; /* display table will make container width match textarea even after being resized by user */
21
18
  position: relative;
22
19
  width: ${({ containerWidth }) => containerWidth};
23
20
  `;
24
21
 
25
- /**
26
- * @type {React.FC<any>}
27
- */
28
- const TextAreaWrapper = styled.div`
22
+ const TextAreaWrapper = styled.div<{ wrapperHeight: string; autoSize: boolean }>`
29
23
  width: ${sizes.full};
30
24
  border-radius: ${radii.sm};
31
25
  border: ${borderWidths.sm} ${borderStyles.solid} ${colors.borderRegular};
32
- height: ${({ wrapperHeight }) => wrapperHeight};
33
- min-height: ${sizes.xl}; /* normal input height */
26
+ height: ${({ wrapperHeight, autoSize }) => `${autoSize || wrapperHeight || 'auto'}`};
27
+ min-height: ${({ wrapperHeight }) => `${wrapperHeight || sizes.xl}`};
34
28
  background-color: ${colors.backgroundPrimary};
29
+ position: relative;
35
30
 
36
31
  /* set resize to the wrapper instead of the textarea to make sure the border move along while resizing */
37
32
  &.resize-both {
@@ -67,12 +62,21 @@ const TextAreaWrapper = styled.div`
67
62
  user-select: none;
68
63
  transform-origin: top left;
69
64
  transition: transform 0.1s ease;
70
- color: ${colors.textTertiary};
71
- font-size: ${fontSizes.sm};
65
+ color: ${colors.textPrimary};
66
+ font-size: 11px;
67
+ font-weight: ${fontWeights.bold};
72
68
  }
73
69
 
74
70
  &:focus-within {
75
71
  border-color: ${colors.borderBrand};
72
+
73
+ &:not(.error) > label {
74
+ color: ${colors.textBrand};
75
+ }
76
+
77
+ & > label {
78
+ color: ${colors.textPrimary};
79
+ }
76
80
  }
77
81
 
78
82
  &.error {
@@ -83,15 +87,33 @@ const TextAreaWrapper = styled.div`
83
87
  color: ${colors.borderError};
84
88
  }
85
89
 
90
+ &.error > label {
91
+ color: ${colors.borderError};
92
+ }
93
+
86
94
  &.disabled {
87
95
  border-color: ${colors.borderDisabled};
88
96
  background-color: ${colors.backgroundSecondary};
89
97
  }
98
+
99
+ &.showRightIcon {
100
+ padding-right: 36px;
101
+ }
102
+
103
+ & > button {
104
+ background: transparent;
105
+ outline: none;
106
+ border: none;
107
+ height: ${sizes.xl};
108
+ min-width: ${sizes.xxs};
109
+ position: absolute;
110
+ top: calc(50% - 24px);
111
+ right: 5px;
112
+ color: ${colors.textInfo};
113
+ padding: ${space.xs};
114
+ }
90
115
  `;
91
116
 
92
- /**
93
- * @type {React.FC<any>}
94
- */
95
117
  const StyledTextArea = styled.textarea`
96
118
  border-radius: ${radii.sm};
97
119
  width: ${sizes.full};
@@ -131,14 +153,12 @@ const StyledTextArea = styled.textarea`
131
153
  &:focus + label,
132
154
  &.hasValue + label,
133
155
  &:-webkit-autofill + label {
134
- transform: scale(0.7143) translateY(-3px);
156
+ transform: scale(0.9143) translateY(-3px);
135
157
  font-weight: ${fontWeights.bold};
158
+ color: ${colors.textBrand};
136
159
  }
137
160
  `;
138
161
 
139
- /**
140
- * @type {React.FC<any>}
141
- */
142
162
  const Paragraph = styled.p`
143
163
  color: ${colors.textTertiary};
144
164
  font-size: ${fontSizes.xxs};
@@ -1,14 +1,14 @@
1
- import theme from '@clad-ui/theme';
2
- import React, { useRef, useState, useCallback } from 'react';
1
+ import * as React from 'react';
2
+ import theme, { type Sizes } from '@clad-ui/theme';
3
+ import { useRef, useState, useCallback, useEffect } from 'react';
3
4
  import { cx, noop } from '../../utils';
4
5
  import { Container, TextAreaWrapper, StyledTextArea, Paragraph } from './TextArea.styles';
6
+ import simulateChangeEvent from '../../utils/_simulateChangeEvent';
7
+ import { CloseFilled } from '../../icons';
5
8
 
6
- const { sizes } = theme;
7
- const keyOfSizes = [...Object.keys(sizes)] as const;
9
+ const { sizes, colors } = theme;
8
10
 
9
- type Size = (typeof keyOfSizes)[number];
10
-
11
- export type TextAreaProps = {
11
+ export interface TextAreaProps {
12
12
  /**
13
13
  * TextArea name
14
14
  */
@@ -20,23 +20,23 @@ export type TextAreaProps = {
20
20
  /**
21
21
  * TextArea ref (implement with useRef() hooks)
22
22
  */
23
- inputRef?: React.RefObject<any>;
23
+ inputRef?: React.RefObject<HTMLTextAreaElement>;
24
24
  /**
25
25
  * The TextArea content value
26
26
  */
27
- value?: number | string;
27
+ value?: string;
28
28
  /**
29
29
  * Callback when user input
30
30
  */
31
- onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
31
+ onChange?: React.ChangeEventHandler<HTMLTextAreaElement>;
32
32
  /**
33
33
  * Callback when user blur
34
34
  */
35
- onBlur?: () => void;
35
+ onBlur?: React.FocusEventHandler<HTMLTextAreaElement>;
36
36
  /**
37
37
  * Callback when user focus
38
38
  */
39
- onFocus?: () => void;
39
+ onFocus?: React.FocusEventHandler<HTMLTextAreaElement>;
40
40
  /**
41
41
  * Disabled TextArea
42
42
  */
@@ -57,10 +57,19 @@ export type TextAreaProps = {
57
57
  * Promp a helptext below TextArea (useful when implemented with form validation)
58
58
  */
59
59
  helptext?: string;
60
+ /**
61
+ * Custom helptext
62
+ */
63
+ helptextClassName?: string;
60
64
  /**
61
65
  * Allow user to resize TextArea
62
66
  */
63
67
  resize?: 'both' | 'horizontal' | 'none' | 'vertical';
68
+ /**
69
+ * Auto resize the TextArea based on content
70
+ * @default false
71
+ */
72
+ autoSize?: boolean;
64
73
  /**
65
74
  * Number of lines
66
75
  */
@@ -76,7 +85,7 @@ export type TextAreaProps = {
76
85
  /**
77
86
  * TextArea width
78
87
  */
79
- width?: Size;
88
+ width?: Sizes;
80
89
  /**
81
90
  * Maximum number of characters allowed. 0, null and undefined mean no limitation
82
91
  */
@@ -85,14 +94,18 @@ export type TextAreaProps = {
85
94
  * Resizeable on focus event ?
86
95
  */
87
96
  isResizeableOnFocus?: boolean;
88
- };
97
+ /**
98
+ * If allow to remove input content with clear icon
99
+ * @default true
100
+ */
101
+ allowClear?: boolean;
102
+ }
89
103
 
90
104
  /**
91
105
  * TextArea component that has floating label, caption and resizability.
92
106
  *
93
107
  * `✅ Stable`
94
108
  */
95
-
96
109
  const TextArea: React.FC<TextAreaProps> = ({
97
110
  id = '',
98
111
  name,
@@ -105,6 +118,7 @@ const TextArea: React.FC<TextAreaProps> = ({
105
118
  required = false,
106
119
  status = 'default',
107
120
  helptext = '',
121
+ helptextClassName = '',
108
122
  inputRef = null,
109
123
  resize = 'none',
110
124
  lines = 5,
@@ -113,6 +127,8 @@ const TextArea: React.FC<TextAreaProps> = ({
113
127
  width = 'full',
114
128
  characterLimit = 0,
115
129
  isResizeableOnFocus = false,
130
+ allowClear = true,
131
+ autoSize = false,
116
132
  }) => {
117
133
  const defaultInputRef = useRef<HTMLElement>(null);
118
134
  const ref = inputRef ?? defaultInputRef;
@@ -122,10 +138,30 @@ const TextArea: React.FC<TextAreaProps> = ({
122
138
  const wrapperHeight = 16 + (lines + 1) * 20;
123
139
  const [resizeableHeight, setResizeableHeight] = useState(wrapperHeight);
124
140
  const className = cx(value && 'hasValue', required && 'required');
141
+
142
+ const adjustHeight = () => {
143
+ if (ref.current) {
144
+ ref.current.style.height = 'auto';
145
+ ref.current.style.height = `${ref.current.scrollHeight}px`;
146
+ }
147
+ };
148
+
149
+ useEffect(() => {
150
+ if (autoSize) {
151
+ adjustHeight();
152
+ }
153
+ }, [value, autoSize]);
154
+
155
+ const customOnChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
156
+ if (autoSize) {
157
+ adjustHeight();
158
+ }
159
+ onChange(e);
160
+ };
125
161
  const attrs: Record<string, unknown> = {
126
162
  className,
127
163
  ref,
128
- onChange,
164
+ onChange: customOnChange,
129
165
  value,
130
166
  disabled,
131
167
  inputMode,
@@ -141,37 +177,55 @@ const TextArea: React.FC<TextAreaProps> = ({
141
177
  const wrapperClassname = cx(
142
178
  disabled && 'disabled',
143
179
  isWithError && 'error',
144
- resizable && `resize-${resize}`
180
+ resizable && `resize-${resize}`,
181
+ allowClear && 'showRightIcon'
145
182
  );
146
183
  const containerWidth = sizes[width] || 'initial';
147
184
 
148
185
  const onEmptySpaceClicked = () => {
149
- ref.current.focus();
186
+ ref.current?.focus();
150
187
  };
151
188
 
152
- const handleResizeOnFocus = useCallback(() => {
153
- if (isResizeableOnFocus) {
154
- setResizeableHeight(wrapperHeight * 2);
155
- }
156
- onFocus();
157
- }, [isResizeableOnFocus, wrapperHeight, onFocus]);
189
+ const handleResizeOnFocus = useCallback(
190
+ (e) => {
191
+ if (isResizeableOnFocus) {
192
+ setResizeableHeight(wrapperHeight * 2);
193
+ }
194
+ onFocus(e);
195
+ },
196
+ [isResizeableOnFocus, wrapperHeight, onFocus]
197
+ );
158
198
 
159
- const handleResizeOnBlur = useCallback(() => {
160
- if (isResizeableOnFocus) {
161
- setResizeableHeight(wrapperHeight);
199
+ const handleResizeOnBlur = useCallback(
200
+ (e) => {
201
+ if (isResizeableOnFocus) {
202
+ setResizeableHeight(wrapperHeight);
203
+ }
204
+ onBlur(e);
205
+ },
206
+ [isResizeableOnFocus, wrapperHeight, onBlur]
207
+ );
208
+
209
+ const handleClearInput = () => {
210
+ if (allowClear) {
211
+ simulateChangeEvent(ref, '');
162
212
  }
163
- onBlur();
164
- }, [isResizeableOnFocus, wrapperHeight, onBlur]);
213
+ };
165
214
 
166
215
  return (
167
216
  <Container containerWidth={containerWidth}>
168
- <TextAreaWrapper className={wrapperClassname} wrapperHeight={resizeableHeight + 'px'}>
217
+ <TextAreaWrapper className={wrapperClassname} wrapperHeight={resizeableHeight + 'px'} autoSize={autoSize}>
169
218
  {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
170
219
  <div className="focus-capture" onClick={onEmptySpaceClicked} />
171
220
  <StyledTextArea {...attrs} onFocus={handleResizeOnFocus} onBlur={handleResizeOnBlur} />
172
221
  {!!label && <label htmlFor={id}>{label}</label>}
222
+ {!!allowClear && !!value && (
223
+ <button tabIndex={-1} type="button" onClick={handleClearInput}>
224
+ <CloseFilled width="20px" height="30px" color={colors.iconTertiary} />
225
+ </button>
226
+ )}
173
227
  </TextAreaWrapper>
174
- <Paragraph>{helptext}</Paragraph>
228
+ <Paragraph className={helptextClassName}>{helptext}</Paragraph>
175
229
  </Container>
176
230
  );
177
231
  };
@@ -0,0 +1,35 @@
1
+ import * as React from 'react';
2
+ export interface TextLabelProps {
3
+ /**
4
+ * Size of Text Label
5
+ * @default 'md'
6
+ */
7
+ size?: 'md' | 'sm';
8
+ /**
9
+ * Badge Label
10
+ */
11
+ label?: string;
12
+ /**
13
+ * Badge Background Color
14
+ */
15
+ color?: 'info' | 'success' | 'error' | 'warning' | 'neutral';
16
+ /**
17
+ * Types
18
+ */
19
+ type?: 'text' | 'status';
20
+ /**
21
+ * Classname
22
+ */
23
+ className?: string;
24
+ /**
25
+ * Custom icon
26
+ */
27
+ icon?: React.ReactNode;
28
+ }
29
+ /**
30
+ * Text Label Component
31
+ *
32
+ * `✅ Stable`
33
+ */
34
+ declare const TextLabel: React.FC<TextLabelProps>;
35
+ export default TextLabel;
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ declare const textLabelStory: {
3
+ title: string;
4
+ component: React.FC<import("./TextLabel").TextLabelProps>;
5
+ tags: string[];
6
+ parameters: {
7
+ docs: {
8
+ description: {
9
+ component: string;
10
+ };
11
+ };
12
+ };
13
+ args: {
14
+ label: string;
15
+ };
16
+ };
17
+ export default textLabelStory;
18
+ export declare const Overview: {
19
+ render: (args: any) => JSX.Element;
20
+ };
21
+ export declare const TypesAndColors: {
22
+ render: () => JSX.Element;
23
+ parameters: {
24
+ docs: {
25
+ description: {
26
+ story: string;
27
+ };
28
+ };
29
+ };
30
+ };
31
+ export declare const Sizes: {
32
+ render: () => JSX.Element;
33
+ parameters: {
34
+ docs: {
35
+ description: {
36
+ story: string;
37
+ };
38
+ };
39
+ };
40
+ };