Skip to content

Commit ca10da0

Browse files
docs(swatch): adding swatch documentation (#5673)
* docs(swatch): adding swatch documentation * docs(swatch): adding suggested changes --------- Co-authored-by: Rajdeep Chandra <[email protected]>
1 parent c3d5558 commit ca10da0

File tree

1 file changed

+56
-24
lines changed

1 file changed

+56
-24
lines changed

packages/swatch/README.md

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Description
1+
## Overview
22

33
An `<sp-swatch>` shows a small sample of a fill — such as a color, gradient, texture, or material — that is intended to be applied to an object.
44

@@ -7,23 +7,25 @@ An `<sp-swatch>` shows a small sample of a fill — such as a color, gradient, t
77
[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/swatch?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/swatch)
88
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/swatch?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/swatch)
99

10-
```
10+
```bash
1111
yarn add @spectrum-web-components/swatch
1212
```
1313

1414
Import the side effectful registration of `<sp-swatch>` via:
1515

16-
```
16+
```js
1717
import '@spectrum-web-components/swatch/sp-swatch.js';
1818
```
1919

2020
When looking to leverage the `Swatch` base class as a type and/or for extension purposes, do so via:
2121

22-
```
22+
```js
2323
import { Swatch } from '@spectrum-web-components/swatch';
2424
```
2525

26-
## Sizes
26+
### Options
27+
28+
#### Sizes
2729

2830
<sp-tabs selected="m" auto label="Size Attribute Options">
2931
<sp-tab value="xs">Extra Small</sp-tab>
@@ -156,11 +158,13 @@ import { Swatch } from '@spectrum-web-components/swatch';
156158
</sp-tab-panel>
157159
</sp-tabs>
158160

159-
## Modifying attributes
161+
#### Variants
160162

161163
An `<sp-swatch>` element can be modified by the following attributes/properties to customize its delivery as desired for your use case: `border`, `color`, `disabled`, `mixedValue` (accepted as the `mixed-value` attribute), `nothing`, `rounding`, and `shape`. Use these in concert with each other for a variety of final visual deliveries.
162164

163-
### Border
165+
<sp-tabs selected="border" auto label="Variant Options">
166+
<sp-tab value="border">Border</sp-tab>
167+
<sp-tab-panel value="border">
164168

165169
The `border` attribute/property is not required and when applied accepts the values of `none` or `light`.
166170

@@ -172,7 +176,9 @@ The `border` attribute/property is not required and when applied accepts the val
172176
</sp-swatch-group>
173177
```
174178

175-
### Color
179+
</sp-tab-panel>
180+
<sp-tab value="color">Color</sp-tab>
181+
<sp-tab-panel value="color">
176182

177183
The `color` attribute/property determines the color value that the `<sp-swatch>` element will deliver.
178184

@@ -184,19 +190,9 @@ The `color` attribute/property determines the color value that the `<sp-swatch>`
184190
</sp-swatch-group>
185191
```
186192

187-
### Disabled
188-
189-
The `disabled` attribute/property determines prevents interaction on the `<sp-swatch>` element.
190-
191-
```html
192-
<sp-swatch-group>
193-
<sp-swatch disabled color="rgb(255 0 0 / 0.7)"></sp-swatch>
194-
<sp-swatch disabled color="orange"></sp-swatch>
195-
<sp-swatch disabled color="var(--spectrum-magenta-500)"></sp-swatch>
196-
</sp-swatch-group>
197-
```
198-
199-
### Mixed value
193+
</sp-tab-panel>
194+
<sp-tab value="mixed-value">Mixed Value</sp-tab>
195+
<sp-tab-panel value="mixed-value">
200196

201197
The `mixed-value` attribute and `mixedValue` property outline when an `<sp-swatch>` element represents more than one color.
202198

@@ -210,7 +206,9 @@ The `mixed-value` attribute and `mixedValue` property outline when an `<sp-swatc
210206

211207
Please note that the `aria-checked="mixed"` value only applies when the swatch is in a group with `selects="multiple"`
212208

213-
### Nothing
209+
</sp-tab-panel>
210+
<sp-tab value="nothing">Nothing</sp-tab>
211+
<sp-tab-panel value="nothing">
214212

215213
The `nothing` attribute/property outlines that the `<sp-swatch>` represents no color or that it represents "transparent".
216214

@@ -222,7 +220,9 @@ The `nothing` attribute/property outlines that the `<sp-swatch>` represents no c
222220
</sp-swatch-group>
223221
```
224222

225-
### Rounding
223+
</sp-tab-panel>
224+
<sp-tab value="rounding">Rounding</sp-tab>
225+
<sp-tab-panel value="rounding">
226226

227227
The `rounding` attribute/property is not required and when applied accepts the values of `none` or `full`.
228228

@@ -234,7 +234,9 @@ The `rounding` attribute/property is not required and when applied accepts the v
234234
</sp-swatch-group>
235235
```
236236

237-
### Shape
237+
</sp-tab-panel>
238+
<sp-tab value="shape">Shape</sp-tab>
239+
<sp-tab-panel value="shape">
238240

239241
The `shape` attribute/property is not required and when applied accepts the values of `rectangle`.
240242

@@ -244,3 +246,33 @@ The `shape` attribute/property is not required and when applied accepts the valu
244246
<sp-swatch color="rgb(255 0 0 / 0.7)" shape="rectangle"></sp-swatch>
245247
</sp-swatch-group>
246248
```
249+
250+
</sp-tab-panel>
251+
</sp-tabs>
252+
253+
### States
254+
255+
#### Disabled
256+
257+
The `disabled` attribute/property determines prevents interaction on the `<sp-swatch>` element.
258+
259+
```html
260+
<sp-swatch-group>
261+
<sp-swatch disabled color="rgb(255 0 0 / 0.7)"></sp-swatch>
262+
<sp-swatch disabled color="orange"></sp-swatch>
263+
<sp-swatch disabled color="var(--spectrum-magenta-500)"></sp-swatch>
264+
</sp-swatch-group>
265+
```
266+
267+
### Accessibility
268+
269+
#### Best practices
270+
271+
- Ensure swatches have sufficient color contrast for visibility.
272+
- Verify that swatches are appropriately labeled for screen readers.
273+
274+
#### Keyboard navigation
275+
276+
- `Tab`: Move focus to the next focusable element
277+
- `Arrow keys`: Navigate between swatches in the group and move the focus indicator
278+
- `Enter` or `Space`: Select the focused swatch

0 commit comments

Comments
 (0)