@casinogate/ui 0.0.3
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/README.md +171 -0
- package/dist/app.d.ts +15 -0
- package/dist/app.html +12 -0
- package/dist/assets/css/root.css +1057 -0
- package/dist/assets/css/theme.css +255 -0
- package/dist/assets/icons/check.svg +4 -0
- package/dist/assets/icons/chevron-down.svg +4 -0
- package/dist/assets/icons/chevron-left.svg +4 -0
- package/dist/assets/icons/chevron-right.svg +4 -0
- package/dist/assets/icons/chevron-small-down.svg +4 -0
- package/dist/assets/icons/chevron-small-left.svg +4 -0
- package/dist/assets/icons/chevron-small-right.svg +4 -0
- package/dist/assets/icons/chevron-small-up.svg +4 -0
- package/dist/assets/icons/chevron-up.svg +4 -0
- package/dist/assets/icons/error.svg +4 -0
- package/dist/assets/icons/info.svg +4 -0
- package/dist/assets/icons/minus.svg +4 -0
- package/dist/assets/icons/success.svg +4 -0
- package/dist/assets/icons/warning.svg +3 -0
- package/dist/components/button/button.component.svelte +173 -0
- package/dist/components/button/button.component.svelte.d.ts +239 -0
- package/dist/components/button/button.stories.svelte +106 -0
- package/dist/components/button/button.stories.svelte.d.ts +19 -0
- package/dist/components/button/index.d.ts +233 -0
- package/dist/components/button/index.js +4 -0
- package/dist/components/checkbox/checkbox.stories.svelte +52 -0
- package/dist/components/checkbox/checkbox.stories.svelte.d.ts +18 -0
- package/dist/components/checkbox/components/checkbox.group.svelte +3 -0
- package/dist/components/checkbox/components/checkbox.group.svelte.d.ts +18 -0
- package/dist/components/checkbox/components/checkbox.root.svelte +51 -0
- package/dist/components/checkbox/components/checkbox.root.svelte.d.ts +6 -0
- package/dist/components/checkbox/index.js +6 -0
- package/dist/components/checkbox/model/checkbox-model.svelte.d.ts +16 -0
- package/dist/components/checkbox/model/checkbox-model.svelte.js +25 -0
- package/dist/components/checkbox/model/index.d.ts +1 -0
- package/dist/components/checkbox/model/index.js +1 -0
- package/dist/components/checkbox/styles.d.ts +126 -0
- package/dist/components/checkbox/styles.js +60 -0
- package/dist/components/collapsible/collapsible.stories.svelte +53 -0
- package/dist/components/collapsible/collapsible.stories.svelte.d.ts +18 -0
- package/dist/components/collapsible/components/collapsaible.content.svelte +40 -0
- package/dist/components/collapsible/components/collapsaible.content.svelte.d.ts +5 -0
- package/dist/components/collapsible/components/collapsaible.group.svelte +0 -0
- package/dist/components/collapsible/components/collapsaible.group.svelte.d.ts +26 -0
- package/dist/components/collapsible/components/collapsaible.root.svelte +62 -0
- package/dist/components/collapsible/components/collapsaible.root.svelte.d.ts +5 -0
- package/dist/components/collapsible/components/collapsaible.svelte.d.ts +44 -0
- package/dist/components/collapsible/components/collapsaible.svelte.js +92 -0
- package/dist/components/collapsible/components/collapsaible.trigger.svelte +50 -0
- package/dist/components/collapsible/components/collapsaible.trigger.svelte.d.ts +8 -0
- package/dist/components/collapsible/index.d.ts +9 -0
- package/dist/components/collapsible/index.js +8 -0
- package/dist/components/collapsible/styles.d.ts +178 -0
- package/dist/components/collapsible/styles.js +27 -0
- package/dist/components/collapsible/types.d.ts +1 -0
- package/dist/components/collapsible/types.js +1 -0
- package/dist/components/switch/components/switch.root.svelte +27 -0
- package/dist/components/switch/components/switch.root.svelte.d.ts +6 -0
- package/dist/components/switch/components/switch.thumb.svelte +17 -0
- package/dist/components/switch/components/switch.thumb.svelte.d.ts +5 -0
- package/dist/components/switch/index.d.ts +5 -0
- package/dist/components/switch/index.js +7 -0
- package/dist/components/switch/model/index.d.ts +1 -0
- package/dist/components/switch/model/index.js +1 -0
- package/dist/components/switch/model/switch-model.svelte.d.ts +12 -0
- package/dist/components/switch/model/switch-model.svelte.js +18 -0
- package/dist/components/switch/styles.d.ts +74 -0
- package/dist/components/switch/styles.js +44 -0
- package/dist/components/switch/switch.stories.svelte +48 -0
- package/dist/components/switch/switch.stories.svelte.d.ts +18 -0
- package/dist/components/toast/toast.component.svelte +149 -0
- package/dist/components/toast/toast.component.svelte.d.ts +158 -0
- package/dist/components/toast/toast.stories.svelte +96 -0
- package/dist/components/toast/toast.stories.svelte.d.ts +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/types/attrs.d.ts +1 -0
- package/dist/internal/types/attrs.js +3 -0
- package/dist/internal/types/common.d.ts +25 -0
- package/dist/internal/types/common.js +1 -0
- package/dist/internal/types/composition.d.ts +45 -0
- package/dist/internal/types/composition.js +1 -0
- package/dist/internal/types/html-attributes.d.ts +48 -0
- package/dist/internal/types/html-attributes.js +1 -0
- package/dist/internal/utils/arrays.d.ts +1 -0
- package/dist/internal/utils/arrays.js +30 -0
- package/dist/internal/utils/common.d.ts +6 -0
- package/dist/internal/utils/common.js +9 -0
- package/dist/internal/utils/tailwindcss.d.ts +3 -0
- package/dist/internal/utils/tailwindcss.js +29 -0
- package/package.json +75 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export type CheckboxRootProps = CheckboxRootPropsPrimitive & CheckboxVariantsProps;
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import CheckIcon from '../../../assets/icons/check.svg?component';
|
|
7
|
+
import { checkboxVariants, type CheckboxVariantsProps } from '../styles.js';
|
|
8
|
+
import { Checkbox, useId, type CheckboxRootProps as CheckboxRootPropsPrimitive } from 'bits-ui';
|
|
9
|
+
import { cubicInOut } from 'svelte/easing';
|
|
10
|
+
import { fly } from 'svelte/transition';
|
|
11
|
+
|
|
12
|
+
let {
|
|
13
|
+
ref = $bindable(null),
|
|
14
|
+
id = useId(),
|
|
15
|
+
checked = $bindable(false),
|
|
16
|
+
indeterminate = $bindable(false),
|
|
17
|
+
class: className,
|
|
18
|
+
children: childrenSnippet,
|
|
19
|
+
size = 'md',
|
|
20
|
+
rounded = 'xs',
|
|
21
|
+
...props
|
|
22
|
+
}: CheckboxRootProps = $props();
|
|
23
|
+
|
|
24
|
+
const variants = $derived(checkboxVariants({ size, rounded }));
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<Checkbox.Root bind:ref bind:checked bind:indeterminate {id} class={[variants.root(), className]} {...props}>
|
|
28
|
+
{#snippet children(childrenProps)}
|
|
29
|
+
{#if childrenSnippet}
|
|
30
|
+
{@render childrenSnippet?.(childrenProps)}
|
|
31
|
+
{:else if childrenProps.indeterminate}
|
|
32
|
+
<span
|
|
33
|
+
data-slot="indeterminate-indicator"
|
|
34
|
+
data-state="indeterminate"
|
|
35
|
+
in:fly={{ duration: 250, y: 4, easing: cubicInOut }}
|
|
36
|
+
out:fly={{ duration: 250, y: -4, easing: cubicInOut }}
|
|
37
|
+
class={variants.indeterminateIndicator()}
|
|
38
|
+
></span>
|
|
39
|
+
{:else if childrenProps.checked}
|
|
40
|
+
<span
|
|
41
|
+
data-slot="checked-indicator"
|
|
42
|
+
data-state="checked"
|
|
43
|
+
in:fly={{ duration: 250, y: 4, easing: cubicInOut }}
|
|
44
|
+
out:fly={{ duration: 250, y: -4, easing: cubicInOut }}
|
|
45
|
+
class={variants.checkedIndicator()}
|
|
46
|
+
>
|
|
47
|
+
<CheckIcon />
|
|
48
|
+
</span>
|
|
49
|
+
{/if}
|
|
50
|
+
{/snippet}
|
|
51
|
+
</Checkbox.Root>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type CheckboxRootProps = CheckboxRootPropsPrimitive & CheckboxVariantsProps;
|
|
2
|
+
import { type CheckboxVariantsProps } from '../styles.js';
|
|
3
|
+
import { Checkbox, type CheckboxRootProps as CheckboxRootPropsPrimitive } from 'bits-ui';
|
|
4
|
+
declare const Checkbox: import("svelte").Component<CheckboxRootProps, {}, "ref" | "checked" | "indeterminate">;
|
|
5
|
+
type Checkbox = ReturnType<typeof Checkbox>;
|
|
6
|
+
export default Checkbox;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type CheckboxModelOpts = {
|
|
2
|
+
defaultChecked?: boolean;
|
|
3
|
+
defaultIndeterminate?: boolean;
|
|
4
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
5
|
+
onIndeterminateChange?: (indeterminate: boolean) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare class CheckboxModel {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(opts?: CheckboxModelOpts);
|
|
10
|
+
get checked(): boolean;
|
|
11
|
+
set checked(value: boolean);
|
|
12
|
+
get indeterminate(): boolean;
|
|
13
|
+
set indeterminate(value: boolean);
|
|
14
|
+
}
|
|
15
|
+
export declare const createCheckboxModel: (opts?: CheckboxModelOpts) => CheckboxModel;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class CheckboxModel {
|
|
2
|
+
#opts;
|
|
3
|
+
#checked = $state(false);
|
|
4
|
+
#indeterminate = $state(false);
|
|
5
|
+
constructor(opts = {}) {
|
|
6
|
+
this.#opts = opts;
|
|
7
|
+
}
|
|
8
|
+
get checked() {
|
|
9
|
+
return this.#checked;
|
|
10
|
+
}
|
|
11
|
+
set checked(value) {
|
|
12
|
+
this.#checked = value;
|
|
13
|
+
this.#opts.onCheckedChange?.(value);
|
|
14
|
+
}
|
|
15
|
+
get indeterminate() {
|
|
16
|
+
return this.#indeterminate;
|
|
17
|
+
}
|
|
18
|
+
set indeterminate(value) {
|
|
19
|
+
this.#indeterminate = value;
|
|
20
|
+
this.#opts.onIndeterminateChange?.(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const createCheckboxModel = (opts = {}) => {
|
|
24
|
+
return new CheckboxModel(opts);
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CheckboxModel, createCheckboxModel } from './checkbox-model.svelte.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CheckboxModel, createCheckboxModel } from './checkbox-model.svelte.js';
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { VariantProps } from 'tailwind-variants';
|
|
2
|
+
export declare const checkboxVariants: import("tailwind-variants").TVReturnType<{
|
|
3
|
+
size: {
|
|
4
|
+
sm: {
|
|
5
|
+
root: string[];
|
|
6
|
+
indeterminateIndicator: string[];
|
|
7
|
+
};
|
|
8
|
+
md: {
|
|
9
|
+
root: string[];
|
|
10
|
+
indeterminateIndicator: string[];
|
|
11
|
+
};
|
|
12
|
+
lg: {
|
|
13
|
+
root: string[];
|
|
14
|
+
};
|
|
15
|
+
xl: {
|
|
16
|
+
root: string[];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
rounded: {
|
|
20
|
+
none: {
|
|
21
|
+
root: never[];
|
|
22
|
+
};
|
|
23
|
+
xs: {
|
|
24
|
+
root: string[];
|
|
25
|
+
};
|
|
26
|
+
sm: {
|
|
27
|
+
root: string[];
|
|
28
|
+
};
|
|
29
|
+
md: {
|
|
30
|
+
root: string[];
|
|
31
|
+
};
|
|
32
|
+
lg: {
|
|
33
|
+
root: string[];
|
|
34
|
+
};
|
|
35
|
+
xl: {
|
|
36
|
+
root: string[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}, {
|
|
40
|
+
root: string[];
|
|
41
|
+
indeterminateIndicator: string[];
|
|
42
|
+
checkedIndicator: string[];
|
|
43
|
+
}, undefined, {
|
|
44
|
+
size: {
|
|
45
|
+
sm: {
|
|
46
|
+
root: string[];
|
|
47
|
+
indeterminateIndicator: string[];
|
|
48
|
+
};
|
|
49
|
+
md: {
|
|
50
|
+
root: string[];
|
|
51
|
+
indeterminateIndicator: string[];
|
|
52
|
+
};
|
|
53
|
+
lg: {
|
|
54
|
+
root: string[];
|
|
55
|
+
};
|
|
56
|
+
xl: {
|
|
57
|
+
root: string[];
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
rounded: {
|
|
61
|
+
none: {
|
|
62
|
+
root: never[];
|
|
63
|
+
};
|
|
64
|
+
xs: {
|
|
65
|
+
root: string[];
|
|
66
|
+
};
|
|
67
|
+
sm: {
|
|
68
|
+
root: string[];
|
|
69
|
+
};
|
|
70
|
+
md: {
|
|
71
|
+
root: string[];
|
|
72
|
+
};
|
|
73
|
+
lg: {
|
|
74
|
+
root: string[];
|
|
75
|
+
};
|
|
76
|
+
xl: {
|
|
77
|
+
root: string[];
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
}, {
|
|
81
|
+
root: string[];
|
|
82
|
+
indeterminateIndicator: string[];
|
|
83
|
+
checkedIndicator: string[];
|
|
84
|
+
}, import("tailwind-variants").TVReturnType<{
|
|
85
|
+
size: {
|
|
86
|
+
sm: {
|
|
87
|
+
root: string[];
|
|
88
|
+
indeterminateIndicator: string[];
|
|
89
|
+
};
|
|
90
|
+
md: {
|
|
91
|
+
root: string[];
|
|
92
|
+
indeterminateIndicator: string[];
|
|
93
|
+
};
|
|
94
|
+
lg: {
|
|
95
|
+
root: string[];
|
|
96
|
+
};
|
|
97
|
+
xl: {
|
|
98
|
+
root: string[];
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
rounded: {
|
|
102
|
+
none: {
|
|
103
|
+
root: never[];
|
|
104
|
+
};
|
|
105
|
+
xs: {
|
|
106
|
+
root: string[];
|
|
107
|
+
};
|
|
108
|
+
sm: {
|
|
109
|
+
root: string[];
|
|
110
|
+
};
|
|
111
|
+
md: {
|
|
112
|
+
root: string[];
|
|
113
|
+
};
|
|
114
|
+
lg: {
|
|
115
|
+
root: string[];
|
|
116
|
+
};
|
|
117
|
+
xl: {
|
|
118
|
+
root: string[];
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
}, {
|
|
122
|
+
root: string[];
|
|
123
|
+
indeterminateIndicator: string[];
|
|
124
|
+
checkedIndicator: string[];
|
|
125
|
+
}, undefined, unknown, unknown, undefined>>;
|
|
126
|
+
export type CheckboxVariantsProps = VariantProps<typeof checkboxVariants>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { tv } from '../../internal/utils/tailwindcss.js';
|
|
2
|
+
export const checkboxVariants = tv({
|
|
3
|
+
slots: {
|
|
4
|
+
root: [
|
|
5
|
+
'cgui:relative cgui:overflow-hidden',
|
|
6
|
+
'cgui:flex cgui:items-center cgui:justify-center',
|
|
7
|
+
'cgui:border cgui:border-surface-regular cgui:outline-none',
|
|
8
|
+
'cgui:cursor-pointer cgui:select-none',
|
|
9
|
+
'cgui:transition-all cgui:duration-250 cgui:ease-in-out',
|
|
10
|
+
'cgui:active:scale-95',
|
|
11
|
+
'cgui:disabled:opacity-50 cgui:disabled:cursor-not-allowed',
|
|
12
|
+
'cgui:data-[state=indeterminate]:border-surface-primary',
|
|
13
|
+
'cgui:data-[state=checked]:border-surface-primary cgui:data-[state=checked]:bg-surface-primary',
|
|
14
|
+
],
|
|
15
|
+
indeterminateIndicator: [
|
|
16
|
+
'cgui:absolute cgui:top-1/2 cgui:left-1/2 cgui:-translate-x-1/2 cgui:-translate-y-1/2 cgui:flex cgui:size-1/2 cgui:bg-surface-primary cgui:rounded-[inherit]',
|
|
17
|
+
],
|
|
18
|
+
checkedIndicator: [
|
|
19
|
+
'cgui:absolute cgui:size-full cgui:flex cgui:items-center cgui:justify-center cgui:text-icon-white',
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
variants: {
|
|
23
|
+
size: {
|
|
24
|
+
sm: {
|
|
25
|
+
root: ['cgui:size-3'],
|
|
26
|
+
indeterminateIndicator: ['cgui:rounded-xxxs'],
|
|
27
|
+
},
|
|
28
|
+
md: {
|
|
29
|
+
root: ['cgui:size-4'],
|
|
30
|
+
indeterminateIndicator: ['cgui:rounded-xxxs'],
|
|
31
|
+
},
|
|
32
|
+
lg: {
|
|
33
|
+
root: ['cgui:size-6'],
|
|
34
|
+
},
|
|
35
|
+
xl: {
|
|
36
|
+
root: ['cgui:size-12'],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
rounded: {
|
|
40
|
+
none: {
|
|
41
|
+
root: [],
|
|
42
|
+
},
|
|
43
|
+
xs: {
|
|
44
|
+
root: ['cgui:rounded-xxs'],
|
|
45
|
+
},
|
|
46
|
+
sm: {
|
|
47
|
+
root: ['cgui:rounded-sm'],
|
|
48
|
+
},
|
|
49
|
+
md: {
|
|
50
|
+
root: ['cgui:rounded-md'],
|
|
51
|
+
},
|
|
52
|
+
lg: {
|
|
53
|
+
root: ['cgui:rounded-md'],
|
|
54
|
+
},
|
|
55
|
+
xl: {
|
|
56
|
+
root: ['cgui:rounded-lg'],
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { defineMeta } from '../../storybook/addon-svelte-csf';
|
|
3
|
+
import type { Parameters } from '../../storybook/sveltekit';
|
|
4
|
+
|
|
5
|
+
import type { ComponentProps } from 'svelte';
|
|
6
|
+
import CollapsibleContent from './components/collapsaible.content.svelte';
|
|
7
|
+
import CollapsibleRoot from './components/collapsaible.root.svelte';
|
|
8
|
+
import CollapsibleTrigger from './components/collapsaible.trigger.svelte';
|
|
9
|
+
|
|
10
|
+
const parameters: Parameters = {
|
|
11
|
+
controls: {
|
|
12
|
+
include: ['open', 'disabled'],
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const { Story } = defineMeta({
|
|
17
|
+
title: 'UI Kit/Collapsible',
|
|
18
|
+
component: CollapsibleRoot,
|
|
19
|
+
render: template,
|
|
20
|
+
tags: ['autodocs'],
|
|
21
|
+
|
|
22
|
+
argTypes: {
|
|
23
|
+
open: {
|
|
24
|
+
table: {
|
|
25
|
+
defaultValue: { summary: '$bindable(false)' },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
parameters,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
type Args = ComponentProps<typeof CollapsibleRoot>;
|
|
34
|
+
|
|
35
|
+
const args: Args = {
|
|
36
|
+
open: false,
|
|
37
|
+
disabled: false,
|
|
38
|
+
};
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
{#snippet template(args: Args)}
|
|
42
|
+
<CollapsibleRoot {...args}>
|
|
43
|
+
<CollapsibleTrigger>Nisi nulla esse qui dolor</CollapsibleTrigger>
|
|
44
|
+
<CollapsibleContent>
|
|
45
|
+
Labore cupidatat nisi nostrud non laboris tempor velit. Commodo in sint ea fugiat ad ullamco labore. Laboris
|
|
46
|
+
labore sunt nostrud labore aliqua. Consectetur nulla anim amet laborum ex sunt nisi do consectetur magna Lorem
|
|
47
|
+
irure. Anim aute magna ad. Aliqua labore enim in quis. Eu exercitation cupidatat anim mollit ipsum eiusmod ex. Id
|
|
48
|
+
exercitation nulla esse consequat incididunt tempor.
|
|
49
|
+
</CollapsibleContent>
|
|
50
|
+
</CollapsibleRoot>
|
|
51
|
+
{/snippet}
|
|
52
|
+
|
|
53
|
+
<Story name="Basic" {args} {template} {parameters} />
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const Collapsible: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
}, {}, {}, string>;
|
|
17
|
+
type Collapsible = InstanceType<typeof Collapsible>;
|
|
18
|
+
export default Collapsible;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export type CollapsibleContentProps = CollapsibleContentPropsPrimitive;
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { CollapsibleStylesContext } from '../styles.js';
|
|
7
|
+
|
|
8
|
+
import { cn } from '../../../internal/utils/common.js';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
Collapsible as CollapsiblePrimitive,
|
|
12
|
+
useId,
|
|
13
|
+
type CollapsibleContentProps as CollapsibleContentPropsPrimitive,
|
|
14
|
+
} from 'bits-ui';
|
|
15
|
+
import { fade } from 'svelte/transition';
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
ref = $bindable(null),
|
|
19
|
+
id = useId(),
|
|
20
|
+
forceMount = true,
|
|
21
|
+
class: className,
|
|
22
|
+
child: childSnippet,
|
|
23
|
+
children,
|
|
24
|
+
...restProps
|
|
25
|
+
}: CollapsibleContentProps = $props();
|
|
26
|
+
|
|
27
|
+
const styles = CollapsibleStylesContext.get();
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<CollapsiblePrimitive.Content bind:ref {id} class={cn(styles.current.content(), className)} {forceMount} {...restProps}>
|
|
31
|
+
{#snippet child(childProps)}
|
|
32
|
+
{#if childSnippet}
|
|
33
|
+
{@render childSnippet?.(childProps)}
|
|
34
|
+
{:else if childProps.open}
|
|
35
|
+
<div {...childProps.props} transition:fade={{ duration: 250 }}>
|
|
36
|
+
{@render children?.()}
|
|
37
|
+
</div>
|
|
38
|
+
{/if}
|
|
39
|
+
{/snippet}
|
|
40
|
+
</CollapsiblePrimitive.Content>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type CollapsibleContentProps = CollapsibleContentPropsPrimitive;
|
|
2
|
+
import { Collapsible as CollapsiblePrimitive, type CollapsibleContentProps as CollapsibleContentPropsPrimitive } from 'bits-ui';
|
|
3
|
+
declare const Collapsaible: import("svelte").Component<CollapsiblePrimitive.ContentProps, {}, "ref">;
|
|
4
|
+
type Collapsaible = ReturnType<typeof Collapsaible>;
|
|
5
|
+
export default Collapsaible;
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default Collapsaible;
|
|
2
|
+
type Collapsaible = SvelteComponent<{
|
|
3
|
+
[x: string]: never;
|
|
4
|
+
}, {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
}, {}> & {
|
|
7
|
+
$$bindings?: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
declare const Collapsaible: $$__sveltets_2_IsomorphicComponent<{
|
|
10
|
+
[x: string]: never;
|
|
11
|
+
}, {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
}, {}, {}, string>;
|
|
14
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
15
|
+
new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
16
|
+
$$bindings?: Bindings;
|
|
17
|
+
} & Exports;
|
|
18
|
+
(internal: unknown, props: {
|
|
19
|
+
$$events?: Events;
|
|
20
|
+
$$slots?: Slots;
|
|
21
|
+
}): Exports & {
|
|
22
|
+
$set?: any;
|
|
23
|
+
$on?: any;
|
|
24
|
+
};
|
|
25
|
+
z_$$bindings?: Bindings;
|
|
26
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export type CollapsibleRootProps = CollapsibleRootPropsPrimitive;
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { CollapsibleStylesContext, collapsibleVariants } from '../styles.js';
|
|
7
|
+
import { cn } from '../../../internal/utils/common.js';
|
|
8
|
+
import {
|
|
9
|
+
Collapsible as CollapsiblePrimitive,
|
|
10
|
+
useId,
|
|
11
|
+
type CollapsibleRootProps as CollapsibleRootPropsPrimitive,
|
|
12
|
+
} from 'bits-ui';
|
|
13
|
+
import { box, mergeProps } from 'svelte-toolbelt';
|
|
14
|
+
import { CollapsibleGroupContext, CollapsibleRootState } from './collapsaible.svelte.js';
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
open = $bindable(false),
|
|
18
|
+
ref = $bindable(null),
|
|
19
|
+
id = useId(),
|
|
20
|
+
disabled,
|
|
21
|
+
class: className,
|
|
22
|
+
...restProps
|
|
23
|
+
}: CollapsibleRootProps = $props();
|
|
24
|
+
|
|
25
|
+
const group = CollapsibleGroupContext.getOr(null);
|
|
26
|
+
|
|
27
|
+
if (group) {
|
|
28
|
+
if (group.opts.value.current.includes(id)) {
|
|
29
|
+
open = true;
|
|
30
|
+
} else {
|
|
31
|
+
open = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const rootState = CollapsibleRootState.create(
|
|
36
|
+
{
|
|
37
|
+
value: box.with(
|
|
38
|
+
() => open,
|
|
39
|
+
(v) => (open = v)
|
|
40
|
+
),
|
|
41
|
+
ref: box.with(
|
|
42
|
+
() => ref,
|
|
43
|
+
(v) => (ref = v)
|
|
44
|
+
),
|
|
45
|
+
disabled: box.with(() => disabled ?? false),
|
|
46
|
+
id: box.with(() => id),
|
|
47
|
+
},
|
|
48
|
+
group
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const variants = $derived(collapsibleVariants());
|
|
52
|
+
|
|
53
|
+
CollapsibleStylesContext.set(box.with(() => variants));
|
|
54
|
+
|
|
55
|
+
const mergedProps = $derived(mergeProps(restProps, rootState.props));
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<CollapsiblePrimitive.Root
|
|
59
|
+
bind:open={rootState.opts.value.current}
|
|
60
|
+
class={cn(variants.root(), className)}
|
|
61
|
+
{...mergedProps}
|
|
62
|
+
/>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type CollapsibleRootProps = CollapsibleRootPropsPrimitive;
|
|
2
|
+
import { Collapsible as CollapsiblePrimitive, type CollapsibleRootProps as CollapsibleRootPropsPrimitive } from 'bits-ui';
|
|
3
|
+
declare const Collapsaible: import("svelte").Component<CollapsiblePrimitive.RootProps, {}, "ref" | "open">;
|
|
4
|
+
type Collapsaible = ReturnType<typeof Collapsaible>;
|
|
5
|
+
export default Collapsaible;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { CollapsibleOpenVariant } from '../types.js';
|
|
2
|
+
import type { OnChangeFn, RefAttachment } from '../../../internal/types/common.js';
|
|
3
|
+
import { Context } from 'runed';
|
|
4
|
+
import { type ReadableBoxedValues, type WithRefProps, type WritableBoxedValues } from 'svelte-toolbelt';
|
|
5
|
+
export declare const CollapsibleGroupContext: Context<CollapsibleGroupState>;
|
|
6
|
+
type CollapsibleGroupStateOpts = WithRefProps<WritableBoxedValues<{
|
|
7
|
+
value: string[];
|
|
8
|
+
}> & ReadableBoxedValues<{
|
|
9
|
+
variant: CollapsibleOpenVariant;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
onValueChange: OnChangeFn<string[]>;
|
|
12
|
+
}>>;
|
|
13
|
+
export declare class CollapsibleGroupState {
|
|
14
|
+
static create(opts: CollapsibleGroupStateOpts): CollapsibleGroupState;
|
|
15
|
+
readonly opts: CollapsibleGroupStateOpts;
|
|
16
|
+
readonly attachment: RefAttachment;
|
|
17
|
+
constructor(opts: CollapsibleGroupStateOpts);
|
|
18
|
+
addValue(value: string | undefined): void;
|
|
19
|
+
removeValue(value: string | undefined): void;
|
|
20
|
+
readonly props: {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly 'data-disabled': "" | undefined;
|
|
23
|
+
readonly role: "group";
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
type CollapsibleRootStateOpts = WithRefProps<WritableBoxedValues<{
|
|
27
|
+
value: boolean;
|
|
28
|
+
}> & ReadableBoxedValues<{
|
|
29
|
+
disabled: boolean;
|
|
30
|
+
}>>;
|
|
31
|
+
export declare class CollapsibleRootState {
|
|
32
|
+
static create(opts: CollapsibleRootStateOpts, group: CollapsibleGroupState | null): CollapsibleRootState;
|
|
33
|
+
readonly opts: CollapsibleRootStateOpts;
|
|
34
|
+
readonly group: CollapsibleGroupState | null;
|
|
35
|
+
readonly attachment: RefAttachment;
|
|
36
|
+
readonly trueDisabled: boolean;
|
|
37
|
+
constructor(opts: CollapsibleRootStateOpts, group: CollapsibleGroupState | null);
|
|
38
|
+
readonly props: {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly disabled: boolean;
|
|
41
|
+
readonly 'data-disabled': "" | undefined;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { getDataDisabled } from '../../../internal/types/attrs.js';
|
|
2
|
+
import { arraysAreEqual } from '../../../internal/utils/arrays.js';
|
|
3
|
+
import { keyWithPrefix } from '../../../internal/utils/common.js';
|
|
4
|
+
import { Context, watch } from 'runed';
|
|
5
|
+
import { attachRef } from 'svelte-toolbelt';
|
|
6
|
+
const CollapsibleRootContext = new Context(keyWithPrefix('collapsible-root'));
|
|
7
|
+
export const CollapsibleGroupContext = new Context(keyWithPrefix('collapsible-group'));
|
|
8
|
+
export class CollapsibleGroupState {
|
|
9
|
+
static create(opts) {
|
|
10
|
+
return CollapsibleGroupContext.set(new CollapsibleGroupState(opts));
|
|
11
|
+
}
|
|
12
|
+
opts;
|
|
13
|
+
attachment;
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
this.opts = opts;
|
|
16
|
+
this.attachment = attachRef(opts.ref);
|
|
17
|
+
}
|
|
18
|
+
addValue(value) {
|
|
19
|
+
if (!value)
|
|
20
|
+
return;
|
|
21
|
+
if (this.opts.value.current.includes(value))
|
|
22
|
+
return;
|
|
23
|
+
let newValue = [];
|
|
24
|
+
if (this.opts.variant.current === 'single') {
|
|
25
|
+
newValue = [value];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
newValue = [...$state.snapshot(this.opts.value.current), value];
|
|
29
|
+
}
|
|
30
|
+
this.opts.value.current = newValue;
|
|
31
|
+
if (arraysAreEqual(this.opts.value.current, newValue))
|
|
32
|
+
return;
|
|
33
|
+
this.opts.onValueChange.current(newValue);
|
|
34
|
+
}
|
|
35
|
+
removeValue(value) {
|
|
36
|
+
if (!value)
|
|
37
|
+
return;
|
|
38
|
+
const idx = this.opts.value.current.indexOf(value);
|
|
39
|
+
if (idx === -1)
|
|
40
|
+
return;
|
|
41
|
+
const newValue = this.opts.value.current.filter((v) => v !== value);
|
|
42
|
+
this.opts.value.current = newValue;
|
|
43
|
+
if (arraysAreEqual(this.opts.value.current, newValue))
|
|
44
|
+
return;
|
|
45
|
+
this.opts.onValueChange.current(newValue);
|
|
46
|
+
}
|
|
47
|
+
props = $derived.by(() => ({
|
|
48
|
+
id: this.opts.id.current,
|
|
49
|
+
'data-disabled': getDataDisabled(this.opts.disabled.current),
|
|
50
|
+
role: 'group',
|
|
51
|
+
...this.attachment,
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
export class CollapsibleRootState {
|
|
55
|
+
static create(opts, group) {
|
|
56
|
+
return CollapsibleRootContext.set(new CollapsibleRootState(opts, group));
|
|
57
|
+
}
|
|
58
|
+
opts;
|
|
59
|
+
group;
|
|
60
|
+
attachment;
|
|
61
|
+
trueDisabled = $derived.by(() => {
|
|
62
|
+
if (this.group && this.group.opts.disabled.current)
|
|
63
|
+
return true;
|
|
64
|
+
return this.opts.disabled.current;
|
|
65
|
+
});
|
|
66
|
+
constructor(opts, group) {
|
|
67
|
+
this.opts = opts;
|
|
68
|
+
this.group = group;
|
|
69
|
+
this.attachment = attachRef(opts.ref);
|
|
70
|
+
watch.pre([() => $state.snapshot(this.group?.opts.value.current), () => this.opts.value.current], ([groupValue, value]) => {
|
|
71
|
+
if (!groupValue || !value)
|
|
72
|
+
return;
|
|
73
|
+
this.opts.value.current = groupValue.includes(this.opts.id.current);
|
|
74
|
+
});
|
|
75
|
+
watch.pre([() => this.opts.value.current], ([value]) => {
|
|
76
|
+
if (!value)
|
|
77
|
+
return;
|
|
78
|
+
if (value) {
|
|
79
|
+
this.group?.addValue(this.opts.id.current);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.group?.removeValue(this.opts.id.current);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
props = $derived.by(() => ({
|
|
87
|
+
id: this.opts.id.current,
|
|
88
|
+
disabled: this.trueDisabled,
|
|
89
|
+
'data-disabled': getDataDisabled(this.trueDisabled),
|
|
90
|
+
...this.attachment,
|
|
91
|
+
}));
|
|
92
|
+
}
|