UNPKG

@scania/tegel

Version:
1 lines 3.04 kB
import{r as t,h as o,H as e,g as s}from"./p-2049fab2.js";const i=["compactDesign"],n=class{constructor(o){t(this,o),this.showIcon=!0,this.renderSlot=!0,this.inputFocused=!1,this.compactDesign=!1,this.tableId=""}internalTdsPropChangeListener(t){this.tableId===t.detail.tableId&&t.detail.changed.filter((t=>i.includes(t))).forEach((o=>{if(void 0===this[o])throw console.error(`Table prop is not supported: ${o}`),new Error(`Table prop is not supported: ${o}`);this[o]=t.detail[o]}))}connectedCallback(){const t=this.host.closest("tds-table");t?this.tableId=t.getAttribute("table-id"):console.error("Failed to find parent tds-table element.")}componentWillLoad(){const t=this.host.closest("tds-table");t?i.forEach((o=>{this[o]=t[o]})):console.error("Failed to find parent tds-table element.")}handleSlotChange(){this.validateSlot()}validateSlot(){const t=Array.from(this.host.children).filter((t=>"INPUT"===t.tagName));if(1!==t.length)console.warn("TABLE-BODY-INPUT-WRAPPER: Wrapper only accepts input as children."),this.renderSlot=!1;else{this.renderSlot||(this.renderSlot=!0);const o=t[0];o.addEventListener("focus",(()=>{this.inputFocused=!0})),o.addEventListener("blur",(()=>{this.inputFocused=!1})),o.addEventListener("keydown",(t=>{"Enter"===t.key&&(t.preventDefault(),this.moveToNextEditableCell())}))}}moveToNextEditableCell(){const t=Array.from(document.querySelectorAll("tds-table-body-input-wrapper")),o=t.indexOf(this.host);if(-1!==o&&o<t.length-1){const e=t[o+1].querySelector("input");e&&e.focus()}}render(){return o(e,{key:"47496dfe7467e43cede5af53d6c30fe17c116eaf",class:{"focused-input-wrapper":this.inputFocused,"show-icon":this.showIcon,"tds-table__compact":this.compactDesign}},this.renderSlot?o("slot",{onSlotchange:()=>this.handleSlotChange()}):null,this.showIcon?o("tds-icon",{class:"edit-icon",slot:"icon",size:"16px",name:"edit"}):null)}get host(){return s(this)}};n.style=":host{position:relative}:host(.focused-input-wrapper) tds-icon{display:inline-block}:host(.show-icon) ::slotted(input){padding-right:var(--tds-spacing-element-24)}:host(:hover) tds-icon{display:inline-block}:host(:hover) ::slotted(input:not(:focus)){background-color:var(--tds-table-input-background-hover)}tds-icon.edit-icon{display:none;position:absolute;right:10px;top:1px;pointer-events:none;cursor:pointer}::slotted(input){box-sizing:border-box;font:var(--tds-detail-02);letter-spacing:var(--tds-detail-02-ls);padding-left:var(--tds-spacing-element-16);padding-right:var(--tds-spacing-element-16);color:var(--tds-table-color);background-color:transparent;height:48px;border-radius:0;border:0;border-bottom:2px solid transparent;width:100%;cursor:pointer}::slotted(input)::placeholder{color:var(--tds-table-color)}::slotted(input:disabled){background-color:var(--tds-table-input-background-disabled)}::slotted(input:focus){outline:none;background-color:var(--tds-table-input-background-focus);border-bottom:2px solid var(--tds-text-field-bar)}:host(.tds-table__compact) ::slotted(input){height:32px;}";export{n as tds_table_body_input_wrapper}