Skip to content

Commit 8067e22

Browse files
committed
docs(button): update clear-button details
1 parent 4cb6376 commit 8067e22

File tree

7 files changed

+197
-158
lines changed

7 files changed

+197
-158
lines changed

.changeset/hot-cups-report.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
---
2-
'@spectrum-web-components/clear-button': patch
2+
'@spectrum-web-components/button': minor
3+
'@spectrum-web-components/clear-button': minor
34
'@spectrum-web-components/styles': patch
45
---
56

6-
More details forthcoming
7+
Clear button styles have been updated to the latest Spectrum CSS version of the clear button.
8+
9+
As the updated styles now offer additional styling options, we have added the following API to the clear button:
10+
11+
- `quiet` - when set to true, the button will be rendered as a quiet button. This is useful for cases where you want to use the clear button in a more subtle way.
12+
- `disabled` - when set to true, the button will be rendered as a disabled button.
13+
- `static-color` - currently this only supports the `white` context color. This is useful for cases where the button appears on a dark background texture. This is a replacement for the previously used `variant="overBackground"` attribute which is deprecated.
14+
15+
### Deprecation
16+
17+
The `variant="overBackground"` attribute is deprecated; please use the new `static-color="white"` attribute instead. When this property is used in the component, a deprecation warning will be shown in the console when in debug mode. The `variant` attribute will be removed in a future release.

packages/button/clear-button.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ The label for an `<sp-clear-button>` element can be set via it's default slot or
9393
</sp-tab-panel>
9494
</sp-tabs>
9595

96+
#### Quiet
97+
98+
The `quiet` attribute will render the `<sp-clear-button>` as a quiet button. This is useful for cases where you want to use the clear button in a more subtle way.
99+
100+
```html
101+
<sp-clear-button quiet label="Clear content"></sp-clear-button>
102+
```
103+
104+
#### Static color
105+
106+
The `static-color` attribute will render the `<sp-clear-button>` with a static color. This is useful for cases where the button appears on a dark background texture. This is a replacement for the previously used `variant="overBackground"` attribute which is deprecated.
107+
108+
```html
109+
<sp-clear-button static-color="white" label="Clear content"></sp-clear-button>
110+
```
111+
96112
### States
97113

98114
In addition to the variant, the `<sp-clear-button>` elements supports a disabled state, which can be applied by adding the attribute `disabled`.

