import {Checkbox} from '@material/mwc-checkbox';
import {html, LitElement} from 'lit';
import {property, query, queryAssignedElements} from 'lit/decorators.js';
import {TextField} from '@material/mwc-textfield';
import {IconButtonToggle} from '@material/mwc-icon-button-toggle';
import '@material/mwc-textfield';
import '@material/mwc-icon-button-toggle';
import '@material/mwc-checkbox';
import '@material/mwc-icon';
import {CellCheckedEventDetail} from './mwa-data-table-cell';
export interface FilterTextFieldInputEventDetail {
field: TextField,
text: string,
column: DataTableColumnBase,
caseSensitive: boolean
}
export class DataTableColumnBase extends LitElement {
/**
* Column type. If `checkbox`, the checkbox inside the column will be also created if not supplied via the default slot.
* If `numeric`, the column label will be aligned to the right.
*/
@property({type: String}) type: '' | 'numeric' | 'checkbox' = '';
/**
* Whether the column can be sorted.
*/
@property({type: Boolean}) sortable = false;
/**
* Whether the column is sorted.
*/
@property({type: Boolean, reflect: true}) sorted = false;
/**
* Whether the column is sorted descending.
*/
@property({type: Boolean, reflect: true}) sortedDescending = false;
/**
* Whether the column is displaying a sort button.
*/
@property({type: Boolean, reflect: true}) withSortButton = false;
/**
* Whether the column can be filtered.
*/
@property({type: Boolean, reflect: true}) filterable = false;
/**
* Label to show on the filter textfield.
*/
@property({type: String}) filterTextFieldLabel = 'Filter';
/**
* Sets the filtering to be case-sensitive.
*/
@property({type: Boolean, reflect: true}) filterCaseSensitive = false;
/** @internal */
slot = 'header-cell';
/** @internal */
@query('mwc-icon-button-toggle') sortButton?: IconButtonToggle;
/** @internal */
@queryAssignedElements({slot: 'checkbox', flatten: true}) protected checkboxSlotElements!: Checkbox[];
/** @internal */
get checkbox(): Checkbox | undefined {
return this.checkboxSlotElements?.[0];
}
render() {
return html`
${this.renderCheckbox()}
${this.renderFilterTextField()}
${this.renderSlot()}
`;
}
renderCheckbox() {
if (this.type === 'checkbox') {
return html`