UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

4 lines 5.51 kB
/*! * KoliBri - The accessible HTML-Standard */ import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import{t as translate}from"./i18n.js";import{k as KolPopoverButtonWcTag,n as KolHeadingTag,b as KolAlertWcTag,o as KolInputCheckboxTag,p as KolInputNumberTag,d 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.translateTableSettings=translate("kol-table-settings"),this.translateTableSettingsCancel=translate("kol-table-settings-cancel"),this.translateTableSettingsApply=translate("kol-table-settings-apply"),this.translateErrorAllInvisible=translate("kol-table-settings-error-all-invisible"),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],n=s.findIndex((t=>t.key===e)),a="up"===t?n-1:n+1,l=s[n],i=s[a],o=s.map((e=>e.key===l.key?Object.assign(Object.assign({},e),{position:i.position}):e.key===i.key?Object.assign(Object.assign({},e),{position:l.position}):e));this.tableSettings=Object.assign(Object.assign({},this.tableSettings),{columns:this.sortColumnsByPosition(o)})}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=this.translateErrorAllInvisible}render(){const e=[...this.tableSettings.columns].sort(((e,t)=>e.position-t.position));return h(KolPopoverButtonWcTag,{key:"8d4db4f7d458bd1ed87a367f6254c268fe9d160c",ref:e=>this.popoverRef=e,class:"kol-table-settings",_icons:"codicon codicon-settings-gear",_label:this.translateTableSettings,_popoverAlign:"top",_hideLabel:!0},h("div",{key:"5311a11dc9beec9ebb1b9afcec74d6fc69b106ec",class:"kol-table-settings__content"},h(KolHeadingTag,{key:"623b06fab8eb938ca7a96d6c59046e35b026ac8b",_label:this.translateTableSettings,_level:0}),this.errorMessage&&h(KolAlertWcTag,{key:"299262a0842783fe746c427498cf48a462e608d7",_type:"error",_label:this.errorMessage,_variant:"msg",class:"kol-table-settings__error-message"}),h("form",{key:"70f2731f3a31e0e61f49e335f179965f96ca6dc9",onSubmit:this.handleSubmit.bind(this)},h("div",{key:"a42564c9d6603c574dfd6c83d71bb67118d6a68d",class:"kol-table-settings__columns-container"},h("div",{key:"220fcd4e67cd50e527d353b0f5618d4186068218",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,_buttonVariant:"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,_buttonVariant:"ghost",_on:{onClick:()=>this.moveColumn(t.key,"down")},_disabled:s===e.length-1,"data-testid":"table-settings-move-down"})))))),h("div",{key:"ab18e657b9e5cf7e964f2107e1ceaec2ebc6cddd",class:"kol-table-settings__actions"},h(KolButtonWcTag,{key:"aedcc655384dedb3feebb28444ac7f488b672ead",_label:this.translateTableSettingsCancel,_buttonVariant:"secondary",_on:{onClick:()=>this.handleCancel()},"data-testid":"table-settings-cancel"}),h(KolButtonWcTag,{key:"2b6a09294353fde7d9bff9a8fcc07be76b18fee1",_label:this.translateTableSettingsApply,_buttonVariant:"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,"_table-settings"],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};