@geoffcox/sterling-svelte 0.0.23 → 0.0.25

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/Button.svelte CHANGED
@@ -1,4 +1,5 @@
1
- <script>export let variant = "regular";
1
+ <script>export let disabled = false;
2
+ export let variant = "regular";
2
3
  export let shape = "rounded";
3
4
  let buttonRef;
4
5
  export const click = () => {
@@ -23,6 +24,7 @@ export const focus = (options) => {
23
24
  class:circular={shape === 'circular'}
24
25
  class:outline={variant === 'outline'}
25
26
  class:ghost={variant === 'ghost'}
27
+ {disabled}
26
28
  type="button"
27
29
  on:blur
28
30
  on:click
@@ -122,13 +124,6 @@ export const focus = (options) => {
122
124
  outline-width: var(--stsv-Common__outline-width);
123
125
  }
124
126
 
125
- button:disabled {
126
- background-color: var(--stsv-Common__background-color--disabled);
127
- border-color: var(--stsv-Common__border-color--disabled);
128
- color: var(--stsv-Common__color--disabled);
129
- cursor: not-allowed;
130
- }
131
-
132
127
  button.outline {
133
128
  background-color: transparent;
134
129
  }
@@ -141,14 +136,6 @@ export const focus = (options) => {
141
136
  background-color: var(--stsv-Button__background-color--active);
142
137
  }
143
138
 
144
- button.outline:disabled {
145
- background-color: transparent;
146
- }
147
-
148
- button.outline:disabled:hover {
149
- border-color: var(--stsv-Common__border-color--disabled);
150
- }
151
-
152
139
  button.ghost {
153
140
  background-color: transparent;
154
141
  border-color: transparent;
@@ -168,12 +155,20 @@ export const focus = (options) => {
168
155
  border-color: var(--stsv-Button__border-color--focus);
169
156
  }
170
157
 
171
- button.ghost:disabled {
172
- border-color: transparent;
173
- }
174
-
175
- button.ghost:disabled:hover {
176
- background-color: var(--stsv-Common__background-color--disabled);
158
+ button:disabled {
159
+ cursor: not-allowed;
160
+ position: relative;
161
+ }
162
+
163
+ button:disabled::after {
164
+ content: '';
165
+ position: absolute;
166
+ left: 0;
167
+ right: 0;
168
+ top: 0;
169
+ bottom: 0;
170
+ background: var(--stsv-Disabled__background);
171
+ pointer-events: none;
177
172
  }
178
173
 
179
174
  @media (prefers-reduced-motion) {
@@ -2,6 +2,7 @@ import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
4
  [x: string]: any;
5
+ disabled?: boolean | undefined;
5
6
  variant?: "regular" | "outline" | "ghost" | undefined;
6
7
  shape?: "circular" | "rounded" | "square" | undefined;
7
8
  click?: (() => void) | undefined;
package/Checkbox.svelte CHANGED
@@ -24,10 +24,11 @@ export const focus = (options) => {
24
24
  @component
25
25
  A styled HTML input type=checkbox element.
26
26
  -->
27
- <div class="sterling-checkbox">
27
+ <div class="sterling-checkbox" class:disabled>
28
28
  <div class="container">
29
29
  <input
30
30
  bind:this={inputRef}
31
+ bind:checked
31
32
  {disabled}
32
33
  {id}
33
34
  type="checkbox"
@@ -56,13 +57,12 @@ export const focus = (options) => {
56
57
  on:mouseout
57
58
  on:mouseup
58
59
  on:wheel
59
- bind:checked
60
60
  {...$$restProps}
61
61
  />
62
62
  <div class="indicator" />
63
63
  </div>
64
64
  {#if $$slots.default}
65
- <Label {disabled} for={id}>
65
+ <Label for={id}>
66
66
  <slot {checked} {disabled} inputId={id} value={$$restProps.value}>
67
67
  {$$restProps.value}
68
68
  </slot>
@@ -133,6 +133,11 @@ export const focus = (options) => {
133
133
  border-color: var(--stsv-Input__border-color);
134
134
  }
135
135
 
136
+ .sterling-checkbox:hover .indicator {
137
+ background-color: var(--stsv-Input__background-color--hover);
138
+ border-color: var(--stsv-Input__border-color--hover);
139
+ }
140
+
136
141
  input:focus-visible + .indicator {
137
142
  outline-color: var(--stsv-Common__outline-color);
138
143
  outline-offset: var(--stsv-Common__outline-offset);
@@ -140,15 +145,10 @@ export const focus = (options) => {
140
145
  outline-width: var(--stsv-Common__outline-width);
141
146
  }
142
147
 
143
- input:disabled + .indicator {
144
- background-color: var(--stsv-Common__background-color--disabled);
145
- border-color: var(--stsv-Common__border-color--disabled);
146
- }
147
-
148
148
  /*
149
149
  The checkmark is a rotated L centered in the box.
150
150
  */
151
- input:checked + .indicator::after {
151
+ .indicator::after {
152
152
  border-color: var(--stsv-Input__color);
153
153
  border-style: solid;
154
154
  border-width: 0 3px 3px 0;
@@ -160,18 +160,45 @@ export const focus = (options) => {
160
160
  top: 45%;
161
161
  transform: translate(-50%, -50%) rotate(45deg);
162
162
  transform-origin: center;
163
- transition: border-color 250ms;
163
+ transition: border-color 250ms, opacity 150ms;
164
164
  width: 7px;
165
- visibility: visible;
165
+ opacity: 0;
166
+ }
167
+
168
+ input:checked + .indicator::after {
169
+ opacity: 1;
170
+ }
171
+
172
+ .sterling-checkbox:hover input:checked + .indicator::after {
173
+ border-color: var(--stsv-Input__color--hover);
174
+ }
175
+
176
+ .sterling-checkbox.disabled,
177
+ .sterling-checkbox.disabled input {
178
+ cursor: not-allowed;
179
+ }
180
+
181
+ .container::after {
182
+ background: var(--stsv-Disabled__background);
183
+ bottom: 0;
184
+ content: '';
185
+ left: 0;
186
+ opacity: 0;
187
+ position: absolute;
188
+ right: 0;
189
+ top: 0;
190
+ pointer-events: none;
191
+ transition: opacity 250ms;
166
192
  }
167
193
 
168
- input:checked:disabled + .indicator::after {
169
- border-color: var(--stsv-Common__color--disabled);
194
+ .sterling-checkbox.disabled .container::after {
195
+ opacity: 1;
170
196
  }
171
197
 
172
198
  @media (prefers-reduced-motion) {
173
199
  .indicator,
174
- input:checked + .indicator::after {
200
+ .indicator::after,
201
+ .container::after {
175
202
  transition: none;
176
203
  }
177
204
  }
package/Dropdown.svelte CHANGED
@@ -1,5 +1,5 @@
1
- <script>import { computePosition, flip, offset, shift, autoUpdate } from "@floating-ui/dom";
2
- import { createEventDispatcher, onMount, tick } from "svelte";
1
+ <script>import { createEventDispatcher } from "svelte";
2
+ import Popup from "./Popover.svelte";
3
3
  import { clickOutside } from "./actions/clickOutside";
4
4
  import { idGenerator } from "./idGenerator";
5
5
  const popupId = idGenerator.nextId("Dropdown-popup");
@@ -8,11 +8,7 @@ export let disabled = false;
8
8
  export let open = false;
9
9
  export let stayOpenOnClickAway = false;
10
10
  let dropdownRef;
11
- let popupRef;
12
- let popupPosition = {
13
- x: void 0,
14
- y: void 0
15
- };
11
+ let popupContentRef;
16
12
  const dispatch = createEventDispatcher();
17
13
  const raiseOpen = (open2) => {
18
14
  dispatch("open", { open: open2 });
@@ -29,29 +25,11 @@ export const blur = () => {
29
25
  export const focus = (options) => {
30
26
  dropdownRef?.focus(options);
31
27
  };
32
- let mounted = false;
33
- onMount(() => {
34
- mounted = true;
35
- const cleanup = autoUpdate(dropdownRef, popupRef, async () => {
36
- const { x, y } = await computePosition(dropdownRef, popupRef, {
37
- placement: "bottom-end",
38
- middleware: [offset({ mainAxis: 2 }), flip(), shift({ padding: 0 })]
39
- });
40
- if (open) {
41
- popupPosition = { x, y };
42
- }
43
- });
44
- return cleanup;
45
- });
46
28
  const onClick = (event) => {
47
- if (!disabled && mounted) {
48
- const targetNode = event.target;
49
- const withinPopup = popupRef?.contains(targetNode);
50
- if (!withinPopup) {
51
- open = !open;
52
- event.preventDefault();
53
- event.stopPropagation();
54
- }
29
+ if (!disabled) {
30
+ open = !open;
31
+ event.preventDefault();
32
+ event.stopPropagation();
55
33
  }
56
34
  };
57
35
  const onKeydown = (event) => {
@@ -81,7 +59,7 @@ const onClickOutside = (event) => {
81
59
  class:disabled
82
60
  role="combobox"
83
61
  tabindex="0"
84
- use:clickOutside
62
+ use:clickOutside={{ ignoreOthers: [popupContentRef] }}
85
63
  on:blur
86
64
  on:click
87
65
  on:click={onClick}
@@ -120,15 +98,11 @@ const onClickOutside = (event) => {
120
98
  </div>
121
99
  </slot>
122
100
 
123
- <div
124
- bind:this={popupRef}
125
- class="popup"
126
- class:open
127
- id={popupId}
128
- style="left:{popupPosition.x}px; top:{popupPosition.y}px"
129
- >
130
- <slot {composed} {disabled} {open} />
131
- </div>
101
+ <Popup reference={dropdownRef} open={!disabled && open}>
102
+ <div class="popup-content" bind:this={popupContentRef}>
103
+ <slot {composed} {disabled} {open} />
104
+ </div>
105
+ </Popup>
132
106
  </div>
133
107
 
134
108
  <style>
@@ -146,6 +120,7 @@ const onClickOutside = (event) => {
146
120
  grid-template-rows: auto;
147
121
  outline: none;
148
122
  padding: 0;
123
+ position: relative;
149
124
  transition: background-color 250ms, color 250ms, border-color 250ms;
150
125
  }
151
126
 
@@ -166,22 +141,39 @@ const onClickOutside = (event) => {
166
141
  }
167
142
 
168
143
  .sterling-dropdown.disabled {
169
- background-color: var(--stsv-Common__background-color--disabled);
170
- border-color: var(--stsv--Common__border-color--disabled);
171
- color: var(--stsv-Common__color--disabled);
172
144
  cursor: not-allowed;
173
145
  outline: none;
174
146
  }
175
147
 
148
+ .sterling-dropdown::after {
149
+ background: var(--stsv-Disabled__background);
150
+ bottom: 0;
151
+ content: '';
152
+ left: 0;
153
+ opacity: 0;
154
+ position: absolute;
155
+ right: 0;
156
+ top: 0;
157
+ pointer-events: none;
158
+ transition: opacity 250ms;
159
+ }
160
+
161
+ .sterling-dropdown.disabled::after {
162
+ opacity: 1;
163
+ }
164
+
176
165
  .sterling-dropdown.composed,
177
166
  .sterling-dropdown.composed:hover,
178
- .sterling-dropdown.composed.focus,
179
- .sterling-dropdown.composed.disabled {
167
+ .sterling-dropdown.composed.focus {
180
168
  background: none;
181
169
  border: none;
182
170
  outline: none;
183
171
  }
184
172
 
173
+ .sterling-dropdown.composed.disabled::after {
174
+ opacity: 0;
175
+ }
176
+
185
177
  .button {
186
178
  grid-column-start: 2;
187
179
  grid-row-start: 1;
@@ -248,8 +240,13 @@ const onClickOutside = (event) => {
248
240
  grid-template-rows: 1fr;
249
241
  }
250
242
 
243
+ .popup-content {
244
+ padding: 0.25em;
245
+ }
246
+
251
247
  @media (prefers-reduced-motion) {
252
- .sterling-dropdown {
248
+ .sterling-dropdown,
249
+ .sterling-dropdown::after {
253
250
  transition: none;
254
251
  }
255
252
  }
package/Field.svelte CHANGED
@@ -180,7 +180,7 @@ const onClick = () => {
180
180
  transition: background-color 250ms, color 250ms, border-color 250ms;
181
181
  }
182
182
 
183
- .sterling-field:hover {
183
+ .sterling-field:not(.disabled):hover {
184
184
  background-color: var(--stsv-Input__background-color--hover);
185
185
  border-color: var(--stsv-Input__border-color--hover);
186
186
  color: var(--stsv-Input__color--hover);
@@ -196,9 +196,11 @@ const onClick = () => {
196
196
  }
197
197
 
198
198
  .sterling-field.disabled {
199
- background-color: var(--stsv-Common__background-color--disabled);
200
- border-color: var(--stsv--Common__border-color--disabled);
201
- color: var(--stsv-Common__color--disabled);
199
+ cursor: not-allowed;
200
+ }
201
+
202
+ .sterling-field.disabled * {
203
+ cursor: not-allowed;
202
204
  }
203
205
 
204
206
  .label-text {
@@ -211,15 +213,17 @@ const onClick = () => {
211
213
  margin: 0;
212
214
  }
213
215
 
214
- .sterling-field.disabled .label-text {
215
- color: var(--stsv-Common__color--disabled);
216
+ .content {
217
+ display: grid;
216
218
  }
217
219
 
218
220
  .message {
221
+ box-sizing: border-box;
219
222
  font-size: 0.8em;
220
223
  background-color: var(--stsv-Display__background-color);
221
224
  color: var(--stsv-Display__color);
222
225
  padding: 0.5em;
226
+ width: 100%;
223
227
  transition: background-color 250ms, color 250ms, border-color 250ms;
224
228
  }
225
229
 
@@ -247,12 +251,6 @@ const onClick = () => {
247
251
  color: var(--stsv-Error__color);
248
252
  }
249
253
 
250
- .sterling-field.disabled .message {
251
- background-color: var(--stsv-Common__background-color--disabled);
252
- border-color: var(--stsv--Common__border-color--disabled);
253
- color: var(--stsv-Common__color--disabled);
254
- }
255
-
256
254
  .required {
257
255
  text-align: center;
258
256
  font-weight: bold;
@@ -271,6 +269,7 @@ const onClick = () => {
271
269
 
272
270
  @media (prefers-reduced-motion) {
273
271
  .sterling-field,
272
+ .sterling-field::after,
274
273
  .message {
275
274
  transition: none;
276
275
  }
package/Input.svelte CHANGED
@@ -39,51 +39,59 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
39
39
  <slot {composed} {disabled} {value} />
40
40
  </Label>
41
41
  {/if}
42
- <input
43
- bind:this={inputRef}
44
- class="sterling-input"
45
- class:composed
46
- {disabled}
47
- {id}
48
- bind:value
49
- on:beforeinput
50
- on:blur
51
- on:click
52
- on:change
53
- on:copy
54
- on:cut
55
- on:paste
56
- on:dblclick
57
- on:dragend
58
- on:dragenter
59
- on:dragleave
60
- on:dragover
61
- on:dragstart
62
- on:drop
63
- on:focus
64
- on:focusin
65
- on:focusout
66
- on:input
67
- on:invalid
68
- on:keydown
69
- on:keypress
70
- on:keyup
71
- on:mousedown
72
- on:mouseenter
73
- on:mouseleave
74
- on:mousemove
75
- on:mouseover
76
- on:mouseout
77
- on:mouseup
78
- on:select
79
- on:submit
80
- on:reset
81
- on:wheel
82
- {...$$restProps}
83
- />
42
+ <div class="sterling-input" class:composed class:disabled>
43
+ <input
44
+ bind:this={inputRef}
45
+ {disabled}
46
+ {id}
47
+ bind:value
48
+ on:beforeinput
49
+ on:blur
50
+ on:click
51
+ on:change
52
+ on:copy
53
+ on:cut
54
+ on:paste
55
+ on:dblclick
56
+ on:dragend
57
+ on:dragenter
58
+ on:dragleave
59
+ on:dragover
60
+ on:dragstart
61
+ on:drop
62
+ on:focus
63
+ on:focusin
64
+ on:focusout
65
+ on:input
66
+ on:invalid
67
+ on:keydown
68
+ on:keypress
69
+ on:keyup
70
+ on:mousedown
71
+ on:mouseenter
72
+ on:mouseleave
73
+ on:mousemove
74
+ on:mouseover
75
+ on:mouseout
76
+ on:mouseup
77
+ on:select
78
+ on:submit
79
+ on:reset
80
+ on:wheel
81
+ {...$$restProps}
82
+ />
83
+ </div>
84
84
 
85
85
  <style>
86
86
  .sterling-input {
87
+ box-sizing: border-box;
88
+ display: inline-block;
89
+ margin: 0;
90
+ padding: 0;
91
+ position: relative;
92
+ }
93
+
94
+ input {
87
95
  background-color: var(--stsv-Input__background-color);
88
96
  border-color: var(--stsv-Input__border-color);
89
97
  border-radius: var(--stsv-Input__border-radius);
@@ -97,13 +105,13 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
97
105
  transition: background-color 250ms, color 250ms, border-color 250ms;
98
106
  }
99
107
 
100
- .sterling-input:hover {
108
+ .sterling-input:hover input {
101
109
  background-color: var(--stsv-Input__background-color--hover);
102
110
  border-color: var(--stsv-Input__border-color--hover);
103
111
  color: var(--stsv-Input__color--hover);
104
112
  }
105
113
 
106
- .sterling-input:focus {
114
+ input:focus {
107
115
  background-color: var(--stsv-Input__background-color--focus);
108
116
  border-color: var(--stsv-Input__border-color--focus);
109
117
  color: var(--stsv-Input__color--focus);
@@ -113,33 +121,43 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
113
121
  outline-width: var(--stsv-Common__outline-width);
114
122
  }
115
123
 
116
- .sterling-input:disabled {
117
- background-color: var(--stsv-Common__background-color--disabled);
118
- border-color: var(--stsv--Common__border-color--disabled);
119
- color: var(--stsv-Common__color--disabled);
120
- cursor: not-allowed;
121
- }
122
-
123
- .sterling-input.composed,
124
- .sterling-input.composed:hover,
125
- .sterling-input.composed:focus,
126
- .sterling-input.composed.disabled {
124
+ .sterling-input.composed input,
125
+ .sterling-input.composed:hover input,
126
+ .sterling-input.composed:focus input {
127
127
  background: transparent;
128
128
  border: none;
129
129
  outline: none;
130
130
  }
131
131
 
132
- .sterling-input::placeholder {
132
+ input::placeholder {
133
133
  color: var(--stsv-Display__color--faint);
134
- transition: background-color 250ms, color 250ms, border-color 250ms;
135
134
  }
136
135
 
137
- .sterling-input:disabled::placeholder {
138
- color: var(--stsv-Display__color--disabled);
136
+ .sterling-input.disabled * {
137
+ cursor: not-allowed;
138
+ outline: none;
139
+ }
140
+
141
+ .sterling-input::after {
142
+ background: var(--stsv-Disabled__background);
143
+ bottom: 0;
144
+ content: '';
145
+ left: 0;
146
+ opacity: 0;
147
+ position: absolute;
148
+ right: 0;
149
+ top: 0;
150
+ pointer-events: none;
151
+ transition: opacity 250ms;
152
+ }
153
+
154
+ .sterling-input.disabled::after {
155
+ opacity: 1;
139
156
  }
140
157
 
141
158
  @media (prefers-reduced-motion) {
142
- .sterling-input {
159
+ .sterling-input::after,
160
+ input {
143
161
  transition: none;
144
162
  }
145
163
  }
package/List.svelte CHANGED
@@ -231,7 +231,9 @@ A list of items where a single item can be selected.
231
231
  on:paste
232
232
  {...$$restProps}
233
233
  >
234
- <slot {composed} {disabled} {horizontal} {selectedValue} />
234
+ <div class="container">
235
+ <slot {composed} {disabled} {horizontal} {selectedValue} />
236
+ </div>
235
237
  </div>
236
238
 
237
239
  <style>
@@ -243,13 +245,10 @@ A list of items where a single item can be selected.
243
245
  border-width: var(--stsv-Common__border-width);
244
246
  box-sizing: border-box;
245
247
  color: var(--stsv-Common__color);
246
- display: flex;
247
- flex-direction: column;
248
- flex-wrap: nowrap;
249
248
  height: 100%;
250
- margin: 0;
251
249
  overflow-x: hidden;
252
- overflow-y: scroll;
250
+ overflow-y: auto;
251
+ margin: 0;
253
252
  outline: none;
254
253
  padding: 0;
255
254
  position: relative;
@@ -257,9 +256,8 @@ A list of items where a single item can be selected.
257
256
  }
258
257
 
259
258
  .sterling-list.horizontal {
260
- flex-direction: row;
261
259
  height: unset;
262
- overflow-x: scroll;
260
+ overflow-x: auto;
263
261
  overflow-y: hidden;
264
262
  width: 100%;
265
263
  }
@@ -278,13 +276,6 @@ A list of items where a single item can be selected.
278
276
  outline-width: var(--stsv-Common__outline-width);
279
277
  }
280
278
 
281
- .sterling-list.disabled {
282
- background-color: var(--stsv-Common__background-color--disabled);
283
- border-color: var(--stsv--Common__border-color--disabled);
284
- color: var(--stsv-Common__color--disabled);
285
- cursor: not-allowed;
286
- }
287
-
288
279
  .sterling-list.composed,
289
280
  .sterling-list.composed:hover,
290
281
  .sterling-list.composed.using-keyboard:focus-within,
@@ -294,8 +285,46 @@ A list of items where a single item can be selected.
294
285
  outline: none;
295
286
  }
296
287
 
288
+ .sterling-list.disabled * {
289
+ cursor: not-allowed;
290
+ }
291
+
292
+ /* ----- container - a layout panel that grows with the items ----- */
293
+
294
+ .container {
295
+ display: flex;
296
+ position: relative;
297
+ flex-direction: column;
298
+ flex-wrap: nowrap;
299
+ }
300
+
301
+ .sterling-list.horizontal .container {
302
+ flex-direction: row;
303
+ }
304
+
305
+ .container::after {
306
+ background: var(--stsv-Disabled__background);
307
+ content: '';
308
+ bottom: 0;
309
+ left: 0;
310
+ opacity: 0;
311
+ position: absolute;
312
+ right: 0;
313
+ top: 0;
314
+ height: 100%;
315
+ pointer-events: none;
316
+ transition: opacity 250ms;
317
+ }
318
+
319
+ .sterling-list.disabled .container::after {
320
+ opacity: 1;
321
+ }
322
+
323
+ /* ----- media queries ----- */
324
+
297
325
  @media (prefers-reduced-motion) {
298
- .sterling-list {
326
+ .sterling-list,
327
+ .container::after {
299
328
  transition: none;
300
329
  }
301
330
  }