UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

131 lines (125 loc) 6.37 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 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-55f8a3b7.js'); const observers = require('./observers-83b3999d.js'); const loadable = require('./loadable-53f729bb.js'); const radioButtonGroupCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}:host{display:flex;max-inline-size:100vw}:host([layout=horizontal]){flex-direction:row;flex-wrap:wrap}:host([layout=horizontal][scale=s]){gap:1rem}:host([layout=horizontal][scale=m]){gap:1.25rem}:host([layout=horizontal][scale=l]){gap:1.5rem}:host([layout=vertical]){flex-direction:column}"; const RadioButtonGroup = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteRadioButtonGroupChange = index.createEvent(this, "calciteRadioButtonGroupChange", 6); // -------------------------------------------------------------------------- // // Private Properties // // -------------------------------------------------------------------------- this.mutationObserver = observers.createObserver("mutation", () => this.passPropsToRadioButtons()); //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- this.passPropsToRadioButtons = () => { this.radioButtons = Array.from(this.el.querySelectorAll("calcite-radio-button")); this.selectedItem = Array.from(this.radioButtons).find((radioButton) => radioButton.checked) || null; if (this.radioButtons.length > 0) { this.radioButtons.forEach((radioButton) => { radioButton.disabled = this.disabled || radioButton.disabled; radioButton.hidden = this.hidden; radioButton.name = this.name; radioButton.required = this.required; radioButton.scale = this.scale; }); } }; this.disabled = false; this.hidden = false; this.layout = "horizontal"; this.name = undefined; this.required = false; this.selectedItem = null; this.scale = "m"; this.radioButtons = []; } onDisabledChange() { this.passPropsToRadioButtons(); } onHiddenChange() { this.passPropsToRadioButtons(); } onLayoutChange() { this.passPropsToRadioButtons(); } onScaleChange() { this.passPropsToRadioButtons(); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- connectedCallback() { this.passPropsToRadioButtons(); this.mutationObserver?.observe(this.el, { childList: true, subtree: true }); } componentWillLoad() { loadable.setUpLoadableComponent(this); } componentDidLoad() { loadable.setComponentLoaded(this); } disconnectedCallback() { this.mutationObserver?.disconnect(); } getFocusableRadioButton() { return this.radioButtons.find((radiobutton) => !radiobutton.disabled) ?? null; } //-------------------------------------------------------------------------- // // Public Method // //-------------------------------------------------------------------------- /** Sets focus on the fist focusable `calcite-radio-button` element in the component. */ async setFocus() { await loadable.componentLoaded(this); if (this.selectedItem && !this.selectedItem.disabled) { this.selectedItem.setFocus(); return; } if (this.radioButtons.length > 0) { this.getFocusableRadioButton()?.setFocus(); } } //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- radioButtonChangeHandler(event) { this.selectedItem = event.target; this.calciteRadioButtonGroupChange.emit(); } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- render() { return (index.h(index.Host, { role: "radiogroup" }, index.h("slot", null))); } get el() { return index.getElement(this); } static get watchers() { return { "disabled": ["onDisabledChange"], "hidden": ["onHiddenChange"], "layout": ["onLayoutChange"], "scale": ["onScaleChange"] }; } }; RadioButtonGroup.style = radioButtonGroupCss; exports.calcite_radio_button_group = RadioButtonGroup;