@firecms/ui 3.0.0-beta.8 → 3.0.0-beta.9
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/BooleanSwitch.d.ts +1 -1
- package/dist/components/Checkbox.d.ts +1 -1
- package/dist/components/Chip.d.ts +3 -2
- package/dist/components/DateTimeField.d.ts +2 -3
- package/dist/components/Dialog.d.ts +4 -1
- package/dist/components/Menu.d.ts +4 -1
- package/dist/components/Menubar.d.ts +19 -9
- package/dist/components/MultiSelect.d.ts +31 -16
- package/dist/components/Popover.d.ts +2 -1
- package/dist/components/RadioGroup.d.ts +1 -0
- package/dist/components/Select.d.ts +5 -9
- package/dist/components/Separator.d.ts +2 -1
- package/dist/components/Sheet.d.ts +4 -0
- package/dist/components/Table.d.ts +10 -10
- package/dist/components/Tooltip.d.ts +6 -2
- package/dist/components/_MultiSelect.d.ts +0 -0
- package/dist/icons/Icon.d.ts +1 -1
- package/dist/index.css +77 -0
- package/dist/index.es.js +13036 -13690
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +19684 -49
- package/dist/index.umd.js.map +1 -1
- package/dist/styles.d.ts +3 -3
- package/package.json +109 -106
- package/src/components/Avatar.tsx +0 -2
- package/src/components/BooleanSwitch.tsx +11 -11
- package/src/components/BooleanSwitchWithLabel.tsx +4 -4
- package/src/components/Button.tsx +6 -8
- package/src/components/Card.tsx +2 -2
- package/src/components/Checkbox.tsx +5 -5
- package/src/components/Chip.tsx +7 -4
- package/src/components/DateTimeField.tsx +30 -41
- package/src/components/Dialog.tsx +11 -2
- package/src/components/ExpandablePanel.tsx +3 -3
- package/src/components/FileUpload.tsx +1 -2
- package/src/components/IconButton.tsx +1 -3
- package/src/components/InputLabel.tsx +4 -2
- package/src/components/Menu.tsx +38 -26
- package/src/components/Menubar.tsx +42 -7
- package/src/components/MultiSelect.tsx +333 -164
- package/src/components/Popover.tsx +15 -13
- package/src/components/RadioGroup.tsx +1 -0
- package/src/components/SearchBar.tsx +1 -2
- package/src/components/Select.tsx +98 -119
- package/src/components/Separator.tsx +10 -4
- package/src/components/Sheet.tsx +39 -22
- package/src/components/Skeleton.tsx +1 -1
- package/src/components/Table.tsx +48 -30
- package/src/components/Tabs.tsx +2 -3
- package/src/components/TextField.tsx +2 -6
- package/src/components/Tooltip.tsx +26 -11
- package/src/components/Typography.tsx +14 -16
- package/src/components/_MultiSelect.tsx +222 -0
- package/src/icons/Icon.tsx +2 -2
- package/src/icons/icon_keys.ts +114 -1301
- package/src/index.css +77 -0
- package/src/scripts/generateIconKeys.ts +20 -10
- package/src/styles.ts +3 -3
- package/tailwind.config.js +3 -3
|
@@ -1,193 +1,331 @@
|
|
|
1
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
1
2
|
import * as React from "react";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import * as Dialog from "@radix-ui/react-dialog";
|
|
4
|
-
|
|
3
|
+
import { ChangeEvent, Children, useEffect } from "react";
|
|
5
4
|
import { Command as CommandPrimitive } from "cmdk";
|
|
6
|
-
|
|
7
|
-
import { ExpandMoreIcon } from "../icons";
|
|
8
|
-
import { fieldBackgroundDisabledMixin, fieldBackgroundHoverMixin, fieldBackgroundMixin, focusedMixin } from "../styles";
|
|
9
5
|
import { cls } from "../util";
|
|
6
|
+
import { CloseIcon, ExpandMoreIcon, Icon } from "../icons";
|
|
7
|
+
import { Separator } from "./Separator";
|
|
8
|
+
import { Chip } from "./Chip";
|
|
10
9
|
import { SelectInputLabel } from "./common/SelectInputLabel";
|
|
11
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
defaultBorderMixin,
|
|
12
|
+
fieldBackgroundDisabledMixin,
|
|
13
|
+
fieldBackgroundHoverMixin,
|
|
14
|
+
fieldBackgroundInvisibleMixin,
|
|
15
|
+
fieldBackgroundMixin,
|
|
16
|
+
focusedDisabled
|
|
17
|
+
} from "../styles";
|
|
18
|
+
import { useInjectStyles } from "../hooks";
|
|
19
|
+
|
|
20
|
+
interface MultiSelectContextProps {
|
|
21
|
+
fieldValue?: string[];
|
|
22
|
+
onItemClick: (v: string) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const MultiSelectContext = React.createContext<MultiSelectContextProps>({} as any);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Props for MultiSelect component
|
|
29
|
+
*/
|
|
30
|
+
interface MultiSelectProps {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The modality of the popover. When set to true, interaction with outside elements
|
|
34
|
+
* will be disabled and only popover content will be visible to screen readers.
|
|
35
|
+
* Optional, defaults to false.
|
|
36
|
+
*/
|
|
37
|
+
modalPopover?: boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Additional class names to apply custom styles to the multi-select component.
|
|
41
|
+
* Optional, can be used to add custom styles.
|
|
42
|
+
*/
|
|
43
|
+
className?: string;
|
|
12
44
|
|
|
13
|
-
export type MultiSelectProps = {
|
|
14
45
|
open?: boolean,
|
|
15
46
|
name?: string,
|
|
16
47
|
id?: string,
|
|
17
48
|
onOpenChange?: (open: boolean) => void,
|
|
18
49
|
value?: string[],
|
|
19
|
-
containerClassName?: string,
|
|
20
|
-
className?: string,
|
|
21
50
|
inputClassName?: string,
|
|
22
|
-
|
|
51
|
+
onChange?: React.EventHandler<ChangeEvent<HTMLSelectElement>>,
|
|
52
|
+
onValueChange?: (updatedValue: string[]) => void,
|
|
23
53
|
placeholder?: React.ReactNode,
|
|
24
|
-
renderValue?: (values: string, index:number) => React.ReactNode,
|
|
25
|
-
renderValues?: (values: string[]) => React.ReactNode,
|
|
26
54
|
size?: "small" | "medium",
|
|
27
|
-
|
|
55
|
+
useChips?: boolean,
|
|
56
|
+
label?: React.ReactNode | string,
|
|
28
57
|
disabled?: boolean,
|
|
29
58
|
error?: boolean,
|
|
30
59
|
position?: "item-aligned" | "popper",
|
|
31
60
|
endAdornment?: React.ReactNode,
|
|
61
|
+
multiple?: boolean,
|
|
62
|
+
includeClear?: boolean,
|
|
32
63
|
inputRef?: React.RefObject<HTMLButtonElement>,
|
|
33
64
|
padding?: boolean,
|
|
34
|
-
|
|
35
|
-
children
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
interface MultiSelectContextProps {
|
|
39
|
-
fieldValue?: string[];
|
|
40
|
-
setInputValue: (v: string) => void;
|
|
41
|
-
onValueChangeInternal: (v: string) => void;
|
|
65
|
+
invisible?: boolean,
|
|
66
|
+
children: React.ReactNode;
|
|
67
|
+
renderValues?: (values: string[]) => React.ReactNode;
|
|
42
68
|
}
|
|
43
69
|
|
|
44
|
-
export const
|
|
70
|
+
export const MultiSelect = React.forwardRef<
|
|
71
|
+
HTMLButtonElement,
|
|
72
|
+
MultiSelectProps
|
|
73
|
+
>(
|
|
74
|
+
(
|
|
75
|
+
{
|
|
76
|
+
value,
|
|
77
|
+
size,
|
|
78
|
+
label,
|
|
79
|
+
error,
|
|
80
|
+
onValueChange,
|
|
81
|
+
invisible,
|
|
82
|
+
disabled,
|
|
83
|
+
placeholder,
|
|
84
|
+
modalPopover = false,
|
|
85
|
+
includeClear = true,
|
|
86
|
+
useChips = true,
|
|
87
|
+
className,
|
|
88
|
+
children,
|
|
89
|
+
renderValues,
|
|
90
|
+
open,
|
|
91
|
+
onOpenChange,
|
|
92
|
+
},
|
|
93
|
+
ref
|
|
94
|
+
) => {
|
|
95
|
+
const [isPopoverOpen, setIsPopoverOpen] = React.useState(open ?? false);
|
|
96
|
+
const [selectedValues, setSelectedValues] = React.useState<string[]>(value ?? []);
|
|
45
97
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
onMultiValueChange,
|
|
50
|
-
size = "medium",
|
|
51
|
-
label,
|
|
52
|
-
disabled,
|
|
53
|
-
renderValue,
|
|
54
|
-
renderValues,
|
|
55
|
-
includeFocusOutline = true,
|
|
56
|
-
containerClassName,
|
|
57
|
-
className,
|
|
58
|
-
children,
|
|
59
|
-
error
|
|
60
|
-
}: MultiSelectProps) {
|
|
61
|
-
|
|
62
|
-
const containerRef = React.useRef<HTMLInputElement>(null);
|
|
63
|
-
const inputRef = React.useRef<HTMLInputElement>(null);
|
|
64
|
-
const listRef = React.useRef<HTMLDivElement>(null);
|
|
65
|
-
useOutsideAlerter(listRef, () => setOpenInternal(false));
|
|
66
|
-
|
|
67
|
-
const [openInternal, setOpenInternal] = React.useState(false);
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
setOpenInternal(open ?? false);
|
|
70
|
-
}, [open]);
|
|
71
|
-
|
|
72
|
-
const onValueChangeInternal = React.useCallback((newValue: string) => {
|
|
73
|
-
if (Array.isArray(value) && value.includes(newValue)) {
|
|
74
|
-
onMultiValueChange?.(value.filter(v => v !== newValue));
|
|
75
|
-
} else {
|
|
76
|
-
onMultiValueChange?.([...(value ?? []), newValue]);
|
|
98
|
+
const onPopoverOpenChange = (open: boolean) => {
|
|
99
|
+
setIsPopoverOpen(open);
|
|
100
|
+
onOpenChange?.(open);
|
|
77
101
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
newSelected.pop();
|
|
90
|
-
onMultiValueChange?.(newSelected);
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
setIsPopoverOpen(open ?? false);
|
|
105
|
+
}, [open]);
|
|
106
|
+
|
|
107
|
+
const allValues = children
|
|
108
|
+
?
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
Children.map(children, (child) => {
|
|
111
|
+
if (React.isValidElement(child)) {
|
|
112
|
+
return child.props.value;
|
|
91
113
|
}
|
|
114
|
+
return null;
|
|
115
|
+
}).filter(Boolean) as string[]
|
|
116
|
+
: [];
|
|
117
|
+
|
|
118
|
+
React.useEffect(() => {
|
|
119
|
+
setSelectedValues(value ?? []);
|
|
120
|
+
}, [value]);
|
|
121
|
+
|
|
122
|
+
function onItemClick(newValue: string) {
|
|
123
|
+
let newSelectedValues: string[];
|
|
124
|
+
if (selectedValues.includes(newValue)) {
|
|
125
|
+
newSelectedValues = selectedValues.filter((v) => v !== newValue);
|
|
126
|
+
} else {
|
|
127
|
+
newSelectedValues = [...selectedValues, newValue];
|
|
92
128
|
}
|
|
93
|
-
|
|
94
|
-
if (e.key === "Escape") {
|
|
95
|
-
input.blur();
|
|
96
|
-
setOpenInternal(false);
|
|
97
|
-
e.stopPropagation();
|
|
98
|
-
}
|
|
129
|
+
updateValues(newSelectedValues);
|
|
99
130
|
}
|
|
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
|
-
|
|
131
|
+
|
|
132
|
+
function updateValues(values: string[]) {
|
|
133
|
+
setSelectedValues(values);
|
|
134
|
+
onValueChange?.(values);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const handleInputKeyDown = (
|
|
138
|
+
event: React.KeyboardEvent<HTMLInputElement>
|
|
139
|
+
) => {
|
|
140
|
+
if (event.key === "Enter") {
|
|
141
|
+
onPopoverOpenChange(true);
|
|
142
|
+
} else if (event.key === "Backspace" && !event.currentTarget.value) {
|
|
143
|
+
const newSelectedValues = [...selectedValues];
|
|
144
|
+
newSelectedValues.pop();
|
|
145
|
+
updateValues(newSelectedValues);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const toggleOption = (value: string) => {
|
|
150
|
+
const newSelectedValues = selectedValues.includes(value)
|
|
151
|
+
? selectedValues.filter((v) => v !== value)
|
|
152
|
+
: [...selectedValues, value];
|
|
153
|
+
updateValues(newSelectedValues);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const handleClear = () => {
|
|
157
|
+
updateValues([]);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const handleTogglePopover = () => {
|
|
161
|
+
onPopoverOpenChange(!isPopoverOpen);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const toggleAll = () => {
|
|
165
|
+
if (selectedValues.length === allValues.length) {
|
|
166
|
+
handleClear();
|
|
167
|
+
} else {
|
|
168
|
+
updateValues(allValues);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
useInjectStyles("MultiSelect", `
|
|
173
|
+
[cmdk-group] {
|
|
174
|
+
max-height: 45vh;
|
|
175
|
+
overflow-y: auto;
|
|
176
|
+
// width: 400px;
|
|
177
|
+
} `)
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<MultiSelectContext.Provider
|
|
181
|
+
value={{
|
|
182
|
+
fieldValue: selectedValues,
|
|
183
|
+
onItemClick
|
|
184
|
+
}}>
|
|
185
|
+
|
|
186
|
+
{typeof label === "string" ? <SelectInputLabel error={error}>{label}</SelectInputLabel> : label}
|
|
187
|
+
|
|
188
|
+
<PopoverPrimitive.Root
|
|
189
|
+
open={isPopoverOpen}
|
|
190
|
+
onOpenChange={onPopoverOpenChange}
|
|
191
|
+
modal={modalPopover}
|
|
134
192
|
>
|
|
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
|
-
<div
|
|
163
|
-
ref={listRef}
|
|
164
|
-
className={"z-50 absolute overflow-auto outline-none"}
|
|
165
|
-
style={{
|
|
166
|
-
pointerEvents: openInternal ? "auto" : "none",
|
|
167
|
-
top: (usedBoundingRect?.top ?? 0) + (usedBoundingRect?.height ?? 0),
|
|
168
|
-
left: usedBoundingRect?.left,
|
|
169
|
-
// right: boundingRect?.right,
|
|
170
|
-
width: usedBoundingRect?.width,
|
|
171
|
-
maxHeight: maxHeight,
|
|
172
|
-
|
|
173
|
-
}}>
|
|
174
|
-
|
|
175
|
-
<CommandPrimitive.Group
|
|
176
|
-
className="mt-2 text-slate-900 dark:text-white animate-in z-50 border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-800 p-2 rounded-lg shadow-lg flex flex-col outline-none w-full"
|
|
177
|
-
>
|
|
193
|
+
<PopoverPrimitive.Trigger asChild>
|
|
194
|
+
<button
|
|
195
|
+
ref={ref}
|
|
196
|
+
onClick={handleTogglePopover}
|
|
197
|
+
className={cls(
|
|
198
|
+
size === "small" ? "min-h-[42px]" : "min-h-[64px]",
|
|
199
|
+
"py-2",
|
|
200
|
+
"px-4",
|
|
201
|
+
"select-none rounded-md text-sm",
|
|
202
|
+
invisible ? fieldBackgroundInvisibleMixin : fieldBackgroundMixin,
|
|
203
|
+
disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
|
|
204
|
+
"relative flex items-center",
|
|
205
|
+
className
|
|
206
|
+
)}
|
|
207
|
+
>
|
|
208
|
+
{selectedValues.length > 0 ? (
|
|
209
|
+
<div className="flex justify-between items-center w-full">
|
|
210
|
+
<div className="flex flex-wrap items-center gap-1.5 text-start">
|
|
211
|
+
{renderValues && renderValues(selectedValues)}
|
|
212
|
+
{!renderValues && selectedValues.map((value) => {
|
|
213
|
+
|
|
214
|
+
// @ts-ignore
|
|
215
|
+
const childrenProps: MultiSelectItemProps[] = Children.map(children, (child) => {
|
|
216
|
+
if (React.isValidElement(child)) {
|
|
217
|
+
return child.props;
|
|
218
|
+
}
|
|
219
|
+
}).filter(Boolean);
|
|
178
220
|
|
|
221
|
+
const option = childrenProps.find((o) => o.value === value);
|
|
222
|
+
if (!useChips) {
|
|
223
|
+
return option?.children;
|
|
224
|
+
}
|
|
225
|
+
return (
|
|
226
|
+
<Chip
|
|
227
|
+
size={"small"}
|
|
228
|
+
key={value}
|
|
229
|
+
className={cls("flex flex-row items-center p-1")}
|
|
230
|
+
>
|
|
231
|
+
{option?.children}
|
|
232
|
+
<CloseIcon
|
|
233
|
+
size={"smallest"}
|
|
234
|
+
onClick={(event) => {
|
|
235
|
+
event.stopPropagation();
|
|
236
|
+
toggleOption(value);
|
|
237
|
+
}}
|
|
238
|
+
/>
|
|
239
|
+
</Chip>
|
|
240
|
+
);
|
|
241
|
+
})}
|
|
242
|
+
</div>
|
|
243
|
+
<div className="flex items-center justify-between">
|
|
244
|
+
{includeClear && <CloseIcon
|
|
245
|
+
className={"ml-4"}
|
|
246
|
+
size={"small"}
|
|
247
|
+
onClick={(event) => {
|
|
248
|
+
event.stopPropagation();
|
|
249
|
+
handleClear();
|
|
250
|
+
}}
|
|
251
|
+
/>}
|
|
252
|
+
<div className={cls("px-2 h-full flex items-center")}>
|
|
253
|
+
<ExpandMoreIcon size={"small"}
|
|
254
|
+
className={cls("transition", isPopoverOpen ? "rotate-180" : "")}/>
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
</div>
|
|
258
|
+
) : (
|
|
259
|
+
<div className="flex items-center justify-between w-full mx-auto">
|
|
260
|
+
<span className="text-sm">
|
|
261
|
+
{placeholder}
|
|
262
|
+
</span>
|
|
263
|
+
<div className={cls("px-2 h-full flex items-center")}>
|
|
264
|
+
<ExpandMoreIcon size={"small"}
|
|
265
|
+
className={cls("transition", isPopoverOpen ? "rotate-180" : "")}/>
|
|
266
|
+
</div>
|
|
267
|
+
</div>
|
|
268
|
+
)}
|
|
269
|
+
</button>
|
|
270
|
+
</PopoverPrimitive.Trigger>
|
|
271
|
+
<PopoverPrimitive.Content
|
|
272
|
+
className={cls("z-50 relative overflow-hidden border bg-white dark:bg-gray-900 rounded-lg w-[400px]", defaultBorderMixin)}
|
|
273
|
+
align="start"
|
|
274
|
+
sideOffset={8}
|
|
275
|
+
onEscapeKeyDown={() => onPopoverOpenChange(false)}
|
|
276
|
+
>
|
|
277
|
+
<CommandPrimitive>
|
|
278
|
+
<div className={"flex flex-row items-center"}>
|
|
279
|
+
<CommandPrimitive.Input
|
|
280
|
+
className={cls(focusedDisabled, "bg-transparent outline-none flex-1 h-full w-full m-4 flex-grow")}
|
|
281
|
+
placeholder="Search..."
|
|
282
|
+
onKeyDown={handleInputKeyDown}
|
|
283
|
+
/>
|
|
284
|
+
{selectedValues.length > 0 && (
|
|
285
|
+
<div
|
|
286
|
+
onClick={handleClear}
|
|
287
|
+
className="text-sm justify-center cursor-pointer py-3 px-4 text-text-secondary dark:text-text-secondary-dark">
|
|
288
|
+
Clear
|
|
289
|
+
</div>
|
|
290
|
+
)}
|
|
291
|
+
</div>
|
|
292
|
+
<Separator orientation={"horizontal"} className={"my-0"}/>
|
|
293
|
+
<CommandPrimitive.List>
|
|
294
|
+
<CommandPrimitive.Empty className={"px-4 py-2"}>
|
|
295
|
+
No results found.
|
|
296
|
+
</CommandPrimitive.Empty>
|
|
297
|
+
<CommandPrimitive.Group>
|
|
298
|
+
<CommandPrimitive.Item
|
|
299
|
+
key="all"
|
|
300
|
+
onSelect={toggleAll}
|
|
301
|
+
className={
|
|
302
|
+
cls(
|
|
303
|
+
"flex flex-row items-center gap-1.5",
|
|
304
|
+
"cursor-pointer",
|
|
305
|
+
"m-1",
|
|
306
|
+
"ring-offset-transparent",
|
|
307
|
+
"p-1 rounded aria-[selected=true]:outline-none aria-[selected=true]:ring-2 aria-[selected=true]:ring-primary aria-[selected=true]:ring-opacity-75 aria-[selected=true]:ring-offset-2",
|
|
308
|
+
"aria-[selected=true]:bg-slate-100 aria-[selected=true]:dark:bg-slate-900",
|
|
309
|
+
"cursor-pointer p-2 rounded aria-[selected=true]:bg-slate-100 aria-[selected=true]:dark:bg-slate-900"
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
>
|
|
313
|
+
<InnerCheckBox checked={selectedValues.length === allValues.length}/>
|
|
314
|
+
<span className={"text-sm text-text-secondary dark:text-text-secondary-dark"}>(Select All)</span>
|
|
315
|
+
</CommandPrimitive.Item>
|
|
179
316
|
{children}
|
|
180
317
|
</CommandPrimitive.Group>
|
|
181
318
|
|
|
182
|
-
</
|
|
183
|
-
</
|
|
184
|
-
</
|
|
185
|
-
</
|
|
186
|
-
</
|
|
319
|
+
</CommandPrimitive.List>
|
|
320
|
+
</CommandPrimitive>
|
|
321
|
+
</PopoverPrimitive.Content>
|
|
322
|
+
</PopoverPrimitive.Root>
|
|
323
|
+
</MultiSelectContext.Provider>
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
);
|
|
187
327
|
|
|
188
|
-
|
|
189
|
-
)
|
|
190
|
-
}
|
|
328
|
+
MultiSelect.displayName = "MultiSelect";
|
|
191
329
|
|
|
192
330
|
export interface MultiSelectItemProps {
|
|
193
331
|
value: string;
|
|
@@ -195,32 +333,63 @@ export interface MultiSelectItemProps {
|
|
|
195
333
|
className?: string;
|
|
196
334
|
}
|
|
197
335
|
|
|
198
|
-
export function MultiSelectItem({
|
|
336
|
+
export function MultiSelectItem({
|
|
337
|
+
children,
|
|
338
|
+
value,
|
|
339
|
+
className
|
|
340
|
+
}: MultiSelectItemProps) {
|
|
199
341
|
|
|
200
342
|
const context = React.useContext(MultiSelectContext);
|
|
201
343
|
if (!context) throw new Error("MultiSelectItem must be used inside a MultiSelect");
|
|
202
|
-
const {
|
|
344
|
+
const {
|
|
345
|
+
fieldValue,
|
|
346
|
+
onItemClick
|
|
347
|
+
} = context;
|
|
203
348
|
|
|
349
|
+
const isSelected = (fieldValue ?? []).includes(value);
|
|
204
350
|
return <CommandPrimitive.Item
|
|
351
|
+
// value={value}
|
|
205
352
|
onMouseDown={(e) => {
|
|
206
353
|
e.preventDefault();
|
|
207
354
|
e.stopPropagation();
|
|
208
355
|
}}
|
|
209
356
|
onSelect={(_) => {
|
|
210
|
-
|
|
211
|
-
onValueChangeInternal(value);
|
|
357
|
+
onItemClick(value);
|
|
212
358
|
}}
|
|
213
359
|
className={cls(
|
|
214
|
-
|
|
360
|
+
"flex flex-row items-center gap-1.5",
|
|
361
|
+
isSelected ? "bg-slate-200 dark:bg-slate-950" : "",
|
|
215
362
|
"cursor-pointer",
|
|
216
363
|
"m-1",
|
|
217
364
|
"ring-offset-transparent",
|
|
218
|
-
"p-
|
|
365
|
+
"p-1 rounded aria-[selected=true]:outline-none aria-[selected=true]:ring-2 aria-[selected=true]:ring-primary aria-[selected=true]:ring-opacity-75 aria-[selected=true]:ring-offset-2",
|
|
219
366
|
"aria-[selected=true]:bg-slate-100 aria-[selected=true]:dark:bg-slate-900",
|
|
220
367
|
"cursor-pointer p-2 rounded aria-[selected=true]:bg-slate-100 aria-[selected=true]:dark:bg-slate-900",
|
|
221
368
|
className
|
|
222
369
|
)}
|
|
223
370
|
>
|
|
371
|
+
<InnerCheckBox checked={isSelected}/>
|
|
224
372
|
{children}
|
|
225
373
|
</CommandPrimitive.Item>;
|
|
374
|
+
|
|
226
375
|
}
|
|
376
|
+
|
|
377
|
+
function InnerCheckBox({ checked }: { checked: boolean }) {
|
|
378
|
+
return <div className={cls(
|
|
379
|
+
"p-2",
|
|
380
|
+
"w-8 h-8",
|
|
381
|
+
"inline-flex items-center justify-center text-sm font-medium focus:outline-none transition-colors ease-in-out duration-150",
|
|
382
|
+
)}>
|
|
383
|
+
<div
|
|
384
|
+
className={cls(
|
|
385
|
+
"border-2 relative transition-colors ease-in-out duration-150",
|
|
386
|
+
"w-4 h-4 rounded flex items-center justify-center",
|
|
387
|
+
(checked ? "bg-primary" : "bg-white dark:bg-slate-900"),
|
|
388
|
+
(checked) ? "text-slate-100 dark:text-slate-900" : "",
|
|
389
|
+
(checked ? "border-transparent" : "border-slate-800 dark:border-slate-200")
|
|
390
|
+
)}>
|
|
391
|
+
{checked && <Icon iconKey={"check"} size={16} className={"absolute"}/>}
|
|
392
|
+
</div>
|
|
393
|
+
</div>
|
|
394
|
+
}
|
|
395
|
+
|
|
@@ -24,6 +24,7 @@ export interface PopoverProps {
|
|
|
24
24
|
enabled?: boolean;
|
|
25
25
|
modal?: boolean;
|
|
26
26
|
className?: string;
|
|
27
|
+
portalContainer?: HTMLElement | null;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export function Popover({
|
|
@@ -41,6 +42,7 @@ export function Popover({
|
|
|
41
42
|
avoidCollisions,
|
|
42
43
|
enabled = true,
|
|
43
44
|
modal = false,
|
|
45
|
+
portalContainer,
|
|
44
46
|
className
|
|
45
47
|
}: PopoverProps) {
|
|
46
48
|
|
|
@@ -51,22 +53,22 @@ export function Popover({
|
|
|
51
53
|
|
|
52
54
|
return <PopoverPrimitive.Root open={open}
|
|
53
55
|
onOpenChange={onOpenChange}
|
|
54
|
-
modal={modal}
|
|
55
|
-
>
|
|
56
|
+
modal={modal}>
|
|
56
57
|
<PopoverPrimitive.Trigger asChild>
|
|
57
58
|
{trigger}
|
|
58
59
|
</PopoverPrimitive.Trigger>
|
|
59
|
-
<PopoverPrimitive.Portal>
|
|
60
|
-
<PopoverPrimitive.Content
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
<PopoverPrimitive.Portal container={portalContainer}>
|
|
61
|
+
<PopoverPrimitive.Content
|
|
62
|
+
className={cls(paperMixin,
|
|
63
|
+
"PopoverContent z-40", className)}
|
|
64
|
+
side={side}
|
|
65
|
+
sideOffset={sideOffset}
|
|
66
|
+
align={align}
|
|
67
|
+
alignOffset={alignOffset}
|
|
68
|
+
arrowPadding={arrowPadding}
|
|
69
|
+
sticky={sticky}
|
|
70
|
+
hideWhenDetached={hideWhenDetached}
|
|
71
|
+
avoidCollisions={avoidCollisions}>
|
|
70
72
|
|
|
71
73
|
{children}
|
|
72
74
|
<PopoverPrimitive.Arrow className="fill-white dark:fill-slate-950"/>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useCallback, useState } from "react";
|
|
2
2
|
|
|
3
|
-
import { defaultBorderMixin
|
|
3
|
+
import { defaultBorderMixin } from "../styles";
|
|
4
4
|
import { CircularProgress, IconButton } from "./index";
|
|
5
5
|
import { ClearIcon, SearchIcon } from "../icons";
|
|
6
6
|
import { cls } from "../util";
|
|
@@ -89,7 +89,6 @@ export function SearchBar({
|
|
|
89
89
|
"relative flex items-center rounded transition-all bg-transparent outline-none appearance-none border-none",
|
|
90
90
|
"pl-12 h-full text-current ",
|
|
91
91
|
expandable ? (active ? "w-[220px]" : "w-[180px]") : "",
|
|
92
|
-
focusedMixin,
|
|
93
92
|
innerClassName
|
|
94
93
|
)}
|
|
95
94
|
/>
|