compote-ui 0.21.2 → 0.22.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.
Files changed (33) hide show
  1. package/dist/components/listbox/index.d.ts +11 -0
  2. package/dist/components/listbox/index.js +11 -0
  3. package/dist/components/listbox/listbox-content.svelte +24 -0
  4. package/dist/components/listbox/listbox-content.svelte.d.ts +13 -0
  5. package/dist/components/listbox/listbox-context.d.ts +12 -0
  6. package/dist/components/listbox/listbox-context.js +2 -0
  7. package/dist/components/listbox/listbox-empty.svelte +17 -0
  8. package/dist/components/listbox/listbox-empty.svelte.d.ts +9 -0
  9. package/dist/components/listbox/listbox-input.svelte +28 -0
  10. package/dist/components/listbox/listbox-input.svelte.d.ts +11 -0
  11. package/dist/components/listbox/listbox-item-group-label.svelte +20 -0
  12. package/dist/components/listbox/listbox-item-group-label.svelte.d.ts +9 -0
  13. package/dist/components/listbox/listbox-item-group.svelte +17 -0
  14. package/dist/components/listbox/listbox-item-group.svelte.d.ts +9 -0
  15. package/dist/components/listbox/listbox-item-indicator.svelte +24 -0
  16. package/dist/components/listbox/listbox-item-indicator.svelte.d.ts +9 -0
  17. package/dist/components/listbox/listbox-item-text.svelte +17 -0
  18. package/dist/components/listbox/listbox-item-text.svelte.d.ts +9 -0
  19. package/dist/components/listbox/listbox-item.svelte +24 -0
  20. package/dist/components/listbox/listbox-item.svelte.d.ts +9 -0
  21. package/dist/components/listbox/listbox-label.svelte +17 -0
  22. package/dist/components/listbox/listbox-label.svelte.d.ts +9 -0
  23. package/dist/components/listbox/listbox-root.svelte +79 -0
  24. package/dist/components/listbox/listbox-root.svelte.d.ts +33 -0
  25. package/dist/components/listbox/listbox-value-text.svelte +13 -0
  26. package/dist/components/listbox/listbox-value-text.svelte.d.ts +7 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +1 -1
  29. package/package.json +1 -1
  30. package/dist/components/listbox/listbox.svelte +0 -117
  31. package/dist/components/listbox/listbox.svelte.d.ts +0 -27
  32. package/dist/components/listbox/types.d.ts +0 -11
  33. package/dist/components/listbox/types.js +0 -1
