glasslikeui 1.1.0 → 1.2.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/LICENSE +21 -21
- package/README.md +215 -215
- package/dist/components/glass/Glass.svelte +165 -164
- package/dist/components/glass/GlassCard.svelte +71 -71
- package/dist/components/glass/GlassDimLayer.svelte +37 -37
- package/dist/components/glass/GlassEffectContainer.svelte +58 -58
- package/dist/components/glass/GlassMorph.svelte +42 -42
- package/dist/components/glass/GlassSection.svelte +82 -82
- package/dist/components/glass/LensFilters.svelte +41 -41
- package/dist/components/glass/Sheet.svelte +261 -266
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +2 -0
- package/dist/components/interactive/Badge.svelte +52 -52
- package/dist/components/interactive/Button.svelte +168 -168
- package/dist/components/interactive/IconButton.svelte +74 -74
- package/dist/components/interactive/TabView.svelte +1 -1
- package/dist/components/layout/Divider.svelte +31 -31
- package/dist/components/layout/Grid.svelte +52 -52
- package/dist/components/layout/HStack.svelte +76 -76
- package/dist/components/layout/ScrollView.svelte +84 -83
- package/dist/components/layout/Spacer.svelte +18 -18
- package/dist/components/layout/VStack.svelte +56 -56
- package/dist/components/layout/ZStack.svelte +51 -51
- package/dist/components/list/List.svelte +50 -50
- package/dist/components/list/ListRow.svelte +181 -181
- package/dist/components/media/SymbolImage.svelte +46 -46
- package/dist/components/menu/Menu.svelte +189 -0
- package/dist/components/menu/Menu.svelte.d.ts +10 -0
- package/dist/components/menu/MenuItem.svelte +114 -0
- package/dist/components/menu/MenuItem.svelte.d.ts +12 -0
- package/dist/components/menu/index.d.ts +6 -0
- package/dist/components/menu/index.js +6 -0
- package/dist/components/navigation/NavigationBar.svelte +195 -195
- package/dist/components/navigation/NavigationLink.svelte +45 -45
- package/dist/components/typography/Text.svelte +98 -98
- package/dist/icons/index.js +4 -1
- package/dist/styles/glasslikeui.css +192 -192
- package/dist/styles/lens.css +93 -93
- package/dist/styles/squircle.css +17 -17
- package/dist/styles/typography.css +27 -27
- package/package.json +50 -50
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
3
|
-
import { HStack } from '../layout';
|
|
4
|
-
import { VStack } from '../layout';
|
|
5
|
-
import { SymbolImage } from '../media';
|
|
6
|
-
|
|
7
|
-
interface Props {
|
|
8
|
-
children: Snippet;
|
|
9
|
-
leading?: Snippet;
|
|
10
|
-
trailing?: Snippet;
|
|
11
|
-
subtitle?: string;
|
|
12
|
-
showDivider?: boolean;
|
|
13
|
-
interactive?: boolean;
|
|
14
|
-
href?: string;
|
|
15
|
-
onclick?: () => void;
|
|
16
|
-
class?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let {
|
|
20
|
-
children,
|
|
21
|
-
leading,
|
|
22
|
-
trailing,
|
|
23
|
-
subtitle = '',
|
|
24
|
-
showDivider = true,
|
|
25
|
-
interactive = false,
|
|
26
|
-
href,
|
|
27
|
-
onclick,
|
|
28
|
-
class: className = ''
|
|
29
|
-
}: Props = $props();
|
|
30
|
-
|
|
31
|
-
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 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
|
-
|
|
70
|
-
<VStack spacing="none" alignment="leading" class="row-main">
|
|
71
|
-
<div class="row-title">
|
|
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}
|
|
96
|
-
|
|
97
|
-
<VStack spacing="none" alignment="leading" class="row-main">
|
|
98
|
-
<div class="row-title">
|
|
99
|
-
{@render children()}
|
|
100
|
-
</div>
|
|
101
|
-
{#if subtitle}
|
|
102
|
-
<div class="row-subtitle">{subtitle}</div>
|
|
103
|
-
{/if}
|
|
104
|
-
</VStack>
|
|
105
|
-
|
|
106
|
-
{#if trailing}
|
|
107
|
-
<div class="row-trailing">
|
|
108
|
-
{@render trailing()}
|
|
109
|
-
</div>
|
|
110
|
-
{/if}
|
|
111
|
-
</HStack>
|
|
112
|
-
</div>
|
|
113
|
-
{/if}
|
|
114
|
-
|
|
115
|
-
<style>
|
|
116
|
-
.list-row {
|
|
117
|
-
display: block;
|
|
118
|
-
width: 100%;
|
|
119
|
-
padding: 0;
|
|
120
|
-
background: transparent;
|
|
121
|
-
border: none;
|
|
122
|
-
text-decoration: none;
|
|
123
|
-
color: inherit;
|
|
124
|
-
text-align: left;
|
|
125
|
-
font-family: inherit;
|
|
126
|
-
cursor: default;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
.list-row.interactive {
|
|
130
|
-
cursor: pointer;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
.list-row.interactive:hover {
|
|
134
|
-
background: var(--glass-hover-subtle);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
.list-row.interactive:active {
|
|
138
|
-
background: var(--glass-active-subtle);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
:global(.row-content) {
|
|
142
|
-
padding: var(--spacing-sm) var(--spacing-md);
|
|
143
|
-
min-height: 44px;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
.list-row.has-divider {
|
|
147
|
-
border-bottom: 1px solid var(--glass-divider);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
.list-row:last-child {
|
|
151
|
-
border-bottom: none;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
.row-leading {
|
|
155
|
-
display: flex;
|
|
156
|
-
align-items: center;
|
|
157
|
-
justify-content: center;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
:global(.row-main) {
|
|
161
|
-
flex: 1;
|
|
162
|
-
min-width: 0;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
.row-title {
|
|
166
|
-
font-size: 1rem;
|
|
167
|
-
color: var(--color-text);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
.row-subtitle {
|
|
171
|
-
font-size: 0.8125rem;
|
|
172
|
-
color: var(--color-text-secondary);
|
|
173
|
-
margin-top: 2px;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
.row-trailing {
|
|
177
|
-
display: flex;
|
|
178
|
-
align-items: center;
|
|
179
|
-
color: var(--color-text-tertiary);
|
|
180
|
-
}
|
|
181
|
-
</style>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { HStack } from '../layout';
|
|
4
|
+
import { VStack } from '../layout';
|
|
5
|
+
import { SymbolImage } from '../media';
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
children: Snippet;
|
|
9
|
+
leading?: Snippet;
|
|
10
|
+
trailing?: Snippet;
|
|
11
|
+
subtitle?: string;
|
|
12
|
+
showDivider?: boolean;
|
|
13
|
+
interactive?: boolean;
|
|
14
|
+
href?: string;
|
|
15
|
+
onclick?: () => void;
|
|
16
|
+
class?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
children,
|
|
21
|
+
leading,
|
|
22
|
+
trailing,
|
|
23
|
+
subtitle = '',
|
|
24
|
+
showDivider = true,
|
|
25
|
+
interactive = false,
|
|
26
|
+
href,
|
|
27
|
+
onclick,
|
|
28
|
+
class: className = ''
|
|
29
|
+
}: Props = $props();
|
|
30
|
+
|
|
31
|
+
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 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
|
+
|
|
70
|
+
<VStack spacing="none" alignment="leading" class="row-main">
|
|
71
|
+
<div class="row-title">
|
|
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}
|
|
96
|
+
|
|
97
|
+
<VStack spacing="none" alignment="leading" class="row-main">
|
|
98
|
+
<div class="row-title">
|
|
99
|
+
{@render children()}
|
|
100
|
+
</div>
|
|
101
|
+
{#if subtitle}
|
|
102
|
+
<div class="row-subtitle">{subtitle}</div>
|
|
103
|
+
{/if}
|
|
104
|
+
</VStack>
|
|
105
|
+
|
|
106
|
+
{#if trailing}
|
|
107
|
+
<div class="row-trailing">
|
|
108
|
+
{@render trailing()}
|
|
109
|
+
</div>
|
|
110
|
+
{/if}
|
|
111
|
+
</HStack>
|
|
112
|
+
</div>
|
|
113
|
+
{/if}
|
|
114
|
+
|
|
115
|
+
<style>
|
|
116
|
+
.list-row {
|
|
117
|
+
display: block;
|
|
118
|
+
width: 100%;
|
|
119
|
+
padding: 0;
|
|
120
|
+
background: transparent;
|
|
121
|
+
border: none;
|
|
122
|
+
text-decoration: none;
|
|
123
|
+
color: inherit;
|
|
124
|
+
text-align: left;
|
|
125
|
+
font-family: inherit;
|
|
126
|
+
cursor: default;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.list-row.interactive {
|
|
130
|
+
cursor: pointer;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.list-row.interactive:hover {
|
|
134
|
+
background: var(--glass-hover-subtle);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.list-row.interactive:active {
|
|
138
|
+
background: var(--glass-active-subtle);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
:global(.row-content) {
|
|
142
|
+
padding: var(--spacing-sm) var(--spacing-md);
|
|
143
|
+
min-height: 44px;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.list-row.has-divider {
|
|
147
|
+
border-bottom: 1px solid var(--glass-divider);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.list-row:last-child {
|
|
151
|
+
border-bottom: none;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.row-leading {
|
|
155
|
+
display: flex;
|
|
156
|
+
align-items: center;
|
|
157
|
+
justify-content: center;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
:global(.row-main) {
|
|
161
|
+
flex: 1;
|
|
162
|
+
min-width: 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.row-title {
|
|
166
|
+
font-size: 1rem;
|
|
167
|
+
color: var(--color-text);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.row-subtitle {
|
|
171
|
+
font-size: 0.8125rem;
|
|
172
|
+
color: var(--color-text-secondary);
|
|
173
|
+
margin-top: 2px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.row-trailing {
|
|
177
|
+
display: flex;
|
|
178
|
+
align-items: center;
|
|
179
|
+
color: var(--color-text-tertiary);
|
|
180
|
+
}
|
|
181
|
+
</style>
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { ICON_SIZES, TEXT_COLORS } from '../../constants';
|
|
3
|
-
import { getIconPath } from '../../icons';
|
|
4
|
-
import type { IconSize, TextColor } from '../../constants';
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
name: string;
|
|
8
|
-
size?: IconSize;
|
|
9
|
-
color?: TextColor;
|
|
10
|
-
class?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let {
|
|
14
|
-
name,
|
|
15
|
-
size = 'md',
|
|
16
|
-
color = 'primary',
|
|
17
|
-
class: className = ''
|
|
18
|
-
}: Props = $props();
|
|
19
|
-
|
|
20
|
-
// Security Note: iconPath is always from hardcoded ICONS map, never user input
|
|
21
|
-
const iconPath = $derived(getIconPath(name));
|
|
22
|
-
const pixelSize = $derived(ICON_SIZES[size]);
|
|
23
|
-
const colorValue = $derived(TEXT_COLORS[color]);
|
|
24
|
-
</script>
|
|
25
|
-
|
|
26
|
-
<svg
|
|
27
|
-
class="symbol-image {className}"
|
|
28
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
29
|
-
width={pixelSize}
|
|
30
|
-
height={pixelSize}
|
|
31
|
-
viewBox="0 0 24 24"
|
|
32
|
-
fill="none"
|
|
33
|
-
stroke={colorValue}
|
|
34
|
-
stroke-width="2"
|
|
35
|
-
stroke-linecap="round"
|
|
36
|
-
stroke-linejoin="round"
|
|
37
|
-
style="color: {colorValue}"
|
|
38
|
-
>
|
|
39
|
-
{@html iconPath}
|
|
40
|
-
</svg>
|
|
41
|
-
|
|
42
|
-
<style>
|
|
43
|
-
.symbol-image {
|
|
44
|
-
flex-shrink: 0;
|
|
45
|
-
}
|
|
46
|
-
</style>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ICON_SIZES, TEXT_COLORS } from '../../constants';
|
|
3
|
+
import { getIconPath } from '../../icons';
|
|
4
|
+
import type { IconSize, TextColor } from '../../constants';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
name: string;
|
|
8
|
+
size?: IconSize;
|
|
9
|
+
color?: TextColor;
|
|
10
|
+
class?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
name,
|
|
15
|
+
size = 'md',
|
|
16
|
+
color = 'primary',
|
|
17
|
+
class: className = ''
|
|
18
|
+
}: Props = $props();
|
|
19
|
+
|
|
20
|
+
// Security Note: iconPath is always from hardcoded ICONS map, never user input
|
|
21
|
+
const iconPath = $derived(getIconPath(name));
|
|
22
|
+
const pixelSize = $derived(ICON_SIZES[size]);
|
|
23
|
+
const colorValue = $derived(TEXT_COLORS[color]);
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<svg
|
|
27
|
+
class="symbol-image {className}"
|
|
28
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
29
|
+
width={pixelSize}
|
|
30
|
+
height={pixelSize}
|
|
31
|
+
viewBox="0 0 24 24"
|
|
32
|
+
fill="none"
|
|
33
|
+
stroke={colorValue}
|
|
34
|
+
stroke-width="2"
|
|
35
|
+
stroke-linecap="round"
|
|
36
|
+
stroke-linejoin="round"
|
|
37
|
+
style="color: {colorValue}"
|
|
38
|
+
>
|
|
39
|
+
{@html iconPath}
|
|
40
|
+
</svg>
|
|
41
|
+
|
|
42
|
+
<style>
|
|
43
|
+
.symbol-image {
|
|
44
|
+
flex-shrink: 0;
|
|
45
|
+
}
|
|
46
|
+
</style>
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { tick } from 'svelte';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
label: Snippet;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
align?: 'start' | 'end';
|
|
9
|
+
class?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { label, children, align = 'start', class: className = '' }: Props = $props();
|
|
13
|
+
|
|
14
|
+
const panelId = $props.id();
|
|
15
|
+
|
|
16
|
+
let open = $state(false);
|
|
17
|
+
let triggerEl = $state<HTMLButtonElement>();
|
|
18
|
+
let panelEl = $state<HTMLDivElement>();
|
|
19
|
+
|
|
20
|
+
function menuItems(): HTMLElement[] {
|
|
21
|
+
if (!panelEl) return [];
|
|
22
|
+
return Array.from(panelEl.querySelectorAll<HTMLElement>('[role="menuitem"]'));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function openMenu() {
|
|
26
|
+
open = true;
|
|
27
|
+
await tick();
|
|
28
|
+
menuItems()[0]?.focus();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function closeMenu(focusTrigger = false) {
|
|
32
|
+
open = false;
|
|
33
|
+
if (focusTrigger) triggerEl?.focus();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function toggle() {
|
|
37
|
+
if (open) closeMenu();
|
|
38
|
+
else openMenu();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function handlePanelKeydown(e: KeyboardEvent) {
|
|
42
|
+
const items = menuItems();
|
|
43
|
+
if (items.length === 0) return;
|
|
44
|
+
const current = items.indexOf(document.activeElement as HTMLElement);
|
|
45
|
+
|
|
46
|
+
if (e.key === 'Escape') {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
closeMenu(true);
|
|
49
|
+
} else if (e.key === 'ArrowDown') {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
items[(current + 1) % items.length]?.focus();
|
|
52
|
+
} else if (e.key === 'ArrowUp') {
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
items[(current - 1 + items.length) % items.length]?.focus();
|
|
55
|
+
} else if (e.key === 'Home') {
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
items[0]?.focus();
|
|
58
|
+
} else if (e.key === 'End') {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
items[items.length - 1]?.focus();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function handlePanelClick(e: MouseEvent) {
|
|
65
|
+
const target = e.target as HTMLElement;
|
|
66
|
+
if (target.closest('[role="menuitem"]')) {
|
|
67
|
+
closeMenu();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function handleDocumentPointerDown(e: PointerEvent) {
|
|
72
|
+
if (!open) return;
|
|
73
|
+
const target = e.target as Node;
|
|
74
|
+
if (triggerEl?.contains(target) || panelEl?.contains(target)) return;
|
|
75
|
+
closeMenu();
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<svelte:document onpointerdown={handleDocumentPointerDown} />
|
|
80
|
+
|
|
81
|
+
<div class="glass-menu">
|
|
82
|
+
<button
|
|
83
|
+
bind:this={triggerEl}
|
|
84
|
+
type="button"
|
|
85
|
+
class="glass-menu-trigger {className}"
|
|
86
|
+
aria-haspopup="menu"
|
|
87
|
+
aria-expanded={open}
|
|
88
|
+
aria-controls={panelId}
|
|
89
|
+
onclick={toggle}
|
|
90
|
+
>
|
|
91
|
+
{@render label()}
|
|
92
|
+
</button>
|
|
93
|
+
|
|
94
|
+
{#if open}
|
|
95
|
+
<div
|
|
96
|
+
bind:this={panelEl}
|
|
97
|
+
id={panelId}
|
|
98
|
+
role="menu"
|
|
99
|
+
tabindex="-1"
|
|
100
|
+
class="glass-menu-panel"
|
|
101
|
+
class:align-end={align === 'end'}
|
|
102
|
+
onkeydown={handlePanelKeydown}
|
|
103
|
+
onclick={handlePanelClick}
|
|
104
|
+
>
|
|
105
|
+
{@render children()}
|
|
106
|
+
</div>
|
|
107
|
+
{/if}
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<style>
|
|
111
|
+
.glass-menu {
|
|
112
|
+
position: relative;
|
|
113
|
+
display: inline-flex;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.glass-menu-trigger {
|
|
117
|
+
display: inline-flex;
|
|
118
|
+
align-items: center;
|
|
119
|
+
gap: 4px;
|
|
120
|
+
margin: 0;
|
|
121
|
+
padding: 0;
|
|
122
|
+
background: none;
|
|
123
|
+
border: none;
|
|
124
|
+
font: inherit;
|
|
125
|
+
color: inherit;
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.glass-menu-panel {
|
|
130
|
+
position: absolute;
|
|
131
|
+
top: calc(100% + 8px);
|
|
132
|
+
left: 0;
|
|
133
|
+
min-width: 220px;
|
|
134
|
+
padding: 0;
|
|
135
|
+
overflow: hidden;
|
|
136
|
+
background: var(--glass-sheet-bg);
|
|
137
|
+
backdrop-filter: blur(var(--glass-blur-nav)) saturate(var(--glass-saturation));
|
|
138
|
+
-webkit-backdrop-filter: blur(var(--glass-blur-nav)) saturate(var(--glass-saturation));
|
|
139
|
+
border: var(--glass-border-width) solid var(--glass-border);
|
|
140
|
+
border-radius: var(--glass-radius-md);
|
|
141
|
+
box-shadow:
|
|
142
|
+
0 12px 40px -8px var(--glass-shadow),
|
|
143
|
+
0 4px 12px -2px var(--glass-shadow);
|
|
144
|
+
z-index: 200;
|
|
145
|
+
transform-origin: top left;
|
|
146
|
+
animation: glass-menu-pop 0.18s cubic-bezier(0.32, 0.72, 0, 1);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.glass-menu-panel.align-end {
|
|
150
|
+
left: auto;
|
|
151
|
+
right: 0;
|
|
152
|
+
transform-origin: top right;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* Hairline divider between consecutive items. */
|
|
156
|
+
.glass-menu-panel :global(.menu-item + .menu-item) {
|
|
157
|
+
border-top: var(--glass-border-width) solid var(--glass-divider);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@keyframes glass-menu-pop {
|
|
161
|
+
from {
|
|
162
|
+
opacity: 0;
|
|
163
|
+
transform: scale(0.92);
|
|
164
|
+
}
|
|
165
|
+
to {
|
|
166
|
+
opacity: 1;
|
|
167
|
+
transform: scale(1);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@media (prefers-reduced-motion: reduce) {
|
|
172
|
+
.glass-menu-panel {
|
|
173
|
+
animation: glass-menu-fade 0.01s linear;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
:global([data-reduced-motion='true']) .glass-menu-panel {
|
|
178
|
+
animation: glass-menu-fade 0.01s linear;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@keyframes glass-menu-fade {
|
|
182
|
+
from {
|
|
183
|
+
opacity: 0;
|
|
184
|
+
}
|
|
185
|
+
to {
|
|
186
|
+
opacity: 1;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
label: Snippet;
|
|
4
|
+
children: Snippet;
|
|
5
|
+
align?: 'start' | 'end';
|
|
6
|
+
class?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const Menu: import("svelte").Component<Props, {}, string>;
|
|
9
|
+
type Menu = ReturnType<typeof Menu>;
|
|
10
|
+
export default Menu;
|