Skip to content

Commit 78fad51

Browse files
committed
docs(breadcrumb): new controls for nested and improved nested docs
Adds controls so a user is able to display the nested truncated menu, root context, set disabled items, and item text. This also clears up and moves around some of the documentation about the truncated menu and root context.
1 parent 9b6f976 commit 78fad51

File tree

2 files changed

+118
-61
lines changed

2 files changed

+118
-61
lines changed

components/breadcrumb/stories/breadcrumb.stories.js

+95-59
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@ import { size } from "@spectrum-css/preview/types";
33
import metadata from "../dist/metadata.json";
44
import packageJson from "../package.json";
55
import { BreadcrumbGroup } from "./breadcrumb.test.js";
6-
import { BreadcrumbTitleHeadings, Template } from "./template";
6+
import { BreadcrumbTitleHeadings, Template } from "./template.js";
77

88
/**
99
* Breadcrumbs show hierarchy and navigational context for a user's location within an app.
10-
*
11-
* ## Nesting
12-
* Breadcrumbs truncate when there is not enough room to display all levels of the breadcrumb list, or as a way of managing relevance of the visible breadcrumb items in a deeply nested hierarchy. The truncation of breadcrumb items begins when either there is not enough room to display all items, or if there are 5 or more breadcrumbs to display. They are typically indicated by the truncated menu folder icon.
13-
*
14-
* The nested variants below are non-functional. Implementations can add their own overflow menus to display all options within a breadcrumb.
15-
*
16-
* ## Root Context
17-
* Some applications find that displaying the root directory is useful for user orientation. This variation keeps the root visible when other folders are truncated into a menu. For example, when users can navigate file directories on their device as well as in the cloud, exposing a root directory called “On this device” is very helpful.
1810
*/
1911
export default {
2012
title: "Breadcrumbs",
2113
component: "Breadcrumbs",
2214
argTypes: {
23-
items: { table: { disable: true } },
15+
items: {
16+
name: "Breadcrumb items",
17+
description: "Additional breadcrumb items after the nav root item, including their label text.<br>Advanced:<ul><li>To show an item as disabled, add a key named `isDisabled` with a value of `true`.</li><li>The \"Show dragged item\" control will affect the item with `isDragged` set to `true`.</li></ul>",
18+
control: "array",
19+
table: {
20+
category: "Content",
21+
},
22+
},
2423
size: {
2524
...size(["m", "l"]),
2625
if: { arg: "variant", neq: "multiline" },
@@ -44,7 +43,7 @@ export default {
4443
},
4544
isDragged: {
4645
name: "Show dragged item",
47-
description: "Breadcrumbs can have optional behavior to allow for drag and drop functionality. Setting this to true will style the second breadcrumb item as if something is currently being dragged on top of it.",
46+
description: "Breadcrumbs can have optional behavior to allow for drag and drop functionality. Setting this to true will style a breadcrumb item as if something is currently being dragged on top of it.",
4847
type: { name: "boolean" },
4948
table: {
5049
type: { summary: "boolean" },
@@ -73,13 +72,70 @@ export default {
7372
defaultValue: undefined,
7473
options: [undefined, "s", "m", "l", "xl"],
7574
if: { arg: "variant", eq: "multiline" },
76-
}
75+
},
76+
showTruncatedMenu: {
77+
name: "Show truncated menu",
78+
description: "Displays a breadcrumb item with a folder icon, that would house truncated breadcrumb items.",
79+
type: { name: "boolean" },
80+
table: {
81+
type: { summary: "boolean" },
82+
category: "State",
83+
},
84+
control: "boolean",
85+
},
86+
showRootContext: {
87+
name: "Show with root context",
88+
description: "Includes a visible breadcrumb item before the truncated menu, for displaying a root directory.",
89+
type: { name: "boolean" },
90+
table: {
91+
type: { summary: "boolean" },
92+
category: "State",
93+
},
94+
control: "boolean",
95+
if: { arg: "showTruncatedMenu" },
96+
},
97+
truncatedMenuIsDisabled: {
98+
name: "Show truncated menu as disabled",
99+
type: { name: "boolean" },
100+
table: {
101+
type: { summary: "boolean" },
102+
category: "State",
103+
},
104+
control: "boolean",
105+
if: { arg: "showTruncatedMenu" },
106+
},
107+
rootItemText: {
108+
name: "Root breadcrumb item label",
109+
type: { name: "string" },
110+
defaultValue: "Nav root",
111+
table: {
112+
type: { summary: "string" },
113+
category: "Content",
114+
},
115+
control: "text",
116+
},
77117
},
78118
args: {
79119
rootClass: "spectrum-Breadcrumbs",
80120
isDragged: false,
81121
variant: undefined,
82122
size: "m",
123+
showTruncatedMenu: false,
124+
showRootContext: false,
125+
truncatedMenuIsDisabled: false,
126+
rootItemText: "Nav root",
127+
items: [
128+
{
129+
label: "Sub item",
130+
isDragged: true,
131+
},
132+
{
133+
label: "Trend",
134+
},
135+
{
136+
label: "January 2019 assets",
137+
},
138+
],
83139
},
84140
parameters: {
85141
design: {
@@ -97,31 +153,17 @@ export default {
97153
* The separator UI icon displayed should be `Chevron100`.
98154
*/
99155
export const Default = BreadcrumbGroup.bind({});
100-
Default.args = {
101-
items: [
102-
{
103-
label: "Nav root",
104-
},
105-
{
106-
label: "Trend",
107-
isDragged: true,
108-
},
109-
{
110-
label: "January 2019 assets",
111-
},
112-
],
113-
};
156+
Default.args = {};
114157

158+
/**
159+
* Breadcrumbs truncate when there is not enough room to display all levels of the breadcrumb list, or as a way of managing relevance of the visible breadcrumb items in a deeply nested hierarchy. The truncation of breadcrumb items begins when either there is not enough room to display all items, or if there are 5 or more breadcrumbs to display. This truncated menu is an icon only action button that typically displays a folder icon.
160+
*
161+
* The nested variants below are non-functional. Implementations should make sure to follow the design guidelines for overflow behavior and displaying all options within the truncated menu.
162+
*/
115163
export const DefaultNested = Template.bind({});
116164
DefaultNested.args = {
165+
showTruncatedMenu: true,
117166
items: [
118-
{
119-
iconName: "FolderOpen",
120-
iconSet: "workflow",
121-
},
122-
{
123-
label: "Sub item",
124-
},
125167
{
126168
label: "Trend",
127169
},
@@ -134,18 +176,18 @@ DefaultNested.tags = ["!dev"];
134176
DefaultNested.parameters = {
135177
chromatic: { disableSnapshot: true },
136178
};
137-
DefaultNested.storyName = "Default, nested";
179+
DefaultNested.storyName = "Default, nested (truncated menu)";
138180

181+
/**
182+
* Some applications find that displaying the root directory is useful for user orientation. This variation keeps the root visible when other folders are
183+
* truncated into a menu. For example, when users can navigate file directories on their device as well as in the cloud, exposing a root directory
184+
* called “On this device” is very helpful.
185+
*/
139186
export const DefaultNestedRootVisible = Template.bind({});
140187
DefaultNestedRootVisible.args = {
188+
showTruncatedMenu: true,
189+
showRootContext: true,
141190
items: [
142-
{
143-
label: "Nav root",
144-
},
145-
{
146-
iconName: "FolderOpen",
147-
iconSet: "workflow",
148-
},
149191
{
150192
label: "Trend",
151193
},
@@ -158,7 +200,7 @@ DefaultNestedRootVisible.tags = ["!dev"];
158200
DefaultNestedRootVisible.parameters = {
159201
chromatic: { disableSnapshot: true },
160202
};
161-
DefaultNestedRootVisible.storyName = "Default, nested (root visible)";
203+
DefaultNestedRootVisible.storyName = "Default, nested with root context";
162204

163205
/**
164206
* The multiline variation places emphasis on the selected breadcrumb item as a page title, helping a user to more clearly identify their current location.
@@ -178,7 +220,7 @@ MultilineNested.args = {
178220
...DefaultNested.args,
179221
variant: "multiline",
180222
};
181-
MultilineNested.storyName = "Multiline, nested";
223+
MultilineNested.storyName = "Multiline, nested (truncated menu)";
182224
MultilineNested.tags= ["!dev"];
183225
MultilineNested.parameters = {
184226
chromatic: { disableSnapshot: true },
@@ -193,7 +235,7 @@ MultilineNestedRootVisible.tags = ["!dev"];
193235
MultilineNestedRootVisible.parameters = {
194236
chromatic: { disableSnapshot: true },
195237
};
196-
MultilineNestedRootVisible.storyName = "Multiline, nested (root visible)";
238+
MultilineNestedRootVisible.storyName = "Multiline, nested with root context";
197239

198240
/**
199241
* When using the large size, the truncated menu action button should also use the large size. The separator UI icon displayed should be `Chevron100`.
@@ -217,7 +259,7 @@ LargeNested.tags = ["!dev"];
217259
LargeNested.parameters = {
218260
chromatic: { disableSnapshot: true },
219261
};
220-
LargeNested.storyName = "Large, nested";
262+
LargeNested.storyName = "Large, nested (truncated menu)";
221263

222264
export const LargeNestedRootVisible = Template.bind({});
223265
LargeNestedRootVisible.args = {
@@ -228,7 +270,7 @@ LargeNestedRootVisible.tags = ["!dev"];
228270
LargeNestedRootVisible.parameters = {
229271
chromatic: { disableSnapshot: true },
230272
};
231-
LargeNestedRootVisible.storyName = "Large, nested (root visible)";
273+
LargeNestedRootVisible.storyName = "Large, nested with root context";
232274

233275
/**
234276
* Breadcrumbs can have optional behavior to allow for drag and drop functionality.
@@ -247,21 +289,15 @@ Dragged.parameters = {
247289

248290
/**
249291
* The example below has two disabled breadcrumb items. When disabling the text link, the `is-disabled` class
250-
* gets added to `.spectrum-Breadcrumbs-itemLink`. When disabling the Action button, the `[disabled]` attribute is applied.
292+
* gets added to `.spectrum-Breadcrumbs-itemLink`. When disabling the truncated menu action button, the `[disabled]` attribute is applied.
251293
*/
252294
export const Disabled = Template.bind({});
253295
Disabled.args = {
296+
showTruncatedMenu: true,
297+
truncatedMenuIsDisabled: true,
254298
items: [
255299
{
256-
label: "Nav root",
257-
},
258-
{
259-
iconName: "FolderOpen",
260-
iconSet: "workflow",
261-
isDisabled: true,
262-
},
263-
{
264-
label: "Trendy",
300+
label: "Trend",
265301
isDisabled: true,
266302
},
267303
{
@@ -282,11 +318,11 @@ Disabled.parameters = {
282318
*/
283319
export const MultilineTitleSizes = BreadcrumbTitleHeadings.bind({});
284320
MultilineTitleSizes.args = {
285-
...DefaultNested.args,
286-
variant: "multiline",
321+
...Multiline.args,
322+
showTruncatedMenu: true,
287323
};
288324
MultilineTitleSizes.storyName = "Multiline, title heading sizes";
289-
MultilineTitleSizes.tags= ["!dev"];
325+
MultilineTitleSizes.tags = ["!dev"];
290326
MultilineTitleSizes.parameters = {
291327
chromatic: { disableSnapshot: true },
292328
};

components/breadcrumb/stories/template.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,28 @@ export const Template = ({
1717
variant,
1818
isDragged = false,
1919
titleHeadingSize,
20+
showTruncatedMenu = false,
21+
showRootContext = true,
22+
truncatedMenuIsDisabled = false,
23+
rootItemText = "Nav root",
2024
} = {}, context = {}) => {
25+
/**
26+
* Build array of breadcrumb items.
27+
* - The presence of the root item and truncated menu are dependent upon controls.
28+
* - The rest of the items, including the current item, come from the `items` array.
29+
*/
30+
const breadcrumbItems = [
31+
...(showTruncatedMenu == false || showRootContext == true) ? [{
32+
label: rootItemText,
33+
}] : [],
34+
...(showTruncatedMenu == true) ? [{
35+
iconName: "FolderOpen",
36+
iconSet: "workflow",
37+
isDragged: true,
38+
}] : [],
39+
...items,
40+
];
41+
2142
return html`
2243
<nav>
2344
<ul
@@ -28,7 +49,7 @@ export const Template = ({
2849
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
2950
})}
3051
>
31-
${items.map((item, idx, arr) => {
52+
${breadcrumbItems.map((item, idx, arr) => {
3253
const { label, isDisabled, iconName, iconSet } = item;
3354
return html` <li
3455
class=${classMap({
@@ -43,7 +64,7 @@ export const Template = ({
4364
{
4465
iconName,
4566
iconSet,
46-
isDisabled,
67+
isDisabled: isDisabled || truncatedMenuIsDisabled,
4768
isQuiet: true,
4869
customIconClasses: [`${rootClass}-folder`],
4970
size: {

0 commit comments

Comments
 (0)