@firecms/ui 3.0.0-canary.177 → 3.0.0-canary.179
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/dist/components/TextField.d.ts +20 -1
- package/dist/index.es.js +8 -10
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +8 -10
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/components/TextField.tsx +178 -153
- package/src/components/Tooltip.tsx +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firecms/ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.0-canary.
|
|
4
|
+
"version": "3.0.0-canary.179",
|
|
5
5
|
"description": "Awesome Firebase/Firestore-based headless open-source CMS",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/firecmsco"
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"index.css",
|
|
116
116
|
"tailwind.config.js"
|
|
117
117
|
],
|
|
118
|
-
"gitHead": "
|
|
118
|
+
"gitHead": "39125fe4c1a15167d203baee64f2bbd5376eb766",
|
|
119
119
|
"publishConfig": {
|
|
120
120
|
"access": "public"
|
|
121
121
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import React, { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
import React, { useCallback, useEffect, useRef, forwardRef, ForwardedRef } from "react";
|
|
3
3
|
|
|
4
4
|
import { TextareaAutosize } from "./TextareaAutosize";
|
|
5
5
|
import {
|
|
@@ -13,7 +13,7 @@ import { InputLabel } from "./InputLabel";
|
|
|
13
13
|
import { cls } from "../util";
|
|
14
14
|
|
|
15
15
|
export type InputType =
|
|
16
|
-
"text"
|
|
16
|
+
| "text"
|
|
17
17
|
| "number"
|
|
18
18
|
| "phone"
|
|
19
19
|
| "email"
|
|
@@ -28,156 +28,181 @@ export type InputType =
|
|
|
28
28
|
| "color";
|
|
29
29
|
|
|
30
30
|
export type TextFieldProps<T extends string | number> = {
|
|
31
|
-
type?: InputType
|
|
32
|
-
value?: T
|
|
33
|
-
onChange?: (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void
|
|
34
|
-
label?: React.ReactNode
|
|
35
|
-
multiline?: boolean
|
|
36
|
-
rows?: number
|
|
37
|
-
disabled?: boolean
|
|
38
|
-
invisible?: boolean
|
|
39
|
-
error?: boolean
|
|
40
|
-
endAdornment?: React.ReactNode
|
|
41
|
-
autoFocus?: boolean
|
|
42
|
-
placeholder?: string
|
|
43
|
-
size?: "small" | "medium" | "large"
|
|
44
|
-
className?: string
|
|
45
|
-
style?: React.CSSProperties
|
|
46
|
-
inputClassName?: string
|
|
47
|
-
inputStyle?: React.CSSProperties
|
|
48
|
-
inputRef?: React.ForwardedRef<any
|
|
31
|
+
type?: InputType;
|
|
32
|
+
value?: T;
|
|
33
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
34
|
+
label?: React.ReactNode;
|
|
35
|
+
multiline?: boolean;
|
|
36
|
+
rows?: number;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
invisible?: boolean;
|
|
39
|
+
error?: boolean;
|
|
40
|
+
endAdornment?: React.ReactNode;
|
|
41
|
+
autoFocus?: boolean;
|
|
42
|
+
placeholder?: string;
|
|
43
|
+
size?: "small" | "medium" | "large";
|
|
44
|
+
className?: string;
|
|
45
|
+
style?: React.CSSProperties;
|
|
46
|
+
inputClassName?: string;
|
|
47
|
+
inputStyle?: React.CSSProperties;
|
|
48
|
+
inputRef?: React.ForwardedRef<any>;
|
|
49
49
|
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">;
|
|
50
50
|
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
"
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
"
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
51
|
+
export const TextField = forwardRef<HTMLDivElement, TextFieldProps<string | number>>(
|
|
52
|
+
<T extends string | number>(
|
|
53
|
+
{
|
|
54
|
+
value,
|
|
55
|
+
onChange,
|
|
56
|
+
label,
|
|
57
|
+
type = "text",
|
|
58
|
+
multiline = false,
|
|
59
|
+
invisible,
|
|
60
|
+
rows,
|
|
61
|
+
disabled,
|
|
62
|
+
error,
|
|
63
|
+
endAdornment,
|
|
64
|
+
autoFocus,
|
|
65
|
+
placeholder,
|
|
66
|
+
size = "large",
|
|
67
|
+
className,
|
|
68
|
+
style,
|
|
69
|
+
inputClassName,
|
|
70
|
+
inputStyle,
|
|
71
|
+
inputRef: inputRefProp,
|
|
72
|
+
...inputProps
|
|
73
|
+
}: TextFieldProps<T>,
|
|
74
|
+
ref: ForwardedRef<HTMLDivElement>
|
|
75
|
+
) => {
|
|
76
|
+
|
|
77
|
+
const inputRef = inputRefProp ?? useRef(null);
|
|
78
|
+
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
const [focused, setFocused] = React.useState(document.activeElement === inputRef.current);
|
|
81
|
+
const hasValue = value !== undefined && value !== null && value !== "";
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (type !== "number") return;
|
|
85
|
+
const handleWheel = (event: any) => {
|
|
86
|
+
if (event.target instanceof HTMLElement) event.target.blur();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const element = "current" in inputRef ? inputRef.current : inputRef;
|
|
90
|
+
|
|
91
|
+
element?.addEventListener("wheel", handleWheel);
|
|
92
|
+
|
|
93
|
+
return () => {
|
|
94
|
+
element?.removeEventListener("wheel", handleWheel);
|
|
95
|
+
};
|
|
96
|
+
}, [inputRef, type]);
|
|
97
|
+
|
|
98
|
+
const input = multiline ? (
|
|
99
|
+
<TextareaAutosize
|
|
100
|
+
{...(inputProps as any)}
|
|
101
|
+
ref={inputRef}
|
|
102
|
+
placeholder={focused || hasValue || !label ? placeholder : undefined}
|
|
103
|
+
autoFocus={autoFocus}
|
|
104
|
+
rows={rows}
|
|
105
|
+
value={value ?? ""}
|
|
106
|
+
onChange={onChange}
|
|
107
|
+
style={inputStyle}
|
|
108
|
+
className={cls(
|
|
109
|
+
invisible ? focusedInvisibleMixin : "",
|
|
110
|
+
"rounded-md resize-none w-full outline-none p-[32px] text-base bg-transparent min-h-[64px] px-3 pt-8",
|
|
111
|
+
disabled && "outline-none opacity-50 text-surface-accent-600 dark:text-surface-accent-500",
|
|
112
|
+
inputClassName
|
|
113
|
+
)}
|
|
114
|
+
/>
|
|
115
|
+
) : (
|
|
116
|
+
<input
|
|
117
|
+
{...inputProps}
|
|
118
|
+
ref={inputRef}
|
|
119
|
+
disabled={disabled}
|
|
120
|
+
style={inputStyle}
|
|
121
|
+
className={cls(
|
|
122
|
+
"w-full outline-none bg-transparent leading-normal px-3",
|
|
123
|
+
"rounded-md",
|
|
124
|
+
"focused:text-text-primary focused:dark:text-text-primary-dark",
|
|
125
|
+
invisible ? focusedInvisibleMixin : "",
|
|
126
|
+
disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
|
|
127
|
+
size === "small"
|
|
128
|
+
? "min-h-[32px]"
|
|
129
|
+
: size === "medium"
|
|
130
|
+
? "min-h-[48px]"
|
|
131
|
+
: "min-h-[64px]",
|
|
132
|
+
label
|
|
133
|
+
? size === "large"
|
|
134
|
+
? "pt-8 pb-2"
|
|
135
|
+
: "pt-4 pb-2"
|
|
136
|
+
: "py-2",
|
|
137
|
+
endAdornment ? "pr-10" : "pr-3",
|
|
138
|
+
disabled &&
|
|
139
|
+
"outline-none opacity-50 dark:opacity-50 text-surface-accent-800 dark:text-white",
|
|
140
|
+
inputClassName
|
|
141
|
+
)}
|
|
142
|
+
placeholder={focused || hasValue || !label ? placeholder : undefined}
|
|
143
|
+
autoFocus={autoFocus}
|
|
144
|
+
onFocus={() => setFocused(true)}
|
|
145
|
+
onBlur={() => setFocused(false)}
|
|
146
|
+
type={type}
|
|
147
|
+
value={type === "number" && Number.isNaN(value) ? "" : value ?? ""}
|
|
148
|
+
onChange={onChange}
|
|
149
|
+
/>
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<div
|
|
154
|
+
ref={ref}
|
|
155
|
+
className={cls(
|
|
156
|
+
"rounded-md relative max-w-full",
|
|
157
|
+
invisible ? fieldBackgroundInvisibleMixin : fieldBackgroundMixin,
|
|
158
|
+
disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
|
|
159
|
+
error ? "border border-red-500 dark:border-red-600" : "",
|
|
160
|
+
{
|
|
161
|
+
"min-h-[32px]": !invisible && size === "small",
|
|
162
|
+
"min-h-[48px]": !invisible && size === "medium",
|
|
163
|
+
"min-h-[64px]": !invisible && size === "large",
|
|
164
|
+
},
|
|
165
|
+
className
|
|
166
|
+
)}
|
|
167
|
+
style={style}
|
|
168
|
+
>
|
|
169
|
+
{label && (
|
|
170
|
+
<InputLabel
|
|
171
|
+
className={cls(
|
|
172
|
+
"pointer-events-none absolute",
|
|
173
|
+
size === "large" ? "top-1" : "top-[-1px]",
|
|
174
|
+
!error
|
|
175
|
+
? focused
|
|
176
|
+
? "text-primary dark:text-primary"
|
|
177
|
+
: "text-text-secondary dark:text-text-secondary-dark"
|
|
178
|
+
: "text-red-500 dark:text-red-600",
|
|
179
|
+
disabled ? "opacity-50" : ""
|
|
180
|
+
)}
|
|
181
|
+
shrink={hasValue || focused}
|
|
182
|
+
>
|
|
183
|
+
{label}
|
|
184
|
+
</InputLabel>
|
|
185
|
+
)}
|
|
186
|
+
|
|
187
|
+
{input}
|
|
188
|
+
|
|
189
|
+
{endAdornment && (
|
|
190
|
+
<div
|
|
191
|
+
className={cls(
|
|
192
|
+
"flex flex-row justify-center items-center absolute h-full right-0 top-0",
|
|
193
|
+
{
|
|
194
|
+
"mr-4": size === "large",
|
|
195
|
+
"mr-3": size === "medium",
|
|
196
|
+
"mr-2": size === "small",
|
|
197
|
+
}
|
|
198
|
+
)}
|
|
199
|
+
>
|
|
200
|
+
{endAdornment}
|
|
201
|
+
</div>
|
|
202
|
+
)}
|
|
203
|
+
</div>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
TextField.displayName = "TextField";
|