@skeletonlabs/skeleton-svelte 1.0.0-next.9 → 1.1.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/README.md +1 -1
- package/dist/components/Accordion/Accordion.svelte +49 -52
- package/dist/components/Accordion/Accordion.svelte.d.ts +2 -14
- package/dist/components/Accordion/AccordionItem.svelte +43 -37
- package/dist/components/Accordion/AccordionItem.svelte.d.ts +2 -14
- package/dist/components/Accordion/context.js +2 -1
- package/dist/components/Accordion/index.d.ts +4 -0
- package/dist/components/Accordion/index.js +1 -1
- package/dist/components/Accordion/types.d.ts +7 -9
- package/dist/components/AppBar/AppBar.svelte +43 -40
- package/dist/components/AppBar/AppBar.svelte.d.ts +2 -14
- package/dist/components/Avatar/Avatar.svelte +56 -44
- package/dist/components/Avatar/Avatar.svelte.d.ts +2 -14
- package/dist/components/Avatar/types.d.ts +3 -3
- package/dist/components/Combobox/Combobox.svelte +144 -0
- package/dist/components/Combobox/Combobox.svelte.d.ts +18 -0
- package/dist/components/Combobox/types.d.ts +64 -0
- package/dist/components/Combobox/types.js +1 -0
- package/dist/components/FileUpload/FileUpload.svelte +70 -63
- package/dist/components/FileUpload/FileUpload.svelte.d.ts +2 -14
- package/dist/components/FileUpload/types.d.ts +3 -4
- package/dist/components/Modal/Modal.svelte +87 -0
- package/dist/components/Modal/Modal.svelte.d.ts +4 -0
- package/dist/components/Modal/types.d.ts +57 -0
- package/dist/components/Modal/types.js +1 -0
- package/dist/components/Navigation/NavBar.svelte +48 -0
- package/dist/components/Navigation/NavBar.svelte.d.ts +5 -0
- package/dist/components/Navigation/NavRail.svelte +90 -0
- package/dist/components/Navigation/NavRail.svelte.d.ts +5 -0
- package/dist/components/Navigation/NavTile.svelte +87 -0
- package/dist/components/Navigation/NavTile.svelte.d.ts +5 -0
- package/dist/components/Navigation/context.js +7 -0
- package/dist/components/Navigation/index.d.ts +6 -0
- package/dist/components/{Nav → Navigation}/index.js +1 -1
- package/dist/components/{Nav → Navigation}/types.d.ts +5 -3
- package/dist/components/Pagination/Pagination.svelte +58 -67
- package/dist/components/Pagination/Pagination.svelte.d.ts +2 -14
- package/dist/components/Pagination/types.d.ts +15 -15
- package/dist/components/Popover/Popover.svelte +78 -0
- package/dist/components/Popover/Popover.svelte.d.ts +4 -0
- package/dist/components/Popover/types.d.ts +42 -0
- package/dist/components/Popover/types.js +1 -0
- package/dist/components/Progress/Progress.svelte +44 -38
- package/dist/components/Progress/Progress.svelte.d.ts +2 -14
- package/dist/components/Progress/types.d.ts +1 -1
- package/dist/components/ProgressRing/ProgressRing.svelte +58 -46
- package/dist/components/ProgressRing/ProgressRing.svelte.d.ts +2 -14
- package/dist/components/ProgressRing/types.d.ts +3 -1
- package/dist/components/Rating/Rating.svelte +101 -57
- package/dist/components/Rating/Rating.svelte.d.ts +2 -14
- package/dist/components/Rating/types.d.ts +1 -5
- package/dist/components/Segment/Segment.svelte +59 -61
- package/dist/components/Segment/Segment.svelte.d.ts +3 -15
- package/dist/components/Segment/SegmentItem.svelte +28 -21
- package/dist/components/Segment/SegmentItem.svelte.d.ts +2 -14
- package/dist/components/Segment/context.js +3 -2
- package/dist/components/Segment/index.d.ts +4 -0
- package/dist/components/Segment/index.js +1 -1
- package/dist/components/Segment/types.d.ts +8 -10
- package/dist/components/Slider/Slider.svelte +67 -72
- package/dist/components/Slider/Slider.svelte.d.ts +2 -14
- package/dist/components/Slider/types.d.ts +5 -9
- package/dist/components/Switch/Switch.svelte +75 -90
- package/dist/components/Switch/Switch.svelte.d.ts +2 -14
- package/dist/components/Switch/types.d.ts +2 -8
- package/dist/components/Tabs/Tabs.svelte +59 -0
- package/dist/components/Tabs/Tabs.svelte.d.ts +5 -0
- package/dist/components/Tabs/TabsControl.svelte +51 -0
- package/dist/components/Tabs/TabsControl.svelte.d.ts +5 -0
- package/dist/components/Tabs/TabsPanel.svelte +23 -0
- package/dist/components/Tabs/TabsPanel.svelte.d.ts +5 -0
- package/dist/components/{Tab → Tabs}/context.js +3 -2
- package/dist/components/Tabs/index.d.ts +5 -0
- package/dist/components/{Tab → Tabs}/index.js +1 -1
- package/dist/components/{Tab → Tabs}/types.d.ts +1 -3
- package/dist/components/TagsInput/TagsInput.svelte +48 -54
- package/dist/components/TagsInput/TagsInput.svelte.d.ts +2 -14
- package/dist/components/TagsInput/types.d.ts +3 -7
- package/dist/components/Toast/Toast.svelte +68 -0
- package/dist/components/Toast/Toast.svelte.d.ts +4 -0
- package/dist/components/Toast/Toaster.svelte +68 -0
- package/dist/components/Toast/Toaster.svelte.d.ts +4 -0
- package/dist/components/Toast/create-toaster.d.ts +2 -0
- package/dist/components/Toast/create-toaster.js +5 -0
- package/dist/components/Toast/types.d.ts +43 -0
- package/dist/components/Toast/types.js +1 -0
- package/dist/components/Tooltip/Tooltip.svelte +79 -0
- package/dist/components/Tooltip/Tooltip.svelte.d.ts +4 -0
- package/dist/components/Tooltip/types.d.ts +44 -0
- package/dist/components/Tooltip/types.js +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +12 -3
- package/dist/internal/create-context.d.ts +6 -0
- package/dist/internal/create-context.js +3 -3
- package/dist/internal/test-utils.d.ts +3 -0
- package/dist/internal/test-utils.js +9 -0
- package/package.json +43 -54
- package/dist/components/Accordion/Accordion.svelte.spec.d.ts +0 -1
- package/dist/components/Accordion/Accordion.svelte.spec.js +0 -4
- package/dist/components/Nav/NavBar.svelte +0 -45
- package/dist/components/Nav/NavBar.svelte.d.ts +0 -17
- package/dist/components/Nav/NavRail.svelte +0 -79
- package/dist/components/Nav/NavRail.svelte.d.ts +0 -17
- package/dist/components/Nav/NavTile.svelte +0 -76
- package/dist/components/Nav/NavTile.svelte.d.ts +0 -17
- package/dist/components/Nav/context.js +0 -7
- package/dist/components/Tab/Tabs.svelte +0 -65
- package/dist/components/Tab/Tabs.svelte.d.ts +0 -17
- package/dist/components/Tab/TabsControl.svelte +0 -42
- package/dist/components/Tab/TabsControl.svelte.d.ts +0 -17
- package/dist/components/Tab/TabsPanel.svelte +0 -18
- package/dist/components/Tab/TabsPanel.svelte.d.ts +0 -17
- package/dist/internal/noop.d.ts +0 -1
- package/dist/internal/noop.js +0 -2
- package/dist/internal/snippets.d.ts +0 -3
- package/dist/internal/snippets.js +0 -45
- package/dist/internal/use-id.d.ts +0 -2
- package/dist/internal/use-id.js +0 -5
- /package/dist/components/{Nav → Navigation}/context.d.ts +0 -0
- /package/dist/components/{Nav → Navigation}/types.js +0 -0
- /package/dist/components/{Tab → Tabs}/context.d.ts +0 -0
- /package/dist/components/{Tab → Tabs}/types.js +0 -0
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { SegmentItemProps } from './types.js';
|
|
3
|
+
import { getSegmentContext } from './context.js';
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
// Root
|
|
7
|
+
base = 'btn cursor-pointer z-[1]',
|
|
8
|
+
classes = '',
|
|
9
|
+
// State
|
|
10
|
+
stateDisabled = 'disabled',
|
|
11
|
+
stateFocused = 'focused',
|
|
12
|
+
// Label
|
|
13
|
+
labelBase = 'pointer-events-none transition-colors duration-100',
|
|
14
|
+
labelClasses = '',
|
|
15
|
+
// Snippets
|
|
16
|
+
children,
|
|
17
|
+
// Zag
|
|
18
|
+
...zagProps
|
|
19
|
+
}: SegmentItemProps = $props();
|
|
20
|
+
|
|
21
|
+
// Context
|
|
22
|
+
const ctx = getSegmentContext();
|
|
23
|
+
|
|
24
|
+
// Reactive
|
|
25
|
+
const state = $derived(ctx.api.getItemState(zagProps));
|
|
26
|
+
const rxDisabled = $derived(state.disabled ? stateDisabled : '');
|
|
27
|
+
const rxActiveText = $derived(state.checked ? ctx.indicatorText : '');
|
|
28
|
+
const rxFocused = $derived(state.focused ? stateFocused : '');
|
|
22
29
|
</script>
|
|
23
30
|
|
|
24
31
|
<!-- @component An individual Segment option. -->
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import type { SegmentItemProps } from './types.js';
|
|
2
|
-
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> {
|
|
3
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports;
|
|
10
|
-
z_$$bindings?: Bindings;
|
|
11
|
-
}
|
|
12
2
|
/** An individual Segment option. */
|
|
13
|
-
declare const SegmentItem:
|
|
14
|
-
|
|
15
|
-
}, {}, {}, "">;
|
|
16
|
-
type SegmentItem = InstanceType<typeof SegmentItem>;
|
|
3
|
+
declare const SegmentItem: import("svelte").Component<SegmentItemProps, {}, "">;
|
|
4
|
+
type SegmentItem = ReturnType<typeof SegmentItem>;
|
|
17
5
|
export default SegmentItem;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
var _a;
|
|
1
2
|
import * as radio from '@zag-js/radio-group';
|
|
2
3
|
import { createContext } from '../../internal/create-context.js';
|
|
3
|
-
export
|
|
4
|
+
export var setSegmentContext = (_a = createContext({
|
|
4
5
|
api: {},
|
|
5
6
|
indicatorText: ''
|
|
6
|
-
});
|
|
7
|
+
}), _a[0]), getSegmentContext = _a[1], key = _a[2];
|
|
@@ -4,11 +4,7 @@ export interface SegmentContext {
|
|
|
4
4
|
api: ReturnType<typeof radio.connect>;
|
|
5
5
|
indicatorText: string;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
8
|
-
/** Set the active value. */
|
|
9
|
-
value?: string;
|
|
10
|
-
/** Set the orientation. */
|
|
11
|
-
orientation?: 'horizontal' | 'vertical' | undefined;
|
|
7
|
+
export interface SegmentProps extends Omit<radio.Props, 'id'> {
|
|
12
8
|
/** Sets base classes. */
|
|
13
9
|
base?: string;
|
|
14
10
|
/** Set background classes. */
|
|
@@ -29,11 +25,11 @@ export interface SegmentControl extends Omit<radio.Context, 'id' | 'orientation'
|
|
|
29
25
|
classes?: string;
|
|
30
26
|
/** Set classes to provide a vertical layout. */
|
|
31
27
|
orientVertical?: string;
|
|
32
|
-
/** Set classes to provide a
|
|
28
|
+
/** Set classes to provide a horizontal layout. */
|
|
33
29
|
orientHorizontal?: string;
|
|
34
|
-
/** Set
|
|
30
|
+
/** Set classes for the disabled state. */
|
|
35
31
|
stateDisabled?: string;
|
|
36
|
-
/** Set
|
|
32
|
+
/** Set classes for the read-only state. */
|
|
37
33
|
stateReadOnly?: string;
|
|
38
34
|
/** Sets base classes to the indicator. */
|
|
39
35
|
indicatorBase?: string;
|
|
@@ -45,6 +41,8 @@ export interface SegmentControl extends Omit<radio.Context, 'id' | 'orientation'
|
|
|
45
41
|
indicatorRounded?: string;
|
|
46
42
|
/** Provide arbitrary CSS classes to the indicator. */
|
|
47
43
|
indicatorClasses?: string;
|
|
44
|
+
/** Set aria-labelledby for element */
|
|
45
|
+
labelledby?: string;
|
|
48
46
|
/** The default child slot. */
|
|
49
47
|
children?: Snippet;
|
|
50
48
|
}
|
|
@@ -53,9 +51,9 @@ export interface SegmentItemProps extends Omit<radio.ItemProps, 'invalid'> {
|
|
|
53
51
|
base?: string;
|
|
54
52
|
/** Provide arbitrary CSS classes. */
|
|
55
53
|
classes?: string;
|
|
56
|
-
/** Set
|
|
54
|
+
/** Set classes for the disabled state. */
|
|
57
55
|
stateDisabled?: string;
|
|
58
|
-
/** Set
|
|
56
|
+
/** Set classes for the focus state. */
|
|
59
57
|
stateFocused?: string;
|
|
60
58
|
/** Sets base classes for the label element. */
|
|
61
59
|
labelBase?: string;
|
|
@@ -1,72 +1,65 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} = $props();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
const api = $derived(slider.connect(snapshot, send, normalizeProps));
|
|
68
|
-
const rxDisabled = $derived(snapshot.context.disabled ? stateDisabled : "");
|
|
69
|
-
const rxReadOnly = $derived(snapshot.context.readOnly ? stateReadOnly : `${thumbScale} ${thumbCursor}`);
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import * as slider from '@zag-js/slider';
|
|
3
|
+
import { normalizeProps, useMachine } from '@zag-js/svelte';
|
|
4
|
+
import type { SliderProps } from './types.js';
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
markers = [],
|
|
8
|
+
height = 'h-1.5',
|
|
9
|
+
// Root ---
|
|
10
|
+
base = 'w-full bg-green',
|
|
11
|
+
spaceY = '',
|
|
12
|
+
classes = '',
|
|
13
|
+
// Control ---
|
|
14
|
+
controlBase = '',
|
|
15
|
+
controlClasses = '',
|
|
16
|
+
// Track ---
|
|
17
|
+
trackBase = 'overflow-hidden',
|
|
18
|
+
trackBg = 'bg-surface-200-800',
|
|
19
|
+
trackRounded = 'rounded-full',
|
|
20
|
+
trackClasses = '',
|
|
21
|
+
// Meter ---
|
|
22
|
+
meterBase = '',
|
|
23
|
+
meterBg = 'bg-surface-950-50',
|
|
24
|
+
meterRounded = 'rounded-container',
|
|
25
|
+
meterClasses = '',
|
|
26
|
+
// Thumb ---
|
|
27
|
+
thumbBase = 'ring-inset transition-scale duration-100 ease-in-out',
|
|
28
|
+
thumbSize = 'size-8 md:size-5',
|
|
29
|
+
thumbBg = 'bg-surface-50-950',
|
|
30
|
+
thumbRingSize = 'ring-2',
|
|
31
|
+
thumbRingColor = 'ring-surface-950-50',
|
|
32
|
+
thumbRounded = 'rounded-full',
|
|
33
|
+
thumbCursor = 'hover:cursor-pointer',
|
|
34
|
+
thumbClasses = '',
|
|
35
|
+
// Markers ---
|
|
36
|
+
markersBase = '',
|
|
37
|
+
markersClasses = '',
|
|
38
|
+
// Mark ---
|
|
39
|
+
markBase = '',
|
|
40
|
+
markText = 'text-[10px]',
|
|
41
|
+
markOpacity = 'opacity-50',
|
|
42
|
+
markClasses = '',
|
|
43
|
+
// State ---
|
|
44
|
+
stateDisabled = 'disabled',
|
|
45
|
+
stateReadOnly = 'cursor-not-allowed',
|
|
46
|
+
// Children ---
|
|
47
|
+
mark,
|
|
48
|
+
// Zag ---
|
|
49
|
+
...zagProps
|
|
50
|
+
}: SliderProps = $props();
|
|
51
|
+
|
|
52
|
+
// Zag
|
|
53
|
+
const id = $props.id();
|
|
54
|
+
const service = useMachine(slider.machine, () => ({
|
|
55
|
+
id: id,
|
|
56
|
+
...zagProps
|
|
57
|
+
}));
|
|
58
|
+
const api = $derived(slider.connect(service, normalizeProps));
|
|
59
|
+
|
|
60
|
+
// Reactive
|
|
61
|
+
const rxDisabled = $derived(service.prop('disabled') ? stateDisabled : '');
|
|
62
|
+
const rxReadOnly = $derived(service.prop('readOnly') ? stateReadOnly : thumbCursor);
|
|
70
63
|
</script>
|
|
71
64
|
|
|
72
65
|
<div {...api.getRootProps()} class="{base} {height} {spaceY} {rxDisabled} {classes}" data-testid="slider">
|
|
@@ -75,10 +68,12 @@ const rxReadOnly = $derived(snapshot.context.readOnly ? stateReadOnly : `${thumb
|
|
|
75
68
|
<!-- Track -->
|
|
76
69
|
<div {...api.getTrackProps()} class="{trackBase} {trackBg} {height} {trackRounded} {trackClasses}" data-testid="slider-track">
|
|
77
70
|
<!-- Meter -->
|
|
78
|
-
<div {...api.getRangeProps()} class="{meterBase} {height} {meterBg} {
|
|
71
|
+
<div {...api.getRangeProps()} class="{meterBase} {height} {meterBg} {meterRounded} {meterClasses}" data-testid="slider-meter"></div>
|
|
79
72
|
</div>
|
|
80
73
|
<!-- NOTE: this div centers thumbs vertically -->
|
|
81
74
|
<div class={height} style="display: flex; align-items: center; transform: translateY(-100%);" data-testid="slider-thumb-wrapper">
|
|
75
|
+
<!-- Disabled: skipping this so we can match Zag implementation. -->
|
|
76
|
+
<!-- eslint-disable @typescript-eslint/no-unused-vars -->
|
|
82
77
|
{#each api.value as _, index}
|
|
83
78
|
<div {...api.getThumbProps({ index })}>
|
|
84
79
|
<!-- Thumb -->
|
|
@@ -94,12 +89,12 @@ const rxReadOnly = $derived(snapshot.context.readOnly ? stateReadOnly : `${thumb
|
|
|
94
89
|
</div>
|
|
95
90
|
<!-- Markers -->
|
|
96
91
|
{#if markers.length > 0}
|
|
97
|
-
<div {...api.getMarkerGroupProps()} class="{markersBase} {
|
|
92
|
+
<div {...api.getMarkerGroupProps()} class="{markersBase} {markersClasses}" data-testid="slider-markers">
|
|
98
93
|
{#each markers as value}
|
|
99
94
|
<!-- Mark -->
|
|
100
95
|
<span {...api.getMarkerProps({ value })} class="{markBase} {markText} {markOpacity} {markClasses}" data-testid="slider-mark">
|
|
101
96
|
{#if mark}
|
|
102
|
-
{@render mark()}
|
|
97
|
+
{@render mark(value)}
|
|
103
98
|
{:else}
|
|
104
99
|
{value}
|
|
105
100
|
{/if}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
import type { SliderProps } from './types.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports;
|
|
10
|
-
z_$$bindings?: Bindings;
|
|
11
|
-
}
|
|
12
|
-
declare const Slider: $$__sveltets_2_IsomorphicComponent<SliderProps, {
|
|
13
|
-
[evt: string]: CustomEvent<any>;
|
|
14
|
-
}, {}, {}, "value">;
|
|
15
|
-
type Slider = InstanceType<typeof Slider>;
|
|
2
|
+
declare const Slider: import("svelte").Component<SliderProps, {}, "">;
|
|
3
|
+
type Slider = ReturnType<typeof Slider>;
|
|
16
4
|
export default Slider;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as slider from '@zag-js/slider';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
export interface SliderProps extends Omit<slider.
|
|
4
|
-
/** Provide the value as an array. */
|
|
5
|
-
value?: number[];
|
|
3
|
+
export interface SliderProps extends Omit<slider.Props, 'id' | 'thumbSize'> {
|
|
6
4
|
/** Provide an array of value markers */
|
|
7
5
|
markers?: number[];
|
|
8
6
|
/** Set height classes for the overall slider. */
|
|
@@ -30,7 +28,7 @@ export interface SliderProps extends Omit<slider.Context, 'id' | 'thumbSize'> {
|
|
|
30
28
|
/** Set background classes for the meter. */
|
|
31
29
|
meterBg?: string;
|
|
32
30
|
/** Set border radius classes for the meter. */
|
|
33
|
-
|
|
31
|
+
meterRounded?: string;
|
|
34
32
|
/** Provide arbitrary classes for the meter. */
|
|
35
33
|
meterClasses?: string;
|
|
36
34
|
/** Set base classes for the thumb. */
|
|
@@ -45,8 +43,6 @@ export interface SliderProps extends Omit<slider.Context, 'id' | 'thumbSize'> {
|
|
|
45
43
|
thumbRingColor?: string;
|
|
46
44
|
/** Set border-radius classes for the thumb. */
|
|
47
45
|
thumbRounded?: string;
|
|
48
|
-
/** Set scale classes for the thumb. */
|
|
49
|
-
thumbScale?: string;
|
|
50
46
|
/** Set cursor classes for the thumb. */
|
|
51
47
|
thumbCursor?: string;
|
|
52
48
|
/** Provide arbitrary classes for the thumb. */
|
|
@@ -54,7 +50,7 @@ export interface SliderProps extends Omit<slider.Context, 'id' | 'thumbSize'> {
|
|
|
54
50
|
/** Set base classes for the markers. */
|
|
55
51
|
markersBase?: string;
|
|
56
52
|
/** Provide arbitrary classes for the markers. */
|
|
57
|
-
|
|
53
|
+
markersClasses?: string;
|
|
58
54
|
/** Set base classes for each mark. */
|
|
59
55
|
markBase?: string;
|
|
60
56
|
/** Set text size classes for each mark. */
|
|
@@ -67,6 +63,6 @@ export interface SliderProps extends Omit<slider.Context, 'id' | 'thumbSize'> {
|
|
|
67
63
|
stateDisabled?: string;
|
|
68
64
|
/** Set read-only state classes for the root element. */
|
|
69
65
|
stateReadOnly?: string;
|
|
70
|
-
/** Replace numeric markers with symbol, such as a icon. */
|
|
71
|
-
mark?: Snippet
|
|
66
|
+
/** Replace numeric markers with symbol, such as a icon. Takes marker value as argument. */
|
|
67
|
+
mark?: Snippet<[number]>;
|
|
72
68
|
}
|
|
@@ -1,97 +1,80 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
const api = $derived(zagSwitch.connect(snapshot, send, normalizeProps));
|
|
72
|
-
if (compact) {
|
|
73
|
-
controlBase = thumbBase;
|
|
74
|
-
controlHeight = "";
|
|
75
|
-
thumbInactive = controlInactive;
|
|
76
|
-
thumbActive = controlActive;
|
|
77
|
-
thumbTranslateX = "";
|
|
78
|
-
controlPadding = "";
|
|
79
|
-
}
|
|
80
|
-
const rxTrackState = $derived(api.checked ? controlActive : controlInactive);
|
|
81
|
-
const rxThumbState = $derived(api.checked ? `${thumbActive} ${thumbTranslateX}` : thumbInactive);
|
|
82
|
-
const rxDisabled = $derived(api.disabled ? controlDisabled : "");
|
|
83
|
-
const rxFocused = $derived(api.focused ? stateFocused : "");
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { normalizeProps, useMachine } from '@zag-js/svelte';
|
|
3
|
+
import * as zagSwitch from '@zag-js/switch';
|
|
4
|
+
import type { SwitchProps } from './types.js';
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
compact = false,
|
|
8
|
+
// Root (Track)
|
|
9
|
+
base = 'inline-flex items-center gap-4',
|
|
10
|
+
classes = '',
|
|
11
|
+
// State
|
|
12
|
+
stateFocused = 'data-[focus-visible]:focused',
|
|
13
|
+
// Control
|
|
14
|
+
controlBase = 'cursor-pointer transition duration-200',
|
|
15
|
+
controlInactive = 'preset-filled-surface-200-800',
|
|
16
|
+
controlActive = 'preset-filled-primary-500',
|
|
17
|
+
controlDisabled = 'opacity-50 cursor-not-allowed',
|
|
18
|
+
controlWidth = 'w-10',
|
|
19
|
+
controlHeight = 'h-6',
|
|
20
|
+
controlPadding = 'p-0.5',
|
|
21
|
+
controlRounded = 'rounded-full',
|
|
22
|
+
controlHover = 'hover:brightness-90 dark:hover:brightness-110',
|
|
23
|
+
controlClasses = '',
|
|
24
|
+
// Thumb
|
|
25
|
+
thumbBase = 'right-0 aspect-square h-full flex justify-center items-center text-right cursor-pointer',
|
|
26
|
+
thumbInactive = 'preset-filled-surface-50-950',
|
|
27
|
+
thumbActive = 'bg-surface-50 text-surface-contrast-50',
|
|
28
|
+
thumbRounded = 'rounded-full',
|
|
29
|
+
thumbTranslateX = 'translate-x-4 rtl:-translate-x-4',
|
|
30
|
+
thumbTransition = 'transition',
|
|
31
|
+
thumbEase = 'ease-in-out',
|
|
32
|
+
thumbDuration = 'duration-200',
|
|
33
|
+
thumbClasses = '',
|
|
34
|
+
// Label
|
|
35
|
+
labelBase = '',
|
|
36
|
+
labelClasses = '',
|
|
37
|
+
// Icons
|
|
38
|
+
iconInactiveBase = 'pointer-events-none',
|
|
39
|
+
iconActiveBase = 'pointer-events-none',
|
|
40
|
+
// Snippets
|
|
41
|
+
children,
|
|
42
|
+
inactiveChild,
|
|
43
|
+
activeChild,
|
|
44
|
+
// ZagProps
|
|
45
|
+
...zagProps
|
|
46
|
+
}: SwitchProps = $props();
|
|
47
|
+
|
|
48
|
+
// Zag
|
|
49
|
+
const id = $props.id();
|
|
50
|
+
const service = useMachine(zagSwitch.machine, () => ({
|
|
51
|
+
id: id,
|
|
52
|
+
...zagProps
|
|
53
|
+
}));
|
|
54
|
+
const api = $derived(zagSwitch.connect(service, normalizeProps));
|
|
55
|
+
|
|
56
|
+
const rxControlBase = $derived(compact ? thumbBase : controlBase);
|
|
57
|
+
const rxControlHeight = $derived(compact ? '' : controlHeight);
|
|
58
|
+
const rxControlPadding = $derived(compact ? '' : controlPadding);
|
|
59
|
+
const rxThumbInactive = $derived(compact ? controlInactive : thumbInactive);
|
|
60
|
+
const rxThumbActive = $derived(compact ? controlActive : thumbActive);
|
|
61
|
+
const rxThumbTranslateX = $derived(compact ? '' : thumbTranslateX);
|
|
62
|
+
|
|
63
|
+
const rxTrackState = $derived(api.checked ? controlActive : controlInactive);
|
|
64
|
+
const rxThumbState = $derived(api.checked ? `${rxThumbActive} ${rxThumbTranslateX}` : rxThumbInactive);
|
|
65
|
+
const rxDisabled = $derived(api.disabled ? controlDisabled : '');
|
|
66
|
+
const rxFocused = $derived(api.focused ? stateFocused : '');
|
|
84
67
|
</script>
|
|
85
68
|
|
|
86
69
|
<!-- @component A control for toggling between checked states. -->
|
|
87
70
|
|
|
88
|
-
<label {...api.getRootProps()} class="{base} {
|
|
71
|
+
<label {...api.getRootProps()} class="{base} {classes}" data-testid="switch">
|
|
89
72
|
<!-- Input -->
|
|
90
73
|
<input {...api.getHiddenInputProps()} data-testid="switch-input" />
|
|
91
74
|
<!-- Control -->
|
|
92
75
|
<span
|
|
93
76
|
{...api.getControlProps()}
|
|
94
|
-
class="{
|
|
77
|
+
class="{rxControlBase} {rxTrackState} {rxFocused} {controlWidth} {rxControlHeight} {rxControlPadding} {controlRounded} {controlHover} {rxDisabled} {controlClasses}"
|
|
95
78
|
data-testid="switch-control"
|
|
96
79
|
>
|
|
97
80
|
<!-- Thumb -->
|
|
@@ -101,17 +84,19 @@ const rxFocused = $derived(api.focused ? stateFocused : "");
|
|
|
101
84
|
data-testid="switch-thumb"
|
|
102
85
|
>
|
|
103
86
|
<!-- Icon: Inactive -->
|
|
104
|
-
{#if !checked && inactiveChild}
|
|
87
|
+
{#if !api.checked && inactiveChild}
|
|
105
88
|
<span class={iconInactiveBase} data-testid="switch-icon-inactive">{@render inactiveChild()}</span>
|
|
106
89
|
{/if}
|
|
107
90
|
<!-- Icon: Active -->
|
|
108
|
-
{#if checked && activeChild}
|
|
91
|
+
{#if api.checked && activeChild}
|
|
109
92
|
<span class={iconActiveBase} data-testid="switch-icon-active">{@render activeChild()}</span>
|
|
110
93
|
{/if}
|
|
111
94
|
</span>
|
|
112
95
|
</span>
|
|
113
96
|
<!-- Label -->
|
|
114
|
-
|
|
115
|
-
{
|
|
116
|
-
|
|
97
|
+
{#if children}
|
|
98
|
+
<span {...api.getLabelProps()} class="{labelBase} {labelClasses}" data-testid="switch-label">
|
|
99
|
+
{@render children()}
|
|
100
|
+
</span>
|
|
101
|
+
{/if}
|
|
117
102
|
</label>
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import type { SwitchProps } from './types.js';
|
|
2
|
-
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> {
|
|
3
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports;
|
|
10
|
-
z_$$bindings?: Bindings;
|
|
11
|
-
}
|
|
12
2
|
/** A control for toggling between checked states. */
|
|
13
|
-
declare const Switch:
|
|
14
|
-
|
|
15
|
-
}, {}, {}, "disabled" | "checked" | "compact">;
|
|
16
|
-
type Switch = InstanceType<typeof Switch>;
|
|
3
|
+
declare const Switch: import("svelte").Component<SwitchProps, {}, "">;
|
|
4
|
+
type Switch = ReturnType<typeof Switch>;
|
|
17
5
|
export default Switch;
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import * as zagSwitch from '@zag-js/switch';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
export interface SwitchProps extends Omit<zagSwitch.
|
|
4
|
-
/** Set a unique name for the switch input. */
|
|
5
|
-
name: string;
|
|
6
|
-
/** Set the checked state. */
|
|
7
|
-
checked?: boolean;
|
|
8
|
-
/** Set the disabled state. */
|
|
9
|
-
disabled?: boolean;
|
|
3
|
+
export interface SwitchProps extends Omit<zagSwitch.Props, 'id'> {
|
|
10
4
|
/** Set the compact display mode. */
|
|
11
5
|
compact?: boolean;
|
|
12
6
|
/** Set base classes for the root element. */
|
|
13
7
|
base?: string;
|
|
14
8
|
/** Provide arbitrary classes to the root element. */
|
|
15
9
|
classes?: string;
|
|
16
|
-
/** Set
|
|
10
|
+
/** Set classes for the focus state. */
|
|
17
11
|
stateFocused?: string;
|
|
18
12
|
/** Set base classes for the control element. */
|
|
19
13
|
controlBase?: string;
|