glasslikeui 1.8.0 → 1.9.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.
- package/README.md +22 -2
- package/dist/actions/sheetLogic.d.ts +25 -0
- package/dist/actions/sheetLogic.js +38 -0
- package/dist/components/glass/Sheet.svelte +92 -29
- package/dist/components/glass/Sheet.svelte.d.ts +8 -0
- package/dist/components/interactive/Button.svelte +3 -0
- package/dist/styles/glasslikeui.css +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -164,8 +164,27 @@ to mirror all of these onto an ancestor that your strip can read.
|
|
|
164
164
|
```
|
|
165
165
|
|
|
166
166
|
A sheet with a `title` shows a header with the title centred and an icon-only
|
|
167
|
-
close button (`aria-label="Close"`) at the
|
|
168
|
-
`dialog`, labelled by its title (or by an `aria-label`
|
|
167
|
+
close button (`aria-label="Close"`) at the leading side, as on iOS 26 sheets.
|
|
168
|
+
The sheet is a modal `dialog`, labelled by its title (or by an `aria-label`
|
|
169
|
+
when there is none).
|
|
170
|
+
|
|
171
|
+
- `closePlacement` picks the side of the close button: `'leading'` (the
|
|
172
|
+
default) or `'trailing'`, the placement before 1.9. The sides are logical:
|
|
173
|
+
under `dir="rtl"` leading is the right. The button moves in the DOM as well,
|
|
174
|
+
so Tab reaches it first in the header when it leads. The title stays centred
|
|
175
|
+
either way. The header carries `data-close-placement` with the value in use.
|
|
176
|
+
Either way the button sits 4px in from the header's padding, so the two
|
|
177
|
+
placements are mirror images.
|
|
178
|
+
- The title and the close button glyph use `--color-text` and
|
|
179
|
+
`--color-text-secondary` when the page sets them. Unset, they fall back to
|
|
180
|
+
`--glass-text-color-default`: `#f5f5f7` in the dark theme and `#1d1d1f` in
|
|
181
|
+
the light one.
|
|
182
|
+
|
|
183
|
+
```svelte
|
|
184
|
+
<Sheet bind:isOpen title="Options" closePlacement="trailing">
|
|
185
|
+
{#snippet children()}...{/snippet}
|
|
186
|
+
</Sheet>
|
|
187
|
+
```
|
|
169
188
|
|
|
170
189
|
- Dragging the handle or the header moves the sheet between its detents.
|
|
171
190
|
Presses on the close button or on interactive content never start a drag.
|
|
@@ -419,6 +438,7 @@ These are unset by default, so you can set them on `:root` or on any ancestor.
|
|
|
419
438
|
| `--color-on-accent` | Labels on accent fills: filled `Button`, filled `IconButton` and `glassProminent`. | `white` |
|
|
420
439
|
| `--color-on-danger` | The `destructive` `Button` label. | `white` |
|
|
421
440
|
| `--glass-sheet-max-width` | `Sheet` width cap on viewports from 769px. | `900px` |
|
|
441
|
+
| `--color-text` | Text, including the `Sheet` title and header. | the page's; the `Sheet` header falls back to `--glass-text-color-default` (`#f5f5f7` dark, `#1d1d1f` light) |
|
|
422
442
|
| `--glass-button-fill` | The resting fill of the plain `glass` `Button`. You own its contrast. | see below |
|
|
423
443
|
| `--glass-button-fill-hover` | Its hover fill. | `--glass-button-fill`, else the library hover fill |
|
|
424
444
|
| `--glass-button-fill-active` | Its pressed fill. | `--glass-button-fill`, else the library pressed fill |
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decisions Sheet makes, as plain functions, so mutation testing reaches
|
|
3
|
+
* them (Stryker cannot instrument .svelte files). The component wires them to
|
|
4
|
+
* its state and the DOM. Internal.
|
|
5
|
+
*/
|
|
6
|
+
import type { SheetDetentName } from './dragSnapMath';
|
|
7
|
+
/** What a key press on the window does to the sheet. */
|
|
8
|
+
export type SheetKeyAction = 'close' | 'trap' | 'none';
|
|
9
|
+
/**
|
|
10
|
+
* Escape closes an open sheet and Tab is kept inside it. A closed sheet ignores
|
|
11
|
+
* every key: the window listener stays attached, and would otherwise fire
|
|
12
|
+
* onClose on every Escape.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sheetKeyAction(key: string, isOpen: boolean): SheetKeyAction;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a close request is acted on. A closed or already closing sheet
|
|
17
|
+
* ignores repeat requests, so onClose fires exactly once per close.
|
|
18
|
+
*/
|
|
19
|
+
export declare function canCloseSheet(isOpen: boolean, exiting: boolean): boolean;
|
|
20
|
+
/** The detent the sheet opens at: `initial`, or the first one when it is not offered. */
|
|
21
|
+
export declare function initialDetentIndex(detents: readonly SheetDetentName[], initial: SheetDetentName): number;
|
|
22
|
+
/** Whether the close button leads the header. Anything but 'trailing' leads. */
|
|
23
|
+
export declare function closeButtonLeads(placement: 'leading' | 'trailing' | undefined): boolean;
|
|
24
|
+
/** Whether content is at its top. An overscroll bounce above it counts as the top. */
|
|
25
|
+
export declare function isAtScrollTop(scrollTop: number): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decisions Sheet makes, as plain functions, so mutation testing reaches
|
|
3
|
+
* them (Stryker cannot instrument .svelte files). The component wires them to
|
|
4
|
+
* its state and the DOM. Internal.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Escape closes an open sheet and Tab is kept inside it. A closed sheet ignores
|
|
8
|
+
* every key: the window listener stays attached, and would otherwise fire
|
|
9
|
+
* onClose on every Escape.
|
|
10
|
+
*/
|
|
11
|
+
export function sheetKeyAction(key, isOpen) {
|
|
12
|
+
if (!isOpen)
|
|
13
|
+
return 'none';
|
|
14
|
+
if (key === 'Escape')
|
|
15
|
+
return 'close';
|
|
16
|
+
if (key === 'Tab')
|
|
17
|
+
return 'trap';
|
|
18
|
+
return 'none';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Whether a close request is acted on. A closed or already closing sheet
|
|
22
|
+
* ignores repeat requests, so onClose fires exactly once per close.
|
|
23
|
+
*/
|
|
24
|
+
export function canCloseSheet(isOpen, exiting) {
|
|
25
|
+
return isOpen && !exiting;
|
|
26
|
+
}
|
|
27
|
+
/** The detent the sheet opens at: `initial`, or the first one when it is not offered. */
|
|
28
|
+
export function initialDetentIndex(detents, initial) {
|
|
29
|
+
return Math.max(0, detents.indexOf(initial));
|
|
30
|
+
}
|
|
31
|
+
/** Whether the close button leads the header. Anything but 'trailing' leads. */
|
|
32
|
+
export function closeButtonLeads(placement) {
|
|
33
|
+
return placement !== 'trailing';
|
|
34
|
+
}
|
|
35
|
+
/** Whether content is at its top. An overscroll bounce above it counts as the top. */
|
|
36
|
+
export function isAtScrollTop(scrollTop) {
|
|
37
|
+
return scrollTop <= 0;
|
|
38
|
+
}
|
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
import { startSheetExit, type SheetExit } from '../../actions/sheetExit';
|
|
14
14
|
import { inertSiblings } from '../../actions/inertSiblings';
|
|
15
15
|
import { trapTab } from '../../actions/focusTrap';
|
|
16
|
+
import {
|
|
17
|
+
canCloseSheet,
|
|
18
|
+
closeButtonLeads,
|
|
19
|
+
initialDetentIndex,
|
|
20
|
+
isAtScrollTop,
|
|
21
|
+
sheetKeyAction
|
|
22
|
+
} from '../../actions/sheetLogic';
|
|
16
23
|
|
|
17
24
|
/** The parts of the sheet a drag starts from on the press: the handle and the header. */
|
|
18
25
|
const DRAG_REGIONS = '.sheet-handle-container, .sheet-header';
|
|
@@ -39,6 +46,14 @@
|
|
|
39
46
|
* close button, Escape and the backdrop still close the sheet.
|
|
40
47
|
*/
|
|
41
48
|
interactiveDismissDisabled?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Which side of the header the close button sits on. 'leading' (the
|
|
51
|
+
* default, as on iOS 26 sheets) is the left in LTR and the right in RTL;
|
|
52
|
+
* 'trailing' is the opposite side, the placement before 1.9. The button
|
|
53
|
+
* moves in the DOM too, so it is first in the header's Tab order when it
|
|
54
|
+
* leads.
|
|
55
|
+
*/
|
|
56
|
+
closePlacement?: 'leading' | 'trailing';
|
|
42
57
|
class?: string;
|
|
43
58
|
}
|
|
44
59
|
|
|
@@ -53,14 +68,17 @@
|
|
|
53
68
|
showHandle = true,
|
|
54
69
|
draggable = true,
|
|
55
70
|
interactiveDismissDisabled = false,
|
|
71
|
+
closePlacement = 'leading',
|
|
56
72
|
class: className = ''
|
|
57
73
|
}: Props = $props();
|
|
58
74
|
|
|
59
75
|
const uid = $props.id();
|
|
60
76
|
const titleId = `${uid}-title`;
|
|
61
77
|
|
|
78
|
+
const closeLeads = $derived(closeButtonLeads(closePlacement));
|
|
79
|
+
|
|
62
80
|
const fractions = $derived(detentFractions(detents));
|
|
63
|
-
const initialIndex = $derived(
|
|
81
|
+
const initialIndex = $derived(initialDetentIndex(detents, initialDetent));
|
|
64
82
|
|
|
65
83
|
let currentIndex = $derived(initialIndex);
|
|
66
84
|
let sheetEl = $state<HTMLElement | undefined>();
|
|
@@ -109,7 +127,7 @@
|
|
|
109
127
|
function close() {
|
|
110
128
|
// A closed or already closing sheet ignores repeat requests, so onClose
|
|
111
129
|
// fires exactly once per close.
|
|
112
|
-
if (!isOpen
|
|
130
|
+
if (!canCloseSheet(isOpen, exit !== null)) return;
|
|
113
131
|
beginExit();
|
|
114
132
|
isOpen = false;
|
|
115
133
|
onClose?.();
|
|
@@ -117,11 +135,11 @@
|
|
|
117
135
|
|
|
118
136
|
function handleKeydown(e: KeyboardEvent) {
|
|
119
137
|
// The window listener is always attached, so a closed sheet would
|
|
120
|
-
// otherwise fire onClose on every Escape.
|
|
121
|
-
|
|
122
|
-
if (
|
|
138
|
+
// otherwise fire onClose on every Escape: sheetKeyAction ignores keys then.
|
|
139
|
+
const action = sheetKeyAction(e.key, isOpen);
|
|
140
|
+
if (action === 'close') {
|
|
123
141
|
close();
|
|
124
|
-
} else if (
|
|
142
|
+
} else if (action === 'trap' && sheetEl) {
|
|
125
143
|
trapTab(e, sheetEl);
|
|
126
144
|
}
|
|
127
145
|
}
|
|
@@ -157,7 +175,7 @@
|
|
|
157
175
|
|
|
158
176
|
function trackScrollTop(node: HTMLElement) {
|
|
159
177
|
// Content is mounted afresh on every open, so start from its real offset.
|
|
160
|
-
const sync = () => (contentAtTop = node.scrollTop
|
|
178
|
+
const sync = () => (contentAtTop = isAtScrollTop(node.scrollTop));
|
|
161
179
|
sync();
|
|
162
180
|
node.addEventListener('scroll', sync, { passive: true });
|
|
163
181
|
return () => node.removeEventListener('scroll', sync);
|
|
@@ -211,6 +229,26 @@
|
|
|
211
229
|
|
|
212
230
|
<svelte:window onkeydown={handleKeydown} />
|
|
213
231
|
|
|
232
|
+
{#snippet closeButton()}
|
|
233
|
+
<button type="button" class="sheet-close-btn" onclick={close} aria-label="Close">
|
|
234
|
+
<svg
|
|
235
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
236
|
+
width="16"
|
|
237
|
+
height="16"
|
|
238
|
+
viewBox="0 0 24 24"
|
|
239
|
+
fill="none"
|
|
240
|
+
stroke="currentColor"
|
|
241
|
+
stroke-width="2.5"
|
|
242
|
+
stroke-linecap="round"
|
|
243
|
+
stroke-linejoin="round"
|
|
244
|
+
aria-hidden="true"
|
|
245
|
+
focusable="false"
|
|
246
|
+
>
|
|
247
|
+
{@html getIconPath('xmark')}
|
|
248
|
+
</svg>
|
|
249
|
+
</button>
|
|
250
|
+
{/snippet}
|
|
251
|
+
|
|
214
252
|
{#if present}
|
|
215
253
|
<div
|
|
216
254
|
class="sheet-backdrop"
|
|
@@ -248,26 +286,18 @@
|
|
|
248
286
|
{/if}
|
|
249
287
|
|
|
250
288
|
{#if title}
|
|
251
|
-
<header class="sheet-header">
|
|
252
|
-
|
|
289
|
+
<header class="sheet-header" data-close-placement={closeLeads ? 'leading' : 'trailing'}>
|
|
290
|
+
{#if closeLeads}
|
|
291
|
+
{@render closeButton()}
|
|
292
|
+
{:else}
|
|
293
|
+
<div class="sheet-spacer"></div>
|
|
294
|
+
{/if}
|
|
253
295
|
<h2 class="sheet-title" id={titleId}>{title}</h2>
|
|
254
|
-
|
|
255
|
-
<
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
viewBox="0 0 24 24"
|
|
260
|
-
fill="none"
|
|
261
|
-
stroke="currentColor"
|
|
262
|
-
stroke-width="2.5"
|
|
263
|
-
stroke-linecap="round"
|
|
264
|
-
stroke-linejoin="round"
|
|
265
|
-
aria-hidden="true"
|
|
266
|
-
focusable="false"
|
|
267
|
-
>
|
|
268
|
-
{@html getIconPath('xmark')}
|
|
269
|
-
</svg>
|
|
270
|
-
</button>
|
|
296
|
+
{#if closeLeads}
|
|
297
|
+
<div class="sheet-spacer"></div>
|
|
298
|
+
{:else}
|
|
299
|
+
{@render closeButton()}
|
|
300
|
+
{/if}
|
|
271
301
|
</header>
|
|
272
302
|
{/if}
|
|
273
303
|
|
|
@@ -350,8 +380,9 @@
|
|
|
350
380
|
border-radius: 3px;
|
|
351
381
|
}
|
|
352
382
|
|
|
353
|
-
/* Title centred between
|
|
354
|
-
title stays centred whatever its length. The header is also a
|
|
383
|
+
/* Title centred between the close button and an empty cell of the same
|
|
384
|
+
width, so the title stays centred whatever its length. The header is also a
|
|
385
|
+
drag region. */
|
|
355
386
|
.sheet-header {
|
|
356
387
|
padding: 0 var(--spacing-md);
|
|
357
388
|
height: 56px;
|
|
@@ -360,6 +391,38 @@
|
|
|
360
391
|
grid-template-columns: 36px minmax(0, 1fr) 36px;
|
|
361
392
|
align-items: center;
|
|
362
393
|
gap: var(--spacing-sm);
|
|
394
|
+
/* The library does not set --color-text, so fall back to the theme's own
|
|
395
|
+
text colour: unset, the header took the page's, black by default, onto
|
|
396
|
+
a dark sheet. The close button glyph follows it through currentColor. */
|
|
397
|
+
color: var(--color-text, var(--glass-text-color-default, #f5f5f7));
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/* Grid lines are logical: column 1 is the inline start, so a leading close
|
|
401
|
+
button sits on the left in LTR and on the right in RTL. The DOM order
|
|
402
|
+
matches, so Tab reaches the button on the side it is drawn. */
|
|
403
|
+
.sheet-title {
|
|
404
|
+
grid-column: 2;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
.sheet-header[data-close-placement='leading'] .sheet-close-btn,
|
|
408
|
+
.sheet-header[data-close-placement='trailing'] .sheet-spacer {
|
|
409
|
+
grid-column: 1;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
.sheet-header[data-close-placement='leading'] .sheet-spacer,
|
|
413
|
+
.sheet-header[data-close-placement='trailing'] .sheet-close-btn {
|
|
414
|
+
grid-column: 3;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/* The button is narrower than its column. Each placement pushes it to the
|
|
418
|
+
column's side nearest the title, so the two sit the same distance in from
|
|
419
|
+
the header's padding and are exact mirrors. */
|
|
420
|
+
.sheet-header[data-close-placement='leading'] .sheet-close-btn {
|
|
421
|
+
justify-self: end;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
.sheet-header[data-close-placement='trailing'] .sheet-close-btn {
|
|
425
|
+
justify-self: start;
|
|
363
426
|
}
|
|
364
427
|
|
|
365
428
|
.sheet-close-btn {
|
|
@@ -394,7 +457,7 @@
|
|
|
394
457
|
.sheet-title {
|
|
395
458
|
font-size: 17px;
|
|
396
459
|
font-weight: 600;
|
|
397
|
-
color: var(--color-text);
|
|
460
|
+
color: var(--color-text, var(--glass-text-color-default, #f5f5f7));
|
|
398
461
|
text-align: center;
|
|
399
462
|
font-family: var(--font-system);
|
|
400
463
|
margin: 0;
|
|
@@ -16,6 +16,14 @@ interface Props {
|
|
|
16
16
|
* close button, Escape and the backdrop still close the sheet.
|
|
17
17
|
*/
|
|
18
18
|
interactiveDismissDisabled?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Which side of the header the close button sits on. 'leading' (the
|
|
21
|
+
* default, as on iOS 26 sheets) is the left in LTR and the right in RTL;
|
|
22
|
+
* 'trailing' is the opposite side, the placement before 1.9. The button
|
|
23
|
+
* moves in the DOM too, so it is first in the header's Tab order when it
|
|
24
|
+
* leads.
|
|
25
|
+
*/
|
|
26
|
+
closePlacement?: 'leading' | 'trailing';
|
|
19
27
|
class?: string;
|
|
20
28
|
}
|
|
21
29
|
declare const Sheet: import("svelte").Component<Props, {}, string>;
|
|
@@ -98,6 +98,9 @@
|
|
|
98
98
|
|
|
99
99
|
<style>
|
|
100
100
|
.button {
|
|
101
|
+
/* A <button> is border-box in the browser's own styles, an <a> is not.
|
|
102
|
+
Set for both, so a full width link keeps its padding inside its width. */
|
|
103
|
+
box-sizing: border-box;
|
|
101
104
|
display: inline-flex;
|
|
102
105
|
align-items: center;
|
|
103
106
|
justify-content: center;
|
|
@@ -65,6 +65,11 @@
|
|
|
65
65
|
--sheet-focus-ring-inner: #ffffff;
|
|
66
66
|
--sheet-focus-ring-outer: #3b8eea;
|
|
67
67
|
|
|
68
|
+
/* Text where the page sets no --color-text, such as the Sheet title. The
|
|
69
|
+
library leaves --color-text to the page; this is the colour used until
|
|
70
|
+
then. */
|
|
71
|
+
--glass-text-color-default: #f5f5f7;
|
|
72
|
+
|
|
68
73
|
/* ========================================
|
|
69
74
|
Accent system
|
|
70
75
|
======================================== */
|
|
@@ -196,6 +201,8 @@
|
|
|
196
201
|
|
|
197
202
|
--sheet-focus-ring-inner: #000000;
|
|
198
203
|
--sheet-focus-ring-outer: #0071e3;
|
|
204
|
+
|
|
205
|
+
--glass-text-color-default: #1d1d1f;
|
|
199
206
|
}
|
|
200
207
|
|
|
201
208
|
/* ========================================
|