Skip to content

Commit 3f14a86

Browse files
authored
fix(button): support for wrapping text (#2248)
* fix(button): restore ability for button text to wrap Remove the CSS that prevents the text in the button from wrapping. The guidelines for the component say "When the button text is too long for the horizontal space available, it wraps to form another line." * docs(button): add wrapping text story Add "Wrapping" story that demonstrates a button with long text that wraps to the next line. Some template adjustments and additional args added to allow for this. * fix(button)!: icon alignment when text is wrapping BREAKING CHANGE: changes vertical flex alignment to start. Previously when the button had an icon and the text was wrapping, the icon was vertically aligned center and the text was aligned center. This fixes this to match with the design spec: for the version of the button that uses a workflow icon, the icon should stay aligned to the top, and the text should be aligned left (start). This uses the defined token for the space between the top of the component and the workflow icon (--spectrum-component-top-to-workflow-icon-*). * docs(button): rename storybook control to layout Rename Storybook control for stacking buttons to "layout" with specified options, which is a more appropriate name. The control has also been made visible. * 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. * feat(button): mod property for icon margin top Add a mod property to make it easy to modify the margin-block-start of the icon, in case of alignment issues with icons that are not the intended workflow sizes.
1 parent 5524456 commit 3f14a86

File tree

4 files changed

+168
-58
lines changed

4 files changed

+168
-58
lines changed

components/button/index.css

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ 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

28-
2929
.spectrum-Button--sizeS {
3030
--spectrum-button-min-width: calc(var(--spectrum-component-height-75) * var(--spectrum-button-minimum-width-multiplier));
3131

@@ -40,6 +40,8 @@ governing permissions and limitations under the License.
4040
--spectrum-button-padding-label-to-icon: var(--spectrum-text-to-visual-75);
4141
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-small);
4242
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-small);
43+
--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 {
@@ -56,6 +58,8 @@ governing permissions and limitations under the License.
5658
--spectrum-button-padding-label-to-icon: var(--spectrum-text-to-visual-100);
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);
61+
--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);
5963

6064
&[pending],
6165
&.is-pending {
@@ -77,7 +81,8 @@ governing permissions and limitations under the License.
7781
--spectrum-button-padding-label-to-icon: var(--spectrum-text-to-visual-200);
7882
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-large);
7983
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-large);
80-
84+
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-200);
85+
--spectrum-button-intended-icon-size: var(--spectrum-workflow-icon-size-200);
8186

