/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.0.0-beta.97 */ import { h, Host } from "@stencil/core"; import { getElementProp, toAriaBoolean } from "../../utils/dom"; import { SLOTS, CSS } from "./resources"; export class RadioGroupItem { constructor() { //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- /** When `true`, the component is checked. */ this.checked = false; /** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */ this.iconFlipRtl = false; /** * Specifies the placement of the icon. * * @deprecated Use either `iconStart` or `iconEnd` but do not combine them with `icon` and `iconPosition`. */ this.iconPosition = "start"; } handleCheckedChange() { this.calciteInternalRadioGroupItemChange.emit(); } render() { const { checked, value } = this; const scale = getElementProp(this.el, "scale", "m"); const appearance = getElementProp(this.el, "appearance", "solid"); const layout = getElementProp(this.el, "layout", "horizontal"); const iconStartEl = this.iconStart ? (h("calcite-icon", { class: CSS.radioGroupItemIcon, flipRtl: this.iconFlipRtl, icon: this.iconStart, key: "icon-start", scale: "s" })) : null; const iconEndEl = this.iconEnd ? (h("calcite-icon", { class: CSS.radioGroupItemIcon, flipRtl: this.iconFlipRtl, icon: this.iconEnd, key: "icon-end", scale: "s" })) : null; const iconEl = (h("calcite-icon", { class: CSS.radioGroupItemIcon, flipRtl: this.iconFlipRtl, icon: this.icon, key: "icon", scale: "s" })); const iconAtStart = this.icon && this.iconPosition === "start" && !this.iconStart ? iconEl : null; const iconAtEnd = this.icon && this.iconPosition === "end" && !this.iconEnd ? iconEl : null; return (h(Host, { "aria-checked": toAriaBoolean(checked), "aria-label": value, role: "radio" }, h("label", { class: { "label--scale-s": scale === "s", "label--scale-m": scale === "m", "label--scale-l": scale === "l", "label--horizontal": layout === "horizontal", "label--outline": appearance === "outline" } }, iconAtStart, this.iconStart ? iconStartEl : null, h("slot", null, value), h("slot", { name: SLOTS.input }), iconAtEnd, this.iconEnd ? iconEndEl : null))); } static get is() { return "calcite-radio-group-item"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["radio-group-item.scss"] }; } static get styleUrls() { return { "$": ["radio-group-item.css"] }; } static get properties() { return { "checked": { "type": "boolean", "mutable": true, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "When `true`, the component is checked." }, "attribute": "checked", "reflect": true, "defaultValue": "false" }, "icon": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [{ "name": "deprecated", "text": "Use either `iconStart` or `iconEnd` but do not combine them with `icon` and `iconPosition`." }], "text": "Specifies an icon to display." }, "attribute": "icon", "reflect": true }, "iconFlipRtl": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "When `true`, the icon will be flipped when the element direction is right-to-left (`\"rtl\"`)." }, "attribute": "icon-flip-rtl", "reflect": true, "defaultValue": "false" }, "iconPosition": { "type": "string", "mutable": false, "complexType": { "original": "Position", "resolved": "\"end\" | \"start\"", "references": { "Position": { "location": "import", "path": "../interfaces" } } }, "required": false, "optional": true, "docs": { "tags": [{ "name": "deprecated", "text": "Use either `iconStart` or `iconEnd` but do not combine them with `icon` and `iconPosition`." }], "text": "Specifies the placement of the icon." }, "attribute": "icon-position", "reflect": true, "defaultValue": "\"start\"" }, "iconStart": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Specifies an icon to display at the start of the component." }, "attribute": "icon-start", "reflect": true }, "iconEnd": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "Specifies an icon to display at the end of the component." }, "attribute": "icon-end", "reflect": true }, "value": { "type": "any", "mutable": true, "complexType": { "original": "any | null", "resolved": "any", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "The component's value." }, "attribute": "value", "reflect": false } }; } static get events() { return [{ "method": "calciteInternalRadioGroupItemChange", "name": "calciteInternalRadioGroupItemChange", "bubbles": true, "cancelable": false, "composed": true, "docs": { "tags": [{ "name": "internal", "text": undefined }], "text": "Fires when the item has been selected." }, "complexType": { "original": "void", "resolved": "void", "references": {} } }]; } static get elementRef() { return "el"; } static get watchers() { return [{ "propName": "checked", "methodName": "handleCheckedChange" }]; } }