@svelte-atoms/core 1.0.0-alpha.29 → 1.0.0-alpha.30
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 +852 -852
- package/dist/attachments/clickout.svelte.d.ts +1 -1
- package/dist/attachments/clickout.svelte.js +2 -2
- package/dist/components/accordion/accordion-root.svelte +61 -61
- package/dist/components/accordion/accordion-root.svelte.d.ts +1 -1
- package/dist/components/accordion/accordion.stories.svelte +145 -134
- package/dist/components/alert/alert.stories.svelte +400 -401
- package/dist/components/atom/html-atom.svelte +71 -17
- package/dist/components/avatar/avatar.stories.svelte +22 -27
- package/dist/components/badge/badge.stories.svelte +12 -17
- package/dist/components/badge/badge.svelte +19 -19
- package/dist/components/breadcrumb/breadcrumb.stories.svelte +16 -21
- package/dist/components/button/button.stories.svelte +27 -60
- package/dist/components/calendar/calendar-day.svelte +96 -96
- package/dist/components/calendar/calendar-header.svelte +29 -29
- package/dist/components/calendar/calendar-root.svelte +206 -206
- package/dist/components/calendar/calendar.stories.svelte +10 -15
- package/dist/components/card/card-body.svelte +39 -39
- package/dist/components/card/card-footer.svelte +41 -41
- package/dist/components/card/card-root.svelte +91 -91
- package/dist/components/card/card.stories.svelte +133 -145
- package/dist/components/checkbox/checkbox.stories.svelte +22 -27
- package/dist/components/checkbox/checkbox.svelte +155 -157
- package/dist/components/collapsible/collapsible.stories.svelte +172 -173
- package/dist/components/combobox/combobox-root.svelte +65 -65
- package/dist/components/combobox/compobox.stories.svelte +51 -54
- package/dist/components/container/container.stories.svelte +20 -23
- package/dist/components/datagrid/datagrid-root.svelte +59 -59
- package/dist/components/datagrid/datagrid.css +5 -5
- package/dist/components/datagrid/datagrid.stories.svelte +72 -75
- package/dist/components/date-picker/date-picker-calendar.svelte +67 -67
- package/dist/components/date-picker/date-picker-header.svelte +100 -100
- package/dist/components/date-picker/date-picker-months.svelte +142 -142
- package/dist/components/date-picker/date-picker-root.svelte +1 -1
- package/dist/components/date-picker/date-picker-years.svelte +205 -205
- package/dist/components/date-picker/date-picker.stories.svelte +11 -18
- package/dist/components/dialog/dialog-content.svelte +62 -62
- package/dist/components/dialog/dialog.stories.svelte +64 -67
- package/dist/components/drawer/attachments.svelte.js +8 -9
- package/dist/components/drawer/drawer-content.svelte +57 -42
- package/dist/components/drawer/drawer.stories.svelte +212 -224
- package/dist/components/dropdown/dropdown-root.svelte +59 -59
- package/dist/components/dropdown/dropdown.stories.svelte +80 -83
- package/dist/components/form/form.stories.svelte +96 -99
- package/dist/components/image/image.stories.svelte +20 -23
- package/dist/components/input/input.stories.svelte +35 -38
- package/dist/components/label/label.stories.svelte +15 -26
- package/dist/components/label/label.stories.svelte.d.ts +24 -4
- package/dist/components/lazy/lazy.stories.svelte +9 -16
- package/dist/components/lazy/lazy.svelte +28 -28
- package/dist/components/link/link.stories.svelte +15 -26
- package/dist/components/link/link.stories.svelte.d.ts +24 -4
- package/dist/components/menu/menu-list.svelte +40 -40
- package/dist/components/menu/menu.stories.svelte +33 -36
- package/dist/components/popover/bond.svelte.js +31 -25
- package/dist/components/popover/popover-arrow.svelte +111 -111
- package/dist/components/popover/popover-content.svelte +175 -178
- package/dist/components/popover/popover-indicator.svelte +44 -43
- package/dist/components/popover/popover-root.svelte +48 -48
- package/dist/components/popover/popover.stories.svelte +49 -52
- package/dist/components/qr-code/qr-code.stories.svelte +4 -13
- package/dist/components/qr-code/qr-code.svelte +75 -75
- package/dist/components/radio/radio-group.stories.svelte +41 -50
- package/dist/components/radio/radio.stories.svelte +17 -26
- package/dist/components/radio/radio.svelte +109 -109
- package/dist/components/root/root.svelte +121 -121
- package/dist/components/root/root.svelte.d.ts +1 -1
- package/dist/components/scrollable/scrollable.stories.svelte +116 -126
- package/dist/components/sidebar/sidebar-content.svelte +13 -2
- package/dist/components/sidebar/sidebar-root.svelte +10 -12
- package/dist/components/sidebar/sidebar.stories.svelte +8 -19
- package/dist/components/sidebar/types.d.ts +1 -0
- package/dist/components/tabs/tab/bond.svelte.d.ts +4 -1
- package/dist/components/tabs/tab/bond.svelte.js +4 -1
- package/dist/components/tabs/tabs.stories.svelte +56 -59
- package/dist/components/tooltip/tooltip-trigger.svelte +39 -37
- package/dist/components/tooltip/tooltip.stories.svelte +32 -35
- package/dist/components/tree/tree.stories.svelte +142 -134
- package/dist/context/preset.svelte.d.ts +3 -3
- package/dist/utils/function.d.ts +2 -0
- package/dist/utils/function.js +6 -0
- package/package.json +6 -9
- package/dist/actions/animation.svelte.d.ts +0 -6
- package/dist/actions/animation.svelte.js +0 -14
- package/dist/actions/clickout.svelte.d.ts +0 -2
- package/dist/actions/clickout.svelte.js +0 -15
- package/dist/actions/popover.svelte.d.ts +0 -19
- package/dist/actions/popover.svelte.js +0 -81
- package/dist/actions/portal.svelte.d.ts +0 -8
- package/dist/actions/portal.svelte.js +0 -32
- package/dist/attachments/gsap.svelte.d.ts +0 -2
- package/dist/attachments/gsap.svelte.js +0 -26
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script module>
|
|
2
2
|
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
3
|
import QrCodeComponent from './qr-code.svelte';
|
|
4
|
-
import { Root } from '../root';
|
|
5
4
|
|
|
6
5
|
const { Story } = defineMeta({
|
|
7
6
|
title: 'Atoms/QR Code'
|
|
@@ -12,16 +11,8 @@
|
|
|
12
11
|
</script>
|
|
13
12
|
|
|
14
13
|
<Story name="QR Code">
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<QrCodeComponent
|
|
20
|
-
class="text-primary-foreground bg-primary size-64 rounded-2xl p-1"
|
|
21
|
-
value="Hello World 123"
|
|
22
|
-
/>
|
|
23
|
-
</div>
|
|
24
|
-
{/snippet}
|
|
25
|
-
</Root>
|
|
26
|
-
{/snippet}
|
|
14
|
+
<QrCodeComponent
|
|
15
|
+
class="text-primary-foreground bg-primary size-64 rounded-2xl p-1"
|
|
16
|
+
value="Hello World 123"
|
|
17
|
+
/>
|
|
27
18
|
</Story>
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { QRCodeBrowser } from '@qrcode-js/browser';
|
|
3
|
-
import { HtmlAtom } from '../atom';
|
|
4
|
-
import type { QRCodeProps } from './types';
|
|
5
|
-
|
|
6
|
-
type Render = typeof QRCodeBrowser;
|
|
7
|
-
|
|
8
|
-
let {
|
|
9
|
-
class: klass = '',
|
|
10
|
-
value = '',
|
|
11
|
-
finder = {
|
|
12
|
-
round: 0.5
|
|
13
|
-
},
|
|
14
|
-
dots = {
|
|
15
|
-
scale: 0.75,
|
|
16
|
-
round: 1
|
|
17
|
-
},
|
|
18
|
-
drawFunction = 'telegram',
|
|
19
|
-
gradient = undefined,
|
|
20
|
-
logo = undefined,
|
|
21
|
-
margin = undefined,
|
|
22
|
-
qr = undefined,
|
|
23
|
-
...restProps
|
|
24
|
-
}: QRCodeProps = $props();
|
|
25
|
-
|
|
26
|
-
let canvasElement: HTMLCanvasElement | undefined = $state();
|
|
27
|
-
|
|
28
|
-
let clientWidth = $state(0);
|
|
29
|
-
let isReady = $state(false);
|
|
30
|
-
let render: Render | undefined = $state();
|
|
31
|
-
let computedColor = $state('black');
|
|
32
|
-
|
|
33
|
-
import('@qrcode-js/browser').then((result) => {
|
|
34
|
-
render = result.QRCodeBrowser;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
$effect(() => {
|
|
38
|
-
if (!canvasElement) return;
|
|
39
|
-
if (!render) return;
|
|
40
|
-
if (!isReady) render;
|
|
41
|
-
|
|
42
|
-
// Get the computed color from the canvas element
|
|
43
|
-
computedColor = getComputedStyle(canvasElement).color;
|
|
44
|
-
|
|
45
|
-
const qrcode = render(canvasElement);
|
|
46
|
-
|
|
47
|
-
qrcode.setOptions({
|
|
48
|
-
text: value,
|
|
49
|
-
size: clientWidth,
|
|
50
|
-
color: computedColor,
|
|
51
|
-
dots,
|
|
52
|
-
finder,
|
|
53
|
-
drawFunction,
|
|
54
|
-
...(gradient && { gradient }),
|
|
55
|
-
...(margin && { margin }),
|
|
56
|
-
...(logo && { logo }),
|
|
57
|
-
...(qr && { qr })
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
qrcode.draw();
|
|
61
|
-
});
|
|
62
|
-
</script>
|
|
63
|
-
|
|
64
|
-
<HtmlAtom class={[klass]} {...restProps}>
|
|
65
|
-
<div bind:clientWidth class="size-full">
|
|
66
|
-
<canvas
|
|
67
|
-
{@attach (node) => {
|
|
68
|
-
canvasElement = node;
|
|
69
|
-
isReady = true;
|
|
70
|
-
}}
|
|
71
|
-
width={clientWidth}
|
|
72
|
-
height={clientWidth}
|
|
73
|
-
></canvas>
|
|
74
|
-
</div>
|
|
75
|
-
</HtmlAtom>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { QRCodeBrowser } from '@qrcode-js/browser';
|
|
3
|
+
import { HtmlAtom } from '../atom';
|
|
4
|
+
import type { QRCodeProps } from './types';
|
|
5
|
+
|
|
6
|
+
type Render = typeof QRCodeBrowser;
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
class: klass = '',
|
|
10
|
+
value = '',
|
|
11
|
+
finder = {
|
|
12
|
+
round: 0.5
|
|
13
|
+
},
|
|
14
|
+
dots = {
|
|
15
|
+
scale: 0.75,
|
|
16
|
+
round: 1
|
|
17
|
+
},
|
|
18
|
+
drawFunction = 'telegram',
|
|
19
|
+
gradient = undefined,
|
|
20
|
+
logo = undefined,
|
|
21
|
+
margin = undefined,
|
|
22
|
+
qr = undefined,
|
|
23
|
+
...restProps
|
|
24
|
+
}: QRCodeProps = $props();
|
|
25
|
+
|
|
26
|
+
let canvasElement: HTMLCanvasElement | undefined = $state();
|
|
27
|
+
|
|
28
|
+
let clientWidth = $state(0);
|
|
29
|
+
let isReady = $state(false);
|
|
30
|
+
let render: Render | undefined = $state();
|
|
31
|
+
let computedColor = $state('black');
|
|
32
|
+
|
|
33
|
+
import('@qrcode-js/browser').then((result) => {
|
|
34
|
+
render = result.QRCodeBrowser;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
$effect(() => {
|
|
38
|
+
if (!canvasElement) return;
|
|
39
|
+
if (!render) return;
|
|
40
|
+
if (!isReady) render;
|
|
41
|
+
|
|
42
|
+
// Get the computed color from the canvas element
|
|
43
|
+
computedColor = getComputedStyle(canvasElement).color;
|
|
44
|
+
|
|
45
|
+
const qrcode = render(canvasElement);
|
|
46
|
+
|
|
47
|
+
qrcode.setOptions({
|
|
48
|
+
text: value,
|
|
49
|
+
size: clientWidth,
|
|
50
|
+
color: computedColor,
|
|
51
|
+
dots,
|
|
52
|
+
finder,
|
|
53
|
+
drawFunction,
|
|
54
|
+
...(gradient && { gradient }),
|
|
55
|
+
...(margin && { margin }),
|
|
56
|
+
...(logo && { logo }),
|
|
57
|
+
...(qr && { qr })
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
qrcode.draw();
|
|
61
|
+
});
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<HtmlAtom class={[klass]} {...restProps}>
|
|
65
|
+
<div bind:clientWidth class="size-full">
|
|
66
|
+
<canvas
|
|
67
|
+
{@attach (node) => {
|
|
68
|
+
canvasElement = node;
|
|
69
|
+
isReady = true;
|
|
70
|
+
}}
|
|
71
|
+
width={clientWidth}
|
|
72
|
+
height={clientWidth}
|
|
73
|
+
></canvas>
|
|
74
|
+
</div>
|
|
75
|
+
</HtmlAtom>
|
|
@@ -1,50 +1,41 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { default as RadioComponent } from './radio.svelte';
|
|
4
|
-
import { default as RadioGroupComponent } from './radio-group.svelte';
|
|
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
|
-
<div class="mt-8">
|
|
44
|
-
Selected value: <strong>{value}</strong>
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
{/snippet}
|
|
48
|
-
</Root>
|
|
49
|
-
{/snippet}
|
|
50
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { default as RadioComponent } from './radio.svelte';
|
|
4
|
+
import { default as RadioGroupComponent } from './radio-group.svelte';
|
|
5
|
+
|
|
6
|
+
const { Story } = defineMeta({
|
|
7
|
+
title: 'ATOMS/Radio'
|
|
8
|
+
});
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
let value = $state('t1');
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<Story name="Group">
|
|
16
|
+
<RadioGroupComponent class="gap-4" name="choice" bind:value>
|
|
17
|
+
<label class="flex items-center gap-2">
|
|
18
|
+
<RadioComponent class="size-8" value="t1" />
|
|
19
|
+
<div>Test 1</div>
|
|
20
|
+
</label>
|
|
21
|
+
|
|
22
|
+
<label class="flex items-center gap-2">
|
|
23
|
+
<RadioComponent class="size-8" value="t2" />
|
|
24
|
+
<div>Test 2</div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label class="flex items-center gap-2">
|
|
28
|
+
<RadioComponent class="size-8" value="t3" />
|
|
29
|
+
<div>Test 3</div>
|
|
30
|
+
</label>
|
|
31
|
+
|
|
32
|
+
<label class="flex items-center gap-2">
|
|
33
|
+
<RadioComponent class="size-8" value="t4" />
|
|
34
|
+
<div>Test 4</div>
|
|
35
|
+
</label>
|
|
36
|
+
</RadioGroupComponent>
|
|
37
|
+
|
|
38
|
+
<div class="mt-8">
|
|
39
|
+
Selected value: <strong>{value}</strong>
|
|
40
|
+
</div>
|
|
41
|
+
</Story>
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
-
import { default as RadioModule } from './radio.svelte';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
<Root>
|
|
19
|
-
{#snippet children({})}
|
|
20
|
-
<div class="flex h-full w-full items-center justify-center">
|
|
21
|
-
<RadioModule class="size-5" />
|
|
22
|
-
</div>
|
|
23
|
-
{/snippet}
|
|
24
|
-
</Root>
|
|
25
|
-
{/snippet}
|
|
26
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
import { default as RadioModule } from './radio.svelte';
|
|
4
|
+
|
|
5
|
+
const { Story } = defineMeta({
|
|
6
|
+
title: 'ATOMS/Radio'
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script>
|
|
11
|
+
let value = $state(undefined);
|
|
12
|
+
let checked = $state(false);
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<Story name="Radio">
|
|
16
|
+
<RadioModule class="size-5" />
|
|
17
|
+
</Story>
|
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { getRadioGroupContext } from './context';
|
|
3
|
-
import { Stack } from '../stack';
|
|
4
|
-
import { toClassValue } from '../../utils';
|
|
5
|
-
import { HtmlAtom, type Base } from '../atom';
|
|
6
|
-
|
|
7
|
-
const radioGroupContext = getRadioGroupContext();
|
|
8
|
-
|
|
9
|
-
let {
|
|
10
|
-
class: klass = '',
|
|
11
|
-
value = $bindable(undefined),
|
|
12
|
-
group = $bindable(),
|
|
13
|
-
id = undefined,
|
|
14
|
-
name = undefined,
|
|
15
|
-
disabled = false,
|
|
16
|
-
required = false,
|
|
17
|
-
readonly = false,
|
|
18
|
-
onchange = undefined,
|
|
19
|
-
oninput = undefined,
|
|
20
|
-
checkedContent = undefined,
|
|
21
|
-
...restProps
|
|
22
|
-
} = $props();
|
|
23
|
-
|
|
24
|
-
const _disabled = $derived(radioGroupContext?.disabled);
|
|
25
|
-
const _required = $derived(radioGroupContext?.required);
|
|
26
|
-
const _readonly = $derived(radioGroupContext?.readonly);
|
|
27
|
-
const _name = $derived(radioGroupContext?.name);
|
|
28
|
-
|
|
29
|
-
const proxy = {
|
|
30
|
-
get current() {
|
|
31
|
-
return radioGroupContext?.value ?? group;
|
|
32
|
-
},
|
|
33
|
-
set current(v) {
|
|
34
|
-
group = v;
|
|
35
|
-
if (radioGroupContext) {
|
|
36
|
-
radioGroupContext.value = v;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const isDisabled = $derived(_disabled || disabled);
|
|
42
|
-
const isRequired = $derived(_required || required);
|
|
43
|
-
const isReadonly = $derived(_readonly || readonly);
|
|
44
|
-
const isChecked = $derived(proxy.current === value);
|
|
45
|
-
|
|
46
|
-
function handleChange(ev: Event) {
|
|
47
|
-
const checked = (ev.currentTarget as HTMLInputElement)?.checked ?? false;
|
|
48
|
-
|
|
49
|
-
onchange?.(ev, {
|
|
50
|
-
checked,
|
|
51
|
-
value: checked,
|
|
52
|
-
type: 'boolean'
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function handleInput(ev: Event) {
|
|
57
|
-
const currentTarget = ev.currentTarget as HTMLInputElement;
|
|
58
|
-
const _checked = currentTarget?.checked ?? false;
|
|
59
|
-
|
|
60
|
-
oninput?.(ev, {
|
|
61
|
-
checked: _checked,
|
|
62
|
-
value: _checked,
|
|
63
|
-
type: 'boolean'
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
if (ev.defaultPrevented) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
</script>
|
|
71
|
-
|
|
72
|
-
<Stack.Root
|
|
73
|
-
preset="radio"
|
|
74
|
-
class={[
|
|
75
|
-
'text-foreground bg-input box-border inline-flex aspect-square size-4 max-
|
|
76
|
-
isDisabled && 'pointer-events-none opacity-50',
|
|
77
|
-
'$preset',
|
|
78
|
-
toClassValue.apply(null, [klass, {}])
|
|
79
|
-
]}
|
|
80
|
-
as="label"
|
|
81
|
-
{...restProps}
|
|
82
|
-
>
|
|
83
|
-
<Stack.Item class="pointer-events-none flex size-full">
|
|
84
|
-
<input
|
|
85
|
-
bind:group={proxy.current}
|
|
86
|
-
{id}
|
|
87
|
-
{value}
|
|
88
|
-
class="pointer-events-auto size-0 opacity-0"
|
|
89
|
-
type="radio"
|
|
90
|
-
name={_name ?? name}
|
|
91
|
-
disabled={isDisabled}
|
|
92
|
-
required={isRequired}
|
|
93
|
-
readonly={isReadonly}
|
|
94
|
-
onchange={handleChange}
|
|
95
|
-
oninput={handleInput}
|
|
96
|
-
/>
|
|
97
|
-
</Stack.Item>
|
|
98
|
-
|
|
99
|
-
{#if isChecked}
|
|
100
|
-
{#if checkedContent}
|
|
101
|
-
<HtmlAtom
|
|
102
|
-
class="rounded-inherit pointer-events-none size-
|
|
103
|
-
base={checkedContent}
|
|
104
|
-
/>
|
|
105
|
-
{:else}
|
|
106
|
-
<Stack.Item class="rounded-inherit pointer-events-none size-
|
|
107
|
-
{/if}
|
|
108
|
-
{/if}
|
|
109
|
-
</Stack.Root>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getRadioGroupContext } from './context';
|
|
3
|
+
import { Stack } from '../stack';
|
|
4
|
+
import { toClassValue } from '../../utils';
|
|
5
|
+
import { HtmlAtom, type Base } from '../atom';
|
|
6
|
+
|
|
7
|
+
const radioGroupContext = getRadioGroupContext();
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
class: klass = '',
|
|
11
|
+
value = $bindable(undefined),
|
|
12
|
+
group = $bindable(),
|
|
13
|
+
id = undefined,
|
|
14
|
+
name = undefined,
|
|
15
|
+
disabled = false,
|
|
16
|
+
required = false,
|
|
17
|
+
readonly = false,
|
|
18
|
+
onchange = undefined,
|
|
19
|
+
oninput = undefined,
|
|
20
|
+
checkedContent = undefined,
|
|
21
|
+
...restProps
|
|
22
|
+
} = $props();
|
|
23
|
+
|
|
24
|
+
const _disabled = $derived(radioGroupContext?.disabled);
|
|
25
|
+
const _required = $derived(radioGroupContext?.required);
|
|
26
|
+
const _readonly = $derived(radioGroupContext?.readonly);
|
|
27
|
+
const _name = $derived(radioGroupContext?.name);
|
|
28
|
+
|
|
29
|
+
const proxy = {
|
|
30
|
+
get current() {
|
|
31
|
+
return radioGroupContext?.value ?? group;
|
|
32
|
+
},
|
|
33
|
+
set current(v) {
|
|
34
|
+
group = v;
|
|
35
|
+
if (radioGroupContext) {
|
|
36
|
+
radioGroupContext.value = v;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const isDisabled = $derived(_disabled || disabled);
|
|
42
|
+
const isRequired = $derived(_required || required);
|
|
43
|
+
const isReadonly = $derived(_readonly || readonly);
|
|
44
|
+
const isChecked = $derived(proxy.current === value);
|
|
45
|
+
|
|
46
|
+
function handleChange(ev: Event) {
|
|
47
|
+
const checked = (ev.currentTarget as HTMLInputElement)?.checked ?? false;
|
|
48
|
+
|
|
49
|
+
onchange?.(ev, {
|
|
50
|
+
checked,
|
|
51
|
+
value: checked,
|
|
52
|
+
type: 'boolean'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function handleInput(ev: Event) {
|
|
57
|
+
const currentTarget = ev.currentTarget as HTMLInputElement;
|
|
58
|
+
const _checked = currentTarget?.checked ?? false;
|
|
59
|
+
|
|
60
|
+
oninput?.(ev, {
|
|
61
|
+
checked: _checked,
|
|
62
|
+
value: _checked,
|
|
63
|
+
type: 'boolean'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (ev.defaultPrevented) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<Stack.Root
|
|
73
|
+
preset="radio"
|
|
74
|
+
class={[
|
|
75
|
+
'text-foreground bg-input box-border inline-flex aspect-square size-4 max-h-fit cursor-pointer place-items-center rounded-full border p-0',
|
|
76
|
+
isDisabled && 'pointer-events-none opacity-50',
|
|
77
|
+
'$preset',
|
|
78
|
+
toClassValue.apply(null, [klass, {}])
|
|
79
|
+
]}
|
|
80
|
+
as="label"
|
|
81
|
+
{...restProps}
|
|
82
|
+
>
|
|
83
|
+
<Stack.Item class="pointer-events-none flex size-full">
|
|
84
|
+
<input
|
|
85
|
+
bind:group={proxy.current}
|
|
86
|
+
{id}
|
|
87
|
+
{value}
|
|
88
|
+
class="pointer-events-auto size-0 opacity-0"
|
|
89
|
+
type="radio"
|
|
90
|
+
name={_name ?? name}
|
|
91
|
+
disabled={isDisabled}
|
|
92
|
+
required={isRequired}
|
|
93
|
+
readonly={isReadonly}
|
|
94
|
+
onchange={handleChange}
|
|
95
|
+
oninput={handleInput}
|
|
96
|
+
/>
|
|
97
|
+
</Stack.Item>
|
|
98
|
+
|
|
99
|
+
{#if isChecked}
|
|
100
|
+
{#if checkedContent}
|
|
101
|
+
<HtmlAtom
|
|
102
|
+
class="rounded-inherit pointer-events-none size-full scale-50 bg-current"
|
|
103
|
+
base={checkedContent}
|
|
104
|
+
/>
|
|
105
|
+
{:else}
|
|
106
|
+
<Stack.Item class="rounded-inherit pointer-events-none size-full scale-50 bg-current" />
|
|
107
|
+
{/if}
|
|
108
|
+
{/if}
|
|
109
|
+
</Stack.Root>
|