8287
&[pending],
8388
&.is-pending {
@@ -99,6 +104,8 @@ governing permissions and limitations under the License.
99104
--spectrum-button-padding-label-to-icon: var(--spectrum-text-to-visual-300);
100105
--spectrum-button-top-to-text: var(--spectrum-button-top-to-text-extra-large);
101106
--spectrum-button-bottom-to-text: var(--spectrum-button-bottom-to-text-extra-large);
107+
--spectrum-button-top-to-icon: var(--spectrum-component-top-to-workflow-icon-300);
108+
--spectrum-button-intended-icon-size: var(--spectrum-workflow-icon-size-300);
102109

103110
.spectrum--medium &[pending],
104111
.spectrum--medium &.is-pending {
@@ -141,11 +148,28 @@ governing permissions and limitations under the License.
141148
}
142149

143150
.spectrum-Icon {
151+
/* Any block-size difference between the intended workflow icon size and actual icon used.
152+
Helps support any existing use of smaller UI icons instead of intended Workflow icons. */
153+
--_icon-size-difference: max(0px,
154+
var(--spectrum-button-intended-icon-size) -
155+
var(--spectrum-icon-block-size, var(--spectrum-button-intended-icon-size))
156+
);
157+
158+
margin-block-start: var(--mod-button-icon-margin-block-start,
159+
max(0px,
160+
var(--mod-button-top-to-icon, var(--spectrum-button-top-to-icon)) -
161+
var(--mod-button-border-width, var(--spectrum-button-border-width)) +
162+
(var(--_icon-size-difference, 0px) / 2)
163+
)
164+
);
165+
144166
margin-inline-start: calc(
145167
var(--mod-button-edge-to-visual, var(--spectrum-button-edge-to-visual)) -
146168
var(--mod-button-edge-to-text, var(--spectrum-button-edge-to-text))
147169
);
148170
color: inherit;
171+
flex-shrink: 0;
172+
align-self: flex-start;
149173
}
150174

151175
/* correct focus indicator radius for t-shirt sizing */
@@ -159,7 +183,9 @@ governing permissions and limitations under the License.
159183
border-radius: 50%;
160184

161185
.spectrum-Icon {
186+
align-self: center;
162187
margin-inline-start: 0;
188+
margin-block-start: 0;
163189
}
164190

165191
&::after {
@@ -176,9 +202,13 @@ a.spectrum-Button {
176202
@extend %spectrum-ButtonLabel;
177203
padding-block-start: calc(var(--mod-button-top-to-text, var(--spectrum-button-top-to-text)) - var(--mod-button-border-width, var(--spectrum-button-border-width)));
178204
padding-block-end: calc(var(--mod-button-bottom-to-text, var(--spectrum-button-bottom-to-text)) - var(--mod-button-border-width, var(--spectrum-button-border-width)));
179-
white-space: nowrap;
180205
line-height: var(--mod-button-line-height, var(--spectrum-button-line-height));
181206
align-self: start;
207+
text-align: var(--mod-button-text-align, center);
208+
}
209+
210+
.spectrum-Button .spectrum-Icon + .spectrum-Button-label {
211+
text-align: var(--mod-button-text-align-with-icon, start);
182212
}
183213

184214
.spectrum-Button {
@@ -190,26 +220,22 @@ a.spectrum-Button {
190220
}
191221
}
192222

193-
/* special cases for focus-ring */
223+
/* Special cases for focus indicator */
194224
.spectrum-Button {
195225
transition: border-color var(--mod-button-animation-duration, var(--spectrum-button-animation-duration)) ease-in-out;
196226

197227
&::after {
198228
position: absolute;
199229
inset: 0;
200-
201230
margin: calc((var(--mod-button-focus-ring-gap, var(--spectrum-button-focus-ring-gap)) + var(--mod-button-border-width, var(--spectrum-button-border-width))) * -1);
202-
203231
border-radius: var(--mod-button-focus-ring-border-radius, var(--spectrum-button-focus-ring-border-radius));
204-
205232
transition: box-shadow var(--mod-button-animation-duration, var(--spectrum-button-animation-duration)) ease-in-out;
206-
207233
pointer-events: none;
208234
content: '';
209235
}
210236

211237
&:focus-visible {
212-
/* kill the default ring */
238+
/* Remove the default focus outline */
213239
box-shadow: none;
214240
outline: none;
215241

@@ -222,7 +248,6 @@ a.spectrum-Button {
222248

223249
/* Core Token Theming */
224250
/* former skin.css, applied / copied from actionbutton/index.css */
225-
226251
.spectrum-Button {
227252
@extend %spectrum-BaseButton;
228253

@@ -268,7 +293,16 @@ a.spectrum-Button {
268293
}
269294
}
270295

271-
/* windows high contrast mode over-writes for accent variant */
296+
/* Static color variants */
297+
.spectrum-Button--staticWhite {
298+
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
299+
}
300+
301+
.spectrum-Button--staticBlack {
302+
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
303+
}
304+
305+
/* Windows High Contrast Mode */
272306
@media (forced-colors: active) {
273307
.spectrum-Button {
274308
--highcontrast-button-content-color-disabled: GrayText;
@@ -302,12 +336,3 @@ a.spectrum-Button {
302336
}
303337
}
304338
}
305-
306-
/* static variants */
307-
.spectrum-Button--staticWhite {
308-
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
309-
}
310-
311-
.spectrum-Button--staticBlack {
312-
--spectrum-button-focus-indicator-color: var(--mod-static-black-focus-indicator-color, var(--spectrum-static-black-focus-indicator-color));
313-
}

components/button/metadata/mods.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@
3232
| `--mod-button-font-family` |
3333
| `--mod-button-font-size` |
3434
| `--mod-button-height` |
35+
| `--mod-button-icon-margin-block-start` |
3536
| `--mod-button-line-height` |
3637
| `--mod-button-margin-block` |
3738
| `--mod-button-margin-left` |
3839
| `--mod-button-margin-right` |
3940
| `--mod-button-min-width` |
4041
| `--mod-button-padding-label-to-icon` |
4142
| `--mod-button-static-content-color` |
43+
| `--mod-button-text-align` |
44+
| `--mod-button-text-align-with-icon` |
45+
| `--mod-button-top-to-icon` |
4246
| `--mod-button-top-to-text` |
4347
| `--mod-focus-indicator-gap` |
4448
| `--mod-line-height-100` |

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/progresscircle": ">=2",
2020
"@spectrum-css/tokens": ">=13"
2121
},

0 commit comments

Comments
 (0)