packages/button/src/ClearButton.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,21 @@ export class ClearButton extends SizedMixin(StyledButton, {
6464
return [...super.styles, buttonStyles, crossMediumStyles];
6565
}
6666

67+
@property({ type: Boolean, reflect: true })
68+
public quiet = false;
69+
6770
/**
6871
* The visual variant to apply to this button.
6972
* @deprecated Use `static-color='white'` instead.
7073
*/
7174
@property({ reflect: true })
7275
public set variant(variant: 'overBackground' | undefined) {
73-
const oldValue = this.variant;
76+
const oldValue = this._variant;
77+
const oldStaticColor = this.staticColor;
7478
if (variant !== 'overBackground') {
7579
this.removeAttribute('variant');
7680
this._variant = undefined;
81+
this.staticColor = undefined;
7782
return;
7883
}
7984

@@ -92,6 +97,7 @@ export class ClearButton extends SizedMixin(StyledButton, {
9297
}
9398

9499
this.requestUpdate('variant', oldValue);
100+
this.requestUpdate('staticColor', oldStaticColor);
95101
}
96102

97103
public get variant(): 'overBackground' | undefined {
@@ -103,7 +109,7 @@ export class ClearButton extends SizedMixin(StyledButton, {
103109
/**
104110
* The visual variant to apply to this button.
105111
*/
106-
@property({ reflect: true })
112+
@property({ reflect: true, attribute: 'static-color' })
107113
public staticColor: 'white' | undefined;
108114

109115
protected override get buttonContent(): TemplateResult[] {

packages/button/test/clear-button.test.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
import '@spectrum-web-components/button/sp-clear-button.js';
1414
import { ClearButton } from '@spectrum-web-components/button';
1515
import { ElementSize } from '@spectrum-web-components/base';
16-
import { expect, fixture, html } from '@open-wc/testing';
16+
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
1717
import { testForLitDevWarnings } from '../../../test/testing-helpers';
18+
import { SinonStub, stub } from 'sinon';
1819

1920
describe('Clear Button', () => {
20-
testForLitDevWarnings(
21-
async () =>
22-
await fixture<ClearButton>(html`
23-
<sp-clear-button size="m" label="Clear"></sp-clear-button>
24-
`)
21+
testForLitDevWarnings(async () =>
22+
fixture<ClearButton>(html`
23+
<sp-clear-button size="m" label="Clear"></sp-clear-button>
24+
`)
2525
);
2626
(['s', 'm', 'l', 'xl'] as ElementSize[]).map((size) => {
2727
it(`loads - ${size}`, async () => {
@@ -32,6 +32,21 @@ describe('Clear Button', () => {
3232
await expect(el).to.be.accessible();
3333
});
3434
});
35+
it(`loads static-color="white" when variant="overBackground"`, async () => {
36+
const el = await fixture<ClearButton>(html`
37+
<sp-clear-button
38+
label="Clear"
39+
variant="overBackground"
40+
></sp-clear-button>
41+
`);
42+
43+
await elementUpdated(el);
44+
45+
// Check that the staticColor is set to white
46+
expect(el.staticColor).to.equal('white');
47+
expect(el.hasAttribute('static-color')).to.be.true;
48+
expect(el.getAttribute('static-color')).to.equal('white');
49+
});
3550

3651
describe('dev mode', () => {
3752
let consoleStub: SinonStub;
@@ -61,11 +76,6 @@ describe('Clear Button', () => {
6176

6277
expect(consoleStub).to.be.calledOnce;
6378
expect(warning.includes(expectedContent)).to.be.true;
64-
65-
// Check that the staticColor is set to white
66-
expect(el.staticColor).to.equal('white');
67-
expect(el.hasAttribute('static-color')).to.be.true;
68-
expect(el.getAttribute('static-color')).to.equal('white');
6979
});
7080
});
7181
});

packages/clear-button/src/clear-button-overrides.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,3 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
:host {
14-
--spectrum-clear-button-background-color: var(--system-clear-button-background-color);
15-
--spectrum-clear-button-background-color-hover: var(--system-clear-button-background-color-hover);
16-
--spectrum-clear-button-background-color-down: var(--system-clear-button-background-color-down);
17-
--spectrum-clear-button-background-color-key-focus: var(--system-clear-button-background-color-key-focus);
18-
}
19-
20-
:host([static-color="white"]) {
21-
--spectrum-clear-button-background-color-hover: var(--system-clear-button-static-white-background-color-hover);
22-
--spectrum-clear-button-background-color-down: var(--system-clear-button-static-white-background-color-down);
23-
--spectrum-clear-button-background-color-key-focus: var(--system-clear-button-static-white-background-color-key-focus);
24-
}

packages/clear-button/src/clear-button.css

Lines changed: 139 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,146 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
@import url("./spectrum-clear-button.css");
14-
@import url("./clear-button-overrides.css");
13+
:host {
14+
--spectrum-clear-button-background-color: var(--system-clear-button-background-color);
15+
--spectrum-clear-button-background-color-hover: var(--system-clear-button-background-color-hover);
16+
--spectrum-clear-button-background-color-down: var(--system-clear-button-background-color-down);
17+
--spectrum-clear-button-background-color-key-focus: var(--system-clear-button-background-color-key-focus);
18+
}
19+
20+
:host([static-color="white"]) {
21+
--spectrum-clear-button-background-color-hover: var(--system-clear-button-static-white-background-color-hover);
22+
--spectrum-clear-button-background-color-down: var(--system-clear-button-static-white-background-color-down);
23+
--spectrum-clear-button-background-color-key-focus: var(--system-clear-button-static-white-background-color-key-focus);
24+
}
1525

1626
:host {
27+
--spectrum-clear-button-height: var(--spectrum-component-height-100);
28+
--spectrum-clear-button-width: var(--spectrum-component-height-100);
29+
--spectrum-clear-button-padding: var(--spectrum-in-field-button-edge-to-fill);
30+
--spectrum-clear-button-icon-color: var(--spectrum-neutral-content-color-default);
31+
--spectrum-clear-button-icon-color-hover: var(--spectrum-neutral-content-color-hover);
32+
--spectrum-clear-button-icon-color-down: var(--spectrum-neutral-content-color-down);
33+
--spectrum-clear-button-icon-color-key-focus: var(--spectrum-neutral-content-color-key-focus);
34+
1735
box-sizing: border-box;
36+
block-size: var(--mod-clear-button-height, var(--spectrum-clear-button-height));
37+
inline-size: var(--mod-clear-button-width, var(--spectrum-clear-button-width));
38+
background-color: var(--mod-clear-button-background-color, transparent);
39+
padding: var(--mod-clear-button-padding, var(--spectrum-clear-button-padding));
40+
color: var(--mod-clear-button-icon-color, var(--spectrum-clear-button-icon-color));
41+
border: none;
42+
border-radius: 100%;
43+
margin: 0;
44+
}
45+
46+
:host([size="s"]) {
47+
--spectrum-clear-button-height: var(--spectrum-component-height-75);
48+
--spectrum-clear-button-width: var(--spectrum-component-height-75);
49+
}
50+
51+
:host([size="l"]) {
52+
--spectrum-clear-button-height: var(--spectrum-component-height-200);
53+
--spectrum-clear-button-width: var(--spectrum-component-height-200);
54+
}
55+
56+
:host([size="xl"]) {
57+
--spectrum-clear-button-height: var(--spectrum-component-height-300);
58+
--spectrum-clear-button-width: var(--spectrum-component-height-300);
59+
}
60+
61+
:host([quiet]) {
62+
--mod-clear-button-background-color: transparent;
63+
--mod-clear-button-background-color-hover: transparent;
64+
--mod-clear-button-background-color-down: transparent;
65+
--mod-clear-button-background-color-key-focus: transparent;
66+
}
67+
68+
:host([static-color="white"]) {
69+
--mod-clear-button-icon-color: var(--spectrum-white);
70+
--mod-clear-button-icon-color-hover: var(--spectrum-white);
71+
--mod-clear-button-icon-color-down: var(--spectrum-white);
72+
--mod-clear-button-icon-color-key-focus: var(--spectrum-white);
73+
--mod-clear-button-icon-color-disabled: var(--spectrum-disabled-static-white-content-color);
74+
--mod-clear-button-background-color: transparent;
75+
}
76+
77+
:host(:disabled),
78+
:host([disabled]) {
79+
--mod-clear-button-icon-color: var(--mod-clear-button-icon-color-disabled, var(--spectrum-disabled-content-color));
80+
--mod-clear-button-icon-color-hover: var(--spectrum-disabled-content-color);
81+
--mod-clear-button-icon-color-down: var(--spectrum-disabled-content-color);
82+
--mod-clear-button-background-color: var(--mod-clear-button-background-color-disabled, transparent);
83+
}
84+
85+
:host(:not(:disabled)),
86+
:host(:not([disabled])) {
87+
cursor: pointer;
88+
}
89+
90+
.icon {
91+
margin-block: 0;
92+
margin-inline: auto;
93+
}
94+
95+
@media (hover: hover) {
96+
:host(:hover:not(:disabled)),
97+
:host(:hover:not([disabled])) {
98+
color: var(--highcontrast-clear-button-icon-color-hover, var(--mod-clear-button-icon-color-hover, var(--spectrum-clear-button-icon-color-hover)));
99+
}
100+
101+
:host(:hover:not(:disabled)) .fill,
102+
:host(:hover:not([disabled])) .fill {
103+
background-color: var(--mod-clear-button-background-color-hover, var(--spectrum-clear-button-background-color-hover));
104+
}
105+
}
106+
107+
:host(:is(:active, [active]):not(:disabled)),
108+
:host(:is(:active, [active]):not([disabled])) {
109+
color: var(--mod-clear-button-icon-color-down, var(--spectrum-clear-button-icon-color-down));
110+
}
111+
112+
:host(:is(:active, [active]):not(:disabled)),
113+
:host(:is(:active, [active]):not([disabled])) .fill {
114+
background-color: var(--mod-clear-button-background-color-down, var(--spectrum-clear-button-background-color-down));
115+
}
116+
117+
:host(:not(:disabled):focus-visible),
118+
:host(:not([disabled]):focus-visible),
119+
:host(:not(:disabled):focus-within),
120+
:host(:not([disabled]):focus-within) {
121+
color: var(--mod-clear-button-icon-color-key-focus, var(--spectrum-clear-button-icon-color-key-focus));
122+
}
123+
124+
:host(:not(:disabled):focus-visible) .fill,
125+
:host(:not([disabled]):focus-visible) .fill,
126+
:host(:not(:disabled):focus-within) .fill,
127+
:host(:not([disabled]):focus-within) .fill {
128+
background-color: var(--mod-clear-button-background-color-key-focus, var(--spectrum-clear-button-background-color-key-focus));
129+
}
130+
131+
.icon {
132+
color: inherit;
133+
}
134+
135+
.fill {
136+
background-color: var(--mod-clear-button-background-color, var(--spectrum-clear-button-background-color));
137+
inline-size: 100%;
138+
block-size: 100%;
139+
border-radius: 100%;
140+
justify-content: center;
141+
align-items: center;
142+
display: flex;
143+
}
144+
145+
:host([variant="overBackground"]:focus-visible),
146+
:host([static-color="white"]:focus-visible) {
147+
outline: none;
148+
}
149+
150+
@media (forced-colors: active) {
151+
:host(:not(:disabled)),
152+
:host(:not([disabled])) {
153+
--highcontrast-clear-button-icon-color-hover: Highlight;
154+
}
18155
}

0 commit comments

Comments
 (0)