glasslikeui 1.9.0 → 1.10.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 +892 -24
- package/dist/actions/adaptiveTone.d.ts +50 -0
- package/dist/actions/adaptiveTone.js +569 -0
- package/dist/actions/alertLogic.d.ts +67 -0
- package/dist/actions/alertLogic.js +123 -0
- package/dist/actions/anchorPlacement.d.ts +92 -0
- package/dist/actions/anchorPlacement.js +137 -0
- package/dist/actions/dragSnap.d.ts +1 -1
- package/dist/actions/dragSnapMath.d.ts +70 -0
- package/dist/actions/dragSnapMath.js +115 -0
- package/dist/actions/glassToneLogic.d.ts +182 -0
- package/dist/actions/glassToneLogic.js +513 -0
- package/dist/actions/heightTransition.d.ts +32 -0
- package/dist/actions/heightTransition.js +64 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.js +1 -0
- package/dist/actions/inertSiblings.js +20 -4
- package/dist/actions/menuLogic.d.ts +40 -0
- package/dist/actions/menuLogic.js +68 -0
- package/dist/actions/modalDialog.d.ts +19 -0
- package/dist/actions/modalDialog.js +48 -0
- package/dist/actions/popoverLogic.d.ts +25 -0
- package/dist/actions/popoverLogic.js +48 -0
- package/dist/actions/rovingIndex.d.ts +30 -0
- package/dist/actions/rovingIndex.js +49 -0
- package/dist/actions/scrollRunTracker.d.ts +36 -0
- package/dist/actions/scrollRunTracker.js +77 -0
- package/dist/actions/scrollUnder.d.ts +21 -0
- package/dist/actions/scrollUnder.js +29 -0
- package/dist/actions/segmentedLogic.d.ts +38 -0
- package/dist/actions/segmentedLogic.js +59 -0
- package/dist/actions/sheetLogic.d.ts +43 -0
- package/dist/actions/sheetLogic.js +71 -0
- package/dist/actions/sliderLogic.d.ts +29 -0
- package/dist/actions/sliderLogic.js +53 -0
- package/dist/actions/swipeActions.d.ts +46 -2
- package/dist/actions/swipeActions.js +267 -46
- package/dist/actions/tabBarMinimize.d.ts +31 -0
- package/dist/actions/tabBarMinimize.js +38 -0
- package/dist/actions/tabViewLogic.d.ts +47 -0
- package/dist/actions/tabViewLogic.js +71 -0
- package/dist/actions/toggleKnobLogic.d.ts +57 -0
- package/dist/actions/toggleKnobLogic.js +66 -0
- package/dist/actions/toolbarFocus.d.ts +44 -0
- package/dist/actions/toolbarFocus.js +228 -0
- package/dist/actions/topLayer.d.ts +12 -0
- package/dist/actions/topLayer.js +18 -0
- package/dist/components/dialog/ActionSheet.svelte +457 -0
- package/dist/components/dialog/ActionSheet.svelte.d.ts +25 -0
- package/dist/components/dialog/Alert.svelte +337 -0
- package/dist/components/dialog/Alert.svelte.d.ts +28 -0
- package/dist/components/dialog/index.d.ts +6 -0
- package/dist/components/dialog/index.js +6 -0
- package/dist/components/glass/Glass.svelte +49 -17
- package/dist/components/glass/Glass.svelte.d.ts +8 -0
- package/dist/components/glass/GlassSection.svelte +9 -1
- package/dist/components/glass/LensFilters.svelte +4 -2
- package/dist/components/glass/Popover.svelte +379 -0
- package/dist/components/glass/Popover.svelte.d.ts +30 -0
- package/dist/components/glass/Sheet.svelte +470 -103
- package/dist/components/glass/Sheet.svelte.d.ts +55 -7
- package/dist/components/glass/index.d.ts +3 -0
- package/dist/components/glass/index.js +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +4 -0
- package/dist/components/interactive/Badge.svelte +97 -6
- package/dist/components/interactive/Badge.svelte.d.ts +13 -2
- package/dist/components/interactive/Button.svelte +162 -20
- package/dist/components/interactive/Button.svelte.d.ts +14 -1
- package/dist/components/interactive/IconButton.svelte +214 -4
- package/dist/components/interactive/IconButton.svelte.d.ts +2 -1
- package/dist/components/interactive/ProgressView.svelte +306 -0
- package/dist/components/interactive/ProgressView.svelte.d.ts +25 -0
- package/dist/components/interactive/Segment.d.ts +14 -0
- package/dist/components/interactive/Segment.js +1 -0
- package/dist/components/interactive/SegmentedControl.svelte +399 -0
- package/dist/components/interactive/SegmentedControl.svelte.d.ts +17 -0
- package/dist/components/interactive/Slider.svelte +299 -0
- package/dist/components/interactive/Slider.svelte.d.ts +23 -0
- package/dist/components/interactive/TabView.svelte +573 -41
- package/dist/components/interactive/TabView.svelte.d.ts +25 -0
- package/dist/components/interactive/Toggle.svelte +287 -16
- package/dist/components/interactive/Toggle.svelte.d.ts +12 -0
- package/dist/components/interactive/index.d.ts +4 -0
- package/dist/components/interactive/index.js +3 -0
- package/dist/components/list/List.svelte +41 -17
- package/dist/components/list/List.svelte.d.ts +1 -0
- package/dist/components/list/ListRow.svelte +208 -47
- package/dist/components/list/ListRow.svelte.d.ts +16 -1
- package/dist/components/menu/Menu.svelte +51 -27
- package/dist/components/menu/Menu.svelte.d.ts +5 -0
- package/dist/components/menu/MenuItem.svelte +82 -25
- package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
- package/dist/components/menu/MenuSection.svelte +95 -0
- package/dist/components/menu/MenuSection.svelte.d.ts +18 -0
- package/dist/components/menu/MenuSubmenu.svelte +196 -0
- package/dist/components/menu/MenuSubmenu.svelte.d.ts +11 -0
- package/dist/components/menu/index.d.ts +4 -1
- package/dist/components/menu/index.js +3 -1
- package/dist/components/navigation/NavigationBar.svelte +97 -15
- package/dist/components/navigation/NavigationBar.svelte.d.ts +6 -0
- package/dist/components/toolbar/Toolbar.svelte +43 -0
- package/dist/components/toolbar/Toolbar.svelte.d.ts +13 -0
- package/dist/components/toolbar/ToolbarItemGroup.svelte +45 -0
- package/dist/components/toolbar/ToolbarItemGroup.svelte.d.ts +14 -0
- package/dist/components/toolbar/ToolbarSpacer.svelte +36 -0
- package/dist/components/toolbar/ToolbarSpacer.svelte.d.ts +12 -0
- package/dist/components/toolbar/index.d.ts +7 -0
- package/dist/components/toolbar/index.js +7 -0
- package/dist/components/typography/Text.svelte +9 -1
- package/dist/constants/alertAction.d.ts +19 -0
- package/dist/constants/alertAction.js +1 -0
- package/dist/constants/badge.d.ts +32 -0
- package/dist/constants/badge.js +47 -0
- package/dist/constants/buttons.d.ts +45 -0
- package/dist/constants/buttons.js +52 -0
- package/dist/constants/colors.d.ts +9 -4
- package/dist/constants/colors.js +9 -4
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.js +3 -0
- package/dist/constants/progress.d.ts +56 -0
- package/dist/constants/progress.js +75 -0
- package/dist/constants/variants.d.ts +6 -2
- package/dist/constants/variants.js +2 -2
- package/dist/styles/glasslikeui.css +135 -1
- package/dist/styles/lens.css +21 -19
- package/dist/styles/squircle.css +17 -7
- package/package.json +1 -1
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
href?: string;
|
|
9
9
|
onclick?: () => void;
|
|
10
10
|
destructive?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Makes the item a checkable one (`menuitemcheckbox`) showing a checkmark
|
|
13
|
+
* when true. Leave it unset for a plain item. The menu does not flip it:
|
|
14
|
+
* update it from `onclick`.
|
|
15
|
+
*/
|
|
16
|
+
checked?: boolean;
|
|
17
|
+
/** Shows the item dimmed. It stays focusable, as the menu pattern asks, but does nothing. */
|
|
18
|
+
disabled?: boolean;
|
|
11
19
|
class?: string;
|
|
12
20
|
}
|
|
13
21
|
|
|
@@ -17,38 +25,57 @@
|
|
|
17
25
|
href,
|
|
18
26
|
onclick,
|
|
19
27
|
destructive = false,
|
|
28
|
+
checked,
|
|
29
|
+
disabled = false,
|
|
20
30
|
class: className = ''
|
|
21
31
|
}: Props = $props();
|
|
22
32
|
|
|
23
33
|
// Security Note: iconPath is always from the hardcoded ICONS map, never user input.
|
|
24
34
|
const iconPath = $derived(icon ? getIconPath(icon) : '');
|
|
35
|
+
const checkable = $derived(checked !== undefined);
|
|
36
|
+
const role = $derived(checkable ? 'menuitemcheckbox' : 'menuitem');
|
|
37
|
+
|
|
38
|
+
function activate() {
|
|
39
|
+
if (!disabled) onclick?.();
|
|
40
|
+
}
|
|
25
41
|
</script>
|
|
26
42
|
|
|
43
|
+
{#snippet glyph(path: string, className: string)}
|
|
44
|
+
<svg
|
|
45
|
+
class={className}
|
|
46
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
47
|
+
width="18"
|
|
48
|
+
height="18"
|
|
49
|
+
viewBox="0 0 24 24"
|
|
50
|
+
fill="none"
|
|
51
|
+
stroke="currentColor"
|
|
52
|
+
stroke-width="2"
|
|
53
|
+
stroke-linecap="round"
|
|
54
|
+
stroke-linejoin="round"
|
|
55
|
+
aria-hidden="true"
|
|
56
|
+
focusable="false"
|
|
57
|
+
>
|
|
58
|
+
{@html path}
|
|
59
|
+
</svg>
|
|
60
|
+
{/snippet}
|
|
61
|
+
|
|
27
62
|
{#snippet rowContent()}
|
|
63
|
+
{#if checkable}
|
|
64
|
+
<span class="menu-item-check" aria-hidden="true">
|
|
65
|
+
{#if checked}{@render glyph(getIconPath('check'), 'menu-item-check-glyph')}{/if}
|
|
66
|
+
</span>
|
|
67
|
+
{/if}
|
|
28
68
|
{#if icon}
|
|
29
|
-
|
|
30
|
-
class="menu-item-icon"
|
|
31
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
32
|
-
width="18"
|
|
33
|
-
height="18"
|
|
34
|
-
viewBox="0 0 24 24"
|
|
35
|
-
fill="none"
|
|
36
|
-
stroke="currentColor"
|
|
37
|
-
stroke-width="2"
|
|
38
|
-
stroke-linecap="round"
|
|
39
|
-
stroke-linejoin="round"
|
|
40
|
-
aria-hidden="true"
|
|
41
|
-
>
|
|
42
|
-
{@html iconPath}
|
|
43
|
-
</svg>
|
|
69
|
+
{@render glyph(iconPath, 'menu-item-icon')}
|
|
44
70
|
{/if}
|
|
45
71
|
<span class="menu-item-label">{@render children()}</span>
|
|
46
72
|
{/snippet}
|
|
47
73
|
|
|
48
|
-
{#if href}
|
|
74
|
+
{#if href && !disabled}
|
|
49
75
|
<a
|
|
50
76
|
{href}
|
|
51
|
-
role
|
|
77
|
+
{role}
|
|
78
|
+
aria-checked={checkable ? checked : undefined}
|
|
52
79
|
tabindex="-1"
|
|
53
80
|
class="menu-item {className}"
|
|
54
81
|
class:destructive
|
|
@@ -58,11 +85,14 @@
|
|
|
58
85
|
{:else}
|
|
59
86
|
<button
|
|
60
87
|
type="button"
|
|
61
|
-
role
|
|
88
|
+
{role}
|
|
89
|
+
aria-checked={checkable ? checked : undefined}
|
|
90
|
+
aria-disabled={disabled ? 'true' : undefined}
|
|
62
91
|
tabindex="-1"
|
|
63
92
|
class="menu-item {className}"
|
|
64
93
|
class:destructive
|
|
65
|
-
|
|
94
|
+
class:disabled
|
|
95
|
+
onclick={activate}
|
|
66
96
|
>
|
|
67
97
|
{@render rowContent()}
|
|
68
98
|
</button>
|
|
@@ -73,16 +103,20 @@
|
|
|
73
103
|
display: flex;
|
|
74
104
|
align-items: center;
|
|
75
105
|
gap: 10px;
|
|
106
|
+
box-sizing: border-box;
|
|
76
107
|
width: 100%;
|
|
77
|
-
|
|
108
|
+
/* iOS 26 rows are taller, and rounded concentric with the panel, which
|
|
109
|
+
insets them 8px (see Menu). The focus ring follows the rounding. */
|
|
110
|
+
min-height: 44px;
|
|
111
|
+
padding: 10px 16px;
|
|
78
112
|
background: none;
|
|
79
113
|
border: none;
|
|
80
|
-
border-radius:
|
|
114
|
+
border-radius: calc(var(--glass-radius-xl) - 8px);
|
|
81
115
|
font: inherit;
|
|
82
|
-
font-size:
|
|
83
|
-
text-align:
|
|
116
|
+
font-size: 17px;
|
|
117
|
+
text-align: start;
|
|
84
118
|
text-decoration: none;
|
|
85
|
-
color: var(--color-text);
|
|
119
|
+
color: var(--glass-fg, var(--color-text));
|
|
86
120
|
cursor: pointer;
|
|
87
121
|
--_danger-text: var(--color-danger-text, color-mix(in srgb, var(--color-danger) var(--glass-danger-text-strength, 30%), var(--glass-text-toward, white)));
|
|
88
122
|
}
|
|
@@ -116,7 +150,30 @@
|
|
|
116
150
|
color: var(--_danger-text);
|
|
117
151
|
}
|
|
118
152
|
|
|
119
|
-
|
|
153
|
+
/* Dimmed, but still readable: WCAG exempts disabled controls from the
|
|
154
|
+
contrast minimum, and iOS greys them the same way. */
|
|
155
|
+
.menu-item.disabled {
|
|
156
|
+
color: var(--glass-fg-secondary, var(--color-text-secondary, var(--color-text)));
|
|
157
|
+
opacity: 0.55;
|
|
158
|
+
cursor: default;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.menu-item.disabled:hover,
|
|
162
|
+
.menu-item.disabled:active {
|
|
163
|
+
background: none;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* The checkmark column is kept on every checkable item, so labels line up
|
|
167
|
+
whether or not their item is checked. */
|
|
168
|
+
.menu-item-check {
|
|
169
|
+
display: inline-flex;
|
|
170
|
+
flex-shrink: 0;
|
|
171
|
+
width: 18px;
|
|
172
|
+
justify-content: center;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.menu-item :global(.menu-item-icon),
|
|
176
|
+
.menu-item :global(.menu-item-check-glyph) {
|
|
120
177
|
flex-shrink: 0;
|
|
121
178
|
}
|
|
122
179
|
|
|
@@ -5,6 +5,14 @@ interface Props {
|
|
|
5
5
|
href?: string;
|
|
6
6
|
onclick?: () => void;
|
|
7
7
|
destructive?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Makes the item a checkable one (`menuitemcheckbox`) showing a checkmark
|
|
10
|
+
* when true. Leave it unset for a plain item. The menu does not flip it:
|
|
11
|
+
* update it from `onclick`.
|
|
12
|
+
*/
|
|
13
|
+
checked?: boolean;
|
|
14
|
+
/** Shows the item dimmed. It stays focusable, as the menu pattern asks, but does nothing. */
|
|
15
|
+
disabled?: boolean;
|
|
8
16
|
class?: string;
|
|
9
17
|
}
|
|
10
18
|
declare const MenuItem: import("svelte").Component<Props, {}, string>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { menuSectionSize, type MenuSectionSize } from '../../actions/menuLogic';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
children: Snippet;
|
|
7
|
+
/** A heading shown over the section's items, and the name of its group. */
|
|
8
|
+
title?: string;
|
|
9
|
+
/**
|
|
10
|
+
* How the items are laid out, as UIMenu's preferredElementSize does.
|
|
11
|
+
* `large` (the default) is the usual list. `medium` puts up to four items
|
|
12
|
+
* in a row, icon over title. `small` puts icons in a row and keeps each
|
|
13
|
+
* title as the item's accessible name only.
|
|
14
|
+
*/
|
|
15
|
+
size?: MenuSectionSize;
|
|
16
|
+
class?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let { children, title, size = 'large', class: className = '' }: Props = $props();
|
|
20
|
+
|
|
21
|
+
const layout = $derived(menuSectionSize(size));
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<div
|
|
25
|
+
role="group"
|
|
26
|
+
aria-label={title}
|
|
27
|
+
class="menu-section size-{layout} {className}"
|
|
28
|
+
data-size={layout}
|
|
29
|
+
>
|
|
30
|
+
{#if title}
|
|
31
|
+
<div class="menu-section-title" aria-hidden="true">{title}</div>
|
|
32
|
+
{/if}
|
|
33
|
+
<div class="menu-section-items">
|
|
34
|
+
{@render children()}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<style>
|
|
39
|
+
/* iOS 26 sets only groups apart, with a thin line inset from the panel
|
|
40
|
+
edges (WWDC25 323, HIG Menus). Items inside a group have none. The line
|
|
41
|
+
goes over a section that follows anything, and under a section that a
|
|
42
|
+
loose item or submenu follows. */
|
|
43
|
+
:global(.menu-section + .menu-section)::before,
|
|
44
|
+
:global(.menu-item + .menu-section)::before,
|
|
45
|
+
:global(.menu-submenu + .menu-section)::before,
|
|
46
|
+
.menu-section:has(:global(+ .menu-item))::after,
|
|
47
|
+
.menu-section:has(:global(+ .menu-submenu))::after {
|
|
48
|
+
content: '';
|
|
49
|
+
display: block;
|
|
50
|
+
margin: 8px 16px;
|
|
51
|
+
/* A border, not a background, so forced colours keep the line. */
|
|
52
|
+
border-top: var(--glass-border-width) solid var(--glass-divider);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.menu-section-title {
|
|
56
|
+
padding: 6px 16px 4px;
|
|
57
|
+
font-size: 15px;
|
|
58
|
+
font-weight: 400;
|
|
59
|
+
color: var(--glass-fg-secondary, var(--color-text-secondary, var(--color-text)));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.size-medium .menu-section-items,
|
|
63
|
+
.size-small .menu-section-items {
|
|
64
|
+
display: flex;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.size-medium .menu-section-items :global(.menu-item),
|
|
68
|
+
.size-small .menu-section-items :global(.menu-item) {
|
|
69
|
+
flex: 1 1 0;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
min-width: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.size-medium .menu-section-items :global(.menu-item) {
|
|
75
|
+
flex-direction: column;
|
|
76
|
+
gap: 4px;
|
|
77
|
+
font-size: 0.75rem;
|
|
78
|
+
text-align: center;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.size-medium .menu-section-items :global(.menu-item-label) {
|
|
82
|
+
flex: none;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Small keeps the title for assistive technology only. */
|
|
86
|
+
.size-small .menu-section-items :global(.menu-item-label) {
|
|
87
|
+
position: absolute;
|
|
88
|
+
width: 1px;
|
|
89
|
+
height: 1px;
|
|
90
|
+
overflow: hidden;
|
|
91
|
+
clip-path: inset(50%);
|
|
92
|
+
white-space: nowrap;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import { type MenuSectionSize } from '../../actions/menuLogic';
|
|
3
|
+
interface Props {
|
|
4
|
+
children: Snippet;
|
|
5
|
+
/** A heading shown over the section's items, and the name of its group. */
|
|
6
|
+
title?: string;
|
|
7
|
+
/**
|
|
8
|
+
* How the items are laid out, as UIMenu's preferredElementSize does.
|
|
9
|
+
* `large` (the default) is the usual list. `medium` puts up to four items
|
|
10
|
+
* in a row, icon over title. `small` puts icons in a row and keeps each
|
|
11
|
+
* title as the item's accessible name only.
|
|
12
|
+
*/
|
|
13
|
+
size?: MenuSectionSize;
|
|
14
|
+
class?: string;
|
|
15
|
+
}
|
|
16
|
+
declare const MenuSection: import("svelte").Component<Props, {}, string>;
|
|
17
|
+
type MenuSection = ReturnType<typeof MenuSection>;
|
|
18
|
+
export default MenuSection;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { tick } from 'svelte';
|
|
4
|
+
import { getIconPath } from '../../icons';
|
|
5
|
+
import { MENU_ITEM_SELECTOR, submenuKeyAction } from '../../actions/menuLogic';
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
/** The title of the item that opens the submenu, and the submenu's name. */
|
|
9
|
+
label: string;
|
|
10
|
+
children: Snippet;
|
|
11
|
+
icon?: string;
|
|
12
|
+
class?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let { label, children, icon, class: className = '' }: Props = $props();
|
|
16
|
+
|
|
17
|
+
const uid = $props.id();
|
|
18
|
+
const triggerId = `${uid}-trigger`;
|
|
19
|
+
const panelId = `${uid}-menu`;
|
|
20
|
+
|
|
21
|
+
let open = $state(false);
|
|
22
|
+
let triggerEl = $state<HTMLButtonElement>();
|
|
23
|
+
let panelEl = $state<HTMLDivElement>();
|
|
24
|
+
|
|
25
|
+
// Security Note: iconPath is always from the hardcoded ICONS map, never user input.
|
|
26
|
+
const iconPath = $derived(icon ? getIconPath(icon) : '');
|
|
27
|
+
|
|
28
|
+
function isRtl(): boolean {
|
|
29
|
+
return triggerEl ? getComputedStyle(triggerEl).direction === 'rtl' : false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function expand() {
|
|
33
|
+
open = true;
|
|
34
|
+
await tick();
|
|
35
|
+
panelEl?.querySelector<HTMLElement>(MENU_ITEM_SELECTOR)?.focus();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function collapse() {
|
|
39
|
+
open = false;
|
|
40
|
+
triggerEl?.focus();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function handleTriggerKeydown(e: KeyboardEvent) {
|
|
44
|
+
if (submenuKeyAction(e.key, isRtl()) !== 'open') return;
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
expand();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handlePanelKeydown(e: KeyboardEvent) {
|
|
51
|
+
if (submenuKeyAction(e.key, isRtl()) !== 'close') return;
|
|
52
|
+
// Only this submenu closes: the menu around it stays open.
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
e.stopPropagation();
|
|
55
|
+
collapse();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function toggle() {
|
|
59
|
+
if (open) collapse();
|
|
60
|
+
else expand();
|
|
61
|
+
}
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<div class="menu-submenu {className}" class:open role="none">
|
|
65
|
+
<button
|
|
66
|
+
bind:this={triggerEl}
|
|
67
|
+
type="button"
|
|
68
|
+
role="menuitem"
|
|
69
|
+
id={triggerId}
|
|
70
|
+
tabindex="-1"
|
|
71
|
+
class="menu-item menu-submenu-trigger"
|
|
72
|
+
aria-haspopup="menu"
|
|
73
|
+
aria-expanded={open}
|
|
74
|
+
aria-controls={open ? panelId : undefined}
|
|
75
|
+
onclick={toggle}
|
|
76
|
+
onkeydown={handleTriggerKeydown}
|
|
77
|
+
>
|
|
78
|
+
{#if icon}
|
|
79
|
+
<svg
|
|
80
|
+
class="menu-item-icon"
|
|
81
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
82
|
+
width="18"
|
|
83
|
+
height="18"
|
|
84
|
+
viewBox="0 0 24 24"
|
|
85
|
+
fill="none"
|
|
86
|
+
stroke="currentColor"
|
|
87
|
+
stroke-width="2"
|
|
88
|
+
stroke-linecap="round"
|
|
89
|
+
stroke-linejoin="round"
|
|
90
|
+
aria-hidden="true"
|
|
91
|
+
focusable="false"
|
|
92
|
+
>
|
|
93
|
+
{@html iconPath}
|
|
94
|
+
</svg>
|
|
95
|
+
{/if}
|
|
96
|
+
<span class="menu-item-label">{label}</span>
|
|
97
|
+
<svg
|
|
98
|
+
class="menu-submenu-chevron"
|
|
99
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
100
|
+
width="14"
|
|
101
|
+
height="14"
|
|
102
|
+
viewBox="0 0 24 24"
|
|
103
|
+
fill="none"
|
|
104
|
+
stroke="currentColor"
|
|
105
|
+
stroke-width="2.5"
|
|
106
|
+
stroke-linecap="round"
|
|
107
|
+
stroke-linejoin="round"
|
|
108
|
+
aria-hidden="true"
|
|
109
|
+
focusable="false"
|
|
110
|
+
>
|
|
111
|
+
{@html getIconPath('chevron.right')}
|
|
112
|
+
</svg>
|
|
113
|
+
</button>
|
|
114
|
+
{#if open}
|
|
115
|
+
<!-- iOS opens a submenu in place, under its item, so the nested menu is
|
|
116
|
+
shown inline rather than to the side. -->
|
|
117
|
+
<div
|
|
118
|
+
bind:this={panelEl}
|
|
119
|
+
id={panelId}
|
|
120
|
+
role="menu"
|
|
121
|
+
tabindex="-1"
|
|
122
|
+
aria-labelledby={triggerId}
|
|
123
|
+
class="menu-submenu-panel"
|
|
124
|
+
onkeydown={handlePanelKeydown}
|
|
125
|
+
>
|
|
126
|
+
{@render children()}
|
|
127
|
+
</div>
|
|
128
|
+
{/if}
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<style>
|
|
132
|
+
.menu-submenu-trigger {
|
|
133
|
+
display: flex;
|
|
134
|
+
align-items: center;
|
|
135
|
+
gap: 10px;
|
|
136
|
+
box-sizing: border-box;
|
|
137
|
+
width: 100%;
|
|
138
|
+
/* The same row as MenuItem. */
|
|
139
|
+
min-height: 44px;
|
|
140
|
+
padding: 10px 16px;
|
|
141
|
+
background: none;
|
|
142
|
+
border: none;
|
|
143
|
+
border-radius: calc(var(--glass-radius-xl) - 8px);
|
|
144
|
+
font: inherit;
|
|
145
|
+
font-size: 17px;
|
|
146
|
+
text-align: start;
|
|
147
|
+
color: var(--glass-fg, var(--color-text));
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.menu-submenu-trigger:hover,
|
|
152
|
+
.menu-submenu-trigger:focus-visible {
|
|
153
|
+
background: var(--glass-hover-subtle);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
:where(.menu-submenu-trigger:focus-visible) {
|
|
157
|
+
outline: var(--glass-focus-ring-width, 2px) solid var(--glass-focus-ring-color, var(--glass-focus-ring-color-default, #9ecbff));
|
|
158
|
+
box-shadow: inset 0 0 0 calc(2 * var(--glass-focus-ring-width, 2px)) var(--glass-focus-ring-halo-color, var(--glass-focus-ring-halo-color-default, #000000));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.menu-submenu-trigger:where(:focus-visible) {
|
|
162
|
+
outline-offset: calc(-1 * var(--glass-focus-ring-width, 2px));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.menu-submenu-trigger .menu-item-label {
|
|
166
|
+
flex: 1;
|
|
167
|
+
min-width: 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.menu-submenu-chevron {
|
|
171
|
+
flex-shrink: 0;
|
|
172
|
+
transition: transform var(--transition-fast);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.open .menu-submenu-chevron {
|
|
176
|
+
transform: rotate(90deg);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
:global([dir='rtl']) .menu-submenu-chevron {
|
|
180
|
+
transform: scaleX(-1);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
:global([dir='rtl']) .open .menu-submenu-chevron {
|
|
184
|
+
transform: rotate(90deg);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* The open submenu is set in by a faint fill under its items, with no lines. */
|
|
188
|
+
.menu-submenu-panel {
|
|
189
|
+
background: var(--glass-hover-subtle);
|
|
190
|
+
border-radius: calc(var(--glass-radius-xl) - 8px);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.menu-submenu-panel :global(.menu-item) {
|
|
194
|
+
padding-inline-start: 28px;
|
|
195
|
+
}
|
|
196
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The title of the item that opens the submenu, and the submenu's name. */
|
|
4
|
+
label: string;
|
|
5
|
+
children: Snippet;
|
|
6
|
+
icon?: string;
|
|
7
|
+
class?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const MenuSubmenu: import("svelte").Component<Props, {}, string>;
|
|
10
|
+
type MenuSubmenu = ReturnType<typeof MenuSubmenu>;
|
|
11
|
+
export default MenuSubmenu;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Menu Components
|
|
3
|
-
* Dropdown menu and
|
|
3
|
+
* Dropdown menu, items, sections and submenus
|
|
4
4
|
*/
|
|
5
5
|
export { default as Menu } from './Menu.svelte';
|
|
6
6
|
export { default as MenuItem } from './MenuItem.svelte';
|
|
7
|
+
export { default as MenuSection } from './MenuSection.svelte';
|
|
8
|
+
export { default as MenuSubmenu } from './MenuSubmenu.svelte';
|
|
9
|
+
export type { MenuSectionSize } from '../../actions/menuLogic';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Menu Components
|
|
3
|
-
* Dropdown menu and
|
|
3
|
+
* Dropdown menu, items, sections and submenus
|
|
4
4
|
*/
|
|
5
5
|
export { default as Menu } from './Menu.svelte';
|
|
6
6
|
export { default as MenuItem } from './MenuItem.svelte';
|
|
7
|
+
export { default as MenuSection } from './MenuSection.svelte';
|
|
8
|
+
export { default as MenuSubmenu } from './MenuSubmenu.svelte';
|