x-ui-design 1.0.31-gamma.1 → 1.0.33
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/.github/workflows/x-ui-design.yml +14 -0
- package/README.md +22 -1
- package/compile.sh +15 -0
- package/dist/{components → esm/types/components}/DatePicker/DatePicker.d.ts +2 -1
- package/dist/{components → esm/types/components}/DatePicker/RangePicker/RangePicker.d.ts +2 -1
- package/dist/{components → esm/types/components}/Dropdown/Dropdown.d.ts +2 -1
- package/dist/{components → esm/types/components}/Empty/Empty.d.ts +2 -1
- package/dist/{components → esm/types/components}/Form/Item/Item.d.ts +2 -1
- package/dist/esm/types/components/Icons/Icons.d.ts +19 -0
- package/dist/{components → esm/types/components}/Input/Input.d.ts +2 -1
- package/dist/{components → esm/types/components}/Input/Textarea/Textarea.d.ts +2 -1
- package/dist/{components → esm/types/components}/Popover/Popover.d.ts +2 -1
- package/dist/{components → esm/types/components}/Radio/Button/Button.d.ts +2 -1
- package/dist/{components → esm/types/components}/Radio/Group/Group.d.ts +2 -1
- package/dist/{components → esm/types/components}/Radio/Radio.d.ts +2 -1
- package/dist/{components → esm/types/components}/Result/Result.d.ts +2 -1
- package/dist/{components → esm/types/components}/Switch/Switch.d.ts +2 -1
- package/dist/{components → esm/types/components}/Upload/Upload.d.ts +2 -1
- package/dist/esm/types/index.d.ts +50 -0
- package/dist/{types → esm/types/types}/input.d.ts +2 -2
- package/dist/index.d.ts +144 -1
- package/dist/index.esm.js +4233 -3792
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +4338 -3897
- package/dist/index.js.map +1 -1
- package/eslint.config.mjs +16 -0
- package/lib/components/Button/Button.tsx +136 -0
- package/lib/components/Button/index.ts +1 -0
- package/lib/components/Button/style.css +197 -0
- package/lib/components/Checkbox/Checkbox.tsx +131 -0
- package/lib/components/Checkbox/index.ts +1 -0
- package/lib/components/Checkbox/style.css +95 -0
- package/lib/components/ConditionalWrapper/index.tsx +12 -0
- package/lib/components/DatePicker/DatePicker.tsx +526 -0
- package/lib/components/DatePicker/RangePicker/RangePicker.tsx +500 -0
- package/lib/components/DatePicker/RangePicker/index.ts +1 -0
- package/lib/components/DatePicker/RangePicker/style.css +434 -0
- package/lib/components/DatePicker/TimePicker/TimePicker.tsx +497 -0
- package/lib/components/DatePicker/TimePicker/index.ts +1 -0
- package/lib/components/DatePicker/TimePicker/style.css +197 -0
- package/lib/components/DatePicker/index.ts +1 -0
- package/lib/components/DatePicker/style.css +318 -0
- package/lib/components/Dropdown/Dropdown.tsx +234 -0
- package/lib/components/Dropdown/index.ts +1 -0
- package/lib/components/Dropdown/style.css +124 -0
- package/lib/components/Empty/Empty.tsx +45 -0
- package/lib/components/Empty/index.ts +1 -0
- package/lib/components/Empty/style.css +13 -0
- package/lib/components/Form/Form.tsx +130 -0
- package/lib/components/Form/Item/Item.tsx +294 -0
- package/lib/components/Form/Item/index.ts +1 -0
- package/lib/components/Form/Item/style.css +61 -0
- package/lib/components/Form/index.ts +1 -0
- package/lib/components/Icons/Icons.tsx +433 -0
- package/lib/components/Icons/index.ts +15 -0
- package/lib/components/Input/Input.tsx +218 -0
- package/lib/components/Input/Textarea/Textarea.tsx +110 -0
- package/lib/components/Input/Textarea/index.ts +1 -0
- package/lib/components/Input/Textarea/style.css +104 -0
- package/lib/components/Input/index.ts +1 -0
- package/lib/components/Input/style.css +137 -0
- package/lib/components/Menu/Item/Item.tsx +65 -0
- package/lib/components/Menu/Menu.tsx +261 -0
- package/lib/components/Menu/SubMenu/SubMenu.tsx +68 -0
- package/lib/components/Menu/index.css +145 -0
- package/lib/components/Menu/index.ts +1 -0
- package/lib/components/Popover/Popover.tsx +135 -0
- package/lib/components/Popover/index.ts +1 -0
- package/lib/components/Popover/style.css +82 -0
- package/lib/components/Radio/Button/Button.tsx +42 -0
- package/lib/components/Radio/Button/index.ts +1 -0
- package/lib/components/Radio/Button/style.css +43 -0
- package/lib/components/Radio/Group/Group.tsx +105 -0
- package/lib/components/Radio/Group/index.ts +1 -0
- package/lib/components/Radio/Group/style.css +53 -0
- package/lib/components/Radio/Radio.tsx +83 -0
- package/lib/components/Radio/index.ts +1 -0
- package/lib/components/Radio/style.css +73 -0
- package/lib/components/Result/Result.tsx +39 -0
- package/lib/components/Result/index.ts +1 -0
- package/lib/components/Result/style.css +173 -0
- package/lib/components/Select/Option/Option.tsx +49 -0
- package/lib/components/Select/Option/index.ts +1 -0
- package/lib/components/Select/Option/style.css +50 -0
- package/lib/components/Select/Select.tsx +935 -0
- package/lib/components/Select/Tag/Tag.tsx +43 -0
- package/lib/components/Select/Tag/index.ts +1 -0
- package/lib/components/Select/Tag/style.css +87 -0
- package/lib/components/Select/index.ts +1 -0
- package/lib/components/Select/style.css +186 -0
- package/lib/components/Skeleton/Avatar/Avatar.tsx +61 -0
- package/lib/components/Skeleton/Avatar/index.ts +1 -0
- package/lib/components/Skeleton/Avatar/style.css +27 -0
- package/lib/components/Skeleton/Button/Button.tsx +44 -0
- package/lib/components/Skeleton/Button/index.ts +1 -0
- package/lib/components/Skeleton/Button/style.css +50 -0
- package/lib/components/Skeleton/Image/Image.tsx +45 -0
- package/lib/components/Skeleton/Image/index.ts +1 -0
- package/lib/components/Skeleton/Image/style.css +23 -0
- package/lib/components/Skeleton/Input/Input.tsx +42 -0
- package/lib/components/Skeleton/Input/index.ts +1 -0
- package/lib/components/Skeleton/Input/style.css +56 -0
- package/lib/components/Skeleton/Skeleton.tsx +97 -0
- package/lib/components/Skeleton/index.ts +1 -0
- package/lib/components/Skeleton/style.css +84 -0
- package/lib/components/Switch/Switch.tsx +68 -0
- package/lib/components/Switch/index.css +50 -0
- package/lib/components/Switch/index.ts +1 -0
- package/lib/components/Upload/Upload.tsx +291 -0
- package/lib/components/Upload/index.ts +1 -0
- package/lib/components/Upload/style.css +151 -0
- package/lib/global.d.ts +1 -0
- package/lib/helpers/flatten.ts +26 -0
- package/lib/helpers/index.ts +52 -0
- package/lib/helpers/mask.ts +52 -0
- package/lib/hooks/useForm.ts +548 -0
- package/lib/hooks/usePosition.ts +206 -0
- package/lib/hooks/useWatch.ts +41 -0
- package/lib/hooks/useWatchError.ts +20 -0
- package/lib/index.ts +184 -0
- package/lib/styles/global.css +57 -0
- package/lib/types/button.ts +83 -0
- package/lib/types/checkbox.ts +32 -0
- package/lib/types/datepicker.ts +165 -0
- package/lib/types/dropdown.ts +41 -0
- package/lib/types/empty.ts +8 -0
- package/lib/types/form.ts +179 -0
- package/lib/types/index.ts +38 -0
- package/lib/types/input.ts +72 -0
- package/lib/types/menu.ts +55 -0
- package/lib/types/popover.ts +16 -0
- package/lib/types/radio.ts +69 -0
- package/lib/types/result.ts +22 -0
- package/lib/types/select.ts +126 -0
- package/lib/types/skeleton.ts +62 -0
- package/lib/types/switch.ts +22 -0
- package/lib/types/upload.ts +67 -0
- package/lib/utils/index.ts +37 -0
- package/lib/utils/lazy.ts +17 -0
- package/next.config.ts +7 -0
- package/package.json +18 -20
- package/rollup.config.js +71 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +48 -0
- package/src/app/layout.d.ts +5 -0
- package/src/app/layout.tsx +16 -0
- package/src/app/page.d.ts +1 -0
- package/src/app/page.tsx +22 -0
- package/tsconfig.json +46 -0
- package/dist/components/Icons/Icons.d.ts +0 -18
- /package/dist/{components → esm/types/components}/Button/Button.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Button/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Checkbox/Checkbox.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Checkbox/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/ConditionalWrapper/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/DatePicker/RangePicker/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/DatePicker/TimePicker/TimePicker.d.ts +0 -0
- /package/dist/{components → esm/types/components}/DatePicker/TimePicker/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/DatePicker/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Dropdown/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Empty/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Form/Form.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Form/Item/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Form/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Icons/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Input/Textarea/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Input/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Menu/Item/Item.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Menu/Menu.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Menu/SubMenu/SubMenu.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Menu/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Popover/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Radio/Button/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Radio/Group/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Radio/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Result/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Select/Option/Option.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Select/Option/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Select/Select.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Select/Tag/Tag.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Select/Tag/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Select/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/Avatar/Avatar.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/Avatar/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/Button/Button.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/Button/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/Image/Image.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/Image/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/Input/Input.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/Input/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/Skeleton.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Skeleton/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Switch/index.d.ts +0 -0
- /package/dist/{components → esm/types/components}/Upload/index.d.ts +0 -0
- /package/dist/{helpers → esm/types/helpers}/flatten.d.ts +0 -0
- /package/dist/{helpers → esm/types/helpers}/index.d.ts +0 -0
- /package/dist/{helpers → esm/types/helpers}/mask.d.ts +0 -0
- /package/dist/{hooks → esm/types/hooks}/useForm.d.ts +0 -0
- /package/dist/{hooks → esm/types/hooks}/usePosition.d.ts +0 -0
- /package/dist/{hooks → esm/types/hooks}/useWatch.d.ts +0 -0
- /package/dist/{hooks → esm/types/hooks}/useWatchError.d.ts +0 -0
- /package/dist/{types → esm/types/types}/button.d.ts +0 -0
- /package/dist/{types → esm/types/types}/checkbox.d.ts +0 -0
- /package/dist/{types → esm/types/types}/datepicker.d.ts +0 -0
- /package/dist/{types → esm/types/types}/dropdown.d.ts +0 -0
- /package/dist/{types → esm/types/types}/empty.d.ts +0 -0
- /package/dist/{types → esm/types/types}/form.d.ts +0 -0
- /package/dist/{types → esm/types/types}/index.d.ts +0 -0
- /package/dist/{types → esm/types/types}/menu.d.ts +0 -0
- /package/dist/{types → esm/types/types}/popover.d.ts +0 -0
- /package/dist/{types → esm/types/types}/radio.d.ts +0 -0
- /package/dist/{types → esm/types/types}/result.d.ts +0 -0
- /package/dist/{types → esm/types/types}/select.d.ts +0 -0
- /package/dist/{types → esm/types/types}/skeleton.d.ts +0 -0
- /package/dist/{types → esm/types/types}/switch.d.ts +0 -0
- /package/dist/{types → esm/types/types}/upload.d.ts +0 -0
- /package/dist/{utils → esm/types/utils}/index.d.ts +0 -0
- /package/dist/{utils → esm/types/utils}/lazy.d.ts +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, {
|
|
4
|
+
KeyboardEvent,
|
|
5
|
+
MouseEvent,
|
|
6
|
+
useEffect,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
useRef,
|
|
9
|
+
useState
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { clsx } from '../../helpers';
|
|
12
|
+
import { RuleType, SyntheticBaseEvent, TargetProps } from '../../types';
|
|
13
|
+
import { InputProps } from '../../types/input';
|
|
14
|
+
import { prefixClsInput, prefixClsInputV3 } from '../../utils';
|
|
15
|
+
import Textarea from './Textarea/Textarea';
|
|
16
|
+
import { ErrorIcon } from '../Icons/Icons';
|
|
17
|
+
import { applyMask, MASK_CHAR, MASK_REGEX, stripMask } from '../../helpers/mask';
|
|
18
|
+
import './style.css';
|
|
19
|
+
|
|
20
|
+
const InputComponent = ({
|
|
21
|
+
size = 'large',
|
|
22
|
+
error,
|
|
23
|
+
suffix,
|
|
24
|
+
prefix,
|
|
25
|
+
addonAfter,
|
|
26
|
+
addonBefore,
|
|
27
|
+
onPressEnter,
|
|
28
|
+
disabled = false,
|
|
29
|
+
allowClear = false,
|
|
30
|
+
prefixCls = prefixClsInput,
|
|
31
|
+
prefixClsV3 = prefixClsInputV3,
|
|
32
|
+
className = '',
|
|
33
|
+
value = undefined,
|
|
34
|
+
iconRender,
|
|
35
|
+
noStyle,
|
|
36
|
+
feedbackIcons,
|
|
37
|
+
mask,
|
|
38
|
+
maskChar = MASK_CHAR,
|
|
39
|
+
maskRegex = MASK_REGEX,
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
|
+
__injected,
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
|
+
defaultValue,
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
47
|
+
child,
|
|
48
|
+
ref,
|
|
49
|
+
...props
|
|
50
|
+
}: InputProps) => {
|
|
51
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
52
|
+
const lastKeyPressed = useRef<string | null>(null);
|
|
53
|
+
const internalValue = mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : value ?? '';
|
|
54
|
+
const [maskValue, setMaskValue] = useState(internalValue)
|
|
55
|
+
const [iconRenderVisible, setIconRenderVisible] = useState(false);
|
|
56
|
+
const animationRef = useRef<number | null>(null);
|
|
57
|
+
|
|
58
|
+
useImperativeHandle(ref, () => ({
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
focus: inputRef.current?.focus,
|
|
62
|
+
input: inputRef.current,
|
|
63
|
+
blur: (inputRef.current as HTMLInputElement).blur,
|
|
64
|
+
nativeElement: inputRef.current,
|
|
65
|
+
setSelectionRange: (start: number, end: number) => {
|
|
66
|
+
if (inputRef.current) {
|
|
67
|
+
inputRef.current.setSelectionRange(start, end);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
setMaskValue(mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : (value ?? ''));
|
|
74
|
+
}, [value, mask, maskChar]);
|
|
75
|
+
|
|
76
|
+
const handleChange = (e: SyntheticBaseEvent) => {
|
|
77
|
+
if (!inputRef.current) return;
|
|
78
|
+
|
|
79
|
+
let rawInput = e.target.value as string;
|
|
80
|
+
const raw = mask ? rawInput.replace(maskRegex, '') : rawInput;
|
|
81
|
+
|
|
82
|
+
if (mask) {
|
|
83
|
+
if (!inputRef.current) return;
|
|
84
|
+
|
|
85
|
+
if (animationRef.current) {
|
|
86
|
+
cancelAnimationFrame(animationRef.current);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const { masked, rawIndex } = applyMask(raw, mask, maskChar);
|
|
90
|
+
rawInput = masked;
|
|
91
|
+
|
|
92
|
+
animationRef.current = requestAnimationFrame(() => {
|
|
93
|
+
const isRemove = lastKeyPressed.current === 'Delete' || lastKeyPressed.current === 'Backspace';
|
|
94
|
+
|
|
95
|
+
let nextCaret = !isRemove ? rawIndex : inputRef.current?.selectionStart ?? 0;
|
|
96
|
+
|
|
97
|
+
while (isRemove ? mask.includes(rawInput[nextCaret - 1]) : maskChar !== rawInput[nextCaret]) {
|
|
98
|
+
if (!isRemove && !rawInput[nextCaret]) {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (isRemove) {
|
|
103
|
+
nextCaret--;
|
|
104
|
+
} else {
|
|
105
|
+
nextCaret++;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
inputRef.current?.setSelectionRange(nextCaret, nextCaret);
|
|
110
|
+
})
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
setMaskValue(rawInput);
|
|
114
|
+
|
|
115
|
+
const eventWithMaskedValue = {
|
|
116
|
+
...e,
|
|
117
|
+
target: {
|
|
118
|
+
...e.target,
|
|
119
|
+
value: rawInput
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
props.onChange?.(eventWithMaskedValue as RuleType);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const handleClear = (e: MouseEvent<HTMLSpanElement> & TargetProps) => {
|
|
127
|
+
if (mask) {
|
|
128
|
+
setMaskValue('')
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
e.target.value = '';
|
|
132
|
+
props.onChange?.(e);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const handleOnKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
136
|
+
lastKeyPressed.current = e.key;
|
|
137
|
+
|
|
138
|
+
if (e.key === 'Enter' && onPressEnter) {
|
|
139
|
+
onPressEnter(e);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<div
|
|
145
|
+
className={clsx([
|
|
146
|
+
`${prefixCls}-container ${prefixClsV3}-container`,
|
|
147
|
+
{
|
|
148
|
+
[`${prefixCls}-error ${prefixClsV3}-error`]: error,
|
|
149
|
+
[`${prefixCls}-disabled ${prefixClsV3}-disabled`]: disabled,
|
|
150
|
+
[`${prefixCls}-${size} ${prefixClsV3}-${size}`]: size,
|
|
151
|
+
noStyle: noStyle
|
|
152
|
+
},
|
|
153
|
+
className
|
|
154
|
+
])}
|
|
155
|
+
style={props.style}
|
|
156
|
+
>
|
|
157
|
+
{addonBefore && (
|
|
158
|
+
<span className={`${prefixCls}-addon ${prefixCls}-before ${prefixClsV3}-addon ${prefixClsV3}-before`}>
|
|
159
|
+
{addonBefore}
|
|
160
|
+
</span>
|
|
161
|
+
)}
|
|
162
|
+
|
|
163
|
+
<div className={`${prefixCls}-wrapper ${prefixClsV3}-wrapper`}>
|
|
164
|
+
{prefix && <span className={`${prefixCls}-prefix ${prefixClsV3}-prefix`}>{prefix}</span>}
|
|
165
|
+
|
|
166
|
+
<input
|
|
167
|
+
{...props}
|
|
168
|
+
ref={inputRef}
|
|
169
|
+
suppressHydrationWarning
|
|
170
|
+
{...(props.type === 'password' && iconRender
|
|
171
|
+
? { type: iconRenderVisible ? 'text' : 'password' }
|
|
172
|
+
: {})}
|
|
173
|
+
disabled={disabled}
|
|
174
|
+
value={maskValue}
|
|
175
|
+
onChange={handleChange}
|
|
176
|
+
onKeyDown={handleOnKeyDown}
|
|
177
|
+
className={clsx([prefixCls, prefixClsV3, className])}
|
|
178
|
+
/>
|
|
179
|
+
|
|
180
|
+
{allowClear && internalValue ?
|
|
181
|
+
<span className={`${prefixCls}-clear ${prefixClsV3}-clear`} onClick={handleClear}>
|
|
182
|
+
<ErrorIcon />
|
|
183
|
+
</span> : null
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
{(suffix || iconRender) && (
|
|
187
|
+
<span
|
|
188
|
+
className={`${prefixCls}-suffix ${prefixClsV3}-suffix`}
|
|
189
|
+
{...(iconRender !== undefined
|
|
190
|
+
? {
|
|
191
|
+
onClick: () => setIconRenderVisible(icon => !icon)
|
|
192
|
+
}
|
|
193
|
+
: {})}
|
|
194
|
+
>
|
|
195
|
+
{suffix || iconRender?.(iconRenderVisible)}
|
|
196
|
+
{error && feedbackIcons ? <ErrorIcon /> : null}
|
|
197
|
+
</span>
|
|
198
|
+
)}
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
{addonAfter ? (
|
|
202
|
+
<span className={`${prefixCls}-addon ${prefixCls}-after ${prefixClsV3}-addon ${prefixClsV3}-after`}>
|
|
203
|
+
{addonAfter}
|
|
204
|
+
</span>
|
|
205
|
+
) : null}
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
InputComponent.displayName = 'Input';
|
|
211
|
+
|
|
212
|
+
const Input = InputComponent as typeof InputComponent & {
|
|
213
|
+
TextArea: typeof Textarea;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
Input.TextArea = Textarea;
|
|
217
|
+
|
|
218
|
+
export default Input;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, {
|
|
4
|
+
ChangeEvent,
|
|
5
|
+
KeyboardEvent,
|
|
6
|
+
RefObject,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { clsx } from '../../../helpers';
|
|
12
|
+
import { TextareaProps } from '../../../types/input';
|
|
13
|
+
import { prefixClsTextArea } from '../../../utils';
|
|
14
|
+
import './style.css';
|
|
15
|
+
|
|
16
|
+
const Textarea = ({
|
|
17
|
+
prefixCls = prefixClsTextArea,
|
|
18
|
+
prefixClsV3 = prefixClsTextArea,
|
|
19
|
+
value,
|
|
20
|
+
className = '',
|
|
21
|
+
style,
|
|
22
|
+
autoSize,
|
|
23
|
+
onPressEnter,
|
|
24
|
+
onResize,
|
|
25
|
+
styles,
|
|
26
|
+
bordered = true,
|
|
27
|
+
size = 'large',
|
|
28
|
+
status,
|
|
29
|
+
rootClassName,
|
|
30
|
+
variant = 'outlined',
|
|
31
|
+
error,
|
|
32
|
+
allowClear = false,
|
|
33
|
+
ref,
|
|
34
|
+
...props
|
|
35
|
+
}: TextareaProps) => {
|
|
36
|
+
const [inputValue, setInputValue] = useState(value?.toString() || '');
|
|
37
|
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const textarea =
|
|
41
|
+
(ref as RefObject<HTMLTextAreaElement>)?.current || textareaRef.current;
|
|
42
|
+
|
|
43
|
+
if (textarea && autoSize) {
|
|
44
|
+
textarea.style.height = 'auto';
|
|
45
|
+
textarea.style.height = `${textarea.scrollHeight}px`;
|
|
46
|
+
|
|
47
|
+
if (onResize) {
|
|
48
|
+
onResize({
|
|
49
|
+
width: textarea.clientWidth,
|
|
50
|
+
height: textarea.scrollHeight
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, [inputValue, autoSize, onResize, ref]);
|
|
55
|
+
|
|
56
|
+
const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
|
|
57
|
+
setInputValue(e.target.value);
|
|
58
|
+
|
|
59
|
+
if (props.onChange) {
|
|
60
|
+
props.onChange(e);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
65
|
+
if (e.key === 'Enter' && onPressEnter) {
|
|
66
|
+
onPressEnter(e);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const handleClear = () => {
|
|
71
|
+
setInputValue('');
|
|
72
|
+
|
|
73
|
+
if (props.onChange) {
|
|
74
|
+
props.onChange({
|
|
75
|
+
target: { value: '' }
|
|
76
|
+
} as ChangeEvent<HTMLTextAreaElement>);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div className={`${prefixCls}-wrapper ${prefixClsV3}-wrapper ${rootClassName || ''}`}>
|
|
82
|
+
<textarea
|
|
83
|
+
{...props}
|
|
84
|
+
ref={ref || textareaRef}
|
|
85
|
+
value={inputValue}
|
|
86
|
+
onChange={handleChange}
|
|
87
|
+
onKeyDown={handleKeyDown}
|
|
88
|
+
style={{ ...styles?.textarea, ...style }}
|
|
89
|
+
className={clsx([
|
|
90
|
+
`${prefixCls} ${prefixClsV3} ${prefixCls}-${size} ${prefixClsV3}-${size} ${prefixClsV3}-${variant} ${prefixCls}-${variant} ${prefixClsV3}-${variant} ${className}`,
|
|
91
|
+
{
|
|
92
|
+
[`${prefixCls}-bordered ${prefixClsV3}-bordered`]: bordered,
|
|
93
|
+
[`${prefixCls}-success ${prefixClsV3}-success`]: status === 'success',
|
|
94
|
+
[`${prefixCls}-error ${prefixClsV3}-error`]: status === 'error' || error
|
|
95
|
+
}
|
|
96
|
+
])}
|
|
97
|
+
/>
|
|
98
|
+
|
|
99
|
+
{allowClear && inputValue && (
|
|
100
|
+
<button className={`${prefixCls}-clear ${prefixClsV3}-clear`} onClick={handleClear}>
|
|
101
|
+
✕
|
|
102
|
+
</button>
|
|
103
|
+
)}
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
Textarea.displayName = 'Textarea';
|
|
109
|
+
|
|
110
|
+
export default Textarea;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Textarea } from '../Textarea/Textarea'
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
.xUi-textarea-wrapper {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
margin-bottom: 10px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.xUi-textarea {
|
|
8
|
+
padding: 8px 12px;
|
|
9
|
+
font-size: 14px;
|
|
10
|
+
border-radius: 6px;
|
|
11
|
+
transition: all 0.3s ease;
|
|
12
|
+
outline: none;
|
|
13
|
+
box-shadow: none;
|
|
14
|
+
resize: vertical;
|
|
15
|
+
min-height: 14px;
|
|
16
|
+
width: 100%;
|
|
17
|
+
border: none;
|
|
18
|
+
color: var(--xui-text-color);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.xUi-textarea:placeholder-shown {
|
|
22
|
+
text-overflow: ellipsis;
|
|
23
|
+
font-size: 14px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.xUi-textarea::placeholder {
|
|
27
|
+
opacity: 0.6;
|
|
28
|
+
color: var(--xui-text-color);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.xUi-textarea-small {
|
|
32
|
+
font-size: 12px;
|
|
33
|
+
padding: 6px 10px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.xUi-textarea-middle {
|
|
37
|
+
font-size: 14px;
|
|
38
|
+
padding: 8px 12px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.xUi-textarea-large {
|
|
42
|
+
padding: 10px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.xUi-textarea-outlined {
|
|
46
|
+
border: 1px solid var(--xui-border-color);
|
|
47
|
+
background: transparent;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.xUi-textarea-outlined:focus {
|
|
51
|
+
border-color: var(--xui-primary-color);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.xUi-textarea-borderless {
|
|
55
|
+
border: none;
|
|
56
|
+
background: transparent;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.xUi-textarea-filled {
|
|
60
|
+
border: 1px solid var(--xui-border-color);
|
|
61
|
+
background: var(--xui-primary-color);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.xUi-textarea-filled:focus {
|
|
65
|
+
background: var(--xui-background-color);
|
|
66
|
+
border-color: var(--xui-primary-color);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.xUi-textarea-underlined {
|
|
70
|
+
border: none;
|
|
71
|
+
border-bottom: 1px solid var(--xui-border-color);
|
|
72
|
+
background: transparent;
|
|
73
|
+
}
|
|
74
|
+
.xUi-textarea-underlined:focus {
|
|
75
|
+
border-bottom-color: var(--xui-primary-color);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.xUi-textarea-container:has(.xUi-textarea-bordered) {
|
|
79
|
+
border: 1px solid var(--xui-border-color);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.xUi-textarea-container:has(.xUi-textarea-success) {
|
|
83
|
+
border-color: var(--xui-success-color);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.xUi-textarea-wrapper:has(.xUi-textarea-error) textarea,
|
|
87
|
+
.xUi-textarea-wrapper:has(.xUi-textarea-error) textarea:focus {
|
|
88
|
+
border: 1px solid var(--xui-error-color);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.xUi-textarea-clear {
|
|
92
|
+
position: absolute;
|
|
93
|
+
right: 0px;
|
|
94
|
+
top: 15px;
|
|
95
|
+
transform: translateY(-50%);
|
|
96
|
+
background: transparent;
|
|
97
|
+
border: none;
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
color: #999;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.xUi-textarea-clear:hover {
|
|
103
|
+
color: #333;
|
|
104
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Input } from '../Input/Input'
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
.xUi-input-container {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
border: 1px solid var(--xui-border-color);
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
background-color: transparent;
|
|
7
|
+
border-radius: var(--xui-border-radius-sm);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.xUi-input-container:not(.xUi-input-error):not(.xUi-input-disabled):has(.xUi-input):hover,
|
|
11
|
+
.xUi-input-container:not(.xUi-input-error):not(.xUi-input-disabled):has(.xUi-input:focus) {
|
|
12
|
+
border: 1px solid var(--xui-primary-color);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.xUi-input-container.xUi-input-error {
|
|
16
|
+
border-color: var(--xui-error-color);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.xUi-input-suffix .error-svg-icon,
|
|
20
|
+
.xUi-input-container.xUi-input-error .error-svg-icon {
|
|
21
|
+
color: var(--xui-error-color);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.xUi-input-wrapper {
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
position: relative;
|
|
28
|
+
height: -webkit-fill-available;
|
|
29
|
+
flex-grow: 1;
|
|
30
|
+
/* margin: -1px; */
|
|
31
|
+
transition: border 0.3s;
|
|
32
|
+
background-color: transparent;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.xUi-input {
|
|
36
|
+
flex: 1;
|
|
37
|
+
padding: 0;
|
|
38
|
+
width: 100%;
|
|
39
|
+
border: none;
|
|
40
|
+
outline: none;
|
|
41
|
+
padding: .1px 7px;
|
|
42
|
+
color: var(--xui-text-color);
|
|
43
|
+
height: -webkit-fill-available;
|
|
44
|
+
background-color: transparent;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.xUi-input:placeholder-shown {
|
|
48
|
+
text-overflow: ellipsis;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.xUi-input::placeholder {
|
|
52
|
+
opacity: 0.6;
|
|
53
|
+
color: var(--xui-text-color);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.xUi-input-suffix,
|
|
57
|
+
.xUi-input-prefix {
|
|
58
|
+
display: flex;
|
|
59
|
+
padding: 0 7px;
|
|
60
|
+
gap: 4px;
|
|
61
|
+
align-items: center;
|
|
62
|
+
color: var(--xui-text-color);
|
|
63
|
+
height: -webkit-fill-available;
|
|
64
|
+
background-color: transparent;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.xUi-input-addon {
|
|
68
|
+
padding: 0 7px;
|
|
69
|
+
display: flex;
|
|
70
|
+
align-items: center;
|
|
71
|
+
color: var(--xui-text-color);
|
|
72
|
+
height: -webkit-fill-available;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.xUi-input-addon.xUi-input-after {
|
|
76
|
+
border-left: 1px solid var(--xui-border-color);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.xUi-input-addon.xUi-input-before {
|
|
80
|
+
border-right: 1px solid var(--xui-border-color);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.xUi-input-large .xUi-input-addon {
|
|
84
|
+
padding: 0 10px;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.xUi-input-clear {
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
position: relative;
|
|
90
|
+
margin: 0 5px;
|
|
91
|
+
display: flex;
|
|
92
|
+
width: 16px;
|
|
93
|
+
align-items: center;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.xUi-input-clear svg {
|
|
97
|
+
color: var(--xui-text-color);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.xUi-input-disabled,
|
|
101
|
+
.xUi-input-disabled .xUi-input,
|
|
102
|
+
.xUi-input-disabled .xUi-input-suffix {
|
|
103
|
+
background-color: var(--xui-color-disabled);
|
|
104
|
+
cursor: not-allowed;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.xUi-input-small {
|
|
108
|
+
height: 22px;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.xUi-input-large .xUi-input-clear,
|
|
112
|
+
.xUi-input-small .xUi-input,
|
|
113
|
+
.xUi-input-small .xUi-input::placeholder {
|
|
114
|
+
font-size: var(--xui-font-size-md);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.xUi-input-middle {
|
|
118
|
+
height: 30px;
|
|
119
|
+
border-radius: var(--xui-border-radius-md);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.xUi-input-large .xUi-input-clear,
|
|
123
|
+
.xUi-input-middle .xUi-input,
|
|
124
|
+
.xUi-input-middle .xUi-input::placeholder {
|
|
125
|
+
font-size: var(--xui-font-size-md);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.xUi-input-large {
|
|
129
|
+
height: 44px;
|
|
130
|
+
border-radius: var(--xui-border-radius-lg);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.xUi-input-large .xUi-input-clear,
|
|
134
|
+
.xUi-input-large .xUi-input,
|
|
135
|
+
.xUi-input-large .xUi-input::placeholder {
|
|
136
|
+
font-size: var(--xui-font-size-lg);
|
|
137
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React, { FC, MouseEvent, useContext } from "react";
|
|
4
|
+
import { MenuContext } from "../Menu";
|
|
5
|
+
import { clsx } from "../../../helpers";
|
|
6
|
+
import { ItemType } from "../../../types/menu";
|
|
7
|
+
import { prefixClsMenu } from "../../../utils";
|
|
8
|
+
|
|
9
|
+
const MenuItem: FC<ItemType> = ({
|
|
10
|
+
itemKey,
|
|
11
|
+
label,
|
|
12
|
+
icon,
|
|
13
|
+
title,
|
|
14
|
+
disabled,
|
|
15
|
+
danger,
|
|
16
|
+
extra,
|
|
17
|
+
selected,
|
|
18
|
+
className = '',
|
|
19
|
+
prefixCls = prefixClsMenu,
|
|
20
|
+
onClick,
|
|
21
|
+
style
|
|
22
|
+
}) => {
|
|
23
|
+
const menuContext = useContext(MenuContext);
|
|
24
|
+
|
|
25
|
+
if (!menuContext) {
|
|
26
|
+
throw new Error('MenuItem must be used within a Menu');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const handleClick = (e: MouseEvent) => {
|
|
30
|
+
if (disabled) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
onClick?.({
|
|
35
|
+
key: itemKey as string,
|
|
36
|
+
keyPath: [itemKey as string],
|
|
37
|
+
domEvent: e as MouseEvent
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
menuContext?.onItemClick(itemKey as string, e);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<li
|
|
45
|
+
style={style}
|
|
46
|
+
role="menuitem"
|
|
47
|
+
title={title as string}
|
|
48
|
+
onClick={handleClick}
|
|
49
|
+
className={clsx([
|
|
50
|
+
`${prefixCls}-item ${className}`,
|
|
51
|
+
{
|
|
52
|
+
[`${prefixCls}-item-disabled`]: disabled,
|
|
53
|
+
[`${prefixCls}-item-selected`]: selected,
|
|
54
|
+
[`${prefixCls}-item-danger`]: danger,
|
|
55
|
+
}
|
|
56
|
+
])}
|
|
57
|
+
>
|
|
58
|
+
{icon && <span className={`${prefixCls}-item-icon`}>{icon}</span>}
|
|
59
|
+
<span className={`${prefixCls}-item-label`}>{label}</span>
|
|
60
|
+
{extra && <span className={`${prefixCls}-item-extra`}>{extra}</span>}
|
|
61
|
+
</li>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default MenuItem;
|