import { Component, ComponentInterface, Element, Event, EventEmitter, Host, Prop, State, Watch, h } from '@stencil/core'; import { getIonMode } from '../../global/ionic-global'; import { Color, Gesture, GestureDetail, StyleEventDetail, ToggleChangeEventDetail } from '../../interface'; import { hapticSelection } from '../../utils/haptic'; import { findItemLabel, renderHiddenInput } from '../../utils/helpers'; import { createColorClasses, hostContext } from '../../utils/theme'; /** * @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use. * * @part track - The background track of the toggle. * @part handle - The toggle handle, or knob, used to change the checked state. */ @Component({ tag: 'ion-toggle', styleUrls: { ios: 'toggle.ios.scss', md: 'toggle.md.scss' }, shadow: true }) export class Toggle implements ComponentInterface { private inputId = `ion-tg-${toggleIds++}`; private gesture?: Gesture; private buttonEl?: HTMLElement; private lastDrag = 0; @Element() el!: HTMLElement; @State() activated = false; /** * The color to use from your application's color palette. * Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. * For more information on colors, see [theming](/docs/theming/basics). */ @Prop() color?: Color; /** * The name of the control, which is submitted with the form data. */ @Prop() name: string = this.inputId; /** * If `true`, the toggle is selected. */ @Prop({ mutable: true }) checked = false; /** * If `true`, the user cannot interact with the toggle. */ @Prop() disabled = false; /** * The value of the toggle does not mean if it's checked or not, use the `checked` * property for that. * * The value of a toggle is analogous to the value of a ``, * it's only used when the toggle participates in a native `