UNPKG

@public-ui/components

Version:

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

4 lines 5.22 kB
/*! * KoliBri - The accessible HTML-Standard */ "use strict";var index=require("./index-DxCCX-ts.js"),i18n=require("./i18n-CR9McMIU.js"),componentNames=require("./component-names-D7MwtuB7.js"),events=require("./events-DDhO-Ns8.js");require("./common-BHv-S8J5.js"),require("./i18n-BLEJ-_9m.js");const KolTableSettings=class{constructor(e){index.registerInstance(this,e),this.tableSettings={columns:[]},this.errorMessage=null,this.translateTableSettings=i18n.translate("kol-table-settings"),this.translateTableSettingsCancel=i18n.translate("kol-table-settings-cancel"),this.translateTableSettingsApply=i18n.translate("kol-table-settings-apply"),this.translateErrorAllInvisible=i18n.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)),i="up"===t?n-1:n+1,a=s[n],l=s[i],o=s.map((e=>e.key===a.key?Object.assign(Object.assign({},e),{position:l.position}):e.key===l.key?Object.assign(Object.assign({},e),{position:a.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,events.dispatchDomEvent(this.host,events.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 index.h(componentNames.KolPopoverButtonWcTag,{key:"8d4db4f7d458bd1ed87a367f6254c268fe9d160c",ref:e=>this.popoverRef=e,class:"kol-table-settings",_icons:"codicon codicon-settings-gear",_label:this.translateTableSettings,_popoverAlign:"top",_hideLabel:!0},index.h("div",{key:"5311a11dc9beec9ebb1b9afcec74d6fc69b106ec",class:"kol-table-settings__content"},index.h(componentNames.KolHeadingTag,{key:"623b06fab8eb938ca7a96d6c59046e35b026ac8b",_label:this.translateTableSettings,_level:0}),this.errorMessage&&index.h(componentNames.KolAlertWcTag,{key:"299262a0842783fe746c427498cf48a462e608d7",_type:"error",_label:this.errorMessage,_variant:"msg",class:"kol-table-settings__error-message"}),index.h("form",{key:"70f2731f3a31e0e61f49e335f179965f96ca6dc9",onSubmit:this.handleSubmit.bind(this)},index.h("div",{key:"a42564c9d6603c574dfd6c83d71bb67118d6a68d",class:"kol-table-settings__columns-container"},index.h("div",{key:"220fcd4e67cd50e527d353b0f5618d4186068218",class:"kol-table-settings__columns"},e.map(((t,s)=>index.h("div",{key:t.key,class:"kol-table-settings__column"},index.h(componentNames.KolInputCheckboxTag,{_checked:t.visible,_label:i18n.translate("kol-table-settings-show-column",{placeholders:{column:t.label}}),_value:!0,_hideLabel:!0,_on:{onInput:(e,s)=>this.handleVisibilityChange(t.key,s)}}),index.h("span",null,t.label),index.h(componentNames.KolInputNumberTag,{_hideLabel:!0,_value:t.width,_label:i18n.translate("kol-table-settings-column-width",{placeholders:{column:t.label}}),_min:1,_on:{onInput:(e,s)=>this.handleWidthChange(t.key,s)}}),index.h(componentNames.KolButtonWcTag,{_icons:"codicon codicon-arrow-up",_label:i18n.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"}),index.h(componentNames.KolButtonWcTag,{_icons:"codicon codicon-arrow-down",_label:i18n.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"})))))),index.h("div",{key:"ab18e657b9e5cf7e964f2107e1ceaec2ebc6cddd",class:"kol-table-settings__actions"},index.h(componentNames.KolButtonWcTag,{key:"aedcc655384dedb3feebb28444ac7f488b672ead",_label:this.translateTableSettingsCancel,_buttonVariant:"secondary",_on:{onClick:()=>this.handleCancel()},"data-testid":"table-settings-cancel"}),index.h(componentNames.KolButtonWcTag,{key:"2b6a09294353fde7d9bff9a8fcc07be76b18fee1",_label:this.translateTableSettingsApply,_buttonVariant:"primary",_type:"submit","data-testid":"table-settings-apply"})))))}get host(){return index.getElement(this)}static get watchers(){return{_tableSettings:["handleTableSettingsChange"]}}};exports.kol_table_settings_wc=KolTableSettings;