Skip to content

Commit 9ea9fec

Browse files
committed
docs: wrong workflow icons appearing for arrow and chevron
Related fixes for Icon migration, that helps fix the wrong workflow icons appearing for arrow and chevron. These are both icons with names that exist in both icon sets. Some component stories need the icon set specified.
1 parent f10a4b3 commit 9ea9fec

File tree

7 files changed

+51
-23
lines changed

7 files changed

+51
-23
lines changed

components/actionbutton/stories/template.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const Template = ({
1717
rootClass = "spectrum-ActionButton",
1818
size = "m",
1919
iconName,
20+
iconSet,
2021
label,
2122
isQuiet = false,
2223
isSelected = false,
@@ -78,6 +79,7 @@ export const Template = ({
7879
...globals,
7980
size,
8081
iconName,
82+
setName: iconSet,
8183
customClasses: [`${rootClass}-icon`, ...customIconClasses],
8284
})
8385
)}

components/combobox/stories/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const Template = ({
104104
... isValid ? ['is-valid'] : [],
105105
],
106106
size,
107-
iconType: "workflow",
107+
iconType: "ui",
108108
iconName: "ChevronDown",
109109
isQuiet,
110110
isOpen,

components/icon/stories/template.js

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { classMap } from "lit/directives/class-map.js";
33
import { ifDefined } from "lit/directives/if-defined.js";
44
import { unsafeSVG } from "lit/directives/unsafe-svg.js";
55

6-
import { fetchIconSVG, uiIcons, workflowIcons } from "./utilities.js";
6+
import { fetchIconSVG, uiIcons, uiIconSizes, workflowIcons } from "./utilities.js";
77

88
import "../index.css";
99

@@ -48,22 +48,50 @@ export const Template = ({
4848

4949
let idKey = iconName;
5050

51-
// If a descriptor like Right, Left, Down, or Up is present for the Chevron or the
51+
// If icon set was not provided, try determine which icon set contains this icon.
52+
// Note: icon sets can contain the same icon name, with different icons.
53+
if (!['workflow','ui'].includes(setName)){
54+
if (workflowIcons.includes(idKey)) {
55+
setName = "workflow";
56+
} else if (uiIcons.includes(idKey.replace(/\d{2,3}$/, "").replace(/(Right|Left|Down|Up)$/, ""))) {
57+
setName = "ui";
58+
}
59+
}
60+
61+
if (!setName) {
62+
console.warn(
63+
`Icon: Could not determine the icon set for the provided icon name: ${idKey}.`
64+
);
65+
return html``;
66+
}
67+
68+
// If a descriptor like Right, Left, Down, or Up is present for the UI icons Chevron or
5269
// Arrow, use that only for the class and not the icon fetch.
5370
if (
71+
setName == "ui" &&
5472
uiIcons.some((c) => idKey.startsWith(c)) &&
5573
["Right", "Left", "Down", "Up"].some((c) => idKey.includes(c))
5674
) {
5775
idKey = idKey.replace(/(Right|Left|Down|Up)/, "");
5876
}
5977

60-
// If the icon name includes its scale, we want to leave that scale
61-
// If the icon name does not include scale, reformat it to match the provided sizing.
62-
// E.g. with a size of "s", the icon name "ChevronRight" would become "ChevronRight75".
78+
/**
79+
* Fallback UI Icon sizing number.
80+
*
81+
* If the icon name includes its scale, we want to leave that scale. This is preferred,
82+
* as UI icons do not use workflow icon sizing.
83+
*
84+
* If the UI icon name does not include scale, reformat it to match the provided sizing.
85+
* E.g. with a size of "s", the icon name "ChevronRight" would become "ChevronRight75".
86+
*/
6387
if (
88+
setName == "ui" &&
89+
// Exists in the list of available UI icons.
6490
uiIcons.includes(idKey.replace(/\d{2,3}$/, "")) &&
91+
// Does not already have size number at the end.
6592
!idKey.match(/^(?!\d).*\d{2,3}$/) &&
66-
!idKey.endsWith("Gripper")
93+
// Exclude some UI icons that do not (yet) have size numbers.
94+
uiIconSizes[idKey]?.length != 0
6795
) {
6896
let sizeVal;
6997
switch (size) {
@@ -88,20 +116,7 @@ export const Template = ({
88116

89117
}
90118

91-
// Determine which icon set contains this icon.
92-
if (workflowIcons.includes(idKey)) {
93-
setName = "workflow";
94-
} else if (uiIcons.includes(idKey.replace(/\d{2,3}$/, ""))) {
95-
setName = "ui";
96-
}
97-
98-
if (!setName) {
99-
console.warn(
100-
`Icon: Could not determine the icon set for the provided icon name: ${idKey}.`
101-
);
102-
return html``;
103-
}
104-
119+
// Fetch SVG file markup, and set optional fill color.
105120
let inlineStyle;
106121
if (fill) inlineStyle = `color: ${fill}`;
107122
let icon;
@@ -110,11 +125,15 @@ export const Template = ({
110125
icon = fetchIconSVG({ iconName: idKey, setName, ...globals });
111126

112127
if (!icon) {
113-
console.warn(`Icon: ${idKey} not found.`);
128+
console.warn(`Icon: "${idKey}" was not found in the "${setName}" icon set.`);
114129
return html``;
115130
}
116131
}
117132

133+
/**
134+
* Classes to apply to the SVG element. Object as used by the classMap function.
135+
* @type {[name: string]: string | boolean | number}
136+
*/
118137
const classList = {
119138
[rootClass]: true,
120139
[`spectrum-UIIcon-${iconName}`]: !!(setName === "ui"),

components/pagination/stories/template.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const Template = ({
3030
${ActionButton({
3131
size,
3232
isQuiet: true,
33+
iconSet: "ui",
3334
iconName: "ChevronLeft",
3435
customClasses: [`${rootClass}-prevButton`],
3536
})}
@@ -42,6 +43,7 @@ export const Template = ({
4243
${ActionButton({
4344
size,
4445
isQuiet: true,
46+
iconSet: "ui",
4547
iconName: "ChevronRight",
4648
customClasses: [`${rootClass}-nextButton`],
4749
})}

components/picker/stories/template.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const Picker = ({
8181
${Icon({
8282
...globals,
8383
size,
84+
setName: "ui",
8485
iconName: "ChevronDown",
8586
customClasses: [`${rootClass}-menuIcon`],
8687
})}

components/pickerbutton/stories/template.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { html } from "lit";
22
import { classMap } from "lit/directives/class-map.js";
3-
import { styleMap } from "lit/directives/style-map.js";
43
import { ifDefined } from "lit/directives/if-defined.js";
4+
import { styleMap } from "lit/directives/style-map.js";
55

66
import { useArgs } from "@storybook/client-api";
77

@@ -72,6 +72,7 @@ export const Template = ({
7272
: ""}
7373
${Icon({
7474
...globals,
75+
setName: iconType,
7576
iconName: iconName ?? "ChevronDown",
7677
size,
7778
customClasses: [`${rootClass}-icon`],

components/treeview/stories/template.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const TreeViewItem = ({
2020
isOpen,
2121
isDropTarget,
2222
icon,
23+
iconSet,
2324
thumbnail,
2425
items,
2526
customClasses = [],
@@ -80,6 +81,7 @@ export const TreeViewItem = ({
8081
? Icon({
8182
...globals,
8283
size,
84+
setName: "ui",
8385
iconName: "ChevronRight",
8486
customClasses: [`${rootClass}-itemIndicator`],
8587
})
@@ -89,6 +91,7 @@ export const TreeViewItem = ({
8991
...globals,
9092
size,
9193
iconName: icon,
94+
setName: iconSet,
9295
customClasses: [`${rootClass}-itemIcon`],
9396
})
9497
: ""}

0 commit comments

Comments
 (0)