ant-float-label 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Tim Ou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Antd 5 form style similar to MUI
2
+ 一个简单的react状态管理库
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Tim Ou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Antd 5 form style similar to MUI
2
+ 一个简单的react状态管理库
@@ -0,0 +1,402 @@
1
+ import "./index.css"
2
+ 'use strict';
3
+
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var antd = require('antd');
6
+ var react = require('react');
7
+
8
+ const { useToken } = antd.theme;
9
+ function FloattingLabelBox({ focused, haveValue, label, children, width, height, status, }) {
10
+ const { token } = useToken();
11
+ const statusColor = react.useMemo(() => {
12
+ const colors = {
13
+ borderColorActive: token.colorPrimaryActive,
14
+ textColorActive: token.colorPrimary,
15
+ textColor: token.colorTextTertiary,
16
+ borderColor: token.colorBorder,
17
+ };
18
+ if (status === "warning") {
19
+ colors.borderColorActive = token.colorWarningActive;
20
+ colors.textColorActive = token.colorWarningTextActive;
21
+ colors.textColor = token.colorWarningText;
22
+ colors.borderColor = token.colorWarningBorder;
23
+ }
24
+ else if (status === "error") {
25
+ colors.borderColorActive = token.colorErrorActive;
26
+ colors.textColorActive = token.colorErrorTextActive;
27
+ colors.textColor = token.colorErrorText;
28
+ colors.borderColor = token.colorErrorBorder;
29
+ }
30
+ return colors;
31
+ }, [status, token]);
32
+ return (jsxRuntime.jsxs("div", { className: "ant-float-label-box", style: {
33
+ width: width ?? "100%",
34
+ height,
35
+ }, children: [jsxRuntime.jsx("div", { style: {
36
+ width: "100%",
37
+ height: "100%",
38
+ overflow: "hidden",
39
+ borderRadius: token.borderRadius,
40
+ }, children: children }), jsxRuntime.jsx("label", { className: "ant-float-label-box-label", style: {
41
+ color: focused ? statusColor.textColorActive : statusColor.textColor,
42
+ height: focused || haveValue ? "auto" : "100%",
43
+ transform: focused || haveValue
44
+ ? "translate(14px, -9px) scale(0.75)"
45
+ : `translate(1em, 0px) scale(1)`,
46
+ }, children: label }), jsxRuntime.jsx("fieldset", { style: {
47
+ border: focused
48
+ ? `2px solid ${statusColor.borderColorActive}`
49
+ : `1px solid ${statusColor.borderColor}`,
50
+ borderRadius: token.borderRadius,
51
+ }, className: "ant-float-label-box-fieldset", children: jsxRuntime.jsx("legend", { className: "ant-float-label-box-legend", style: {
52
+ maxWidth: focused || haveValue ? "100%" : "0.01px",
53
+ }, children: label }) })] }));
54
+ }
55
+
56
+ function FloatAutoComplete({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
57
+ const initFlag = react.useRef(false);
58
+ const [isFocus, setIsFocus] = react.useState(false);
59
+ const [inputValue, setInputValue] = react.useState(defaultValue ?? value);
60
+ const handleFocus = react.useCallback((e) => {
61
+ setIsFocus(true);
62
+ if (onFocus) {
63
+ onFocus(e);
64
+ }
65
+ }, [onFocus]);
66
+ const handleBlur = react.useCallback((e) => {
67
+ setIsFocus(false);
68
+ setInputValue(e.target.value);
69
+ if (onBlur) {
70
+ onBlur(e);
71
+ }
72
+ }, [onBlur]);
73
+ const handleChange = react.useCallback((value, option) => {
74
+ setInputValue(value);
75
+ if (onChange) {
76
+ onChange(value, option);
77
+ }
78
+ }, [onChange]);
79
+ react.useEffect(() => {
80
+ if (initFlag.current) {
81
+ setInputValue(value);
82
+ }
83
+ initFlag.current = true;
84
+ return () => {
85
+ initFlag.current = false;
86
+ };
87
+ }, [value]);
88
+ return (jsxRuntime.jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: !!inputValue, width: style?.width, height: style?.height, status: restProps.status, children: jsxRuntime.jsx(antd.AutoComplete, { style: {
89
+ width: "100%",
90
+ ...style,
91
+ border: "none",
92
+ }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-auto-complete" }) }));
93
+ }
94
+
95
+ function FloatCascader({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
96
+ const initFlag = react.useRef(false);
97
+ const [isFocus, setIsFocus] = react.useState(false);
98
+ const [inputValue, setInputValue] = react.useState(defaultValue ?? value);
99
+ const handleFocus = react.useCallback((e) => {
100
+ setIsFocus(true);
101
+ if (onFocus) {
102
+ onFocus(e);
103
+ }
104
+ }, [onFocus]);
105
+ const handleBlur = react.useCallback((e) => {
106
+ setIsFocus(false);
107
+ if (onBlur) {
108
+ onBlur(e);
109
+ }
110
+ }, [onBlur]);
111
+ const handleChange = react.useCallback((value, selectedOptions) => {
112
+ setInputValue(value);
113
+ if (onChange) {
114
+ onChange(value, selectedOptions);
115
+ }
116
+ }, [onChange]);
117
+ react.useEffect(() => {
118
+ if (initFlag.current) {
119
+ setInputValue(value);
120
+ }
121
+ initFlag.current = true;
122
+ return () => {
123
+ initFlag.current = false;
124
+ };
125
+ }, [value]);
126
+ const haveValue = react.useMemo(() => {
127
+ const currValue = Array.isArray(inputValue) && inputValue.length === 0
128
+ ? undefined
129
+ : inputValue;
130
+ return !!currValue;
131
+ }, [inputValue]);
132
+ return (jsxRuntime.jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsxRuntime.jsx(antd.Cascader, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-select" }) }));
133
+ }
134
+
135
+ function FloatDatePicker({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
136
+ const initFlag = react.useRef(false);
137
+ const [isFocus, setIsFocus] = react.useState(false);
138
+ const [inputValue, setInputValue] = react.useState(defaultValue ?? value);
139
+ const handleFocus = react.useCallback((event, info) => {
140
+ setIsFocus(true);
141
+ if (onFocus) {
142
+ onFocus(event, info);
143
+ }
144
+ }, [onFocus]);
145
+ const handleBlur = react.useCallback((event, info) => {
146
+ setIsFocus(false);
147
+ if (onBlur) {
148
+ onBlur(event, info);
149
+ }
150
+ }, [onBlur]);
151
+ const handleChange = react.useCallback((value, dateString) => {
152
+ setInputValue(value);
153
+ if (onChange) {
154
+ onChange(value, dateString);
155
+ }
156
+ }, [onChange]);
157
+ react.useEffect(() => {
158
+ if (initFlag.current) {
159
+ setInputValue(value);
160
+ }
161
+ initFlag.current = true;
162
+ return () => {
163
+ initFlag.current = false;
164
+ };
165
+ }, [value]);
166
+ return (jsxRuntime.jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: !!inputValue, width: style?.width, height: style?.height, status: restProps.status, children: jsxRuntime.jsx(antd.DatePicker, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-picker", placeholder: "" }) }));
167
+ }
168
+
169
+ function FloatInput({ placeholder, onFocus, onBlur, value, defaultValue, style, size, ...restProps }) {
170
+ const initFlag = react.useRef(false);
171
+ const [isFocus, setIsFocus] = react.useState(false);
172
+ const [inputValue, setInputValue] = react.useState(defaultValue ?? value);
173
+ const handleFocus = react.useCallback((e) => {
174
+ setIsFocus(true);
175
+ if (onFocus) {
176
+ onFocus(e);
177
+ }
178
+ }, [onFocus]);
179
+ const handleBlur = react.useCallback((e) => {
180
+ setIsFocus(false);
181
+ setInputValue(e.target.value);
182
+ if (onBlur) {
183
+ onBlur(e);
184
+ }
185
+ }, [onBlur]);
186
+ react.useEffect(() => {
187
+ if (initFlag.current) {
188
+ setInputValue(value);
189
+ }
190
+ initFlag.current = true;
191
+ return () => {
192
+ initFlag.current = false;
193
+ };
194
+ }, [value]);
195
+ return (jsxRuntime.jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: !!inputValue, width: style?.width, height: style?.height, status: restProps.status, children: jsxRuntime.jsx(antd.Input, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size }) }));
196
+ }
197
+
198
+ function FloatInputNumber({ placeholder, onFocus, onBlur, value, defaultValue, style, size, ...restProps }) {
199
+ const initFlag = react.useRef(false);
200
+ const [isFocus, setIsFocus] = react.useState(false);
201
+ const [inputValue, setInputValue] = react.useState(defaultValue ?? value);
202
+ const handleFocus = react.useCallback((e) => {
203
+ setIsFocus(true);
204
+ if (onFocus) {
205
+ onFocus(e);
206
+ }
207
+ }, [onFocus]);
208
+ const handleBlur = react.useCallback((e) => {
209
+ setIsFocus(false);
210
+ setInputValue(e.target.value);
211
+ if (onBlur) {
212
+ onBlur(e);
213
+ }
214
+ }, [onBlur]);
215
+ react.useEffect(() => {
216
+ if (initFlag.current) {
217
+ setInputValue(value);
218
+ }
219
+ initFlag.current = true;
220
+ return () => {
221
+ initFlag.current = false;
222
+ };
223
+ }, [value]);
224
+ return (jsxRuntime.jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: !!inputValue, width: style?.width, height: style?.height, status: restProps.status, children: jsxRuntime.jsx(antd.InputNumber, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, rootClassName: "ant-float-label-form-input-number" }) }));
225
+ }
226
+
227
+ const { RangePicker } = antd.DatePicker;
228
+ function FloatRangePicker({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
229
+ const initFlag = react.useRef(false);
230
+ const [isFocus, setIsFocus] = react.useState(false);
231
+ const [inputValue, setInputValue] = react.useState(defaultValue ?? value);
232
+ const handleFocus = react.useCallback((event, info) => {
233
+ setIsFocus(true);
234
+ if (onFocus) {
235
+ onFocus(event, info);
236
+ }
237
+ }, [onFocus]);
238
+ const handleBlur = react.useCallback((event, info) => {
239
+ setIsFocus(false);
240
+ if (onBlur) {
241
+ onBlur(event, info);
242
+ }
243
+ }, [onBlur]);
244
+ const handleChange = react.useCallback((value, dateString) => {
245
+ setInputValue(value);
246
+ if (onChange) {
247
+ onChange(value, dateString);
248
+ }
249
+ }, [onChange]);
250
+ react.useEffect(() => {
251
+ if (initFlag.current) {
252
+ setInputValue(value);
253
+ }
254
+ initFlag.current = true;
255
+ return () => {
256
+ initFlag.current = false;
257
+ };
258
+ }, [value]);
259
+ const haveValue = react.useMemo(() => {
260
+ return !!(isFocus || inputValue);
261
+ }, [inputValue, isFocus]);
262
+ return (jsxRuntime.jsx(FloattingLabelBox, { label: haveValue && placeholder ? placeholder.join(" - ") : "", focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsxRuntime.jsx(RangePicker, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-picker", placeholder: haveValue ? ["", ""] : placeholder }) }));
263
+ }
264
+
265
+ function FloatSelect({ placeholder, onFocus, onBlur, value, defaultValue, style, size, mode, onChange, ...restProps }) {
266
+ const initFlag = react.useRef(false);
267
+ const [isFocus, setIsFocus] = react.useState(false);
268
+ const [inputValue, setInputValue] = react.useState(defaultValue ?? value);
269
+ const handleFocus = react.useCallback((e) => {
270
+ setIsFocus(true);
271
+ if (onFocus) {
272
+ onFocus(e);
273
+ }
274
+ }, [onFocus]);
275
+ const handleBlur = react.useCallback((e) => {
276
+ setIsFocus(false);
277
+ if (onBlur) {
278
+ onBlur(e);
279
+ }
280
+ }, [onBlur]);
281
+ const handleChange = react.useCallback((value, option) => {
282
+ setInputValue(value);
283
+ if (onChange) {
284
+ onChange(value, option);
285
+ }
286
+ }, [onChange]);
287
+ react.useEffect(() => {
288
+ if (initFlag.current) {
289
+ setInputValue(value);
290
+ }
291
+ initFlag.current = true;
292
+ return () => {
293
+ initFlag.current = false;
294
+ };
295
+ }, [value]);
296
+ const haveValue = react.useMemo(() => {
297
+ const currValue = Array.isArray(inputValue) && inputValue.length === 0
298
+ ? undefined
299
+ : inputValue;
300
+ return !!currValue;
301
+ }, [inputValue]);
302
+ return (jsxRuntime.jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsxRuntime.jsx(antd.Select, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, mode: mode, rootClassName: "ant-float-label-form-select" }) }));
303
+ }
304
+
305
+ function FloatTimePicker({ placeholder, onFocus, onBlur, value, defaultValue, style, size, mode, onChange, ...restProps }) {
306
+ const initFlag = react.useRef(false);
307
+ const [isFocus, setIsFocus] = react.useState(false);
308
+ const [inputValue, setInputValue] = react.useState(defaultValue ?? value);
309
+ const handleFocus = react.useCallback((e, info) => {
310
+ setIsFocus(true);
311
+ if (onFocus) {
312
+ onFocus(e, info);
313
+ }
314
+ }, [onFocus]);
315
+ const handleBlur = react.useCallback((e, info) => {
316
+ setIsFocus(false);
317
+ if (onBlur) {
318
+ onBlur(e, info);
319
+ }
320
+ }, [onBlur]);
321
+ const handleChange = react.useCallback((value, option) => {
322
+ setInputValue(value);
323
+ if (onChange) {
324
+ onChange(value, option);
325
+ }
326
+ }, [onChange]);
327
+ react.useEffect(() => {
328
+ if (initFlag.current) {
329
+ setInputValue(value);
330
+ }
331
+ initFlag.current = true;
332
+ return () => {
333
+ initFlag.current = false;
334
+ };
335
+ }, [value]);
336
+ const haveValue = react.useMemo(() => {
337
+ const currValue = Array.isArray(inputValue) && inputValue.length === 0
338
+ ? undefined
339
+ : inputValue;
340
+ return !!currValue;
341
+ }, [inputValue]);
342
+ return (jsxRuntime.jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsxRuntime.jsx(antd.TimePicker, { style: {
343
+ ...style,
344
+ width: "100%",
345
+ border: "none",
346
+ }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, mode: mode, rootClassName: "ant-float-label-form-select", placeholder: "" }) }));
347
+ }
348
+
349
+ function FloatTreeSelect({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
350
+ const initFlag = react.useRef(false);
351
+ const [isFocus, setIsFocus] = react.useState(false);
352
+ const [inputValue, setInputValue] = react.useState(defaultValue ?? value);
353
+ const handleFocus = react.useCallback((e) => {
354
+ setIsFocus(true);
355
+ if (onFocus) {
356
+ onFocus(e);
357
+ }
358
+ }, [onFocus]);
359
+ const handleBlur = react.useCallback((e) => {
360
+ setIsFocus(false);
361
+ if (onBlur) {
362
+ onBlur(e);
363
+ }
364
+ }, [onBlur]);
365
+ const handleChange = react.useCallback((value, labelList, extra) => {
366
+ setInputValue(value);
367
+ if (onChange) {
368
+ onChange(value, labelList, extra);
369
+ }
370
+ }, [onChange]);
371
+ react.useEffect(() => {
372
+ if (initFlag.current) {
373
+ setInputValue(value);
374
+ }
375
+ initFlag.current = true;
376
+ return () => {
377
+ initFlag.current = false;
378
+ };
379
+ }, [value]);
380
+ const haveValue = react.useMemo(() => {
381
+ const currValue = Array.isArray(inputValue) && inputValue.length === 0
382
+ ? undefined
383
+ : inputValue;
384
+ return !!currValue;
385
+ }, [inputValue]);
386
+ return (jsxRuntime.jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsxRuntime.jsx(antd.TreeSelect, { style: {
387
+ ...style,
388
+ width: "100%",
389
+ border: "none",
390
+ }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-select" }) }));
391
+ }
392
+
393
+ exports.FloatAutoComplete = FloatAutoComplete;
394
+ exports.FloatCascader = FloatCascader;
395
+ exports.FloatDatePicker = FloatDatePicker;
396
+ exports.FloatInput = FloatInput;
397
+ exports.FloatInputNumber = FloatInputNumber;
398
+ exports.FloatRangePicker = FloatRangePicker;
399
+ exports.FloatSelect = FloatSelect;
400
+ exports.FloatTimePicker = FloatTimePicker;
401
+ exports.FloatTreeSelect = FloatTreeSelect;
402
+ exports.FloattingLabelBox = FloattingLabelBox;
package/dist/index.css ADDED
@@ -0,0 +1,6 @@
1
+ .ant-float-label-box{position:relative;line-height:normal;}.ant-float-label-box-label{position:absolute;max-width:99%;overflow:hidden;text-overflow:ellipsis;left:0;top:0;font-size:0.85rem;white-space:nowrap;font-weight:400;transform-origin:top left;pointer-events:none;height:100%;display:flex;align-items:center;transition:color 200ms cubic-bezier(0,0,0.2,1) 0ms,transform 200ms cubic-bezier(0,0,0.2,1) 0ms,max-width 200ms cubic-bezier(0,0,0.2,1) 0ms;}.ant-float-label-box-fieldset{padding:0 8px;position:absolute;top:-5px;left:0;right:0;bottom:0;margin:0;pointer-events:none;text-align:left;box-sizing:border-box;min-width:0%;}.ant-float-label-box-legend{width:auto;overflow:hidden;display:block;padding:0;height:11px;font-size:0.85rem;visibility:hidden;transition:max-width 100ms cubic-bezier(0.0,0,0.2,1) 50ms;white-space:nowrap;padding-inline:0;}
2
+ .ant-float-label-form-auto-complete .ant-select-selector {border:none!important;box-shadow:none!important;}
3
+ .ant-float-label-form-picker {border:none!important;box-shadow:none!important;}
4
+ .ant-float-label-form-input-number {border:none!important;box-shadow:none!important;}
5
+ .ant-float-label-form-picker {border:none!important;box-shadow:none!important;}
6
+ .ant-float-label-form-select .ant-select-selector {border:none!important;box-shadow:none!important;}.ant-float-label-form-select{height:auto!important;}
package/dist/index.js ADDED
@@ -0,0 +1,391 @@
1
+ import "./index.css"
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { theme, AutoComplete, Cascader, DatePicker, Input, InputNumber, Select, TimePicker, TreeSelect } from 'antd';
4
+ import { useMemo, useRef, useState, useCallback, useEffect } from 'react';
5
+
6
+ const { useToken } = theme;
7
+ function FloattingLabelBox({ focused, haveValue, label, children, width, height, status, }) {
8
+ const { token } = useToken();
9
+ const statusColor = useMemo(() => {
10
+ const colors = {
11
+ borderColorActive: token.colorPrimaryActive,
12
+ textColorActive: token.colorPrimary,
13
+ textColor: token.colorTextTertiary,
14
+ borderColor: token.colorBorder,
15
+ };
16
+ if (status === "warning") {
17
+ colors.borderColorActive = token.colorWarningActive;
18
+ colors.textColorActive = token.colorWarningTextActive;
19
+ colors.textColor = token.colorWarningText;
20
+ colors.borderColor = token.colorWarningBorder;
21
+ }
22
+ else if (status === "error") {
23
+ colors.borderColorActive = token.colorErrorActive;
24
+ colors.textColorActive = token.colorErrorTextActive;
25
+ colors.textColor = token.colorErrorText;
26
+ colors.borderColor = token.colorErrorBorder;
27
+ }
28
+ return colors;
29
+ }, [status, token]);
30
+ return (jsxs("div", { className: "ant-float-label-box", style: {
31
+ width: width ?? "100%",
32
+ height,
33
+ }, children: [jsx("div", { style: {
34
+ width: "100%",
35
+ height: "100%",
36
+ overflow: "hidden",
37
+ borderRadius: token.borderRadius,
38
+ }, children: children }), jsx("label", { className: "ant-float-label-box-label", style: {
39
+ color: focused ? statusColor.textColorActive : statusColor.textColor,
40
+ height: focused || haveValue ? "auto" : "100%",
41
+ transform: focused || haveValue
42
+ ? "translate(14px, -9px) scale(0.75)"
43
+ : `translate(1em, 0px) scale(1)`,
44
+ }, children: label }), jsx("fieldset", { style: {
45
+ border: focused
46
+ ? `2px solid ${statusColor.borderColorActive}`
47
+ : `1px solid ${statusColor.borderColor}`,
48
+ borderRadius: token.borderRadius,
49
+ }, className: "ant-float-label-box-fieldset", children: jsx("legend", { className: "ant-float-label-box-legend", style: {
50
+ maxWidth: focused || haveValue ? "100%" : "0.01px",
51
+ }, children: label }) })] }));
52
+ }
53
+
54
+ function FloatAutoComplete({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
55
+ const initFlag = useRef(false);
56
+ const [isFocus, setIsFocus] = useState(false);
57
+ const [inputValue, setInputValue] = useState(defaultValue ?? value);
58
+ const handleFocus = useCallback((e) => {
59
+ setIsFocus(true);
60
+ if (onFocus) {
61
+ onFocus(e);
62
+ }
63
+ }, [onFocus]);
64
+ const handleBlur = useCallback((e) => {
65
+ setIsFocus(false);
66
+ setInputValue(e.target.value);
67
+ if (onBlur) {
68
+ onBlur(e);
69
+ }
70
+ }, [onBlur]);
71
+ const handleChange = useCallback((value, option) => {
72
+ setInputValue(value);
73
+ if (onChange) {
74
+ onChange(value, option);
75
+ }
76
+ }, [onChange]);
77
+ useEffect(() => {
78
+ if (initFlag.current) {
79
+ setInputValue(value);
80
+ }
81
+ initFlag.current = true;
82
+ return () => {
83
+ initFlag.current = false;
84
+ };
85
+ }, [value]);
86
+ return (jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: !!inputValue, width: style?.width, height: style?.height, status: restProps.status, children: jsx(AutoComplete, { style: {
87
+ width: "100%",
88
+ ...style,
89
+ border: "none",
90
+ }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-auto-complete" }) }));
91
+ }
92
+
93
+ function FloatCascader({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
94
+ const initFlag = useRef(false);
95
+ const [isFocus, setIsFocus] = useState(false);
96
+ const [inputValue, setInputValue] = useState(defaultValue ?? value);
97
+ const handleFocus = useCallback((e) => {
98
+ setIsFocus(true);
99
+ if (onFocus) {
100
+ onFocus(e);
101
+ }
102
+ }, [onFocus]);
103
+ const handleBlur = useCallback((e) => {
104
+ setIsFocus(false);
105
+ if (onBlur) {
106
+ onBlur(e);
107
+ }
108
+ }, [onBlur]);
109
+ const handleChange = useCallback((value, selectedOptions) => {
110
+ setInputValue(value);
111
+ if (onChange) {
112
+ onChange(value, selectedOptions);
113
+ }
114
+ }, [onChange]);
115
+ useEffect(() => {
116
+ if (initFlag.current) {
117
+ setInputValue(value);
118
+ }
119
+ initFlag.current = true;
120
+ return () => {
121
+ initFlag.current = false;
122
+ };
123
+ }, [value]);
124
+ const haveValue = useMemo(() => {
125
+ const currValue = Array.isArray(inputValue) && inputValue.length === 0
126
+ ? undefined
127
+ : inputValue;
128
+ return !!currValue;
129
+ }, [inputValue]);
130
+ return (jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsx(Cascader, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-select" }) }));
131
+ }
132
+
133
+ function FloatDatePicker({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
134
+ const initFlag = useRef(false);
135
+ const [isFocus, setIsFocus] = useState(false);
136
+ const [inputValue, setInputValue] = useState(defaultValue ?? value);
137
+ const handleFocus = useCallback((event, info) => {
138
+ setIsFocus(true);
139
+ if (onFocus) {
140
+ onFocus(event, info);
141
+ }
142
+ }, [onFocus]);
143
+ const handleBlur = useCallback((event, info) => {
144
+ setIsFocus(false);
145
+ if (onBlur) {
146
+ onBlur(event, info);
147
+ }
148
+ }, [onBlur]);
149
+ const handleChange = useCallback((value, dateString) => {
150
+ setInputValue(value);
151
+ if (onChange) {
152
+ onChange(value, dateString);
153
+ }
154
+ }, [onChange]);
155
+ useEffect(() => {
156
+ if (initFlag.current) {
157
+ setInputValue(value);
158
+ }
159
+ initFlag.current = true;
160
+ return () => {
161
+ initFlag.current = false;
162
+ };
163
+ }, [value]);
164
+ return (jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: !!inputValue, width: style?.width, height: style?.height, status: restProps.status, children: jsx(DatePicker, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-picker", placeholder: "" }) }));
165
+ }
166
+
167
+ function FloatInput({ placeholder, onFocus, onBlur, value, defaultValue, style, size, ...restProps }) {
168
+ const initFlag = useRef(false);
169
+ const [isFocus, setIsFocus] = useState(false);
170
+ const [inputValue, setInputValue] = useState(defaultValue ?? value);
171
+ const handleFocus = useCallback((e) => {
172
+ setIsFocus(true);
173
+ if (onFocus) {
174
+ onFocus(e);
175
+ }
176
+ }, [onFocus]);
177
+ const handleBlur = useCallback((e) => {
178
+ setIsFocus(false);
179
+ setInputValue(e.target.value);
180
+ if (onBlur) {
181
+ onBlur(e);
182
+ }
183
+ }, [onBlur]);
184
+ useEffect(() => {
185
+ if (initFlag.current) {
186
+ setInputValue(value);
187
+ }
188
+ initFlag.current = true;
189
+ return () => {
190
+ initFlag.current = false;
191
+ };
192
+ }, [value]);
193
+ return (jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: !!inputValue, width: style?.width, height: style?.height, status: restProps.status, children: jsx(Input, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size }) }));
194
+ }
195
+
196
+ function FloatInputNumber({ placeholder, onFocus, onBlur, value, defaultValue, style, size, ...restProps }) {
197
+ const initFlag = useRef(false);
198
+ const [isFocus, setIsFocus] = useState(false);
199
+ const [inputValue, setInputValue] = useState(defaultValue ?? value);
200
+ const handleFocus = useCallback((e) => {
201
+ setIsFocus(true);
202
+ if (onFocus) {
203
+ onFocus(e);
204
+ }
205
+ }, [onFocus]);
206
+ const handleBlur = useCallback((e) => {
207
+ setIsFocus(false);
208
+ setInputValue(e.target.value);
209
+ if (onBlur) {
210
+ onBlur(e);
211
+ }
212
+ }, [onBlur]);
213
+ useEffect(() => {
214
+ if (initFlag.current) {
215
+ setInputValue(value);
216
+ }
217
+ initFlag.current = true;
218
+ return () => {
219
+ initFlag.current = false;
220
+ };
221
+ }, [value]);
222
+ return (jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: !!inputValue, width: style?.width, height: style?.height, status: restProps.status, children: jsx(InputNumber, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, rootClassName: "ant-float-label-form-input-number" }) }));
223
+ }
224
+
225
+ const { RangePicker } = DatePicker;
226
+ function FloatRangePicker({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
227
+ const initFlag = useRef(false);
228
+ const [isFocus, setIsFocus] = useState(false);
229
+ const [inputValue, setInputValue] = useState(defaultValue ?? value);
230
+ const handleFocus = useCallback((event, info) => {
231
+ setIsFocus(true);
232
+ if (onFocus) {
233
+ onFocus(event, info);
234
+ }
235
+ }, [onFocus]);
236
+ const handleBlur = useCallback((event, info) => {
237
+ setIsFocus(false);
238
+ if (onBlur) {
239
+ onBlur(event, info);
240
+ }
241
+ }, [onBlur]);
242
+ const handleChange = useCallback((value, dateString) => {
243
+ setInputValue(value);
244
+ if (onChange) {
245
+ onChange(value, dateString);
246
+ }
247
+ }, [onChange]);
248
+ useEffect(() => {
249
+ if (initFlag.current) {
250
+ setInputValue(value);
251
+ }
252
+ initFlag.current = true;
253
+ return () => {
254
+ initFlag.current = false;
255
+ };
256
+ }, [value]);
257
+ const haveValue = useMemo(() => {
258
+ return !!(isFocus || inputValue);
259
+ }, [inputValue, isFocus]);
260
+ return (jsx(FloattingLabelBox, { label: haveValue && placeholder ? placeholder.join(" - ") : "", focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsx(RangePicker, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-picker", placeholder: haveValue ? ["", ""] : placeholder }) }));
261
+ }
262
+
263
+ function FloatSelect({ placeholder, onFocus, onBlur, value, defaultValue, style, size, mode, onChange, ...restProps }) {
264
+ const initFlag = useRef(false);
265
+ const [isFocus, setIsFocus] = useState(false);
266
+ const [inputValue, setInputValue] = useState(defaultValue ?? value);
267
+ const handleFocus = useCallback((e) => {
268
+ setIsFocus(true);
269
+ if (onFocus) {
270
+ onFocus(e);
271
+ }
272
+ }, [onFocus]);
273
+ const handleBlur = useCallback((e) => {
274
+ setIsFocus(false);
275
+ if (onBlur) {
276
+ onBlur(e);
277
+ }
278
+ }, [onBlur]);
279
+ const handleChange = useCallback((value, option) => {
280
+ setInputValue(value);
281
+ if (onChange) {
282
+ onChange(value, option);
283
+ }
284
+ }, [onChange]);
285
+ useEffect(() => {
286
+ if (initFlag.current) {
287
+ setInputValue(value);
288
+ }
289
+ initFlag.current = true;
290
+ return () => {
291
+ initFlag.current = false;
292
+ };
293
+ }, [value]);
294
+ const haveValue = useMemo(() => {
295
+ const currValue = Array.isArray(inputValue) && inputValue.length === 0
296
+ ? undefined
297
+ : inputValue;
298
+ return !!currValue;
299
+ }, [inputValue]);
300
+ return (jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsx(Select, { style: { ...style, width: "100%", border: "none" }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, mode: mode, rootClassName: "ant-float-label-form-select" }) }));
301
+ }
302
+
303
+ function FloatTimePicker({ placeholder, onFocus, onBlur, value, defaultValue, style, size, mode, onChange, ...restProps }) {
304
+ const initFlag = useRef(false);
305
+ const [isFocus, setIsFocus] = useState(false);
306
+ const [inputValue, setInputValue] = useState(defaultValue ?? value);
307
+ const handleFocus = useCallback((e, info) => {
308
+ setIsFocus(true);
309
+ if (onFocus) {
310
+ onFocus(e, info);
311
+ }
312
+ }, [onFocus]);
313
+ const handleBlur = useCallback((e, info) => {
314
+ setIsFocus(false);
315
+ if (onBlur) {
316
+ onBlur(e, info);
317
+ }
318
+ }, [onBlur]);
319
+ const handleChange = useCallback((value, option) => {
320
+ setInputValue(value);
321
+ if (onChange) {
322
+ onChange(value, option);
323
+ }
324
+ }, [onChange]);
325
+ useEffect(() => {
326
+ if (initFlag.current) {
327
+ setInputValue(value);
328
+ }
329
+ initFlag.current = true;
330
+ return () => {
331
+ initFlag.current = false;
332
+ };
333
+ }, [value]);
334
+ const haveValue = useMemo(() => {
335
+ const currValue = Array.isArray(inputValue) && inputValue.length === 0
336
+ ? undefined
337
+ : inputValue;
338
+ return !!currValue;
339
+ }, [inputValue]);
340
+ return (jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsx(TimePicker, { style: {
341
+ ...style,
342
+ width: "100%",
343
+ border: "none",
344
+ }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, mode: mode, rootClassName: "ant-float-label-form-select", placeholder: "" }) }));
345
+ }
346
+
347
+ function FloatTreeSelect({ placeholder, onFocus, onBlur, value, defaultValue, style, size, onChange, ...restProps }) {
348
+ const initFlag = useRef(false);
349
+ const [isFocus, setIsFocus] = useState(false);
350
+ const [inputValue, setInputValue] = useState(defaultValue ?? value);
351
+ const handleFocus = useCallback((e) => {
352
+ setIsFocus(true);
353
+ if (onFocus) {
354
+ onFocus(e);
355
+ }
356
+ }, [onFocus]);
357
+ const handleBlur = useCallback((e) => {
358
+ setIsFocus(false);
359
+ if (onBlur) {
360
+ onBlur(e);
361
+ }
362
+ }, [onBlur]);
363
+ const handleChange = useCallback((value, labelList, extra) => {
364
+ setInputValue(value);
365
+ if (onChange) {
366
+ onChange(value, labelList, extra);
367
+ }
368
+ }, [onChange]);
369
+ useEffect(() => {
370
+ if (initFlag.current) {
371
+ setInputValue(value);
372
+ }
373
+ initFlag.current = true;
374
+ return () => {
375
+ initFlag.current = false;
376
+ };
377
+ }, [value]);
378
+ const haveValue = useMemo(() => {
379
+ const currValue = Array.isArray(inputValue) && inputValue.length === 0
380
+ ? undefined
381
+ : inputValue;
382
+ return !!currValue;
383
+ }, [inputValue]);
384
+ return (jsx(FloattingLabelBox, { label: placeholder, focused: isFocus, haveValue: haveValue, width: style?.width, height: style?.height, status: restProps.status, children: jsx(TreeSelect, { style: {
385
+ ...style,
386
+ width: "100%",
387
+ border: "none",
388
+ }, ...restProps, onFocus: handleFocus, onBlur: handleBlur, value: value, defaultValue: defaultValue, size: size, onChange: handleChange, rootClassName: "ant-float-label-form-select" }) }));
389
+ }
390
+
391
+ export { FloatAutoComplete, FloatCascader, FloatDatePicker, FloatInput, FloatInputNumber, FloatRangePicker, FloatSelect, FloatTimePicker, FloatTreeSelect, FloattingLabelBox };
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "ant-float-label",
3
+ "version": "1.0.0",
4
+ "description": "Antd 5 form style similar to MUI",
5
+ "main": "dist/index.cjs.js",
6
+ "module": "dist/index.js",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "scripts": {
10
+ "build": "rollup -c --bundleConfigAsCjs"
11
+ },
12
+ "files": [
13
+ "/dist",
14
+ "LICENSE"
15
+ ],
16
+ "devDependencies": {
17
+ "@rollup/plugin-typescript": "^11.1.6",
18
+ "@types/react": "^18.2.69",
19
+ "@types/react-dom": "^18.2.22",
20
+ "rollup": "^4.13.0",
21
+ "rollup-plugin-copy": "^3.5.0",
22
+ "rollup-plugin-delete": "^2.0.0",
23
+ "rollup-plugin-import-css": "^3.5.0",
24
+ "tslib": "^2.6.2",
25
+ "typescript": "^5.4.3"
26
+ },
27
+ "dependencies": {
28
+ "antd": "^5.15.3",
29
+ "react": "^18.2.0",
30
+ "react-dom": "^18.2.0"
31
+ }
32
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "ant-float-label",
3
+ "version": "1.0.0",
4
+ "description": "Antd 5 form style similar to MUI",
5
+ "main": "dist/index.cjs.js",
6
+ "module": "dist/index.js",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "scripts": {
10
+ "build": "rollup -c --bundleConfigAsCjs"
11
+ },
12
+ "files": [
13
+ "/dist",
14
+ "LICENSE"
15
+ ],
16
+ "devDependencies": {
17
+ "@rollup/plugin-typescript": "^11.1.6",
18
+ "@types/react": "^18.2.69",
19
+ "@types/react-dom": "^18.2.22",
20
+ "rollup": "^4.13.0",
21
+ "rollup-plugin-copy": "^3.5.0",
22
+ "rollup-plugin-delete": "^2.0.0",
23
+ "rollup-plugin-import-css": "^3.5.0",
24
+ "tslib": "^2.6.2",
25
+ "typescript": "^5.4.3"
26
+ },
27
+ "dependencies": {
28
+ "antd": "^5.15.3",
29
+ "react": "^18.2.0",
30
+ "react-dom": "^18.2.0"
31
+ }
32
+ }