1.0.0 • Published 8 months ago

@spectrum-web-components/swatch v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

Description

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.

Usage

See it on NPM! How big is this package in your project?

yarn add @spectrum-web-components/swatch

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

import '@spectrum-web-components/swatch/sp-swatch.js';

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

import { Swatch } from '@spectrum-web-components/swatch';

Sizes

<div style="display: flex;gap: 5px;">
    <sp-swatch color="rgb(255 0 0 / 0.7)" size="xs"></sp-swatch>
    <sp-swatch rounding="none" color="rgb(255 0 0 / 0.7)" size="xs"></sp-swatch>
    <sp-swatch rounding="full" color="rgb(255 0 0 / 0.7)" size="xs"></sp-swatch>
    <sp-swatch border="light" color="rgb(255 0 0 / 0.7)" size="xs"></sp-swatch>
    <sp-swatch border="none" color="rgb(255 0 0 / 0.7)" size="xs"></sp-swatch>
    <sp-swatch nothing size="xs"></sp-swatch>
    <sp-swatch
        shape="rectangle"
        color="rgb(255 0 0 / 0.7)"
        size="xs"
    ></sp-swatch>
    <sp-swatch
        shape="rectangle"
        disabled
        color="rgb(255 0 0 / 0.7)"
        size="xs"
    ></sp-swatch>
    <sp-swatch
        rounding="full"
        shape="rectangle"
        mixed-value
        size="xs"
    ></sp-swatch>
</div>
<div style="display: flex;gap: 5px;">
    <sp-swatch color="rgb(255 0 0 / 0.7)" size="s"></sp-swatch>
    <sp-swatch rounding="none" color="rgb(255 0 0 / 0.7)" size="s"></sp-swatch>
    <sp-swatch rounding="full" color="rgb(255 0 0 / 0.7)" size="s"></sp-swatch>
    <sp-swatch border="light" color="rgb(255 0 0 / 0.7)" size="s"></sp-swatch>
    <sp-swatch border="none" color="rgb(255 0 0 / 0.7)" size="s"></sp-swatch>
    <sp-swatch nothing size="s"></sp-swatch>
    <sp-swatch
        shape="rectangle"
        color="rgb(255 0 0 / 0.7)"
        size="s"
    ></sp-swatch>
    <sp-swatch
        shape="rectangle"
        disabled
        color="rgb(255 0 0 / 0.7)"
        size="s"
    ></sp-swatch>
    <sp-swatch
        rounding="full"
        shape="rectangle"
        mixed-value
        size="s"
    ></sp-swatch>
</div>
<div style="display: flex;gap: 5px;">
    <sp-swatch color="rgb(255 0 0 / 0.7)" size="m"></sp-swatch>
    <sp-swatch rounding="none" color="rgb(255 0 0 / 0.7)" size="m"></sp-swatch>
    <sp-swatch rounding="full" color="rgb(255 0 0 / 0.7)" size="m"></sp-swatch>
    <sp-swatch border="light" color="rgb(255 0 0 / 0.7)" size="m"></sp-swatch>
    <sp-swatch border="none" color="rgb(255 0 0 / 0.7)" size="m"></sp-swatch>
    <sp-swatch nothing size="m"></sp-swatch>
    <sp-swatch
        shape="rectangle"
        color="rgb(255 0 0 / 0.7)"
        size="m"
    ></sp-swatch>
    <sp-swatch
        shape="rectangle"
        disabled
        color="rgb(255 0 0 / 0.7)"
        size="m"
    ></sp-swatch>
    <sp-swatch
        rounding="full"
        shape="rectangle"
        mixed-value
        size="m"
    ></sp-swatch>
</div>
<div style="display: flex;gap: 5px;">
    <sp-swatch color="rgb(255 0 0 / 0.7)" size="l"></sp-swatch>
    <sp-swatch rounding="none" color="rgb(255 0 0 / 0.7)" size="l"></sp-swatch>
    <sp-swatch rounding="full" color="rgb(255 0 0 / 0.7)" size="l"></sp-swatch>
    <sp-swatch border="light" color="rgb(255 0 0 / 0.7)" size="l"></sp-swatch>
    <sp-swatch border="none" color="rgb(255 0 0 / 0.7)" size="l"></sp-swatch>
    <sp-swatch nothing size="l"></sp-swatch>
    <sp-swatch
        shape="rectangle"
        color="rgb(255 0 0 / 0.7)"
        size="l"
    ></sp-swatch>
    <sp-swatch
        shape="rectangle"
        disabled
        color="rgb(255 0 0 / 0.7)"
        size="l"
    ></sp-swatch>
    <sp-swatch
        rounding="full"
        shape="rectangle"
        mixed-value
        size="l"
    ></sp-swatch>
</div>

Modifying attributes

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.

Border

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

<sp-swatch-group>
    <sp-swatch color="rgb(255 0 0 / 0.7)"></sp-swatch>
    <sp-swatch color="rgb(255 0 0 / 0.7)" border="light"></sp-swatch>
    <sp-swatch color="rgb(255 0 0 / 0.7)" border="none"></sp-swatch>
</sp-swatch-group>

Color

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

<sp-swatch-group>
    <sp-swatch color="rgb(255 0 0 / 0.7)"></sp-swatch>
    <sp-swatch color="orange"></sp-swatch>
    <sp-swatch color="var(--spectrum-magenta-500)"></sp-swatch>
</sp-swatch-group>

