addon-ui 0.3.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/README.md +1197 -0
- package/package.json +113 -0
- package/src/components/Avatar/Avatar.tsx +56 -0
- package/src/components/Avatar/avatar.module.scss +78 -0
- package/src/components/Avatar/index.ts +2 -0
- package/src/components/Avatar/types.ts +11 -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 +1 -0
- package/src/components/Button/Button.tsx +51 -0
- package/src/components/Button/button.module.scss +140 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/Button/types.ts +24 -0
- package/src/components/Checkbox/Checkbox.tsx +58 -0
- package/src/components/Checkbox/checkbox.module.scss +82 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/Checkbox/types.ts +15 -0
- package/src/components/Dialog/Dialog.tsx +126 -0
- package/src/components/Dialog/dialog.module.scss +55 -0
- package/src/components/Dialog/index.ts +1 -0
- package/src/components/Drawer/Drawer.tsx +53 -0
- package/src/components/Drawer/drawer.module.scss +170 -0
- package/src/components/Drawer/index.ts +2 -0
- package/src/components/Drawer/types.ts +6 -0
- package/src/components/Footer/Footer.tsx +59 -0
- package/src/components/Footer/footer.module.scss +45 -0
- package/src/components/Footer/index.ts +1 -0
- package/src/components/Header/Header.tsx +74 -0
- package/src/components/Header/header.module.scss +56 -0
- package/src/components/Header/index.ts +1 -0
- package/src/components/Highlight/Highlight.tsx +36 -0
- package/src/components/Highlight/highlight.module.scss +48 -0
- package/src/components/Highlight/index.ts +2 -0
- package/src/components/Highlight/types.ts +5 -0
- package/src/components/Icon/Icon.tsx +46 -0
- package/src/components/Icon/icon.module.scss +17 -0
- package/src/components/Icon/index.ts +1 -0
- package/src/components/IconButton/IconButton.tsx +50 -0
- package/src/components/IconButton/icon-button.module.scss +86 -0
- package/src/components/IconButton/index.ts +2 -0
- package/src/components/IconButton/types.ts +17 -0
- package/src/components/Layout/Provider.tsx +60 -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.tsx +24 -0
- package/src/components/List/index.ts +1 -0
- package/src/components/List/list.module.scss +8 -0
- package/src/components/ListItem/ListItem.tsx +75 -0
- package/src/components/ListItem/index.ts +1 -0
- package/src/components/ListItem/list-item.module.scss +37 -0
- package/src/components/Modal/Modal.tsx +90 -0
- package/src/components/Modal/index.ts +2 -0
- package/src/components/Modal/modal.module.scss +97 -0
- package/src/components/Modal/types.ts +6 -0
- package/src/components/Odometer/Odometer.tsx +45 -0
- package/src/components/Odometer/hooks/useOdometer.tsx +24 -0
- package/src/components/Odometer/index.ts +2 -0
- package/src/components/Odometer/odometer.module.scss +81 -0
- package/src/components/Odometer/odometr.d.ts +9 -0
- package/src/components/ScrollArea/ScrollArea.tsx +75 -0
- package/src/components/ScrollArea/index.ts +1 -0
- package/src/components/ScrollArea/scroll-area.module.scss +58 -0
- package/src/components/SvgSprite/SvgSprite.tsx +21 -0
- package/src/components/SvgSprite/index.ts +1 -0
- package/src/components/Switch/Switch.tsx +24 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Switch/switch.module.scss +65 -0
- package/src/components/Tag/Tag.tsx +50 -0
- package/src/components/Tag/index.ts +2 -0
- package/src/components/Tag/tag.module.scss +118 -0
- package/src/components/Tag/types.ts +23 -0
- package/src/components/TextArea/TextArea.tsx +126 -0
- package/src/components/TextArea/index.ts +2 -0
- package/src/components/TextArea/text-area.module.scss +88 -0
- package/src/components/TextArea/types.ts +18 -0
- package/src/components/TextField/TextField.tsx +139 -0
- package/src/components/TextField/index.ts +2 -0
- package/src/components/TextField/text-field.module.scss +129 -0
- package/src/components/TextField/types.ts +24 -0
- package/src/components/Toast/Toast.tsx +124 -0
- package/src/components/Toast/index.ts +2 -0
- package/src/components/Toast/toast.module.scss +267 -0
- package/src/components/Toast/types.ts +20 -0
- package/src/components/Tooltip/Tooltip.tsx +82 -0
- package/src/components/Tooltip/index.ts +1 -0
- package/src/components/Tooltip/tooltip.module.scss +123 -0
- package/src/components/View/View.tsx +68 -0
- package/src/components/View/index.ts +1 -0
- package/src/components/View/view.module.scss +38 -0
- package/src/components/ViewDrawer/ViewDrawer.tsx +24 -0
- package/src/components/ViewDrawer/index.ts +1 -0
- package/src/components/ViewModal/ViewModal.tsx +24 -0
- package/src/components/ViewModal/index.ts +1 -0
- package/src/components/index.ts +27 -0
- package/src/components/types.ts +65 -0
- package/src/config/default.ts +3 -0
- package/src/config/index.ts +8 -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 +35 -0
- package/src/plugin/builder/virtual.config.ts +5 -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 +73 -0
- package/src/plugin/types.ts +8 -0
- package/src/providers/extra/ExtraProvider.tsx +13 -0
- package/src/providers/extra/context.ts +14 -0
- package/src/providers/extra/index.ts +2 -0
- package/src/providers/icons/IconsProvider.tsx +35 -0
- package/src/providers/icons/context.ts +20 -0
- package/src/providers/icons/index.ts +2 -0
- package/src/providers/index.ts +4 -0
- package/src/providers/theme/ThemeProvider.tsx +60 -0
- package/src/providers/theme/ThemeStorage.tsx +36 -0
- package/src/providers/theme/context.ts +30 -0
- package/src/providers/theme/index.ts +3 -0
- package/src/providers/ui/UIProvider.tsx +41 -0
- package/src/providers/ui/index.ts +1 -0
- package/src/providers/ui/styles/default.scss +95 -0
- package/src/providers/ui/styles/reset.scss +127 -0
- package/src/styles/mixins.scss +23 -0
- package/src/types/config.ts +15 -0
- package/src/types/theme.ts +11 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/react.ts +21 -0
- package/src/utils/utils.ts +12 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export enum TagVariant {
|
|
2
|
+
Contained = "contained",
|
|
3
|
+
Outlined = "outlined",
|
|
4
|
+
Soft = "soft",
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum TagColor {
|
|
8
|
+
Primary = "primary",
|
|
9
|
+
Secondary = "secondary",
|
|
10
|
+
Accent = "accent",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum TagSize {
|
|
14
|
+
Small = "small",
|
|
15
|
+
Medium = "medium",
|
|
16
|
+
Large = "large",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export enum TagRadius {
|
|
20
|
+
Small = "small",
|
|
21
|
+
Medium = "medium",
|
|
22
|
+
Large = "large",
|
|
23
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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 {TextAreaVariant, TextAreaSize, TextAreaRadius} from "./types";
|
|
19
|
+
|
|
20
|
+
import styles from "./text-area.module.scss";
|
|
21
|
+
|
|
22
|
+
export interface TextAreaActions {
|
|
23
|
+
select(): void;
|
|
24
|
+
|
|
25
|
+
focus(): void;
|
|
26
|
+
|
|
27
|
+
setValue(value: string): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface TextAreaProps extends ComponentProps<"textarea"> {
|
|
31
|
+
variant?: TextAreaVariant;
|
|
32
|
+
radius?: TextAreaRadius;
|
|
33
|
+
size?: TextAreaSize;
|
|
34
|
+
fullWidth?: boolean;
|
|
35
|
+
label?: string;
|
|
36
|
+
children?: string | ReadonlyArray<string> | number | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const TextArea = forwardRef<TextAreaActions, TextAreaProps>((props, ref) => {
|
|
40
|
+
const {
|
|
41
|
+
variant = TextAreaVariant.Regular,
|
|
42
|
+
radius,
|
|
43
|
+
size,
|
|
44
|
+
fullWidth,
|
|
45
|
+
label,
|
|
46
|
+
id,
|
|
47
|
+
name,
|
|
48
|
+
rows = 4,
|
|
49
|
+
value: propValue = "",
|
|
50
|
+
children,
|
|
51
|
+
onChange,
|
|
52
|
+
className,
|
|
53
|
+
...other
|
|
54
|
+
} = {...useComponentProps("textArea"), ...props};
|
|
55
|
+
|
|
56
|
+
const [value, setValue] = useState(propValue || children);
|
|
57
|
+
|
|
58
|
+
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
|
|
59
|
+
|
|
60
|
+
const handleChange = useCallback<ChangeEventHandler<HTMLTextAreaElement>>(
|
|
61
|
+
event => {
|
|
62
|
+
onChange?.(event);
|
|
63
|
+
setValue(event.currentTarget.value);
|
|
64
|
+
},
|
|
65
|
+
[onChange]
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
useImperativeHandle(
|
|
69
|
+
ref,
|
|
70
|
+
() => ({
|
|
71
|
+
select() {
|
|
72
|
+
textareaRef.current?.select();
|
|
73
|
+
},
|
|
74
|
+
focus() {
|
|
75
|
+
textareaRef.current?.focus();
|
|
76
|
+
},
|
|
77
|
+
setValue(value: string) {
|
|
78
|
+
setValue(value);
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
[]
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const textarea = textareaRef.current;
|
|
86
|
+
|
|
87
|
+
if (textarea) {
|
|
88
|
+
autosize(textarea);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return () => {
|
|
92
|
+
if (textarea) {
|
|
93
|
+
autosize.destroy(textarea);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
setValue(propValue || children);
|
|
100
|
+
}, [propValue, children]);
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<textarea
|
|
104
|
+
{...other}
|
|
105
|
+
ref={textareaRef}
|
|
106
|
+
id={id}
|
|
107
|
+
name={name || id}
|
|
108
|
+
value={value}
|
|
109
|
+
rows={rows}
|
|
110
|
+
aria-label={label}
|
|
111
|
+
onChange={handleChange}
|
|
112
|
+
className={classnames(
|
|
113
|
+
styles["text-area"],
|
|
114
|
+
{
|
|
115
|
+
[styles[`text-area--${variant}`]]: variant,
|
|
116
|
+
[styles[`text-area--${size}-size`]]: size,
|
|
117
|
+
[styles[`text-area--${radius}-radius`]]: radius,
|
|
118
|
+
[styles["text-area--full-width"]]: fullWidth,
|
|
119
|
+
},
|
|
120
|
+
className
|
|
121
|
+
)}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
export default memo(TextArea);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
$root: text-area;
|
|
2
|
+
|
|
3
|
+
.#{$root} {
|
|
4
|
+
outline: none;
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
font-family: var(--text-area-font-family, var(--font-family)), sans-serif;
|
|
7
|
+
font-weight: var(--text-area-font-weight, 400);
|
|
8
|
+
font-size: var(--text-area-font-size, 14px);
|
|
9
|
+
letter-spacing: var(--text-area-letter-spacing, 0.5px);
|
|
10
|
+
line-height: var(--text-area-line-height, var(--line-height, 1 rem));
|
|
11
|
+
padding: var(--text-area-padding, 8px 12px);
|
|
12
|
+
border-radius: var(--text-area-border-radius, 8px);
|
|
13
|
+
min-width: var(--text-area-min-width, 200px);
|
|
14
|
+
transition:
|
|
15
|
+
border-color var(--transition-speed-sm),
|
|
16
|
+
box-shadow var(--transition-speed-sm),
|
|
17
|
+
background var(--transition-speed-sm);
|
|
18
|
+
|
|
19
|
+
&:focus {
|
|
20
|
+
border-color: var(--text-area-focus-border-color, color-mix(in srgb, white 40%, var(--primary-color)));
|
|
21
|
+
box-shadow: var(--text-area-focus-shadow, 0 0 4px var(--primary-color));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&:disabled {
|
|
25
|
+
opacity: var(--text-area-disabled-opacity, 0.7);
|
|
26
|
+
cursor: not-allowed;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&--full-width {
|
|
30
|
+
width: 100% !important;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Variants
|
|
34
|
+
&--regular {
|
|
35
|
+
color: var(--text-area-regular-color, var(--text-area-color, var(--text-primary-color)));
|
|
36
|
+
background: var(--text-area-regular-bg-color, var(--text-area-bg-color, var(--bg-secondary-color)));
|
|
37
|
+
border-style: solid;
|
|
38
|
+
border-width: var(--text-area-regular-border-width, var(--text-area-border-width, 1px));
|
|
39
|
+
border-color: var(--text-area-regular-border-color, var(--border-color));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&--outlined {
|
|
43
|
+
color: var(--text-area-outlined-color, var(--text-area-color, var(--text-primary-color)));
|
|
44
|
+
background: transparent;
|
|
45
|
+
border-style: solid;
|
|
46
|
+
border-width: var(--text-area-outlined-border-width, var(--text-area-border-width, 1px));
|
|
47
|
+
border-color: var(--text-area-outlined-border-color, var(--border-color));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
&--filled {
|
|
51
|
+
color: var(--text-area-filled-color, var(--text-area-color, var(--text-primary-color)));
|
|
52
|
+
background: var(--text-area-filled-bg-color, var(--text-area-bg-color, var(--bg-secondary-color)));
|
|
53
|
+
border: none;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Radius
|
|
57
|
+
&--none-radius {
|
|
58
|
+
border-radius: 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&--small-radius {
|
|
62
|
+
border-radius: var(--text-area-border-radius-sm, 5px);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&--medium-radius {
|
|
66
|
+
border-radius: var(--text-area-border-radius-md, 10px);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&--large-radius {
|
|
70
|
+
border-radius: var(--text-area-border-radius-lg, 15px);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Sizes
|
|
74
|
+
&--small-size {
|
|
75
|
+
padding: var(--text-area-padding-sm, 6px 10px);
|
|
76
|
+
font-size: var(--text-area-font-size-sm, 12px);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&--medium-size {
|
|
80
|
+
padding: var(--text-area-padding-md, 10px 14px);
|
|
81
|
+
font-size: var(--text-area-font-size-sm, 16px);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&--large-size {
|
|
85
|
+
padding: var(--text-area-padding-lg, 12px 16px);
|
|
86
|
+
font-size: var(--text-area-font-size-sm, 18px);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export enum TextAreaVariant {
|
|
2
|
+
Regular = "regular",
|
|
3
|
+
Outlined = "outlined",
|
|
4
|
+
Filled = "filled",
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum TextAreaSize {
|
|
8
|
+
Small = "small",
|
|
9
|
+
Medium = "medium",
|
|
10
|
+
Large = "large",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum TextAreaRadius {
|
|
14
|
+
None = "none",
|
|
15
|
+
Small = "small",
|
|
16
|
+
Medium = "medium",
|
|
17
|
+
Large = "large",
|
|
18
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
ChangeEventHandler,
|
|
3
|
+
ComponentProps,
|
|
4
|
+
forwardRef,
|
|
5
|
+
memo,
|
|
6
|
+
ReactNode,
|
|
7
|
+
useCallback,
|
|
8
|
+
useEffect,
|
|
9
|
+
useImperativeHandle,
|
|
10
|
+
useRef,
|
|
11
|
+
useState,
|
|
12
|
+
} from "react";
|
|
13
|
+
|
|
14
|
+
import classnames from "classnames";
|
|
15
|
+
|
|
16
|
+
import {cloneOrCreateElement} from "../../utils";
|
|
17
|
+
import {useComponentProps} from "../../providers";
|
|
18
|
+
|
|
19
|
+
import {TextFieldVariant, TextFieldSize, TextFieldRadius, TextFieldAccent} from "./types";
|
|
20
|
+
|
|
21
|
+
import styles from "./text-field.module.scss";
|
|
22
|
+
|
|
23
|
+
export interface TextFieldActions {
|
|
24
|
+
select(): void;
|
|
25
|
+
|
|
26
|
+
focus(): void;
|
|
27
|
+
|
|
28
|
+
getValue(): string | undefined;
|
|
29
|
+
|
|
30
|
+
setValue(value: string | number | undefined): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface TextFieldProps extends ComponentProps<"input"> {
|
|
34
|
+
variant?: TextFieldVariant;
|
|
35
|
+
accent?: TextFieldAccent;
|
|
36
|
+
radius?: TextFieldRadius;
|
|
37
|
+
customSize?: TextFieldSize;
|
|
38
|
+
value?: string | number | undefined;
|
|
39
|
+
defaultValue?: string | number | undefined;
|
|
40
|
+
label?: string;
|
|
41
|
+
fullWidth?: boolean;
|
|
42
|
+
before?: ReactNode;
|
|
43
|
+
after?: ReactNode;
|
|
44
|
+
inputClassName?: string;
|
|
45
|
+
afterClassName?: string;
|
|
46
|
+
beforeClassName?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const TextField = forwardRef<TextFieldActions, TextFieldProps>((props, ref) => {
|
|
50
|
+
const {
|
|
51
|
+
variant = TextFieldVariant.Regular,
|
|
52
|
+
accent,
|
|
53
|
+
radius,
|
|
54
|
+
customSize,
|
|
55
|
+
label,
|
|
56
|
+
fullWidth,
|
|
57
|
+
type = "text",
|
|
58
|
+
value: propValue = "",
|
|
59
|
+
defaultValue,
|
|
60
|
+
before,
|
|
61
|
+
after,
|
|
62
|
+
className,
|
|
63
|
+
inputClassName,
|
|
64
|
+
afterClassName,
|
|
65
|
+
beforeClassName,
|
|
66
|
+
onChange,
|
|
67
|
+
...other
|
|
68
|
+
} = {...useComponentProps("textField"), ...props};
|
|
69
|
+
|
|
70
|
+
const [value, setValue] = useState<string | number | undefined>(defaultValue || propValue);
|
|
71
|
+
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
72
|
+
|
|
73
|
+
useImperativeHandle(
|
|
74
|
+
ref,
|
|
75
|
+
() => ({
|
|
76
|
+
select() {
|
|
77
|
+
inputRef.current?.select();
|
|
78
|
+
},
|
|
79
|
+
focus() {
|
|
80
|
+
inputRef.current?.focus();
|
|
81
|
+
},
|
|
82
|
+
getValue(): string | undefined {
|
|
83
|
+
return inputRef.current?.value;
|
|
84
|
+
},
|
|
85
|
+
setValue(value: string | number | undefined) {
|
|
86
|
+
setValue(value);
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
[]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const handleChange = useCallback<ChangeEventHandler<HTMLInputElement>>(
|
|
93
|
+
event => {
|
|
94
|
+
onChange?.(event);
|
|
95
|
+
setValue(event.currentTarget.value);
|
|
96
|
+
},
|
|
97
|
+
[onChange]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
setValue(propValue);
|
|
102
|
+
}, [propValue]);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div
|
|
106
|
+
aria-label={label}
|
|
107
|
+
className={classnames(
|
|
108
|
+
styles["text-field"],
|
|
109
|
+
{
|
|
110
|
+
[styles[`text-field--${variant}`]]: variant,
|
|
111
|
+
[styles[`text-field--${accent}`]]: accent,
|
|
112
|
+
[styles[`text-field--${radius}-radius`]]: radius,
|
|
113
|
+
[styles[`text-field--${customSize}-size`]]: customSize,
|
|
114
|
+
[styles["text-field--full-width"]]: fullWidth,
|
|
115
|
+
},
|
|
116
|
+
className
|
|
117
|
+
)}
|
|
118
|
+
>
|
|
119
|
+
{cloneOrCreateElement(
|
|
120
|
+
before,
|
|
121
|
+
{className: classnames(styles["text-field__before"], beforeClassName)},
|
|
122
|
+
"span"
|
|
123
|
+
)}
|
|
124
|
+
<input
|
|
125
|
+
{...other}
|
|
126
|
+
ref={inputRef}
|
|
127
|
+
type={type}
|
|
128
|
+
value={value}
|
|
129
|
+
defaultValue={defaultValue}
|
|
130
|
+
aria-label={label}
|
|
131
|
+
className={classnames(styles["text-field__input"], inputClassName)}
|
|
132
|
+
onChange={handleChange}
|
|
133
|
+
/>
|
|
134
|
+
{cloneOrCreateElement(after, {className: classnames(styles["text-field__after"], afterClassName)}, "span")}
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export default memo(TextField);
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
$root: text-field;
|
|
2
|
+
|
|
3
|
+
.#{$root} {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: var(--text-field-gap, 0.3em);
|
|
7
|
+
font-family: var(--text-field-font-family, var(--font-family)), sans-serif;
|
|
8
|
+
font-weight: var(--text-field-font-weight, 400);
|
|
9
|
+
font-size: var(--text-field-font-size, 14px);
|
|
10
|
+
letter-spacing: var(--text-field-letter-spacing, 0.5px);
|
|
11
|
+
line-height: var(--text-field-line-height, var(--line-height, 1 rem));
|
|
12
|
+
padding: var(--text-field-padding, 8px 12px);
|
|
13
|
+
border-radius: var(--text-field-border-radius, 8px);
|
|
14
|
+
transition:
|
|
15
|
+
border-color var(--transition-speed-sm),
|
|
16
|
+
box-shadow var(--transition-speed-sm),
|
|
17
|
+
background var(--transition-speed-sm);
|
|
18
|
+
|
|
19
|
+
&:has(&__input:focus) {
|
|
20
|
+
border-color: var(--text-field-focus-border-color, color-mix(in srgb, white 40%, var(--primary-color)));
|
|
21
|
+
box-shadow: var(--text-field-focus-shadow, 0 0 4px var(--primary-color));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&:has(&__input:disabled) {
|
|
25
|
+
opacity: var(--text-field-disabled-opacity, 0.7);
|
|
26
|
+
cursor: not-allowed;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&__input {
|
|
30
|
+
width: 100%;
|
|
31
|
+
color: inherit;
|
|
32
|
+
font-size: inherit;
|
|
33
|
+
font-family: inherit;
|
|
34
|
+
padding: 0;
|
|
35
|
+
border: none;
|
|
36
|
+
outline: none;
|
|
37
|
+
background: transparent;
|
|
38
|
+
|
|
39
|
+
&:focus {
|
|
40
|
+
outline: none;
|
|
41
|
+
}
|
|
42
|
+
&:disabled {
|
|
43
|
+
cursor: not-allowed;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&__before,
|
|
48
|
+
&__after {
|
|
49
|
+
display: inline;
|
|
50
|
+
cursor: default;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
&--full-width {
|
|
54
|
+
width: 100%;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Variants
|
|
58
|
+
&--regular {
|
|
59
|
+
color: var(--text-field-regular-color, var(--text-field-color, var(--text-primary-color)));
|
|
60
|
+
background: var(--text-field-regular-bg-color, var(--text-field-bg-color, var(--bg-secondary-color)));
|
|
61
|
+
border-style: solid;
|
|
62
|
+
border-width: var(--text-field-regular-border-width, var(--text-field-border-width, 1px));
|
|
63
|
+
border-color: var(--text-field-regular-border-color, var(--border-color));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&--outlined {
|
|
67
|
+
color: var(--text-field-outlined-color, var(--text-field-color, var(--text-primary-color)));
|
|
68
|
+
background: transparent;
|
|
69
|
+
border-style: solid;
|
|
70
|
+
border-width: var(--text-field-outlined-border-width, var(--text-field-border-width, 1px));
|
|
71
|
+
border-color: var(--text-field-outlined-border-color, var(--border-color));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&--filled {
|
|
75
|
+
color: var(--text-field-filled-color, var(--text-field-color, var(--text-primary-color)));
|
|
76
|
+
background: var(--text-field-filled-bg-color, var(--text-field-bg-color, var(--bg-secondary-color)));
|
|
77
|
+
border: none;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Radius
|
|
81
|
+
&--none-radius {
|
|
82
|
+
border-radius: 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&--small-radius {
|
|
86
|
+
border-radius: var(--text-field-border-radius-sm, 5px);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&--medium-radius {
|
|
90
|
+
border-radius: var(--text-field-border-radius-md, 10px);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
&--large-radius {
|
|
94
|
+
border-radius: var(--text-field-border-radius-lg, 15px);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&--full-radius {
|
|
98
|
+
border-radius: var(--text-field-border-radius-full, 999px);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Sizes
|
|
102
|
+
&--small-size {
|
|
103
|
+
padding: var(--text-field-padding-sm, 6px 10px);
|
|
104
|
+
font-size: var(--text-field-font-size-sm, 12px);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
&--medium-size {
|
|
108
|
+
padding: var(--text-field-padding-md, 10px 14px);
|
|
109
|
+
font-size: var(--text-field-font-size-sm, 16px);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
&--large-size {
|
|
113
|
+
padding: var(--text-field-padding-lg, 12px 16px);
|
|
114
|
+
font-size: var(--text-field-font-size-sm, 18px);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Accents
|
|
118
|
+
&--success {
|
|
119
|
+
border-color: var(--text-field-success-color, var(--success-color)) !important;
|
|
120
|
+
border-width: var(--text-field-accent-border-width, 2px) !important;
|
|
121
|
+
box-shadow: var(--text-field-success-color, 0 0 4px var(--success-color)) !important;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
&--error {
|
|
125
|
+
border-color: var(--text-field-error-color, var(--error-color)) !important;
|
|
126
|
+
border-width: var(--text-field-accent-border-width, 2px) !important;
|
|
127
|
+
box-shadow: var(--text-field-error-color, 0 0 4px var(--error-color)) !important;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export enum TextFieldVariant {
|
|
2
|
+
Regular = "regular",
|
|
3
|
+
Outlined = "outlined",
|
|
4
|
+
Filled = "filled",
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum TextFieldSize {
|
|
8
|
+
Small = "small",
|
|
9
|
+
Medium = "medium",
|
|
10
|
+
Large = "large",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum TextFieldRadius {
|
|
14
|
+
None = "none",
|
|
15
|
+
Small = "small",
|
|
16
|
+
Medium = "medium",
|
|
17
|
+
Large = "large",
|
|
18
|
+
Full = "full",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export enum TextFieldAccent {
|
|
22
|
+
Success = "success",
|
|
23
|
+
Error = "error",
|
|
24
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React, {memo, ReactElement, ReactNode, forwardRef, ForwardRefRenderFunction} from "react";
|
|
2
|
+
import classnames from "classnames";
|
|
3
|
+
import {
|
|
4
|
+
Description,
|
|
5
|
+
Provider,
|
|
6
|
+
Root,
|
|
7
|
+
Title,
|
|
8
|
+
ToastProps as ToastRootProps,
|
|
9
|
+
ToastProviderProps,
|
|
10
|
+
Viewport,
|
|
11
|
+
} from "@radix-ui/react-toast";
|
|
12
|
+
|
|
13
|
+
import {IconButton, IconButtonProps} from "../IconButton";
|
|
14
|
+
import {cloneOrCreateElement} from "../../utils";
|
|
15
|
+
import {useComponentProps} from "../../providers";
|
|
16
|
+
|
|
17
|
+
import {ToastSide, ToastRadius, ToastColor} from "./types";
|
|
18
|
+
|
|
19
|
+
import styles from "./toast.module.scss";
|
|
20
|
+
|
|
21
|
+
const toastSideBySwipeDirectionMap = {
|
|
22
|
+
[ToastSide.TopLeft]: "left",
|
|
23
|
+
[ToastSide.TopCenter]: "up",
|
|
24
|
+
[ToastSide.TopRight]: "right",
|
|
25
|
+
[ToastSide.BottomRight]: "right",
|
|
26
|
+
[ToastSide.BottomCenter]: "down",
|
|
27
|
+
[ToastSide.BottomLeft]: "left",
|
|
28
|
+
} as Record<ToastSide, ToastProviderProps["swipeDirection"]>;
|
|
29
|
+
|
|
30
|
+
export interface ToastProps extends Omit<ToastRootProps, "title">, Omit<ToastProviderProps, "children"> {
|
|
31
|
+
side?: ToastSide;
|
|
32
|
+
color?: ToastColor;
|
|
33
|
+
radius?: ToastRadius;
|
|
34
|
+
title?: ReactNode;
|
|
35
|
+
action?: ReactNode;
|
|
36
|
+
description?: ReactNode;
|
|
37
|
+
closeIcon?: ReactElement;
|
|
38
|
+
closeProps?: IconButtonProps;
|
|
39
|
+
titleClassName?: string;
|
|
40
|
+
actionClassName?: string;
|
|
41
|
+
viewportClassName?: string;
|
|
42
|
+
descriptionClassName?: string;
|
|
43
|
+
onClose?: () => void;
|
|
44
|
+
fullWidth?: boolean;
|
|
45
|
+
sticky?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const Toast: ForwardRefRenderFunction<HTMLLIElement, ToastProps> = (props, ref) => {
|
|
49
|
+
const defaultProps = useComponentProps("toast");
|
|
50
|
+
const mergedProps = {...defaultProps, ...props};
|
|
51
|
+
const {
|
|
52
|
+
side = ToastSide.BottomRight,
|
|
53
|
+
color,
|
|
54
|
+
radius,
|
|
55
|
+
title,
|
|
56
|
+
action,
|
|
57
|
+
description,
|
|
58
|
+
fullWidth,
|
|
59
|
+
sticky,
|
|
60
|
+
closeIcon = "✖",
|
|
61
|
+
closeProps,
|
|
62
|
+
|
|
63
|
+
label,
|
|
64
|
+
duration,
|
|
65
|
+
swipeDirection = toastSideBySwipeDirectionMap[side],
|
|
66
|
+
swipeThreshold = ["up", "down"].includes(swipeDirection || "") ? 15 : 50,
|
|
67
|
+
|
|
68
|
+
className,
|
|
69
|
+
titleClassName,
|
|
70
|
+
actionClassName,
|
|
71
|
+
viewportClassName,
|
|
72
|
+
descriptionClassName,
|
|
73
|
+
children,
|
|
74
|
+
onClose,
|
|
75
|
+
...other
|
|
76
|
+
} = mergedProps;
|
|
77
|
+
|
|
78
|
+
const {className: closeClassName, ...otherCloseProps} = closeProps || {};
|
|
79
|
+
return (
|
|
80
|
+
<Provider label={label} duration={duration} swipeDirection={swipeDirection} swipeThreshold={swipeThreshold}>
|
|
81
|
+
{children}
|
|
82
|
+
<Root
|
|
83
|
+
ref={ref}
|
|
84
|
+
className={classnames(
|
|
85
|
+
styles["toast"],
|
|
86
|
+
{
|
|
87
|
+
[styles[`toast--${side}`]]: side,
|
|
88
|
+
[styles[`toast--${color}-color`]]: color,
|
|
89
|
+
[styles[`toast--${radius}-radius`]]: radius,
|
|
90
|
+
[styles["toast--sticky"]]: sticky,
|
|
91
|
+
[styles["toast--full-width"]]: fullWidth,
|
|
92
|
+
},
|
|
93
|
+
className
|
|
94
|
+
)}
|
|
95
|
+
{...other}
|
|
96
|
+
>
|
|
97
|
+
{title && <Title className={classnames(styles["toast__title"], titleClassName)}>{title}</Title>}
|
|
98
|
+
|
|
99
|
+
{description && (
|
|
100
|
+
<Description className={classnames(styles["toast__description"], descriptionClassName)}>
|
|
101
|
+
{description}
|
|
102
|
+
</Description>
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
{cloneOrCreateElement(action, {className: classnames(styles["toast__action"], actionClassName)})}
|
|
106
|
+
|
|
107
|
+
{onClose && (
|
|
108
|
+
<IconButton
|
|
109
|
+
aria-label="Close"
|
|
110
|
+
onClick={onClose}
|
|
111
|
+
className={classnames(styles["toast__close"], closeClassName)}
|
|
112
|
+
{...otherCloseProps}
|
|
113
|
+
>
|
|
114
|
+
{closeIcon}
|
|
115
|
+
</IconButton>
|
|
116
|
+
)}
|
|
117
|
+
</Root>
|
|
118
|
+
|
|
119
|
+
<Viewport className={classnames(styles["toast__viewport"], viewportClassName)} />
|
|
120
|
+
</Provider>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export default memo(forwardRef(Toast));
|