Skip to content

Commit d4346c7

Browse files
committed
fix(spinner): remove diameter attribute in favor of CSS custom property
1 parent 856d178 commit d4346c7

4 files changed

Lines changed: 55 additions & 14 deletions

File tree

elements/pf-v6-spinner/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# PatternFly Elements Spinner
2+
3+
`<pf-v6-spinner>` is used to indicate to users that an action is in progress.
4+
5+
Read more about Spinner in the [PatternFly Elements Spinner documentation](https://patternflyelements.org/components/spinner)
6+
7+
## Installation
8+
9+
Load `<pf-v6-spinner>` via CDN:
10+
11+
```html
12+
<script src="https://jspm.dev/@patternfly/elements/pf-v6-spinner/pf-v6-spinner.js"></script>
13+
```
14+
15+
Or, if you are using [NPM](https://npm.im), install it
16+
17+
```bash
18+
npm install @patternfly/elements
19+
```
20+
21+
Then once installed, import it to your application:
22+
23+
```js
24+
import '@patternfly/elements/pf-v6-spinner/pf-v6-spinner.js';
25+
```
26+
27+
## Usage
28+
```html
29+
<pf-v6-spinner>Loading...</pf-v6-spinner>
30+
```
31+
32+
### Size variations
33+
34+
```html
35+
<pf-v6-spinner size="sm">Loading...</pf-v6-spinner>
36+
<pf-v6-spinner size="md">Loading...</pf-v6-spinner>
37+
<pf-v6-spinner size="lg">Loading...</pf-v6-spinner>
38+
<pf-v6-spinner size="xl">Loading...</pf-v6-spinner>
39+
```
40+
41+
### Custom size
42+
43+
```html
44+
<pf-v6-spinner style="--pf-v6-c-spinner--diameter: 80px">Loading...</pf-v6-spinner>
45+
```
46+
47+
## Discrepancies from React
48+
49+
| React Prop | Web Component | Rationale |
50+
|------------|---------------|-----------|
51+
| `diameter` | `--pf-v6-c-spinner--diameter` CSS custom property | React's `diameter` prop abstracts setting this CSS custom property. In HTML, authors can set the custom property directly via `style`, so a dedicated attribute is not needed. |

elements/pf-v6-spinner/demo/custom-size.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
name: Custom size
3-
description: A spinner can have a custom diameter using the `diameter` attribute.
3+
description: A spinner can have a custom diameter using the `--pf-v6-c-spinner--diameter` CSS custom property.
44
---
55
<section>
6-
<pf-v6-spinner diameter="80px" accessible-label="Custom size spinner">Loading...</pf-v6-spinner>
6+
<pf-v6-spinner style="--pf-v6-c-spinner--diameter: 80px" accessible-label="Custom size spinner">Loading...</pf-v6-spinner>
77
</section>
88

99
<script type="module">

elements/pf-v6-spinner/pf-v6-spinner.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ export class PfV6Spinner extends LitElement {
3030
*/
3131
@property({ type: Boolean, reflect: true }) inline = false;
3232

33-
/** Custom diameter of spinner set as CSS variable */
34-
@property({ reflect: true }) diameter?: string;
35-
3633
/** Accessible label describing what is loading */
3734
@property({ attribute: 'accessible-label' }) accessibleLabel?: string;
3835

@@ -48,13 +45,6 @@ export class PfV6Spinner extends LitElement {
4845
this.#internals.ariaLabel = label;
4946
this.#internals.ariaValueText = label;
5047
}
51-
if (changed.has('diameter')) {
52-
if (this.diameter) {
53-
this.style.setProperty('--pf-v6-c-spinner--diameter', this.diameter);
54-
} else {
55-
this.style.removeProperty('--pf-v6-c-spinner--diameter');
56-
}
57-
}
5848
}
5949

6050
override render(): TemplateResult {

elements/pf-v6-spinner/test/pf-v6-spinner.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ describe('<pf-v6-spinner>', function() {
103103
}
104104
});
105105

106-
describe('diameter attribute', function() {
106+
describe('custom diameter via CSS custom property', function() {
107107
it('sets the element diameter', async function() {
108108
const customDiameterValue = 80;
109109
const element = await createFixture<PfV6Spinner>(html`
110-
<pf-v6-spinner diameter="${customDiameterValue}px">Loading...</pf-v6-spinner>
110+
<pf-v6-spinner style="--pf-v6-c-spinner--diameter: ${customDiameterValue}px">Loading...</pf-v6-spinner>
111111
`);
112112
expect(element.offsetWidth).to.equal(customDiameterValue);
113113
});

0 commit comments

Comments
 (0)