Skip to content

Commit 0242f7f

Browse files
authored
feat(clearbutton): s2 migration (#4043)
* feat(clearbutton): s2 migration * chore(clearbutton): add search + tags links to docs * chore(clearbutton): add hover + down state tests * chore(clearbutton): add hover + down state controls, add migrated tags * chore(clearbutton): add down state to changelog * chore(clearbutton): move size table out of usage notes to size story * fix(clearbutton): correct test key names * chore(clearbutton): remove keyboard focus outline
1 parent faea651 commit 0242f7f

File tree

6 files changed

+87
-133
lines changed

6 files changed

+87
-133
lines changed

.changeset/neat-schools-take.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@spectrum-css/clearbutton": major
3+
---
4+
5+
#### S2 migration for clear button
6+
7+
This migrates the clear button component to the latest Spectrum 2 designs. Custom properties have been remapped and added per the design specification.
8+
9+
- The quiet variant has been remove as all clear buttons have a transparent background.
10+
- The over-background and static color variants have been removed.
11+
- Test and stories for deprecated variants have been removed.
12+
- The down state has been added, corresponding controls and tests have been added.

components/clearbutton/dist/metadata.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
"selectors": [
44
".spectrum-ClearButton",
55
".spectrum-ClearButton > .spectrum-Icon",
6-
".spectrum-ClearButton--overBackground:focus-visible",
7-
".spectrum-ClearButton--staticWhite:focus-visible",
86
".spectrum-ClearButton-fill",
97
".spectrum-ClearButton-icon",
108
".spectrum-ClearButton.is-disabled",
11-
".spectrum-ClearButton.spectrum-ClearButton--quiet",
129
".spectrum-ClearButton.spectrum-ClearButton--sizeL",
1310
".spectrum-ClearButton.spectrum-ClearButton--sizeS",
1411
".spectrum-ClearButton.spectrum-ClearButton--sizeXL",
15-
".spectrum-ClearButton.spectrum-ClearButton--staticWhite",
1612
".spectrum-ClearButton:disabled",
13+
".spectrum-ClearButton:focus-visible",
1714
".spectrum-ClearButton:not(:disabled)",
1815
".spectrum-ClearButton:not(:disabled):active",
1916
".spectrum-ClearButton:not(:disabled):active .spectrum-ClearButton-fill",
@@ -57,16 +54,17 @@
5754
"--spectrum-component-height-200",
5855
"--spectrum-component-height-300",
5956
"--spectrum-component-height-75",
57+
"--spectrum-component-size-difference-down",
58+
"--spectrum-component-size-minimum-perspective-down",
6059
"--spectrum-disabled-content-color",
61-
"--spectrum-disabled-static-white-content-color",
62-
"--spectrum-in-field-button-edge-to-fill",
60+
"--spectrum-in-field-button-edge-to-fill-extra-large",
61+
"--spectrum-in-field-button-edge-to-fill-large",
62+
"--spectrum-in-field-button-edge-to-fill-medium",
63+
"--spectrum-in-field-button-edge-to-fill-small",
6364
"--spectrum-neutral-content-color-default",
6465
"--spectrum-neutral-content-color-down",
6566
"--spectrum-neutral-content-color-hover",
66-
"--spectrum-neutral-content-color-key-focus",
67-
"--spectrum-transparent-white-400",
68-
"--spectrum-transparent-white-500",
69-
"--spectrum-white"
67+
"--spectrum-neutral-content-color-key-focus"
7068
],
7169
"passthroughs": [],
7270
"high-contrast": ["--highcontrast-clear-button-icon-color-hover"]

components/clearbutton/index.css

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright 2024 Adobe. All rights reserved.
2+
* Copyright 2025 Adobe. All rights reserved.
33
*
44
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License. You may obtain a copy
@@ -14,7 +14,7 @@
1414
.spectrum-ClearButton {
1515
--spectrum-clear-button-height: var(--spectrum-component-height-100);
1616
--spectrum-clear-button-width: var(--spectrum-component-height-100);
17-
--spectrum-clear-button-padding: var(--spectrum-in-field-button-edge-to-fill);
17+
--spectrum-clear-button-padding: var(--spectrum-in-field-button-edge-to-fill-medium);
1818

1919
--spectrum-clear-button-icon-color: var(--spectrum-neutral-content-color-default);
2020
--spectrum-clear-button-icon-color-hover: var(--spectrum-neutral-content-color-hover);
@@ -26,46 +26,25 @@
2626
--spectrum-clear-button-background-color-down: transparent;
2727
--spectrum-clear-button-background-color-key-focus: transparent;
2828

29-
&.spectrum-ClearButton--staticWhite {
30-
--spectrum-clear-button-background-color-hover: var(--spectrum-transparent-white-400);
31-
--spectrum-clear-button-background-color-down: var(--spectrum-transparent-white-500);
32-
--spectrum-clear-button-background-color-key-focus: var(--spectrum-transparent-white-400);
33-
}
34-
3529
&.spectrum-ClearButton--sizeS {
3630
--spectrum-clear-button-height: var(--spectrum-component-height-75);
3731
--spectrum-clear-button-width: var(--spectrum-component-height-75);
32+
33+
--spectrum-clear-button-padding: var(--spectrum-in-field-button-edge-to-fill-small);
3834
}
3935

4036
&.spectrum-ClearButton--sizeL {
4137
--spectrum-clear-button-height: var(--spectrum-component-height-200);
4238
--spectrum-clear-button-width: var(--spectrum-component-height-200);
39+
40+
--spectrum-clear-button-padding: var(--spectrum-in-field-button-edge-to-fill-large);
4341
}
4442

4543
&.spectrum-ClearButton--sizeXL {
4644
--spectrum-clear-button-height: var(--spectrum-component-height-300);
4745
--spectrum-clear-button-width: var(--spectrum-component-height-300);
48-
}
49-
50-
&.spectrum-ClearButton--quiet {
51-
--mod-clear-button-background-color: transparent;
52-
--mod-clear-button-background-color-hover: transparent;
53-
--mod-clear-button-background-color-down: transparent;
54-
--mod-clear-button-background-color-key-focus: transparent;
55-
}
56-
57-
&.spectrum-ClearButton--staticWhite {
58-
--spectrum-clear-button-background-color-hover: var(--spectrum-transparent-white-400);
59-
--spectrum-clear-button-background-color-down: var(--spectrum-transparent-white-500);
60-
--spectrum-clear-button-background-color-key-focus: var(--spectrum-transparent-white-400);
61-
62-
--mod-clear-button-icon-color: var(--spectrum-white);
63-
--mod-clear-button-icon-color-hover: var(--spectrum-white);
64-
--mod-clear-button-icon-color-down: var(--spectrum-white);
65-
--mod-clear-button-icon-color-key-focus: var(--spectrum-white);
66-
--mod-clear-button-icon-color-disabled: var(--spectrum-disabled-static-white-content-color);
6746

68-
--mod-clear-button-background-color: transparent;
47+
--spectrum-clear-button-padding: var(--spectrum-in-field-button-edge-to-fill-extra-large);
6948
}
7049

7150
&:disabled,
@@ -80,9 +59,8 @@
8059
.spectrum-ClearButton {
8160
block-size: var(--mod-clear-button-height, var(--spectrum-clear-button-height));
8261
inline-size: var(--mod-clear-button-width, var(--spectrum-clear-button-width));
83-
border-radius: 100%;
8462

85-
background-color: var(--mod-clear-button-background-color, transparent);
63+
background-color: transparent;
8664
margin: 0;
8765
padding: var(--mod-clear-button-padding, var(--spectrum-clear-button-padding));
8866

@@ -93,6 +71,10 @@
9371
cursor: pointer;
9472
}
9573

74+
&:focus-visible {
75+
outline: none;
76+
}
77+
9678
> .spectrum-Icon {
9779
/* @safari10 Workaround for https://bugs.webkit.org/show_bug.cgi?id=169700 */
9880
margin-block: 0;
@@ -109,6 +91,7 @@
10991

11092
&:not(:disabled):active {
11193
color: var(--mod-clear-button-icon-color-down, var(--spectrum-clear-button-icon-color-down));
94+
transform: perspective(var(--spectrum-component-size-minimum-perspective-down)) translateZ(var(--spectrum-component-size-difference-down));
11295

11396
.spectrum-ClearButton-fill {
11497
background-color: var(--mod-clear-button-background-color-down, var(--spectrum-clear-button-background-color-down));
@@ -134,21 +117,12 @@
134117

135118
inline-size: 100%;
136119
block-size: 100%;
137-
border-radius: 100%;
138120

139121
display: flex;
140122
align-items: center;
141123
justify-content: center;
142124
}
143125

144-
/* @deprecated .spectrum-ClearButton--overBackground */
145-
.spectrum-ClearButton--staticWhite,
146-
.spectrum-ClearButton--overBackground {
147-
&:focus-visible {
148-
outline: none;
149-
}
150-
}
151-
152126
@media (forced-colors: active) {
153127
.spectrum-ClearButton {
154128
&:not(:disabled) {

components/clearbutton/stories/clearbutton.stories.js

Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,22 @@
11
import { Sizes } from "@spectrum-css/preview/decorators";
22
import { disableDefaultModes } from "@spectrum-css/preview/modes";
3-
import { isDisabled, isQuiet, size, staticColor } from "@spectrum-css/preview/types";
3+
import { isActive, isDisabled, isHovered, size } from "@spectrum-css/preview/types";
44
import metadata from "../dist/metadata.json";
55
import packageJson from "../package.json";
66
import { ClearButtonGroup } from "./clearbutton.test.js";
77
import { Template } from "./template.js";
88

99
/**
10-
* The clear button component is an in-field button used in search and tags.
11-
*
12-
* ## Usage Notes
13-
14-
Use the correct cross icon size that corresponds to the t-shirt size you require for the clear button.
15-
16-
<table>
17-
<thead>
18-
<tr>
19-
<th>**T-Shirt Size**</th>
20-
<th>**Icon Size**</th>
21-
</tr>
22-
</thead>
23-
<tbody>
24-
<tr>
25-
<td>spectrum-ClearButton--sizeS</td>
26-
<td>spectrum-css-icon-Cross75</td>
27-
</tr>
28-
<tr>
29-
<td>spectrum-ClearButton--sizeM</td>
30-
<td>spectrum-css-icon-Cross100</td>
31-
</tr>
32-
<tr>
33-
<td>spectrum-ClearButton--sizeL</td>
34-
<td>spectrum-css-icon-Cross200</td>
35-
</tr>
36-
<tr>
37-
<td>spectrum-ClearButton--sizeXL</td>
38-
<td>spectrum-css-icon-Cross300</td>
39-
</tr>
40-
</tbody>
41-
</table>
10+
* The clear button component is an in-field button used in [search](/docs/components-search-field--docs) and [tags](/docs/components-tag--docs).
4211
*/
4312
export default {
4413
title: "Clear button",
4514
component: "ClearButton",
4615
argTypes: {
4716
size: size(["s", "m", "l", "xl"]),
4817
isDisabled,
49-
isQuiet,
50-
staticColor: {
51-
...staticColor,
52-
options: ["white"],
53-
},
18+
isHovered,
19+
isActive,
5420
isFocusable: {
5521
table: { disable: true },
5622
type: { name: "boolean" },
@@ -60,21 +26,25 @@ export default {
6026
rootClass: "spectrum-ClearButton",
6127
size: "m",
6228
isDisabled: false,
63-
isQuiet: false,
29+
isHovered: false,
30+
isActive: false,
6431
},
6532
parameters: {
6633
packageJson,
6734
metadata,
35+
status: {
36+
type: "migrated",
37+
},
38+
tags: ["migrated"],
6839
},
6940
};
7041

71-
/**
72-
* The default size for clear button is medium.
73-
*/
74-
7542
export const Default = ClearButtonGroup.bind({});
7643
Default.args = {};
7744

45+
/**
46+
* When disabled, the clear button color changes to `--spectrum-disabled-content-color` and is not interactive.
47+
*/
7848
export const Disabled = Template.bind({});
7949
Disabled.args = {
8050
isDisabled: true,
@@ -85,17 +55,36 @@ Disabled.parameters = {
8555
};
8656

8757
/**
88-
* The `.spectrum-ClearButton--quiet` class will use a transparent background (including when the Express theme is active).
89-
*/
90-
export const Quiet = Template.bind({});
91-
Quiet.args = {
92-
isQuiet: true,
93-
};
94-
Quiet.tags = ["!dev"];
95-
Quiet.parameters = {
96-
chromatic: { disableSnapshot: true },
97-
};
58+
* Use the correct cross icon size that corresponds to the t-shirt size you require for the clear button. The default size is medium.
9859
60+
<table>
61+
<thead>
62+
<tr>
63+
<th>**T-Shirt Size**</th>
64+
<th>**Icon Size**</th>
65+
</tr>
66+
</thead>
67+
<tbody>
68+
<tr>
69+
<td>spectrum-ClearButton--sizeS</td>
70+
<td>spectrum-css-icon-Cross75</td>
71+
</tr>
72+
<tr>
73+
<td>spectrum-ClearButton--sizeM</td>
74+
<td>spectrum-css-icon-Cross100</td>
75+
</tr>
76+
<tr>
77+
<td>spectrum-ClearButton--sizeL</td>
78+
<td>spectrum-css-icon-Cross200</td>
79+
</tr>
80+
<tr>
81+
<td>spectrum-ClearButton--sizeXL</td>
82+
<td>spectrum-css-icon-Cross300</td>
83+
</tr>
84+
</tbody>
85+
</table>
86+
*
87+
*/
9988
export const Sizing = (args, context) => Sizes({
10089
Template,
10190
withHeading: false,
@@ -109,15 +98,6 @@ Sizing.parameters = {
10998

11099
};
111100

112-
export const OverBackground = ClearButtonGroup.bind({});
113-
OverBackground.tags = ["!dev"];
114-
OverBackground.args = {
115-
staticColor: "white",
116-
};
117-
OverBackground.parameters = {
118-
chromatic: { disableSnapshot: true },
119-
};
120-
121101
// ********* VRT ONLY ********* //
122102
export const WithForcedColors = ClearButtonGroup.bind({});
123103
WithForcedColors.tags = ["!autodocs", "!dev"];

components/clearbutton/stories/clearbutton.test.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,19 @@ export const ClearButtonGroup = Variants({
99
{
1010
testHeading: "Default",
1111
},
12-
{
13-
testHeading: "Quiet",
14-
isQuiet: true,
15-
},
16-
{
17-
testHeading: "Static white",
18-
staticColor: "white",
19-
},
20-
{
21-
testHeading: "Static white - quiet",
22-
staticColor: "white",
23-
isQuiet: true,
24-
},
2512
],
2613
stateData: [
2714
{
2815
testHeading: "Disabled",
2916
isDisabled: true,
3017
},
18+
{
19+
testHeading: "Hover",
20+
isHovered: true,
21+
},
22+
{
23+
testHeading: "Down",
24+
isActive: true,
25+
},
3126
]
3227
});

components/clearbutton/stories/template.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import "../index.css";
1010
export const Template = ({
1111
rootClass = "spectrum-ClearButton",
1212
isDisabled = false,
13+
isHovered = false,
14+
isActive = false,
1315
size = "m",
14-
isQuiet = false,
1516
isFocusable = true,
16-
staticColor,
1717
id = getRandomId("clearbutton"),
1818
onclick = () => {},
1919
customClasses = [],
@@ -24,14 +24,9 @@ export const Template = ({
2424
class=${classMap({
2525
[rootClass]: true,
2626
[`${rootClass}--size${size?.toUpperCase()}`]: typeof size !== "undefined",
27-
[`${rootClass}--quiet`]: isQuiet,
28-
[`${rootClass}--overBackground`]: staticColor === "white",
29-
/**
30-
* There aren't styles for `--staticWhite` in clear button (yet)
31-
* but this makes it easier to support in the testing grid
32-
*/
33-
[`${rootClass}--staticWhite`]: staticColor === "white",
3427
"is-disabled": isDisabled,
28+
"is-hover": isHovered,
29+
"is-active": isActive,
3530
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
3631
})}
3732
id=${ifDefined(id)}

0 commit comments

Comments
 (0)