UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

6 lines 11.7 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{r as t,c as i,h as a,H as e,a as n}from"./p-8789682d.js";import{b as o,v as l,t as r}from"./p-68f223ec.js";import{a as c,c as s,d as m,H as d}from"./p-51fa67d7.js";import{c as h,d as u,u as f}from"./p-0d8324b6.js";import{c as p,d as g}from"./p-4dcc9524.js";import{s as b,a as v,c as y}from"./p-deebcc06.js";import"./p-d2aa9245.js";import"./p-9280476e.js";import"./p-7fb6664e.js";const k=class{constructor(a){t(this,a),this.calciteSegmentedControlChange=i(this,"calciteSegmentedControlChange",6),this.handleClick=t=>{this.disabled||"calcite-segmented-control-item"===t.target.localName&&this.selectItem(t.target,!0)},this.appearance="solid",this.disabled=!1,this.form=void 0,this.required=!1,this.layout="horizontal",this.name=void 0,this.scale="m",this.value=null,this.selectedItem=void 0,this.width="auto"}valueHandler(t){this.getItems().forEach((i=>i.checked=i.value===t))}handleSelectedItemChange(t,i){if(this.value=t?.value,t===i)return;const a=this.getItems(),e=a.filter((i=>i===t)).pop();e?this.selectItem(e):a[0]&&(a[0].tabIndex=0)}componentWillLoad(){b(this);const t=this.getItems(),i=t.filter((t=>t.checked)).pop();i?this.selectItem(i):t[0]&&(t[0].tabIndex=0)}componentDidLoad(){c(this,this.value),v(this)}connectedCallback(){h(this),p(this),s(this)}disconnectedCallback(){u(this),g(this),m(this)}componentDidRender(){f(this)}render(){return a(e,{onClick:this.handleClick,role:"radiogroup"},a("slot",null),a(d,{component:this}))}handleSelected(t){t.preventDefault(),this.selectItem(t.target),t.stopPropagation()}handleKeyDown(t){const{key:i}=t,{el:a,selectedItem:e}=this;if(-1===["ArrowLeft","ArrowUp","ArrowRight","ArrowDown"," "].indexOf(i))return;let n=i;"rtl"===o(a)&&("ArrowRight"===i&&(n="ArrowLeft"),"ArrowLeft"===i&&(n="ArrowRight"));const l=this.getItems();let r=-1;switch(l.forEach(((t,i)=>{t===e&&(r=i)})),n){case"ArrowLeft":case"ArrowUp":return t.preventDefault(),void this.selectItem(r<1?l[l.length-1]:l[r-1],!0);case"ArrowRight":case"ArrowDown":return t.preventDefault(),void this.selectItem(-1===r?l[1]:l[r+1]||l[0],!0);case" ":return t.preventDefault(),void this.selectItem(t.target,!0);default:return}}async setFocus(){await y(this),(this.selectedItem||this.getItems()[0])?.focus()}onLabelClick(){this.setFocus()}getItems(){return Array.from(this.el.querySelectorAll("calcite-segmented-control-item"))}selectItem(t,i=!1){if(t===this.selectedItem)return;const a=this.getItems();let e=null;a.forEach((a=>{const n=a===t;(n&&!a.checked||!n&&a.checked)&&(a.checked=n),a.tabIndex=n?0:-1,n&&(e=a,i&&this.calciteSegmentedControlChange.emit())})),this.selectedItem=e,e&&e.focus()}get el(){return n(this)}static get watchers(){return{value:["valueHandler"],selectedItem:["handleSelectedItemChange"]}}};k.style="@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([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{display:flex;background-color:var(--calcite-ui-foreground-1);inline-size:-moz-fit-content;inline-size:fit-content;outline:1px solid var(--calcite-ui-border-input);outline-offset:-1px}:host([appearance=outline]){background-color:transparent}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host([layout=vertical]){flex-direction:column;align-items:flex-start;align-self:flex-start}:host([width=full]){inline-size:100%;min-inline-size:-moz-fit-content;min-inline-size:fit-content}:host([width=full]) ::slotted(calcite-segmented-control-item){flex:1 1 auto}:host([width=full][layout=vertical]) ::slotted(calcite-segmented-control-item){justify-content:flex-start}::slotted(input[slot=hidden-form-input]){margin:0 !important;opacity:0 !important;outline:none !important;padding:0 !important;position:absolute !important;inset:0 !important;transform:none !important;-webkit-appearance:none !important;z-index:-1 !important}";const x="segmented-control-item-icon",w=class{constructor(a){t(this,a),this.calciteInternalSegmentedControlItemChange=i(this,"calciteInternalSegmentedControlItemChange",6),this.checked=!1,this.iconFlipRtl=!1,this.iconStart=void 0,this.iconEnd=void 0,this.value=void 0}handleCheckedChange(){this.calciteInternalSegmentedControlItemChange.emit()}render(){const{checked:t,value:i}=this,n=l(this.el,"scale","m"),o=l(this.el,"appearance","solid"),c=l(this.el,"layout","horizontal"),s=this.iconStart?a("calcite-icon",{class:x,flipRtl:this.iconFlipRtl,icon:this.iconStart,key:"icon-start",scale:"s"}):null,m=this.iconEnd?a("calcite-icon",{class:x,flipRtl:this.iconFlipRtl,icon:this.iconEnd,key:"icon-end",scale:"s"}):null;return a(e,{"aria-checked":r(t),"aria-label":i,role:"radio"},a("label",{class:{"label--scale-s":"s"===n,"label--scale-m":"m"===n,"label--scale-l":"l"===n,"label--horizontal":"horizontal"===c,"label--outline":"outline"===o,"label--outline-fill":"outline-fill"===o}},this.iconStart?s:null,a("slot",null,i),a("slot",{name:"input"}),this.iconEnd?m:null))}get el(){return n(this)}static get watchers(){return{checked:["handleCheckedChange"]}}};w.style="@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;cursor:pointer;align-self:stretch;font-weight:var(--calcite-font-weight-normal);transition:background-color var(--calcite-internal-animation-timing-fast) ease-in-out, border-color var(--calcite-animation-timing) ease-in-out}:host label{pointer-events:none;margin:0.125rem;box-sizing:border-box;display:flex;flex:1 1 0%;align-items:center;color:var(--calcite-ui-text-3);transition:background-color var(--calcite-internal-animation-timing-fast) ease-in-out, border-color var(--calcite-internal-animation-timing-fast) ease-in-out, color var(--calcite-internal-animation-timing-fast) ease-in-out}.label--horizontal{justify-content:center}:host{outline-color:transparent}:host(:focus){outline:2px solid var(--calcite-ui-focus-color, var(--calcite-ui-brand));outline-offset:calc(\n -2px *\n calc(\n 1 -\n 2 * clamp(\n 0,\n var(--calcite-ui-focus-offset-invert),\n 1\n )\n )\n );outline-offset:-1px}.label--scale-s{padding-inline:0.5rem;font-size:var(--calcite-font-size--2);line-height:1rem;padding-block:0.125rem}.label--scale-m{padding-inline:0.75rem;font-size:var(--calcite-font-size--1);line-height:1rem;padding-block:0.375rem}.label--scale-l{padding-inline:1rem;padding-block:0.625rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}:host(:hover) label{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1)}:host(:active) label{background-color:var(--calcite-ui-foreground-3)}:host([checked]) label{cursor:default;border-color:var(--calcite-ui-brand);background-color:var(--calcite-ui-brand);color:var(--calcite-ui-background)}:host([checked]) .label--outline,:host([checked]) .label--outline-fill{border-color:var(--calcite-ui-brand);background-color:var(--calcite-ui-foreground-1);box-shadow:inset 0 0 0 1px var(--calcite-ui-brand);color:var(--calcite-ui-brand)}:host([checked]) .label--outline{background-color:transparent}::slotted(input){display:none}@media (forced-colors: active){:host([checked]) label{background-color:highlight}:host([checked]) .label--outline,:host([checked]) .label--outline-fill{outline:2px solid transparent;outline-offset:2px}:host([checked]) label:not([class~=label--outline]) .segmented-control-item-icon{color:highlightText}}.segmented-control-item-icon{position:relative;margin:0px;display:inline-flex;line-height:inherit}:host([icon-start]) .label--scale-s .segmented-control-item-icon{margin-inline-end:0.5rem}:host([icon-end]) .label--scale-s .segmented-control-item-icon{margin-inline-start:0.5rem}:host([icon-start]) .label--scale-m .segmented-control-item-icon{margin-inline-end:0.75rem}:host([icon-end]) .label--scale-m .segmented-control-item-icon{margin-inline-start:0.75rem}:host([icon-start]) .label--scale-l .segmented-control-item-icon{margin-inline-end:1rem}:host([icon-end]) .label--scale-l .segmented-control-item-icon{margin-inline-start:1rem}";export{k as calcite_segmented_control,w as calcite_segmented_control_item}