fluentui-svelte 0.5.0 → 0.7.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/dist/components/app-surface/app-surface.svelte +96 -0
- package/dist/components/app-surface/app-surface.svelte.d.ts +22 -0
- package/dist/components/app-surface/docs/llms.md +73 -0
- package/dist/components/app-surface/types.d.ts +19 -0
- package/dist/components/app-surface/types.js +1 -0
- package/dist/components/app-window/app-window.d.ts +3 -0
- package/dist/components/app-window/app-window.js +3 -0
- package/dist/components/app-window/app-window.svelte +193 -0
- package/dist/components/app-window/app-window.svelte.d.ts +25 -0
- package/dist/components/app-window/docs/llms.md +119 -0
- package/dist/components/app-window/types.d.ts +66 -0
- package/dist/components/app-window/types.js +1 -0
- package/dist/components/auto-suggest-box/auto-suggest-box.svelte +47 -31
- package/dist/components/auto-suggest-box/auto-suggest-box.svelte.d.ts +2 -2
- package/dist/components/auto-suggest-box/docs/llms.md +34 -33
- package/dist/components/auto-suggest-box/option.svelte +6 -4
- package/dist/components/auto-suggest-box/types.d.ts +13 -16
- package/dist/components/avatar/avatar.svelte +4 -3
- package/dist/components/avatar/docs/llms.md +1 -1
- package/dist/components/avatar/type.d.ts +1 -1
- package/dist/components/badge/badge-icon.svelte +2 -2
- package/dist/components/badge/badge.svelte +2 -2
- package/dist/components/badge/docs/llms.md +2 -2
- package/dist/components/badge/types.d.ts +2 -2
- package/dist/components/breadcrumb/breadcrumb-button.svelte +2 -2
- package/dist/components/breadcrumb/breadcrumb-divider.svelte +2 -2
- package/dist/components/breadcrumb/breadcrumb-item.svelte +2 -2
- package/dist/components/breadcrumb/breadcrumb.svelte +10 -5
- package/dist/components/breadcrumb/docs/llms.md +11 -11
- package/dist/components/breadcrumb/types.d.ts +7 -7
- package/dist/components/button/button.svelte +2 -2
- package/dist/components/button/docs/llms.md +17 -17
- package/dist/components/button/split-button.svelte +7 -7
- package/dist/components/button/types.d.ts +5 -5
- package/dist/components/calendar-date-picker/calendar-date-picker.svelte +98 -10
- package/dist/components/calendar-date-picker/calendar-date-picker.svelte.d.ts +1 -1
- package/dist/components/calendar-date-picker/docs/llms.md +19 -14
- package/dist/components/calendar-date-picker/types.d.ts +22 -8
- package/dist/components/calendar-view/calendar-view-days.svelte +3 -2
- package/dist/components/calendar-view/calendar-view-grid.js +8 -3
- package/dist/components/calendar-view/calendar-view-item.svelte +10 -4
- package/dist/components/calendar-view/calendar-view-months.svelte +3 -2
- package/dist/components/calendar-view/calendar-view-years.svelte +3 -2
- package/dist/components/calendar-view/calendar-view.svelte +11 -4
- package/dist/components/calendar-view/calendar-view.svelte.js +5 -0
- package/dist/components/calendar-view/docs/llms.md +20 -19
- package/dist/components/calendar-view/types.d.ts +6 -1
- package/dist/components/card/card-footer.svelte +2 -2
- package/dist/components/card/card-header.svelte +5 -4
- package/dist/components/card/card-preview.svelte +13 -2
- package/dist/components/card/card.svelte +5 -5
- package/dist/components/card/docs/llms.md +22 -21
- package/dist/components/card/types.d.ts +8 -4
- package/dist/components/checkbox/checkbox.svelte +47 -26
- package/dist/components/checkbox/checkbox.svelte.d.ts +3 -24
- package/dist/components/checkbox/docs/llms.md +24 -23
- package/dist/components/checkbox/types.d.ts +10 -23
- package/dist/components/date-picker/date-picker.svelte +98 -27
- package/dist/components/date-picker/date-picker.svelte.d.ts +1 -1
- package/dist/components/date-picker/docs/llms.md +23 -20
- package/dist/components/date-picker/types.d.ts +24 -15
- package/dist/components/dialog/dialog-actions.svelte +17 -2
- package/dist/components/dialog/dialog-content.svelte +2 -2
- package/dist/components/dialog/dialog-content.svelte.d.ts +1 -1
- package/dist/components/dialog/dialog-surface.svelte +130 -8
- package/dist/components/dialog/dialog-title.svelte +23 -6
- package/dist/components/dialog/dialog-trigger.svelte +8 -2
- package/dist/components/dialog/dialog-trigger.svelte.d.ts +1 -1
- package/dist/components/dialog/dialog.svelte +22 -11
- package/dist/components/dialog/docs/llms.md +56 -19
- package/dist/components/dialog/types.d.ts +31 -9
- package/dist/components/dialog/utils.d.ts +2 -0
- package/dist/components/dialog/utils.js +1 -0
- package/dist/components/divider/divider.svelte +6 -4
- package/dist/components/divider/types.d.ts +1 -1
- package/dist/components/dropdown/docs/llms.md +30 -28
- package/dist/components/dropdown/dropdown-option.svelte +17 -5
- package/dist/components/dropdown/dropdown.svelte +182 -84
- package/dist/components/dropdown/dropdown.svelte.d.ts +1 -1
- package/dist/components/dropdown/types.d.ts +26 -20
- package/dist/components/dropdown-select/docs/llms.md +24 -22
- package/dist/components/dropdown-select/dropdown-select-option.svelte +2 -2
- package/dist/components/dropdown-select/dropdown-select.svelte +42 -7
- package/dist/components/dropdown-select/types.d.ts +4 -4
- package/dist/components/expander/docs/llms.md +3 -3
- package/dist/components/expander/expander.svelte +13 -8
- package/dist/components/expander/types.d.ts +5 -5
- package/dist/components/flyout/docs/llms.md +1 -1
- package/dist/components/flyout/flyout.svelte +17 -6
- package/dist/components/flyout/types.d.ts +1 -1
- package/dist/components/hyperlink/docs/llms.md +6 -6
- package/dist/components/hyperlink/hyperlink.svelte +13 -4
- package/dist/components/hyperlink/types.d.ts +1 -1
- package/dist/components/info-bar/docs/llms.md +11 -10
- package/dist/components/info-bar/info-bar.svelte +3 -2
- package/dist/components/info-bar/types.d.ts +4 -0
- package/dist/components/label/docs/llms.md +75 -22
- package/dist/components/label/label-context.d.ts +14 -0
- package/dist/components/label/label-context.js +10 -0
- package/dist/components/label/label.svelte +153 -30
- package/dist/components/label/label.svelte.d.ts +1 -1
- package/dist/components/label/types.d.ts +48 -4
- package/dist/components/list-view/docs/llms.md +103 -33
- package/dist/components/list-view/list-view-item-branch.svelte +257 -0
- package/dist/components/list-view/list-view-item-branch.svelte.d.ts +4 -0
- package/dist/components/list-view/list-view-item.svelte +164 -46
- package/dist/components/list-view/list-view-item.svelte.d.ts +5 -5
- package/dist/components/list-view/list-view.svelte +73 -25
- package/dist/components/list-view/types.d.ts +71 -8
- package/dist/components/list-view/utils.d.ts +10 -0
- package/dist/components/list-view/utils.js +17 -1
- package/dist/components/menu/docs/llms.md +98 -15
- package/dist/components/menu/menu-command-bar-item.svelte +61 -0
- package/dist/components/menu/menu-command-bar-item.svelte.d.ts +14 -0
- package/dist/components/menu/menu-command-bar.svelte +218 -0
- package/dist/components/menu/menu-command-bar.svelte.d.ts +21 -0
- package/dist/components/menu/menu-group.svelte +6 -3
- package/dist/components/menu/menu-item-checkbox.svelte +5 -4
- package/dist/components/menu/menu-item-radio.svelte +5 -4
- package/dist/components/menu/menu-item-switch.svelte +5 -4
- package/dist/components/menu/menu-item.svelte +5 -5
- package/dist/components/menu/menu-item.svelte.d.ts +2 -3
- package/dist/components/menu/menu-list.svelte +10 -1
- package/dist/components/menu/menu-popover.svelte +9 -5
- package/dist/components/menu/menu-trigger.svelte +2 -1
- package/dist/components/menu/menu.svelte.js +1 -0
- package/dist/components/menu/types.d.ts +62 -7
- package/dist/components/number-box/docs/llms.md +6 -4
- package/dist/components/number-box/number-box.svelte +35 -29
- package/dist/components/number-box/number-box.svelte.d.ts +1 -1
- package/dist/components/number-box/types.d.ts +1 -1
- package/dist/components/persona/docs/llms.md +29 -25
- package/dist/components/persona/persona.svelte +8 -6
- package/dist/components/persona/types.d.ts +4 -3
- package/dist/components/progress-bar/docs/llms.md +13 -13
- package/dist/components/progress-bar/progress-bar.svelte +6 -6
- package/dist/components/progress-bar/types.d.ts +4 -4
- package/dist/components/progress-ring/docs/llms.md +14 -14
- package/dist/components/progress-ring/progress-ring.svelte +5 -5
- package/dist/components/progress-ring/types.d.ts +3 -3
- package/dist/components/radio-button/docs/llms.md +11 -8
- package/dist/components/radio-button/radio-button.svelte +38 -12
- package/dist/components/radio-button/radio-button.svelte.d.ts +1 -1
- package/dist/components/radio-button/types.d.ts +11 -8
- package/dist/components/rating/docs/llms.md +111 -0
- package/dist/components/rating/rating.svelte +247 -0
- package/dist/components/rating/rating.svelte.d.ts +19 -0
- package/dist/components/rating/types.d.ts +44 -0
- package/dist/components/rating/types.js +1 -0
- package/dist/components/side-nav/docs/llms.md +110 -0
- package/dist/components/side-nav/side-nav-branch.svelte +43 -0
- package/dist/components/side-nav/side-nav-branch.svelte.d.ts +4 -0
- package/dist/components/side-nav/side-nav-item.svelte +75 -0
- package/dist/components/side-nav/side-nav-item.svelte.d.ts +25 -0
- package/dist/components/side-nav/side-nav-list.svelte +32 -0
- package/dist/components/side-nav/side-nav-list.svelte.d.ts +7 -0
- package/dist/components/side-nav/side-nav.d.ts +2 -0
- package/dist/components/side-nav/side-nav.js +2 -0
- package/dist/components/side-nav/side-nav.svelte +355 -0
- package/dist/components/side-nav/side-nav.svelte.d.ts +24 -0
- package/dist/components/side-nav/types.d.ts +149 -0
- package/dist/components/side-nav/types.js +1 -0
- package/dist/components/skeleton/docs/llms.md +1 -1
- package/dist/components/skeleton/skeleton.svelte +2 -2
- package/dist/components/skeleton/types.d.ts +1 -1
- package/dist/components/slider/docs/llms.md +31 -28
- package/dist/components/slider/slider.svelte +126 -61
- package/dist/components/slider/slider.svelte.d.ts +1 -3
- package/dist/components/slider/types.d.ts +21 -14
- package/dist/components/tab-view/docs/llms.md +7 -7
- package/dist/components/tab-view/tab-view-tab.svelte +16 -14
- package/dist/components/tab-view/tab-view.svelte +16 -9
- package/dist/components/tab-view/types.d.ts +6 -6
- package/dist/components/table/docs/llms.md +38 -33
- package/dist/components/table/table-body.svelte +2 -2
- package/dist/components/table/table-cell-actions.svelte +8 -2
- package/dist/components/table/table-cell-layout.svelte +2 -2
- package/dist/components/table/table-cell.svelte +2 -2
- package/dist/components/table/table-header-cell.svelte +2 -2
- package/dist/components/table/table-header.svelte +2 -2
- package/dist/components/table/table-row.svelte +2 -2
- package/dist/components/table/table-selection-cell.svelte +6 -6
- package/dist/components/table/table.svelte +2 -2
- package/dist/components/table/types.d.ts +11 -11
- package/dist/components/tag/docs/llms.md +383 -0
- package/dist/components/tag/tag-group.d.ts +2 -0
- package/dist/components/tag/tag-group.js +2 -0
- package/dist/components/tag/tag-group.svelte +117 -0
- package/dist/components/tag/tag-group.svelte.d.ts +20 -0
- package/dist/components/tag/tag.svelte +459 -0
- package/dist/components/tag/tag.svelte.d.ts +19 -0
- package/dist/components/tag/types.d.ts +137 -0
- package/dist/components/tag/types.js +1 -0
- package/dist/components/tag-picker/docs/llms.md +298 -0
- package/dist/components/tag-picker/option-group.svelte +51 -0
- package/dist/components/tag-picker/option-group.svelte.d.ts +4 -0
- package/dist/components/tag-picker/option.svelte +82 -0
- package/dist/components/tag-picker/option.svelte.d.ts +4 -0
- package/dist/components/tag-picker/tag-picker.d.ts +2 -0
- package/dist/components/tag-picker/tag-picker.js +2 -0
- package/dist/components/tag-picker/tag-picker.svelte +716 -0
- package/dist/components/tag-picker/tag-picker.svelte.d.ts +21 -0
- package/dist/components/tag-picker/types.d.ts +142 -0
- package/dist/components/tag-picker/types.js +1 -0
- package/dist/components/text-box/docs/llms.md +31 -4
- package/dist/components/text-box/text-box-button.svelte +3 -3
- package/dist/components/text-box/text-box-button.svelte.d.ts +1 -1
- package/dist/components/text-box/text-box.svelte +41 -14
- package/dist/components/text-box/types.d.ts +5 -5
- package/dist/components/textarea/docs/llms.md +4 -3
- package/dist/components/textarea/textarea.svelte +14 -6
- package/dist/components/textarea/types.d.ts +2 -4
- package/dist/components/time-picker/docs/llms.md +18 -15
- package/dist/components/time-picker/time-picker.svelte +133 -33
- package/dist/components/time-picker/time-picker.svelte.d.ts +1 -1
- package/dist/components/time-picker/types.d.ts +23 -13
- package/dist/components/title-bar/docs/llms.md +382 -0
- package/dist/components/title-bar/title-bar-left-controls.svelte +215 -0
- package/dist/components/title-bar/title-bar-left-controls.svelte.d.ts +22 -0
- package/dist/components/title-bar/title-bar-right-controls.svelte +190 -0
- package/dist/components/title-bar/title-bar-right-controls.svelte.d.ts +27 -0
- package/dist/components/title-bar/title-bar.d.ts +3 -0
- package/dist/components/title-bar/title-bar.js +4 -0
- package/dist/components/title-bar/title-bar.svelte +224 -0
- package/dist/components/title-bar/title-bar.svelte.d.ts +26 -0
- package/dist/components/title-bar/types.d.ts +165 -0
- package/dist/components/title-bar/types.js +1 -0
- package/dist/components/toggle-switch/docs/llms.md +11 -9
- package/dist/components/toggle-switch/toggle-switch.svelte +23 -14
- package/dist/components/toggle-switch/toggle-switch.svelte.d.ts +1 -1
- package/dist/components/toggle-switch/types.d.ts +12 -10
- package/dist/components/tooltip/docs/llms.md +1 -1
- package/dist/components/tooltip/tooltip.svelte +5 -4
- package/dist/components/tooltip/types.d.ts +1 -1
- package/dist/components/top-nav/docs/llms.md +1 -1
- package/dist/components/top-nav/top-nav-item.svelte +2 -2
- package/dist/components/top-nav/top-nav.svelte +2 -2
- package/dist/components/top-nav/types.d.ts +2 -2
- package/dist/components/tree-view/docs/llms.md +11 -11
- package/dist/components/tree-view/tree-view-item-content.svelte +3 -3
- package/dist/components/tree-view/tree-view-item.svelte +13 -5
- package/dist/components/tree-view/tree-view.svelte +20 -5
- package/dist/components/tree-view/tree-view.svelte.d.ts +1 -1
- package/dist/components/tree-view/tree-view.svelte.js +31 -3
- package/dist/components/tree-view/types.d.ts +7 -3
- package/dist/index.d.ts +25 -0
- package/dist/index.js +32 -0
- package/dist/internal/components/dynamic-carousel/dynamic-carousel.svelte +26 -5
- package/dist/internal/components/dynamic-carousel/dynamic-carousel.svelte.d.ts +2 -0
- package/dist/internal/constants.d.ts +0 -4
- package/dist/internal/constants.js +0 -4002
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +1 -0
- package/dist/internal/native-field.svelte.d.ts +44 -0
- package/dist/internal/native-field.svelte.js +85 -0
- package/dist/internal/utils.d.ts +16 -2
- package/dist/internal/utils.js +25 -3
- package/dist/types/index.d.ts +3 -3
- package/package.json +51 -37
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
<script lang="ts" generics="Tag extends 'ul' | 'ol' | 'div' = 'ul'">
|
|
2
2
|
import type { ListViewContext, ListViewProps, ListViewDOM } from './types.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
attachTabspot,
|
|
5
|
+
getListViewContext,
|
|
6
|
+
getListViewItemContext,
|
|
7
|
+
getRole,
|
|
8
|
+
LIST_VIEW_SKIP,
|
|
9
|
+
TAG,
|
|
10
|
+
setListViewContext
|
|
11
|
+
} from './utils.js';
|
|
12
|
+
import { getTabspotAttributes, type TabspotNodeOptions } from 'tabspot';
|
|
5
13
|
|
|
6
14
|
let {
|
|
7
15
|
as = 'ul' as Tag,
|
|
8
|
-
ref = $bindable(),
|
|
16
|
+
ref = $bindable(null),
|
|
9
17
|
selectionMode = 'none',
|
|
10
18
|
navigationMode = 'items',
|
|
19
|
+
manageSpecialKeys = true,
|
|
11
20
|
shape = 'rounded',
|
|
12
21
|
selectedItems = $bindable([]),
|
|
13
22
|
onSelectionChange,
|
|
14
23
|
disableTabspot = false,
|
|
15
24
|
toggleOnClick = false,
|
|
16
25
|
children,
|
|
26
|
+
class: classes,
|
|
17
27
|
...attributes
|
|
18
28
|
}: ListViewProps<Tag> = $props();
|
|
19
29
|
|
|
@@ -21,40 +31,69 @@
|
|
|
21
31
|
* The tag the invariant rules over. The markup renders it through here, so it is checked
|
|
22
32
|
* during SSR and on every prop update rather than only once on mount.
|
|
23
33
|
*/
|
|
34
|
+
const itemContext = getListViewItemContext();
|
|
24
35
|
const _as = $derived.by(() => {
|
|
25
36
|
if (!TAG.includes(as)) throw new Error(`Invalid tag: ${as}. Must be one of ${TAG.join(', ')}`);
|
|
37
|
+
if (itemContext?.as === 'a' || itemContext?.as === 'button') {
|
|
38
|
+
throw new Error('Nested ListView must be inside a li or div ListViewItem, outside links and buttons.');
|
|
39
|
+
}
|
|
26
40
|
return as;
|
|
27
41
|
});
|
|
28
42
|
|
|
29
|
-
const
|
|
43
|
+
const parent = getListViewContext();
|
|
44
|
+
const tabspotDisabled = $derived(disableTabspot || !!parent?.config.disableTabspot);
|
|
45
|
+
const ROLE = $derived(attributes.role ?? getRole(as, selectionMode, navigationMode));
|
|
30
46
|
|
|
31
47
|
const MULTISELECTABLE = $derived(selectionMode === 'multiselect' || selectionMode === 'extended');
|
|
32
48
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
const tabspotConfig: TabspotNodeOptions | undefined = $derived(
|
|
50
|
+
tabspotDisabled
|
|
51
|
+
? undefined
|
|
52
|
+
: {
|
|
53
|
+
...(parent
|
|
54
|
+
? { grouper: { enterDirection: 'right', exitDirection: 'left' } }
|
|
55
|
+
: { root: { manageSpecialKeys } }),
|
|
56
|
+
mover: {
|
|
57
|
+
axis: 'vertical',
|
|
58
|
+
items:
|
|
59
|
+
'.fs-list-view-item[data-list-view-interactive], .fs-list-view-item:not([data-list-view-interactive]) :is(a[href], button), .fs-list-view-item-branch-trigger',
|
|
60
|
+
visibilityAware: 'Visible',
|
|
61
|
+
skip: LIST_VIEW_SKIP,
|
|
62
|
+
...(!parent && { activation: { mode: 'focus', roving: navigationMode === 'composite' } })
|
|
63
|
+
}
|
|
42
64
|
}
|
|
43
|
-
})
|
|
44
65
|
);
|
|
66
|
+
const tabspotAttrs = $derived(tabspotConfig && getTabspotAttributes(tabspotConfig));
|
|
45
67
|
|
|
46
68
|
let anchorIndex: number | null = $state(null);
|
|
47
69
|
|
|
48
70
|
let items: {
|
|
49
71
|
id: string;
|
|
50
|
-
value: string;
|
|
51
|
-
disabled: boolean;
|
|
72
|
+
getItem: () => { value: string; disabled: boolean; element: HTMLElement | null };
|
|
52
73
|
}[] = $state([]);
|
|
53
74
|
|
|
75
|
+
// The item that holds the tab stop in the server HTML, before Tabspot runs. Plain, since only the first render reads it.
|
|
76
|
+
let tabStopId: string | null = null;
|
|
77
|
+
|
|
54
78
|
const CONTEXT: ListViewContext = $state({
|
|
55
79
|
config: {
|
|
56
80
|
get shape() {
|
|
57
81
|
return shape;
|
|
82
|
+
},
|
|
83
|
+
get as() {
|
|
84
|
+
return as;
|
|
85
|
+
},
|
|
86
|
+
get selectionMode() {
|
|
87
|
+
return selectionMode;
|
|
88
|
+
},
|
|
89
|
+
get role() {
|
|
90
|
+
return ROLE;
|
|
91
|
+
},
|
|
92
|
+
get disableTabspot() {
|
|
93
|
+
return tabspotDisabled;
|
|
94
|
+
},
|
|
95
|
+
get roving() {
|
|
96
|
+
return !parent && navigationMode === 'composite';
|
|
58
97
|
}
|
|
59
98
|
},
|
|
60
99
|
state: {
|
|
@@ -73,19 +112,27 @@
|
|
|
73
112
|
},
|
|
74
113
|
events: null,
|
|
75
114
|
methods: {
|
|
115
|
+
claimTabStop: (id) => (tabStopId ??= id) === id,
|
|
76
116
|
handleSelection: (e: MouseEvent, value: string, toggle = false) => {
|
|
77
117
|
if (selectionMode === 'none') return;
|
|
78
118
|
|
|
79
|
-
|
|
119
|
+
// Registration order can differ from the DOM after keyed items are reordered.
|
|
120
|
+
const orderedItems = items
|
|
121
|
+
.map((item) => item.getItem())
|
|
122
|
+
.sort((a, b) => {
|
|
123
|
+
if (!a.element || !b.element) return 0;
|
|
124
|
+
return a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
|
|
125
|
+
});
|
|
126
|
+
const itemIndex = orderedItems.findIndex((item) => item.value === value);
|
|
80
127
|
if (itemIndex === -1) return;
|
|
81
128
|
|
|
82
|
-
const item =
|
|
129
|
+
const item = orderedItems[itemIndex];
|
|
83
130
|
if (item.disabled) return;
|
|
84
131
|
|
|
85
132
|
if (selectionMode === 'extended' && e.shiftKey && anchorIndex !== null) {
|
|
86
133
|
const start = Math.min(anchorIndex, itemIndex);
|
|
87
134
|
const end = Math.max(anchorIndex, itemIndex);
|
|
88
|
-
const rangeValues =
|
|
135
|
+
const rangeValues = orderedItems
|
|
89
136
|
.slice(start, end + 1)
|
|
90
137
|
.filter((i) => !i.disabled)
|
|
91
138
|
.map((i) => i.value);
|
|
@@ -101,13 +148,13 @@
|
|
|
101
148
|
}
|
|
102
149
|
onSelectionChange?.(e, selectedItems);
|
|
103
150
|
},
|
|
104
|
-
registerItem: (id
|
|
105
|
-
items.push({ id,
|
|
151
|
+
registerItem: (id, getItem) => {
|
|
152
|
+
items.push({ id, getItem });
|
|
106
153
|
},
|
|
107
154
|
unregisterItem: (id: string) => {
|
|
108
155
|
items = items.filter((item) => item.id !== id);
|
|
109
156
|
},
|
|
110
|
-
getChildrenRole: (_tag: 'li' | 'a' | 'div') => {
|
|
157
|
+
getChildrenRole: (_tag: 'li' | 'a' | 'button' | 'div') => {
|
|
111
158
|
if (ROLE === 'grid') return 'row';
|
|
112
159
|
if (ROLE === 'listbox') return 'option';
|
|
113
160
|
return _tag !== 'li' ? 'listitem' : undefined;
|
|
@@ -120,12 +167,13 @@
|
|
|
120
167
|
|
|
121
168
|
<svelte:element
|
|
122
169
|
this={_as}
|
|
170
|
+
{...attributes}
|
|
123
171
|
bind:this={ref as ListViewDOM[Tag]}
|
|
124
|
-
class=
|
|
172
|
+
class={['fs-list-view', classes]}
|
|
125
173
|
role={ROLE}
|
|
126
|
-
aria-multiselectable={MULTISELECTABLE || undefined}
|
|
174
|
+
aria-multiselectable={((ROLE === 'grid' || ROLE === 'listbox') && MULTISELECTABLE) || undefined}
|
|
127
175
|
{...tabspotAttrs}
|
|
128
|
-
{
|
|
176
|
+
{@attach attachTabspot(tabspotConfig)}
|
|
129
177
|
>
|
|
130
178
|
{@render children?.()}
|
|
131
179
|
</svelte:element>
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { CheckboxProps } from '../checkbox/types.ts';
|
|
2
2
|
import type { FSContext } from '../../internal/index.js';
|
|
3
3
|
import type { PolymorphicProps, Shapes } from '../../types/index.js';
|
|
4
|
+
import type { AriaRole, HTMLAttributes, HTMLButtonAttributes } from 'svelte/elements';
|
|
5
|
+
import type { Component, Snippet } from 'svelte';
|
|
6
|
+
import type { TabspotRootOptions } from 'tabspot';
|
|
4
7
|
export type SelectionMode = 'none' | 'single' | 'multiselect' | 'extended';
|
|
5
8
|
export type NavigationMode = 'items' | 'composite';
|
|
6
9
|
/** @propsmith ListViewProps */
|
|
7
10
|
export type ListViewProps<T extends 'ul' | 'ol' | 'div'> = {
|
|
11
|
+
/** Overrides the list role and the roles derived for its items. Use `list` for nested navigation with independent selection. */
|
|
12
|
+
role?: AriaRole;
|
|
8
13
|
/** How many items can be selected, and how the selection is made.
|
|
9
14
|
* @default 'none'
|
|
10
15
|
*/
|
|
@@ -13,6 +18,11 @@ export type ListViewProps<T extends 'ul' | 'ol' | 'div'> = {
|
|
|
13
18
|
* @default 'items'
|
|
14
19
|
*/
|
|
15
20
|
navigationMode?: NavigationMode;
|
|
21
|
+
/** Which special keys Tabspot handles at the root. Set individual keys to leave Escape to an enclosing panel. Omitted keys in an object are off.
|
|
22
|
+
* @type boolean | TabspotRootOptions['manageSpecialKeys']
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
manageSpecialKeys?: TabspotRootOptions['manageSpecialKeys'];
|
|
16
26
|
/** The values of the selected items.
|
|
17
27
|
* @bindable
|
|
18
28
|
*/
|
|
@@ -36,7 +46,7 @@ export type ListViewProps<T extends 'ul' | 'ol' | 'div'> = {
|
|
|
36
46
|
* @type HTMLUListElement | HTMLOListElement | HTMLDivElement
|
|
37
47
|
* @bindable
|
|
38
48
|
*/
|
|
39
|
-
ref?: ListViewDOM[T];
|
|
49
|
+
ref?: ListViewDOM[T] | null;
|
|
40
50
|
/** Opts the list out of the tabspot focus management, to wire your own.
|
|
41
51
|
* @default false
|
|
42
52
|
*/
|
|
@@ -48,12 +58,14 @@ export type ListViewDOM = {
|
|
|
48
58
|
div: HTMLDivElement;
|
|
49
59
|
};
|
|
50
60
|
/** @propsmith ListViewItemProps */
|
|
51
|
-
export type ListViewItemProps<T extends 'li' | 'a' | 'div' = 'li'> = {
|
|
61
|
+
export type ListViewItemProps<T extends 'li' | 'a' | 'button' | 'div' = 'li'> = {
|
|
52
62
|
/** The HTML element to render the item as.
|
|
53
|
-
*
|
|
63
|
+
* Links and buttons are wrapped in a list item when the list renders as `ul` or `ol`.
|
|
64
|
+
* Use `li` or `div` for nested lists and content with multiple controls. Buttons cannot contain checkmarks or composite rows.
|
|
65
|
+
* @type 'li' | 'a' | 'button' | 'div'
|
|
54
66
|
* @default 'li'
|
|
55
67
|
*/
|
|
56
|
-
as?: T | 'a' | 'div';
|
|
68
|
+
as?: T | 'a' | 'button' | 'div';
|
|
57
69
|
/** The item can have a circular, rounded or square shape. Inherited from the list by default. */
|
|
58
70
|
shape?: Shapes;
|
|
59
71
|
/** The value reported to the list when the item is selected. Falls back to a generated id. */
|
|
@@ -73,18 +85,63 @@ export type ListViewItemProps<T extends 'li' | 'a' | 'div' = 'li'> = {
|
|
|
73
85
|
/** Called when the item receives the focus. */
|
|
74
86
|
onfocus?: (e: Event, value: string) => void;
|
|
75
87
|
/** The DOM reference of the item element.
|
|
76
|
-
* @type HTMLLIElement | HTMLAnchorElement | HTMLDivElement
|
|
88
|
+
* @type HTMLLIElement | HTMLAnchorElement | HTMLButtonElement | HTMLDivElement
|
|
77
89
|
* @bindable
|
|
78
90
|
*/
|
|
79
91
|
ref?: ListViewItemDOM[T] | null;
|
|
80
|
-
} & PolymorphicProps<T>;
|
|
92
|
+
} & PolymorphicProps<T, 'onfocus'>;
|
|
81
93
|
export type ListViewItemDOM = {
|
|
82
94
|
li: HTMLLIElement;
|
|
83
95
|
a: HTMLAnchorElement;
|
|
96
|
+
button: HTMLButtonElement;
|
|
84
97
|
div: HTMLDivElement;
|
|
85
98
|
};
|
|
99
|
+
/** @propsmith ListViewItemBranchProps */
|
|
100
|
+
export type ListViewItemBranchProps = {
|
|
101
|
+
/** The accessible label rendered in the disclosure button. */
|
|
102
|
+
label: string;
|
|
103
|
+
/** The decorative icon before the label.
|
|
104
|
+
* @type Snippet | Component
|
|
105
|
+
*/
|
|
106
|
+
icon?: Snippet | Component;
|
|
107
|
+
/** Whether the nested content is visible. Branches only expand or collapse and are never selectable.
|
|
108
|
+
* @default false
|
|
109
|
+
* @bindable
|
|
110
|
+
*/
|
|
111
|
+
expanded?: boolean;
|
|
112
|
+
/** Called when a user expands or collapses the branch. */
|
|
113
|
+
onExpandedChange?: (e: Event, expanded: boolean) => void;
|
|
114
|
+
/** Disables the disclosure button.
|
|
115
|
+
* @default false
|
|
116
|
+
*/
|
|
117
|
+
disabled?: boolean;
|
|
118
|
+
/** The disclosure button shape. Inherited from the list by default. */
|
|
119
|
+
shape?: Shapes;
|
|
120
|
+
/** The DOM reference of the native disclosure button. Additional HTML attributes, including class and id, also target this button.
|
|
121
|
+
* @type HTMLButtonElement
|
|
122
|
+
* @bindable
|
|
123
|
+
*/
|
|
124
|
+
ref?: HTMLButtonElement | null;
|
|
125
|
+
/** The DOM reference of the wrapper element, the list item that holds the button and the nested list.
|
|
126
|
+
* @type HTMLLIElement | HTMLDivElement
|
|
127
|
+
* @bindable
|
|
128
|
+
*/
|
|
129
|
+
wrapperRef?: HTMLLIElement | HTMLDivElement | null;
|
|
130
|
+
/** The attributes to spread on the wrapper element.
|
|
131
|
+
* @type HTMLAttributes
|
|
132
|
+
*/
|
|
133
|
+
wrapperAttributes?: HTMLAttributes<HTMLLIElement | HTMLDivElement>;
|
|
134
|
+
/** Nested ListView content, kept mounted while collapsed to preserve its selection. */
|
|
135
|
+
children?: Snippet;
|
|
136
|
+
} & Omit<HTMLButtonAttributes, 'children' | 'role' | 'type' | 'value' | 'aria-expanded' | 'aria-controls'>;
|
|
86
137
|
export type ListViewContextConfig = {
|
|
87
138
|
shape: Shapes;
|
|
139
|
+
as: 'ul' | 'ol' | 'div';
|
|
140
|
+
selectionMode: SelectionMode;
|
|
141
|
+
role: AriaRole | undefined;
|
|
142
|
+
disableTabspot: boolean;
|
|
143
|
+
/** Whether the list keeps a single tab stop that the arrow keys move. */
|
|
144
|
+
roving: boolean;
|
|
88
145
|
};
|
|
89
146
|
export type ListViewContextState = {
|
|
90
147
|
selectedItems: string[];
|
|
@@ -92,8 +149,14 @@ export type ListViewContextState = {
|
|
|
92
149
|
};
|
|
93
150
|
export type ListViewContextMethods = {
|
|
94
151
|
handleSelection: (e: MouseEvent, value: string, toggle?: boolean) => void;
|
|
95
|
-
getChildrenRole: (tag: 'li' | 'a' | 'div') => 'listitem' | 'option' | 'row' | undefined;
|
|
96
|
-
registerItem: (id: string,
|
|
152
|
+
getChildrenRole: (tag: 'li' | 'a' | 'button' | 'div') => 'listitem' | 'option' | 'row' | undefined;
|
|
153
|
+
registerItem: (id: string, getItem: () => {
|
|
154
|
+
value: string;
|
|
155
|
+
disabled: boolean;
|
|
156
|
+
element: HTMLElement | null;
|
|
157
|
+
}) => void;
|
|
97
158
|
unregisterItem: (id: string) => void;
|
|
159
|
+
/** True for the first item to ask: it holds the tab stop until Tabspot takes the stop over on mount. */
|
|
160
|
+
claimTabStop: (id: string) => boolean;
|
|
98
161
|
};
|
|
99
162
|
export type ListViewContext = FSContext<ListViewContextConfig, ListViewContextState, null, ListViewContextMethods>;
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import type { ListViewContext, NavigationMode, SelectionMode } from './types.ts';
|
|
2
|
+
import type { Attachment } from 'svelte/attachments';
|
|
3
|
+
import { type TabspotNodeOptions, type TabspotEventListener, type TabspotInstance } from 'tabspot';
|
|
2
4
|
export declare const COMPONENT_NAME = "fslist-view-";
|
|
3
5
|
export declare const TAG: string[];
|
|
4
6
|
export declare const ITEM_TAG: string[];
|
|
7
|
+
export declare const LIST_VIEW_SKIP = "[disabled], [aria-disabled=\"true\"], [hidden], [hidden] *, [inert], [inert] *, [aria-hidden=\"true\"], [aria-hidden=\"true\"] *";
|
|
8
|
+
export declare const getListViewItemContext: () => {
|
|
9
|
+
readonly as: "li" | "a" | "button" | "div";
|
|
10
|
+
} | null, setListViewItemContext: (context: {
|
|
11
|
+
readonly as: "li" | "a" | "button" | "div";
|
|
12
|
+
}) => void;
|
|
13
|
+
/** Register roots mounted after the provider starts, and release managed focus on updates/unmount. */
|
|
14
|
+
export declare function attachTabspot(config: TabspotNodeOptions | undefined, onNavigate?: TabspotEventListener, instance?: TabspotInstance): Attachment<HTMLElement>;
|
|
5
15
|
export declare function getRole(tag: 'ul' | 'ol' | 'div', selectionMode: SelectionMode, navigationMode: NavigationMode): 'grid' | 'listbox' | 'list' | undefined;
|
|
6
16
|
export declare const getListViewContext: () => ListViewContext | null, setListViewContext: (context: ListViewContext) => void;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import { PREFIX } from '../../internal/constants.js';
|
|
2
2
|
import { createFSContext } from '../../internal/index.js';
|
|
3
|
+
import { setTabspotAttributes } from 'tabspot';
|
|
3
4
|
export const COMPONENT_NAME = `${PREFIX}list-view-`;
|
|
4
5
|
export const TAG = ['ul', 'ol', 'div'];
|
|
5
|
-
export const ITEM_TAG = ['li', 'a', 'div'];
|
|
6
|
+
export const ITEM_TAG = ['li', 'a', 'button', 'div'];
|
|
7
|
+
export const LIST_VIEW_SKIP = '[disabled], [aria-disabled="true"], [hidden], [hidden] *, [inert], [inert] *, [aria-hidden="true"], [aria-hidden="true"] *';
|
|
8
|
+
export const [getListViewItemContext, setListViewItemContext] = createFSContext();
|
|
9
|
+
/** Register roots mounted after the provider starts, and release managed focus on updates/unmount. */
|
|
10
|
+
export function attachTabspot(config, onNavigate, instance) {
|
|
11
|
+
return (element) => {
|
|
12
|
+
if (!config)
|
|
13
|
+
return;
|
|
14
|
+
const result = setTabspotAttributes({ element, config });
|
|
15
|
+
const detach = onNavigate && (result.ok ? (result.instance ?? instance) : undefined)?.subscribe(onNavigate);
|
|
16
|
+
return () => {
|
|
17
|
+
detach?.();
|
|
18
|
+
setTabspotAttributes({ element, config: {} });
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
6
22
|
export function getRole(tag, selectionMode, navigationMode) {
|
|
7
23
|
if (selectionMode !== 'none') {
|
|
8
24
|
return navigationMode === 'composite' ? 'grid' : 'listbox';
|
|
@@ -21,6 +21,8 @@ Other components that can be used within the menu include:
|
|
|
21
21
|
- `MenuItemCheckbox`: A menu item that can be checked or unchecked.
|
|
22
22
|
- `MenuItemSwitch`: A menu item that can be toggled on or off.
|
|
23
23
|
- `MenuItemRadio`: A menu item that can be selected as part of a group of radio items.
|
|
24
|
+
- `MenuCommandBar`: A row of icon-only commands placed at the top or at the bottom of the menu, with an optional overflow submenu.
|
|
25
|
+
- `MenuCommandBarItem`: A square, icon-only command of a MenuCommandBar, with a label that names it and shows as its tooltip.
|
|
24
26
|
|
|
25
27
|
## Usage
|
|
26
28
|
|
|
@@ -87,7 +89,7 @@ To correctly attach events to the trigger element, you should wrap the element w
|
|
|
87
89
|
{#snippet children({ state, menuTriggerProps, primaryButtonProps })}
|
|
88
90
|
<SplitButton
|
|
89
91
|
bind:menuTriggerRef={state.ref}
|
|
90
|
-
{menuTriggerProps}
|
|
92
|
+
menuTriggerProps={{ ...menuTriggerProps, 'aria-label': 'More options' }}
|
|
91
93
|
primaryButtonProps={{ onclick: () => alert('Primary action'), ...primaryButtonProps }}
|
|
92
94
|
>
|
|
93
95
|
Primary Action
|
|
@@ -103,6 +105,51 @@ To correctly attach events to the trigger element, you should wrap the element w
|
|
|
103
105
|
</Menu>
|
|
104
106
|
```
|
|
105
107
|
|
|
108
|
+
### Menu with a command bar
|
|
109
|
+
|
|
110
|
+
A command bar flyout pairs a row of square, icon-only primary commands with the items of the menu. Place a `MenuCommandBar` at the top or at the bottom of the `MenuList` and set its `position` to match. Fill it with `MenuCommandBarItem`, each with an `icon` and a `label` that names it and shows as its tooltip. The `overflow` snippet adds a "more" button at the end of the row that opens the secondary commands in a submenu.
|
|
111
|
+
|
|
112
|
+
Left and Right move along the bar. Up and Down move between the bar and the items of the menu.
|
|
113
|
+
|
|
114
|
+
```svelte
|
|
115
|
+
<Menu>
|
|
116
|
+
<MenuTrigger>
|
|
117
|
+
{#snippet children({ state, menuTriggerProps })}
|
|
118
|
+
<Button bind:ref={state.ref} {...menuTriggerProps}>Commands on top</Button>
|
|
119
|
+
{/snippet}
|
|
120
|
+
</MenuTrigger>
|
|
121
|
+
<MenuPopover>
|
|
122
|
+
<MenuList>
|
|
123
|
+
<!-- position="bottom" when the bar comes after the items -->
|
|
124
|
+
<MenuCommandBar>
|
|
125
|
+
<MenuCommandBarItem icon={CutRegular} label="Cut" />
|
|
126
|
+
<MenuCommandBarItem icon={CopyRegular} label="Copy" />
|
|
127
|
+
<MenuCommandBarItem icon={ClipboardPasteRegular} label="Paste" />
|
|
128
|
+
{#snippet overflow()}
|
|
129
|
+
<MenuItem>Select all</MenuItem>
|
|
130
|
+
<MenuItem>Rename</MenuItem>
|
|
131
|
+
{/snippet}
|
|
132
|
+
</MenuCommandBar>
|
|
133
|
+
<MenuItem>Open</MenuItem>
|
|
134
|
+
<MenuItem>Open with</MenuItem>
|
|
135
|
+
<MenuItem>Properties</MenuItem>
|
|
136
|
+
</MenuList>
|
|
137
|
+
</MenuPopover>
|
|
138
|
+
</Menu>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
By default every command is a square that shows only its icon. `showLabels` shows the label of every command below its icon, and `showDividers` draws a divider between every two commands; with either of them the commands share the width of the bar evenly.
|
|
142
|
+
|
|
143
|
+
```svelte
|
|
144
|
+
<MenuCommandBar showLabels showDividers>
|
|
145
|
+
<MenuCommandBarItem icon={CutRegular} label="Cut" />
|
|
146
|
+
<MenuCommandBarItem icon={CopyRegular} label="Copy" />
|
|
147
|
+
<MenuCommandBarItem icon={EditRegular} label="Rename" />
|
|
148
|
+
<MenuCommandBarItem icon={ShareRegular} label="Share" />
|
|
149
|
+
<MenuCommandBarItem icon={DeleteRegular} label="Delete" />
|
|
150
|
+
</MenuCommandBar>
|
|
151
|
+
```
|
|
152
|
+
|
|
106
153
|
## Context Menu
|
|
107
154
|
|
|
108
155
|
This variant of the `MenuTrigger` component allows you to create context menus that open on right-click. You can specify the element to which the context menu should be attached using the `ref` prop. If no element is provided, it will attach to the `document.body` by default.
|
|
@@ -147,8 +194,8 @@ This variant of the `MenuTrigger` component allows you to create context menus t
|
|
|
147
194
|
|
|
148
195
|
| Name | Type | Default | Description |
|
|
149
196
|
| ----------------- | ------------------------------------ | ------- | -------------------------------------------------------- |
|
|
150
|
-
| `ref` | `HTMLElement`
|
|
151
|
-
| `open` _bindable_ | `boolean`
|
|
197
|
+
| `ref` | `HTMLElement` | `null` | | The element used to position the popover. |
|
|
198
|
+
| `open` _bindable_ | `boolean` | `null` | | Controls the open state of the popover. |
|
|
152
199
|
| `keepMounted` | `boolean` | `false` | Keeps the popover mounted in the DOM while it is closed. |
|
|
153
200
|
| `placement` | `ComputePositionConfig['placement']` | | Where the popover is positioned relative to its trigger. |
|
|
154
201
|
| `positionConfig` | `ComputePositionConfig` | | The position configuration handed over to floating-ui. |
|
|
@@ -190,13 +237,13 @@ This variant of the `MenuTrigger` component allows you to create context menus t
|
|
|
190
237
|
<!-- DO NOT EDIT THIS SECTION (propsmith generated) -->
|
|
191
238
|
<!-- props:MenuItemActionableProps -->
|
|
192
239
|
|
|
193
|
-
| Name
|
|
194
|
-
|
|
|
195
|
-
| `checked` _bindable_
|
|
196
|
-
| `value`
|
|
197
|
-
| `name`
|
|
198
|
-
| `MenuItemProps` without `href`
|
|
199
|
-
| `
|
|
240
|
+
| Name | Type | Default | Description |
|
|
241
|
+
| ------------------------------ | ----------------------- | ------- | ------------------------------------------------------------------------------------------ |
|
|
242
|
+
| `checked` _bindable_ | `boolean` | `null` | | Whether the item is checked. |
|
|
243
|
+
| `value` | `string` | `id` | The value reported to the menu when the item is checked. Falls back to the id of the item. |
|
|
244
|
+
| `name` | `string` | `id` | The group of items this one belongs to. Falls back to the id of the item. |
|
|
245
|
+
| `MenuItemProps` without `href` | | | |
|
|
246
|
+
| `ButtonProps<'button'>` | | | |
|
|
200
247
|
|
|
201
248
|
<!-- /props:MenuItemActionableProps -->
|
|
202
249
|
|
|
@@ -205,10 +252,46 @@ This variant of the `MenuTrigger` component allows you to create context menus t
|
|
|
205
252
|
<!-- DO NOT EDIT THIS SECTION (propsmith generated) -->
|
|
206
253
|
<!-- props:MenuGroupProps -->
|
|
207
254
|
|
|
208
|
-
| Name | Type
|
|
209
|
-
| ---------------- |
|
|
210
|
-
| `ref` _bindable_ | `HTMLDivElement` | | The DOM reference of the group element. |
|
|
211
|
-
| `header` | `string`
|
|
212
|
-
| `children` | `Snippet`
|
|
255
|
+
| Name | Type | Default | Description |
|
|
256
|
+
| ---------------- | ------------------------------ | ------- | --------------------------------------- |
|
|
257
|
+
| `ref` _bindable_ | `HTMLDivElement` | `null` | | The DOM reference of the group element. |
|
|
258
|
+
| `header` | `string` | | The label of the group. |
|
|
259
|
+
| `children` | `Snippet` | | The items of the group. |
|
|
213
260
|
|
|
214
261
|
<!-- /props:MenuGroupProps -->
|
|
262
|
+
|
|
263
|
+
## Component Props (MenuCommandBar)
|
|
264
|
+
|
|
265
|
+
<!-- DO NOT EDIT THIS SECTION (propsmith generated) -->
|
|
266
|
+
<!-- props:MenuCommandBarProps -->
|
|
267
|
+
|
|
268
|
+
| Name | Type | Default | Description |
|
|
269
|
+
| ----------------------------------------------------------- | ------------------------------ | ---------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
270
|
+
| `ref` _bindable_ | `HTMLDivElement` | `null` | | The DOM reference of the command bar element. |
|
|
271
|
+
| `position` | `'top'` | `'bottom'` | `'top'` | Where the bar sits in the menu. A bar at the top has its divider below it, and one at the bottom has it above. |
|
|
272
|
+
| `label` | `string` | `'Commands'` | The accessible name of the group of commands. |
|
|
273
|
+
| `overflowLabel` | `string` | `'More options'` | The accessible name of the button that opens the overflow. |
|
|
274
|
+
| `overflow` | `Snippet` | | The secondary commands. When present, a "more" button at the end of the bar opens them in a submenu. |
|
|
275
|
+
| `showLabels` | `boolean` | `false` | Shows the label of every command below its icon. Without labels, every command is a square. |
|
|
276
|
+
| `showDividers` | `boolean` | `false` | Draws a divider between every two commands. |
|
|
277
|
+
| `children` | `Snippet` | | The primary commands, as `MenuCommandBarItem`s. |
|
|
278
|
+
| `HTMLAttributes<HTMLDivElement>` without `children`, `role` | | | |
|
|
279
|
+
|
|
280
|
+
<!-- /props:MenuCommandBarProps -->
|
|
281
|
+
|
|
282
|
+
## Component Props (MenuCommandBarItem)
|
|
283
|
+
|
|
284
|
+
<!-- DO NOT EDIT THIS SECTION (propsmith generated) -->
|
|
285
|
+
<!-- props:MenuCommandBarItemProps -->
|
|
286
|
+
|
|
287
|
+
| Name | Type | Default | Description |
|
|
288
|
+
| --------------------------------------------------------------------------- | --------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
289
|
+
| `ref` _bindable_ | `HTMLButtonElement` | `null` | | The DOM reference of the button element. |
|
|
290
|
+
| `icon` | `Snippet` | `Component` | | The icon of the command. |
|
|
291
|
+
| `label` | `string` | | The name of the command. Without visible labels it is the accessible name of the button and shows as its tooltip; with them it shows below the icon. |
|
|
292
|
+
| `disabled` | `boolean` | | Disables the user interaction. |
|
|
293
|
+
| `onclick` | `(e: MouseEvent) => void` | | Called when the command is activated. The menu closes afterwards, unless it persists on item activation. |
|
|
294
|
+
| `AriaAttributes` without `aria-label` | | | |
|
|
295
|
+
| `id`, `class`, `onkeydown`, `onfocus`, `onblur` from `HTMLButtonAttributes` | | | |
|
|
296
|
+
|
|
297
|
+
<!-- /props:MenuCommandBarItemProps -->
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Button } from '../../index.js';
|
|
3
|
+
import { RenderSoC } from '../../internal/index.js';
|
|
4
|
+
import { getMenuCommandBarContext, getMenuContext, COMPONENT_NAME as MENU_COMPONENT_NAME } from './menu.svelte.js';
|
|
5
|
+
import type { MenuCommandBarItemProps } from './types.js';
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
ref = $bindable(null),
|
|
9
|
+
icon,
|
|
10
|
+
label,
|
|
11
|
+
disabled,
|
|
12
|
+
onclick,
|
|
13
|
+
class: classes,
|
|
14
|
+
...attributes
|
|
15
|
+
}: MenuCommandBarItemProps = $props();
|
|
16
|
+
|
|
17
|
+
const context = getMenuContext();
|
|
18
|
+
|
|
19
|
+
if (!context) throw new Error(`No MenuContext found for ${MENU_COMPONENT_NAME}.`);
|
|
20
|
+
|
|
21
|
+
const { toggle } = context.methods;
|
|
22
|
+
|
|
23
|
+
const commandBarContext = getMenuCommandBarContext();
|
|
24
|
+
|
|
25
|
+
// A visible label names the button itself, a hidden one names it and shows as its tooltip.
|
|
26
|
+
const showLabel = $derived(!!commandBarContext?.showLabels);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<!--
|
|
30
|
+
@component
|
|
31
|
+
|
|
32
|
+
A command of a `MenuCommandBar`: a square icon whose label names it and shows as its tooltip, or the icon with the label below it when the bar shows labels.
|
|
33
|
+
|
|
34
|
+
- Usage:
|
|
35
|
+
```tsx
|
|
36
|
+
<MenuCommandBar>
|
|
37
|
+
<MenuCommandBarItem icon={CutRegular} label="Cut" onclick={cut} />
|
|
38
|
+
</MenuCommandBar>
|
|
39
|
+
```
|
|
40
|
+
-->
|
|
41
|
+
<Button
|
|
42
|
+
{...attributes}
|
|
43
|
+
bind:ref
|
|
44
|
+
{disabled}
|
|
45
|
+
role="menuitem"
|
|
46
|
+
appearance="subtle"
|
|
47
|
+
aria-label={showLabel ? undefined : label}
|
|
48
|
+
title={showLabel ? undefined : label}
|
|
49
|
+
class={['fs-menu-command-bar-item', classes]}
|
|
50
|
+
onclick={(e: MouseEvent) => {
|
|
51
|
+
if (disabled) return;
|
|
52
|
+
onclick?.(e);
|
|
53
|
+
if (!context.config.persistOnItemActivation) toggle(e);
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
<RenderSoC SoC={icon} args={{ class: 'fs-menu-command-bar-item-icon' }} />
|
|
57
|
+
{#if showLabel}
|
|
58
|
+
<span class="fs-menu-command-bar-item-label">{label}</span>
|
|
59
|
+
{/if}
|
|
60
|
+
</Button>
|
|
61
|
+
<!-- The layout is drawn by MenuCommandBar, which styles the overflow button the same way. -->
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MenuCommandBarItemProps } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* A command of a `MenuCommandBar`: a square icon whose label names it and shows as its tooltip, or the icon with the label below it when the bar shows labels.
|
|
4
|
+
*
|
|
5
|
+
* - Usage:
|
|
6
|
+
* ```tsx
|
|
7
|
+
* <MenuCommandBar>
|
|
8
|
+
* <MenuCommandBarItem icon={CutRegular} label="Cut" onclick={cut} />
|
|
9
|
+
* </MenuCommandBar>
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
declare const MenuCommandBarItem: import("svelte").Component<MenuCommandBarItemProps, {}, "ref">;
|
|
13
|
+
type MenuCommandBarItem = ReturnType<typeof MenuCommandBarItem>;
|
|
14
|
+
export default MenuCommandBarItem;
|