@r2digisolutions/components 0.8.8 → 0.8.10

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.
@@ -46,7 +46,7 @@
46
46
  ghost:
47
47
  'text-secondary hover:text-primary hover:bg-surface-overlay focus-visible:ring-brand-500 active:scale-[0.98]',
48
48
  outline:
49
- 'border-2 border-brand-500 text-brand-600 dark:text-brand-400 hover:bg-brand-50 dark:hover:bg-brand-950 focus-visible:ring-brand-500 active:scale-[0.98]',
49
+ 'border border-border text-primary hover:bg-surface-overlay hover:border-border-strong focus-visible:ring-brand-500 active:scale-[0.98]',
50
50
  destructive:
51
51
  'bg-red-500 text-white hover:bg-red-600 active:bg-red-700 focus-visible:ring-red-500 shadow-sm hover:shadow-md active:scale-[0.98]'
52
52
  };
@@ -1,6 +1,4 @@
1
1
  <script lang="ts">
2
- import { createId } from '../../../utils/id.js';
3
-
4
2
  interface ToggleProps {
5
3
  checked?: boolean;
6
4
  disabled?: boolean;
@@ -23,12 +21,6 @@
23
21
  onchange
24
22
  }: ToggleProps = $props();
25
23
 
26
- let autoId = $state<string | undefined>(undefined);
27
- $effect(() => {
28
- if (id == null) autoId ??= createId('toggle');
29
- });
30
- const inputId = $derived(id ?? autoId);
31
-
32
24
  const trackClasses = {
33
25
  sm: 'h-4 w-7',
34
26
  md: 'h-5 w-9',
@@ -47,32 +39,35 @@
47
39
  lg: 'translate-x-5'
48
40
  };
49
41
 
50
- function handleChange(e: Event) {
51
- const target = e.target as HTMLInputElement;
52
- checked = target.checked;
42
+ function toggle() {
43
+ if (disabled) return;
44
+ checked = !checked;
53
45
  onchange?.(checked);
54
46
  }
47
+
48
+ function handleKeydown(event: KeyboardEvent) {
49
+ if (event.key !== 'Enter') return;
50
+ event.preventDefault();
51
+ toggle();
52
+ }
55
53
  </script>
56
54
 
57
- <label
55
+ <button
56
+ type="button"
57
+ id={id}
58
+ role="switch"
59
+ aria-checked={checked}
60
+ aria-label={label}
61
+ {disabled}
58
62
  class={[
59
- 'inline-flex items-center gap-2.5 cursor-pointer select-none',
63
+ 'inline-flex items-center gap-2.5 select-none',
60
64
  labelPosition === 'left' && 'flex-row-reverse',
61
- disabled && 'opacity-50 cursor-not-allowed',
65
+ disabled ? 'cursor-not-allowed opacity-50' : 'cursor-pointer',
62
66
  className
63
67
  ]}
64
- for={inputId}
68
+ onclick={toggle}
69
+ onkeydown={handleKeydown}
65
70
  >
66
- <input
67
- id={inputId}
68
- type="checkbox"
69
- class="sr-only"
70
- checked={checked}
71
- {disabled}
72
- onchange={handleChange}
73
- />
74
-
75
- <!-- Track -->
76
71
  <span
77
72
  class={[
78
73
  'relative inline-flex items-center shrink-0 rounded-full transition-colors duration-200 ease-in-out',
@@ -96,4 +91,4 @@
96
91
  {#if label}
97
92
  <span class="text-sm font-medium text-primary">{label}</span>
98
93
  {/if}
99
- </label>
94
+ </button>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.8.8",
3
+ "version": "0.8.10",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",