@geoffcox/sterling-svelte 2.0.13 → 2.0.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.
package/dist/Radio.svelte CHANGED
@@ -1,15 +1,16 @@
1
1
  <svelte:options runes={true} />
2
2
 
3
3
  <script lang="ts">
4
+ import type { ChangeEventHandler } from 'svelte/elements';
4
5
  import { usingKeyboard } from './mediaQueries/usingKeyboard';
5
6
  import type { RadioProps } from './Radio.types';
7
+ import { onMount } from 'svelte';
6
8
 
7
9
  const uuid = $props.id();
8
10
 
9
11
  let {
10
12
  id,
11
13
  children,
12
- checked = $bindable(false),
13
14
  class: _class,
14
15
  disabled = false,
15
16
  group = $bindable(),
@@ -25,13 +26,6 @@
25
26
  }
26
27
  });
27
28
 
28
- $effect(() => {
29
- // checked isn't set by input type="radio"
30
- checked = group === value;
31
- });
32
-
33
- // ----- Methods ----- //
34
-
35
29
  export const blur = () => {
36
30
  inputRef?.blur();
37
31
  };
@@ -43,6 +37,12 @@
43
37
  export const focus = (options?: FocusOptions) => {
44
38
  inputRef?.focus(options);
45
39
  };
40
+
41
+ const onChange: ChangeEventHandler<HTMLInputElement> = (e) => {
42
+ if (e.currentTarget.checked) {
43
+ group = value;
44
+ }
45
+ };
46
46
  </script>
47
47
 
48
48
  <!--
@@ -51,20 +51,21 @@
51
51
  -->
52
52
  <div
53
53
  class={['sterling-radio', _class]}
54
- class:checked
54
+ class:checked={group === value}
55
55
  class:disabled
56
56
  class:using-keyboard={$usingKeyboard}
57
57
  >
58
58
  <div class="container">
59
59
  <input
60
60
  bind:this={inputRef}
61
- {checked}
61
+ checked={group === value}
62
62
  {disabled}
63
- bind:group
63
+ {group}
64
64
  {id}
65
65
  type="radio"
66
66
  {value}
67
67
  {...rest}
68
+ onchange={onChange}
68
69
  />
69
70
  <div class="indicator"></div>
70
71
  </div>
@@ -1,9 +1,8 @@
1
- import type { RadioProps } from './Radio.types';
2
1
  /** A styled HTML input type=radio element with optional label. */
3
- declare const Radio: import("svelte").Component<RadioProps, {
2
+ declare const Radio: import("svelte").Component<import("svelte/elements").HTMLInputAttributes, {
4
3
  blur: () => void;
5
4
  click: () => void;
6
5
  focus: (options?: FocusOptions) => void;
7
- }, "group" | "checked">;
6
+ }, "group">;
8
7
  type Radio = ReturnType<typeof Radio>;
9
8
  export default Radio;
@@ -1,4 +1,2 @@
1
1
  import type { HTMLInputAttributes } from 'svelte/elements';
2
- export type RadioProps = HTMLInputAttributes & {
3
- group?: any | null;
4
- };
2
+ export type RadioProps = HTMLInputAttributes;
@@ -15,16 +15,18 @@
15
15
  precision = 0,
16
16
  reverse,
17
17
  step = 1,
18
- value = $bindable(0),
18
+ value = $bindable(),
19
19
  vertical,
20
20
  ...rest
21
21
  }: SliderProps = $props();
22
22
 
23
23
  const ensureValueValid = () => {
24
- const clamped = Math.max(min, Math.min(max, value));
25
- const newValue = precision !== undefined ? round(clamped, precision) : clamped;
26
- if (value !== newValue) {
27
- value = newValue;
24
+ if (value !== undefined) {
25
+ const clamped = Math.max(min, Math.min(max, value));
26
+ const newValue = precision !== undefined ? round(clamped, precision) : clamped;
27
+ if (value !== newValue) {
28
+ value = newValue;
29
+ }
28
30
  }
29
31
  };
30
32
 
@@ -49,7 +51,7 @@
49
51
  sliderRef?.parentElement?.focus(options);
50
52
  };
51
53
 
52
- let ratio = $derived(max - min > 0 ? (value - min) / (max - min) : 0);
54
+ let ratio = $derived(value !== undefined && max - min > 0 ? (value - min) / (max - min) : 0);
53
55
 
54
56
  // when value changes, ensure it is valid right away
55
57
  const setValue = (newValue: number) => {
@@ -71,7 +73,7 @@
71
73
 
72
74
  // Raise change event when value changes
73
75
  $effect(() => {
74
- onChange?.(value);
76
+ value && onChange?.(value);
75
77
  });
76
78
 
77
79
  // ----- Size tracking ----- //
@@ -139,7 +141,7 @@
139
141
  };
140
142
 
141
143
  const onKeyDown: KeyboardEventHandler<HTMLDivElement> = (event) => {
142
- if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey) {
144
+ if (!disabled && value !== undefined && !event.ctrlKey && !event.shiftKey && !event.altKey) {
143
145
  let change = 0;
144
146
 
145
147
  if (vertical) {
@@ -180,6 +182,7 @@
180
182
  class={['sterling-slider', _class]}
181
183
  class:disabled
182
184
  class:horizontal={!vertical}
185
+ class:no-value={value === undefined}
183
186
  class:reverse
184
187
  class:using-keyboard={$usingKeyboard}
185
188
  class:vertical
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoffcox/sterling-svelte",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "author": "Geoff Cox",
5
5
  "description": "A modern, accessible, and lightweight component library for Svelte.",
6
6
  "license": "MIT",
@@ -74,7 +74,7 @@
74
74
  "@eslint/js": "^9.18.0",
75
75
  "@fontsource/atkinson-hyperlegible": "^5.1.1",
76
76
  "@fontsource/source-code-pro": "^4.5.14",
77
- "@geoffcox/sterling-svelte-themes": "^2.0.7",
77
+ "@geoffcox/sterling-svelte-themes": "^2.0.12",
78
78
  "@sveltejs/adapter-static": "^3.0.8",
79
79
  "@sveltejs/kit": "^2.16.0",
80
80
  "@sveltejs/package": "^2.0.0",