UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

168 lines (167 loc) 5.21 kB
/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.5.0-next.4 */ import { h, Host } from "@stencil/core"; import { getElementProp, toAriaBoolean } from "../../utils/dom"; import { CSS, SLOTS } from "./resources"; export class SegmentedControlItem { constructor() { this.checked = false; this.iconFlipRtl = false; this.iconStart = undefined; this.iconEnd = undefined; this.value = undefined; } handleCheckedChange() { this.calciteInternalSegmentedControlItemChange.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.segmentedControlItemIcon, flipRtl: this.iconFlipRtl, icon: this.iconStart, key: "icon-start", scale: "s" })) : null; const iconEndEl = this.iconEnd ? (h("calcite-icon", { class: CSS.segmentedControlItemIcon, flipRtl: this.iconFlipRtl, icon: this.iconEnd, key: "icon-end", scale: "s" })) : 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", "label--outline-fill": appearance === "outline-fill" } }, this.iconStart ? iconStartEl : null, h("slot", null, value), h("slot", { name: SLOTS.input }), this.iconEnd ? iconEndEl : null))); } static get is() { return "calcite-segmented-control-item"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["segmented-control-item.scss"] }; } static get styleUrls() { return { "$": ["segmented-control-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" }, "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" }, "iconStart": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "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": false, "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": "calciteInternalSegmentedControlItemChange", "name": "calciteInternalSegmentedControlItemChange", "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" }]; } }