glasslikeui 1.5.0 → 1.6.0
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 +53 -2
- package/dist/actions/deviceMotion.js +2 -3
- package/dist/actions/dragSnap.d.ts +31 -1
- package/dist/actions/dragSnap.js +68 -50
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +2 -0
- package/dist/actions/refreshable.d.ts +36 -0
- package/dist/actions/refreshable.js +157 -0
- package/dist/actions/swipeActions.d.ts +61 -0
- package/dist/actions/swipeActions.js +201 -0
- package/dist/components/glass/Glass.svelte +28 -6
- package/dist/components/glass/Glass.svelte.d.ts +3 -0
- package/dist/components/glass/Sheet.svelte +3 -0
- package/dist/components/interactive/Button.svelte +81 -1
- package/dist/components/interactive/Button.svelte.d.ts +2 -1
- package/dist/components/interactive/Toggle.svelte +110 -0
- package/dist/components/interactive/Toggle.svelte.d.ts +11 -0
- package/dist/components/interactive/index.d.ts +1 -0
- package/dist/components/interactive/index.js +1 -0
- package/dist/components/layout/ScrollView.svelte +83 -15
- package/dist/components/layout/ScrollView.svelte.d.ts +3 -0
- package/dist/components/layout/ZStack.svelte +3 -1
- package/dist/components/list/ListRow.svelte +135 -77
- package/dist/components/list/ListRow.svelte.d.ts +6 -0
- package/dist/components/typography/Label.svelte +82 -0
- package/dist/components/typography/Label.svelte.d.ts +11 -0
- package/dist/components/typography/index.d.ts +1 -0
- package/dist/components/typography/index.js +1 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +2 -0
- package/dist/constants/label.d.ts +15 -0
- package/dist/constants/label.js +14 -0
- package/dist/constants/shapes.d.ts +18 -0
- package/dist/constants/shapes.js +26 -0
- package/dist/constants/variants.d.ts +28 -0
- package/dist/constants/variants.js +26 -0
- package/package.json +6 -2
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
type ScrollEdgeEffect,
|
|
7
7
|
type ScrollEdgeWhich
|
|
8
8
|
} from '../../actions/scrollEdge';
|
|
9
|
+
import { refreshable } from '../../actions/refreshable';
|
|
9
10
|
|
|
10
11
|
interface Props {
|
|
11
12
|
children: Snippet;
|
|
@@ -14,6 +15,9 @@
|
|
|
14
15
|
edgeEffect?: 'none' | ScrollEdgeEffect;
|
|
15
16
|
edges?: ScrollEdgeWhich;
|
|
16
17
|
edgeSize?: string;
|
|
18
|
+
/** Pull-to-refresh handler. Mirrors SwiftUI's .refreshable. */
|
|
19
|
+
onRefresh?: (() => void | Promise<void>) | undefined;
|
|
20
|
+
refreshThreshold?: number | undefined;
|
|
17
21
|
class?: string;
|
|
18
22
|
}
|
|
19
23
|
|
|
@@ -24,27 +28,43 @@
|
|
|
24
28
|
edgeEffect = 'none',
|
|
25
29
|
edges = 'bottom',
|
|
26
30
|
edgeSize,
|
|
31
|
+
onRefresh,
|
|
32
|
+
refreshThreshold,
|
|
27
33
|
class: className = ''
|
|
28
34
|
}: Props = $props();
|
|
35
|
+
|
|
36
|
+
// An attachment that does nothing, so each feature can opt out without
|
|
37
|
+
// multiplying the markup into one branch per combination.
|
|
38
|
+
const noAttachment = () => {};
|
|
39
|
+
|
|
40
|
+
const edgeAttachment = $derived(
|
|
41
|
+
edgeEffect === 'none'
|
|
42
|
+
? noAttachment
|
|
43
|
+
: fromAction(scrollEdge, () => ({ edges, effect: edgeEffect, size: edgeSize }))
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const refreshAttachment = $derived(
|
|
47
|
+
onRefresh
|
|
48
|
+
? fromAction(refreshable, () => ({ onRefresh, threshold: refreshThreshold }))
|
|
49
|
+
: noAttachment
|
|
50
|
+
);
|
|
29
51
|
</script>
|
|
30
52
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
53
|
+
<div
|
|
54
|
+
class="scroll-view axis-{axis} {className}"
|
|
55
|
+
class:hide-indicators={!showsIndicators}
|
|
56
|
+
{@attach edgeAttachment}
|
|
57
|
+
{@attach refreshAttachment}
|
|
58
|
+
>
|
|
59
|
+
{#if onRefresh}
|
|
60
|
+
<div class="refresh-indicator" aria-hidden="true">
|
|
61
|
+
<span class="refresh-spinner"></span>
|
|
35
62
|
</div>
|
|
63
|
+
{/if}
|
|
64
|
+
<div class="scroll-content">
|
|
65
|
+
{@render children()}
|
|
36
66
|
</div>
|
|
37
|
-
|
|
38
|
-
<div
|
|
39
|
-
class="scroll-view axis-{axis} {className}"
|
|
40
|
-
class:hide-indicators={!showsIndicators}
|
|
41
|
-
{@attach fromAction(scrollEdge, () => ({ edges, effect: edgeEffect, size: edgeSize }))}
|
|
42
|
-
>
|
|
43
|
-
<div class="scroll-content">
|
|
44
|
-
{@render children()}
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
{/if}
|
|
67
|
+
</div>
|
|
48
68
|
|
|
49
69
|
<style>
|
|
50
70
|
.scroll-view {
|
|
@@ -81,4 +101,52 @@
|
|
|
81
101
|
display: flex;
|
|
82
102
|
width: max-content;
|
|
83
103
|
}
|
|
104
|
+
|
|
105
|
+
/* Pull to refresh. data-refresh-phase is written by the action, so :global
|
|
106
|
+
keeps these rules from being pruned as unused. */
|
|
107
|
+
.scroll-view:global([data-refresh-phase]) .scroll-content {
|
|
108
|
+
transform: translateY(var(--refresh-pull, 0));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.scroll-view:global([data-refresh-phase='idle']) .scroll-content,
|
|
112
|
+
.scroll-view:global([data-refresh-phase='refreshing']) .scroll-content {
|
|
113
|
+
transition: transform var(--transition-fast);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.refresh-indicator {
|
|
117
|
+
position: absolute;
|
|
118
|
+
top: 0;
|
|
119
|
+
left: 0;
|
|
120
|
+
right: 0;
|
|
121
|
+
display: flex;
|
|
122
|
+
align-items: center;
|
|
123
|
+
justify-content: center;
|
|
124
|
+
height: var(--refresh-pull, 0);
|
|
125
|
+
overflow: hidden;
|
|
126
|
+
pointer-events: none;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.refresh-spinner {
|
|
130
|
+
width: 20px;
|
|
131
|
+
height: 20px;
|
|
132
|
+
border-radius: 50%;
|
|
133
|
+
border: 2px solid var(--color-text-tertiary);
|
|
134
|
+
border-top-color: transparent;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.scroll-view:global([data-refresh-phase='refreshing']) .refresh-spinner {
|
|
138
|
+
animation: refresh-spin 0.8s linear infinite;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@media (prefers-reduced-motion: reduce) {
|
|
142
|
+
.scroll-view:global([data-refresh-phase='refreshing']) .refresh-spinner {
|
|
143
|
+
animation: none;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@keyframes refresh-spin {
|
|
148
|
+
to {
|
|
149
|
+
transform: rotate(360deg);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
84
152
|
</style>
|
|
@@ -7,6 +7,9 @@ interface Props {
|
|
|
7
7
|
edgeEffect?: 'none' | ScrollEdgeEffect;
|
|
8
8
|
edges?: ScrollEdgeWhich;
|
|
9
9
|
edgeSize?: string;
|
|
10
|
+
/** Pull-to-refresh handler. Mirrors SwiftUI's .refreshable. */
|
|
11
|
+
onRefresh?: (() => void | Promise<void>) | undefined;
|
|
12
|
+
refreshThreshold?: number | undefined;
|
|
10
13
|
class?: string;
|
|
11
14
|
}
|
|
12
15
|
declare const ScrollView: import("svelte").Component<Props, {}, string>;
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
bottomTrailing: { justifyContent: 'flex-end', alignItems: 'flex-end' }
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
// An unrecognised alignment (a JavaScript caller, or a value read from data)
|
|
29
|
+
// would otherwise read a property of undefined and crash the render.
|
|
30
|
+
const style = $derived(alignmentStyles[alignment] ?? alignmentStyles.center);
|
|
29
31
|
</script>
|
|
30
32
|
|
|
31
33
|
<div
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
import { HStack } from '../layout';
|
|
4
4
|
import { VStack } from '../layout';
|
|
5
5
|
import { SymbolImage } from '../media';
|
|
6
|
+
import { fromAction } from 'svelte/attachments';
|
|
7
|
+
import {
|
|
8
|
+
swipeActions as swipeGesture,
|
|
9
|
+
type SwipeEdge
|
|
10
|
+
} from '../../actions/swipeActions';
|
|
6
11
|
|
|
7
12
|
interface Props {
|
|
8
13
|
children: Snippet;
|
|
@@ -13,6 +18,11 @@
|
|
|
13
18
|
interactive?: boolean;
|
|
14
19
|
href?: string;
|
|
15
20
|
onclick?: () => void;
|
|
21
|
+
/** Actions revealed by swiping. Mirrors SwiftUI's .swipeActions. */
|
|
22
|
+
swipeActions?: Snippet;
|
|
23
|
+
swipeEdge?: SwipeEdge;
|
|
24
|
+
allowsFullSwipe?: boolean;
|
|
25
|
+
onFullSwipe?: () => void;
|
|
16
26
|
class?: string;
|
|
17
27
|
}
|
|
18
28
|
|
|
@@ -25,91 +35,101 @@
|
|
|
25
35
|
interactive = false,
|
|
26
36
|
href,
|
|
27
37
|
onclick,
|
|
38
|
+
swipeActions,
|
|
39
|
+
swipeEdge = 'trailing',
|
|
40
|
+
allowsFullSwipe = false,
|
|
41
|
+
onFullSwipe,
|
|
28
42
|
class: className = ''
|
|
29
43
|
}: Props = $props();
|
|
30
44
|
|
|
31
45
|
const isInteractive = $derived(interactive || !!href || !!onclick);
|
|
32
|
-
</script>
|
|
33
|
-
|
|
34
|
-
{#if href}
|
|
35
|
-
<a {href} class="list-row {className}" class:interactive={isInteractive} class:has-divider={showDivider}>
|
|
36
|
-
<HStack spacing="sm" alignment="center" class="row-content">
|
|
37
|
-
{#if leading}
|
|
38
|
-
<div class="row-leading">
|
|
39
|
-
{@render leading()}
|
|
40
|
-
</div>
|
|
41
|
-
{/if}
|
|
42
|
-
|
|
43
|
-
<VStack spacing="none" alignment="leading" class="row-main">
|
|
44
|
-
<div class="row-title">
|
|
45
|
-
{@render children()}
|
|
46
|
-
</div>
|
|
47
|
-
{#if subtitle}
|
|
48
|
-
<div class="row-subtitle">{subtitle}</div>
|
|
49
|
-
{/if}
|
|
50
|
-
</VStack>
|
|
51
|
-
|
|
52
|
-
{#if trailing}
|
|
53
|
-
<div class="row-trailing">
|
|
54
|
-
{@render trailing()}
|
|
55
|
-
</div>
|
|
56
|
-
{:else if isInteractive}
|
|
57
|
-
<SymbolImage name="chevron.right" size="sm" color="tertiary" />
|
|
58
|
-
{/if}
|
|
59
|
-
</HStack>
|
|
60
|
-
</a>
|
|
61
|
-
{:else if onclick}
|
|
62
|
-
<button type="button" class="list-row {className}" class:interactive={isInteractive} class:has-divider={showDivider} {onclick}>
|
|
63
|
-
<HStack spacing="sm" alignment="center" class="row-content">
|
|
64
|
-
{#if leading}
|
|
65
|
-
<div class="row-leading">
|
|
66
|
-
{@render leading()}
|
|
67
|
-
</div>
|
|
68
|
-
{/if}
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
{@render children()}
|
|
73
|
-
</div>
|
|
74
|
-
{#if subtitle}
|
|
75
|
-
<div class="row-subtitle">{subtitle}</div>
|
|
76
|
-
{/if}
|
|
77
|
-
</VStack>
|
|
78
|
-
|
|
79
|
-
{#if trailing}
|
|
80
|
-
<div class="row-trailing">
|
|
81
|
-
{@render trailing()}
|
|
82
|
-
</div>
|
|
83
|
-
{:else if isInteractive}
|
|
84
|
-
<SymbolImage name="chevron.right" size="sm" color="tertiary" />
|
|
85
|
-
{/if}
|
|
86
|
-
</HStack>
|
|
87
|
-
</button>
|
|
88
|
-
{:else}
|
|
89
|
-
<div class="list-row {className}" class:has-divider={showDivider}>
|
|
90
|
-
<HStack spacing="sm" alignment="center" class="row-content">
|
|
91
|
-
{#if leading}
|
|
92
|
-
<div class="row-leading">
|
|
93
|
-
{@render leading()}
|
|
94
|
-
</div>
|
|
95
|
-
{/if}
|
|
47
|
+
let actionsElement = $state<HTMLElement | null>(null);
|
|
48
|
+
</script>
|
|
96
49
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
50
|
+
{#snippet rowInner()}
|
|
51
|
+
<HStack spacing="sm" alignment="center" class="row-content">
|
|
52
|
+
{#if leading}
|
|
53
|
+
<div class="row-leading">
|
|
54
|
+
{@render leading()}
|
|
55
|
+
</div>
|
|
56
|
+
{/if}
|
|
57
|
+
|
|
58
|
+
<VStack spacing="none" alignment="leading" class="row-main">
|
|
59
|
+
<div class="row-title">
|
|
60
|
+
{@render children()}
|
|
61
|
+
</div>
|
|
62
|
+
{#if subtitle}
|
|
63
|
+
<div class="row-subtitle">{subtitle}</div>
|
|
110
64
|
{/if}
|
|
111
|
-
</
|
|
65
|
+
</VStack>
|
|
66
|
+
|
|
67
|
+
{#if trailing}
|
|
68
|
+
<div class="row-trailing">
|
|
69
|
+
{@render trailing()}
|
|
70
|
+
</div>
|
|
71
|
+
{:else if isInteractive && (href || onclick)}
|
|
72
|
+
<SymbolImage name="chevron.right" size="sm" color="tertiary" />
|
|
73
|
+
{/if}
|
|
74
|
+
</HStack>
|
|
75
|
+
{/snippet}
|
|
76
|
+
|
|
77
|
+
{#snippet row()}
|
|
78
|
+
{#if href}
|
|
79
|
+
<a
|
|
80
|
+
{href}
|
|
81
|
+
class="list-row {className}"
|
|
82
|
+
class:interactive={isInteractive}
|
|
83
|
+
class:has-divider={showDivider}
|
|
84
|
+
>
|
|
85
|
+
{@render rowInner()}
|
|
86
|
+
</a>
|
|
87
|
+
{:else if onclick}
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
class="list-row {className}"
|
|
91
|
+
class:interactive={isInteractive}
|
|
92
|
+
class:has-divider={showDivider}
|
|
93
|
+
{onclick}
|
|
94
|
+
>
|
|
95
|
+
{@render rowInner()}
|
|
96
|
+
</button>
|
|
97
|
+
{:else}
|
|
98
|
+
<div
|
|
99
|
+
class="list-row {className}"
|
|
100
|
+
class:interactive={isInteractive}
|
|
101
|
+
class:has-divider={showDivider}
|
|
102
|
+
>
|
|
103
|
+
{@render rowInner()}
|
|
104
|
+
</div>
|
|
105
|
+
{/if}
|
|
106
|
+
{/snippet}
|
|
107
|
+
|
|
108
|
+
{#if swipeActions}
|
|
109
|
+
<div class="swipe-row">
|
|
110
|
+
<!-- Behind the row until revealed, so it stays out of the reading order. -->
|
|
111
|
+
<div
|
|
112
|
+
class="swipe-actions"
|
|
113
|
+
data-swipe-edge={swipeEdge}
|
|
114
|
+
aria-hidden="true"
|
|
115
|
+
bind:this={actionsElement}
|
|
116
|
+
>
|
|
117
|
+
{@render swipeActions()}
|
|
118
|
+
</div>
|
|
119
|
+
<div
|
|
120
|
+
class="swipe-content"
|
|
121
|
+
{@attach fromAction(swipeGesture, () => ({
|
|
122
|
+
edge: swipeEdge,
|
|
123
|
+
actionsElement,
|
|
124
|
+
allowsFullSwipe,
|
|
125
|
+
onFullSwipe
|
|
126
|
+
}))}
|
|
127
|
+
>
|
|
128
|
+
{@render row()}
|
|
129
|
+
</div>
|
|
112
130
|
</div>
|
|
131
|
+
{:else}
|
|
132
|
+
{@render row()}
|
|
113
133
|
{/if}
|
|
114
134
|
|
|
115
135
|
<style>
|
|
@@ -178,4 +198,42 @@
|
|
|
178
198
|
align-items: center;
|
|
179
199
|
color: var(--color-text-tertiary);
|
|
180
200
|
}
|
|
201
|
+
|
|
202
|
+
/* Swipe actions */
|
|
203
|
+
.swipe-row {
|
|
204
|
+
position: relative;
|
|
205
|
+
overflow: hidden;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.swipe-actions {
|
|
209
|
+
position: absolute;
|
|
210
|
+
top: 0;
|
|
211
|
+
bottom: 0;
|
|
212
|
+
display: flex;
|
|
213
|
+
align-items: stretch;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.swipe-actions[data-swipe-edge='trailing'] {
|
|
217
|
+
right: 0;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.swipe-actions[data-swipe-edge='leading'] {
|
|
221
|
+
left: 0;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.swipe-content {
|
|
225
|
+
position: relative;
|
|
226
|
+
background: var(--color-bg, transparent);
|
|
227
|
+
transform: translateX(var(--swipe-x, 0));
|
|
228
|
+
touch-action: pan-y;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/* Settled positions animate; the drag itself tracks the finger.
|
|
232
|
+
data-swipe-state is written by the action, so the compiler cannot see it
|
|
233
|
+
in the markup -- :global keeps these rules from being pruned away. */
|
|
234
|
+
.swipe-content:global([data-swipe-state='closed']),
|
|
235
|
+
.swipe-content:global([data-swipe-state='open']),
|
|
236
|
+
.swipe-content:global([data-swipe-state='fullSwipe']) {
|
|
237
|
+
transition: transform var(--transition-fast);
|
|
238
|
+
}
|
|
181
239
|
</style>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
+
import { type SwipeEdge } from '../../actions/swipeActions';
|
|
2
3
|
interface Props {
|
|
3
4
|
children: Snippet;
|
|
4
5
|
leading?: Snippet;
|
|
@@ -8,6 +9,11 @@ interface Props {
|
|
|
8
9
|
interactive?: boolean;
|
|
9
10
|
href?: string;
|
|
10
11
|
onclick?: () => void;
|
|
12
|
+
/** Actions revealed by swiping. Mirrors SwiftUI's .swipeActions. */
|
|
13
|
+
swipeActions?: Snippet;
|
|
14
|
+
swipeEdge?: SwipeEdge;
|
|
15
|
+
allowsFullSwipe?: boolean;
|
|
16
|
+
onFullSwipe?: () => void;
|
|
11
17
|
class?: string;
|
|
12
18
|
}
|
|
13
19
|
declare const ListRow: import("svelte").Component<Props, {}, string>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { SymbolImage } from '../media';
|
|
3
|
+
import {
|
|
4
|
+
labelVisibility,
|
|
5
|
+
DEFAULT_LABEL_STYLE,
|
|
6
|
+
type LabelStyle
|
|
7
|
+
} from '../../constants/label';
|
|
8
|
+
import type { IconSize } from '../../constants';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
title: string;
|
|
12
|
+
systemImage?: string | undefined;
|
|
13
|
+
labelStyle?: LabelStyle;
|
|
14
|
+
size?: 'sm' | 'md' | 'lg';
|
|
15
|
+
class?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
title,
|
|
20
|
+
systemImage,
|
|
21
|
+
labelStyle = DEFAULT_LABEL_STYLE,
|
|
22
|
+
size = 'md',
|
|
23
|
+
class: className = ''
|
|
24
|
+
}: Props = $props();
|
|
25
|
+
|
|
26
|
+
const visibility = $derived(labelVisibility(labelStyle));
|
|
27
|
+
const iconSize: Record<'sm' | 'md' | 'lg', IconSize> = {
|
|
28
|
+
sm: 'sm',
|
|
29
|
+
md: 'md',
|
|
30
|
+
lg: 'lg'
|
|
31
|
+
};
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<span class="label size-{size} {className}" data-label-style={labelStyle}>
|
|
35
|
+
{#if visibility.showIcon && systemImage}
|
|
36
|
+
<span class="label-icon" aria-hidden="true">
|
|
37
|
+
<SymbolImage name={systemImage} size={iconSize[size]} />
|
|
38
|
+
</span>
|
|
39
|
+
{/if}
|
|
40
|
+
<span class="label-title" class:is-hidden={visibility.titleHidden}>{title}</span>
|
|
41
|
+
</span>
|
|
42
|
+
|
|
43
|
+
<style>
|
|
44
|
+
.label {
|
|
45
|
+
display: inline-flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
gap: var(--spacing-xs);
|
|
48
|
+
font-family: var(--font-system);
|
|
49
|
+
color: inherit;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.label.size-sm {
|
|
53
|
+
font-size: 0.875rem;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.label.size-md {
|
|
57
|
+
font-size: 1rem;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.label.size-lg {
|
|
61
|
+
font-size: 1.0625rem;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.label-icon {
|
|
65
|
+
display: inline-flex;
|
|
66
|
+
align-items: center;
|
|
67
|
+
flex-shrink: 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* Visually hidden, still announced: iconOnly must keep its accessible name. */
|
|
71
|
+
.label-title.is-hidden {
|
|
72
|
+
position: absolute;
|
|
73
|
+
width: 1px;
|
|
74
|
+
height: 1px;
|
|
75
|
+
padding: 0;
|
|
76
|
+
margin: -1px;
|
|
77
|
+
overflow: hidden;
|
|
78
|
+
clip-path: inset(50%);
|
|
79
|
+
white-space: nowrap;
|
|
80
|
+
border: 0;
|
|
81
|
+
}
|
|
82
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type LabelStyle } from '../../constants/label';
|
|
2
|
+
interface Props {
|
|
3
|
+
title: string;
|
|
4
|
+
systemImage?: string | undefined;
|
|
5
|
+
labelStyle?: LabelStyle;
|
|
6
|
+
size?: 'sm' | 'md' | 'lg';
|
|
7
|
+
class?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const Label: import("svelte").Component<Props, {}, string>;
|
|
10
|
+
type Label = ReturnType<typeof Label>;
|
|
11
|
+
export default Label;
|
package/dist/constants/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Label styles, mirroring SwiftUI's LabelStyle set.
|
|
3
|
+
*
|
|
4
|
+
* `iconOnly` hides the title *visually* -- the text stays in the DOM so the
|
|
5
|
+
* control keeps its accessible name. Nothing here may drop the title.
|
|
6
|
+
*/
|
|
7
|
+
export declare const LABEL_STYLES: readonly ["automatic", "titleAndIcon", "iconOnly", "titleOnly"];
|
|
8
|
+
export type LabelStyle = (typeof LABEL_STYLES)[number];
|
|
9
|
+
export declare const DEFAULT_LABEL_STYLE: LabelStyle;
|
|
10
|
+
export interface LabelVisibility {
|
|
11
|
+
showIcon: boolean;
|
|
12
|
+
/** Title is rendered but visually hidden (still read by assistive tech). */
|
|
13
|
+
titleHidden: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function labelVisibility(style: LabelStyle): LabelVisibility;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Label styles, mirroring SwiftUI's LabelStyle set.
|
|
3
|
+
*
|
|
4
|
+
* `iconOnly` hides the title *visually* -- the text stays in the DOM so the
|
|
5
|
+
* control keeps its accessible name. Nothing here may drop the title.
|
|
6
|
+
*/
|
|
7
|
+
export var LABEL_STYLES = ['automatic', 'titleAndIcon', 'iconOnly', 'titleOnly'];
|
|
8
|
+
export var DEFAULT_LABEL_STYLE = 'automatic';
|
|
9
|
+
export function labelVisibility(style) {
|
|
10
|
+
return {
|
|
11
|
+
showIcon: style !== 'titleOnly',
|
|
12
|
+
titleHidden: style === 'iconOnly'
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glass surface shapes, mirroring SwiftUI's
|
|
3
|
+
* `glassEffect(_ glass: Glass, in shape: some Shape)`.
|
|
4
|
+
*
|
|
5
|
+
* A shape overrides the corner-radius token entirely -- once you ask for a
|
|
6
|
+
* capsule or a circle, the radius knob no longer applies.
|
|
7
|
+
*/
|
|
8
|
+
import { type CornerRadius } from './sizes';
|
|
9
|
+
export declare const GLASS_SHAPES: readonly ["rect", "capsule", "circle"];
|
|
10
|
+
export type GlassShape = (typeof GLASS_SHAPES)[number];
|
|
11
|
+
export declare const DEFAULT_GLASS_SHAPE: GlassShape;
|
|
12
|
+
export interface GlassShapeStyle {
|
|
13
|
+
/** CSS border-radius value. */
|
|
14
|
+
radius: string;
|
|
15
|
+
/** CSS aspect-ratio, or null to leave the box unconstrained. */
|
|
16
|
+
aspectRatio: string | null;
|
|
17
|
+
}
|
|
18
|
+
export declare function glassShapeStyle(shape: GlassShape, cornerRadius: CornerRadius): GlassShapeStyle;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glass surface shapes, mirroring SwiftUI's
|
|
3
|
+
* `glassEffect(_ glass: Glass, in shape: some Shape)`.
|
|
4
|
+
*
|
|
5
|
+
* A shape overrides the corner-radius token entirely -- once you ask for a
|
|
6
|
+
* capsule or a circle, the radius knob no longer applies.
|
|
7
|
+
*/
|
|
8
|
+
import { CORNER_RADIUS } from './sizes';
|
|
9
|
+
export var GLASS_SHAPES = ['rect', 'capsule', 'circle'];
|
|
10
|
+
export var DEFAULT_GLASS_SHAPE = 'rect';
|
|
11
|
+
/** Radius used when a caller passes a corner-radius key that is not a token. */
|
|
12
|
+
var FALLBACK_RADIUS = CORNER_RADIUS.lg;
|
|
13
|
+
function rectRadius(cornerRadius) {
|
|
14
|
+
// hasOwnProperty, not `?? fallback`: 'toString' resolves to a function.
|
|
15
|
+
return Object.prototype.hasOwnProperty.call(CORNER_RADIUS, cornerRadius)
|
|
16
|
+
? CORNER_RADIUS[cornerRadius]
|
|
17
|
+
: FALLBACK_RADIUS;
|
|
18
|
+
}
|
|
19
|
+
export function glassShapeStyle(shape, cornerRadius) {
|
|
20
|
+
if (shape === 'capsule')
|
|
21
|
+
return { radius: CORNER_RADIUS.full, aspectRatio: null };
|
|
22
|
+
// 50% alone renders an ellipse on a non-square box, so pin the ratio too.
|
|
23
|
+
if (shape === 'circle')
|
|
24
|
+
return { radius: '50%', aspectRatio: '1 / 1' };
|
|
25
|
+
return { radius: rectRadius(cornerRadius), aspectRatio: null };
|
|
26
|
+
}
|
|
@@ -21,3 +21,31 @@ export declare const INTENSITY_CONFIG: Record<GlassIntensity, IntensityConfig>;
|
|
|
21
21
|
export declare const VARIANT_CONFIG: Record<GlassVariant, VariantConfig>;
|
|
22
22
|
export declare const DEFAULT_VARIANT: GlassVariant;
|
|
23
23
|
export declare const DEFAULT_INTENSITY: GlassIntensity;
|
|
24
|
+
/**
|
|
25
|
+
* Button styles, mirroring SwiftUI's ButtonStyle set. `glass` and
|
|
26
|
+
* `glassProminent` correspond to iOS 26's GlassButtonStyle /
|
|
27
|
+
* GlassProminentButtonStyle.
|
|
28
|
+
*/
|
|
29
|
+
export type ButtonVariant = 'filled' | 'outlined' | 'plain' | 'tinted' | 'destructive' | 'glass' | 'glassProminent';
|
|
30
|
+
export interface GlassButtonStyle {
|
|
31
|
+
variant: GlassVariant;
|
|
32
|
+
intensity: GlassIntensity;
|
|
33
|
+
/** Prominent glass carries the accent tint; plain glass stays neutral. */
|
|
34
|
+
tinted: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** Which glass surface each glass button style renders. */
|
|
37
|
+
export declare const BUTTON_GLASS_STYLE: Record<string, GlassButtonStyle>;
|
|
38
|
+
export type GlassButtonVariant = keyof typeof BUTTON_GLASS_STYLE;
|
|
39
|
+
export interface GlassButtonVars {
|
|
40
|
+
blur: number;
|
|
41
|
+
saturation: number;
|
|
42
|
+
opacity: number;
|
|
43
|
+
tinted: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare function isGlassButtonVariant(variant: string): variant is GlassButtonVariant;
|
|
46
|
+
/**
|
|
47
|
+
* Resolve a glass button style into the CSS values Button renders, reading the
|
|
48
|
+
* shared tokens so button glass cannot drift from surface glass. Returns null
|
|
49
|
+
* for the solid variants, which need no backdrop layer.
|
|
50
|
+
*/
|
|
51
|
+
export declare function glassButtonVars(variant: ButtonVariant): GlassButtonVars | null;
|
|
@@ -16,3 +16,29 @@ export var VARIANT_CONFIG = {
|
|
|
16
16
|
};
|
|
17
17
|
export var DEFAULT_VARIANT = 'regular';
|
|
18
18
|
export var DEFAULT_INTENSITY = 'standard';
|
|
19
|
+
/** Which glass surface each glass button style renders. */
|
|
20
|
+
export var BUTTON_GLASS_STYLE = {
|
|
21
|
+
glass: { variant: 'regular', intensity: 'subtle', tinted: false },
|
|
22
|
+
glassProminent: { variant: 'regular', intensity: 'standard', tinted: true }
|
|
23
|
+
};
|
|
24
|
+
export function isGlassButtonVariant(variant) {
|
|
25
|
+
// hasOwnProperty, not `in`: 'toString' would otherwise pass.
|
|
26
|
+
return Object.prototype.hasOwnProperty.call(BUTTON_GLASS_STYLE, variant);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolve a glass button style into the CSS values Button renders, reading the
|
|
30
|
+
* shared tokens so button glass cannot drift from surface glass. Returns null
|
|
31
|
+
* for the solid variants, which need no backdrop layer.
|
|
32
|
+
*/
|
|
33
|
+
export function glassButtonVars(variant) {
|
|
34
|
+
if (!isGlassButtonVariant(variant))
|
|
35
|
+
return null;
|
|
36
|
+
var style = BUTTON_GLASS_STYLE[variant];
|
|
37
|
+
var intensity = INTENSITY_CONFIG[style.intensity];
|
|
38
|
+
return {
|
|
39
|
+
blur: intensity.blur,
|
|
40
|
+
saturation: intensity.saturation,
|
|
41
|
+
opacity: VARIANT_CONFIG[style.variant].opacityDark,
|
|
42
|
+
tinted: style.tinted
|
|
43
|
+
};
|
|
44
|
+
}
|