Skip to content

Commit 68e309b

Browse files
authored
docs(opacity-checkerboard): enhance README with detailed usage (#5751)
* docs(opacity-checkerboard): enhance README with detailed usage * docs(opacity-checkerboard): update README for improved accessibility practices
1 parent 72d807c commit 68e309b

File tree

1 file changed

+111
-8
lines changed

1 file changed

+111
-8
lines changed
Lines changed: 111 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,132 @@
1-
## Description
1+
## Overview
22

3-
The `opacity-checkerboard` class is used to highlight opacity. Leverage these styles in your component as outlined below to unify you application's visuals with those delivered by various Spectrum Web Components.
3+
The `opacity-checkerboard` class provides a CSS utility that displays a checkerboard pattern background, commonly used to highlight transparent or semi-transparent areas in UI components. This visual indicator helps users distinguish between transparent and opaque regions, making it an essential tool for color pickers, image editors, and other components that work with opacity.
44

5-
## Usage
5+
### Usage
66

7-
Import the styles from the `opacity-checkerboard` CSS:
7+
[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/opacity-checkerboard?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/opacity-checkerboard)
8+
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/opacity-checkerboard?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/opacity-checkerboard)
89

10+
```bash
11+
yarn add @spectrum-web-components/opacity-checkerboard
912
```
13+
14+
Import the opacity checkerboard styles from:
15+
16+
```javascript
1017
import opacityCheckerBoardStyles from '@spectrum-web-components/opacity-checkerboard/src/opacity-checkerboard.css.js';
1118
```
1219

13-
Add it to your component's styles array before your component's styles. The order that you include the styles in makes a difference, because selectors within opacity checkerboard may have the same
14-
specificity as those within your component.
20+
### Integration
1521

16-
```js
22+
To integrate the opacity checkerboard styles into your component, add them to your component's styles array. The order of inclusion is important, as selectors within opacity checkerboard may have the same specificity as those within your component:
23+
24+
```javascript
1725
public static override get styles(): CSSResultArray {
1826
return [opacityCheckerBoardStyles, styles];
1927
}
2028
```
2129

22-
Use the `opacity-checkerboard` class in your component's `render()` method:
30+
### Examples
31+
32+
#### Basic usage
33+
34+
Apply the `opacity-checkerboard` class to any element that needs to display the checkerboard pattern:
2335

2436
```html-live demo
2537
<div
2638
class="opacity-checkerboard"
2739
style="inline-size: 100px; block-size: 100px;"
40+
aria-hidden="true"
2841
></div>
2942
```
43+
44+
#### With overlaid content
45+
46+
The opacity checkerboard works well as a background for elements with partial transparency:
47+
48+
```html-live
49+
<div
50+
class="opacity-checkerboard"
51+
style="inline-size: 200px; block-size: 200px; position: relative;"
52+
aria-hidden="true"
53+
>
54+
<div
55+
style="
56+
position: absolute;
57+
inset: 0;
58+
background-color: rgba(255, 0, 0, 0.5);
59+
"
60+
></div>
61+
</div>
62+
```
63+
64+
### Accessibility
65+
66+
When implementing the opacity checkerboard pattern, ensure proper accessibility by:
67+
68+
- **Hiding from screen readers**: Use `aria-hidden="true"` on the checkerboard element since it's purely visual
69+
- **Providing semantic information**: Use separate text nodes or live regions to convey opacity information
70+
- **Using live regions**: Implement `aria-live` regions to announce opacity changes dynamically
71+
- **Descriptive context**: Provide meaningful descriptions of the actual color and opacity values, not the visual pattern
72+
73+
#### Screen reader support
74+
75+
The opacity checkerboard is a purely visual indicator and should remain hidden from screen readers. Instead, provide semantic information through separate text nodes or live regions that update as opacity changes:
76+
77+
```html-live
78+
<div class="color-container">
79+
<div
80+
class="opacity-checkerboard"
81+
style="inline-size: 100px; block-size: 100px;"
82+
aria-hidden="true"
83+
></div>
84+
<div class="visually-hidden" aria-live="polite" id="opacity-status">
85+
Current opacity: 75%
86+
</div>
87+
</div>
88+
```
89+
90+
For components that change opacity dynamically, use a live region to announce changes:
91+
92+
```html-live
93+
<div class="dynamic-opacity-example">
94+
<div
95+
class="opacity-checkerboard"
96+
style="inline-size: 100px; block-size: 100px; position: relative;"
97+
aria-hidden="true"
98+
>
99+
<div
100+
style="
101+
position: absolute;
102+
inset: 0;
103+
background-color: rgba(255, 0, 0, 0.6);
104+
"
105+
></div>
106+
</div>
107+
<div aria-live="assertive" class="visually-hidden">
108+
Opacity changed to 60%
109+
</div>
110+
</div>
111+
```
112+
113+
#### Keyboard navigation
114+
115+
When the opacity checkerboard is part of an interactive component, ensure it doesn't interfere with keyboard navigation:
116+
117+
```html-live
118+
<button
119+
class="color-button"
120+
aria-label="Select red color with 50% opacity"
121+
aria-describedby="opacity-description"
122+
>
123+
<span
124+
class="opacity-checkerboard"
125+
style="inline-size: 40px; block-size: 40px; display: block;"
126+
aria-hidden="true"
127+
></span>
128+
<span id="opacity-description" class="visually-hidden">
129+
Red color with 50% transparency
130+
</span>
131+
</button>
132+
```

0 commit comments

Comments
 (0)