GitHub

Switch

A switch allows users to toggle the state of a single setting.

Components

DaffSwitchComponent

import { DaffSwitchComponent } from '@daffodil/design/switch'

The switch component provides a way to toggle between two settings.

<daff-switch>Label</daff-switch>
@Component()
class DaffSwitchComponent extends DaffSizableDirective<DaffSwitchSize> implements DaffDisableable {
  checked: ModelSignal<boolean> = model(false)
  defaultSize: "sm"

  labelPosition: InputSignal<DaffSwitchLabelPosition> = DaffSwitchLabelPositionEnum.LEFT
  @Input() disabled: any
  id: InputSignal<string> = 'daff-switch-' + switchIncrementalId++
  @Input() size: DaffButtonSize

  toggled: OutputEmitterRef<boolean> = output<boolean>()
}

Inputs

labelPosition
InputSignal<DaffSwitchLabelPosition>
DefaultDaffSwitchLabelPositionEnum.LEFT
Description

The position of the label relative to the switch.

disabled
any
Default
Description

Whether the switch is disabled.

id
InputSignal<string>
Default'daff-switch-' + switchIncrementalId++
Description

The unique id of the switch. Defaults to an autogenerated value. When using this, it's your responsibility to ensure that the id for each switch is unique.

It gets assigned to the for attribute on the <label> inside of the switch.

size
DaffButtonSize
Default
Description

The size of the component.

Outputs

toggled
OutputEmitterRef<boolean>
Default
Description

Output event triggered when the switch has been toggled.

Properties

checked
ModelSignal<boolean>
Defaultmodel(false)
Description

Current state of switch (on/off).

defaultSize
"sm"
Default
Description

Sets a default size.