noph-ui 0.12.0 → 0.12.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.
@@ -45,7 +45,7 @@ export interface SegmentedButtonProps extends HTMLAttributes<HTMLDivElement> {
45
45
  icon?: Snippet;
46
46
  onclick?: (event: Event) => void;
47
47
  }[];
48
- group?: string | number | null;
48
+ group?: string | number | (string | number)[] | null;
49
49
  element?: HTMLElement;
50
50
  }
51
51
  export {};
@@ -10,31 +10,42 @@
10
10
  style,
11
11
  ...attributes
12
12
  }: CheckboxProps = $props()
13
+
14
+ $effect(() => {
15
+ if (group && attributes.value) {
16
+ checked = group.includes(attributes.value)
17
+ }
18
+ })
19
+
20
+ $effect(() => {
21
+ if (attributes.value && group) {
22
+ const index = group.indexOf(attributes.value)
23
+ if (checked) {
24
+ if (index < 0) {
25
+ group?.push(attributes.value)
26
+ group = group
27
+ }
28
+ } else {
29
+ if (index >= 0) {
30
+ group.splice(index, 1)
31
+ group = group
32
+ }
33
+ }
34
+ }
35
+ })
13
36
  </script>
14
37
 
15
38
  <div {style} class={['np-host', attributes.class]} bind:this={element}>
16
39
  <div class="np-container">
17
40
  <label class="np-input-wrapper">
18
- {#if group !== undefined}
19
- <input
20
- {...attributes}
21
- class="np-input"
22
- type="checkbox"
23
- bind:indeterminate
24
- bind:checked
25
- bind:group
26
- aria-checked={indeterminate ? 'mixed' : undefined}
27
- />
28
- {:else}
29
- <input
30
- {...attributes}
31
- class="np-input"
32
- type="checkbox"
33
- bind:indeterminate
34
- bind:checked
35
- aria-checked={indeterminate ? 'mixed' : undefined}
36
- />
37
- {/if}
41
+ <input
42
+ {...attributes}
43
+ class="np-input"
44
+ type="checkbox"
45
+ bind:indeterminate
46
+ bind:checked
47
+ aria-checked={indeterminate ? 'mixed' : undefined}
48
+ />
38
49
  {#if !attributes.disabled}
39
50
  <Ripple />
40
51
  {/if}
@@ -1,5 +1,5 @@
1
1
  import type { HTMLInputAttributes } from 'svelte/elements';
2
2
  export interface CheckboxProps extends Omit<HTMLInputAttributes, 'type'> {
3
3
  element?: HTMLElement;
4
- group?: string | number | null;
4
+ group?: (string | number)[] | null;
5
5
  }
@@ -23,6 +23,29 @@
23
23
  }: FilterChipProps = $props()
24
24
 
25
25
  let chipLabel: HTMLLabelElement | undefined = $state()
26
+
27
+ $effect(() => {
28
+ if (group && value) {
29
+ selected = group.includes(value)
30
+ }
31
+ })
32
+
33
+ $effect(() => {
34
+ if (value && group) {
35
+ const index = group.indexOf(value)
36
+ if (selected) {
37
+ if (index < 0) {
38
+ group?.push(value)
39
+ group = group
40
+ }
41
+ } else {
42
+ if (index >= 0) {
43
+ group.splice(index, 1)
44
+ group = group
45
+ }
46
+ }
47
+ }
48
+ })
26
49
  </script>
27
50
 
28
51
  <div
@@ -47,26 +70,14 @@
47
70
  <CheckIcon width={18} height={18} />
48
71
  </div>
49
72
  <div class="np-chip-label">{label}</div>
50
- {#if group !== undefined}
51
- <input
52
- type="checkbox"
53
- bind:checked={selected}
54
- {value}
55
- {name}
56
- {disabled}
57
- defaultChecked={defaultSelected}
58
- bind:group
59
- />
60
- {:else}
61
- <input
62
- type="checkbox"
63
- bind:checked={selected}
64
- {value}
65
- {name}
66
- {disabled}
67
- defaultChecked={defaultSelected}
68
- />
69
- {/if}
73
+ <input
74
+ type="checkbox"
75
+ bind:checked={selected}
76
+ {value}
77
+ {name}
78
+ {disabled}
79
+ defaultChecked={defaultSelected}
80
+ />
70
81
  </label>
71
82
  {#if !disabled}
72
83
  <Ripple forElement={chipLabel} />
@@ -11,7 +11,7 @@ export interface FilterChipProps extends HTMLAttributes<HTMLDivElement> {
11
11
  element?: HTMLDivElement;
12
12
  name?: string;
13
13
  value?: string;
14
- group?: string | number | null;
14
+ group?: (string | number)[] | null;
15
15
  defaultSelected?: boolean | null;
16
16
  remove?: (chip: HTMLDivElement) => void;
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noph-ui",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "license": "MIT",
5
5
  "homepage": "https://noph.dev",
6
6
  "repository": {