@immich/ui 0.58.3 → 0.58.4
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.
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<script lang="ts" generics="T extends string">
|
|
2
2
|
import InternalSelect from '../../internal/Select.svelte';
|
|
3
|
-
import type { MultiSelectProps,
|
|
3
|
+
import type { MultiSelectProps, SelectOption } from '../../types.js';
|
|
4
4
|
|
|
5
|
-
let { onChange,
|
|
5
|
+
let { onChange, onSelect, values = $bindable([]), ...restProps }: MultiSelectProps<T> = $props();
|
|
6
6
|
|
|
7
7
|
const handleChange = (values: T[]) => {
|
|
8
8
|
onChange?.(values);
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const handleSelect = (items: SelectOption<T>[]) => {
|
|
12
|
+
onSelect?.(items);
|
|
13
13
|
};
|
|
14
14
|
</script>
|
|
15
15
|
|
|
16
|
-
<InternalSelect multiple bind:values
|
|
16
|
+
<InternalSelect multiple bind:values onSelect={handleSelect} onChange={handleChange} {...restProps} />
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
<script lang="ts" generics="T extends string">
|
|
2
2
|
import InternalSelect from '../../internal/Select.svelte';
|
|
3
|
-
import type {
|
|
3
|
+
import type { SelectOption, SelectProps } from '../../types.js';
|
|
4
4
|
|
|
5
|
-
let { onChange,
|
|
5
|
+
let { onChange, onSelect, value = $bindable(), ...restProps }: SelectProps<T> = $props();
|
|
6
6
|
|
|
7
|
-
let values = $derived(value ? [
|
|
7
|
+
let values = $derived(value === null || value === undefined ? [] : [value]);
|
|
8
8
|
|
|
9
9
|
const handleChange = (values: T[]) => {
|
|
10
10
|
value = values[0];
|
|
11
11
|
onChange?.(value);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const handleSelect = (items: SelectOption<T>[]) => {
|
|
15
|
+
onSelect?.(items[0]);
|
|
16
16
|
};
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
|
-
<InternalSelect bind:values onChange={handleChange}
|
|
19
|
+
<InternalSelect bind:values onChange={handleChange} onSelect={handleSelect} {...restProps} />
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import IconButton from '../components/IconButton/IconButton.svelte';
|
|
5
5
|
import Input from '../components/Input/Input.svelte';
|
|
6
6
|
import { zIndex } from '../constants.js';
|
|
7
|
-
import type { SelectCommonProps,
|
|
7
|
+
import type { SelectCommonProps, SelectOption } from '../types.js';
|
|
8
8
|
import { cleanClass } from '../utilities/internal.js';
|
|
9
9
|
import { mdiArrowDown, mdiArrowUp, mdiCheck, mdiChevronDown } from '@mdi/js';
|
|
10
10
|
import { Select } from 'bits-ui';
|
|
@@ -13,28 +13,28 @@
|
|
|
13
13
|
type Props = {
|
|
14
14
|
multiple?: boolean;
|
|
15
15
|
values: T[];
|
|
16
|
-
asLabel?: (items:
|
|
16
|
+
asLabel?: (items: SelectOption<T>[]) => string;
|
|
17
17
|
onChange?: (values: T[]) => void;
|
|
18
|
-
|
|
18
|
+
onSelect?: (items: SelectOption<T>[]) => void;
|
|
19
19
|
} & SelectCommonProps<T>;
|
|
20
20
|
|
|
21
21
|
let {
|
|
22
|
-
|
|
22
|
+
options: optionsOrItems,
|
|
23
23
|
shape,
|
|
24
24
|
size: initialSize,
|
|
25
25
|
multiple = false,
|
|
26
26
|
values = $bindable([]),
|
|
27
27
|
onChange,
|
|
28
|
-
onItemChange,
|
|
29
|
-
asLabel = (options:
|
|
28
|
+
onSelect: onItemChange,
|
|
29
|
+
asLabel = (options: SelectOption<T>[]) => options.map(({ label }) => label).join(', '),
|
|
30
30
|
placeholder,
|
|
31
31
|
class: className,
|
|
32
32
|
}: Props = $props();
|
|
33
33
|
|
|
34
|
-
const asOptions = (items: string[] |
|
|
34
|
+
const asOptions = (items: string[] | SelectOption<T>[]) => {
|
|
35
35
|
return items.map((item) => {
|
|
36
36
|
if (typeof item === 'string') {
|
|
37
|
-
return { value: item, label: item } as
|
|
37
|
+
return { value: item, label: item } as SelectOption<T>;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const label = item.label ?? item.value;
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
const context = getFieldContext();
|
|
46
46
|
const { invalid, disabled, ...labelProps } = $derived(context());
|
|
47
47
|
const size = $derived(initialSize ?? labelProps.size ?? 'small');
|
|
48
|
-
const options = $derived(asOptions(
|
|
48
|
+
const options = $derived(asOptions(optionsOrItems));
|
|
49
49
|
|
|
50
50
|
const findOption = (value: string) => options.find((option) => option.value === value);
|
|
51
51
|
const valuesToOptions = (values: T[]) =>
|
|
52
|
-
values.map(findOption).filter((item): item is
|
|
52
|
+
values.map(findOption).filter((item): item is SelectOption<T> => Boolean(item));
|
|
53
53
|
|
|
54
54
|
const selectedLabel = $derived(asLabel(valuesToOptions(values)));
|
|
55
55
|
|
|
@@ -75,7 +75,9 @@
|
|
|
75
75
|
|
|
76
76
|
const onValueChange = (newValues: string[] | string) => {
|
|
77
77
|
values = (Array.isArray(newValues) ? newValues : [newValues]) as T[];
|
|
78
|
-
const items = values
|
|
78
|
+
const items = values
|
|
79
|
+
.map((value) => findOption(value))
|
|
80
|
+
.filter((item): item is SelectOption<T> => item !== undefined);
|
|
79
81
|
|
|
80
82
|
onChange?.(values);
|
|
81
83
|
onItemChange?.(items);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { SelectCommonProps,
|
|
1
|
+
import type { SelectCommonProps, SelectOption } from '../types.js';
|
|
2
2
|
import { Select } from 'bits-ui';
|
|
3
3
|
declare function $$render<T extends string>(): {
|
|
4
4
|
props: {
|
|
5
5
|
multiple?: boolean;
|
|
6
6
|
values: T[];
|
|
7
|
-
asLabel?: (items:
|
|
7
|
+
asLabel?: (items: SelectOption<T>[]) => string;
|
|
8
8
|
onChange?: (values: T[]) => void;
|
|
9
|
-
|
|
9
|
+
onSelect?: (items: SelectOption<T>[]) => void;
|
|
10
10
|
} & SelectCommonProps<T>;
|
|
11
11
|
exports: {};
|
|
12
12
|
bindings: "values";
|
package/dist/types.d.ts
CHANGED
|
@@ -152,13 +152,13 @@ export type TextareaProps = {
|
|
|
152
152
|
shape?: Shape;
|
|
153
153
|
grow?: boolean;
|
|
154
154
|
} & HTMLTextareaAttributes;
|
|
155
|
-
export type
|
|
155
|
+
export type SelectOption<T extends string = string> = {
|
|
156
156
|
label?: string;
|
|
157
157
|
value: T;
|
|
158
158
|
disabled?: boolean;
|
|
159
159
|
};
|
|
160
160
|
export type SelectCommonProps<T extends string> = {
|
|
161
|
-
|
|
161
|
+
options: string[] | SelectOption<T>[];
|
|
162
162
|
size?: Size;
|
|
163
163
|
shape?: Shape;
|
|
164
164
|
placeholder?: string;
|
|
@@ -167,12 +167,12 @@ export type SelectCommonProps<T extends string> = {
|
|
|
167
167
|
export type SelectProps<T extends string> = SelectCommonProps<T> & {
|
|
168
168
|
value?: T;
|
|
169
169
|
onChange?: (value: T) => void;
|
|
170
|
-
|
|
170
|
+
onSelect?: (options: SelectOption<T>) => void;
|
|
171
171
|
};
|
|
172
172
|
export type MultiSelectProps<T extends string> = SelectCommonProps<T> & {
|
|
173
173
|
values?: T[];
|
|
174
174
|
onChange?: (values: T[]) => void;
|
|
175
|
-
|
|
175
|
+
onSelect?: (options: SelectOption<T>[]) => void;
|
|
176
176
|
};
|
|
177
177
|
export type ToastId = {
|
|
178
178
|
id: string;
|