@casinogate/ui 1.6.2 → 1.8.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.
- package/dist/assets/css/root.css +236 -32
- package/dist/assets/css/theme.css +6 -3
- package/dist/components/breadcrumb/breadcrumb.svelte +2 -2
- package/dist/components/breadcrumb/styles.d.ts +21 -21
- package/dist/components/breadcrumb/types.d.ts +2 -2
- package/dist/components/button/button.component.svelte +2 -1
- package/dist/components/button/styles.d.ts +15 -0
- package/dist/components/button/styles.js +10 -5
- package/dist/components/button-group/components/button-group.root.svelte +1 -3
- package/dist/components/collapsible/components/collapsaible.svelte.js +3 -3
- package/dist/components/collapsible/styles.d.ts +8 -8
- package/dist/components/data-table/data-table.svelte +1 -1
- package/dist/components/data-table/utils/pagination-state.svelte.js +3 -3
- package/dist/components/data-table/utils/resize-state.svelte.js +3 -3
- package/dist/components/data-table/utils/row-selection-state.svelte.js +3 -3
- package/dist/components/dialog/components/dialog.overlay.svelte +1 -7
- package/dist/components/dropdown/components/dropdown.content.svelte +39 -0
- package/dist/components/dropdown/components/dropdown.content.svelte.d.ts +4 -0
- package/dist/components/dropdown/components/dropdown.group-heading.svelte +16 -0
- package/dist/components/dropdown/components/dropdown.group-heading.svelte.d.ts +4 -0
- package/dist/components/dropdown/components/dropdown.group.svelte +16 -0
- package/dist/components/dropdown/components/dropdown.group.svelte.d.ts +4 -0
- package/dist/components/dropdown/components/dropdown.item.svelte +22 -0
- package/dist/components/dropdown/components/dropdown.item.svelte.d.ts +4 -0
- package/dist/components/dropdown/components/dropdown.portal.svelte +10 -0
- package/dist/components/dropdown/components/dropdown.portal.svelte.d.ts +3 -0
- package/dist/components/dropdown/components/dropdown.root.svelte +10 -0
- package/dist/components/dropdown/components/dropdown.root.svelte.d.ts +3 -0
- package/dist/components/dropdown/components/dropdown.separator.svelte +22 -0
- package/dist/components/dropdown/components/dropdown.separator.svelte.d.ts +4 -0
- package/dist/components/dropdown/components/dropdown.sub-content.svelte +16 -0
- package/dist/components/dropdown/components/dropdown.sub-content.svelte.d.ts +4 -0
- package/dist/components/dropdown/components/dropdown.sub-trigger.svelte +21 -0
- package/dist/components/dropdown/components/dropdown.sub-trigger.svelte.d.ts +4 -0
- package/dist/components/dropdown/components/dropdown.sub.svelte +8 -0
- package/dist/components/dropdown/components/dropdown.sub.svelte.d.ts +3 -0
- package/dist/components/dropdown/components/dropdown.trigger.svelte +16 -0
- package/dist/components/dropdown/components/dropdown.trigger.svelte.d.ts +4 -0
- package/dist/components/dropdown/dropdown.svelte +196 -0
- package/dist/components/dropdown/dropdown.svelte.d.ts +7 -0
- package/dist/components/dropdown/exports-primitive.d.ts +11 -0
- package/dist/components/dropdown/exports-primitive.js +11 -0
- package/dist/components/dropdown/exports.d.ts +1 -0
- package/dist/components/dropdown/exports.js +1 -0
- package/dist/components/dropdown/index.d.ts +3 -0
- package/dist/components/dropdown/index.js +2 -0
- package/dist/components/dropdown/styles.d.ts +496 -0
- package/dist/components/dropdown/styles.js +111 -0
- package/dist/components/dropdown/types.d.ts +86 -0
- package/dist/components/dropdown/types.js +1 -0
- package/dist/components/field/field.svelte +0 -1
- package/dist/components/field/styles.d.ts +15 -15
- package/dist/components/popover/components/popover.content.svelte +7 -2
- package/dist/components/popover/components/popover.content.svelte.d.ts +2 -2
- package/dist/components/popover/components/popover.root.svelte +0 -6
- package/dist/components/popover/components/popover.trigger.svelte +6 -2
- package/dist/components/popover/components/popover.trigger.svelte.d.ts +2 -2
- package/dist/components/popover/styles.d.ts +60 -52
- package/dist/components/popover/styles.js +37 -14
- package/dist/components/popover/types.d.ts +4 -4
- package/dist/components/segment/components/segment.root.svelte +2 -1
- package/dist/components/segment/components/segmet.svelte.d.ts +0 -1
- package/dist/components/segment/components/segmet.svelte.js +0 -1
- package/dist/components/segment/styles.d.ts +18 -0
- package/dist/components/segment/styles.js +7 -1
- package/dist/components/select/components/select.content.svelte +2 -4
- package/dist/components/select/components/select.group-heading.svelte +2 -4
- package/dist/components/select/components/select.group-heading.svelte.d.ts +2 -2
- package/dist/components/select/components/select.group.svelte.d.ts +2 -2
- package/dist/components/select/components/select.item.svelte +5 -13
- package/dist/components/select/components/select.item.svelte.d.ts +2 -2
- package/dist/components/select/components/select.root.svelte +1 -17
- package/dist/components/select/components/select.root.svelte.d.ts +1 -2
- package/dist/components/select/components/select.trigger.svelte +17 -5
- package/dist/components/select/components/select.viewport.svelte +2 -4
- package/dist/components/select/components/select.viewport.svelte.d.ts +2 -2
- package/dist/components/select/exports.d.ts +1 -1
- package/dist/components/select/exports.js +1 -1
- package/dist/components/select/select.async.svelte +146 -83
- package/dist/components/select/select.async.svelte.d.ts +1 -1
- package/dist/components/select/select.svelte +107 -62
- package/dist/components/select/select.svelte.d.ts +4 -2
- package/dist/components/select/styles.d.ts +48 -139
- package/dist/components/select/styles.js +74 -101
- package/dist/components/select/types.d.ts +69 -29
- package/dist/components/select/types.js +0 -1
- package/dist/components/select/utils/get-item-key.d.ts +1 -1
- package/dist/components/separator/separator.svelte +4 -5
- package/dist/components/separator/separator.svelte.d.ts +2 -2
- package/dist/components/separator/styles.d.ts +18 -0
- package/dist/components/separator/styles.js +10 -0
- package/dist/components/separator/types.d.ts +2 -1
- package/dist/components/spinner/spinner.svelte +1 -6
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +1 -0
- package/dist/internal/lib/collection/grid-collection.d.ts +3 -0
- package/dist/internal/lib/collection/grid-collection.js +2 -0
- package/dist/internal/lib/collection/index.d.ts +5 -0
- package/dist/internal/lib/collection/index.js +5 -0
- package/dist/internal/lib/collection/list-collection.d.ts +3 -0
- package/dist/internal/lib/collection/list-collection.js +2 -0
- package/dist/internal/lib/collection/tree-collection.d.ts +4 -0
- package/dist/internal/lib/collection/tree-collection.js +3 -0
- package/dist/internal/lib/collection/use-list-collection.svelte.d.ts +88 -0
- package/dist/internal/lib/collection/use-list-collection.svelte.js +94 -0
- package/dist/internal/lib/collection/use-list-selection.svelte.d.ts +92 -0
- package/dist/internal/lib/collection/use-list-selection.svelte.js +80 -0
- package/dist/internal/lib/index.d.ts +1 -0
- package/dist/internal/lib/index.js +1 -0
- package/dist/internal/utils/equal.d.ts +3 -0
- package/dist/internal/utils/equal.js +56 -0
- package/dist/internal/utils/functions.d.ts +2 -0
- package/dist/internal/utils/functions.js +4 -0
- package/dist/internal/utils/guard.d.ts +5 -0
- package/dist/internal/utils/guard.js +5 -0
- package/dist/internal/utils/tailwindcss.d.ts +3 -2
- package/dist/internal/utils/tailwindcss.js +25 -5
- package/package.json +6 -4
- package/dist/components/app-shell/app-shell.stories.svelte +0 -107
- package/dist/components/app-shell/app-shell.stories.svelte.d.ts +0 -18
- package/dist/components/badge/badge.stories.svelte +0 -81
- package/dist/components/badge/badge.stories.svelte.d.ts +0 -19
- package/dist/components/breadcrumb/breadcrumb.stories.svelte +0 -67
- package/dist/components/breadcrumb/breadcrumb.stories.svelte.d.ts +0 -4
- package/dist/components/button/button.stories.svelte +0 -106
- package/dist/components/button/button.stories.svelte.d.ts +0 -19
- package/dist/components/button-group/button-group.stories.svelte +0 -59
- package/dist/components/button-group/button-group.stories.svelte.d.ts +0 -18
- package/dist/components/checkbox/checkbox.stories.svelte +0 -52
- package/dist/components/checkbox/checkbox.stories.svelte.d.ts +0 -18
- package/dist/components/collapsible/collapsible.stories.svelte +0 -69
- package/dist/components/collapsible/collapsible.stories.svelte.d.ts +0 -18
- package/dist/components/data-table/data-table.stories.svelte +0 -327
- package/dist/components/data-table/data-table.stories.svelte.d.ts +0 -4
- package/dist/components/dialog/dialog.stories.svelte +0 -102
- package/dist/components/dialog/dialog.stories.svelte.d.ts +0 -3
- package/dist/components/field/field.stories.svelte +0 -56
- package/dist/components/field/field.stories.svelte.d.ts +0 -19
- package/dist/components/input/input.stories.svelte +0 -41
- package/dist/components/input/input.stories.svelte.d.ts +0 -19
- package/dist/components/navigation/navigation.stories.svelte +0 -99
- package/dist/components/navigation/navigation.stories.svelte.d.ts +0 -19
- package/dist/components/pagination/pagination.stories.svelte +0 -69
- package/dist/components/pagination/pagination.stories.svelte.d.ts +0 -19
- package/dist/components/popover/popover.stories.svelte +0 -135
- package/dist/components/popover/popover.stories.svelte.d.ts +0 -4
- package/dist/components/segment/segment.stories.svelte +0 -57
- package/dist/components/segment/segment.stories.svelte.d.ts +0 -19
- package/dist/components/select/select.stories.svelte +0 -263
- package/dist/components/select/select.stories.svelte.d.ts +0 -4
- package/dist/components/separator/separator.stories.svelte +0 -44
- package/dist/components/separator/separator.stories.svelte.d.ts +0 -19
- package/dist/components/skeleton/skeleton.stories.svelte +0 -129
- package/dist/components/skeleton/skeleton.stories.svelte.d.ts +0 -19
- package/dist/components/spinner/spinner.stories.svelte +0 -29
- package/dist/components/spinner/spinner.stories.svelte.d.ts +0 -19
- package/dist/components/switch/switch.stories.svelte +0 -55
- package/dist/components/switch/switch.stories.svelte.d.ts +0 -19
- package/dist/components/textarea/textarea.stories.svelte +0 -36
- package/dist/components/textarea/textarea.stories.svelte.d.ts +0 -19
- package/dist/components/toast/toast.stories.svelte +0 -96
- package/dist/components/toast/toast.stories.svelte.d.ts +0 -19
- package/dist/internal/utils/arrays.d.ts +0 -1
- package/dist/internal/utils/arrays.js +0 -30
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type CollectionItem, type CollectionOptions, ListCollection } from '@zag-js/collection';
|
|
2
|
+
export declare const createListCollection: <T extends CollectionItem>(options: CollectionOptions<T>) => ListCollection<T>;
|
|
3
|
+
export type { CollectionItem, CollectionOptions, ListCollection };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FilePathTreeNode, TreeCollection, type TreeCollectionOptions, type TreeNode } from '@zag-js/collection';
|
|
2
|
+
export type { FilePathTreeNode, FlatTreeNode, TreeCollection, TreeCollectionOptions, TreeNode, } from '@zag-js/collection';
|
|
3
|
+
export declare const createTreeCollection: <T extends TreeNode>(options: TreeCollectionOptions<T>) => TreeCollection<T>;
|
|
4
|
+
export declare const createFileTreeCollection: (paths: string[]) => TreeCollection<FilePathTreeNode>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { type MaybeFunction } from '../../utils/functions.js';
|
|
2
|
+
import { type CollectionOptions, type ListCollection } from './list-collection.js';
|
|
3
|
+
export interface UseListCollectionProps<T> extends Omit<CollectionOptions<T>, 'items'> {
|
|
4
|
+
/**
|
|
5
|
+
* The initial items to display in the collection.
|
|
6
|
+
*/
|
|
7
|
+
initialItems: T[] | readonly T[];
|
|
8
|
+
/**
|
|
9
|
+
* The filter function to use to filter the items.
|
|
10
|
+
*/
|
|
11
|
+
filter?: (itemText: string, filterText: string, item: T) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The maximum number of items to display in the collection.
|
|
14
|
+
* Useful for performance when you have a large number of items.
|
|
15
|
+
*/
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function useListCollection<T>(props: MaybeFunction<UseListCollectionProps<T>>): UseListCollectionReturn<T>;
|
|
19
|
+
export interface UseListCollectionReturn<T> {
|
|
20
|
+
/**
|
|
21
|
+
* The collection of items.
|
|
22
|
+
*/
|
|
23
|
+
collection: () => ListCollection<T>;
|
|
24
|
+
/**
|
|
25
|
+
* The function to filter the items.
|
|
26
|
+
*/
|
|
27
|
+
filter: (inputValue: string) => void;
|
|
28
|
+
/**
|
|
29
|
+
* The function to set the items.
|
|
30
|
+
*/
|
|
31
|
+
set: (items: T[]) => void;
|
|
32
|
+
/**
|
|
33
|
+
* The function to reset the items.
|
|
34
|
+
*/
|
|
35
|
+
reset: () => void;
|
|
36
|
+
/**
|
|
37
|
+
* The function to clear the items.
|
|
38
|
+
*/
|
|
39
|
+
clear: () => void;
|
|
40
|
+
/**
|
|
41
|
+
* The function to insert items at a specific index.
|
|
42
|
+
*/
|
|
43
|
+
insert: (index: number, ...items: T[]) => void;
|
|
44
|
+
/**
|
|
45
|
+
* The function to insert items before a specific value.
|
|
46
|
+
*/
|
|
47
|
+
insertBefore: (value: string, ...items: T[]) => void;
|
|
48
|
+
/**
|
|
49
|
+
* The function to insert items after a specific value.
|
|
50
|
+
*/
|
|
51
|
+
insertAfter: (value: string, ...items: T[]) => void;
|
|
52
|
+
/**
|
|
53
|
+
* The function to remove items.
|
|
54
|
+
*/
|
|
55
|
+
remove: (...itemOrValues: Array<T | string>) => void;
|
|
56
|
+
/**
|
|
57
|
+
* The function to move an item to a specific index.
|
|
58
|
+
*/
|
|
59
|
+
move: (value: string, to: number) => void;
|
|
60
|
+
/**
|
|
61
|
+
* The function to move an item before a specific value.
|
|
62
|
+
*/
|
|
63
|
+
moveBefore: (value: string, ...values: string[]) => void;
|
|
64
|
+
/**
|
|
65
|
+
* The function to move an item after a specific value.
|
|
66
|
+
*/
|
|
67
|
+
moveAfter: (value: string, ...values: string[]) => void;
|
|
68
|
+
/**
|
|
69
|
+
* The function to reorder items.
|
|
70
|
+
*/
|
|
71
|
+
reorder: (from: number, to: number) => void;
|
|
72
|
+
/**
|
|
73
|
+
* The function to append items.
|
|
74
|
+
*/
|
|
75
|
+
append: (...items: T[]) => void;
|
|
76
|
+
/**
|
|
77
|
+
* The function to upsert an item.
|
|
78
|
+
*/
|
|
79
|
+
upsert: (value: string, item: T, mode?: 'append' | 'prepend') => void;
|
|
80
|
+
/**
|
|
81
|
+
* The function to prepend items.
|
|
82
|
+
*/
|
|
83
|
+
prepend: (...items: T[]) => void;
|
|
84
|
+
/**
|
|
85
|
+
* The function to update an item.
|
|
86
|
+
*/
|
|
87
|
+
update: (value: string, item: T) => void;
|
|
88
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { untrack } from 'svelte';
|
|
2
|
+
import { runIfFn } from '../../utils/functions.js';
|
|
3
|
+
import { createListCollection } from './list-collection.js';
|
|
4
|
+
export function useListCollection(props) {
|
|
5
|
+
const [localProps, collectionOptions] = $derived.by(() => {
|
|
6
|
+
const { initialItems = [], filter, limit, ...collectionOptions } = runIfFn(props);
|
|
7
|
+
return [{ initialItems, filter, limit }, collectionOptions];
|
|
8
|
+
});
|
|
9
|
+
let items = $state(untrack(() => localProps.initialItems));
|
|
10
|
+
let filterText = $state('');
|
|
11
|
+
const setItems = (newItems) => {
|
|
12
|
+
items = newItems;
|
|
13
|
+
filterText = '';
|
|
14
|
+
};
|
|
15
|
+
const create = (itemsToCreate) => {
|
|
16
|
+
return createListCollection({ ...collectionOptions, items: itemsToCreate });
|
|
17
|
+
};
|
|
18
|
+
const collection = $derived.by(() => {
|
|
19
|
+
let activeItems = items;
|
|
20
|
+
// Apply filter if we have filter text and a filter function
|
|
21
|
+
const filter = localProps.filter;
|
|
22
|
+
if (filterText && filter) {
|
|
23
|
+
activeItems = create(items).filter((itemString, _index, item) => filter(itemString, filterText, item)).items;
|
|
24
|
+
}
|
|
25
|
+
// Apply limit
|
|
26
|
+
const limitedItems = localProps.limit == null ? activeItems : activeItems.slice(0, localProps.limit);
|
|
27
|
+
return createListCollection({ ...collectionOptions, items: limitedItems });
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
collection() {
|
|
31
|
+
return collection;
|
|
32
|
+
},
|
|
33
|
+
filter: (inputValue = '') => {
|
|
34
|
+
filterText = inputValue;
|
|
35
|
+
},
|
|
36
|
+
set: (newItems) => {
|
|
37
|
+
setItems(newItems);
|
|
38
|
+
},
|
|
39
|
+
reset: () => {
|
|
40
|
+
setItems(localProps.initialItems);
|
|
41
|
+
},
|
|
42
|
+
clear: () => {
|
|
43
|
+
setItems([]);
|
|
44
|
+
},
|
|
45
|
+
insert: (index, ...itemsToInsert) => {
|
|
46
|
+
const newItems = create(items).insert(index, ...itemsToInsert).items;
|
|
47
|
+
setItems(newItems);
|
|
48
|
+
},
|
|
49
|
+
insertBefore: (value, ...itemsToInsert) => {
|
|
50
|
+
const newItems = create(items).insertBefore(value, ...itemsToInsert).items;
|
|
51
|
+
setItems(newItems);
|
|
52
|
+
},
|
|
53
|
+
insertAfter: (value, ...itemsToInsert) => {
|
|
54
|
+
const newItems = create(items).insertAfter(value, ...itemsToInsert).items;
|
|
55
|
+
setItems(newItems);
|
|
56
|
+
},
|
|
57
|
+
remove: (...itemOrValues) => {
|
|
58
|
+
const newItems = create(items).remove(...itemOrValues).items;
|
|
59
|
+
setItems(newItems);
|
|
60
|
+
},
|
|
61
|
+
move: (value, to) => {
|
|
62
|
+
const newItems = create(items).move(value, to).items;
|
|
63
|
+
setItems(newItems);
|
|
64
|
+
},
|
|
65
|
+
moveBefore: (value, ...values) => {
|
|
66
|
+
const newItems = create(items).moveBefore(value, ...values).items;
|
|
67
|
+
setItems(newItems);
|
|
68
|
+
},
|
|
69
|
+
moveAfter: (value, ...values) => {
|
|
70
|
+
const newItems = create(items).moveAfter(value, ...values).items;
|
|
71
|
+
setItems(newItems);
|
|
72
|
+
},
|
|
73
|
+
reorder: (from, to) => {
|
|
74
|
+
const newItems = create(items).reorder(from, to).items;
|
|
75
|
+
setItems(newItems);
|
|
76
|
+
},
|
|
77
|
+
append: (...itemsToAppend) => {
|
|
78
|
+
const newItems = create(items).append(...itemsToAppend).items;
|
|
79
|
+
setItems(newItems);
|
|
80
|
+
},
|
|
81
|
+
upsert: (value, item, mode = 'append') => {
|
|
82
|
+
const newItems = create(items).upsert(value, item, mode).items;
|
|
83
|
+
setItems(newItems);
|
|
84
|
+
},
|
|
85
|
+
prepend: (...itemsToPrepend) => {
|
|
86
|
+
const newItems = create(items).prepend(...itemsToPrepend).items;
|
|
87
|
+
setItems(newItems);
|
|
88
|
+
},
|
|
89
|
+
update: (value, item) => {
|
|
90
|
+
const newItems = create(items).update(value, item).items;
|
|
91
|
+
setItems(newItems);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type SelectionMode } from '@zag-js/collection';
|
|
2
|
+
import { type MaybeFunction } from '../../utils/functions.js';
|
|
3
|
+
import type { CollectionItem, ListCollection } from './list-collection.js';
|
|
4
|
+
export interface UseListSelectionProps<T extends CollectionItem> {
|
|
5
|
+
/**
|
|
6
|
+
* The selection mode.
|
|
7
|
+
*/
|
|
8
|
+
selectionMode?: SelectionMode;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the selection is deselectable.
|
|
11
|
+
*/
|
|
12
|
+
deselectable?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The initial selected values.
|
|
15
|
+
*/
|
|
16
|
+
initialSelectedValues?: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Whether to reset the selection when the collection changes.
|
|
19
|
+
*/
|
|
20
|
+
resetOnCollectionChange?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The collection to use.
|
|
23
|
+
*/
|
|
24
|
+
collection: ListCollection<T>;
|
|
25
|
+
}
|
|
26
|
+
export declare function useListSelection<T extends CollectionItem>(props: MaybeFunction<UseListSelectionProps<T>>): UseListSelectionReturn;
|
|
27
|
+
export interface UseListSelectionReturn {
|
|
28
|
+
/**
|
|
29
|
+
* The selected values as an array.
|
|
30
|
+
*/
|
|
31
|
+
selectedValues: () => string[];
|
|
32
|
+
/**
|
|
33
|
+
* Whether the selection is empty.
|
|
34
|
+
*/
|
|
35
|
+
isEmpty: () => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The first selected value.
|
|
38
|
+
*/
|
|
39
|
+
firstSelectedValue: () => string | null;
|
|
40
|
+
/**
|
|
41
|
+
* The last selected value.
|
|
42
|
+
*/
|
|
43
|
+
lastSelectedValue: () => string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a value is selected.
|
|
46
|
+
*/
|
|
47
|
+
isSelected: (value: string | null) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a value can be selected.
|
|
50
|
+
*/
|
|
51
|
+
canSelect: (value: string) => boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Select a value.
|
|
54
|
+
*/
|
|
55
|
+
select: (value: string, forceToggle?: boolean) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Deselect a value.
|
|
58
|
+
*/
|
|
59
|
+
deselect: (value: string) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Toggle selection of a value.
|
|
62
|
+
*/
|
|
63
|
+
toggle: (value: string) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Replace the selection with a single value.
|
|
66
|
+
*/
|
|
67
|
+
replace: (value: string | null) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Extend the selection from anchor to target.
|
|
70
|
+
*/
|
|
71
|
+
extend: (anchorValue: string, targetValue: string) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Set the selected values.
|
|
74
|
+
*/
|
|
75
|
+
setSelectedValues: (values: string[]) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Clear the selection.
|
|
78
|
+
*/
|
|
79
|
+
clear: () => void;
|
|
80
|
+
/**
|
|
81
|
+
* Clear all selections.
|
|
82
|
+
*/
|
|
83
|
+
resetSelection: () => void;
|
|
84
|
+
/**
|
|
85
|
+
* Returns true if all items from the collection are selected.
|
|
86
|
+
*/
|
|
87
|
+
isAllSelected: () => boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Returns true if at least one item from the collection is selected.
|
|
90
|
+
*/
|
|
91
|
+
isSomeSelected: () => boolean;
|
|
92
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Selection } from '@zag-js/collection';
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import { runIfFn } from '../../utils/functions.js';
|
|
4
|
+
export function useListSelection(props) {
|
|
5
|
+
const localProps = $derived.by(() => {
|
|
6
|
+
const { collection, selectionMode = 'single', deselectable = true, initialSelectedValues = [], resetOnCollectionChange = false, } = runIfFn(props);
|
|
7
|
+
return {
|
|
8
|
+
collection,
|
|
9
|
+
selectionMode,
|
|
10
|
+
deselectable,
|
|
11
|
+
initialSelectedValues,
|
|
12
|
+
resetOnCollectionChange,
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
const createSelection = (values = []) => {
|
|
16
|
+
const selection = new Selection(values);
|
|
17
|
+
selection.selectionMode = localProps.selectionMode;
|
|
18
|
+
selection.deselectable = localProps.deselectable;
|
|
19
|
+
return selection;
|
|
20
|
+
};
|
|
21
|
+
const initialSelectedValues = untrack(() => localProps.initialSelectedValues);
|
|
22
|
+
let selection = $state(createSelection(initialSelectedValues));
|
|
23
|
+
// Watch for collection changes and reset selection if needed
|
|
24
|
+
$effect(() => {
|
|
25
|
+
const { collection, resetOnCollectionChange } = localProps;
|
|
26
|
+
// Trigger effect when collection values change
|
|
27
|
+
collection.getValues();
|
|
28
|
+
if (resetOnCollectionChange) {
|
|
29
|
+
selection = createSelection();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const selectedValues = $derived(Array.from(selection));
|
|
33
|
+
const isEmpty = $derived(selection.isEmpty());
|
|
34
|
+
const firstSelectedValue = $derived(selection.firstSelectedValue(localProps.collection));
|
|
35
|
+
const lastSelectedValue = $derived(selection.lastSelectedValue(localProps.collection));
|
|
36
|
+
return {
|
|
37
|
+
selectedValues: () => selectedValues,
|
|
38
|
+
isEmpty: () => isEmpty,
|
|
39
|
+
firstSelectedValue: () => firstSelectedValue,
|
|
40
|
+
lastSelectedValue: () => lastSelectedValue,
|
|
41
|
+
isSelected: (value) => {
|
|
42
|
+
return selection.isSelected(value);
|
|
43
|
+
},
|
|
44
|
+
isAllSelected: () => {
|
|
45
|
+
const allValues = localProps.collection.getValues();
|
|
46
|
+
return allValues.length > 0 && allValues.every((value) => selection.isSelected(value));
|
|
47
|
+
},
|
|
48
|
+
isSomeSelected: () => {
|
|
49
|
+
const allValues = localProps.collection.getValues();
|
|
50
|
+
return allValues.some((value) => selection.isSelected(value));
|
|
51
|
+
},
|
|
52
|
+
canSelect: (value) => {
|
|
53
|
+
return selection.canSelect(localProps.collection, value);
|
|
54
|
+
},
|
|
55
|
+
select: (value, forceToggle) => {
|
|
56
|
+
selection = selection.select(localProps.collection, value, forceToggle);
|
|
57
|
+
},
|
|
58
|
+
deselect: (value) => {
|
|
59
|
+
selection = selection.deselect(value);
|
|
60
|
+
},
|
|
61
|
+
toggle: (value) => {
|
|
62
|
+
selection = selection.toggleSelection(localProps.collection, value);
|
|
63
|
+
},
|
|
64
|
+
replace: (value) => {
|
|
65
|
+
selection = selection.replaceSelection(localProps.collection, value);
|
|
66
|
+
},
|
|
67
|
+
extend: (anchorValue, targetValue) => {
|
|
68
|
+
selection = selection.extendSelection(localProps.collection, anchorValue, targetValue);
|
|
69
|
+
},
|
|
70
|
+
setSelectedValues: (values) => {
|
|
71
|
+
selection = selection.setSelection(values);
|
|
72
|
+
},
|
|
73
|
+
clear: () => {
|
|
74
|
+
selection = selection.clearSelection();
|
|
75
|
+
},
|
|
76
|
+
resetSelection: () => {
|
|
77
|
+
selection = createSelection();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './collection/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './collection/index.js';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const isArrayLike = (value) => value?.constructor.name === 'Array';
|
|
2
|
+
export const isArrayEqual = (a, b) => {
|
|
3
|
+
if (a.length !== b.length)
|
|
4
|
+
return false;
|
|
5
|
+
for (let i = 0; i < a.length; i++) {
|
|
6
|
+
if (!isEqual(a[i], b[i]))
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
|
+
};
|
|
11
|
+
export const isEqual = (a, b) => {
|
|
12
|
+
if (Object.is(a, b))
|
|
13
|
+
return true;
|
|
14
|
+
if ((a == null && b != null) || (a != null && b == null))
|
|
15
|
+
return false;
|
|
16
|
+
if (typeof a?.isEqual === 'function' && typeof b?.isEqual === 'function') {
|
|
17
|
+
return a.isEqual(b);
|
|
18
|
+
}
|
|
19
|
+
if (typeof a === 'function' && typeof b === 'function') {
|
|
20
|
+
return a.toString() === b.toString();
|
|
21
|
+
}
|
|
22
|
+
if (isArrayLike(a) && isArrayLike(b)) {
|
|
23
|
+
return isArrayEqual(Array.from(a), Array.from(b));
|
|
24
|
+
}
|
|
25
|
+
if (!(typeof a === 'object') || !(typeof b === 'object'))
|
|
26
|
+
return false;
|
|
27
|
+
const keys = Object.keys(b ?? Object.create(null));
|
|
28
|
+
const length = keys.length;
|
|
29
|
+
for (let i = 0; i < length; i++) {
|
|
30
|
+
const hasKey = Reflect.has(a, keys[i]);
|
|
31
|
+
if (!hasKey)
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
for (let i = 0; i < length; i++) {
|
|
35
|
+
const key = keys[i];
|
|
36
|
+
if (!isEqual(a[key], b[key]))
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
41
|
+
export function isDeepEqual(a, b) {
|
|
42
|
+
if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null)
|
|
43
|
+
return false;
|
|
44
|
+
const aKeys = Object.keys(a);
|
|
45
|
+
const bKeys = Object.keys(b);
|
|
46
|
+
if (aKeys.length !== bKeys.length)
|
|
47
|
+
return false;
|
|
48
|
+
for (const key of aKeys) {
|
|
49
|
+
if (!bKeys.includes(key))
|
|
50
|
+
return false;
|
|
51
|
+
if (!isEqual(a[key], b[key])) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const isArray: (v: any) => v is any[];
|
|
2
|
+
export declare const isBoolean: (v: any) => v is boolean;
|
|
3
|
+
export declare const isObjectLike: (v: any) => v is Record<string, any>;
|
|
4
|
+
export declare const isObject: (v: any) => v is Record<string, any>;
|
|
5
|
+
export declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const isArray = (v) => Array.isArray(v);
|
|
2
|
+
export const isBoolean = (v) => v === true || v === false;
|
|
3
|
+
export const isObjectLike = (v) => v != null && typeof v === 'object';
|
|
4
|
+
export const isObject = (v) => isObjectLike(v) && !isArray(v);
|
|
5
|
+
export const hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TV } from 'tailwind-variants';
|
|
1
2
|
declare const twMerge: (...classLists: import("tailwind-merge").ClassNameValue[]) => string;
|
|
2
|
-
declare const tv:
|
|
3
|
-
export {
|
|
3
|
+
export declare const tv: TV;
|
|
4
|
+
export { twMerge };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { extendTailwindMerge, } from 'tailwind-merge';
|
|
2
|
-
import {
|
|
2
|
+
import { tv as tvBase } from 'tailwind-variants';
|
|
3
3
|
const tailwindMergeConfig = {
|
|
4
4
|
prefix: 'cgui:',
|
|
5
5
|
extend: {
|
|
@@ -35,12 +35,32 @@ const tailwindMergeConfig = {
|
|
|
35
35
|
'border-state-info-light',
|
|
36
36
|
],
|
|
37
37
|
blur: ['blur-xxs', 'blur-xs', 'blur-sm', 'blur-md', 'blur-lg', 'blur-xl', 'blur-2xl'],
|
|
38
|
+
shadow: [
|
|
39
|
+
'shadow-base',
|
|
40
|
+
'shadow-toast',
|
|
41
|
+
'shadow-switch-thumb',
|
|
42
|
+
'shadow-segment-item',
|
|
43
|
+
'shadow-popover',
|
|
44
|
+
'shadow-select',
|
|
45
|
+
'shadow-dialog',
|
|
46
|
+
'shadow-dropdown',
|
|
47
|
+
],
|
|
38
48
|
},
|
|
39
49
|
},
|
|
40
50
|
};
|
|
51
|
+
const tvMergeConfig = {
|
|
52
|
+
classGroups: tailwindMergeConfig.extend?.classGroups,
|
|
53
|
+
};
|
|
41
54
|
const twMerge = extendTailwindMerge(tailwindMergeConfig);
|
|
42
|
-
const tv =
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
export const tv = (options, config) => tvBase(options, {
|
|
56
|
+
...config,
|
|
57
|
+
twMerge: config?.twMerge ?? true,
|
|
58
|
+
twMergeConfig: {
|
|
59
|
+
...config?.twMergeConfig,
|
|
60
|
+
classGroups: {
|
|
61
|
+
...tvMergeConfig.classGroups,
|
|
62
|
+
...config?.twMergeConfig?.classGroups,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
45
65
|
});
|
|
46
|
-
export {
|
|
66
|
+
export { twMerge };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casinogate/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"svelte": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"!dist/**/*.
|
|
18
|
-
"!dist
|
|
17
|
+
"!dist/**/*.stories.*",
|
|
18
|
+
"!dist/**/examples/**",
|
|
19
|
+
"!dist/**/*.test.*"
|
|
19
20
|
],
|
|
20
21
|
"sideEffects": [
|
|
21
22
|
"**/*.css"
|
|
@@ -62,11 +63,12 @@
|
|
|
62
63
|
},
|
|
63
64
|
"dependencies": {
|
|
64
65
|
"@tanstack/table-core": "^8.21.3",
|
|
66
|
+
"@zag-js/collection": "^1.30.0",
|
|
65
67
|
"bits-ui": "^2.8.11",
|
|
66
68
|
"runed": "^0.35.1",
|
|
67
69
|
"svelte-toolbelt": "^0.10.6",
|
|
68
70
|
"tailwind-merge": "^3.3.1",
|
|
69
|
-
"tailwind-variants": "^
|
|
71
|
+
"tailwind-variants": "^3.2.2"
|
|
70
72
|
},
|
|
71
73
|
"scripts": {
|
|
72
74
|
"dev": "vite dev",
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import { Skeleton } from '../skeleton/index.js';
|
|
3
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
4
|
-
import type { Parameters } from '@storybook/sveltekit';
|
|
5
|
-
import type { ComponentProps } from 'svelte';
|
|
6
|
-
import Root from './components/app-shell.root.svelte';
|
|
7
|
-
import { AppShellPrimitive } from './index.js';
|
|
8
|
-
|
|
9
|
-
const parameters: Parameters = {
|
|
10
|
-
controls: {
|
|
11
|
-
include: ['collapsed', 'layout', 'sidebar', 'header', 'withBorder'],
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
docs: {
|
|
15
|
-
story: {
|
|
16
|
-
inline: false,
|
|
17
|
-
iframeHeight: 700,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const { Story } = defineMeta({
|
|
23
|
-
title: 'UI Kit/AppShell',
|
|
24
|
-
component: Root,
|
|
25
|
-
tags: ['autodocs'],
|
|
26
|
-
parameters,
|
|
27
|
-
|
|
28
|
-
argTypes: {
|
|
29
|
-
collapsed: {
|
|
30
|
-
table: {
|
|
31
|
-
defaultValue: { summary: 'false' },
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
type Args = ComponentProps<typeof Root>;
|
|
38
|
-
|
|
39
|
-
const args: Args = {
|
|
40
|
-
collapsed: false,
|
|
41
|
-
layout: 'adjacent',
|
|
42
|
-
withBorder: true,
|
|
43
|
-
sidebar: {
|
|
44
|
-
width: 256,
|
|
45
|
-
collapsedWidth: 80,
|
|
46
|
-
},
|
|
47
|
-
header: {
|
|
48
|
-
height: 48,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const items = Array.from({ length: 10 }).map((_, idx) => idx);
|
|
53
|
-
|
|
54
|
-
function formatDate(date: Date): string {
|
|
55
|
-
const formatter = new Intl.DateTimeFormat('en-GB', {
|
|
56
|
-
day: '2-digit',
|
|
57
|
-
month: '2-digit',
|
|
58
|
-
year: 'numeric',
|
|
59
|
-
hour: 'numeric',
|
|
60
|
-
minute: '2-digit',
|
|
61
|
-
timeZoneName: 'shortOffset',
|
|
62
|
-
hour12: false,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const parts = formatter.formatToParts(date);
|
|
66
|
-
const day = parts.find((p) => p.type === 'day')?.value;
|
|
67
|
-
const month = parts.find((p) => p.type === 'month')?.value;
|
|
68
|
-
const year = parts.find((p) => p.type === 'year')?.value;
|
|
69
|
-
const hour = parts.find((p) => p.type === 'hour')?.value;
|
|
70
|
-
const minute = parts.find((p) => p.type === 'minute')?.value;
|
|
71
|
-
const timeZone = parts.find((p) => p.type === 'timeZoneName')?.value;
|
|
72
|
-
|
|
73
|
-
return `${day}.${month}.${year} ${hour}:${minute} ${timeZone}`;
|
|
74
|
-
}
|
|
75
|
-
</script>
|
|
76
|
-
|
|
77
|
-
<Story name="Basic" {parameters} {args}>
|
|
78
|
-
{#snippet template(args: Args)}
|
|
79
|
-
<div class="cgui:fixed cgui:inset-0">
|
|
80
|
-
<AppShellPrimitive.Root {...args}>
|
|
81
|
-
<AppShellPrimitive.Header class="cgui:p-4">
|
|
82
|
-
<p class="cgui:text-caption cgui:text-fg-regular">
|
|
83
|
-
{formatDate(new Date())}
|
|
84
|
-
</p>
|
|
85
|
-
</AppShellPrimitive.Header>
|
|
86
|
-
<AppShellPrimitive.Sidebar>
|
|
87
|
-
<AppShellPrimitive.SidebarHead></AppShellPrimitive.SidebarHead>
|
|
88
|
-
<AppShellPrimitive.NavBar></AppShellPrimitive.NavBar>
|
|
89
|
-
<AppShellPrimitive.SidebarFooter class="cgui:justify-end">
|
|
90
|
-
<AppShellPrimitive.SidebarToggle />
|
|
91
|
-
</AppShellPrimitive.SidebarFooter>
|
|
92
|
-
</AppShellPrimitive.Sidebar>
|
|
93
|
-
<AppShellPrimitive.Viewport>
|
|
94
|
-
<AppShellPrimitive.Content class="cgui:p-4">
|
|
95
|
-
<div class="cgui:grow cgui:flex cgui:flex-col cgui:gap-4">
|
|
96
|
-
{#each items as item (item)}
|
|
97
|
-
<div class="cgui:flex cgui:items-center cgui:gap-4">
|
|
98
|
-
<Skeleton count={2} class="cgui:h-20 cgui:flex-1" color="surface" />
|
|
99
|
-
</div>
|
|
100
|
-
{/each}
|
|
101
|
-
</div>
|
|
102
|
-
</AppShellPrimitive.Content>
|
|
103
|
-
</AppShellPrimitive.Viewport>
|
|
104
|
-
</AppShellPrimitive.Root>
|
|
105
|
-
</div>
|
|
106
|
-
{/snippet}
|
|
107
|
-
</Story>
|