Skip to content

Commit b6bbbd8

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 a92ed3f commit b6bbbd8

File tree

3 files changed

+74
-23
lines changed

3 files changed

+74
-23
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: 58 additions & 21 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",
@@ -119,6 +119,18 @@ export default {
119119
},
120120
};
121121

122+
/**
123+
* Optional wrapper for each button used within other templates, to assist with the "stacked"
124+
* layout and the testing of wrapping text.
125+
*/
126+
const ButtonWrap = (layout, content) => {
127+
const buttonWrapStyles = {
128+
'margin-block': '15px',
129+
'max-width': '480px',
130+
};
131+
return layout === "stacked" ? html`<div style=${styleMap(buttonWrapStyles)}>${content}</div>` : content;
132+
};
133+
122134
/**
123135
* Multiple button variations displayed in one story template.
124136
* Used as the base template for the stories.
@@ -131,15 +143,6 @@ const CustomButton = ({
131143
customStyles = {},
132144
...args
133145
}) => {
134-
// Optional wrapper for each button, to assist with the testing of wrapping text.
135-
const ButtonWrap = (content) => {
136-
const buttonWrapStyles = {
137-
'margin-block': '15px',
138-
'max-width': '480px',
139-
};
140-
return layout === "stacked" ? html`<div style=${styleMap(buttonWrapStyles)}>${content}</div>` : content;
141-
};
142-
143146
return html`
144147
<div
145148
style=${ifDefined(styleMap({
@@ -148,32 +151,65 @@ const CustomButton = ({
148151
...customStyles
149152
}))}
150153
>
151-
${ButtonWrap(Template({
154+
${ButtonWrap(layout, Template({
152155
...args,
153156
staticColor,
154157
iconName: undefined,
155158
}))}
156-
${ButtonWrap(Template({
159+
${ButtonWrap(layout, Template({
157160
...args,
158161
staticColor,
159162
iconName: undefined,
160163
treatment: "outline",
161164
}))}
162-
${ButtonWrap(Template({
165+
${ButtonWrap(layout, Template({
163166
...args,
164167
staticColor,
165168
iconName: iconName ?? "Edit",
166169
}))}
167-
${showIconOnlyButton ? ButtonWrap(Template({
168-
...args,
169-
staticColor,
170-
hideLabel: true,
171-
iconName: iconName ?? "Edit",
172-
})) : ''}
170+
${when(showIconOnlyButton, () =>
171+
ButtonWrap(layout, Template({
172+
...args,
173+
staticColor,
174+
hideLabel: true,
175+
iconName: iconName ?? "Edit",
176+
}))
177+
)}
173178
</div>
174179
`;
175180
};
176181

182+
/**
183+
* Wrapping story template, displaying some additional variants for Chromatic.
184+
*/
185+
const WrappingTemplate = ({layout, ...args}) => {
186+
if (window.isChromatic()) {
187+
return html`
188+
${CustomButton({layout, ...args})}
189+
<div style=${ifDefined(styleMap({ padding: "1rem" }))}>
190+
${ButtonWrap(layout, Template({
191+
...args,
192+
iconName: "Edit",
193+
treatment: "outline",
194+
}))}
195+
${ButtonWrap(layout, Template({
196+
...args,
197+
// Uses a UI icon that is smaller than workflow sizing, to test alignment:
198+
iconName: "Cross100",
199+
}))}
200+
${ButtonWrap(layout, Template({
201+
...args,
202+
// UI icon that is larger than workflow sizing:
203+
iconName: "ArrowDown600",
204+
treatment: "outline",
205+
}))}
206+
</div>
207+
`;
208+
}
209+
// Otherwise use the default template.
210+
return CustomButton({layout, ...args});
211+
};
212+
177213
export const Accent = CustomButton.bind({});
178214
Accent.args = {
179215
variant: "accent",
@@ -219,7 +255,8 @@ WithForcedColors.args = {
219255
iconName: "Actions",
220256
};
221257

222-
export const Wrapping = CustomButton.bind({});
258+
export const Wrapping = WrappingTemplate.bind({});
259+
Wrapping.storyName = "Wrapping";
223260
Wrapping.args = {
224261
layout: "stacked",
225262
showIconOnlyButton: false,

0 commit comments

Comments
 (0)