@r2digisolutions/components 0.21.14 → 0.21.15
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.
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import Check from '@lucide/svelte/icons/check';
|
|
3
|
+
import Minus from '@lucide/svelte/icons/minus';
|
|
4
|
+
|
|
2
5
|
export type SelectionBoxSize = 'sm' | 'md' | 'lg';
|
|
3
6
|
export type SelectionBoxTone = 'brand' | 'primary' | 'success' | 'neutral';
|
|
4
7
|
export type SelectionBoxRadius = 'sm' | 'md' | 'none';
|
|
@@ -44,6 +47,12 @@
|
|
|
44
47
|
lg: 'h-5 w-5'
|
|
45
48
|
};
|
|
46
49
|
|
|
50
|
+
const iconSizeClasses: Record<SelectionBoxSize, string> = {
|
|
51
|
+
sm: 'h-2.5 w-2.5',
|
|
52
|
+
md: 'h-3 w-3',
|
|
53
|
+
lg: 'h-3.5 w-3.5'
|
|
54
|
+
};
|
|
55
|
+
|
|
47
56
|
const radiusClasses: Record<SelectionBoxRadius, string> = {
|
|
48
57
|
none: 'rounded-none',
|
|
49
58
|
sm: 'rounded',
|
|
@@ -66,6 +75,13 @@
|
|
|
66
75
|
'checked:bg-neutral-800 checked:border-neutral-800 indeterminate:bg-neutral-800 indeterminate:border-neutral-800 hover:border-neutral-500 focus-visible:ring-neutral-500 dark:checked:bg-neutral-200 dark:checked:border-neutral-200 dark:indeterminate:bg-neutral-200 dark:indeterminate:border-neutral-200 dark:hover:border-neutral-400 dark:focus-visible:ring-neutral-400'
|
|
67
76
|
};
|
|
68
77
|
|
|
78
|
+
const toneIconColors: Record<SelectionBoxTone, string> = {
|
|
79
|
+
brand: 'text-white',
|
|
80
|
+
success: 'text-white',
|
|
81
|
+
primary: 'text-white dark:text-neutral-900',
|
|
82
|
+
neutral: 'text-white dark:text-neutral-900'
|
|
83
|
+
};
|
|
84
|
+
|
|
69
85
|
function handleChange(e: Event) {
|
|
70
86
|
const target = e.target as HTMLInputElement;
|
|
71
87
|
checked = target.checked;
|
|
@@ -86,35 +102,41 @@
|
|
|
86
102
|
className
|
|
87
103
|
]}
|
|
88
104
|
>
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
<span class={['relative inline-flex shrink-0', sizeClasses[size]]}>
|
|
106
|
+
<input
|
|
107
|
+
id={inputId}
|
|
108
|
+
type="checkbox"
|
|
109
|
+
{name}
|
|
110
|
+
{value}
|
|
111
|
+
{disabled}
|
|
112
|
+
bind:checked
|
|
113
|
+
{@attach setIndeterminate}
|
|
114
|
+
class={[
|
|
115
|
+
'absolute inset-0 cursor-pointer border-2 border-border bg-surface-elevated appearance-none transition-all duration-150',
|
|
116
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2',
|
|
117
|
+
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
118
|
+
radiusClasses[radius],
|
|
119
|
+
toneChecked[tone]
|
|
120
|
+
]}
|
|
121
|
+
onchange={handleChange}
|
|
122
|
+
aria-label={showLabel ? undefined : label}
|
|
123
|
+
/>
|
|
124
|
+
{#if indeterminate || checked}
|
|
125
|
+
<span
|
|
126
|
+
class={[
|
|
127
|
+
'pointer-events-none absolute inset-0 z-10 flex items-center justify-center',
|
|
128
|
+
toneIconColors[tone]
|
|
129
|
+
]}
|
|
130
|
+
aria-hidden="true"
|
|
131
|
+
>
|
|
132
|
+
{#if indeterminate}
|
|
133
|
+
<Minus class={iconSizeClasses[size]} strokeWidth={3} />
|
|
134
|
+
{:else}
|
|
135
|
+
<Check class={iconSizeClasses[size]} strokeWidth={3} />
|
|
136
|
+
{/if}
|
|
137
|
+
</span>
|
|
138
|
+
{/if}
|
|
139
|
+
</span>
|
|
118
140
|
{#if label && showLabel}
|
|
119
141
|
<span class={['font-medium text-primary', labelSizeClasses[size]]}>{label}</span>
|
|
120
142
|
{:else if label}
|