fluentui-svelte 0.2.1 → 0.4.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/breadcrumb/breadcrumb-button.svelte +130 -0
- package/dist/components/breadcrumb/breadcrumb-button.svelte.d.ts +35 -0
- package/dist/components/breadcrumb/breadcrumb-divider.svelte +39 -0
- package/dist/components/breadcrumb/breadcrumb-divider.svelte.d.ts +14 -0
- package/dist/components/breadcrumb/breadcrumb-item.svelte +30 -0
- package/dist/components/breadcrumb/breadcrumb-item.svelte.d.ts +16 -0
- package/dist/components/breadcrumb/breadcrumb.svelte +101 -0
- package/dist/components/breadcrumb/breadcrumb.svelte.d.ts +25 -0
- package/dist/components/breadcrumb/docs/llms.md +193 -0
- package/dist/components/breadcrumb/types.d.ts +80 -0
- package/dist/components/breadcrumb/types.js +1 -0
- package/dist/components/tab-view/docs/llms.md +146 -0
- package/dist/components/tab-view/tab-view-tab.svelte +290 -0
- package/dist/components/tab-view/tab-view-tab.svelte.d.ts +20 -0
- package/dist/components/tab-view/tab-view.svelte +188 -0
- package/dist/components/tab-view/tab-view.svelte.d.ts +26 -0
- package/dist/components/tab-view/tab-view.svelte.js +15 -0
- package/dist/components/tab-view/types.d.ts +79 -0
- package/dist/components/tab-view/types.js +1 -0
- package/dist/components/table/docs/llms.md +531 -0
- package/dist/components/table/table-body.svelte +31 -0
- package/dist/components/table/table-body.svelte.d.ts +25 -0
- package/dist/components/table/table-cell-actions.svelte +48 -0
- package/dist/components/table/table-cell-actions.svelte.d.ts +17 -0
- package/dist/components/table/table-cell-layout.svelte +88 -0
- package/dist/components/table/table-cell-layout.svelte.d.ts +14 -0
- package/dist/components/table/table-cell.svelte +74 -0
- package/dist/components/table/table-cell.svelte.d.ts +25 -0
- package/dist/components/table/table-header-cell.svelte +257 -0
- package/dist/components/table/table-header-cell.svelte.d.ts +25 -0
- package/dist/components/table/table-header.svelte +28 -0
- package/dist/components/table/table-header.svelte.d.ts +25 -0
- package/dist/components/table/table-row.svelte +57 -0
- package/dist/components/table/table-row.svelte.d.ts +25 -0
- package/dist/components/table/table-selection-cell.svelte +89 -0
- package/dist/components/table/table-selection-cell.svelte.d.ts +25 -0
- package/dist/components/table/table.svelte +189 -0
- package/dist/components/table/table.svelte.d.ts +49 -0
- package/dist/components/table/table.svelte.js +138 -0
- package/dist/components/table/types.d.ts +287 -0
- package/dist/components/table/types.js +1 -0
- package/dist/components/top-nav/docs/llms.md +176 -0
- package/dist/components/top-nav/top-nav-item.svelte +234 -0
- package/dist/components/top-nav/top-nav-item.svelte.d.ts +41 -0
- package/dist/components/top-nav/top-nav.svelte +259 -0
- package/dist/components/top-nav/top-nav.svelte.d.ts +26 -0
- package/dist/components/top-nav/top-nav.svelte.js +18 -0
- package/dist/components/top-nav/types.d.ts +89 -0
- package/dist/components/top-nav/types.js +1 -0
- package/dist/css/class-darkmode.css +1 -1
- package/dist/css/media-darkmode.css +1 -1
- package/dist/css/theme.css +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.js +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import type { FSContext } from '../../internal/index.js';
|
|
2
|
+
import type { PolymorphicProps } from '../../types/index.js';
|
|
3
|
+
import type { Component, Snippet } from 'svelte';
|
|
4
|
+
import type { CheckboxProps } from '../checkbox/types.ts';
|
|
5
|
+
import type { RadioButtonProps } from '../radio-button/types.ts';
|
|
6
|
+
export type TableSize = 'extra-small' | 'small' | 'medium';
|
|
7
|
+
export type CellFocusMode = 'cell' | 'group' | 'none';
|
|
8
|
+
export type TableRowAppearance = 'none' | 'brand' | 'neutral';
|
|
9
|
+
export type SortDirection = 'ascending' | 'descending';
|
|
10
|
+
export type SelectionType = 'checkbox' | 'radio';
|
|
11
|
+
export type TableDOM = {
|
|
12
|
+
table: HTMLTableElement;
|
|
13
|
+
thead: HTMLTableSectionElement;
|
|
14
|
+
tbody: HTMLTableSectionElement;
|
|
15
|
+
tr: HTMLTableRowElement;
|
|
16
|
+
th: HTMLTableCellElement;
|
|
17
|
+
td: HTMLTableCellElement;
|
|
18
|
+
div: HTMLDivElement;
|
|
19
|
+
};
|
|
20
|
+
/** @propsmith TableProps */
|
|
21
|
+
export type TableProps<Tag extends 'table' | 'div' = 'table'> = {
|
|
22
|
+
/** The HTML element to render the table as. Defaults to a `div` when `noNativeElements` is set.
|
|
23
|
+
* @type 'table' | 'div'
|
|
24
|
+
* @default 'table'
|
|
25
|
+
*/
|
|
26
|
+
as?: Tag;
|
|
27
|
+
/** The DOM reference of the table element.
|
|
28
|
+
* @type HTMLTableElement | HTMLDivElement
|
|
29
|
+
* @bindable
|
|
30
|
+
*/
|
|
31
|
+
ref?: TableDOM[Tag] | HTMLDivElement;
|
|
32
|
+
/** Affects the sizes of all table subcomponents.
|
|
33
|
+
* @default 'medium'
|
|
34
|
+
*/
|
|
35
|
+
size?: TableSize;
|
|
36
|
+
/** Renders every table part as a `div` instead of a semantic table element. The layout switches
|
|
37
|
+
* from `display: table` to `display: flex`, which virtualization and sticky headers need.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
noNativeElements?: boolean;
|
|
41
|
+
/** Turns every header cell into a sort button. Individual cells can still opt in on their own.
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
sortable?: boolean;
|
|
45
|
+
/** Drops the line that separates one row from the next.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
noRowBorders?: boolean;
|
|
49
|
+
/** Moves the focus between cells with the arrow keys, through a single tab stop. It also
|
|
50
|
+
* switches the table over to the `role="grid"` pattern, which that navigation requires.
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
enableTabspot?: boolean;
|
|
54
|
+
/** Lets the arrow keys reach rows a windowed list has not rendered. Only read when
|
|
55
|
+
* `enableTabspot` is set, and the rows need an `aria-rowindex` for it to find them again.
|
|
56
|
+
* @type TableVirtualizer
|
|
57
|
+
*/
|
|
58
|
+
virtualizer?: TableVirtualizer;
|
|
59
|
+
/** Gives every header cell a handle that drags its column wider or narrower. It also pins the
|
|
60
|
+
* table to a fixed layout, so a column keeps the width it was given.
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
resizableColumns?: boolean;
|
|
64
|
+
/** The width of each column in pixels, by column position. Columns left out keep their own size.
|
|
65
|
+
* @bindable
|
|
66
|
+
*/
|
|
67
|
+
columnWidths?: number[];
|
|
68
|
+
/** Per column limits, by column position.
|
|
69
|
+
* @type ColumnSizing[]
|
|
70
|
+
*/
|
|
71
|
+
columnSizing?: ColumnSizing[];
|
|
72
|
+
/** Called whenever a column is dragged or nudged to a new width.
|
|
73
|
+
* @type (e: Event, data: { index: number; width: number }) => void
|
|
74
|
+
*/
|
|
75
|
+
onColumnResize?: (e: Event, data: {
|
|
76
|
+
index: number;
|
|
77
|
+
width: number;
|
|
78
|
+
}) => void;
|
|
79
|
+
} & PolymorphicProps<Tag>;
|
|
80
|
+
export type ColumnSizing = {
|
|
81
|
+
/** Narrowest the column may be dragged, in pixels.
|
|
82
|
+
* @default 40
|
|
83
|
+
*/
|
|
84
|
+
minWidth?: number;
|
|
85
|
+
/** Width the column starts at, in pixels. Without it the browser sizes the column. */
|
|
86
|
+
defaultWidth?: number;
|
|
87
|
+
};
|
|
88
|
+
export type TableVirtualizer = {
|
|
89
|
+
/** Total number of real rows, the whole data set rather than the rendered window. */
|
|
90
|
+
size: number;
|
|
91
|
+
/** Scroll so the row at `index` renders. May be async. */
|
|
92
|
+
scrollToIndex?: (index: number) => void | Promise<void>;
|
|
93
|
+
};
|
|
94
|
+
/** @propsmith TableHeaderProps */
|
|
95
|
+
export type TableHeaderProps<Tag extends 'thead' | 'div' = 'thead'> = {
|
|
96
|
+
/** The HTML element to render the header as. Inherited from the table by default.
|
|
97
|
+
* @type 'thead' | 'div'
|
|
98
|
+
* @default 'thead'
|
|
99
|
+
*/
|
|
100
|
+
as?: Tag;
|
|
101
|
+
/** The DOM reference of the header element.
|
|
102
|
+
* @type HTMLTableSectionElement | HTMLDivElement
|
|
103
|
+
* @bindable
|
|
104
|
+
*/
|
|
105
|
+
ref?: TableDOM[Tag] | HTMLDivElement;
|
|
106
|
+
} & PolymorphicProps<Tag>;
|
|
107
|
+
/** @propsmith TableHeaderCellProps */
|
|
108
|
+
export type TableHeaderCellProps<Tag extends 'th' | 'div' = 'th'> = {
|
|
109
|
+
/** The HTML element to render the header cell as. Inherited from the table by default.
|
|
110
|
+
* @type 'th' | 'div'
|
|
111
|
+
* @default 'th'
|
|
112
|
+
*/
|
|
113
|
+
as?: Tag;
|
|
114
|
+
/** The DOM reference of the header cell element.
|
|
115
|
+
* @type HTMLTableCellElement | HTMLDivElement
|
|
116
|
+
* @bindable
|
|
117
|
+
*/
|
|
118
|
+
ref?: TableDOM[Tag] | HTMLDivElement;
|
|
119
|
+
/** Whether the column is sortable. Inherited from the table by default. */
|
|
120
|
+
sortable?: boolean;
|
|
121
|
+
/** The direction the column is currently sorted in. Also sets `aria-sort`. */
|
|
122
|
+
sortDirection?: SortDirection;
|
|
123
|
+
/** The indicator rendered next to the label of a sortable column.
|
|
124
|
+
* @type Snippet | Component
|
|
125
|
+
*/
|
|
126
|
+
sortIcon?: Snippet<[{
|
|
127
|
+
class: string;
|
|
128
|
+
}]> | Component<{
|
|
129
|
+
class: string;
|
|
130
|
+
}>;
|
|
131
|
+
/** Content placed after the label, outside the sort button.
|
|
132
|
+
* @type Snippet | Component
|
|
133
|
+
*/
|
|
134
|
+
aside?: Snippet<[{
|
|
135
|
+
class: string;
|
|
136
|
+
}]> | Component<{
|
|
137
|
+
class: string;
|
|
138
|
+
}>;
|
|
139
|
+
/** How the arrow keys treat the cell. `'group'` holds the focusable content of the cell out of
|
|
140
|
+
* the tab order until `Enter` steps in, and `Escape` steps back out. `'none'` skips the cell
|
|
141
|
+
* altogether. Only read when the table sets `enableTabspot`. A resizable header cell defaults to
|
|
142
|
+
* `'group'`, so the arrows reach its handle instead of leaving the column behind.
|
|
143
|
+
* @default 'cell'
|
|
144
|
+
*/
|
|
145
|
+
focusMode?: CellFocusMode;
|
|
146
|
+
/** Whether the column can be resized. Inherited from the table by default. */
|
|
147
|
+
resizable?: boolean;
|
|
148
|
+
/** The accessible name of the resize handle. Give it a translated, and ideally per column, string
|
|
149
|
+
* — the attributes of the cell reach the cell, never the handle inside it.
|
|
150
|
+
* @default 'Resize column'
|
|
151
|
+
*/
|
|
152
|
+
resizeLabel?: string;
|
|
153
|
+
} & PolymorphicProps<Tag>;
|
|
154
|
+
/** @propsmith TableBodyProps */
|
|
155
|
+
export type TableBodyProps<Tag extends 'tbody' | 'div' = 'tbody'> = {
|
|
156
|
+
/** The HTML element to render the body as. Inherited from the table by default.
|
|
157
|
+
* @type 'tbody' | 'div'
|
|
158
|
+
* @default 'tbody'
|
|
159
|
+
*/
|
|
160
|
+
as?: Tag;
|
|
161
|
+
/** The DOM reference of the body element.
|
|
162
|
+
* @type HTMLTableSectionElement | HTMLDivElement
|
|
163
|
+
* @bindable
|
|
164
|
+
*/
|
|
165
|
+
ref?: TableDOM[Tag] | HTMLDivElement;
|
|
166
|
+
} & PolymorphicProps<Tag>;
|
|
167
|
+
/** @propsmith TableRowProps */
|
|
168
|
+
export type TableRowProps<Tag extends 'tr' | 'div' = 'tr'> = {
|
|
169
|
+
/** The HTML element to render the row as. Inherited from the table by default.
|
|
170
|
+
* @type 'tr' | 'div'
|
|
171
|
+
* @default 'tr'
|
|
172
|
+
*/
|
|
173
|
+
as?: Tag;
|
|
174
|
+
/** The DOM reference of the row element.
|
|
175
|
+
* @type HTMLTableRowElement | HTMLDivElement
|
|
176
|
+
* @bindable
|
|
177
|
+
*/
|
|
178
|
+
ref?: TableDOM[Tag] | HTMLDivElement;
|
|
179
|
+
/** How the row is filled. Intended to mark a selected row.
|
|
180
|
+
* @default 'none'
|
|
181
|
+
*/
|
|
182
|
+
appearance?: TableRowAppearance;
|
|
183
|
+
} & PolymorphicProps<Tag>;
|
|
184
|
+
/** @propsmith TableCellProps */
|
|
185
|
+
export type TableCellProps<Tag extends 'td' | 'div' = 'td'> = {
|
|
186
|
+
/** The HTML element to render the cell as. Inherited from the table by default.
|
|
187
|
+
* @type 'td' | 'div'
|
|
188
|
+
* @default 'td'
|
|
189
|
+
*/
|
|
190
|
+
as?: Tag;
|
|
191
|
+
/** The DOM reference of the cell element.
|
|
192
|
+
* @type HTMLTableCellElement | HTMLDivElement
|
|
193
|
+
* @bindable
|
|
194
|
+
*/
|
|
195
|
+
ref?: TableDOM[Tag] | HTMLDivElement;
|
|
196
|
+
/** How the arrow keys treat the cell. `'group'` holds the focusable content of the cell out of
|
|
197
|
+
* the tab order until `Enter` steps in, and `Escape` steps back out. `'none'` skips the cell
|
|
198
|
+
* altogether. Only read when the table sets `enableTabspot`.
|
|
199
|
+
* @default 'cell'
|
|
200
|
+
*/
|
|
201
|
+
focusMode?: CellFocusMode;
|
|
202
|
+
} & PolymorphicProps<Tag>;
|
|
203
|
+
/** @propsmith TableSelectionCellProps */
|
|
204
|
+
export type TableSelectionCellProps<Tag extends 'td' | 'div' = 'td'> = {
|
|
205
|
+
/** The HTML element to render the cell as. Inherited from the table by default.
|
|
206
|
+
* @type 'td' | 'div'
|
|
207
|
+
* @default 'td'
|
|
208
|
+
*/
|
|
209
|
+
as?: Tag;
|
|
210
|
+
/** The DOM reference of the cell element.
|
|
211
|
+
* @type HTMLTableCellElement | HTMLDivElement
|
|
212
|
+
* @bindable
|
|
213
|
+
*/
|
|
214
|
+
ref?: TableDOM[Tag] | HTMLDivElement;
|
|
215
|
+
/** A table can have two kinds of selection modes.
|
|
216
|
+
* @default 'checkbox'
|
|
217
|
+
*/
|
|
218
|
+
type?: SelectionType;
|
|
219
|
+
/** Whether the row is selected. `'mixed'` renders the indeterminate state.
|
|
220
|
+
* @type boolean | 'mixed'
|
|
221
|
+
* @default false
|
|
222
|
+
*/
|
|
223
|
+
checked?: boolean | 'mixed';
|
|
224
|
+
/** Only shows the indicator when it is checked, or the row is hovered or focused.
|
|
225
|
+
* @default false
|
|
226
|
+
*/
|
|
227
|
+
subtle?: boolean;
|
|
228
|
+
/** Hides the indicator while it keeps taking up the same space.
|
|
229
|
+
* @default false
|
|
230
|
+
*/
|
|
231
|
+
invisible?: boolean;
|
|
232
|
+
/** The props to spread on the checkbox rendered when `type` is `'checkbox'`.
|
|
233
|
+
* @type CheckboxProps
|
|
234
|
+
*/
|
|
235
|
+
checkboxIndicator?: Omit<CheckboxProps<'div'>, 'wrapperAs' | 'checked' | 'indeterminate' | 'children'>;
|
|
236
|
+
/** The props to spread on the radio button rendered when `type` is `'radio'`.
|
|
237
|
+
* @type RadioButtonProps
|
|
238
|
+
*/
|
|
239
|
+
radioIndicator?: Omit<RadioButtonProps, 'checked' | 'group'>;
|
|
240
|
+
} & PolymorphicProps<Tag>;
|
|
241
|
+
/** @propsmith TableCellLayoutProps */
|
|
242
|
+
export type TableCellLayoutProps = {
|
|
243
|
+
/** The DOM reference of the layout element.
|
|
244
|
+
* @bindable
|
|
245
|
+
*/
|
|
246
|
+
ref?: HTMLDivElement;
|
|
247
|
+
/** An icon, an avatar or any other visual element placed before the main content.
|
|
248
|
+
* @type Snippet | Component
|
|
249
|
+
*/
|
|
250
|
+
media?: Snippet<[{
|
|
251
|
+
class: string;
|
|
252
|
+
}]> | Component<{
|
|
253
|
+
class: string;
|
|
254
|
+
}>;
|
|
255
|
+
/** A second line of text that describes or complements the main content. */
|
|
256
|
+
description?: string;
|
|
257
|
+
/** Emphasizes the cell by enlarging the media and bolding the main content. */
|
|
258
|
+
appearance?: 'primary';
|
|
259
|
+
/** Clips the content with an ellipsis instead of letting it wrap. */
|
|
260
|
+
truncate?: boolean;
|
|
261
|
+
} & PolymorphicProps<'div'>;
|
|
262
|
+
/** @propsmith TableCellActionsProps */
|
|
263
|
+
export type TableCellActionsProps = {
|
|
264
|
+
/** The DOM reference of the actions element.
|
|
265
|
+
* @bindable
|
|
266
|
+
*/
|
|
267
|
+
ref?: HTMLDivElement;
|
|
268
|
+
/** Keeps the actions on screen instead of waiting for the row to be hovered or focused. */
|
|
269
|
+
visible?: boolean;
|
|
270
|
+
} & PolymorphicProps<'div'>;
|
|
271
|
+
export type TableContextConfig = {
|
|
272
|
+
size: TableSize;
|
|
273
|
+
noNativeElements: boolean;
|
|
274
|
+
sortable: boolean;
|
|
275
|
+
enableTabspot: boolean;
|
|
276
|
+
resizableColumns: boolean;
|
|
277
|
+
};
|
|
278
|
+
export type TableContextState = {
|
|
279
|
+
columnWidths: number[];
|
|
280
|
+
};
|
|
281
|
+
export type TableContextMethods = {
|
|
282
|
+
/** The width a column should render at, or `undefined` to let the browser decide. */
|
|
283
|
+
getColumnWidth: (index: number) => number | undefined;
|
|
284
|
+
/** Records a new width for a column, clamped to the minimum it was given. */
|
|
285
|
+
resizeColumn: (e: Event, index: number, width: number) => void;
|
|
286
|
+
};
|
|
287
|
+
export type TableContext = FSContext<TableContextConfig, TableContextState, null, TableContextMethods>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# TopNav
|
|
2
|
+
|
|
3
|
+
TopNav gives a single selection from a row of items, with a bar that marks the selected one. Each item carries a short label and often an icon.
|
|
4
|
+
|
|
5
|
+
The bar belongs to the strip rather than to any one item: when the selection moves it travels to the item that took it, staying on screen the whole way instead of disappearing from one and reappearing under the next.
|
|
6
|
+
|
|
7
|
+
The strip owns the selection and nothing else. What an item opens is rendered by you, wherever it belongs on the page, so an item can open a panel underneath it, swap a region somewhere else, or drive a route.
|
|
8
|
+
|
|
9
|
+
To create a top nav, you will need to use the following components:
|
|
10
|
+
|
|
11
|
+
- `TopNav`: The root component that creates the context every item reads: which item is selected, the appearance, the size and the axis. It renders the `tablist` and the bar that travels across it.
|
|
12
|
+
- `TopNavItem`: A single item of the strip. It reports its own selection and can carry an icon.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
A top nav expects a `value` on every item and a `selectedValue` to match it against. Bind `selectedValue` to follow the selection, and render whatever the selected item opens yourself.
|
|
17
|
+
|
|
18
|
+
```svelte
|
|
19
|
+
<script>
|
|
20
|
+
import { TopNav, TopNavItem } from 'fluentui-svelte';
|
|
21
|
+
|
|
22
|
+
let selectedValue = $state('arrivals');
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<TopNav bind:selectedValue aria-label="Flights">
|
|
26
|
+
<TopNavItem id="tab-arrivals" value="arrivals">Arrivals</TopNavItem>
|
|
27
|
+
<TopNavItem id="tab-departures" value="departures">Departures</TopNavItem>
|
|
28
|
+
</TopNav>
|
|
29
|
+
|
|
30
|
+
{#if selectedValue === 'arrivals'}
|
|
31
|
+
<div role="tabpanel" aria-labelledby="tab-arrivals">Everything landing in the next hour.</div>
|
|
32
|
+
{:else}
|
|
33
|
+
<div role="tabpanel" aria-labelledby="tab-departures">Everything leaving in the next hour.</div>
|
|
34
|
+
{/if}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Examples
|
|
38
|
+
|
|
39
|
+
### Appearance
|
|
40
|
+
|
|
41
|
+
`appearance` decides how the strip is painted. `transparent` has no background of its own and `subtle` fills an item while it is engaged; both mark the selection with the travelling bar. The two circular appearances trade that bar for a pill: `subtle-circular` outlines the selected item and `filled-circular` fills it.
|
|
42
|
+
|
|
43
|
+
```svelte
|
|
44
|
+
<TopNav appearance="transparent">...</TopNav>
|
|
45
|
+
<TopNav appearance="subtle">...</TopNav>
|
|
46
|
+
<TopNav appearance="subtle-circular">...</TopNav>
|
|
47
|
+
<TopNav appearance="filled-circular">...</TopNav>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Size
|
|
51
|
+
|
|
52
|
+
`size` sets the padding, the type and the thickness of the bar for every item at once.
|
|
53
|
+
|
|
54
|
+
```svelte
|
|
55
|
+
<TopNav size="small">...</TopNav>
|
|
56
|
+
<TopNav size="medium">...</TopNav>
|
|
57
|
+
<TopNav size="large">...</TopNav>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Vertical
|
|
61
|
+
|
|
62
|
+
`vertical` stacks the items in a column and moves the bar to their leading edge, where it travels up and down instead of across. The arrow keys follow the same turn.
|
|
63
|
+
|
|
64
|
+
```svelte
|
|
65
|
+
<TopNav bind:selectedValue vertical>
|
|
66
|
+
<TopNavItem value="tab1">First Tab</TopNavItem>
|
|
67
|
+
<TopNavItem value="tab2">Second Tab</TopNavItem>
|
|
68
|
+
</TopNav>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Icon
|
|
72
|
+
|
|
73
|
+
`icon` takes a snippet or a component and renders it before the label.
|
|
74
|
+
|
|
75
|
+
```svelte
|
|
76
|
+
<script>
|
|
77
|
+
import { TopNav, TopNavItem } from 'fluentui-svelte';
|
|
78
|
+
import { AirplaneRegular, AirplaneTakeOffRegular } from 'fluentui-icons-svelte';
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<TopNav bind:selectedValue>
|
|
82
|
+
<TopNavItem value="arrivals" icon={AirplaneRegular}>Arrivals</TopNavItem>
|
|
83
|
+
<TopNavItem value="departures" icon={AirplaneTakeOffRegular}>Departures</TopNavItem>
|
|
84
|
+
</TopNav>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### As an Anchor
|
|
88
|
+
|
|
89
|
+
`as="a"` renders the item as an anchor and takes the attributes of one, `href` among them, so the item has a real URL to open in a new tab or copy. It still reports as a `tab`, which is what a strip of tabs over one page should be; if the items are navigation between pages rather than tabs, a `nav` of plain links is the better shape.
|
|
90
|
+
|
|
91
|
+
```svelte
|
|
92
|
+
<TopNav bind:selectedValue>
|
|
93
|
+
<TopNavItem as="a" href="#arrivals" value="arrivals">Arrivals</TopNavItem>
|
|
94
|
+
<TopNavItem as="a" href="#departures" value="departures">Departures</TopNavItem>
|
|
95
|
+
</TopNav>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Disabled
|
|
99
|
+
|
|
100
|
+
`disabled` on the strip disables every item at once, and a single item can be disabled on its own. The arrow keys pass over a disabled item rather than landing on it.
|
|
101
|
+
|
|
102
|
+
```svelte
|
|
103
|
+
<TopNav disabled>...</TopNav>
|
|
104
|
+
|
|
105
|
+
<TopNav>
|
|
106
|
+
<TopNavItem value="tab1">First Tab</TopNavItem>
|
|
107
|
+
<TopNavItem value="tab2" disabled>Second Tab</TopNavItem>
|
|
108
|
+
</TopNav>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Select on Focus
|
|
112
|
+
|
|
113
|
+
`selectTabOnFocus` selects an item as soon as the focus reaches it, so the arrow keys move the selection rather than only the focus. Use it when what an item opens is already on the page; leave it off when opening one costs a request.
|
|
114
|
+
|
|
115
|
+
```svelte
|
|
116
|
+
<TopNav bind:selectedValue selectTabOnFocus>
|
|
117
|
+
<TopNavItem value="tab1">First Tab</TopNavItem>
|
|
118
|
+
<TopNavItem value="tab2">Second Tab</TopNavItem>
|
|
119
|
+
</TopNav>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Reserved Space
|
|
123
|
+
|
|
124
|
+
A selected item sets its label in semibold, which is wider than the same label at rest. `reserveSelectedTabSpace` is on by default and holds that width from the start, so selecting an item never shoves the ones beside it along. Turning it off lets the items size to what they are showing, and the row shifts as the selection moves.
|
|
125
|
+
|
|
126
|
+
```svelte
|
|
127
|
+
<TopNav bind:selectedValue reserveSelectedTabSpace={false}>
|
|
128
|
+
<TopNavItem value="tab1">First Tab</TopNavItem>
|
|
129
|
+
<TopNavItem value="tab2">Second Tab</TopNavItem>
|
|
130
|
+
</TopNav>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Component Props (TopNav)
|
|
134
|
+
|
|
135
|
+
<!-- DO NOT EDIT THIS SECTION (propsmith generated) -->
|
|
136
|
+
<!-- props:TopNavProps -->
|
|
137
|
+
|
|
138
|
+
| Name | Type | Default | Description |
|
|
139
|
+
| -------------------------- | ------------------------------------------------------------------------------ | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
140
|
+
| `ref` _bindable_ | `HTMLDivElement` | | The DOM reference of the strip. |
|
|
141
|
+
| `selectedValue` _bindable_ | `string` | | The value of the selected item. |
|
|
142
|
+
| `onTabSelect` | `(event: Event, value: string) => void` | | Fired when an item is selected. |
|
|
143
|
+
| `appearance` | [`TopNavAppearance`](https://fluentui-svelte.dev/docs/types/#topnavappearance) | `'transparent'` | How the strip is painted: `transparent` has no background of its own, `subtle` fills an item while it is engaged, and the two circular appearances trade the moving bar for a pill. |
|
|
144
|
+
| `size` | `'small'` | `'medium'` | `'large'` | `'medium'` | The size of every item of the strip. |
|
|
145
|
+
| `vertical` | `boolean` | `false` | Arranges the items in a column, with the bar down their leading edge. |
|
|
146
|
+
| `disabled` | `boolean` | `false` | Disables the user interaction on every item. |
|
|
147
|
+
| `selectTabOnFocus` | `boolean` | `false` | Selects an item as soon as the focus reaches it, rather than waiting to be asked. |
|
|
148
|
+
| `reserveSelectedTabSpace` | `boolean` | `true` | A selected item sets its label in semibold, which is wider than the same label at rest. This holds that width from the start, so selecting an item never shifts the ones beside it. |
|
|
149
|
+
| `disableTabspot` | `boolean` | `false` | Opts the strip out of the tabspot focus management, to wire your own. |
|
|
150
|
+
| Element Attributes (`div`) | | | |
|
|
151
|
+
|
|
152
|
+
<!-- /props:TopNavProps -->
|
|
153
|
+
|
|
154
|
+
## Component Props (TopNavItem)
|
|
155
|
+
|
|
156
|
+
<!-- DO NOT EDIT THIS SECTION (propsmith generated) -->
|
|
157
|
+
<!-- props:TopNavItemProps -->
|
|
158
|
+
|
|
159
|
+
| Name | Type | Default | Description |
|
|
160
|
+
| ---------------- | ----------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
161
|
+
| `ref` _bindable_ | `TopNavItemElementDOMType[T]` | | The DOM reference of the item. |
|
|
162
|
+
| `as` | `'button'` | `'a'` | `'button'` | The DOM element to render. An anchor takes the attributes of one, `href` among them, and is what an item that navigates should be. |
|
|
163
|
+
| `value` | `string` | | The value that identifies the item. Defaults to a generated id. |
|
|
164
|
+
| `icon` | `Snippet` | `Component` | | The icon to display before the label. |
|
|
165
|
+
| `disabled` | `boolean` | | Disables the user interaction. |
|
|
166
|
+
| HTML Attributes | | | |
|
|
167
|
+
|
|
168
|
+
<!-- /props:TopNavItemProps -->
|
|
169
|
+
|
|
170
|
+
## Keyboard Navigation
|
|
171
|
+
|
|
172
|
+
The strip is a single tab stop. The arrows walk the items along the axis they are laid out on, `Home` and `End` jump to the ends, and `Enter` and `Space` select the focused item — or `selectTabOnFocus` selects it on arrival. `disableTabspot` hands the focus management back to you.
|
|
173
|
+
|
|
174
|
+
## Accessibility
|
|
175
|
+
|
|
176
|
+
The strip renders a `tablist` and every item a `tab`, so give it a name through `aria-label`. Since you render what an item opens, give that element a `tabpanel` role and point its `aria-labelledby` at the `id` of its item. An item with an icon and no label needs an `aria-label` of its own.
|