@noxlovette/material 0.1.0 → 0.1.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.
|
@@ -9,58 +9,57 @@ Checkboxes let users select one or more items from a list, or turn an item on or
|
|
|
9
9
|
import { checkbox } from './theme.js';
|
|
10
10
|
import type { CheckboxProps } from './types.js';
|
|
11
11
|
import { Layer } from '../../../utils/index.js';
|
|
12
|
-
import { Checkbox } from 'bits-ui';
|
|
12
|
+
import { Checkbox, Label, useId } from 'bits-ui';
|
|
13
13
|
|
|
14
14
|
let {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
labelText,
|
|
16
|
+
labelRef,
|
|
17
|
+
id = useId(),
|
|
18
|
+
ref,
|
|
17
19
|
indeterminate = $bindable(false),
|
|
18
20
|
checked = $bindable(false),
|
|
19
21
|
disabled = false,
|
|
20
22
|
error = false,
|
|
21
|
-
align = 'start',
|
|
22
23
|
class: className,
|
|
23
24
|
...restProps
|
|
24
25
|
}: CheckboxProps = $props();
|
|
25
26
|
|
|
26
27
|
const state = $derived(indeterminate ? 'indeterminate' : checked ? 'checked' : 'unchecked');
|
|
27
|
-
const cls = $derived(checkbox({ state, error,
|
|
28
|
+
const cls = $derived(checkbox({ state, error, disabled }));
|
|
28
29
|
</script>
|
|
29
30
|
|
|
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
|
-
{/if}
|
|
60
|
-
{#if supportingText}
|
|
61
|
-
<span class={cls.supporting()}>{supportingText}</span>
|
|
31
|
+
<div class="flex cursor-pointer items-center space-x-3">
|
|
32
|
+
<Checkbox.Root
|
|
33
|
+
bind:checked
|
|
34
|
+
bind:indeterminate
|
|
35
|
+
{ref}
|
|
36
|
+
{disabled}
|
|
37
|
+
{id}
|
|
38
|
+
class={cls.root({ class: clsx(className) })}
|
|
39
|
+
{...restProps}
|
|
40
|
+
>
|
|
41
|
+
{#snippet children({ checked, indeterminate })}
|
|
42
|
+
<div class={cls.container()}>
|
|
43
|
+
<div class={cls.control()}>
|
|
44
|
+
<Layer />
|
|
45
|
+
<div class={cls.box()}></div>
|
|
46
|
+
</div>
|
|
47
|
+
{#if indeterminate}
|
|
48
|
+
<span class={cls.indeterminateIcon()}></span>
|
|
49
|
+
{:else if checked}
|
|
50
|
+
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class={cls.checkIcon()}>
|
|
51
|
+
<path
|
|
52
|
+
d="M 4.83 13.41 L 9 17.585 L 19.59 7"
|
|
53
|
+
fill="none"
|
|
54
|
+
stroke="currentColor"
|
|
55
|
+
stroke-width="2"
|
|
56
|
+
stroke-linecap="round"
|
|
57
|
+
stroke-linejoin="round"
|
|
58
|
+
/>
|
|
59
|
+
</svg>
|
|
62
60
|
{/if}
|
|
63
61
|
</div>
|
|
64
|
-
{/
|
|
65
|
-
|
|
66
|
-
</
|
|
62
|
+
{/snippet}
|
|
63
|
+
</Checkbox.Root>
|
|
64
|
+
<Label.Root for={id} ref={labelRef} class={cls.label()}>{labelText}</Label.Root>
|
|
65
|
+
</div>
|
|
@@ -44,7 +44,6 @@ export declare const checkbox: import("tailwind-variants").TVReturnType<{
|
|
|
44
44
|
checkIcon: string;
|
|
45
45
|
indeterminateIcon: string;
|
|
46
46
|
label: string;
|
|
47
|
-
supporting: string;
|
|
48
47
|
}, undefined, {
|
|
49
48
|
state: {
|
|
50
49
|
unchecked: {};
|
|
@@ -90,7 +89,6 @@ export declare const checkbox: import("tailwind-variants").TVReturnType<{
|
|
|
90
89
|
checkIcon: string;
|
|
91
90
|
indeterminateIcon: string;
|
|
92
91
|
label: string;
|
|
93
|
-
supporting: string;
|
|
94
92
|
}, import("tailwind-variants").TVReturnType<{
|
|
95
93
|
state: {
|
|
96
94
|
unchecked: {};
|
|
@@ -136,6 +134,5 @@ export declare const checkbox: import("tailwind-variants").TVReturnType<{
|
|
|
136
134
|
checkIcon: string;
|
|
137
135
|
indeterminateIcon: string;
|
|
138
136
|
label: string;
|
|
139
|
-
supporting: string;
|
|
140
137
|
}, undefined, unknown, unknown, undefined>>;
|
|
141
138
|
export type CheckboxM3Variants = VariantProps<typeof checkbox>;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { tv } from 'tailwind-variants';
|
|
2
2
|
export const checkbox = tv({
|
|
3
3
|
slots: {
|
|
4
|
-
root: 'inline-flex min-h-10 select-none items-start gap-3 text-md-sys-color-on-surface min-h-4.5',
|
|
4
|
+
root: 'inline-flex min-h-10 select-none items-start gap-3 text-md-sys-color-on-surface min-h-4.5 cursor-pointer',
|
|
5
5
|
container: 'relative inline-flex size-[18px] shrink-0',
|
|
6
6
|
control: 'layer-container absolute -inset-[11px] rounded-full text-md-sys-color-on-surface-variant state-layer before:rounded-full peer-focus-visible:outline peer-focus-visible:outline-3 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-md-sys-color-secondary',
|
|
7
7
|
box: 'absolute inset-[11px] rounded-[4px] border-2 border-current bg-md-sys-color-surface',
|
|
8
8
|
checkIcon: 'pointer-events-none absolute inset-0 m-auto size-5 text-md-sys-color-on-primary opacity-0 scale-75',
|
|
9
9
|
indeterminateIcon: 'pointer-events-none absolute inset-0 m-auto block h-0.5 w-3 rounded-full bg-md-sys-color-on-primary opacity-0 scale-75',
|
|
10
|
-
label: 'md-sys-typescale-body-large leading-5 text-md-sys-color-on-surface'
|
|
11
|
-
supporting: 'md-sys-typescale-body-medium text-md-sys-color-on-surface-variant'
|
|
10
|
+
label: 'md-sys-typescale-body-large leading-5 text-md-sys-color-on-surface cursor-pointer'
|
|
12
11
|
},
|
|
13
12
|
variants: {
|
|
14
13
|
state: {
|
|
@@ -1,39 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
label?: string;
|
|
8
|
-
/**
|
|
9
|
-
* Supporting text displayed below the label.
|
|
10
|
-
*/
|
|
11
|
-
supportingText?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Whether the checkbox is in an indeterminate state.
|
|
14
|
-
* @bindable
|
|
15
|
-
*/
|
|
16
|
-
indeterminate?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* The value associated with the checkbox.
|
|
19
|
-
*/
|
|
20
|
-
value?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Whether the checkbox is checked.
|
|
23
|
-
* @bindable
|
|
24
|
-
*/
|
|
25
|
-
checked?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Whether the checkbox is disabled.
|
|
28
|
-
*/
|
|
1
|
+
import type { Checkbox, WithoutChildrenOrChild } from 'bits-ui';
|
|
2
|
+
export type CheckboxProps = WithoutChildrenOrChild<Checkbox.RootProps> & {
|
|
3
|
+
labelText: string;
|
|
4
|
+
labelRef?: HTMLLabelElement;
|
|
5
|
+
} & {
|
|
29
6
|
disabled?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Whether the checkbox is in an error state.
|
|
32
|
-
*/
|
|
33
7
|
error?: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Vertical alignment of the checkbox relative to its label.
|
|
36
|
-
* @default 'start'
|
|
37
|
-
*/
|
|
38
|
-
align?: 'start' | 'center';
|
|
39
8
|
};
|