adnbn-ui 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +3 -0
- package/.prettierrc +28 -0
- package/.storybook/main.ts +22 -0
- package/.storybook/preview.tsx +100 -0
- package/.storybook/styles/custom.scss +59 -0
- package/.storybook/styles/preview.css +58 -0
- package/.storybook/vitest.setup.ts +9 -0
- package/README.md +1057 -0
- package/eslint.config.js +39 -0
- package/package.json +95 -4
- package/src/components/Avatar/Avatar.stories.tsx +118 -0
- package/src/components/Avatar/Avatar.tsx +65 -0
- package/src/components/Avatar/avatar.module.scss +77 -0
- package/src/components/Avatar/index.ts +2 -0
- package/src/components/BaseButton/BaseButton.tsx +36 -0
- package/src/components/BaseButton/base-button.module.scss +24 -0
- package/src/components/BaseButton/index.ts +2 -0
- package/src/components/Button/Button.stories.tsx +148 -0
- package/src/components/Button/Button.tsx +73 -0
- package/src/components/Button/button.module.scss +140 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +180 -0
- package/src/components/Checkbox/Checkbox.tsx +71 -0
- package/src/components/Checkbox/checkbox.module.scss +82 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/Dialog/Dialog.tsx +125 -0
- package/src/components/Dialog/dialog.module.scss +55 -0
- package/src/components/Dialog/index.ts +2 -0
- package/src/components/Drawer/Drawer.stories.tsx +89 -0
- package/src/components/Drawer/Drawer.tsx +57 -0
- package/src/components/Drawer/drawer.module.scss +170 -0
- package/src/components/Drawer/index.ts +2 -0
- package/src/components/Footer/Footer.stories.tsx +118 -0
- package/src/components/Footer/Footer.tsx +58 -0
- package/src/components/Footer/footer.module.scss +44 -0
- package/src/components/Footer/index.ts +2 -0
- package/src/components/Header/Header.stories.tsx +49 -0
- package/src/components/Header/Header.tsx +73 -0
- package/src/components/Header/header.module.scss +56 -0
- package/src/components/Header/index.ts +2 -0
- package/src/components/Highlight/Highlight.stories.tsx +83 -0
- package/src/components/Highlight/Highlight.tsx +40 -0
- package/src/components/Highlight/highlight.module.scss +47 -0
- package/src/components/Highlight/index.ts +2 -0
- package/src/components/Icon/Icon.tsx +46 -0
- package/src/components/Icon/icon.module.scss +17 -0
- package/src/components/Icon/index.ts +2 -0
- package/src/components/IconButton/IconButton.stories.tsx +179 -0
- package/src/components/IconButton/IconButton.tsx +65 -0
- package/src/components/IconButton/icon-button.module.scss +86 -0
- package/src/components/IconButton/index.ts +2 -0
- package/src/components/Layout/Layout.stories.tsx +88 -0
- package/src/components/Layout/Provider.tsx +47 -0
- package/src/components/Layout/context.ts +24 -0
- package/src/components/Layout/index.ts +2 -0
- package/src/components/Layout/layout.module.scss +17 -0
- package/src/components/List/List.stories.tsx +81 -0
- package/src/components/List/List.tsx +24 -0
- package/src/components/List/index.ts +2 -0
- package/src/components/List/list.module.scss +8 -0
- package/src/components/ListItem/ListItem.tsx +75 -0
- package/src/components/ListItem/index.ts +2 -0
- package/src/components/ListItem/list-item.module.scss +36 -0
- package/src/components/Modal/Modal.stories.tsx +95 -0
- package/src/components/Modal/Modal.tsx +94 -0
- package/src/components/Modal/index.ts +2 -0
- package/src/components/Modal/modal.module.scss +97 -0
- package/src/components/Odometer/Odometer.stories.tsx +66 -0
- package/src/components/Odometer/Odometer.tsx +45 -0
- package/src/components/Odometer/hooks/useOdometer.tsx +24 -0
- package/src/components/Odometer/index.ts +3 -0
- package/src/components/Odometer/odometer.module.scss +81 -0
- package/src/components/Odometer/odometr.d.ts +9 -0
- package/src/components/ScrollArea/ScrollArea.stories.tsx +58 -0
- package/src/components/ScrollArea/ScrollArea.tsx +63 -0
- package/src/components/ScrollArea/index.ts +2 -0
- package/src/components/ScrollArea/scroll-area.module.scss +54 -0
- package/src/components/SvgSprite/SvgSprite.tsx +21 -0
- package/src/components/SvgSprite/index.ts +2 -0
- package/src/components/Switch/Switch.stories.tsx +25 -0
- package/src/components/Switch/Switch.tsx +23 -0
- package/src/components/Switch/index.ts +2 -0
- package/src/components/Switch/switch.module.scss +65 -0
- package/src/components/Tag/Tag.stories.tsx +157 -0
- package/src/components/Tag/Tag.tsx +71 -0
- package/src/components/Tag/index.ts +2 -0
- package/src/components/Tag/tag.module.scss +118 -0
- package/src/components/TextArea/TextArea.stories.tsx +145 -0
- package/src/components/TextArea/TextArea.tsx +143 -0
- package/src/components/TextArea/index.ts +2 -0
- package/src/components/TextArea/text-area.module.scss +88 -0
- package/src/components/TextField/TextField.stories.tsx +177 -0
- package/src/components/TextField/TextField.tsx +162 -0
- package/src/components/TextField/index.ts +2 -0
- package/src/components/TextField/text-field.module.scss +129 -0
- package/src/components/Toast/Toast.stories.tsx +209 -0
- package/src/components/Toast/Toast.tsx +142 -0
- package/src/components/Toast/index.ts +2 -0
- package/src/components/Toast/toast.module.scss +267 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +80 -0
- package/src/components/Tooltip/Tooltip.tsx +79 -0
- package/src/components/Tooltip/index.ts +2 -0
- package/src/components/Tooltip/tooltip.module.scss +93 -0
- package/src/components/View/View.stories.tsx +47 -0
- package/src/components/View/View.tsx +68 -0
- package/src/components/View/index.ts +2 -0
- package/src/components/View/view.module.scss +38 -0
- package/src/components/ViewDrawer/ViewDrawer.stories.tsx +75 -0
- package/src/components/ViewDrawer/ViewDrawer.tsx +24 -0
- package/src/components/ViewDrawer/index.ts +2 -0
- package/src/components/ViewModal/ViewModal.stories.tsx +68 -0
- package/src/components/ViewModal/ViewModal.tsx +24 -0
- package/src/components/ViewModal/index.ts +2 -0
- package/src/components/index.ts +29 -0
- package/src/components/types.ts +65 -0
- package/src/config/default.ts +3 -0
- package/src/config/index.ts +26 -0
- package/src/declaration.d.ts +8 -0
- package/src/index.ts +3 -0
- package/src/plugin/builder/ConfigBuilder.ts +32 -0
- package/src/plugin/builder/StyleBuilder.ts +34 -0
- package/src/plugin/builder/virtual.config.ts +7 -0
- package/src/plugin/finder/ConfigFinder.ts +26 -0
- package/src/plugin/finder/Finder.ts +76 -0
- package/src/plugin/finder/StyleFinder.ts +23 -0
- package/src/plugin/index.ts +70 -0
- package/src/plugin/types.ts +8 -0
- package/src/providers/UIProvider.tsx +26 -0
- package/src/providers/icons/IconsProvider.tsx +34 -0
- package/src/providers/icons/context.ts +22 -0
- package/src/providers/icons/index.ts +3 -0
- package/src/providers/index.ts +3 -0
- package/src/providers/theme/ThemeProvider.tsx +39 -0
- package/src/providers/theme/context.ts +30 -0
- package/src/providers/theme/index.ts +2 -0
- package/src/providers/theme/styles/default.scss +95 -0
- package/src/providers/theme/styles/reset.css +111 -0
- package/src/styles/mixins.scss +23 -0
- package/src/types/theme.ts +4 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/react.ts +21 -0
- package/src/utils/utils.ts +12 -0
- package/tsconfig.json +18 -0
- package/vite.config.ts +11 -0
- package/vitest.workspace.ts +19 -0
- package/components/Button/index.ts +0 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
import {Meta, StoryObj} from "@storybook/react";
|
2
|
+
|
3
|
+
import {capitalizeFirstLetter} from "../../utils";
|
4
|
+
|
5
|
+
import TagComponent, {TagColor, TagRadius, TagSize, TagVariant} from "./Tag";
|
6
|
+
|
7
|
+
const variants: TagVariant[] = [TagVariant.Contained, TagVariant.Outlined, TagVariant.Soft];
|
8
|
+
const colors: (TagColor | "default")[] = ["default", TagColor.Primary, TagColor.Secondary, TagColor.Accent];
|
9
|
+
const sizes: (TagSize | "default")[] = [TagSize.Small, "default", TagSize.Medium, TagSize.Large];
|
10
|
+
const radius: (TagRadius | "default")[] = [TagRadius.Small, TagRadius.Medium, TagRadius.Large, "default"];
|
11
|
+
|
12
|
+
const meta: Meta<typeof TagComponent> = {
|
13
|
+
title: "Components/Tag",
|
14
|
+
component: TagComponent,
|
15
|
+
tags: ["autodocs"],
|
16
|
+
argTypes: {
|
17
|
+
variant: {
|
18
|
+
options: variants,
|
19
|
+
control: {type: "select"},
|
20
|
+
},
|
21
|
+
color: {
|
22
|
+
options: colors,
|
23
|
+
control: {type: "select"},
|
24
|
+
},
|
25
|
+
size: {
|
26
|
+
options: sizes,
|
27
|
+
control: {type: "select"},
|
28
|
+
},
|
29
|
+
radius: {
|
30
|
+
options: radius,
|
31
|
+
control: {type: "select"},
|
32
|
+
},
|
33
|
+
},
|
34
|
+
};
|
35
|
+
|
36
|
+
export default meta;
|
37
|
+
|
38
|
+
export const Tag: StoryObj<typeof TagComponent> = {
|
39
|
+
args: {
|
40
|
+
children: "Test",
|
41
|
+
variant: TagVariant.Contained,
|
42
|
+
color: TagColor.Primary,
|
43
|
+
clickable: false,
|
44
|
+
},
|
45
|
+
};
|
46
|
+
|
47
|
+
export const Variant = () => {
|
48
|
+
return (
|
49
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(3, auto)"}}>
|
50
|
+
{variants.map(variant => (
|
51
|
+
<div key={variant} className="item-card">
|
52
|
+
<TagComponent variant={variant} color={TagColor.Primary}>
|
53
|
+
{capitalizeFirstLetter(variant)}
|
54
|
+
</TagComponent>
|
55
|
+
</div>
|
56
|
+
))}
|
57
|
+
</div>
|
58
|
+
);
|
59
|
+
};
|
60
|
+
|
61
|
+
export const VariantDisabled = () => {
|
62
|
+
return (
|
63
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(3, auto)"}}>
|
64
|
+
{variants.map(variant => (
|
65
|
+
<div key={variant} className="item-card">
|
66
|
+
<TagComponent variant={variant} color={TagColor.Primary}>
|
67
|
+
{capitalizeFirstLetter(variant)}
|
68
|
+
</TagComponent>
|
69
|
+
</div>
|
70
|
+
))}
|
71
|
+
</div>
|
72
|
+
);
|
73
|
+
};
|
74
|
+
|
75
|
+
export const Size = () => {
|
76
|
+
return (
|
77
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
|
78
|
+
{sizes.map(size => (
|
79
|
+
<div key={size} className="item-card">
|
80
|
+
<TagComponent size={size !== "default" ? size : undefined} color={TagColor.Primary}>
|
81
|
+
{capitalizeFirstLetter(size)}
|
82
|
+
</TagComponent>
|
83
|
+
</div>
|
84
|
+
))}
|
85
|
+
</div>
|
86
|
+
);
|
87
|
+
};
|
88
|
+
|
89
|
+
export const Radius = () => {
|
90
|
+
return (
|
91
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
|
92
|
+
{radius.map(radius => (
|
93
|
+
<div key={radius} className="item-card">
|
94
|
+
<TagComponent radius={radius !== "default" ? radius : undefined} color={TagColor.Primary}>
|
95
|
+
{capitalizeFirstLetter(radius)}
|
96
|
+
</TagComponent>
|
97
|
+
</div>
|
98
|
+
))}
|
99
|
+
</div>
|
100
|
+
);
|
101
|
+
};
|
102
|
+
|
103
|
+
export const VariantColor = () => {
|
104
|
+
return (
|
105
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
|
106
|
+
{variants.map(variant =>
|
107
|
+
colors.map(color => (
|
108
|
+
<div key={`${variant}-${color}`}>
|
109
|
+
<TagComponent variant={variant} color={color !== "default" ? color : undefined}>
|
110
|
+
{capitalizeFirstLetter(color)}
|
111
|
+
</TagComponent>
|
112
|
+
</div>
|
113
|
+
))
|
114
|
+
)}
|
115
|
+
</div>
|
116
|
+
);
|
117
|
+
};
|
118
|
+
|
119
|
+
export const VariantSize = () => {
|
120
|
+
return (
|
121
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
|
122
|
+
{variants.map(variant =>
|
123
|
+
sizes.map(size => (
|
124
|
+
<div key={`${variant}-${size}`}>
|
125
|
+
<TagComponent
|
126
|
+
variant={variant}
|
127
|
+
size={size !== "default" ? size : undefined}
|
128
|
+
color={TagColor.Primary}
|
129
|
+
>
|
130
|
+
{capitalizeFirstLetter(size)}
|
131
|
+
</TagComponent>
|
132
|
+
</div>
|
133
|
+
))
|
134
|
+
)}
|
135
|
+
</div>
|
136
|
+
);
|
137
|
+
};
|
138
|
+
|
139
|
+
export const VariantRadius = () => {
|
140
|
+
return (
|
141
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
|
142
|
+
{variants.map(variant =>
|
143
|
+
radius.map(radius => (
|
144
|
+
<div key={`${variant}-${radius}`}>
|
145
|
+
<TagComponent
|
146
|
+
variant={variant}
|
147
|
+
radius={radius !== "default" ? radius : undefined}
|
148
|
+
color={TagColor.Primary}
|
149
|
+
>
|
150
|
+
{capitalizeFirstLetter(radius)}
|
151
|
+
</TagComponent>
|
152
|
+
</div>
|
153
|
+
))
|
154
|
+
)}
|
155
|
+
</div>
|
156
|
+
);
|
157
|
+
};
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import React, {ComponentProps, FC, memo} from "react";
|
2
|
+
import classnames from "classnames";
|
3
|
+
import {useComponentProps} from "../../providers";
|
4
|
+
|
5
|
+
import styles from "./tag.module.scss";
|
6
|
+
|
7
|
+
export enum TagVariant {
|
8
|
+
Contained = "contained",
|
9
|
+
Outlined = "outlined",
|
10
|
+
Soft = "soft",
|
11
|
+
}
|
12
|
+
|
13
|
+
export enum TagColor {
|
14
|
+
Primary = "primary",
|
15
|
+
Secondary = "secondary",
|
16
|
+
Accent = "accent",
|
17
|
+
}
|
18
|
+
|
19
|
+
export enum TagSize {
|
20
|
+
Small = "small",
|
21
|
+
Medium = "medium",
|
22
|
+
Large = "large",
|
23
|
+
}
|
24
|
+
|
25
|
+
export enum TagRadius {
|
26
|
+
Small = "small",
|
27
|
+
Medium = "medium",
|
28
|
+
Large = "large",
|
29
|
+
}
|
30
|
+
|
31
|
+
export interface TagProps extends ComponentProps<"span"> {
|
32
|
+
size?: TagSize;
|
33
|
+
color?: TagColor;
|
34
|
+
radius?: TagRadius;
|
35
|
+
variant?: TagVariant;
|
36
|
+
clickable?: boolean;
|
37
|
+
}
|
38
|
+
|
39
|
+
const Tag: FC<TagProps> = props => {
|
40
|
+
const {
|
41
|
+
size,
|
42
|
+
color,
|
43
|
+
radius,
|
44
|
+
variant = TagVariant.Contained,
|
45
|
+
clickable,
|
46
|
+
children,
|
47
|
+
className,
|
48
|
+
...other
|
49
|
+
} = {...useComponentProps("tag"), ...props};
|
50
|
+
|
51
|
+
return (
|
52
|
+
<span
|
53
|
+
{...other}
|
54
|
+
className={classnames(
|
55
|
+
styles["tag"],
|
56
|
+
{
|
57
|
+
[styles[`tag--${variant}`]]: variant,
|
58
|
+
[styles[`tag--${radius}-radius`]]: radius,
|
59
|
+
[styles[`tag--${color}-color`]]: color,
|
60
|
+
[styles[`tag--${size}-size`]]: size,
|
61
|
+
[styles["tag--clickable"]]: clickable,
|
62
|
+
},
|
63
|
+
className
|
64
|
+
)}
|
65
|
+
>
|
66
|
+
{children}
|
67
|
+
</span>
|
68
|
+
);
|
69
|
+
};
|
70
|
+
|
71
|
+
export default memo(Tag);
|
@@ -0,0 +1,118 @@
|
|
1
|
+
$root: tag;
|
2
|
+
|
3
|
+
.#{$root} {
|
4
|
+
cursor: default;
|
5
|
+
display: inline-flex;
|
6
|
+
align-items: center;
|
7
|
+
justify-content: center;
|
8
|
+
font-size: var(--tag-font-size, 13px);
|
9
|
+
font-weight: var(--tag-font-weight, 500);
|
10
|
+
line-height: var(--tag-line-height, 1rem);
|
11
|
+
letter-spacing: var(--tag-letter-spacing, 0.5px);
|
12
|
+
padding: var(--tag-padding, 4px 8px);
|
13
|
+
border-radius: var(--tag-border-radius, 999px);
|
14
|
+
color: var(--tag-color, var(--text-secondary-color));
|
15
|
+
background: var(--tag-bg-color, var(--bg-secondary-color));
|
16
|
+
|
17
|
+
&--clickable {
|
18
|
+
cursor: pointer;
|
19
|
+
|
20
|
+
&:active {
|
21
|
+
transform: scale(var(--tag-scale, 0.98));
|
22
|
+
user-select: none;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
// Variants
|
27
|
+
&--contained {
|
28
|
+
color: var(--tag-contained-color, var(--tag-color, var(--text-secondary-color)));
|
29
|
+
background: var(--tag-contained-bg-color, var(--tag-bg-color, var(--bg-secondary-color)));
|
30
|
+
border: none;
|
31
|
+
|
32
|
+
&.#{$root}--primary-color {
|
33
|
+
color: var(--tag-contained-primary-color, #fff);
|
34
|
+
background: var(--primary-color);
|
35
|
+
}
|
36
|
+
|
37
|
+
&.#{$root}--secondary-color {
|
38
|
+
color: var(--tag-contained-secondary-color, #fff);
|
39
|
+
background: var(--secondary-color);
|
40
|
+
}
|
41
|
+
|
42
|
+
&.#{$root}--accent-color {
|
43
|
+
color: var(--tag-contained-accent-color, #fff);
|
44
|
+
background: var(--accent-color);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
&--outlined {
|
49
|
+
color: var(--tag-outlined-color, var(--tag-color, var(--text-secondary-color)));
|
50
|
+
border: var(--tag-border-width, 1px) solid
|
51
|
+
var(--tag-outlined-border-color, var(--tag-outlined-color, var(--text-secondary-color)));
|
52
|
+
background: none;
|
53
|
+
|
54
|
+
&.#{$root}--primary-color {
|
55
|
+
color: var(--primary-color);
|
56
|
+
border-color: var(--tag-outlined-border-primary-color, var(--primary-color));
|
57
|
+
}
|
58
|
+
|
59
|
+
&.#{$root}--secondary-color {
|
60
|
+
color: var(--secondary-color);
|
61
|
+
border-color: var(--tag-outlined-border-secondary-color, var(--secondary-color));
|
62
|
+
}
|
63
|
+
|
64
|
+
&.#{$root}--accent-color {
|
65
|
+
color: var(--accent-color);
|
66
|
+
border-color: var(--tag-outlined-border-accent-color, var(--accent-color));
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
&--soft {
|
71
|
+
color: var(--tag-soft-color, var(--tag-color, var(--text-secondary-color)));
|
72
|
+
background-color: color-mix(in srgb, white 30%, var(--tag-bg-color, var(--bg-secondary-color)));
|
73
|
+
|
74
|
+
&.#{$root}--primary-color {
|
75
|
+
color: var(--tag-soft-primary-color, #fff);
|
76
|
+
background-color: color-mix(in srgb, white 30%, var(--primary-color));
|
77
|
+
}
|
78
|
+
|
79
|
+
&.#{$root}--secondary-color {
|
80
|
+
color: var(--tag-soft-secondary-color, #fff);
|
81
|
+
background-color: color-mix(in srgb, white 30%, var(--secondary-color));
|
82
|
+
}
|
83
|
+
|
84
|
+
&.#{$root}--accent-color {
|
85
|
+
color: var(--tag-soft-accent-color, #fff);
|
86
|
+
background-color: color-mix(in srgb, white 30%, var(--accent-color));
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
// Sizes
|
91
|
+
&--small-size {
|
92
|
+
padding: var(--tag-padding, 3px 6px);
|
93
|
+
font-size: var(--tag-font-size-sm, 12px);
|
94
|
+
}
|
95
|
+
|
96
|
+
&--medium-size {
|
97
|
+
padding: var(--tag-padding, 5px 10px);
|
98
|
+
font-size: var(--tag-font-size-sm, 14px);
|
99
|
+
}
|
100
|
+
|
101
|
+
&--large-size {
|
102
|
+
padding: var(--tag-padding, 6px 12px);
|
103
|
+
font-size: var(--tag-font-size-sm, 16px);
|
104
|
+
}
|
105
|
+
|
106
|
+
//Radius
|
107
|
+
&--small-radius {
|
108
|
+
border-radius: var(--tag-border-radius-sm, 5px);
|
109
|
+
}
|
110
|
+
|
111
|
+
&--medium-radius {
|
112
|
+
border-radius: var(--tag-border-radius-md, 8px);
|
113
|
+
}
|
114
|
+
|
115
|
+
&--large-radius {
|
116
|
+
border-radius: var(--tag-border-radius-lg, 10px);
|
117
|
+
}
|
118
|
+
}
|
@@ -0,0 +1,145 @@
|
|
1
|
+
import {Fragment} from "react";
|
2
|
+
import {Meta, StoryObj} from "@storybook/react";
|
3
|
+
|
4
|
+
import {capitalizeFirstLetter, hideInTable} from "../../utils";
|
5
|
+
|
6
|
+
import TextAreaComponent, {TextAreaRadius, TextAreaSize, TextAreaVariant} from "./TextArea";
|
7
|
+
|
8
|
+
const variants: TextAreaVariant[] = [TextAreaVariant.Regular, TextAreaVariant.Outlined, TextAreaVariant.Filled];
|
9
|
+
const sizes: (TextAreaSize | "default")[] = [TextAreaSize.Small, "default", TextAreaSize.Medium, TextAreaSize.Large];
|
10
|
+
const radius: (TextAreaRadius | "default")[] = [
|
11
|
+
TextAreaRadius.None,
|
12
|
+
TextAreaRadius.Small,
|
13
|
+
"default",
|
14
|
+
TextAreaRadius.Medium,
|
15
|
+
TextAreaRadius.Large,
|
16
|
+
];
|
17
|
+
|
18
|
+
const meta: Meta<typeof TextAreaComponent> = {
|
19
|
+
title: "Components/TextArea",
|
20
|
+
component: TextAreaComponent,
|
21
|
+
tags: ["autodocs"],
|
22
|
+
argTypes: {
|
23
|
+
variant: {
|
24
|
+
options: variants,
|
25
|
+
control: {type: "select"},
|
26
|
+
},
|
27
|
+
size: {
|
28
|
+
options: sizes,
|
29
|
+
control: {type: "select"},
|
30
|
+
},
|
31
|
+
radius: {
|
32
|
+
options: radius,
|
33
|
+
control: {type: "select"},
|
34
|
+
},
|
35
|
+
|
36
|
+
label: hideInTable,
|
37
|
+
children: hideInTable,
|
38
|
+
},
|
39
|
+
};
|
40
|
+
|
41
|
+
export default meta;
|
42
|
+
|
43
|
+
export const TextArea: StoryObj<typeof TextAreaComponent> = {
|
44
|
+
args: {
|
45
|
+
placeholder: "Enter text",
|
46
|
+
disabled: false,
|
47
|
+
fullWidth: false,
|
48
|
+
},
|
49
|
+
};
|
50
|
+
|
51
|
+
export const Variant = () => {
|
52
|
+
return (
|
53
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(3, auto)"}}>
|
54
|
+
{variants.map(variant => (
|
55
|
+
<div key={variant}>
|
56
|
+
<TextAreaComponent variant={variant} placeholder={capitalizeFirstLetter(variant)} />
|
57
|
+
</div>
|
58
|
+
))}
|
59
|
+
</div>
|
60
|
+
);
|
61
|
+
};
|
62
|
+
|
63
|
+
export const Size = () => {
|
64
|
+
return (
|
65
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(4, auto)"}}>
|
66
|
+
{sizes.map(size => (
|
67
|
+
<div key={size}>
|
68
|
+
<TextAreaComponent
|
69
|
+
size={size !== "default" ? size : undefined}
|
70
|
+
placeholder={capitalizeFirstLetter(size)}
|
71
|
+
/>
|
72
|
+
</div>
|
73
|
+
))}
|
74
|
+
</div>
|
75
|
+
);
|
76
|
+
};
|
77
|
+
|
78
|
+
export const Radius = () => {
|
79
|
+
return (
|
80
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(3, auto)"}}>
|
81
|
+
{radius.map(radius => (
|
82
|
+
<div key={radius}>
|
83
|
+
<TextAreaComponent
|
84
|
+
radius={radius !== "default" ? radius : undefined}
|
85
|
+
placeholder={capitalizeFirstLetter(radius)}
|
86
|
+
/>
|
87
|
+
</div>
|
88
|
+
))}
|
89
|
+
</div>
|
90
|
+
);
|
91
|
+
};
|
92
|
+
|
93
|
+
export const VariantRadius = () => {
|
94
|
+
return (
|
95
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(5, auto)"}}>
|
96
|
+
<span className="item-card__title"> Variant \ Radius</span>
|
97
|
+
{radius.slice(1).map(radius => (
|
98
|
+
<span key={radius} className="item-card__title">
|
99
|
+
{capitalizeFirstLetter(radius)} radius
|
100
|
+
</span>
|
101
|
+
))}
|
102
|
+
{variants.map(variant => (
|
103
|
+
<Fragment key={variant}>
|
104
|
+
<span className="item-card__title">{capitalizeFirstLetter(variant)}</span>
|
105
|
+
{radius.slice(1).map(radius => (
|
106
|
+
<div key={`${radius}-${variant}`} className="item-card">
|
107
|
+
<TextAreaComponent
|
108
|
+
variant={variant}
|
109
|
+
radius={radius !== "default" ? radius : undefined}
|
110
|
+
placeholder="Enter value"
|
111
|
+
/>
|
112
|
+
</div>
|
113
|
+
))}
|
114
|
+
</Fragment>
|
115
|
+
))}
|
116
|
+
</div>
|
117
|
+
);
|
118
|
+
};
|
119
|
+
|
120
|
+
export const VariantSize = () => {
|
121
|
+
return (
|
122
|
+
<div className="grid-wrapper" style={{gridTemplateColumns: "repeat(5, auto)"}}>
|
123
|
+
<span className="item-card__title"> Variant \ Size</span>
|
124
|
+
{sizes.map(size => (
|
125
|
+
<span key={size} className="item-card__title">
|
126
|
+
{capitalizeFirstLetter(size)} size
|
127
|
+
</span>
|
128
|
+
))}
|
129
|
+
{variants.map(variant => (
|
130
|
+
<Fragment key={variant}>
|
131
|
+
<span className="item-card__title">{capitalizeFirstLetter(variant)}</span>
|
132
|
+
{sizes.map(size => (
|
133
|
+
<div key={`${size}-${variant}`} className="item-card">
|
134
|
+
<TextAreaComponent
|
135
|
+
variant={variant}
|
136
|
+
size={size !== "default" ? size : undefined}
|
137
|
+
placeholder="Enter value"
|
138
|
+
/>
|
139
|
+
</div>
|
140
|
+
))}
|
141
|
+
</Fragment>
|
142
|
+
))}
|
143
|
+
</div>
|
144
|
+
);
|
145
|
+
};
|
@@ -0,0 +1,143 @@
|
|
1
|
+
import React, {
|
2
|
+
ChangeEventHandler,
|
3
|
+
ComponentProps,
|
4
|
+
forwardRef,
|
5
|
+
memo,
|
6
|
+
useCallback,
|
7
|
+
useEffect,
|
8
|
+
useImperativeHandle,
|
9
|
+
useRef,
|
10
|
+
useState,
|
11
|
+
} from "react";
|
12
|
+
|
13
|
+
import classnames from "classnames";
|
14
|
+
import autosize from "autosize";
|
15
|
+
|
16
|
+
import {useComponentProps} from "../../providers";
|
17
|
+
|
18
|
+
import styles from "./text-area.module.scss";
|
19
|
+
|
20
|
+
export enum TextAreaVariant {
|
21
|
+
Regular = "regular",
|
22
|
+
Outlined = "outlined",
|
23
|
+
Filled = "filled",
|
24
|
+
}
|
25
|
+
|
26
|
+
export enum TextAreaSize {
|
27
|
+
Small = "small",
|
28
|
+
Medium = "medium",
|
29
|
+
Large = "large",
|
30
|
+
}
|
31
|
+
|
32
|
+
export enum TextAreaRadius {
|
33
|
+
None = "none",
|
34
|
+
Small = "small",
|
35
|
+
Medium = "medium",
|
36
|
+
Large = "large",
|
37
|
+
}
|
38
|
+
|
39
|
+
export interface TextAreaActions {
|
40
|
+
select(): void;
|
41
|
+
|
42
|
+
focus(): void;
|
43
|
+
|
44
|
+
setValue(value: string): void;
|
45
|
+
}
|
46
|
+
|
47
|
+
export interface TextAreaProps extends ComponentProps<"textarea"> {
|
48
|
+
variant?: TextAreaVariant;
|
49
|
+
radius?: TextAreaRadius;
|
50
|
+
size?: TextAreaSize;
|
51
|
+
fullWidth?: boolean;
|
52
|
+
label?: string;
|
53
|
+
children?: string | ReadonlyArray<string> | number | undefined;
|
54
|
+
}
|
55
|
+
|
56
|
+
const TextArea = forwardRef<TextAreaActions, TextAreaProps>((props, ref) => {
|
57
|
+
const {
|
58
|
+
variant = TextAreaVariant.Regular,
|
59
|
+
radius,
|
60
|
+
size,
|
61
|
+
fullWidth,
|
62
|
+
label,
|
63
|
+
id,
|
64
|
+
name,
|
65
|
+
rows = 4,
|
66
|
+
value: propValue = "",
|
67
|
+
children,
|
68
|
+
onChange,
|
69
|
+
className,
|
70
|
+
...other
|
71
|
+
} = {...useComponentProps("textArea"), ...props};
|
72
|
+
|
73
|
+
const [value, setValue] = useState(propValue || children);
|
74
|
+
|
75
|
+
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
|
76
|
+
|
77
|
+
const handleChange = useCallback<ChangeEventHandler<HTMLTextAreaElement>>(
|
78
|
+
event => {
|
79
|
+
onChange?.(event);
|
80
|
+
setValue(event.currentTarget.value);
|
81
|
+
},
|
82
|
+
[onChange]
|
83
|
+
);
|
84
|
+
|
85
|
+
useImperativeHandle(
|
86
|
+
ref,
|
87
|
+
() => ({
|
88
|
+
select() {
|
89
|
+
textareaRef.current?.select();
|
90
|
+
},
|
91
|
+
focus() {
|
92
|
+
textareaRef.current?.focus();
|
93
|
+
},
|
94
|
+
setValue(value: string) {
|
95
|
+
setValue(value);
|
96
|
+
},
|
97
|
+
}),
|
98
|
+
[]
|
99
|
+
);
|
100
|
+
|
101
|
+
useEffect(() => {
|
102
|
+
const textarea = textareaRef.current;
|
103
|
+
|
104
|
+
if (textarea) {
|
105
|
+
autosize(textarea);
|
106
|
+
}
|
107
|
+
|
108
|
+
return () => {
|
109
|
+
if (textarea) {
|
110
|
+
autosize.destroy(textarea);
|
111
|
+
}
|
112
|
+
};
|
113
|
+
}, []);
|
114
|
+
|
115
|
+
useEffect(() => {
|
116
|
+
setValue(propValue || children);
|
117
|
+
}, [propValue, children]);
|
118
|
+
|
119
|
+
return (
|
120
|
+
<textarea
|
121
|
+
{...other}
|
122
|
+
ref={textareaRef}
|
123
|
+
id={id}
|
124
|
+
name={name || id}
|
125
|
+
value={value}
|
126
|
+
rows={rows}
|
127
|
+
aria-label={label}
|
128
|
+
onChange={handleChange}
|
129
|
+
className={classnames(
|
130
|
+
styles["text-area"],
|
131
|
+
{
|
132
|
+
[styles[`text-area--${variant}`]]: variant,
|
133
|
+
[styles[`text-area--${size}-size`]]: size,
|
134
|
+
[styles[`text-area--${radius}-radius`]]: radius,
|
135
|
+
[styles["text-area--full-width"]]: fullWidth,
|
136
|
+
},
|
137
|
+
className
|
138
|
+
)}
|
139
|
+
/>
|
140
|
+
);
|
141
|
+
});
|
142
|
+
|
143
|
+
export default memo(TextArea);
|