@streamscloud/kit 0.94.4 → 0.94.5

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.
@@ -1,15 +1,28 @@
1
- <script lang="ts">import { IconSlot } from '../icon';
2
- const { label, icon, href, active = false, activeStyle = 'plain', disabled = false, badge, target, rel, on } = $props();
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()}
@@ -22,33 +35,42 @@ const handleClick = (event) => {
22
35
  <span class="nav-menu-item__label">{label}</span>
23
36
  {/snippet}
24
37
 
25
- {#if href && !disabled}
26
- <a
27
- class="nav-menu-item"
28
- class:nav-menu-item--active={active}
29
- class:nav-menu-item--active-filled={activeFilled}
30
- class:nav-menu-item--active-plain={activePlain}
31
- href={href}
32
- target={target}
33
- rel={rel}
34
- aria-current={active ? 'page' : undefined}
35
- onclick={handleClick}>
36
- {@render content()}
37
- </a>
38
- {:else}
39
- <button
40
- type="button"
41
- class="nav-menu-item"
42
- class:nav-menu-item--active={active}
43
- class:nav-menu-item--active-filled={activeFilled}
44
- class:nav-menu-item--active-plain={activePlain}
45
- class:nav-menu-item--disabled={disabled}
46
- disabled={disabled}
47
- aria-current={active ? 'page' : undefined}
48
- onclick={handleClick}>
49
- {@render content()}
50
- </button>
51
- {/if}
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 class="nav-menu-item__control" href={href} target={target} rel={rel} aria-current={active ? 'page' : undefined} onclick={handleClick}>
48
+ {@render content()}
49
+ </a>
50
+ {:else}
51
+ <button type="button" class="nav-menu-item__control" disabled={disabled} aria-current={active ? 'page' : undefined} onclick={handleClick}>
52
+ {@render content()}
53
+ </button>
54
+ {/if}
55
+
56
+ {#if actionsShown}
57
+ <div class="nav-menu-item__actions">
58
+ <Popover position="bottom-end" aria-label={localization.actionsFor(label)} on={{ opened: handleActionsOpened, closed: handleActionsClosed }}>
59
+ {#snippet trigger()}
60
+ <span class="nav-menu-item__actions-trigger">
61
+ <Icon src={IconMoreVertical} />
62
+ </span>
63
+ {/snippet}
64
+
65
+ {#each actions as action (action)}
66
+ <PopoverItem on={{ click: action.action }}>
67
+ <IconText icon={action.icon} size="sm">{action.name}</IconText>
68
+ </PopoverItem>
69
+ {/each}
70
+ </Popover>
71
+ </div>
72
+ {/if}
73
+ </div>
52
74
 
53
75
  <!--
54
76
  @component
@@ -59,6 +81,7 @@ with the `MouseEvent` and the link default is left intact. Active state is consu
59
81
  (`active` prop) — wire it to your router's pathname matching upstream. `activeStyle` picks how the
60
82
  active row reads: `'plain'` (default) drops the plate, so color plus a heavier label weight carry the
61
83
  signal and hover keeps working on the active row; `'filled'` plates it and suppresses hover there.
84
+ `actions` add a "⋮" menu at the end of the row, a sibling of the link, so the link stays a plain link.
62
85
 
63
86
  ### CSS Custom Properties
64
87
  | Property | Description | Default |
@@ -87,25 +110,18 @@ signal and hover keeps working on the active row; `'filled'` plates it and suppr
87
110
  --_nav-menu-item--background-active: var(--sc-kit--nav-menu-item--background--active, var(--sc-kit--color--bg--menu-active));
88
111
  --_nav-menu-item--badge-background: var(--sc-kit--nav-menu-item--badge--background, var(--sc-kit--color--accent));
89
112
  --_nav-menu-item--badge-color: var(--sc-kit--nav-menu-item--badge--color, var(--sc-kit--color--text--on-accent));
90
- display: flex;
91
- align-items: center;
92
- gap: var(--_nav-menu-item--gap);
113
+ --_nav-menu-item--actions-size: 1.5rem;
114
+ --_nav-menu-item--actions-inset: var(--sc-kit--space--2);
115
+ position: relative;
93
116
  width: 100%;
94
- padding: 0.375rem var(--sc-kit--space--5);
95
- background: none;
96
- border: none;
97
117
  border-radius: var(--_nav-menu-item--radius);
98
- cursor: pointer;
99
- text-decoration: none;
100
118
  color: var(--_nav-menu-item--color);
101
- font-family: inherit;
102
- text-align: left;
103
119
  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
120
  }
105
- .nav-menu-item:hover:not(.nav-menu-item--active-filled):not(.nav-menu-item--disabled):not(:disabled) {
121
+ .nav-menu-item:hover:not(.nav-menu-item--active-filled, .nav-menu-item--disabled) {
106
122
  background: var(--_nav-menu-item--background-hover);
107
123
  }
108
- .nav-menu-item:hover:not(.nav-menu-item--disabled):not(:disabled), .nav-menu-item--active {
124
+ .nav-menu-item:hover:not(.nav-menu-item--disabled), .nav-menu-item--active {
109
125
  color: var(--_nav-menu-item--color-active);
110
126
  }
111
127
  .nav-menu-item--active-filled {
@@ -114,14 +130,48 @@ signal and hover keeps working on the active row; `'filled'` plates it and suppr
114
130
  .nav-menu-item--active-plain {
115
131
  font-weight: var(--_nav-menu-item--font-weight-active);
116
132
  }
117
- .nav-menu-item--disabled, .nav-menu-item:disabled {
133
+ .nav-menu-item--disabled {
118
134
  color: var(--_nav-menu-item--color-disabled);
135
+ }
136
+ @media (any-hover: hover) {
137
+ .nav-menu-item--with-actions:not(:hover, :has(:global(:focus-visible)), .nav-menu-item--actions-opened) .nav-menu-item__actions {
138
+ position: absolute;
139
+ width: 1px;
140
+ height: 1px;
141
+ margin: -1px;
142
+ padding: 0;
143
+ overflow: hidden;
144
+ clip-path: inset(50%);
145
+ white-space: nowrap;
146
+ border: 0;
147
+ }
148
+ }
149
+
150
+ .nav-menu-item__control {
151
+ display: flex;
152
+ align-items: center;
153
+ gap: var(--_nav-menu-item--gap);
154
+ width: 100%;
155
+ padding: 0.375rem var(--sc-kit--space--5);
156
+ background: none;
157
+ border: none;
158
+ border-radius: inherit;
159
+ cursor: pointer;
160
+ text-decoration: none;
161
+ color: inherit;
162
+ font: inherit;
163
+ text-align: left;
164
+ }
165
+ .nav-menu-item__control:disabled {
119
166
  cursor: default;
120
167
  }
121
- .nav-menu-item:focus-visible {
168
+ .nav-menu-item__control:focus-visible {
122
169
  outline: 2px solid var(--sc-kit--color--border--focus);
123
170
  outline-offset: -2px;
124
171
  }
172
+ .nav-menu-item--with-actions > .nav-menu-item__control {
173
+ padding-right: calc(var(--_nav-menu-item--actions-size) + var(--_nav-menu-item--actions-inset) * 2);
174
+ }
125
175
 
126
176
  .nav-menu-item__icon {
127
177
  --sc-kit--icon--size: var(--_nav-menu-item--icon-size);
@@ -162,4 +212,28 @@ signal and hover keeps working on the active row; `'filled'` plates it and suppr
162
212
  max-width: 100%;
163
213
  white-space: nowrap;
164
214
  overflow: hidden;
215
+ }
216
+
217
+ .nav-menu-item__actions {
218
+ position: absolute;
219
+ top: 50%;
220
+ right: var(--_nav-menu-item--actions-inset);
221
+ display: flex;
222
+ translate: 0 -50%;
223
+ }
224
+
225
+ .nav-menu-item__actions-trigger {
226
+ --sc-kit--icon--size: 1rem;
227
+ display: inline-flex;
228
+ align-items: center;
229
+ justify-content: center;
230
+ width: var(--_nav-menu-item--actions-size);
231
+ height: var(--_nav-menu-item--actions-size);
232
+ border-radius: var(--sc-kit--radius--sm);
233
+ color: var(--sc-kit--color--text--secondary);
234
+ transition: color var(--sc-kit--duration--base) var(--sc-kit--ease--default), background-color var(--sc-kit--duration--base) var(--sc-kit--ease--default);
235
+ }
236
+ .nav-menu-item__actions-trigger:hover {
237
+ background: var(--sc-kit--color--bg--active);
238
+ color: var(--sc-kit--color--text--primary);
165
239
  }</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. @default false */
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,3 @@
1
+ export declare class NavMenuItemLocalization {
2
+ actionsFor: (label: string) => string;
3
+ }
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.94.4",
3
+ "version": "0.94.5",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",