@geoffcox/sterling-svelte 0.0.9 → 0.0.11

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,7 +1,10 @@
1
1
  <script>import { onMount } from "svelte";
2
+ import { v4 as uuid } from "uuid";
3
+ import Label from "../display/Label.svelte";
2
4
  export let checked = false;
3
5
  export let group = void 0;
4
6
  export let disabled = false;
7
+ const inputId = uuid();
5
8
  const onChange = (e) => {
6
9
  if (e.currentTarget.checked) {
7
10
  group = $$restProps.value;
@@ -25,149 +28,153 @@ $: {
25
28
  @component
26
29
  A styled HTML input type=radio element with optional label.
27
30
  -->
28
- <!-- svelte-ignore a11y-label-has-associated-control -->
29
- <label class="sterling-radio">
30
- <div class="container">
31
- <input
32
- type="radio"
33
- on:blur
34
- on:click
35
- on:change
36
- on:change={onChange}
37
- on:dblclick
38
- on:focus
39
- on:focusin
40
- on:focusout
41
- on:keydown
42
- on:keypress
43
- on:keyup
44
- on:input
45
- on:mousedown
46
- on:mouseenter
47
- on:mouseleave
48
- on:mousemove
49
- on:mouseover
50
- on:mouseout
51
- on:mouseup
52
- on:toggle
53
- on:wheel
54
- checked={group === $$restProps.value}
55
- {...$$restProps}
56
- {disabled}
57
- />
58
- <div class="indicator" />
59
- </div>
60
- <div class="label-content" class:disabled>
61
- <slot name="label" />
62
- </div>
63
- </label>
31
+ <div class="sterling-radio">
32
+ <div class="container">
33
+ <input
34
+ type="radio"
35
+ on:blur
36
+ on:click
37
+ on:change
38
+ on:change={onChange}
39
+ on:dblclick
40
+ on:focus
41
+ on:focusin
42
+ on:focusout
43
+ on:keydown
44
+ on:keypress
45
+ on:keyup
46
+ on:input
47
+ on:mousedown
48
+ on:mouseenter
49
+ on:mouseleave
50
+ on:mousemove
51
+ on:mouseover
52
+ on:mouseout
53
+ on:mouseup
54
+ on:toggle
55
+ on:wheel
56
+ checked={group === $$restProps.value}
57
+ {...$$restProps}
58
+ {disabled}
59
+ id={inputId}
60
+ />
61
+ <div class="indicator" />
62
+ </div>
63
+ {#if $$slots.label}
64
+ <div class="label">
65
+ <Label {disabled} for={inputId}>
66
+ <slot name="label" />
67
+ </Label>
68
+ </div>
69
+ {/if}
70
+ </div>
64
71
 
65
72
  <style>
66
- label {
67
- display: inline-flex;
68
- align-items: center;
69
- gap: 0.4em;
70
- outline: none;
71
- padding: 0;
72
- margin: 0;
73
- }
74
-
75
- /*
73
+ .sterling-radio {
74
+ display: inline-flex;
75
+ align-content: stretch;
76
+ align-items: stretch;
77
+ box-sizing: border-box;
78
+ font: inherit;
79
+ gap: 0.4em;
80
+ outline: none;
81
+ padding: 0;
82
+ margin: 0;
83
+ }
84
+ /*
76
85
  The container
77
86
  - allows the input to be hidden
78
87
  - avoids input participating in layout
79
88
  - prevents collisions with surrounding slots
80
89
  */
81
- .container {
82
- box-sizing: border-box;
83
- position: relative;
84
- font: inherit;
85
- display: flex;
86
- align-items: center;
87
- }
90
+ .container {
91
+ box-sizing: border-box;
92
+ position: relative;
93
+ font: inherit;
94
+ display: flex;
95
+ align-items: center;
96
+ }
88
97
 
89
- /*
98
+ /*
90
99
  The input is hidden since the built-in browser radio cannot be customized
91
100
  */
92
- input {
93
- font: inherit;
94
- margin: 0;
95
- padding: 0;
96
- position: absolute;
97
- opacity: 0;
98
- }
101
+ input {
102
+ font: inherit;
103
+ margin: 0;
104
+ padding: 0;
105
+ position: absolute;
106
+ opacity: 0;
107
+ height: 21px;
108
+ width: 21px;
109
+ }
99
110
 
100
- /*
111
+ /*
101
112
  The indicator handles both the radio box and circle mark.
102
113
  The box cannot be on the container since the adjacent sibling selector is needed
103
114
  and there is not a parent CSS selector.
104
115
  */
105
- .indicator {
106
- background-color: var(--Input__background-color);
107
- border-color: var(--Input__border-color);
108
- border-style: var(--Input__border-style);
109
- border-width: var(--Input__border-width);
110
- border-radius: 10000px;
111
- box-sizing: border-box;
112
- display: inline-block;
113
- height: 21px;
114
- position: relative;
115
- transition: background-color 250ms, color 250ms, border-color 250ms;
116
- width: 21px;
117
- }
118
-
119
- input:checked + .indicator {
120
- background-color: var(--Input__background-color);
121
- border-color: var(--Input__border-color);
122
- }
116
+ .indicator {
117
+ background-color: var(--Input__background-color);
118
+ border-color: var(--Input__border-color);
119
+ border-style: var(--Input__border-style);
120
+ border-width: var(--Input__border-width);
121
+ border-radius: 10000px;
122
+ box-sizing: border-box;
123
+ display: inline-block;
124
+ height: 21px;
125
+ position: relative;
126
+ pointer-events: none;
127
+ transition: background-color 250ms, color 250ms, border-color 250ms;
128
+ width: 21px;
129
+ }
123
130
 
124
- input:focus-visible + .indicator {
125
- outline-color: var(--Common__outline-color);
126
- outline-offset: var(--Common__outline-offset);
127
- outline-style: var(--Common__outline-style);
128
- outline-width: var(--Common__outline-width);
129
- }
131
+ input:checked + .indicator {
132
+ background-color: var(--Input__background-color);
133
+ border-color: var(--Input__border-color);
134
+ }
130
135
 
131
- input:disabled + .indicator {
132
- background-color: var(--Input__background-color--disabled);
133
- border-color: var(--Input__border-color--disabled);
134
- }
136
+ input:focus-visible + .indicator {
137
+ outline-color: var(--Common__outline-color);
138
+ outline-offset: var(--Common__outline-offset);
139
+ outline-style: var(--Common__outline-style);
140
+ outline-width: var(--Common__outline-width);
141
+ }
135
142
 
136
- .indicator::after {
137
- background-color: transparent;
138
- border-radius: 10000px;
139
- content: '';
140
- height: 9px;
141
- left: 50%;
142
- position: absolute;
143
- top: 50%;
144
- transform: translate(-50%, -50%);
145
- transition: background-color 250ms;
146
- width: 9px;
147
- }
143
+ input:disabled + .indicator {
144
+ background-color: var(--Input__background-color--disabled);
145
+ border-color: var(--Input__border-color--disabled);
146
+ }
148
147
 
149
- input:checked + .indicator::after {
150
- background-color: var(--Input__color);
151
- }
148
+ .indicator::after {
149
+ background-color: transparent;
150
+ border-radius: 10000px;
151
+ content: '';
152
+ height: 9px;
153
+ left: 50%;
154
+ position: absolute;
155
+ top: 50%;
156
+ transform: translate(-50%, -50%);
157
+ transition: background-color 250ms;
158
+ width: 9px;
159
+ }
152
160
 
153
- input:checked:disabled + .indicator::after {
154
- background-color: var(--Input__color--disabled);
155
- }
161
+ input:checked + .indicator::after {
162
+ background-color: var(--Input__color);
163
+ }
156
164
 
157
- .label-content {
158
- color: var(--Input__color);
159
- transition: background-color 250ms, color 250ms, border-color 250ms;
160
- }
165
+ input:checked:disabled + .indicator::after {
166
+ background-color: var(--Input__color--disabled);
167
+ }
161
168
 
162
- .label-content.disabled {
163
- color: var(--Input__color--disabled);
164
- }
169
+ .label {
170
+ user-select: none;
171
+ margin-top: 0.25em;
172
+ }
165
173
 
166
- @media (prefers-reduced-motion) {
167
- .indicator,
168
- .indicator::after,
169
- .label-content {
170
- transition: none;
171
- }
172
- }
174
+ @media (prefers-reduced-motion) {
175
+ .indicator,
176
+ .indicator::after {
177
+ transition: none;
178
+ }
179
+ }
173
180
  </style>