Disabled

The disabled attribute/property determines prevents interaction on the <sp-swatch> element.

<sp-swatch-group>
    <sp-swatch disabled color="rgb(255 0 0 / 0.7)"></sp-swatch>
    <sp-swatch disabled color="orange"></sp-swatch>
    <sp-swatch disabled color="var(--spectrum-magenta-500)"></sp-swatch>
</sp-swatch-group>

Mixed value

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

<sp-swatch-group selects="multiple">
    <sp-swatch mixed-value></sp-swatch>
    <sp-swatch mixed-value rounding="full"></sp-swatch>
    <sp-swatch mixed-value shape="rectangle"></sp-swatch>
</sp-swatch-group>

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

Nothing

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

<sp-swatch-group>
    <sp-swatch nothing></sp-swatch>
    <sp-swatch nothing rounding="full"></sp-swatch>
    <sp-swatch nothing shape="rectangle"></sp-swatch>
</sp-swatch-group>

Rounding

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

<sp-swatch-group>
    <sp-swatch color="rgb(255 0 0 / 0.7)"></sp-swatch>
    <sp-swatch color="rgb(255 0 0 / 0.7)" rounding="none"></sp-swatch>
    <sp-swatch color="rgb(255 0 0 / 0.7)" rounding="full"></sp-swatch>
</sp-swatch-group>

Shape

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

<sp-swatch-group>
    <sp-swatch color="rgb(255 0 0 / 0.7)"></sp-swatch>
    <sp-swatch color="rgb(255 0 0 / 0.7)" shape="rectangle"></sp-swatch>
</sp-swatch-group>
0.50.0-beta.11

8 months ago

0.50.0-beta.12

8 months ago

0.50.0-beta.10

8 months ago

1.1.0-beta.1

8 months ago

1.1.0-beta.0

8 months ago

0.50.0-beta.9

8 months ago

0.50.0-beta.8

8 months ago

0.50.0-beta.7

8 months ago

0.50.0-beta.6

8 months ago

0.50.0-beta.5

8 months ago

0.50.0-beta.4

8 months ago

1.0.0

8 months ago

1.0.0-rc.9

8 months ago

1.0.0-rc.7

8 months ago

1.0.0-rc.8

8 months ago

1.0.0-rc.5

8 months ago

1.0.0-rc.6

8 months ago

1.0.0-rc.10

8 months ago

1.0.0-rc.3

8 months ago

1.0.0-rc.4

8 months ago

1.0.0-rc.1

8 months ago

1.0.0-rc.2

8 months ago

0.50.0-beta.3

8 months ago

0.50.0-beta.2

8 months ago

1.0.0-rc.0

8 months ago

0.50.0-beta.1

8 months ago

0.50.0-beta.0

8 months ago

0.49.0

8 months ago

0.49.0-beta.2

8 months ago

0.49.0-beta.1

8 months ago

0.48.1

9 months ago

0.48.0-beta.0

9 months ago

0.48.0-beta.1

9 months ago

0.48.0-beta.2

9 months ago

0.49.0-beta.0

9 months ago

0.43.0

1 year ago

0.48.0

9 months ago

0.44.0

11 months ago

0.45.0

11 months ago

0.46.0

10 months ago

0.42.5

1 year ago

0.47.1

10 months ago

0.47.2

10 months ago

0.47.0

10 months ago

0.42.4

1 year ago

0.42.3

1 year ago

0.42.2

1 year ago

0.42.1

1 year ago

0.42.0

1 year ago

0.41.2

1 year ago

0.41.1

1 year ago

0.41.0

1 year ago

0.40.5

1 year ago

0.40.4

1 year ago

0.40.3

1 year ago

0.40.2

1 year ago

0.40.1

2 years ago

0.38.0

2 years ago

0.35.1-rc.34

2 years ago

0.36.0

2 years ago

0.34.0

2 years ago

0.35.1-rc.43

2 years ago

0.35.1-rc.41

2 years ago

0.40.0

2 years ago

0.39.1

2 years ago

0.39.0

2 years ago

0.35.1-rc.15

2 years ago

0.37.0

2 years ago

0.35.0

2 years ago

0.39.4

2 years ago

0.39.3

2 years ago

0.39.2

2 years ago

0.34.1-rc.0

2 years ago

0.35.1-rc.25

2 years ago

0.35.1-rc.26

2 years ago

0.35.1-rc.24

2 years ago

0.31.1-react.21

2 years ago

0.32.0

2 years ago

0.30.0

2 years ago

0.31.1-react.3

2 years ago

0.31.1-react.2

2 years ago

0.33.2

2 years ago

0.33.0

2 years ago

0.31.0

2 years ago

0.3.9

2 years ago

0.3.10

2 years ago

0.3.9-overlay.22

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.9-overlay.9

2 years ago

0.3.9-overlay.8

2 years ago

0.3.6-react.75

2 years ago

0.3.7-overlay.37

2 years ago

0.3.6-react.50

2 years ago

0.3.6-react.48

2 years ago

0.3.6-react.49

2 years ago

0.3.6

2 years ago

0.3.6-react.32

2 years ago

0.3.3-react.54

3 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago

0.1.4-devmode2.0

3 years ago

0.1.4-devmode.0

3 years ago

0.2.0-devmode.0

3 years ago

0.1.3

3 years ago

0.1.3-devmode.0

3 years ago

0.1.2

3 years ago

0.1.2-devmode.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago