Skip to content

Commit 1a3df2a

Browse files
committed
fix(button): support any existing use of ui icons
Support any existing use of ui icons with the updated wrapping behavior. And add Chromatic only testing of them to the Wrapping story. Workflow icons are intended, with the use of the spectrum-component-top-to-workflow-icon tokens, but UI icons have not yet been specifically excluded in guidelines and are currently in use within SplitButton in this library. This keeps UI icons that are smaller than the intended workflow icon, better vertically centered with the text within the button.
1 parent ab2f88e commit 1a3df2a

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

components/button/index.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ governing permissions and limitations under the License.
2323
--spectrum-button-focus-ring-border-radius: calc(var(--spectrum-button-border-radius) + var(--spectrum-button-focus-ring-gap));
2424
--spectrum-button-focus-ring-thickness: var(--spectrum-focus-indicator-thickness);
2525
--spectrum-button-focus-indicator-color: var(--spectrum-focus-indicator-color);
26+
--spectrum-button-intended-icon-size: var(--spectrum-workflow-icon-size-50);
2627
}
2728

2829
.spectrum-Button--sizeS {
@@ -40,6 +41,7 @@ governing permissions and limitations under the License.
4041
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-small);
4142
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-small);
4243
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-75);
44+
--spectrum-button-intended-icon-size: var(--spectrum-workflow-icon-size-75);
4345
}
4446

4547
.spectrum-Button--sizeM {
@@ -57,6 +59,7 @@ governing permissions and limitations under the License.
5759
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-medium);
5860
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-medium);
5961
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-100);
62+
--spectrum-button-intended-icon-size: var(--spectrum-workflow-icon-size-100);
6063
}
6164

6265
.spectrum-Button--sizeL {
@@ -74,6 +77,7 @@ governing permissions and limitations under the License.
7477
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-large);
7578
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-large);
7679
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-200);
80+
--spectrum-button-intended-icon-size: var(--spectrum-workflow-icon-size-200);
7781
}
7882

7983
.spectrum-Button--sizeXL {
@@ -91,6 +95,7 @@ governing permissions and limitations under the License.
9195
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-extra-large);
9296
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-extra-large);
9397
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-300);
98+
--spectrum-button-intended-icon-size: var(--spectrum-workflow-icon-size-300);
9499
}
95100

96101
.spectrum-Button {
@@ -123,10 +128,19 @@ governing permissions and limitations under the License.
123128
}
124129

125130
.spectrum-Icon {
131+
/* Any block-size difference between the intended workflow icon size and actual icon used.
132+
Helps support any existing use of smaller UI icons instead of intended Workflow icons. */
133+
--_icon-size-difference: max(0px,
134+
var(--spectrum-button-intended-icon-size) -
135+
var(--spectrum-icon-block-size, var(--spectrum-button-intended-icon-size))
136+
);
137+
126138
margin-block-start: max(0px,
127139
var(--mod-button-top-to-icon, var(--spectrum-button-top-to-icon)) -
128-
var(--mod-button-border-width, var(--spectrum-button-border-width))
140+
var(--mod-button-border-width, var(--spectrum-button-border-width)) +
141+
(var(--_icon-size-difference, 0px) / 2)
129142
);
143+
130144
margin-inline-start: calc(
131145
var(--mod-button-edge-to-visual, var(--spectrum-button-edge-to-visual)) -
132146
var(--mod-button-edge-to-text, var(--spectrum-button-edge-to-text))

components/button/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"main": "dist/index-vars.css",
1717
"peerDependencies": {
18-
"@spectrum-css/icon": ">=4",
18+
"@spectrum-css/icon": ">=6",
1919
"@spectrum-css/tokens": ">=13"
2020
},
2121
"peerDependenciesMeta": {

components/button/stories/button.stories.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { html } from "lit";
22
import { ifDefined } from "lit/directives/if-defined.js";
33
import { styleMap } from "lit/directives/style-map.js";
4-
5-
import { Template } from "./template";
4+
import { when } from "lit/directives/when.js";
65

76
import { default as IconStories } from "@spectrum-css/icon/stories/icon.stories.js";
7+
import { Template } from "./template";
88

99
export default {
1010
title: "Components/Button",
@@ -164,12 +164,29 @@ const CustomButton = ({
164164
staticColor,
165165
iconName: iconName ?? "Edit",
166166
}))}
167-
${showIconOnlyButton ? ButtonWrap(Template({
168-
...args,
169-
staticColor,
170-
hideLabel: true,
171-
iconName: iconName ?? "Edit",
172-
})) : ''}
167+
${when(window.isChromatic(), () => html`
168+
${ButtonWrap(Template({
169+
...args,
170+
staticColor,
171+
// Uses a UI icon that is smaller than workflow sizing, to test alignment:
172+
iconName: "Cross100",
173+
treatment: "outline",
174+
}))}
175+
${ButtonWrap(Template({
176+
...args,
177+
staticColor,
178+
iconName: "ArrowDown600",
179+
treatment: "outline",
180+
}))}
181+
`)}
182+
${when(showIconOnlyButton, () =>
183+
ButtonWrap(Template({
184+
...args,
185+
staticColor,
186+
hideLabel: true,
187+
iconName: iconName ?? "Edit",
188+
}))
189+
)}
173190
</div>
174191
`;
175192
};

0 commit comments

Comments
 (0)