UNPKG

@3mo/data-grid

Version:
62 lines (61 loc) 2.32 kB
var DataGridColumnCurrency_1; import { __decorate } from "tslib"; import { component, html, ifDefined, property } from '@a11d/lit'; import { Localizer, Currency } from '@3mo/localization'; import { FieldCurrency } from '@3mo/number-fields'; import { DataGridColumnNumberBase } from './DataGridColumnNumberBase.js'; Localizer.dictionaries.add('de', { 'Currency': 'Währung', }); /** * @element mo-data-grid-column-currency * * @attr currency - The currency of the values. * @attr currencyDataSelector - The key path to the currency of the values. */ let DataGridColumnCurrency = class DataGridColumnCurrency extends DataGridColumnNumberBase { static { DataGridColumnCurrency_1 = this; } getCurrency(data) { return (this.currencyDataSelector ? Currency[KeyPath.get(data, this.currencyDataSelector)] : undefined) ?? this.currency ?? DataGridColumnCurrency_1.defaultCurrency; } getContentTemplate(value, data) { return html `${this.getNumber(value)?.formatAsCurrency(this.getCurrency(data)) ?? html.nothing}`; } getEditContentTemplate(value, data) { return html ` <mo-field-currency dense autofocus selectOnFocus .currency=${this.getCurrency(data)} min=${ifDefined(this.getMin(data))} max=${ifDefined(this.getMax(data))} step=${ifDefined(this.getStep(data))} value=${ifDefined(value)} @change=${(e) => this.handleEdit(e.detail, data)} ></mo-field-currency> `; } getSumTemplate(sum) { return html ` <span style='font-weight: 500'>${sum.formatAsCurrency(this.currency ?? DataGridColumnCurrency_1.defaultCurrency)}</span> `; } *generateCsvHeading() { yield* super.generateCsvHeading(); yield t('Currency'); } *generateCsvValue(value, data) { yield* super.generateCsvValue(value, data); yield this.getCurrency(data).code; } }; __decorate([ property({ type: Object, converter: FieldCurrency.currencyConverter }) ], DataGridColumnCurrency.prototype, "currency", void 0); __decorate([ property() ], DataGridColumnCurrency.prototype, "currencyDataSelector", void 0); DataGridColumnCurrency = DataGridColumnCurrency_1 = __decorate([ component('mo-data-grid-column-currency') ], DataGridColumnCurrency); export { DataGridColumnCurrency };