@onsvisual/svelte-components 1.0.50 → 1.0.51

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.
@@ -2,7 +2,13 @@
2
2
  import { setContext } from "svelte";
3
3
  import { writable } from "svelte/store";
4
4
 
5
- let { name = "", legend = "", value = $bindable(), visuallyHideLegend = false } = $props();
5
+ let {
6
+ name = "",
7
+ legend = "",
8
+ value = $bindable(),
9
+ visuallyHideLegend = false,
10
+ children
11
+ } = $props();
6
12
 
7
13
  // create the store
8
14
  const selectedValue = writable(value);
@@ -32,13 +38,13 @@
32
38
  <legend class:ons-u-vh={visuallyHideLegend}>{legend}</legend>
33
39
  {/if}
34
40
  <div class="buttons">
35
- <slot />
41
+ {@render children?.()}
36
42
  </div>
37
43
  </fieldset>
38
44
 
39
45
  <style>
40
46
  .button-group {
41
- display: inline-block;
47
+ display: block;
42
48
  }
43
49
 
44
50
  legend {
@@ -47,7 +53,7 @@
47
53
  }
48
54
 
49
55
  .buttons {
50
- display: flex;
56
+ display: inline-flex;
51
57
  gap: 8px;
52
58
  background: #f5f5f6;
53
59
  padding: 4px;
@@ -5,9 +5,7 @@ export default class ButtonGroup extends SvelteComponentTyped<{
5
5
  [x: string]: never;
6
6
  }, {
7
7
  [evt: string]: CustomEvent<any>;
8
- }, {
9
- default: {};
10
- }> {
8
+ }, {}> {
11
9
  }
12
10
  export type ButtonGroupProps = typeof __propDef.props;
13
11
  export type ButtonGroupEvents = typeof __propDef.events;
@@ -20,8 +18,6 @@ declare const __propDef: {
20
18
  events: {
21
19
  [evt: string]: CustomEvent<any>;
22
20
  };
23
- slots: {
24
- default: {};
25
- };
21
+ slots: {};
26
22
  };
27
23
  export {};
@@ -1,7 +1,7 @@
1
1
  <script>
2
2
  import { getContext } from "svelte";
3
3
 
4
- let { value = "", label = "" } = $props();
4
+ let { value = "", label = value } = $props();
5
5
 
6
6
  // Get the parent ButtonGroup context
7
7
  const buttonGroup = getContext("buttonGroup");
@@ -11,31 +11,11 @@
11
11
  const currentSelected = $derived(selectedValue);
12
12
  const selected = $derived($currentSelected === value);
13
13
 
14
- function handleClick() {
14
+ function handleChange() {
15
15
  selectedValue.set(value); // Update the store
16
16
  }
17
17
 
18
18
  let buttonRef;
19
-
20
- function handleKeydown(event) {
21
- const buttons = Array.from(document.querySelectorAll(`[name="${groupName}"]`));
22
- const currentIndex = buttons.indexOf(buttonRef);
23
-
24
- let newIndex = -1;
25
-
26
- if (event.key === "ArrowRight" || event.key === "ArrowDown") {
27
- newIndex = (currentIndex + 1) % buttons.length;
28
- } else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
29
- newIndex = (currentIndex - 1 + buttons.length) % buttons.length;
30
- } else if (event.key === "Enter" || event.key === " ") {
31
- handleClick();
32
- return;
33
- }
34
-
35
- if (newIndex !== -1) {
36
- buttons[newIndex].focus();
37
- }
38
- }
39
19
  </script>
40
20
 
41
21
  <div class="button-container">
@@ -46,14 +26,12 @@
46
26
  {value}
47
27
  checked={selected}
48
28
  class="radio-input"
49
- on:click={handleClick}
50
- on:keydown={handleKeydown}
29
+ onchange={handleChange}
51
30
  aria-checked={selected}
52
- tabindex="0"
53
31
  bind:this={buttonRef}
54
32
  />
55
- <label for={value} class="button" class:selected on:click={handleClick}>
56
- {label || value}
33
+ <label for={value} class="radio-label">
34
+ {label}
57
35
  </label>
58
36
  </div>
59
37
 
@@ -69,7 +47,7 @@
69
47
  height: 0;
70
48
  }
71
49
 
72
- .button {
50
+ .radio-label {
73
51
  flex-grow: 0;
74
52
  padding: 4px 8px;
75
53
  border: none;
@@ -84,18 +62,19 @@
84
62
  text-align: center;
85
63
  }
86
64
 
87
- .button:hover {
65
+ .radio-label:hover {
88
66
  background-color: #e8e8e8;
89
67
  }
90
68
 
91
- .button:focus {
92
- box-shadow: orange 0 0 0 2px;
93
- }
94
-
95
- .button.selected {
69
+ .radio-input:checked + .radio-label {
96
70
  background: white;
97
71
  font-weight: bold;
98
- color: #206095;
72
+ color: var(--ons-color-text-link);
99
73
  box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
100
74
  }
75
+
76
+ .radio-input:focus + .radio-label {
77
+ background: var(--ons-color-focus);
78
+ color: var(--ons-color-text);
79
+ }
101
80
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "1.0.50",
3
+ "version": "1.0.51",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "npm run build:package && npm run build:docs",