@@ -0,0 +1,11 @@
1
+ export { default as Root } from './listbox-root.svelte';
2
+ export { default as Input } from './listbox-input.svelte';
3
+ export { default as Content } from './listbox-content.svelte';
4
+ export { default as Label } from './listbox-label.svelte';
5
+ export { default as Item } from './listbox-item.svelte';
6
+ export { default as ItemText } from './listbox-item-text.svelte';
7
+ export { default as ItemIndicator } from './listbox-item-indicator.svelte';
8
+ export { default as ItemGroup } from './listbox-item-group.svelte';
9
+ export { default as ItemGroupLabel } from './listbox-item-group-label.svelte';
10
+ export { default as Empty } from './listbox-empty.svelte';
11
+ export { default as ValueText } from './listbox-value-text.svelte';
@@ -0,0 +1,11 @@
1
+ export { default as Root } from './listbox-root.svelte';
2
+ export { default as Input } from './listbox-input.svelte';
3
+ export { default as Content } from './listbox-content.svelte';
4
+ export { default as Label } from './listbox-label.svelte';
5
+ export { default as Item } from './listbox-item.svelte';
6
+ export { default as ItemText } from './listbox-item-text.svelte';
7
+ export { default as ItemIndicator } from './listbox-item-indicator.svelte';
8
+ export { default as ItemGroup } from './listbox-item-group.svelte';
9
+ export { default as ItemGroupLabel } from './listbox-item-group-label.svelte';
10
+ export { default as Empty } from './listbox-empty.svelte';
11
+ export { default as ValueText } from './listbox-value-text.svelte';
@@ -0,0 +1,24 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxContentBaseProps } from '@ark-ui/svelte/listbox';
4
+ import type { Snippet } from 'svelte';
5
+ import type { ListItem } from '../../utils/collections';
6
+ import { cn } from 'tailwind-variants';
7
+ import { getListboxContext } from './listbox-context';
8
+
9
+ type Props = ListboxContentBaseProps & {
10
+ class?: string;
11
+ items?: Snippet<[{ items: ListItem[]; group: [string, ListItem[]][] }]>;
12
+ };
13
+
14
+ let { class: className, items, ...restProps }: Props = $props();
15
+
16
+ const ctx = getListboxContext();
17
+ </script>
18
+
19
+ <Listbox.Content
20
+ {...restProps}
21
+ class={cn('flex min-h-0 w-full flex-1 flex-col overflow-y-auto outline-none', className)}
22
+ >
23
+ {@render items?.({ items: ctx.collection.items, group: ctx.collection.group() })}
24
+ </Listbox.Content>
@@ -0,0 +1,13 @@
1
+ import type { ListboxContentBaseProps } from '@ark-ui/svelte/listbox';
2
+ import type { Snippet } from 'svelte';
3
+ import type { ListItem } from '../../utils/collections';
4
+ type Props = ListboxContentBaseProps & {
5
+ class?: string;
6
+ items?: Snippet<[{
7
+ items: ListItem[];
8
+ group: [string, ListItem[]][];
9
+ }]>;
10
+ };
11
+ declare const ListboxContent: import("svelte").Component<Props, {}, "">;
12
+ type ListboxContent = ReturnType<typeof ListboxContent>;
13
+ export default ListboxContent;
@@ -0,0 +1,12 @@
1
+ import type { ListCollection } from '@ark-ui/svelte/collection';
2
+ import type { ListItem } from '../../utils/collections';
3
+ export declare const getListboxContext: () => {
4
+ readonly collection: ListCollection<ListItem>;
5
+ filter: (text: string) => void;
6
+ }, setListboxContext: (context: {
7
+ readonly collection: ListCollection<ListItem>;
8
+ filter: (text: string) => void;
9
+ }) => {
10
+ readonly collection: ListCollection<ListItem>;
11
+ filter: (text: string) => void;
12
+ };
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'svelte';
2
+ export const [getListboxContext, setListboxContext] = createContext();
@@ -0,0 +1,17 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxEmptyBaseProps } from '@ark-ui/svelte/listbox';
4
+ import type { Snippet } from 'svelte';
5
+ import { cn } from 'tailwind-variants';
6
+
7
+ type Props = ListboxEmptyBaseProps & {
8
+ class?: string;
9
+ children?: Snippet;
10
+ };
11
+
12
+ let { class: className, children, ...restProps }: Props = $props();
13
+ </script>
14
+
15
+ <Listbox.Empty {...restProps} class={cn('py-4 text-center text-sm text-ink-dim', className)}>
16
+ {@render children?.()}
17
+ </Listbox.Empty>
@@ -0,0 +1,9 @@
1
+ import type { ListboxEmptyBaseProps } from '@ark-ui/svelte/listbox';
2
+ import type { Snippet } from 'svelte';
3
+ type Props = ListboxEmptyBaseProps & {
4
+ class?: string;
5
+ children?: Snippet;
6
+ };
7
+ declare const ListboxEmpty: import("svelte").Component<Props, {}, "">;
8
+ type ListboxEmpty = ReturnType<typeof ListboxEmpty>;
9
+ export default ListboxEmpty;
@@ -0,0 +1,28 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxInputBaseProps } from '@ark-ui/svelte/listbox';
4
+ import { cn } from 'tailwind-variants';
5
+ import { getListboxContext } from './listbox-context';
6
+
7
+ type Props = ListboxInputBaseProps & {
8
+ class?: string;
9
+ placeholder?: string;
10
+ oninput?: (event: Event & { currentTarget: HTMLInputElement }) => void;
11
+ };
12
+
13
+ let { class: className, oninput, ...restProps }: Props = $props();
14
+
15
+ const ctx = getListboxContext();
16
+ </script>
17
+
18
+ <Listbox.Input
19
+ {...restProps}
20
+ oninput={(e) => {
21
+ ctx.filter(e.currentTarget.value);
22
+ oninput?.(e);
23
+ }}
24
+ class={cn(
25
+ 'w-full rounded-md border border-surface-3 bg-transparent px-3 py-2 text-sm outline-none placeholder:text-ink-dim focus-visible:border-primary focus-visible:shadow-xs',
26
+ className
27
+ )}
28
+ />
@@ -0,0 +1,11 @@
1
+ import type { ListboxInputBaseProps } from '@ark-ui/svelte/listbox';
2
+ type Props = ListboxInputBaseProps & {
3
+ class?: string;
4
+ placeholder?: string;
5
+ oninput?: (event: Event & {
6
+ currentTarget: HTMLInputElement;
7
+ }) => void;
8
+ };
9
+ declare const ListboxInput: import("svelte").Component<Props, {}, "">;
10
+ type ListboxInput = ReturnType<typeof ListboxInput>;
11
+ export default ListboxInput;
@@ -0,0 +1,20 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxItemGroupLabelBaseProps } from '@ark-ui/svelte/listbox';
4
+ import type { Snippet } from 'svelte';
5
+ import { cn } from 'tailwind-variants';
6
+
7
+ type Props = ListboxItemGroupLabelBaseProps & {
8
+ class?: string;
9
+ children?: Snippet;
10
+ };
11
+
12
+ let { class: className, children, ...restProps }: Props = $props();
13
+ </script>
14
+
15
+ <Listbox.ItemGroupLabel
16
+ {...restProps}
17
+ class={cn('px-2 py-1.5 text-xs font-semibold tracking-wide text-ink-dim uppercase', className)}
18
+ >
19
+ {@render children?.()}
20
+ </Listbox.ItemGroupLabel>
@@ -0,0 +1,9 @@
1
+ import type { ListboxItemGroupLabelBaseProps } from '@ark-ui/svelte/listbox';
2
+ import type { Snippet } from 'svelte';
3
+ type Props = ListboxItemGroupLabelBaseProps & {
4
+ class?: string;
5
+ children?: Snippet;
6
+ };
7
+ declare const ListboxItemGroupLabel: import("svelte").Component<Props, {}, "">;
8
+ type ListboxItemGroupLabel = ReturnType<typeof ListboxItemGroupLabel>;
9
+ export default ListboxItemGroupLabel;
@@ -0,0 +1,17 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxItemGroupBaseProps } from '@ark-ui/svelte/listbox';
4
+ import type { Snippet } from 'svelte';
5
+ import { cn } from 'tailwind-variants';
6
+
7
+ type Props = ListboxItemGroupBaseProps & {
8
+ class?: string;
9
+ children?: Snippet;
10
+ };
11
+
12
+ let { class: className, children, ...restProps }: Props = $props();
13
+ </script>
14
+
15
+ <Listbox.ItemGroup {...restProps} class={cn('flex flex-col', className)}>
16
+ {@render children?.()}
17
+ </Listbox.ItemGroup>
@@ -0,0 +1,9 @@
1
+ import type { ListboxItemGroupBaseProps } from '@ark-ui/svelte/listbox';
2
+ import type { Snippet } from 'svelte';
3
+ type Props = ListboxItemGroupBaseProps & {
4
+ class?: string;
5
+ children?: Snippet;
6
+ };
7
+ declare const ListboxItemGroup: import("svelte").Component<Props, {}, "">;
8
+ type ListboxItemGroup = ReturnType<typeof ListboxItemGroup>;
9
+ export default ListboxItemGroup;
@@ -0,0 +1,24 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxItemIndicatorBaseProps } from '@ark-ui/svelte/listbox';
4
+ import type { Snippet } from 'svelte';
5
+ import { cn } from 'tailwind-variants';
6
+ import { PhCheck } from '../../icons';
7
+
8
+ type Props = ListboxItemIndicatorBaseProps & {
9
+ class?: string;
10
+ children?: Snippet;
11
+ };
12
+
13
+ let { class: className, children, ...restProps }: Props = $props();
14
+ </script>
15
+
16
+ <Listbox.ItemIndicator
17
+ {...restProps}
18
+ class={cn(
19
+ 'flex h-3.5 w-3.5 shrink-0 items-center justify-center text-primary data-[state=unchecked]:hidden',
20
+ className
21
+ )}
22
+ >
23
+ {#if children}{@render children()}{:else}<PhCheck />{/if}
24
+ </Listbox.ItemIndicator>
@@ -0,0 +1,9 @@
1
+ import type { ListboxItemIndicatorBaseProps } from '@ark-ui/svelte/listbox';
2
+ import type { Snippet } from 'svelte';
3
+ type Props = ListboxItemIndicatorBaseProps & {
4
+ class?: string;
5
+ children?: Snippet;
6
+ };
7
+ declare const ListboxItemIndicator: import("svelte").Component<Props, {}, "">;
8
+ type ListboxItemIndicator = ReturnType<typeof ListboxItemIndicator>;
9
+ export default ListboxItemIndicator;
@@ -0,0 +1,17 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxItemTextBaseProps } from '@ark-ui/svelte/listbox';
4
+ import type { Snippet } from 'svelte';
5
+ import { cn } from 'tailwind-variants';
6
+
7
+ type Props = ListboxItemTextBaseProps & {
8
+ class?: string;
9
+ children?: Snippet;
10
+ };
11
+
12
+ let { class: className, children, ...restProps }: Props = $props();
13
+ </script>
14
+
15
+ <Listbox.ItemText {...restProps} class={cn('flex-1 truncate', className)}>
16
+ {@render children?.()}
17
+ </Listbox.ItemText>
@@ -0,0 +1,9 @@
1
+ import type { ListboxItemTextBaseProps } from '@ark-ui/svelte/listbox';
2
+ import type { Snippet } from 'svelte';
3
+ type Props = ListboxItemTextBaseProps & {
4
+ class?: string;
5
+ children?: Snippet;
6
+ };
7
+ declare const ListboxItemText: import("svelte").Component<Props, {}, "">;
8
+ type ListboxItemText = ReturnType<typeof ListboxItemText>;
9
+ export default ListboxItemText;
@@ -0,0 +1,24 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxItemBaseProps } from '@ark-ui/svelte/listbox';
4
+ import type { Snippet } from 'svelte';
5
+ import { cn } from 'tailwind-variants';
6
+
7
+ type Props = ListboxItemBaseProps & {
8
+ class?: string;
9
+ children?: Snippet;
10
+ };
11
+
12
+ let { class: className, item, children, ...restProps }: Props = $props();
13
+ </script>
14
+
15
+ <Listbox.Item
16
+ {item}
17
+ {...restProps}
18
+ class={cn(
19
+ 'flex min-h-8 cursor-pointer items-center justify-between gap-2 rounded-xs px-2 text-sm transition-colors outline-none select-none hover:bg-surface-2 data-disabled:opacity-50 data-highlighted:bg-surface-2 data-[state=checked]:text-primary',
20
+ className
21
+ )}
22
+ >
23
+ {@render children?.()}
24
+ </Listbox.Item>
@@ -0,0 +1,9 @@
1
+ import type { ListboxItemBaseProps } from '@ark-ui/svelte/listbox';
2
+ import type { Snippet } from 'svelte';
3
+ type Props = ListboxItemBaseProps & {
4
+ class?: string;
5
+ children?: Snippet;
6
+ };
7
+ declare const ListboxItem: import("svelte").Component<Props, {}, "">;
8
+ type ListboxItem = ReturnType<typeof ListboxItem>;
9
+ export default ListboxItem;
@@ -0,0 +1,17 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxLabelBaseProps } from '@ark-ui/svelte/listbox';
4
+ import type { Snippet } from 'svelte';
5
+ import { cn } from 'tailwind-variants';
6
+
7
+ type Props = ListboxLabelBaseProps & {
8
+ class?: string;
9
+ children?: Snippet;
10
+ };
11
+
12
+ let { class: className, children, ...restProps }: Props = $props();
13
+ </script>
14
+
15
+ <Listbox.Label {...restProps} class={cn('text-sm font-medium text-ink', className)}>
16
+ {@render children?.()}
17
+ </Listbox.Label>
@@ -0,0 +1,9 @@
1
+ import type { ListboxLabelBaseProps } from '@ark-ui/svelte/listbox';
2
+ import type { Snippet } from 'svelte';
3
+ type Props = ListboxLabelBaseProps & {
4
+ class?: string;
5
+ children?: Snippet;
6
+ };
7
+ declare const ListboxLabel: import("svelte").Component<Props, {}, "">;
8
+ type ListboxLabel = ReturnType<typeof ListboxLabel>;
9
+ export default ListboxLabel;
@@ -0,0 +1,79 @@
1
+ <script lang="ts" generics="T extends string | number = string">
2
+ import { Listbox, createListCollection } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxRootBaseProps } from '@ark-ui/svelte/listbox';
4
+ import { useFilter } from '@ark-ui/svelte/locale';
5
+ import type { Snippet } from 'svelte';
6
+ import type { ListCollection } from '@ark-ui/svelte/collection';
7
+ import type { ListItem } from '../../utils/collections';
8
+ import { cn } from 'tailwind-variants';
9
+ import { setListboxContext } from './listbox-context';
10
+
11
+ type Props = Omit<ListboxRootBaseProps<ListItem<T>>, 'collection' | 'value'> & {
12
+ items: ListItem<T>[];
13
+ value?: T[];
14
+ name?: string;
15
+ class?: string;
16
+ children?: Snippet;
17
+ };
18
+
19
+ let {
20
+ items,
21
+ value = $bindable(),
22
+ name,
23
+ class: className,
24
+ children,
25
+ onValueChange,
26
+ ...restProps
27
+ }: Props = $props();
28
+
29
+ const filters = useFilter({ sensitivity: 'base' });
30
+ let filterText = $state('');
31
+
32
+ const hasGroups = $derived(items.some((i) => i.group));
33
+
34
+ const baseCollection = $derived(
35
+ createListCollection({
36
+ items,
37
+ itemToValue: (item) => item.value.toString(),
38
+ itemToString: (item) => item.label,
39
+ isItemDisabled: (item) => item.disabled === true,
40
+ ...(hasGroups ? { groupBy: (item: ListItem<T>) => item.group ?? '' } : {})
41
+ })
42
+ );
43
+
44
+ const collection = $derived(
45
+ filterText
46
+ ? baseCollection.filter((itemString) => filters().contains(itemString, filterText))
47
+ : baseCollection
48
+ );
49
+
50
+ const stringValue = $derived(value?.map(String) ?? []);
51
+
52
+ setListboxContext({
53
+ get collection() {
54
+ return collection as unknown as ListCollection<ListItem>;
55
+ },
56
+ filter: (text) => {
57
+ filterText = text;
58
+ }
59
+ });
60
+ </script>
61
+
62
+ <Listbox.Root
63
+ {collection}
64
+ value={stringValue}
65
+ onValueChange={(details) => {
66
+ value = details.value as unknown as T[];
67
+ onValueChange?.(details);
68
+ }}
69
+ {...restProps}
70
+ class={cn('flex h-full w-full flex-col gap-1.5 overflow-hidden', className)}
71
+ >
72
+ {@render children?.()}
73
+ </Listbox.Root>
74
+
75
+ {#if name}
76
+ {#each value ?? [] as v, i (v)}
77
+ <input type="hidden" name="{name}[{i}]" value={v ?? ''} />
78
+ {/each}
79
+ {/if}
@@ -0,0 +1,33 @@
1
+ import { Listbox } from '@ark-ui/svelte/listbox';
2
+ import type { Snippet } from 'svelte';
3
+ import type { ListItem } from '../../utils/collections';
4
+ declare function $$render<T extends string | number = string>(): {
5
+ props: Omit<Listbox.RootBaseProps<ListItem<T>>, "value" | "collection"> & {
6
+ items: ListItem<T>[];
7
+ value?: T[];
8
+ name?: string;
9
+ class?: string;
10
+ children?: Snippet;
11
+ };
12
+ exports: {};
13
+ bindings: "value";
14
+ slots: {};
15
+ events: {};
16
+ };
17
+ declare class __sveltets_Render<T extends string | number = string> {
18
+ props(): ReturnType<typeof $$render<T>>['props'];
19
+ events(): ReturnType<typeof $$render<T>>['events'];
20
+ slots(): ReturnType<typeof $$render<T>>['slots'];
21
+ bindings(): "value";
22
+ exports(): {};
23
+ }
24
+ interface $$IsomorphicComponent {
25
+ new <T extends string | number = string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
26
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
27
+ } & ReturnType<__sveltets_Render<T>['exports']>;
28
+ <T extends string | number = string>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
29
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
30
+ }
31
+ declare const ListboxRoot: $$IsomorphicComponent;
32
+ type ListboxRoot<T extends string | number = string> = InstanceType<typeof ListboxRoot<T>>;
33
+ export default ListboxRoot;
@@ -0,0 +1,13 @@
1
+ <script lang="ts">
2
+ import { Listbox } from '@ark-ui/svelte/listbox';
3
+ import type { ListboxValueTextBaseProps } from '@ark-ui/svelte/listbox';
4
+ import { cn } from 'tailwind-variants';
5
+
6
+ type Props = ListboxValueTextBaseProps & {
7
+ class?: string;
8
+ };
9
+
10
+ let { class: className, ...restProps }: Props = $props();
11
+ </script>
12
+
13
+ <Listbox.ValueText {...restProps} class={cn('text-sm text-ink', className)} />
@@ -0,0 +1,7 @@
1
+ import type { ListboxValueTextBaseProps } from '@ark-ui/svelte/listbox';
2
+ type Props = ListboxValueTextBaseProps & {
3
+ class?: string;
4
+ };
5
+ declare const ListboxValueText: import("svelte").Component<Props, {}, "">;
6
+ type ListboxValueText = ReturnType<typeof ListboxValueText>;
7
+ export default ListboxValueText;
package/dist/index.d.ts CHANGED
@@ -19,7 +19,7 @@ export { default as ImageCropper } from './components/image-cropper/image-croppe
19
19
  export type { ImageCropperProps, ImageCropperCropData } from './components/image-cropper/types';
20
20
  export { default as ImageCropDialog } from './components/image-crop-dialog/image-crop-dialog.svelte';
21
21
  export type { ImageCropDialogProps } from './components/image-crop-dialog/types';
22
- export { default as Listbox } from './components/listbox/listbox.svelte';
22
+ export * as Listbox from './components/listbox';
23
23
  export { default as NumberInput } from './components/number-input/number-input.svelte';
24
24
  export type { NumberInputProps } from './components/number-input/types';
25
25
  export { default as Select } from './components/select/select.svelte';
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ export { default as FileUploadDropzone } from './components/file-upload/file-upl
15
15
  export { default as FileUpload } from './components/file-upload/file-upload.svelte';
16
16
  export { default as ImageCropper } from './components/image-cropper/image-cropper.svelte';
17
17
  export { default as ImageCropDialog } from './components/image-crop-dialog/image-crop-dialog.svelte';
18
- export { default as Listbox } from './components/listbox/listbox.svelte';
18
+ export * as Listbox from './components/listbox';
19
19
  export { default as NumberInput } from './components/number-input/number-input.svelte';
20
20
  export { default as Select } from './components/select/select.svelte';
21
21
  export { default as Splitter } from './components/splitter/splitter.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compote-ui",
3
- "version": "0.21.2",
3
+ "version": "0.22.0",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -1,117 +0,0 @@
1
- <script module>
2
- // eslint-disable-next-line no-import-assign
3
- export type { ListboxProps } from './types';
4
- </script>
5
-
6
- <script lang="ts" generics="T extends number | string = number | string">
7
- import { Listbox, createListCollection } from '@ark-ui/svelte/listbox';
8
- import { useFilter } from '@ark-ui/svelte/locale';
9
- import type { ListboxProps } from './types';
10
- import type { ListItem } from '../../utils/collections';
11
- import { cn } from 'tailwind-variants';
12
- import { PhCheck } from '../../icons';
13
-
14
- type Props = ListboxProps<T>;
15
-
16
- let {
17
- value = $bindable(),
18
- items,
19
- label,
20
- name,
21
- onValueChange,
22
- filterable = false,
23
- filterPlaceholder = 'Search...',
24
- class: className,
25
- ...restProps
26
- }: Props = $props();
27
-
28
- const filters = useFilter({ sensitivity: 'base' });
29
- let filterText = $state('');
30
- const hasGroups = $derived(items.some((i) => i.group));
31
-
32
- const baseCollection = $derived(
33
- createListCollection({
34
- items,
35
- itemToValue: (item) => item.value.toString(),
36
- isItemDisabled: (item) => item.disabled === true,
37
- ...(hasGroups ? { groupBy: (item: ListItem<T>) => item.group ?? '' } : {})
38
- })
39
- );
40
-
41
- const collection = $derived(
42
- filterable && filterText
43
- ? baseCollection.filter((itemString) => filters().contains(itemString, filterText))
44
- : baseCollection
45
- );
46
-
47
- const stringValue = $derived(value?.map(String) ?? []);
48
- </script>
49
-
50
- <Listbox.Root
51
- value={stringValue}
52
- {collection}
53
- onValueChange={(details) => {
54
- value = details.value as unknown as T[];
55
- onValueChange?.(details);
56
- }}
57
- {...restProps}
58
- class={cn('flex h-full w-full flex-col gap-1.5 overflow-hidden', className)}
59
- >
60
- {#if label}
61
- <Listbox.Label>{label}</Listbox.Label>
62
- {/if}
63
- {#if filterable}
64
- <Listbox.Input
65
- placeholder={filterPlaceholder}
66
- oninput={(e) => (filterText = e.currentTarget.value)}
67
- class="h-8 w-full rounded-xs border border-surface-3 bg-transparent px-2.5 text-sm outline-none placeholder:text-ink-dim focus-visible:ring-1 focus-visible:ring-ring"
68
- />
69
- {/if}
70
- <Listbox.Content class="flex min-h-0 w-full flex-1 flex-col overflow-y-auto outline-none">
71
- {#if hasGroups}
72
- {#each collection.group() as [type, group] (type)}
73
- <Listbox.ItemGroup class="flex flex-col">
74
- <Listbox.ItemGroupLabel
75
- class="px-2 py-1.5 text-xs font-semibold tracking-wide text-ink-dim uppercase"
76
- >
77
- {type}
78
- </Listbox.ItemGroupLabel>
79
- {#each group as item (item.value)}
80
- <Listbox.Item
81
- {item}
82
- class="flex min-h-8 cursor-pointer items-center justify-between gap-2 rounded-xs px-2 text-sm transition-colors outline-none select-none hover:bg-surface-2 data-disabled:opacity-50 data-highlighted:bg-surface-2 data-[state=checked]:text-primary"
83
- >
84
- <Listbox.ItemText class="flex-1 truncate">{item.label}</Listbox.ItemText>
85
- <Listbox.ItemIndicator
86
- class="flex h-3.5 w-3.5 shrink-0 items-center justify-center text-primary data-[state=unchecked]:hidden"
87
- >
88
- <PhCheck />
89
- </Listbox.ItemIndicator>
90
- </Listbox.Item>
91
- {/each}
92
- </Listbox.ItemGroup>
93
- {/each}
94
- {:else}
95
- {#each collection.items as item (item.value)}
96
- <Listbox.Item
97
- {item}
98
- class="flex min-h-8 cursor-pointer items-center justify-between gap-2 rounded-xs px-2 text-sm transition-colors outline-none select-none hover:bg-surface-2 data-disabled:opacity-50 data-highlighted:bg-surface-2 data-[state=checked]:text-primary"
99
- >
100
- <Listbox.ItemText class="flex-1 truncate">{item.label}</Listbox.ItemText>
101
- <Listbox.ItemIndicator
102
- class="flex h-3.5 w-3.5 shrink-0 items-center justify-center text-primary data-[state=unchecked]:hidden"
103
- >
104
- <PhCheck />
105
- </Listbox.ItemIndicator>
106
- </Listbox.Item>
107
- {/each}
108
- {/if}
109
- <Listbox.Empty class="py-4 text-center text-sm text-ink-dim">No results found</Listbox.Empty>
110
- </Listbox.Content>
111
- </Listbox.Root>
112
-
113
- {#if name}
114
- {#each value ?? [] as v, i (v)}
115
- <input type="hidden" name="{name}[{i}]" value={v ?? ''} />
116
- {/each}
117
- {/if}
@@ -1,27 +0,0 @@
1
- export type { ListboxProps } from './types';
2
- import { Listbox } from '@ark-ui/svelte/listbox';
3
- import type { ListboxProps } from './types';
4
- declare function $$render<T extends number | string = number | string>(): {
5
- props: ListboxProps<T>;
6
- exports: {};
7
- bindings: "value";
8
- slots: {};
9
- events: {};
10
- };
11
- declare class __sveltets_Render<T extends number | string = number | string> {
12
- props(): ReturnType<typeof $$render<T>>['props'];
13
- events(): ReturnType<typeof $$render<T>>['events'];
14
- slots(): ReturnType<typeof $$render<T>>['slots'];
15
- bindings(): "value";
16
- exports(): {};
17
- }
18
- interface $$IsomorphicComponent {
19
- new <T extends number | string = number | string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
20
- $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
21
- } & ReturnType<__sveltets_Render<T>['exports']>;
22
- <T extends number | string = number | string>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
23
- z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
24
- }
25
- declare const Listbox: $$IsomorphicComponent;
26
- type Listbox<T extends number | string = number | string> = InstanceType<typeof Listbox<T>>;
27
- export default Listbox;
@@ -1,11 +0,0 @@
1
- import type { ListboxRootBaseProps } from '@ark-ui/svelte/listbox';
2
- import type { ListItem } from '../../utils/collections';
3
- export interface ListboxProps<T extends number | string = number | string> extends Omit<ListboxRootBaseProps<ListItem<T>>, 'collection' | 'value'> {
4
- items: ListItem<T>[];
5
- value?: T[];
6
- label?: string;
7
- name?: string;
8
- filterable?: boolean;
9
- filterPlaceholder?: string;
10
- class?: string;
11
- }
@@ -1 +0,0 @@
1
- export {};