@firecms/ui 3.0.0-beta.11 → 3.0.0-beta.13

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.
Files changed (37) hide show
  1. package/dist/components/Avatar.d.ts +1 -0
  2. package/dist/components/BooleanSwitch.d.ts +1 -1
  3. package/dist/components/BooleanSwitchWithLabel.d.ts +1 -1
  4. package/dist/components/Button.d.ts +6 -4
  5. package/dist/components/CircularProgress.d.ts +1 -1
  6. package/dist/components/DateTimeField.d.ts +1 -1
  7. package/dist/components/Dialog.d.ts +2 -1
  8. package/dist/components/Menu.d.ts +4 -1
  9. package/dist/components/MultiSelect.d.ts +14 -22
  10. package/dist/components/Select.d.ts +10 -9
  11. package/dist/components/Sheet.d.ts +2 -0
  12. package/dist/components/TextField.d.ts +38 -3
  13. package/dist/index.es.js +788 -684
  14. package/dist/index.es.js.map +1 -1
  15. package/dist/index.umd.js +788 -684
  16. package/dist/index.umd.js.map +1 -1
  17. package/package.json +30 -29
  18. package/src/components/Avatar.tsx +4 -1
  19. package/src/components/BooleanSwitch.tsx +1 -1
  20. package/src/components/BooleanSwitchWithLabel.tsx +7 -2
  21. package/src/components/Button.tsx +16 -17
  22. package/src/components/Chip.tsx +1 -0
  23. package/src/components/CircularProgress.tsx +7 -3
  24. package/src/components/DateTimeField.tsx +29 -23
  25. package/src/components/Dialog.tsx +3 -1
  26. package/src/components/DialogContent.tsx +1 -1
  27. package/src/components/FileUpload.tsx +2 -1
  28. package/src/components/Menu.tsx +13 -4
  29. package/src/components/Menubar.tsx +1 -1
  30. package/src/components/MultiSelect.tsx +54 -51
  31. package/src/components/SearchBar.tsx +1 -1
  32. package/src/components/Select.tsx +70 -55
  33. package/src/components/Sheet.tsx +9 -1
  34. package/src/components/Tabs.tsx +3 -1
  35. package/src/components/TextField.tsx +190 -153
  36. package/src/components/TextareaAutosize.tsx +2 -2
  37. package/src/components/Tooltip.tsx +0 -1
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import React, { useCallback, useEffect, useRef } from "react";
2
+ import React, { ForwardedRef, forwardRef, useEffect, useRef } 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,193 @@ 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
+ disabled?: boolean;
37
+ invisible?: boolean;
38
+ error?: boolean;
39
+ endAdornment?: React.ReactNode;
40
+ autoFocus?: boolean;
41
+ placeholder?: string;
42
+ size?: "smallest" | "small" | "medium" | "large";
43
+ className?: string;
44
+ style?: React.CSSProperties;
45
+ inputClassName?: string;
46
+ inputStyle?: React.CSSProperties;
47
+ inputRef?: React.ForwardedRef<any>;
48
+ /**
49
+ * Maximum number of rows to display.
50
+ */
51
+ maxRows?: number | string;
52
+ /**
53
+ * Minimum number of rows to display.
54
+ * @default 1
55
+ */
56
+ minRows?: number | string;
49
57
  } & Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">;
50
58
 
