import type { ComponentInterface, EventEmitter } from '@stencil/core'; import { Component, Element, Event, Host, Prop, Watch, h } from '@stencil/core'; import type { LegacyFormController } from '@utils/forms'; import { createLegacyFormController } from '@utils/forms'; import type { Attributes } from '@utils/helpers'; import { getAriaLabel, inheritAriaAttributes, renderHiddenInput } from '@utils/helpers'; import { printIonWarning } from '@utils/logging'; import { createColorClasses, hostContext } from '@utils/theme'; import { getIonMode } from '../../global/ionic-global'; import type { Color, Mode, StyleEventDetail } from '../../interface'; import type { CheckboxChangeEventDetail } from './checkbox-interface'; /** * @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use. * * @slot - The label text to associate with the checkbox. Use the "labelPlacement" property to control where the label is placed relative to the checkbox. * * @part container - The container for the checkbox mark. * @part mark - The checkmark used to indicate the checked state. */ @Component({ tag: 'ion-checkbox', styleUrls: { ios: 'checkbox.ios.scss', md: 'checkbox.md.scss', }, shadow: true, }) export class Checkbox implements ComponentInterface { private inputId = `ion-cb-${checkboxIds++}`; private focusEl?: HTMLElement; private legacyFormController!: LegacyFormController; // TODO(FW-3100): remove this private inheritedAttributes: Attributes = {}; // TODO(FW-3100): remove this // This flag ensures we log the deprecation warning at most once. private hasLoggedDeprecationWarning = false; @Element() el!: HTMLIonCheckboxElement; /** * 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({ reflect: true }) color?: Color; /** * The name of the control, which is submitted with the form data. */ @Prop() name: string = this.inputId; /** * If `true`, the checkbox is selected. */ @Prop({ mutable: true }) checked = false; /** * If `true`, the checkbox will visually appear as indeterminate. */ @Prop({ mutable: true }) indeterminate = false; /** * If `true`, the user cannot interact with the checkbox. */ @Prop() disabled = false; /** * The value of the checkbox does not mean if it's checked or not, use the `checked` * property for that. * * The value of a checkbox is analogous to the value of an ``, * it's only used when the checkbox participates in a native `