@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 5.22 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import{t as translate}from"./i18n2.js";import{i as KolPopoverButtonWcTag,l as KolHeadingTag,b as KolAlertWcTag,m as KolInputCheckboxTag,n as KolInputNumberTag,a as KolButtonWcTag}from"./component-names.js";import{d as dispatchDomEvent,K as KolEvent}from"./events.js";const KolTableSettings=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.tableSettings={columns:[]},this.errorMessage=null,this._tableSettings={columns:[]}}handleTableSettingsChange(e){this.tableSettings=Object.assign(Object.assign({},e),{columns:this.sortColumnsByPosition(e.columns)})}componentWillLoad(){this.handleTableSettingsChange(this._tableSettings)}sortColumnsByPosition(e){return[...e].sort(((e,t)=>e.position-t.position))}moveColumn(e,t){const s=[...this.tableSettings.columns],a=s.findIndex((t=>t.key===e)),n="up"===t?a-1:a+1,l=s[a],o=s[n],i=s.map((e=>e.key===l.key?Object.assign(Object.assign({},e),{position:o.position}):e.key===o.key?Object.assign(Object.assign({},e),{position:l.position}):e));this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.sortColumnsByPosition(i)})}handleVisibilityChange(e,t){this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.tableSettings.columns.map((s=>s.key===e?Object.assign(Object.assign({},s),{visible:Boolean(t)}):s))})}handleWidthChange(e,t){this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.tableSettings.columns.map((s=>s.key===e?Object.assign(Object.assign({},s),{width:Number(t)}):s))})}handleCancel(){var e;null===(e=this.popoverRef)||void 0===e||e.hidePopover()}handleSubmit(e){var t;e.preventDefault();this.tableSettings.columns.some((e=>e.visible))?this.host&&(this.errorMessage=null,dispatchDomEvent(this.host,KolEvent.settingsChange,this.tableSettings),null===(t=this.popoverRef)||void 0===t||t.hidePopover()):this.errorMessage=translate("kol-table-settings-error-all-invisible")}render(){const e=[...this.tableSettings.columns].sort(((e,t)=>e.position-t.position));return h(KolPopoverButtonWcTag,{key:"a3e0145a3399d8dee361f7e29e34198b1ec99b27",ref:e=>this.popoverRef=e,class:"kol-table-settings",_icons:"codicon codicon-settings-gear",_label:translate("kol-table-settings"),_popoverAlign:"top",_hideLabel:!0},h("div",{key:"66f2e14ac78f6d865a6a6ad9e2393c94c42fa8a7",class:"kol-table-settings__content"},h(KolHeadingTag,{key:"558f2b97ac8c7f049147125a642e5e4862108dda",_label:translate("kol-table-settings"),_level:0}),this.errorMessage&&h(KolAlertWcTag,{key:"433c0381c504eff423516b40d899751ae5ea4658",_type:"error",_label:this.errorMessage,_variant:"msg",class:"kol-table-settings__error-message"}),h("form",{key:"404aae1da74273e840c1980fe3a94d126cbfbe8b",onSubmit:this.handleSubmit.bind(this)},h("div",{key:"d18a3fe79c0f576dbf23444eb06a744d003b77af",class:"kol-table-settings__columns-container"},h("div",{key:"adb1ad8d4afc6e0dc062f7dfb2cbbfebbc5b83d1",class:"kol-table-settings__columns"},e.map(((t,s)=>h("div",{key:t.key,class:"kol-table-settings__column"},h(KolInputCheckboxTag,{_checked:t.visible,_label:translate("kol-table-settings-show-column",{placeholders:{column:t.label}}),_value:!0,_hideLabel:!0,_on:{onInput:(e,s)=>this.handleVisibilityChange(t.key,s)}}),h("span",null,t.label),h(KolInputNumberTag,{_hideLabel:!0,_value:t.width,_label:translate("kol-table-settings-column-width",{placeholders:{column:t.label}}),_min:1,_on:{onInput:(e,s)=>this.handleWidthChange(t.key,s)}}),h(KolButtonWcTag,{_icons:"codicon codicon-arrow-up",_label:translate("kol-table-settings-move-up",{placeholders:{column:t.label}}),_hideLabel:!0,_variant:"ghost",_on:{onClick:()=>this.moveColumn(t.key,"up")},_disabled:0===s,"data-testid":"table-settings-move-up"}),h(KolButtonWcTag,{_icons:"codicon codicon-arrow-down",_label:translate("kol-table-settings-move-down",{placeholders:{column:t.label}}),_hideLabel:!0,_variant:"ghost",_on:{onClick:()=>this.moveColumn(t.key,"down")},_disabled:s===e.length-1,"data-testid":"table-settings-move-down"})))))),h("div",{key:"d0f48d73ce013cbd5b185a437756482c855ac9dc",class:"kol-table-settings__actions"},h(KolButtonWcTag,{key:"a7e5797e348e821f8054a92121ecff1d61b13135",_label:translate("kol-table-settings-cancel"),_variant:"secondary",_on:{onClick:()=>this.handleCancel()},"data-testid":"table-settings-cancel"}),h(KolButtonWcTag,{key:"b42ca9c4f951fcc93a281f022dabafda59fe3373",_label:translate("kol-table-settings-apply"),_variant:"primary",_type:"submit","data-testid":"table-settings-apply"})))))}get host(){return this}static get watchers(){return{_tableSettings:["handleTableSettingsChange"]}}},[0,"kol-table-settings-wc",{_tableSettings:[16],tableSettings:[32],errorMessage:[32]},void 0,{_tableSettings:["handleTableSettingsChange"]}]);function defineCustomElement$1(){if("undefined"==typeof customElements)return;["kol-table-settings-wc"].forEach((e=>{if("kol-table-settings-wc"===e)customElements.get(e)||customElements.define(e,KolTableSettings)}))}const KolTableSettingsWc=KolTableSettings,defineCustomElement=defineCustomElement$1;export{KolTableSettingsWc,defineCustomElement};