@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
1 lines • 7.24 kB
JavaScript
import{r as t,c as i,h as e,H as a,g as s}from"./p-ff68592a.js";import{g as c}from"./p-fbd3d700.js";import{g as r}from"./p-a4e6e35b.js";const o=class{constructor(e){t(this,e),this.calciteRadioButtonChange=i(this,"calciteRadioButtonChange",7),this.calciteRadioButtonCheckedChange=i(this,"calciteRadioButtonCheckedChange",7),this.calciteRadioButtonFocusedChange=i(this,"calciteRadioButtonFocusedChange",7),this.checked=!1,this.disabled=!1,this.focused=!1,this.hidden=!1,this.hovered=!1,this.required=!1,this.scale="m",this.theme="light",this.formResetHandler=()=>{var t;this.checked=this.initialChecked,this.initialChecked&&(null===(t=this.input)||void 0===t||t.setAttribute("checked",""))},this.onInputBlur=()=>{this.focused=!1,this.calciteRadioButtonFocusedChange.emit()},this.onInputFocus=()=>{this.focused=!0,this.calciteRadioButtonFocusedChange.emit()}}checkedChanged(t){t&&this.uncheckOtherRadioButtonsInGroup(),this.input&&(this.input.checked=t),this.calciteRadioButtonCheckedChange.emit(t)}disabledChanged(t){this.input.disabled=t}focusedChanged(t){this.input&&(t&&!this.el.hasAttribute("hidden")?this.input.focus():this.input.blur())}hiddenChanged(t){this.input.hidden=t}nameChanged(t){if(this.name===t)return;this.input&&(this.input.name=t),this.checkLastRadioButton();const i=this.rootNode.querySelector(`input[name="${this.name}"]:checked`);(null==i?void 0:i.value)||this.uncheckAllRadioButtonsInGroup()}requiredChanged(t){this.input.required=t}checkLastRadioButton(){const t=Array.from(this.rootNode.querySelectorAll("calcite-radio-button")).filter((t=>t.name===this.name)).filter((t=>t.checked));if((null==t?void 0:t.length)>1){const i=t[t.length-1];t.filter((t=>t!==i)).forEach((t=>{t.checked=!1,t.emitCheckedChange()}))}}async emitCheckedChange(){this.calciteRadioButtonCheckedChange.emit()}uncheckAllRadioButtonsInGroup(){Array.from(this.rootNode.querySelectorAll("calcite-radio-button")).filter((t=>t.name===this.name)).forEach((t=>{t.checked&&(t.checked=!1,t.focused=!1)}))}uncheckOtherRadioButtonsInGroup(){Array.from(this.rootNode.querySelectorAll("calcite-radio-button")).filter((t=>t.name===this.name&&t.guid!==this.guid)).forEach((t=>{t.checked&&(t.checked=!1,t.focused=!1)}))}check(t){!this.el.closest("label")||t.target!==this.el&&t.target!==this.radio||t.preventDefault(),this.disabled||this.hidden||(this.uncheckOtherRadioButtonsInGroup(),this.checked=!0,this.focused=!0,this.calciteRadioButtonChange.emit())}mouseenter(){this.hovered=!0}mouseleave(){this.hovered=!1}connectedCallback(){this.rootNode=this.el.getRootNode(),this.guid=this.el.id||"calcite-radio-button-"+r(),this.initialChecked=this.checked,this.name&&this.checkLastRadioButton();const t=this.el.closest("form");t&&t.addEventListener("reset",this.formResetHandler)}componentDidLoad(){this.focused&&this.input.focus()}disconnectedCallback(){const t=this.el.closest("form");t&&t.removeEventListener("reset",this.formResetHandler)}renderLabel(){return this.el.textContent?e("calcite-label",{dir:c(this.el),"disable-spacing":!0,disabled:this.disabled,for:this.guid+"-input",layout:"inline",scale:this.scale},e("slot",null)):e("slot",null)}render(){return e(a,{labeled:!!this.el.textContent},e("input",{"aria-label":this.value||this.guid,checked:this.checked,disabled:this.disabled,hidden:this.hidden,id:this.guid+"-input",name:this.name,onBlur:this.onInputBlur,onFocus:this.onInputFocus,ref:t=>this.input=t,required:this.required,style:{opacity:"0",position:"fixed",zIndex:"-1"},type:"radio",value:this.value}),e("calcite-radio",{checked:this.checked,disabled:this.disabled,focused:this.focused,hidden:this.hidden,hovered:this.hovered,ref:t=>this.radio=t,scale:this.scale,theme:this.theme}),this.renderLabel())}get el(){return s(this)}static get watchers(){return{checked:["checkedChanged"],disabled:["disabledChanged"],focused:["focusedChanged"],hidden:["hiddenChanged"],name:["nameChanged"],required:["requiredChanged"]}}};o.style="@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}.sc-calcite-radio-button:root{--calcite-popper-transition:150ms ease-in-out}[hidden].sc-calcite-radio-button-h{display:none}[theme=dark].sc-calcite-radio-button-h,[theme=dark] .sc-calcite-radio-button-h{--calcite-ui-blue-1:#00A0FF;--calcite-ui-blue-2:#0087D7;--calcite-ui-blue-3:#47BBFF;--calcite-ui-green-1:#36DA43;--calcite-ui-green-2:#11AD1D;--calcite-ui-green-3:#44ED51;--calcite-ui-yellow-1:#FFC900;--calcite-ui-yellow-2:#F4B000;--calcite-ui-yellow-3:#FFE24D;--calcite-ui-red-1:#FE583E;--calcite-ui-red-2:#F3381B;--calcite-ui-red-3:#FF7465;--calcite-ui-background:#202020;--calcite-ui-foreground-1:#2b2b2b;--calcite-ui-foreground-2:#353535;--calcite-ui-foreground-3:#404040;--calcite-ui-text-1:#ffffff;--calcite-ui-text-2:#bfbfbf;--calcite-ui-text-3:#9f9f9f;--calcite-ui-border-1:#4a4a4a;--calcite-ui-border-2:#404040;--calcite-ui-border-3:#353535;--calcite-ui-border-4:#757575;--calcite-ui-border-5:#9f9f9f}.sc-calcite-radio-button-h{cursor:pointer;display:inline-block}[labeled].sc-calcite-radio-button-h{--calcite-label-margin-bottom:0;-ms-flex-align:center;align-items:center;display:-ms-inline-flexbox;display:inline-flex;gap:8px}[disabled].sc-calcite-radio-button-h{cursor:default}.sc-calcite-radio-button-h[disabled]>.sc-calcite-radio-button-s>calcite-label{cursor:default}[scale=s][labeled].sc-calcite-radio-button-h{line-height:1.33;margin-bottom:8px;margin-right:12px}@supports not (display: grid){[scale=s][labeled].sc-calcite-radio-button-h calcite-radio.sc-calcite-radio-button{margin-right:8px}}[scale=m][labeled].sc-calcite-radio-button-h{line-height:1.15;margin-bottom:8px;margin-right:16px}@supports not (display: grid){[scale=m][labeled].sc-calcite-radio-button-h calcite-radio.sc-calcite-radio-button{margin-right:8px}}[scale=l][labeled].sc-calcite-radio-button-h{gap:12px;line-height:1.2;margin-bottom:10px;margin-right:20px}@supports not (display: grid){[scale=l][labeled].sc-calcite-radio-button-h calcite-radio.sc-calcite-radio-button{margin-right:12px}}[hidden].sc-calcite-radio-button-h{display:none}";export{o as calcite_radio_button}