All components

Switch

Toggle an immediately applied preference.

Examples

Toggle an immediately applied preference

React code
import { Label, Switch } from "@accelerate/react/components";

export function Example() {
  return (
    <>
      <Label><Switch defaultChecked name="notifications" /> Enable notifications</Label>
    </>
  );
}
Angular code
import { Component } from "@angular/core";
import { AccLabel, AccSwitch } from "@accelerate/angular/components";

@Component({
  selector: "app-example",
  imports: [
    AccLabel,
    AccSwitch,
  ],
  template: `
    <label accLabel><input accSwitch checked name="notifications"> Enable notifications</label>
  `,
})
export class Example {}

Disabled preference

React code
import { Label, Switch } from "@accelerate/react/components";

export function Example() {
  return (
    <>
      <Label><Switch disabled /> Enable previews</Label>
    </>
  );
}
Angular code
import { Component } from "@angular/core";
import { AccLabel, AccSwitch } from "@accelerate/angular/components";

@Component({
  selector: "app-example",
  imports: [
    AccLabel,
    AccSwitch,
  ],
  template: `
    <label accLabel><input accSwitch disabled> Enable previews</label>
  `,
})
export class Example {}

Installation

Source preview. The expanded component catalog is ahead of the public npm releases. To run these examples in your own application, use packages built from the SDK source used for the previews or a release that includes the APIs below.

React
@accelerate/ui@0.4.0 and @accelerate/react@0.4.0
Angular
@accelerate/ui@0.4.0 and @accelerate/angular@0.2.0

Load @accelerate/ui/theme.css and put acc-theme on the app or the region using Accelerator components. See the framework setup guide for the theme and adapter conventions.

Usage

Styled checkbox announced as a switch, with native form and disabled behavior.

Import the React component Switch from @accelerate/react/components. For Angular, add AccSwitch to the standalone component’s imports and use <input accSwitch>.

Examples use these React parts: Label, Switch. The Angular examples show the corresponding directives and template hosts.

API reference

checked
Uses the native checkbox checked state.
role
Exposes the state as a switch to assistive technology.