51
- export function TextField<T extends string | number>({
52
- value,
53
- onChange,
54
- label,
55
- type = "text",
56
- multiline = false,
57
- invisible,
58
- rows,
59
- disabled,
60
- error,
61
- endAdornment,
62
- autoFocus,
63
- placeholder,
64
- size = "large",
65
- className,
66
- style,
67
- inputClassName,
68
- inputStyle,
69
- inputRef: inputRefProp,
70
- ...inputProps
71
- }: TextFieldProps<T>) {
72
-
73
- const inputRef = inputRefProp ?? useRef(null);
74
-
75
- // @ts-ignore
76
- const [focused, setFocused] = React.useState(document.activeElement === inputRef.current);
77
- const hasValue = value !== undefined && value !== null && value !== "";
78
-
79
- useEffect(() => {
80
- if (type !== "number") return;
81
- const handleWheel = (event: any) => {
82
- if (event.target instanceof HTMLElement) event.target.blur()
83
- };
84
-
85
- // Current input element
86
- const element = "current" in inputRef ? inputRef.current : inputRef;
87
-
88
- // Add the event listener
89
- element.addEventListener("wheel", handleWheel);
90
-
91
- // Remove event listener on cleanup
92
- return () => {
93
- element.removeEventListener("wheel", handleWheel);
94
- };
95
- }, [inputRef, type]);
96
-
97
- const numberInputOnWheelPreventChange = useCallback((e: any) => {
98
- e.preventDefault()
99
- }, []);
100
-
101
- const input = multiline
102
- ? <TextareaAutosize
103
- {...inputProps as any}
104
- ref={inputRef}
105
- placeholder={focused || hasValue || !label ? placeholder : undefined}
106
- autoFocus={autoFocus}
107
- rows={rows}
108
- value={value ?? ""}
109
- onChange={onChange}
110
- style={inputStyle}
111
- className={cls(
112
- invisible ? focusedInvisibleMixin : "",
113
- "rounded-md resize-none w-full outline-none p-[32px] text-base bg-transparent min-h-[64px] px-3 pt-8",
114
- disabled && "border border-transparent outline-none opacity-50 text-surface-accent-600 dark:text-surface-accent-500"
115
- )}
116
- />
117
- : <input
118
- {...inputProps}
119
- ref={inputRef}
120
- onWheel={type === "number" ? numberInputOnWheelPreventChange : undefined}
121
- disabled={disabled}
122
- style={inputStyle}
123
- className={cls(
124
- "w-full outline-none bg-transparent leading-normal px-3",
125
- "rounded-md",
126
- "focused:text-text-primary focused:dark:text-text-primary-dark",
127
- invisible ? focusedInvisibleMixin : "",
128
- disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
129
- size === "small" ? "min-h-[32px]" : (size === "medium" ? "min-h-[48px]" : "min-h-[64px]"),
130
- label ? (size === "large" ? "pt-8 pb-2" : "pt-4 pb-2") : "py-2",
131
- endAdornment ? "pr-10" : "pr-3",
132
- disabled && "border border-transparent outline-none opacity-50 dark:opacity-50 text-surface-accent-800 dark:text-white",
133
- inputClassName
134
- )}
135
- placeholder={focused || hasValue || !label ? placeholder : undefined}
136
- autoFocus={autoFocus}
137
- onFocus={() => setFocused(true)}
138
- onBlur={() => setFocused(false)}
139
- type={type}
140
- value={Number.isNaN(value) ? "" : (value ?? "")}
141
- onChange={onChange}
142
- />;
143
-
144
- return (
145
- <div
146
- className={cls(
147
- "rounded-md relative max-w-full",
148
- invisible ? fieldBackgroundInvisibleMixin : fieldBackgroundMixin,
149
- disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
150
- error ? "border border-red-500 dark:border-red-600" : "",
151
- {
152
- "min-h-[32px]": !invisible && size === "small",
153
- "min-h-[48px]": !invisible && size === "medium",
154
- "min-h-[64px]": !invisible && size === "large"
155
- },
156
- className)}
157
- style={style}>
158
-
159
- {label && (
160
- <InputLabel
161
- className={cls(
162
- "pointer-events-none absolute",
163
- size === "large" ? "top-1" : "top-[-1px]",
164
- !error ? (focused ? "text-primary dark:text-primary" : "text-text-secondary dark:text-text-secondary-dark") : "text-red-500 dark:text-red-600",
165
- disabled ? "opacity-50" : "")}
166
- shrink={hasValue || focused}
167
- >
168
- {label}
169
- </InputLabel>
170
- )}
171
-
172
- {input}
173
-
174
- {endAdornment && <div
175
- className={cls("flex flex-row justify-center items-center absolute h-full right-0 top-0", {
176
- "mr-4": size === "large",
177
- "mr-3": size === "medium",
178
- "mr-2": size === "small"
179
- })}>{endAdornment}</div>}
180
-
181
- </div>
182
- );
183
- }
59
+ export const TextField = forwardRef<HTMLDivElement, TextFieldProps<string | number>>(
60
+ <T extends string | number>(
61
+ {
62
+ value,
63
+ onChange,
64
+ label,
65
+ type = "text",
66
+ multiline = false,
67
+ invisible,
68
+ maxRows,
69
+ minRows,
70
+ disabled,
71
+ error,
72
+ endAdornment,
73
+ autoFocus,
74
+ placeholder,
75
+ size = "large",
76
+ className,
77
+ style,
78
+ inputClassName,
79
+ inputStyle,
80
+ inputRef: inputRefProp,
81
+ ...inputProps
82
+ }: TextFieldProps<T>,
83
+ ref: ForwardedRef<HTMLDivElement>
84
+ ) => {
85
+
86
+ const inputRef = inputRefProp ?? useRef(null);
87
+
88
+ // @ts-ignore
89
+ const [focused, setFocused] = React.useState(document.activeElement === inputRef.current);
90
+ const hasValue = value !== undefined && value !== null && value !== "";
91
+
92
+ useEffect(() => {
93
+ if (type !== "number") return;
94
+ const handleWheel = (event: any) => {
95
+ if (event.target instanceof HTMLElement) event.target.blur();
96
+ };
97
+
98
+ const element = "current" in inputRef ? inputRef.current : inputRef;
99
+
100
+ element?.addEventListener("wheel", handleWheel);
101
+
102
+ return () => {
103
+ element?.removeEventListener("wheel", handleWheel);
104
+ };
105
+ }, [inputRef, type]);
106
+
107
+ const input = multiline ? (
108
+ <TextareaAutosize
109
+ {...(inputProps as any)}
110
+ ref={inputRef}
111
+ placeholder={focused || hasValue || !label ? placeholder : undefined}
112
+ autoFocus={autoFocus}
113
+ minRows={minRows}
114
+ maxRows={maxRows}
115
+ value={value ?? ""}
116
+ onChange={onChange}
117
+ style={inputStyle}
118
+ className={cls(
119
+ invisible ? focusedInvisibleMixin : "",
120
+ "rounded-md resize-none w-full outline-none p-[32px] text-base bg-transparent min-h-[64px] px-3 pt-8",
121
+ disabled && "outline-none opacity-50 text-surface-accent-600 dark:text-surface-accent-500",
122
+ inputClassName
123
+ )}
124
+ />
125
+ ) : (
126
+ <input
127
+ {...inputProps}
128
+ ref={inputRef}
129
+ disabled={disabled}
130
+ style={inputStyle}
131
+ className={cls(
132
+ "w-full outline-none bg-transparent leading-normal px-3",
133
+ "rounded-md",
134
+ "focused:text-text-primary focused:dark:text-text-primary-dark",
135
+ invisible ? focusedInvisibleMixin : "",
136
+ disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
137
+ {
138
+ "min-h-[28px]": size === "smallest",
139
+ "min-h-[32px]": size === "small",
140
+ "min-h-[42px]": size === "medium",
141
+ "min-h-[64px]": size === "large",
142
+ },
143
+ label
144
+ ? size === "large"
145
+ ? "pt-8 pb-2"
146
+ : "pt-4 pb-2"
147
+ : "py-2",
148
+ endAdornment ? "pr-10" : "pr-3",
149
+ disabled &&
150
+ "outline-none opacity-50 dark:opacity-50 text-surface-accent-800 dark:text-white",
151
+ inputClassName
152
+ )}
153
+ placeholder={focused || hasValue || !label ? placeholder : undefined}
154
+ autoFocus={autoFocus}
155
+ onFocus={() => setFocused(true)}
156
+ onBlur={() => setFocused(false)}
157
+ type={type}
158
+ value={type === "number" && Number.isNaN(value) ? "" : value ?? ""}
159
+ onChange={onChange}
160
+ />
161
+ );
162
+
163
+ return (
164
+ <div
165
+ ref={ref}
166
+ className={cls(
167
+ "rounded-md relative max-w-full",
168
+ invisible ? fieldBackgroundInvisibleMixin : fieldBackgroundMixin,
169
+ disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
170
+ error ? "border border-red-500 dark:border-red-600" : "",
171
+ {
172
+ "min-h-[28px]": size === "smallest",
173
+ "min-h-[32px]": size === "small",
174
+ "min-h-[42px]": size === "medium",
175
+ "min-h-[64px]": size === "large",
176
+ },
177
+ className
178
+ )}
179
+ style={style}
180
+ >
181
+ {label && (
182
+ <InputLabel
183
+ className={cls(
184
+ "pointer-events-none absolute",
185
+ size === "large" ? "top-1" : "top-[-1px]",
186
+ !error
187
+ ? focused
188
+ ? "text-primary dark:text-primary"
189
+ : "text-text-secondary dark:text-text-secondary-dark"
190
+ : "text-red-500 dark:text-red-600",
191
+ disabled ? "opacity-50" : ""
192
+ )}
193
+ shrink={hasValue || focused}
194
+ >
195
+ {label}
196
+ </InputLabel>
197
+ )}
198
+
199
+ {input}
200
+
201
+ {endAdornment && (
202
+ <div
203
+ className={cls(
204
+ "flex flex-row justify-center items-center absolute h-full right-0 top-0",
205
+ {
206
+ "mr-4": size === "large",
207
+ "mr-3": size === "medium",
208
+ "mr-2": size === "small" || size === "smallest",
209
+ }
210
+ )}
211
+ >
212
+ {endAdornment}
213
+ </div>
214
+ )}
215
+ </div>
216
+ );
217
+ }
218
+ );
219
+
220
+ TextField.displayName = "TextField";
@@ -270,7 +270,7 @@ export const TextareaAutosize = React.forwardRef(function TextareaAutosize(
270
270
  // Need a large enough difference to allow scrolling.
271
271
  // This prevents infinite rendering loop.
272
272
  overflow: state.overflow ? "hidden" : undefined,
273
- ...style
273
+ ...style,
274
274
  }}
275
275
  onScroll={onScroll}
276
276
  {...other}
@@ -282,9 +282,9 @@ export const TextareaAutosize = React.forwardRef(function TextareaAutosize(
282
282
  ref={shadowRef}
283
283
  tabIndex={-1}
284
284
  style={{
285
+ padding: 0,
285
286
  ...styles.shadow,
286
287
  ...style,
287
- padding: 0
288
288
  }}
289
289
  />
290
290
  </React.Fragment>
@@ -71,7 +71,6 @@ export const Tooltip = ({
71
71
  align={align}
72
72
  side={side}>
73
73
  {title}
74
- {/*<TooltipPrimitive.Arrow className="fill-surface-accent-600"/>*/}
75
74
  </TooltipPrimitive.Content>
76
75
  </TooltipPrimitive.Portal>
77
76
  </TooltipPrimitive.Root>