glasslikeui 1.9.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 CHANGED
@@ -173,6 +173,12 @@ when there is none).
173
173
  under `dir="rtl"` leading is the right. The button moves in the DOM as well,
174
174
  so Tab reaches it first in the header when it leads. The title stays centred
175
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.
176
182
 
177
183
  ```svelte
178
184
  <Sheet bind:isOpen title="Options" closePlacement="trailing">
@@ -432,6 +438,7 @@ These are unset by default, so you can set them on `:root` or on any ancestor.
432
438
  | `--color-on-accent` | Labels on accent fills: filled `Button`, filled `IconButton` and `glassProminent`. | `white` |
433
439
  | `--color-on-danger` | The `destructive` `Button` label. | `white` |
434
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) |
435
442
  | `--glass-button-fill` | The resting fill of the plain `glass` `Button`. You own its contrast. | see below |
436
443
  | `--glass-button-fill-hover` | Its hover fill. | `--glass-button-fill`, else the library hover fill |
437
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';
@@ -68,10 +75,10 @@
68
75
  const uid = $props.id();
69
76
  const titleId = `${uid}-title`;
70
77
 
71
- const closeLeads = $derived(closePlacement !== 'trailing');
78
+ const closeLeads = $derived(closeButtonLeads(closePlacement));
72
79
 
73
80
  const fractions = $derived(detentFractions(detents));
74
- const initialIndex = $derived(Math.max(0, detents.indexOf(initialDetent)));
81
+ const initialIndex = $derived(initialDetentIndex(detents, initialDetent));
75
82
 
76
83
  let currentIndex = $derived(initialIndex);
77
84
  let sheetEl = $state<HTMLElement | undefined>();
@@ -120,7 +127,7 @@
120
127
  function close() {
121
128
  // A closed or already closing sheet ignores repeat requests, so onClose
122
129
  // fires exactly once per close.
123
- if (!isOpen || exit) return;
130
+ if (!canCloseSheet(isOpen, exit !== null)) return;
124
131
  beginExit();
125
132
  isOpen = false;
126
133
  onClose?.();
@@ -128,11 +135,11 @@
128
135
 
129
136
  function handleKeydown(e: KeyboardEvent) {
130
137
  // The window listener is always attached, so a closed sheet would
131
- // otherwise fire onClose on every Escape.
132
- if (!isOpen) return;
133
- if (e.key === 'Escape') {
138
+ // otherwise fire onClose on every Escape: sheetKeyAction ignores keys then.
139
+ const action = sheetKeyAction(e.key, isOpen);
140
+ if (action === 'close') {
134
141
  close();
135
- } else if (e.key === 'Tab' && sheetEl) {
142
+ } else if (action === 'trap' && sheetEl) {
136
143
  trapTab(e, sheetEl);
137
144
  }
138
145
  }
@@ -168,7 +175,7 @@
168
175
 
169
176
  function trackScrollTop(node: HTMLElement) {
170
177
  // Content is mounted afresh on every open, so start from its real offset.
171
- const sync = () => (contentAtTop = node.scrollTop <= 0);
178
+ const sync = () => (contentAtTop = isAtScrollTop(node.scrollTop));
172
179
  sync();
173
180
  node.addEventListener('scroll', sync, { passive: true });
174
181
  return () => node.removeEventListener('scroll', sync);
@@ -384,6 +391,10 @@
384
391
  grid-template-columns: 36px minmax(0, 1fr) 36px;
385
392
  align-items: center;
386
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));
387
398
  }
388
399
 
389
400
  /* Grid lines are logical: column 1 is the inline start, so a leading close
@@ -403,6 +414,17 @@
403
414
  grid-column: 3;
404
415
  }
405
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;
426
+ }
427
+
406
428
  .sheet-close-btn {
407
429
  display: inline-flex;
408
430
  align-items: center;
@@ -435,7 +457,7 @@
435
457
  .sheet-title {
436
458
  font-size: 17px;
437
459
  font-weight: 600;
438
- color: var(--color-text);
460
+ color: var(--color-text, var(--glass-text-color-default, #f5f5f7));
439
461
  text-align: center;
440
462
  font-family: var(--font-system);
441
463
  margin: 0;
@@ -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
  /* ========================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glasslikeui",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "description": "Svelte component library with frosted glass materials",
5
5
  "license": "MPL-2.0",
6
6
  "type": "module",