Latitude ComponentsLibrary 0.1.0

Switch

Turns a setting on or off immediately, with no Save step. When the choice is saved with a form, use acheckbox. Rules: UX Elements & Rules → Switch. The old Switcher is deprecated; use a segmented control.

Add it to a page

Load the pinned file once in your Latitude Site or web page, then use the tag.

<script type="module" src="https://web-components.sites.latd.com/components/lat-switch/0.1.0/lat-switch.js"></script>

The file is an ES module. It loads Lit, the design-system tokens and the Roobert stylesheet from this catalog once per page, however many components you use.

Version0.1.0
File/components/lat-switch/0.1.0/lat-switch.js (1.1 KB gzipped)
SHA-2566963a7f0ee6a8ec198020f42ac0d1c0835f1c10d1149b6584bd8fce8dfafbcb0

Permutations

Off and on

Dark
Autoplay next video Show captions
Light
Autoplay next video Show captions
<lat-switch>Autoplay next video</lat-switch>
<lat-switch checked>Show captions</lat-switch>

Disabled

Dark
Collect emails Anonymous viewing
Light
Collect emails Anonymous viewing
<lat-switch disabled>Collect emails</lat-switch>
<lat-switch disabled checked>Anonymous viewing</lat-switch>

Without visible text

Dark
Light
<lat-switch label="Comments"></lat-switch>
<lat-switch label="Reactions" checked></lat-switch>

Settings list

Dark
Comments Reactions One-touch rating
Light
Comments Reactions One-touch rating
<div style="display: flex; flex-direction: column">
  <lat-switch checked>Comments</lat-switch>
  <lat-switch checked>Reactions</lat-switch>
  <lat-switch>One-touch rating</lat-switch>
</div>

Attributes

AttributeValuesNotes
checkedbooleanOn. Its value when the page loads is what a form reset restores.
name, valuetextSubmitted as name=value while on. value defaults to on.
disabledbooleanShown at 40% opacity. Also follows a disabled <fieldset>.
labeltextThe name for screen readers when there's no visible text.

Events

EventWhen
changeThe user turns it on or off. Apply the setting now; read checked on the element.
inputSame moment as change.