@streamscloud/kit 0.94.4 → 0.94.6
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/dist/ui/navigation/cmp.nav-menu-item.svelte +134 -47
- package/dist/ui/navigation/cmp.nav-menu-item.svelte.d.ts +5 -1
- package/dist/ui/navigation/index.d.ts +1 -1
- package/dist/ui/navigation/nav-menu-item-localization.d.ts +3 -0
- package/dist/ui/navigation/nav-menu-item-localization.js +12 -0
- package/dist/ui/navigation/types.d.ts +6 -0
- package/package.json +1 -1
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
<script lang="ts">import { IconSlot } from '../icon';
|
|
2
|
-
|
|
1
|
+
<script lang="ts">import { Icon, IconSlot } from '../icon';
|
|
2
|
+
import { IconText } from '../icon-text';
|
|
3
|
+
import { Popover, PopoverItem } from '../popover';
|
|
4
|
+
import { NavMenuItemLocalization } from './nav-menu-item-localization';
|
|
5
|
+
import IconMoreVertical from '@fluentui/svg-icons/icons/more_vertical_20_regular.svg?raw';
|
|
6
|
+
const { label, icon, href, active = false, activeStyle = 'plain', disabled = false, badge, target, rel, actions = [], on } = $props();
|
|
7
|
+
const localization = new NavMenuItemLocalization();
|
|
8
|
+
let actionsOpened = $state(false);
|
|
3
9
|
const activeFilled = $derived(active && activeStyle === 'filled');
|
|
4
10
|
const activePlain = $derived(active && activeStyle === 'plain');
|
|
5
11
|
const badgeText = $derived(typeof badge === 'number' && badge > 99 ? '99+' : badge);
|
|
6
12
|
const hasBadge = $derived(badge !== undefined && badge !== null && badge !== '');
|
|
13
|
+
const actionsShown = $derived(!disabled && actions.length > 0);
|
|
7
14
|
const handleClick = (event) => {
|
|
8
15
|
if (disabled) {
|
|
9
16
|
return;
|
|
10
17
|
}
|
|
11
18
|
on?.click?.(event);
|
|
12
19
|
};
|
|
20
|
+
const handleActionsOpened = () => {
|
|
21
|
+
actionsOpened = true;
|
|
22
|
+
};
|
|
23
|
+
const handleActionsClosed = () => {
|
|
24
|
+
actionsOpened = false;
|
|
25
|
+
};
|
|
13
26
|
</script>
|
|
14
27
|
|
|
15
28
|
{#snippet content()}
|
|
@@ -19,36 +32,58 @@ const handleClick = (event) => {
|
|
|
19
32
|
<span class="nav-menu-item__badge">{badgeText}</span>
|
|
20
33
|
{/if}
|
|
21
34
|
</span>
|
|
22
|
-
<span class="nav-menu-item__label">{label}</span>
|
|
35
|
+
<span class="nav-menu-item__label" class:nav-menu-item__label--active-plain={activePlain}>{label}</span>
|
|
23
36
|
{/snippet}
|
|
24
37
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
{
|
|
38
|
+
<div
|
|
39
|
+
class="nav-menu-item"
|
|
40
|
+
class:nav-menu-item--active={active}
|
|
41
|
+
class:nav-menu-item--active-filled={activeFilled}
|
|
42
|
+
class:nav-menu-item--active-plain={activePlain}
|
|
43
|
+
class:nav-menu-item--disabled={disabled}
|
|
44
|
+
class:nav-menu-item--with-actions={actionsShown}
|
|
45
|
+
class:nav-menu-item--actions-opened={actionsOpened}>
|
|
46
|
+
{#if href && !disabled}
|
|
47
|
+
<a
|
|
48
|
+
class="nav-menu-item__control"
|
|
49
|
+
class:nav-menu-item__control--with-actions={actionsShown}
|
|
50
|
+
href={href}
|
|
51
|
+
target={target}
|
|
52
|
+
rel={rel}
|
|
53
|
+
aria-current={active ? 'page' : undefined}
|
|
54
|
+
onclick={handleClick}>
|
|
55
|
+
{@render content()}
|
|
56
|
+
</a>
|
|
57
|
+
{:else}
|
|
58
|
+
<button
|
|
59
|
+
type="button"
|
|
60
|
+
class="nav-menu-item__control"
|
|
61
|
+
class:nav-menu-item__control--with-actions={actionsShown}
|
|
62
|
+
disabled={disabled}
|
|
63
|
+
aria-current={active ? 'page' : undefined}
|
|
64
|
+
onclick={handleClick}>
|
|
65
|
+
{@render content()}
|
|
66
|
+
</button>
|
|
67
|
+
{/if}
|
|
68
|
+
|
|
69
|
+
{#if actionsShown}
|
|
70
|
+
<div class="nav-menu-item__actions">
|
|
71
|
+
<Popover position="bottom-end" aria-label={localization.actionsFor(label)} on={{ opened: handleActionsOpened, closed: handleActionsClosed }}>
|
|
72
|
+
{#snippet trigger()}
|
|
73
|
+
<span class="nav-menu-item__actions-trigger">
|
|
74
|
+
<Icon src={IconMoreVertical} />
|
|
75
|
+
</span>
|
|
76
|
+
{/snippet}
|
|
77
|
+
|
|
78
|
+
{#each actions as action (action)}
|
|
79
|
+
<PopoverItem on={{ click: action.action }}>
|
|
80
|
+
<IconText icon={action.icon} size="sm">{action.name}</IconText>
|
|
81
|
+
</PopoverItem>
|
|
82
|
+
{/each}
|
|
83
|
+
</Popover>
|
|
84
|
+
</div>
|
|
85
|
+
{/if}
|
|
86
|
+
</div>
|
|
52
87
|
|
|
53
88
|
<!--
|
|
54
89
|
@component
|
|
@@ -59,6 +94,7 @@ with the `MouseEvent` and the link default is left intact. Active state is consu
|
|
|
59
94
|
(`active` prop) — wire it to your router's pathname matching upstream. `activeStyle` picks how the
|
|
60
95
|
active row reads: `'plain'` (default) drops the plate, so color plus a heavier label weight carry the
|
|
61
96
|
signal and hover keeps working on the active row; `'filled'` plates it and suppresses hover there.
|
|
97
|
+
`actions` add a "⋮" menu at the end of the row, a sibling of the link, so the link stays a plain link.
|
|
62
98
|
|
|
63
99
|
### CSS Custom Properties
|
|
64
100
|
| Property | Description | Default |
|
|
@@ -87,41 +123,65 @@ signal and hover keeps working on the active row; `'filled'` plates it and suppr
|
|
|
87
123
|
--_nav-menu-item--background-active: var(--sc-kit--nav-menu-item--background--active, var(--sc-kit--color--bg--menu-active));
|
|
88
124
|
--_nav-menu-item--badge-background: var(--sc-kit--nav-menu-item--badge--background, var(--sc-kit--color--accent));
|
|
89
125
|
--_nav-menu-item--badge-color: var(--sc-kit--nav-menu-item--badge--color, var(--sc-kit--color--text--on-accent));
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
126
|
+
--_nav-menu-item--actions-size: 1.5rem;
|
|
127
|
+
--_nav-menu-item--actions-inset: var(--sc-kit--space--2);
|
|
128
|
+
position: relative;
|
|
93
129
|
width: 100%;
|
|
94
|
-
padding: 0.375rem var(--sc-kit--space--5);
|
|
95
|
-
background: none;
|
|
96
|
-
border: none;
|
|
97
130
|
border-radius: var(--_nav-menu-item--radius);
|
|
98
|
-
cursor: pointer;
|
|
99
|
-
text-decoration: none;
|
|
100
131
|
color: var(--_nav-menu-item--color);
|
|
101
|
-
font-family: inherit;
|
|
102
|
-
text-align: left;
|
|
103
132
|
transition: color var(--sc-kit--duration--base) var(--sc-kit--ease--default), background-color var(--sc-kit--duration--base) var(--sc-kit--ease--default);
|
|
104
133
|
}
|
|
105
|
-
.nav-menu-item:hover:not(.nav-menu-item--active-filled
|
|
134
|
+
.nav-menu-item:hover:not(.nav-menu-item--active-filled, .nav-menu-item--disabled) {
|
|
106
135
|
background: var(--_nav-menu-item--background-hover);
|
|
107
136
|
}
|
|
108
|
-
.nav-menu-item:hover:not(.nav-menu-item--disabled)
|
|
137
|
+
.nav-menu-item:hover:not(.nav-menu-item--disabled), .nav-menu-item--active {
|
|
109
138
|
color: var(--_nav-menu-item--color-active);
|
|
110
139
|
}
|
|
111
140
|
.nav-menu-item--active-filled {
|
|
112
141
|
background: var(--_nav-menu-item--background-active);
|
|
113
142
|
}
|
|
114
|
-
.nav-menu-item--
|
|
115
|
-
font-weight: var(--_nav-menu-item--font-weight-active);
|
|
116
|
-
}
|
|
117
|
-
.nav-menu-item--disabled, .nav-menu-item:disabled {
|
|
143
|
+
.nav-menu-item--disabled {
|
|
118
144
|
color: var(--_nav-menu-item--color-disabled);
|
|
145
|
+
}
|
|
146
|
+
@media (any-hover: hover) {
|
|
147
|
+
.nav-menu-item--with-actions:not(:hover, :has(:global(:focus-visible)), .nav-menu-item--actions-opened) .nav-menu-item__actions {
|
|
148
|
+
position: absolute;
|
|
149
|
+
width: 1px;
|
|
150
|
+
height: 1px;
|
|
151
|
+
margin: -1px;
|
|
152
|
+
padding: 0;
|
|
153
|
+
overflow: hidden;
|
|
154
|
+
clip-path: inset(50%);
|
|
155
|
+
white-space: nowrap;
|
|
156
|
+
border: 0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.nav-menu-item__control {
|
|
161
|
+
display: flex;
|
|
162
|
+
align-items: center;
|
|
163
|
+
gap: var(--_nav-menu-item--gap);
|
|
164
|
+
width: 100%;
|
|
165
|
+
padding: 0.375rem var(--sc-kit--space--5);
|
|
166
|
+
background: none;
|
|
167
|
+
border: none;
|
|
168
|
+
border-radius: inherit;
|
|
169
|
+
cursor: pointer;
|
|
170
|
+
text-decoration: none;
|
|
171
|
+
color: inherit;
|
|
172
|
+
font: inherit;
|
|
173
|
+
text-align: left;
|
|
174
|
+
}
|
|
175
|
+
.nav-menu-item__control:disabled {
|
|
119
176
|
cursor: default;
|
|
120
177
|
}
|
|
121
|
-
.nav-menu-
|
|
178
|
+
.nav-menu-item__control:focus-visible {
|
|
122
179
|
outline: 2px solid var(--sc-kit--color--border--focus);
|
|
123
180
|
outline-offset: -2px;
|
|
124
181
|
}
|
|
182
|
+
.nav-menu-item__control--with-actions {
|
|
183
|
+
padding-right: calc(var(--_nav-menu-item--actions-size) + var(--_nav-menu-item--actions-inset) * 2);
|
|
184
|
+
}
|
|
125
185
|
|
|
126
186
|
.nav-menu-item__icon {
|
|
127
187
|
--sc-kit--icon--size: var(--_nav-menu-item--icon-size);
|
|
@@ -162,4 +222,31 @@ signal and hover keeps working on the active row; `'filled'` plates it and suppr
|
|
|
162
222
|
max-width: 100%;
|
|
163
223
|
white-space: nowrap;
|
|
164
224
|
overflow: hidden;
|
|
225
|
+
}
|
|
226
|
+
.nav-menu-item__label--active-plain {
|
|
227
|
+
font-weight: var(--_nav-menu-item--font-weight-active);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.nav-menu-item__actions {
|
|
231
|
+
position: absolute;
|
|
232
|
+
top: 50%;
|
|
233
|
+
right: var(--_nav-menu-item--actions-inset);
|
|
234
|
+
display: flex;
|
|
235
|
+
translate: 0 -50%;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.nav-menu-item__actions-trigger {
|
|
239
|
+
--sc-kit--icon--size: 1rem;
|
|
240
|
+
display: inline-flex;
|
|
241
|
+
align-items: center;
|
|
242
|
+
justify-content: center;
|
|
243
|
+
width: var(--_nav-menu-item--actions-size);
|
|
244
|
+
height: var(--_nav-menu-item--actions-size);
|
|
245
|
+
border-radius: var(--sc-kit--radius--sm);
|
|
246
|
+
color: var(--sc-kit--color--text--secondary);
|
|
247
|
+
transition: color var(--sc-kit--duration--base) var(--sc-kit--ease--default), background-color var(--sc-kit--duration--base) var(--sc-kit--ease--default);
|
|
248
|
+
}
|
|
249
|
+
.nav-menu-item__actions-trigger:hover {
|
|
250
|
+
background: var(--sc-kit--color--bg--active);
|
|
251
|
+
color: var(--sc-kit--color--text--primary);
|
|
165
252
|
}</style>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type IconProp } from '../icon';
|
|
2
|
+
import type { NavMenuItemAction } from './types';
|
|
2
3
|
type Props = {
|
|
3
4
|
label: string;
|
|
4
5
|
/** Icon — string SVG source, `{ src, color?, size? }` object, or custom snippet. */
|
|
5
6
|
icon: IconProp;
|
|
6
7
|
/** Render as `<a href>` — unless `disabled`, which falls back to the button form. `on.click` still fires; `event.preventDefault()` keeps the click from navigating. */
|
|
7
8
|
href?: string;
|
|
8
|
-
/** Highlight as the current item. Consumer-controlled.
|
|
9
|
+
/** Highlight as the current item. Consumer-controlled. */
|
|
9
10
|
active?: boolean;
|
|
10
11
|
/** Active row visuals — `'plain'` uses color plus a heavier label weight and keeps hover, `'filled'` paints the active background (no hover on it). @default 'plain' */
|
|
11
12
|
activeStyle?: 'filled' | 'plain';
|
|
@@ -16,6 +17,8 @@ type Props = {
|
|
|
16
17
|
target?: string;
|
|
17
18
|
/** Anchor rel — only relevant when `href` is set. */
|
|
18
19
|
rel?: string;
|
|
20
|
+
/** Row menu behind a "⋮" button at the end of the row, revealed on hover, keyboard focus, while open and on touch screens. Hidden while `disabled`. */
|
|
21
|
+
actions?: NavMenuItemAction[];
|
|
19
22
|
on?: {
|
|
20
23
|
click?: (event: MouseEvent) => void;
|
|
21
24
|
};
|
|
@@ -28,6 +31,7 @@ type Props = {
|
|
|
28
31
|
* (`active` prop) — wire it to your router's pathname matching upstream. `activeStyle` picks how the
|
|
29
32
|
* active row reads: `'plain'` (default) drops the plate, so color plus a heavier label weight carry the
|
|
30
33
|
* signal and hover keeps working on the active row; `'filled'` plates it and suppresses hover there.
|
|
34
|
+
* `actions` add a "⋮" menu at the end of the row, a sibling of the link, so the link stays a plain link.
|
|
31
35
|
*
|
|
32
36
|
* ### CSS Custom Properties
|
|
33
37
|
* | Property | Description | Default |
|
|
@@ -5,4 +5,4 @@ export { default as NavMenuGroup } from './cmp.nav-menu-group.svelte';
|
|
|
5
5
|
export { default as NavMenuHeader } from './cmp.nav-menu-header.svelte';
|
|
6
6
|
export { default as NavMenuItem } from './cmp.nav-menu-item.svelte';
|
|
7
7
|
export { default as NavRail } from './cmp.nav-rail.svelte';
|
|
8
|
-
export type { NavRailFooterToggle, NavRailItemData } from './types';
|
|
8
|
+
export type { NavMenuItemAction, NavRailFooterToggle, NavRailItemData } from './types';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AppLocale } from '../../core/locale';
|
|
2
|
+
const loc = {
|
|
3
|
+
actionsFor: {
|
|
4
|
+
en: (label) => `Actions for ${label}`,
|
|
5
|
+
no: (label) => `Handlinger for ${label}`
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
export class NavMenuItemLocalization {
|
|
9
|
+
actionsFor = (label) => {
|
|
10
|
+
return loc.actionsFor[AppLocale.current](label);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -20,6 +20,12 @@ export type NavRailItemData = {
|
|
|
20
20
|
click?: (event: MouseEvent) => void;
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
+
/** One entry of a `NavMenuItem` "⋮" menu. */
|
|
24
|
+
export type NavMenuItemAction = {
|
|
25
|
+
name: string;
|
|
26
|
+
icon?: IconProp;
|
|
27
|
+
action: () => void;
|
|
28
|
+
};
|
|
23
29
|
export type NavRailFooterToggle = {
|
|
24
30
|
/** Icon — string SVG source, `{ src, color?, size? }` object, or custom snippet. */
|
|
25
31
|
icon: IconProp;
|