sdocs 0.0.1
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 +43 -0
- package/bin/sdocs.js +2 -0
- package/dist/Sdocs.svelte +1210 -0
- package/dist/Sdocs.svelte.d.ts +5 -0
- package/dist/cli/app-plugin.d.ts +7 -0
- package/dist/cli/app-plugin.js +69 -0
- package/dist/cli/config.d.ts +12 -0
- package/dist/cli/config.js +34 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +72 -0
- package/dist/cli/server.d.ts +2 -0
- package/dist/cli/server.js +62 -0
- package/dist/docgen.d.ts +47 -0
- package/dist/docgen.js +463 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/internal/ComponentPreview.svelte +58 -0
- package/dist/internal/ComponentPreview.svelte.d.ts +17 -0
- package/dist/internal/CssPropsTable.svelte +239 -0
- package/dist/internal/CssPropsTable.svelte.d.ts +11 -0
- package/dist/internal/Home.svelte +92 -0
- package/dist/internal/Home.svelte.d.ts +9 -0
- package/dist/internal/MethodsTable.svelte +72 -0
- package/dist/internal/MethodsTable.svelte.d.ts +7 -0
- package/dist/internal/PropsTable.svelte +342 -0
- package/dist/internal/PropsTable.svelte.d.ts +12 -0
- package/dist/internal/Showcase.svelte +130 -0
- package/dist/internal/Showcase.svelte.d.ts +21 -0
- package/dist/types.d.ts +162 -0
- package/dist/types.js +1 -0
- package/dist/ui/Badge/Badge.docs.svelte +46 -0
- package/dist/ui/Badge/Badge.docs.svelte.d.ts +26 -0
- package/dist/ui/Badge/Badge.svelte +59 -0
- package/dist/ui/Badge/Badge.svelte.d.ts +17 -0
- package/dist/ui/Badge/index.d.ts +1 -0
- package/dist/ui/Badge/index.js +1 -0
- package/dist/ui/Checkbox/Checkbox.docs.svelte +51 -0
- package/dist/ui/Checkbox/Checkbox.docs.svelte.d.ts +27 -0
- package/dist/ui/Checkbox/Checkbox.svelte +169 -0
- package/dist/ui/Checkbox/Checkbox.svelte.d.ts +18 -0
- package/dist/ui/Checkbox/index.d.ts +1 -0
- package/dist/ui/Checkbox/index.js +1 -0
- package/dist/ui/CodeBlock/CodeBlock.docs.svelte +28 -0
- package/dist/ui/CodeBlock/CodeBlock.docs.svelte.d.ts +24 -0
- package/dist/ui/CodeBlock/CodeBlock.svelte +101 -0
- package/dist/ui/CodeBlock/CodeBlock.svelte.d.ts +7 -0
- package/dist/ui/CodeBlock/index.d.ts +1 -0
- package/dist/ui/CodeBlock/index.js +1 -0
- package/dist/ui/Frame/Frame.docs.svelte +140 -0
- package/dist/ui/Frame/Frame.docs.svelte.d.ts +26 -0
- package/dist/ui/Frame/Frame.svelte +88 -0
- package/dist/ui/Frame/Frame.svelte.d.ts +15 -0
- package/dist/ui/Frame/index.d.ts +1 -0
- package/dist/ui/Frame/index.js +1 -0
- package/dist/ui/InputNumber/InputNumber.docs.svelte +50 -0
- package/dist/ui/InputNumber/InputNumber.docs.svelte.d.ts +26 -0
- package/dist/ui/InputNumber/InputNumber.svelte +275 -0
- package/dist/ui/InputNumber/InputNumber.svelte.d.ts +26 -0
- package/dist/ui/InputNumber/index.d.ts +1 -0
- package/dist/ui/InputNumber/index.js +1 -0
- package/dist/ui/InputText/InputText.docs.svelte +43 -0
- package/dist/ui/InputText/InputText.docs.svelte.d.ts +26 -0
- package/dist/ui/InputText/InputText.svelte +116 -0
- package/dist/ui/InputText/InputText.svelte.d.ts +22 -0
- package/dist/ui/InputText/index.d.ts +1 -0
- package/dist/ui/InputText/index.js +1 -0
- package/dist/ui/Panel/CollapsiblePanel.docs.svelte +45 -0
- package/dist/ui/Panel/CollapsiblePanel.docs.svelte.d.ts +25 -0
- package/dist/ui/Panel/CollapsiblePanel.svelte +93 -0
- package/dist/ui/Panel/CollapsiblePanel.svelte.d.ts +14 -0
- package/dist/ui/Panel/index.d.ts +1 -0
- package/dist/ui/Panel/index.js +1 -0
- package/dist/ui/Placeholder/Placeholder.docs.svelte +49 -0
- package/dist/ui/Placeholder/Placeholder.docs.svelte.d.ts +26 -0
- package/dist/ui/Placeholder/Placeholder.svelte +99 -0
- package/dist/ui/Placeholder/Placeholder.svelte.d.ts +21 -0
- package/dist/ui/Placeholder/index.d.ts +1 -0
- package/dist/ui/Placeholder/index.js +1 -0
- package/dist/ui/Radio/Radio.docs.svelte +67 -0
- package/dist/ui/Radio/Radio.docs.svelte.d.ts +27 -0
- package/dist/ui/Radio/Radio.svelte +165 -0
- package/dist/ui/Radio/Radio.svelte.d.ts +22 -0
- package/dist/ui/Radio/RadioGroup.docs.svelte +70 -0
- package/dist/ui/Radio/RadioGroup.docs.svelte.d.ts +27 -0
- package/dist/ui/Radio/RadioGroup.svelte +98 -0
- package/dist/ui/Radio/RadioGroup.svelte.d.ts +27 -0
- package/dist/ui/Radio/index.d.ts +2 -0
- package/dist/ui/Radio/index.js +2 -0
- package/dist/ui/SegmentControl/SegmentControl.docs.svelte +54 -0
- package/dist/ui/SegmentControl/SegmentControl.docs.svelte.d.ts +25 -0
- package/dist/ui/SegmentControl/SegmentControl.svelte +120 -0
- package/dist/ui/SegmentControl/SegmentControl.svelte.d.ts +18 -0
- package/dist/ui/SegmentControl/index.d.ts +1 -0
- package/dist/ui/SegmentControl/index.js +1 -0
- package/dist/ui/Stack/Stack.docs.svelte +63 -0
- package/dist/ui/Stack/Stack.docs.svelte.d.ts +26 -0
- package/dist/ui/Stack/Stack.svelte +45 -0
- package/dist/ui/Stack/Stack.svelte.d.ts +19 -0
- package/dist/ui/Stack/index.d.ts +1 -0
- package/dist/ui/Stack/index.js +1 -0
- package/dist/ui/Table/Body.svelte +17 -0
- package/dist/ui/Table/Body.svelte.d.ts +11 -0
- package/dist/ui/Table/Caption.svelte +17 -0
- package/dist/ui/Table/Caption.svelte.d.ts +11 -0
- package/dist/ui/Table/Cell.svelte +24 -0
- package/dist/ui/Table/Cell.svelte.d.ts +15 -0
- package/dist/ui/Table/Foot.svelte +17 -0
- package/dist/ui/Table/Foot.svelte.d.ts +11 -0
- package/dist/ui/Table/Head.svelte +17 -0
- package/dist/ui/Table/Head.svelte.d.ts +11 -0
- package/dist/ui/Table/Header.svelte +27 -0
- package/dist/ui/Table/Header.svelte.d.ts +17 -0
- package/dist/ui/Table/Row.svelte +19 -0
- package/dist/ui/Table/Row.svelte.d.ts +13 -0
- package/dist/ui/Table/Table.docs.svelte +197 -0
- package/dist/ui/Table/Table.docs.svelte.d.ts +28 -0
- package/dist/ui/Table/Table.svelte +140 -0
- package/dist/ui/Table/Table.svelte.d.ts +27 -0
- package/dist/ui/Table/index.js +10 -0
- package/dist/ui/css/colors.css +377 -0
- package/dist/ui/css/global.css +10 -0
- package/dist/ui/index.d.ts +12 -0
- package/dist/ui/index.js +12 -0
- package/dist/virtual-sdocs.d.ts +20 -0
- package/dist/vite-plugin.d.ts +18 -0
- package/dist/vite-plugin.js +206 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.js +2 -0
- package/package.json +76 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Radio from './Radio.svelte';
|
|
2
|
+
import type { DocMeta } from '../../types.js';
|
|
3
|
+
declare const Default: (args: any) => ReturnType<import("svelte").Snippet>;
|
|
4
|
+
declare const Sizes: () => ReturnType<import("svelte").Snippet>;
|
|
5
|
+
declare const GroupedByName: () => ReturnType<import("svelte").Snippet>;
|
|
6
|
+
declare const WithoutLabel: () => ReturnType<import("svelte").Snippet>;
|
|
7
|
+
declare const Disabled: () => ReturnType<import("svelte").Snippet>;
|
|
8
|
+
export declare const meta: DocMeta;
|
|
9
|
+
export { Default, Sizes, GroupedByName, WithoutLabel, Disabled };
|
|
10
|
+
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> {
|
|
11
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
12
|
+
$$bindings?: Bindings;
|
|
13
|
+
} & Exports;
|
|
14
|
+
(internal: unknown, props: {
|
|
15
|
+
$$events?: Events;
|
|
16
|
+
$$slots?: Slots;
|
|
17
|
+
}): Exports & {
|
|
18
|
+
$set?: any;
|
|
19
|
+
$on?: any;
|
|
20
|
+
};
|
|
21
|
+
z_$$bindings?: Bindings;
|
|
22
|
+
}
|
|
23
|
+
declare const Radio: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
24
|
+
[evt: string]: CustomEvent<any>;
|
|
25
|
+
}, {}, {}, string>;
|
|
26
|
+
type Radio = InstanceType<typeof Radio>;
|
|
27
|
+
export default Radio;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A native radio input with customizable styling. Use the name prop to group radios together.
|
|
4
|
+
*/
|
|
5
|
+
interface Props {
|
|
6
|
+
/** Whether this radio is selected */
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
/** The value of this radio */
|
|
9
|
+
value: string;
|
|
10
|
+
/** Label text */
|
|
11
|
+
label?: string;
|
|
12
|
+
/** Group name (for native radio behavior) */
|
|
13
|
+
name?: string;
|
|
14
|
+
/** Size variant */
|
|
15
|
+
size?: 'xs' | 's' | 'm' | 'l';
|
|
16
|
+
/** Disable the radio */
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
/** Callback when selected */
|
|
19
|
+
onchange?: (value: string) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let {
|
|
23
|
+
checked = false,
|
|
24
|
+
value,
|
|
25
|
+
label,
|
|
26
|
+
name,
|
|
27
|
+
size = 'm',
|
|
28
|
+
disabled = false,
|
|
29
|
+
onchange
|
|
30
|
+
}: Props = $props();
|
|
31
|
+
|
|
32
|
+
function handleChange() {
|
|
33
|
+
onchange?.(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Make checked reactive
|
|
37
|
+
let isChecked = $derived(checked);
|
|
38
|
+
|
|
39
|
+
// Size-based dimensions
|
|
40
|
+
const sizes = {
|
|
41
|
+
xs: { box: 14, dot: 6, gap: 6 },
|
|
42
|
+
s: { box: 16, dot: 7, gap: 8 },
|
|
43
|
+
m: { box: 18, dot: 8, gap: 8 },
|
|
44
|
+
l: { box: 22, dot: 10, gap: 10 }
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
let sizeConfig = $derived(sizes[size]);
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<label
|
|
51
|
+
class="Radio {size}"
|
|
52
|
+
class:disabled
|
|
53
|
+
style="--box-size: {sizeConfig.box}px; --dot-size: {sizeConfig.dot}px; --gap: {sizeConfig.gap}px;"
|
|
54
|
+
>
|
|
55
|
+
<input
|
|
56
|
+
type="radio"
|
|
57
|
+
{name}
|
|
58
|
+
{value}
|
|
59
|
+
{disabled}
|
|
60
|
+
checked={isChecked}
|
|
61
|
+
onchange={handleChange}
|
|
62
|
+
class="Radio-input"
|
|
63
|
+
/>
|
|
64
|
+
<span class="Radio-box">
|
|
65
|
+
<span class="Radio-dot"></span>
|
|
66
|
+
</span>
|
|
67
|
+
{#if label}
|
|
68
|
+
<span class="Radio-label">{label}</span>
|
|
69
|
+
{/if}
|
|
70
|
+
</label>
|
|
71
|
+
|
|
72
|
+
<style>
|
|
73
|
+
.Radio {
|
|
74
|
+
display: inline-flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
gap: var(--gap);
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
font-family: var(--font-sans);
|
|
79
|
+
color: var(--color-text);
|
|
80
|
+
transition: opacity 0.15s ease;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.Radio.disabled {
|
|
84
|
+
opacity: 0.5;
|
|
85
|
+
cursor: not-allowed;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.Radio-input {
|
|
89
|
+
position: absolute;
|
|
90
|
+
opacity: 0;
|
|
91
|
+
width: 0;
|
|
92
|
+
height: 0;
|
|
93
|
+
pointer-events: none;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.Radio-box {
|
|
97
|
+
display: flex;
|
|
98
|
+
align-items: center;
|
|
99
|
+
justify-content: center;
|
|
100
|
+
width: var(--box-size);
|
|
101
|
+
height: var(--box-size);
|
|
102
|
+
border-radius: 50%;
|
|
103
|
+
border: 1.5px solid var(--base-300);
|
|
104
|
+
background: var(--base-0);
|
|
105
|
+
transition: all 0.15s ease;
|
|
106
|
+
flex-shrink: 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.Radio:not(.disabled):hover .Radio-box {
|
|
110
|
+
border-color: var(--base-400);
|
|
111
|
+
background: var(--base-50);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.Radio-input:focus-visible + .Radio-box {
|
|
115
|
+
box-shadow: 0 0 0 2px var(--action-200);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.Radio-input:checked + .Radio-box {
|
|
119
|
+
border-color: var(--action-500);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.Radio:not(.disabled):hover .Radio-input:checked + .Radio-box {
|
|
123
|
+
border-color: var(--action-600);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.Radio-dot {
|
|
127
|
+
width: var(--dot-size);
|
|
128
|
+
height: var(--dot-size);
|
|
129
|
+
border-radius: 50%;
|
|
130
|
+
background: var(--action-500);
|
|
131
|
+
opacity: 0;
|
|
132
|
+
transform: scale(0);
|
|
133
|
+
transition: all 0.15s ease;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.Radio-input:checked + .Radio-box .Radio-dot {
|
|
137
|
+
opacity: 1;
|
|
138
|
+
transform: scale(1);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.Radio:not(.disabled):hover .Radio-input:checked + .Radio-box .Radio-dot {
|
|
142
|
+
background: var(--action-600);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.Radio-label {
|
|
146
|
+
user-select: none;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* Size-specific label font sizes */
|
|
150
|
+
.xs .Radio-label {
|
|
151
|
+
font-size: 11px;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.s .Radio-label {
|
|
155
|
+
font-size: 12px;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.m .Radio-label {
|
|
159
|
+
font-size: 13px;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.l .Radio-label {
|
|
163
|
+
font-size: 14px;
|
|
164
|
+
}
|
|
165
|
+
</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A native radio input with customizable styling. Use the name prop to group radios together.
|
|
3
|
+
*/
|
|
4
|
+
interface Props {
|
|
5
|
+
/** Whether this radio is selected */
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
/** The value of this radio */
|
|
8
|
+
value: string;
|
|
9
|
+
/** Label text */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Group name (for native radio behavior) */
|
|
12
|
+
name?: string;
|
|
13
|
+
/** Size variant */
|
|
14
|
+
size?: 'xs' | 's' | 'm' | 'l';
|
|
15
|
+
/** Disable the radio */
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/** Callback when selected */
|
|
18
|
+
onchange?: (value: string) => void;
|
|
19
|
+
}
|
|
20
|
+
declare const Radio: import("svelte").Component<Props, {}, "">;
|
|
21
|
+
type Radio = ReturnType<typeof Radio>;
|
|
22
|
+
export default Radio;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import RadioGroup from './RadioGroup.svelte';
|
|
3
|
+
import type { DocMeta } from '../../types.js';
|
|
4
|
+
|
|
5
|
+
export const meta: DocMeta = {
|
|
6
|
+
title: 'RadioGroup',
|
|
7
|
+
component: RadioGroup,
|
|
8
|
+
args: {
|
|
9
|
+
options: ['Option A', 'Option B', 'Option C'],
|
|
10
|
+
value: 'Option A',
|
|
11
|
+
size: 'm',
|
|
12
|
+
direction: 'vertical',
|
|
13
|
+
disabled: false
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { Default, Sizes, Horizontal, Disabled, WithDisabledOption };
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
{#snippet Default(args: any)}
|
|
21
|
+
<RadioGroup {...args} />
|
|
22
|
+
{/snippet}
|
|
23
|
+
|
|
24
|
+
{#snippet Sizes()}
|
|
25
|
+
<div style="display: flex; gap: 48px;">
|
|
26
|
+
<div>
|
|
27
|
+
<p style="margin: 0 0 8px; font-size: 12px; color: var(--base-500);">Extra small</p>
|
|
28
|
+
<RadioGroup options={['Yes', 'No', 'Maybe']} value="Yes" size="xs" />
|
|
29
|
+
</div>
|
|
30
|
+
<div>
|
|
31
|
+
<p style="margin: 0 0 8px; font-size: 12px; color: var(--base-500);">Small</p>
|
|
32
|
+
<RadioGroup options={['Yes', 'No', 'Maybe']} value="Yes" size="s" />
|
|
33
|
+
</div>
|
|
34
|
+
<div>
|
|
35
|
+
<p style="margin: 0 0 8px; font-size: 12px; color: var(--base-500);">Medium</p>
|
|
36
|
+
<RadioGroup options={['Yes', 'No', 'Maybe']} value="Yes" size="m" />
|
|
37
|
+
</div>
|
|
38
|
+
<div>
|
|
39
|
+
<p style="margin: 0 0 8px; font-size: 12px; color: var(--base-500);">Large</p>
|
|
40
|
+
<RadioGroup options={['Yes', 'No', 'Maybe']} value="Yes" size="l" />
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
{/snippet}
|
|
44
|
+
|
|
45
|
+
{#snippet Horizontal()}
|
|
46
|
+
<RadioGroup
|
|
47
|
+
options={['Daily', 'Weekly', 'Monthly', 'Yearly']}
|
|
48
|
+
value="Weekly"
|
|
49
|
+
direction="horizontal"
|
|
50
|
+
/>
|
|
51
|
+
{/snippet}
|
|
52
|
+
|
|
53
|
+
{#snippet Disabled()}
|
|
54
|
+
<RadioGroup
|
|
55
|
+
options={['Option 1', 'Option 2', 'Option 3']}
|
|
56
|
+
value="Option 1"
|
|
57
|
+
disabled
|
|
58
|
+
/>
|
|
59
|
+
{/snippet}
|
|
60
|
+
|
|
61
|
+
{#snippet WithDisabledOption()}
|
|
62
|
+
<RadioGroup
|
|
63
|
+
options={[
|
|
64
|
+
{ value: 'free', label: 'Free Plan' },
|
|
65
|
+
{ value: 'pro', label: 'Pro Plan' },
|
|
66
|
+
{ value: 'enterprise', label: 'Enterprise (Coming Soon)', disabled: true }
|
|
67
|
+
]}
|
|
68
|
+
value="pro"
|
|
69
|
+
/>
|
|
70
|
+
{/snippet}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import RadioGroup from './RadioGroup.svelte';
|
|
2
|
+
import type { DocMeta } from '../../types.js';
|
|
3
|
+
declare const Default: (args: any) => ReturnType<import("svelte").Snippet>;
|
|
4
|
+
declare const Sizes: () => ReturnType<import("svelte").Snippet>;
|
|
5
|
+
declare const Horizontal: () => ReturnType<import("svelte").Snippet>;
|
|
6
|
+
declare const Disabled: () => ReturnType<import("svelte").Snippet>;
|
|
7
|
+
declare const WithDisabledOption: () => ReturnType<import("svelte").Snippet>;
|
|
8
|
+
export declare const meta: DocMeta;
|
|
9
|
+
export { Default, Sizes, Horizontal, Disabled, WithDisabledOption };
|
|
10
|
+
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> {
|
|
11
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
12
|
+
$$bindings?: Bindings;
|
|
13
|
+
} & Exports;
|
|
14
|
+
(internal: unknown, props: {
|
|
15
|
+
$$events?: Events;
|
|
16
|
+
$$slots?: Slots;
|
|
17
|
+
}): Exports & {
|
|
18
|
+
$set?: any;
|
|
19
|
+
$on?: any;
|
|
20
|
+
};
|
|
21
|
+
z_$$bindings?: Bindings;
|
|
22
|
+
}
|
|
23
|
+
declare const RadioGroup: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
24
|
+
[evt: string]: CustomEvent<any>;
|
|
25
|
+
}, {}, {}, string>;
|
|
26
|
+
type RadioGroup = InstanceType<typeof RadioGroup>;
|
|
27
|
+
export default RadioGroup;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Radio from './Radio.svelte';
|
|
3
|
+
|
|
4
|
+
interface RadioOption {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A managed group of radio buttons with built-in state handling and layout options.
|
|
12
|
+
*/
|
|
13
|
+
interface Props {
|
|
14
|
+
/** Array of options to display */
|
|
15
|
+
options: RadioOption[] | string[];
|
|
16
|
+
/** Currently selected value */
|
|
17
|
+
value?: string;
|
|
18
|
+
/** Group name */
|
|
19
|
+
name?: string;
|
|
20
|
+
/** Size variant */
|
|
21
|
+
size?: 'xs' | 's' | 'm' | 'l';
|
|
22
|
+
/** Disable all radios */
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/** Layout direction */
|
|
25
|
+
direction?: 'horizontal' | 'vertical';
|
|
26
|
+
/** Callback when selection changes */
|
|
27
|
+
onchange?: (value: string) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
options,
|
|
32
|
+
value = '',
|
|
33
|
+
name,
|
|
34
|
+
size = 'm',
|
|
35
|
+
disabled = false,
|
|
36
|
+
direction = 'vertical',
|
|
37
|
+
onchange
|
|
38
|
+
}: Props = $props();
|
|
39
|
+
|
|
40
|
+
let selectedValue = $state(value);
|
|
41
|
+
|
|
42
|
+
// Sync with external changes
|
|
43
|
+
$effect(() => {
|
|
44
|
+
selectedValue = value;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Normalize options to RadioOption format
|
|
48
|
+
let normalizedOptions = $derived(
|
|
49
|
+
options.map((opt) =>
|
|
50
|
+
typeof opt === 'string' ? { value: opt, label: opt } : opt
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
function handleChange(newValue: string) {
|
|
55
|
+
selectedValue = newValue;
|
|
56
|
+
onchange?.(newValue);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Gap based on size
|
|
60
|
+
const gaps = {
|
|
61
|
+
xs: '8px',
|
|
62
|
+
s: '10px',
|
|
63
|
+
m: '12px',
|
|
64
|
+
l: '14px'
|
|
65
|
+
};
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<div
|
|
69
|
+
class="RadioGroup"
|
|
70
|
+
class:horizontal={direction === 'horizontal'}
|
|
71
|
+
role="radiogroup"
|
|
72
|
+
style="--gap: {gaps[size]};"
|
|
73
|
+
>
|
|
74
|
+
{#each normalizedOptions as option (option.value)}
|
|
75
|
+
<Radio
|
|
76
|
+
value={option.value}
|
|
77
|
+
label={option.label}
|
|
78
|
+
{name}
|
|
79
|
+
{size}
|
|
80
|
+
checked={selectedValue === option.value}
|
|
81
|
+
disabled={disabled || option.disabled}
|
|
82
|
+
onchange={handleChange}
|
|
83
|
+
/>
|
|
84
|
+
{/each}
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<style>
|
|
88
|
+
.RadioGroup {
|
|
89
|
+
display: flex;
|
|
90
|
+
flex-direction: column;
|
|
91
|
+
gap: var(--gap);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.RadioGroup.horizontal {
|
|
95
|
+
flex-direction: row;
|
|
96
|
+
flex-wrap: wrap;
|
|
97
|
+
}
|
|
98
|
+
</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface RadioOption {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A managed group of radio buttons with built-in state handling and layout options.
|
|
8
|
+
*/
|
|
9
|
+
interface Props {
|
|
10
|
+
/** Array of options to display */
|
|
11
|
+
options: RadioOption[] | string[];
|
|
12
|
+
/** Currently selected value */
|
|
13
|
+
value?: string;
|
|
14
|
+
/** Group name */
|
|
15
|
+
name?: string;
|
|
16
|
+
/** Size variant */
|
|
17
|
+
size?: 'xs' | 's' | 'm' | 'l';
|
|
18
|
+
/** Disable all radios */
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
/** Layout direction */
|
|
21
|
+
direction?: 'horizontal' | 'vertical';
|
|
22
|
+
/** Callback when selection changes */
|
|
23
|
+
onchange?: (value: string) => void;
|
|
24
|
+
}
|
|
25
|
+
declare const RadioGroup: import("svelte").Component<Props, {}, "">;
|
|
26
|
+
type RadioGroup = ReturnType<typeof RadioGroup>;
|
|
27
|
+
export default RadioGroup;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import SegmentControl from './SegmentControl.svelte';
|
|
3
|
+
import type { DocMeta } from '../../types.js';
|
|
4
|
+
|
|
5
|
+
export const meta: DocMeta = {
|
|
6
|
+
title: 'SegmentControl',
|
|
7
|
+
component: SegmentControl,
|
|
8
|
+
args: {
|
|
9
|
+
options: ['Option 1', 'Option 2', 'Option 3'],
|
|
10
|
+
value: 'Option 1',
|
|
11
|
+
size: 'm',
|
|
12
|
+
disabled: false
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { Default, Sizes, Disabled };
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
{#snippet Default(args: any)}
|
|
20
|
+
<SegmentControl {...args} />
|
|
21
|
+
{/snippet}
|
|
22
|
+
|
|
23
|
+
{#snippet Sizes()}
|
|
24
|
+
<div style="display: flex; flex-direction: column; gap: 16px;">
|
|
25
|
+
<SegmentControl
|
|
26
|
+
options={['XS', 'S', 'M', 'L']}
|
|
27
|
+
value="XS"
|
|
28
|
+
size="xs"
|
|
29
|
+
/>
|
|
30
|
+
<SegmentControl
|
|
31
|
+
options={['XS', 'S', 'M', 'L']}
|
|
32
|
+
value="S"
|
|
33
|
+
size="s"
|
|
34
|
+
/>
|
|
35
|
+
<SegmentControl
|
|
36
|
+
options={['XS', 'S', 'M', 'L']}
|
|
37
|
+
value="M"
|
|
38
|
+
size="m"
|
|
39
|
+
/>
|
|
40
|
+
<SegmentControl
|
|
41
|
+
options={['XS', 'S', 'M', 'L']}
|
|
42
|
+
value="L"
|
|
43
|
+
size="l"
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
{/snippet}
|
|
47
|
+
|
|
48
|
+
{#snippet Disabled()}
|
|
49
|
+
<SegmentControl
|
|
50
|
+
options={['One', 'Two', 'Three']}
|
|
51
|
+
value="Two"
|
|
52
|
+
disabled
|
|
53
|
+
/>
|
|
54
|
+
{/snippet}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import SegmentControl from './SegmentControl.svelte';
|
|
2
|
+
import type { DocMeta } from '../../types.js';
|
|
3
|
+
declare const Default: (args: any) => ReturnType<import("svelte").Snippet>;
|
|
4
|
+
declare const Sizes: () => ReturnType<import("svelte").Snippet>;
|
|
5
|
+
declare const Disabled: () => ReturnType<import("svelte").Snippet>;
|
|
6
|
+
export declare const meta: DocMeta;
|
|
7
|
+
export { Default, Sizes, Disabled };
|
|
8
|
+
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> {
|
|
9
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
10
|
+
$$bindings?: Bindings;
|
|
11
|
+
} & Exports;
|
|
12
|
+
(internal: unknown, props: {
|
|
13
|
+
$$events?: Events;
|
|
14
|
+
$$slots?: Slots;
|
|
15
|
+
}): Exports & {
|
|
16
|
+
$set?: any;
|
|
17
|
+
$on?: any;
|
|
18
|
+
};
|
|
19
|
+
z_$$bindings?: Bindings;
|
|
20
|
+
}
|
|
21
|
+
declare const SegmentControl: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
22
|
+
[evt: string]: CustomEvent<any>;
|
|
23
|
+
}, {}, {}, string>;
|
|
24
|
+
type SegmentControl = InstanceType<typeof SegmentControl>;
|
|
25
|
+
export default SegmentControl;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A segmented toggle control for selecting one option from a set of choices.
|
|
4
|
+
*/
|
|
5
|
+
interface Props {
|
|
6
|
+
/** Available options */
|
|
7
|
+
options: string[];
|
|
8
|
+
/** Initially selected value */
|
|
9
|
+
value?: string;
|
|
10
|
+
/** Callback when selection changes */
|
|
11
|
+
onchange?: (value: string) => void;
|
|
12
|
+
/** Size variant */
|
|
13
|
+
size?: 'xs' | 's' | 'm' | 'l';
|
|
14
|
+
/** Disable the control */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let { options, value, onchange, size = 'm', disabled = false }: Props = $props();
|
|
19
|
+
|
|
20
|
+
// Internal state, initialized from prop
|
|
21
|
+
let selected = $state(value ?? options[0]);
|
|
22
|
+
|
|
23
|
+
function select(option: string) {
|
|
24
|
+
if (disabled || option === selected) return;
|
|
25
|
+
selected = option;
|
|
26
|
+
onchange?.(option);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function handleKeydown(event: KeyboardEvent, option: string) {
|
|
30
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
select(option);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<div class="SegmentControl {size}" class:disabled role="radiogroup">
|
|
38
|
+
{#each options as option (option)}
|
|
39
|
+
<button
|
|
40
|
+
type="button"
|
|
41
|
+
class="SegmentControl-option"
|
|
42
|
+
class:selected={selected === option}
|
|
43
|
+
role="radio"
|
|
44
|
+
aria-checked={selected === option}
|
|
45
|
+
{disabled}
|
|
46
|
+
onclick={() => select(option)}
|
|
47
|
+
onkeydown={(e) => handleKeydown(e, option)}
|
|
48
|
+
>
|
|
49
|
+
{option}
|
|
50
|
+
</button>
|
|
51
|
+
{/each}
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<style>
|
|
55
|
+
.SegmentControl {
|
|
56
|
+
display: inline-flex;
|
|
57
|
+
background: var(--base-100);
|
|
58
|
+
border-radius: 8px;
|
|
59
|
+
padding: 3px;
|
|
60
|
+
gap: 2px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.SegmentControl.disabled {
|
|
64
|
+
opacity: 0.5;
|
|
65
|
+
pointer-events: none;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.SegmentControl-option {
|
|
69
|
+
font-family: var(--font-sans);
|
|
70
|
+
font-weight: 500;
|
|
71
|
+
border: none;
|
|
72
|
+
background: transparent;
|
|
73
|
+
color: var(--color-text-secondary);
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
border-radius: 6px;
|
|
76
|
+
transition: all 0.15s ease;
|
|
77
|
+
white-space: nowrap;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.SegmentControl-option:hover:not(.selected):not(:disabled) {
|
|
81
|
+
color: var(--color-text);
|
|
82
|
+
background: var(--base-50);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.SegmentControl-option.selected {
|
|
86
|
+
background: white;
|
|
87
|
+
color: var(--color-text);
|
|
88
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.SegmentControl-option:focus-visible {
|
|
92
|
+
outline: 2px solid var(--action-500);
|
|
93
|
+
outline-offset: 1px;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* Size variants - heights: xs=24px, s=28px, m=32px, l=40px (minus 6px container padding) */
|
|
97
|
+
.xs .SegmentControl-option {
|
|
98
|
+
height: 18px;
|
|
99
|
+
padding: 0 8px;
|
|
100
|
+
font-size: 11px;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.s .SegmentControl-option {
|
|
104
|
+
height: 22px;
|
|
105
|
+
padding: 0 10px;
|
|
106
|
+
font-size: 12px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.m .SegmentControl-option {
|
|
110
|
+
height: 26px;
|
|
111
|
+
padding: 0 12px;
|
|
112
|
+
font-size: 13px;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.l .SegmentControl-option {
|
|
116
|
+
height: 34px;
|
|
117
|
+
padding: 0 16px;
|
|
118
|
+
font-size: 14px;
|
|
119
|
+
}
|
|
120
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A segmented toggle control for selecting one option from a set of choices.
|
|
3
|
+
*/
|
|
4
|
+
interface Props {
|
|
5
|
+
/** Available options */
|
|
6
|
+
options: string[];
|
|
7
|
+
/** Initially selected value */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** Callback when selection changes */
|
|
10
|
+
onchange?: (value: string) => void;
|
|
11
|
+
/** Size variant */
|
|
12
|
+
size?: 'xs' | 's' | 'm' | 'l';
|
|
13
|
+
/** Disable the control */
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare const SegmentControl: import("svelte").Component<Props, {}, "">;
|
|
17
|
+
type SegmentControl = ReturnType<typeof SegmentControl>;
|
|
18
|
+
export default SegmentControl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SegmentControl } from './SegmentControl.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SegmentControl } from './SegmentControl.svelte';
|