@trendyol/baklava
Version:
Trendyol Baklava Design System
18 lines (17 loc) • 5.38 kB
JavaScript
import{a as g}from"./chunk-DJOD4BTL.js";import{a as v}from"./chunk-6LT7O7T2.js";import{a as i}from"./chunk-GRL4DWKG.js";import{a as c,b as a,c as u,d as m}from"./chunk-IRDH7CN2.js";import{a as s,b as n,f as d}from"./chunk-4OT5AMS5.js";import{c as t}from"./chunk-VO7C5OZC.js";var y=s`:host{display:block}fieldset{border:none;padding:0}legend{font:var(--bl-font-title-3-medium);color:var(--bl-color-neutral-darker)}.options{display:flex;flex-flow:var(--bl-radio-direction, column) wrap;align-items:var(--bl-radio-group-cross-axis-item-alignment, normal);align-content:var(--bl-radio-group-cross-axis-content-alignment, normal);justify-content:var(--bl-radio-group-main-axis-content-alignment, normal);gap:var(--bl-size-m);margin-block:var(--bl-size-xs)}`,f=y;var h="bl-radio-group",p="bl-radio-change",r=class extends g(d){constructor(){super(...arguments);this.value="";this.required=!1;this.focusedOptionIndex=0}static get styles(){return[f]}get options(){return[...this.querySelectorAll(b)]}get availableOptions(){return this.options.filter(e=>!e.disabled)}updated(e){e.has("value")&&(this.setValue(this.value),this.onChange(this.value))}handleOptionChecked(e){let o=e.target;this.setValue(o.value),this.onChange(o.value)}handleKeyDown(e){if(["ArrowDown","ArrowRight"].includes(e.key))this.focusedOptionIndex++;else if(["ArrowUp","ArrowLeft"].includes(e.key))this.focusedOptionIndex--;else if([" "].includes(e.key)){this.availableOptions[this.focusedOptionIndex].select();return}else return;this.focusedOptionIndex=Math.max(0,Math.min(this.focusedOptionIndex,this.availableOptions.length-1)),this.availableOptions[this.focusedOptionIndex].focus(),e.preventDefault()}connectedCallback(){super.connectedCallback(),this.tabIndex=0,this.addEventListener("focus",this.handleFocus),this.addEventListener("keydown",this.handleKeyDown)}handleFocus(){this.availableOptions[this.focusedOptionIndex].focus()}render(){return n`<fieldset role="radiogroup" aria-labelledby="label" aria-required=${this.required}>
<legend id="label">${this.label}</legend>
<div class="options" -checked=${this.handleOptionChecked}>
<slot></slot>
</div>
</fieldset>`}};t([a({type:String})],r.prototype,"label",2),t([a()],r.prototype,"value",2),t([a({type:Boolean,reflect:!0})],r.prototype,"required",2),t([i("bl-radio-change")],r.prototype,"onChange",2),r=t([c(h)],r);var C=s`:host{cursor:pointer;outline:none}.wrapper{--size:var(--bl-size-m);outline:none}#label{display:flex;font:var(--bl-font-title-3-regular);line-height:normal;align-items:var(--bl-radio-align-items, center);margin-block:0;color:var(--bl-color-neutral-darker);gap:var(--bl-size-2xs)}#label::before{content:"";display:inline-block;box-sizing:border-box;min-width:var(--size);min-height:var(--size);max-width:var(--size);max-height:var(--size);background-color:white;border-radius:var(--bl-border-radius-circle);border:solid 1px var(--bl-color-neutral-lighter)}.selected #label::before{border-width:var(--bl-size-3xs);border-color:var(--bl-color-primary)}:host(.__ONLY_FOR_STORYBOOK_DEMONSTRATION_HOVER__) #label,.selected #label,:host(:hover) #label,.selected #label{color:var(--bl-color-primary)}:host([disabled]){cursor:not-allowed;pointer-events:none}:host([disabled]) .wrapper{--size:calc(var(--bl-size-m) - 2px)}:host([disabled]) #label{color:var(--bl-color-neutral-light)}:host([disabled]) #label::before{background-color:var(--bl-color-neutral-lightest);border-width:0;box-shadow:0 0 0 1px var(--bl-color-neutral-lighter)}:host([disabled]) .selected #label::before{background-color:var(--bl-color-neutral-light);border-color:var(--bl-color-neutral-lightest);border-width:calc(var(--bl-size-3xs) - 1px)}.wrapper:focus-visible #label::before{box-shadow:0 0 0 1px white,0 0 0 3px var(--bl-color-primary)}`,x=C;var b="bl-radio",W="bl-checked",l=class extends d{constructor(){super(...arguments);this.disabled=!1;this.selected=!1;this.handleFieldValueChange=e=>{let o=e.detail;this.selected=o===this.value}}static get styles(){return[x]}select(){this.selected=!0,this.onChecked(this.value)}get checked(){return this.selected}focus(){this.radioElement.tabIndex=0,this.radioElement.focus(),this.onFocus(this.value)}blur(){this.radioElement.tabIndex=-1,this.onBlur(this.value)}connectedCallback(){var e;super.connectedCallback(),this.field=this.closest(h),this.field||console.warn("bl-radio is designed to be used inside a bl-radio-group",this),(e=this.field)==null||e.addEventListener(p,this.handleFieldValueChange)}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this.field)==null||e.removeEventListener(p,this.handleFieldValueChange)}render(){let e=v({wrapper:!0,selected:this.selected});return n`<div
class=${e}
role="radio"
aria-labelledby="label"
aria-disabled=${this.disabled}
aria-readonly=${this.disabled}
=${this.blur}
=${this.select}
>
<p id="label"><slot></slot></p>
</div>`}};t([a()],l.prototype,"name",2),t([a()],l.prototype,"value",2),t([a({type:Boolean,reflect:!0})],l.prototype,"disabled",2),t([u()],l.prototype,"selected",2),t([i("bl-checked")],l.prototype,"onChecked",2),t([i("bl-focus")],l.prototype,"onFocus",2),t([i("bl-blur")],l.prototype,"onBlur",2),t([m("[role=radio]")],l.prototype,"radioElement",2),l=t([c(b)],l);export{b as a,W as b,l as c,h as d,p as e,r as f};
//# sourceMappingURL=chunk-6F253HWQ.js.map