@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.
- package/README.md +3 -3
- package/components/Announcer/Announcer.d.ts +9 -4
- package/components/Announcer/Announcer.stories.d.ts +142 -0
- package/components/Announcer/{Announcer.stories.js → Announcer.stories.tsx} +36 -31
- package/components/Announcer/Announcer.styles.d.ts +24 -12
- package/components/Announcer/{Announcer.styles.js → Announcer.styles.ts} +43 -18
- package/components/Announcer/Announcer.tsx +62 -47
- package/components/Badge/Badge.d.ts +4 -2
- package/components/Badge/Badge.stories.d.ts +61 -0
- package/components/Badge/{Badge.stories.js → Badge.stories.tsx} +5 -5
- package/components/Badge/Badge.styles.d.ts +20 -5
- package/components/Badge/{Badge.styles.js → Badge.styles.ts} +14 -1
- package/components/Badge/Badge.tsx +8 -4
- package/components/Box/Box.d.ts +3 -3
- package/components/Box/Box.stories.d.ts +240 -0
- package/components/Box/{Box.stories.js → Box.stories.tsx} +2 -2
- package/components/Box/Box.styles.d.ts +19 -4
- package/components/Box/{Box.styles.js → Box.styles.ts} +17 -4
- package/components/Box/Box.tsx +4 -4
- package/components/Breadcrumbs/Breadcrumbs.d.ts +2 -2
- package/components/Breadcrumbs/Breadcrumbs.stories.d.ts +52 -0
- package/components/Breadcrumbs/{Breadcrumbs.stories.js → Breadcrumbs.stories.tsx} +17 -15
- package/components/Breadcrumbs/Breadcrumbs.styles.d.ts +5 -4
- package/components/Breadcrumbs/Breadcrumbs.tsx +2 -2
- package/components/Button/Button.d.ts +21 -6
- package/components/Button/Button.stories.d.ts +103 -0
- package/components/Button/{Button.stories.js → Button.stories.tsx} +5 -1
- package/components/Button/Button.styles.d.ts +1 -1
- package/components/Button/{Button.styles.js → Button.styles.ts} +100 -6
- package/components/Button/Button.tsx +51 -18
- package/components/Button/ButtonLink.d.ts +4 -4
- package/components/Button/ButtonLink.stories.d.ts +30 -0
- package/components/Button/ButtonLink.styles.d.ts +1 -1
- package/components/Button/ButtonLink.tsx +5 -5
- package/components/Button/IconButton.d.ts +3 -29
- package/components/Button/IconButton.stories.d.ts +60 -0
- package/components/Button/{IconButton.stories.js → IconButton.stories.tsx} +27 -0
- package/components/Button/IconButton.tsx +2 -42
- package/components/Checkbox/Checkbox.d.ts +3 -3
- package/components/Checkbox/Checkbox.stories.d.ts +88 -0
- package/components/Checkbox/Checkbox.styles.d.ts +2 -2
- package/components/Checkbox/Checkbox.tsx +3 -6
- package/components/Chip/Chip.d.ts +5 -4
- package/components/Chip/Chip.stories.d.ts +153 -0
- package/components/Chip/{Chip.stories.js → Chip.stories.tsx} +4 -5
- package/components/Chip/Chip.styles.d.ts +11 -8
- package/components/Chip/{Chip.styles.js → Chip.styles.ts} +4 -4
- package/components/Chip/Chip.tsx +19 -12
- package/components/CurrencyInput/CurrencyInput.d.ts +3 -56
- package/components/CurrencyInput/CurrencyInput.stories.d.ts +104 -0
- package/components/CurrencyInput/{CurrencyInput.stories.js → CurrencyInput.stories.tsx} +2 -2
- package/components/CurrencyInput/CurrencyInput.styles.d.ts +16 -10
- package/components/CurrencyInput/{CurrencyInput.styles.js → CurrencyInput.styles.ts} +23 -9
- package/components/CurrencyInput/CurrencyInput.tsx +7 -61
- package/components/Dropdown/Dropdown.d.ts +22 -7
- package/components/Dropdown/Dropdown.stories.d.ts +148 -0
- package/components/Dropdown/{Dropdown.stories.js → Dropdown.stories.tsx} +115 -1
- package/components/Dropdown/Dropdown.styles.d.ts +10 -0
- package/components/Dropdown/Dropdown.styles.ts +42 -0
- package/components/Dropdown/Dropdown.tsx +120 -24
- package/components/Grid/Col.d.ts +2 -2
- package/components/Grid/Col.tsx +6 -3
- package/components/Grid/Grid.styles.d.ts +25 -5
- package/components/Grid/{Grid.styles.js → Grid.styles.ts} +16 -3
- package/components/Grid/aGrid.stories.d.ts +127 -0
- package/components/Grid/bCol.stories.d.ts +74 -0
- package/components/Input/Input.d.ts +14 -10
- package/components/Input/Input.stories.d.ts +226 -0
- package/components/Input/{Input.stories.js → Input.stories.tsx} +20 -16
- package/components/Input/Input.styles.d.ts +22 -11
- package/components/Input/{Input.styles.js → Input.styles.ts} +29 -7
- package/components/Input/Input.tsx +22 -20
- package/components/Popover/Popover.d.ts +44 -0
- package/components/Popover/Popover.stories.d.ts +53 -0
- package/components/Popover/Popover.stories.tsx +133 -0
- package/components/Popover/Popover.tsx +121 -0
- package/components/RadioButton/RadioButton.d.ts +5 -6
- package/components/RadioButton/RadioButton.stories.d.ts +94 -0
- package/components/RadioButton/RadioButton.styles.d.ts +7 -3
- package/components/RadioButton/{RadioButton.styles.js → RadioButton.styles.ts} +1 -1
- package/components/RadioButton/RadioButton.tsx +5 -11
- package/components/RowItem/RowItem.d.ts +27 -9
- package/components/RowItem/RowItem.stories.d.ts +131 -0
- package/components/RowItem/RowItem.stories.tsx +710 -0
- package/components/RowItem/RowItem.styles.d.ts +31 -10
- package/components/RowItem/{RowItem.styles.js → RowItem.styles.ts} +41 -13
- package/components/RowItem/RowItem.tsx +106 -42
- package/components/ShapeIcon/ShapeIcon.d.ts +23 -16
- package/components/ShapeIcon/ShapeIcon.stories.d.ts +91 -0
- package/components/ShapeIcon/{ShapeIcon.stories.js → ShapeIcon.stories.tsx} +21 -8
- package/components/ShapeIcon/ShapeIcon.styles.d.ts +8 -3
- package/components/ShapeIcon/{ShapeIcon.styles.js → ShapeIcon.styles.ts} +6 -3
- package/components/ShapeIcon/ShapeIcon.tsx +25 -21
- package/components/Slider/Slider.d.ts +9 -7
- package/components/Slider/Slider.stories.d.ts +81 -0
- package/components/Slider/{Slider.stories.js → Slider.stories.tsx} +7 -7
- package/components/Slider/Slider.styles.d.ts +15 -11
- package/components/Slider/{Slider.styles.js → Slider.styles.ts} +1 -1
- package/components/Slider/Slider.tsx +21 -16
- package/components/Snack/Snack.d.ts +4 -5
- package/components/Snack/Snack.stories.d.ts +87 -0
- package/components/Snack/Snack.styles.d.ts +9 -8
- package/components/Snack/{Snack.styles.js → Snack.styles.ts} +4 -4
- package/components/Snack/Snack.tsx +14 -11
- package/components/Tabs/Tab.d.ts +6 -6
- package/components/Tabs/Tab.tsx +6 -7
- package/components/Tabs/Tabs.d.ts +7 -4
- package/components/Tabs/Tabs.stories.d.ts +64 -0
- package/components/Tabs/{Tabs.stories.js → Tabs.stories.tsx} +2 -2
- package/components/Tabs/Tabs.styles.d.ts +30 -12
- package/components/Tabs/{Tabs.styles.js → Tabs.styles.ts} +4 -4
- package/components/Tabs/Tabs.tsx +11 -7
- package/components/TextArea/TextArea.d.ts +24 -11
- package/components/TextArea/TextArea.stories.d.ts +151 -0
- package/components/TextArea/{TextArea.stories.js → TextArea.stories.tsx} +5 -96
- package/components/TextArea/TextArea.styles.d.ts +18 -16
- package/components/TextArea/{TextArea.styles.js → TextArea.styles.ts} +39 -19
- package/components/TextArea/TextArea.tsx +85 -31
- package/components/TextLabel/TextLabel.d.ts +35 -0
- package/components/TextLabel/TextLabel.stories.d.ts +40 -0
- package/components/TextLabel/TextLabel.stories.tsx +177 -0
- package/components/TextLabel/TextLabel.styles.d.ts +9 -0
- package/components/TextLabel/TextLabel.styles.ts +24 -0
- package/components/TextLabel/TextLabel.tsx +112 -0
- package/components/ToggleSwitch/ToggleSwitch.d.ts +2 -2
- package/components/ToggleSwitch/ToggleSwitch.stories.d.ts +38 -0
- package/components/ToggleSwitch/ToggleSwitch.styles.d.ts +21 -14
- package/components/ToggleSwitch/{ToggleSwitch.styles.js → ToggleSwitch.styles.ts} +8 -12
- package/components/ToggleSwitch/ToggleSwitch.tsx +12 -6
- package/components/Tooltip/Tooltip.d.ts +9 -3
- package/components/Tooltip/Tooltip.spec.js +5 -3
- package/components/Tooltip/Tooltip.styles.d.ts +7 -8
- package/components/Tooltip/Tooltip.tsx +10 -3
- package/components/index.d.ts +2 -0
- package/components/index.ts +2 -0
- package/icons/PrivateSellerAvatar.d.ts +3 -0
- package/icons/PrivateSellerAvatar.js +3 -0
- package/icons/Sda.d.ts +5 -2
- package/icons/Sda.js +7 -7
- package/icons/VerifiedShop.d.ts +3 -0
- package/icons/VerifiedShop.js +3 -0
- package/package.json +6 -6
- package/patterns/Drawer/Drawer.d.ts +13 -13
- package/patterns/Drawer/Drawer.stories.d.ts +90 -0
- package/patterns/Drawer/{Drawer.stories.js → Drawer.stories.tsx} +25 -0
- package/patterns/Drawer/Drawer.styles.d.ts +30 -26
- package/patterns/Drawer/{Drawer.styles.js → Drawer.styles.ts} +2 -5
- package/patterns/Drawer/Drawer.tsx +20 -41
- package/patterns/EmptyState/EmptyState.d.ts +5 -4
- package/patterns/EmptyState/EmptyState.stories.d.ts +40 -0
- package/patterns/EmptyState/EmptyState.styles.d.ts +10 -10
- package/patterns/EmptyState/{EmptyState.styles.js → EmptyState.styles.ts} +5 -4
- package/patterns/EmptyState/EmptyState.tsx +14 -12
- package/patterns/InputGroup/InputGroup.d.ts +4 -0
- package/patterns/InputGroup/InputGroup.styles.d.ts +5 -4
- package/patterns/InputGroup/InputGroup.tsx +11 -5
- package/patterns/LegacyDialog/DialogMainIcon.d.ts +1 -0
- package/patterns/LegacyDialog/DialogMainIcon.js +51 -0
- package/patterns/LegacyDialog/LegacyDialog.d.ts +3 -3
- package/patterns/LegacyDialog/LegacyDialog.styles.d.ts +8 -10
- package/patterns/LegacyDialog/LegacyDialog.styles.js +1 -46
- package/patterns/LegacyDialog/LegacyDialog.tsx +5 -11
- package/patterns/LegacyPopup/LegacyPopup.d.ts +4 -4
- package/patterns/LegacyPopup/LegacyPopup.styles.d.ts +18 -13
- package/patterns/LegacyPopup/{LegacyPopup.styles.js → LegacyPopup.styles.ts} +3 -1
- package/patterns/LegacyPopup/LegacyPopup.tsx +4 -6
- package/patterns/MultiSearchDropdown/MultiSearchDropdown.d.ts +20 -17
- package/patterns/MultiSearchDropdown/MultiSearchDropdown.stories.d.ts +125 -0
- package/patterns/MultiSearchDropdown/{MultiSearchDropdown.stories.js → MultiSearchDropdown.stories.tsx} +31 -30
- package/patterns/MultiSearchDropdown/MultiSearchDropdown.styles.d.ts +22 -21
- package/patterns/MultiSearchDropdown/{MultiSearchDropdown.styles.js → MultiSearchDropdown.styles.ts} +1 -7
- package/patterns/MultiSearchDropdown/MultiSearchDropdown.tsx +33 -32
- package/patterns/Popup/Popup.d.ts +8 -7
- package/patterns/Popup/Popup.stories.d.ts +102 -0
- package/patterns/Popup/Popup.styles.d.ts +41 -30
- package/patterns/Popup/{Popup.styles.js → Popup.styles.ts} +26 -33
- package/patterns/Popup/Popup.tsx +14 -33
- package/patterns/SearchInput/SearchInput.d.ts +38 -21
- package/patterns/SearchInput/SearchInput.stories.d.ts +186 -0
- package/patterns/SearchInput/{SearchInput.stories.js → SearchInput.stories.tsx} +78 -45
- package/patterns/SearchInput/SearchInput.styles.d.ts +6 -5
- package/patterns/SearchInput/{SearchInput.styles.js → SearchInput.styles.ts} +7 -4
- package/patterns/SearchInput/SearchInput.tsx +53 -34
- package/patterns/TagCloud/TagCloud.d.ts +19 -6
- package/patterns/TagCloud/TagCloud.stories.d.ts +159 -0
- package/patterns/TagCloud/{TagCloud.stories.js → TagCloud.stories.tsx} +59 -14
- package/patterns/TagCloud/TagCloud.styles.d.ts +12 -8
- package/patterns/TagCloud/{TagCloud.styles.js → TagCloud.styles.ts} +6 -7
- package/patterns/TagCloud/TagCloud.tsx +24 -8
- package/patterns/TagCloud/TagCloudMultiActive.d.ts +6 -4
- package/patterns/TagCloud/TagCloudMultiActive.tsx +5 -5
- package/patterns/TagCloud/TagCloudSingleActive.d.ts +5 -2
- package/patterns/TagCloud/TagCloudSingleActive.tsx +18 -5
- package/patterns/patterns-index.spec.js +1 -1
- package/storybook/GuideImage.d.ts +2 -2
- package/storybook/Swatch.d.ts +2 -2
- package/theme/__snapshots__/chotot.spec.js.snap +2 -2
- package/theme/chotot-color1.d.ts +7 -14
- package/theme/chotot.d.ts +32 -32
- package/theme/chotot.js +4 -4
- package/theme/ct-job.d.ts +6 -14
- package/theme/ct-pty.d.ts +6 -8
- package/theme/mudah.d.ts +14 -13
- package/types.d.ts +0 -9
- package/utils/_simulateChangeEvent.d.ts +18 -3
- package/utils/_simulateChangeEvent.js +13 -6
- package/utils/_simulateChangeEvent.spec.js +1 -1
- package/utils/cx.d.ts +8 -4
- package/utils/cx.js +8 -4
- package/utils/sx.d.ts +12 -4192
- package/components/RowItem/RowItem.stories.js +0 -560
- /package/components/Breadcrumbs/{Breadcrumbs.styles.js → Breadcrumbs.styles.ts} +0 -0
- /package/components/Button/{ButtonLink.stories.js → ButtonLink.stories.tsx} +0 -0
- /package/components/Button/{ButtonLink.styles.js → ButtonLink.styles.ts} +0 -0
- /package/components/Checkbox/{Checkbox.stories.js → Checkbox.stories.tsx} +0 -0
- /package/components/Checkbox/{Checkbox.styles.js → Checkbox.styles.ts} +0 -0
- /package/components/Grid/{aGrid.stories.js → aGrid.stories.tsx} +0 -0
- /package/components/Grid/{bCol.stories.js → bCol.stories.tsx} +0 -0
- /package/components/RadioButton/{RadioButton.stories.js → RadioButton.stories.tsx} +0 -0
- /package/components/Snack/{Snack.stories.js → Snack.stories.tsx} +0 -0
- /package/components/ToggleSwitch/{ToggleSwitch.stories.js → ToggleSwitch.stories.tsx} +0 -0
- /package/patterns/EmptyState/{EmptyState.stories.js → EmptyState.stories.tsx} +0 -0
- /package/patterns/InputGroup/{InputGroup.styles.js → InputGroup.styles.ts} +0 -0
- /package/patterns/Popup/{Popup.stories.js → Popup.stories.tsx} +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React, { useState
|
|
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
|
|
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
|
-
|
|
382
|
-
label="
|
|
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: '
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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};
|
|
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.
|
|
71
|
-
font-size:
|
|
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.
|
|
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
|
|
2
|
-
import
|
|
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
|
-
|
|
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<
|
|
23
|
+
inputRef?: React.RefObject<HTMLTextAreaElement>;
|
|
24
24
|
/**
|
|
25
25
|
* The TextArea content value
|
|
26
26
|
*/
|
|
27
|
-
value?:
|
|
27
|
+
value?: string;
|
|
28
28
|
/**
|
|
29
29
|
* Callback when user input
|
|
30
30
|
*/
|
|
31
|
-
onChange?:
|
|
31
|
+
onChange?: React.ChangeEventHandler<HTMLTextAreaElement>;
|
|
32
32
|
/**
|
|
33
33
|
* Callback when user blur
|
|
34
34
|
*/
|
|
35
|
-
onBlur?:
|
|
35
|
+
onBlur?: React.FocusEventHandler<HTMLTextAreaElement>;
|
|
36
36
|
/**
|
|
37
37
|
* Callback when user focus
|
|
38
38
|
*/
|
|
39
|
-
onFocus?:
|
|
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?:
|
|
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
|
|
186
|
+
ref.current?.focus();
|
|
150
187
|
};
|
|
151
188
|
|
|
152
|
-
const handleResizeOnFocus = useCallback(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
161
|
-
|
|
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
|
-
|
|
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
|
+
};
|