@trendyol/baklava
Version:
Trendyol Baklava Design System
24 lines (23 loc) • 6.19 kB
JavaScript
import{a as v}from"./chunk-YOV2DMM7.js";import{a as d}from"./chunk-DJOD4BTL.js";import{a as o}from"./chunk-GRL4DWKG.js";import{a as c,b as r,d as m}from"./chunk-IRDH7CN2.js";import{a as f}from"./chunk-DINNT5P2.js";import{a as s,b as a,f as n}from"./chunk-4OT5AMS5.js";import{c as t}from"./chunk-VO7C5OZC.js";var E=s`:host{display:flex;flex-direction:row}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-checkbox-direction, column) wrap;gap:var(--bl-size-m);margin-block:var(--bl-size-xs)}`,g=E;var u="bl-checkbox-group",p="bl-checkbox-group-change",l=class extends d(n){constructor(){super(...arguments);this.value=[];this.required=!1;this.focusedOptionIndex=0}static get styles(){return[g]}get options(){return[...this.querySelectorAll(h)]}get checkedOptions(){return this.options.filter(e=>e.checked).map(e=>e.value)}get availableOptions(){return this.options.filter(e=>!e.disabled)}connectedCallback(){super.connectedCallback(),this.tabIndex=0,this.addEventListener("focus",this.handleFocus),this.addEventListener("keydown",this.handleKeyDown)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("focus",this.handleFocus),this.removeEventListener("keydown",this.handleKeyDown)}updated(e){e.has("value")&&(this.setValue(this.checkedOptions.join(",")),this.onChange(this.value))}handleOptionChecked(){this.value=this.checkedOptions}handleKeyDown(e){if(["ArrowDown","ArrowRight"].includes(e.key))this.focusedOptionIndex++;else if(["ArrowUp","ArrowLeft"].includes(e.key))this.focusedOptionIndex--;else if(e.key==="Tab"){if(e.shiftKey?this.focusedOptionIndex--:this.focusedOptionIndex++,this.focusedOptionIndex===this.availableOptions.length){this.tabIndex=0,this.focusedOptionIndex=0;return}}else return;this.focusedOptionIndex=Math.max(0,Math.min(this.focusedOptionIndex,this.availableOptions.length-1)),this.availableOptions[this.focusedOptionIndex].focus(),e.preventDefault()}handleFocus(){this.availableOptions[this.focusedOptionIndex].focus()}render(){return a`<fieldset role="group" aria-labelledby="label" aria-required=${this.required}>
<legend id="label">${this.label}</legend>
<div class="options" -checkbox-change=${this.handleOptionChecked}>
<slot></slot>
</div>
</fieldset>`}};t([r({type:String})],l.prototype,"label",2),t([r({type:Array,reflect:!0})],l.prototype,"value",2),t([r({type:Boolean,reflect:!0})],l.prototype,"required",2),t([o("bl-checkbox-group-change")],l.prototype,"onChange",2),l=t([c(u)],l);var O=s`:host{display:inline-block;vertical-align:middle}:host *{outline:none}label{display:flex;gap:var(--bl-size-2xs);color:var(--bl-color-neutral-darker);font:var(--bl-font-title-3);cursor:pointer;user-select:none}.label{overflow-wrap:anywhere}input{appearance:none;position:absolute}.check-mark{display:flex;align-items:center;justify-content:center;box-sizing:border-box;width:var(--bl-size-m);height:var(--bl-size-m);min-width:var(--bl-size-m);min-height:var(--bl-size-m);max-width:var(--bl-size-m);max-height:var(--bl-size-m);border:1px solid var(--bl-color-neutral-lighter);border-radius:var(--bl-border-radius-xs);color:var(--bl-color-neutral-full);font-size:var(--bl-font-size-2xs);background-color:var(--bl-color-neutral-full)}:host([checked]) .label,:host(.__ONLY_FOR_STORYBOOK_DEMONSTRATION_HOVER__) .label,:host(:hover) .label{color:var(--bl-color-primary)}:host(:is([checked], [indeterminate])) .check-mark{background-color:var(--bl-color-primary);border:none}:host([disabled]){cursor:not-allowed;pointer-events:none}:host([disabled]) .check-mark,:host([disabled]) .label{color:var(--bl-color-neutral-light);border:1px solid var(--bl-color-neutral-lighter)}:host([disabled]) .check-mark{background-color:var(--bl-color-neutral-lightest)}:host(:not([disabled])) input:focus-visible + .check-mark{box-shadow:0 0 0 1px white,0 0 0 3px var(--bl-color-primary)}`,k=O;var h="bl-checkbox",i=class extends d(n){constructor(){super(...arguments);this.checked=!1;this.required=!1;this.disabled=!1;this.indeterminate=!1;this.handleFieldValueChange=e=>{this.checked=e.detail.includes(this.value)}}static get styles(){return[k]}connectedCallback(){var e;super.connectedCallback(),this.field=this.closest(u),(e=this.field)==null||e.addEventListener(p,this.handleFieldValueChange)}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this.field)==null||e.removeEventListener(p,this.handleFieldValueChange)}updated(e){e.has("checked")&&this.required&&this.checked&&this.setValue(this.value)}update(e){super.update(e),this.indeterminate&&this.checked&&(this.checked=!1,this.requestUpdate("checked",!0))}focus(){this.checkboxElement.tabIndex=0,this.checkboxElement.focus(),this.onFocus(this.value)}blur(){this.onBlur(this.value),this.field&&(this.checkboxElement.tabIndex=-1)}handleChange(e){let b=e.target;this.checked=b.checked,this.onChange(b.checked),this.indeterminate=!1}render(){let e="";return this.checked&&(e="check"),this.indeterminate&&(e="minus"),a`
<label>
<input
type="checkbox"
.checked=${v(this.checked)}
?disabled=${this.disabled}
aria-required=${this.required}
aria-readonly=${this.disabled}
.indeterminate=${this.indeterminate}
=${this.handleChange}
value=${f(this.value)}
=${this.blur}
/>
<div class="check-mark">${e?a`<bl-icon name="${e}"></bl-icon>`:null}</div>
<slot class="label"></slot>
</label>
`}};i.shadowRootOptions={...n.shadowRootOptions,delegatesFocus:!0},t([r({type:Boolean,reflect:!0})],i.prototype,"checked",2),t([r()],i.prototype,"value",2),t([r({type:Boolean,reflect:!0})],i.prototype,"required",2),t([r({type:Boolean,reflect:!0})],i.prototype,"disabled",2),t([r({type:Boolean,reflect:!0})],i.prototype,"indeterminate",2),t([o("bl-checkbox-change")],i.prototype,"onChange",2),t([o("bl-focus")],i.prototype,"onFocus",2),t([o("bl-blur")],i.prototype,"onBlur",2),t([m("[type=checkbox]")],i.prototype,"checkboxElement",2),i=t([c(h)],i);export{h as a,i as b,u as c,p as d,l as e};
//# sourceMappingURL=chunk-AIIJINAR.js.map