openstamanager/resources/ts/Components/FilledDateTextField.tsx

37 lines
1.3 KiB
TypeScript
Raw Normal View History

import '@material/web/textfield/filled-text-field.js';
2023-08-17 15:36:30 +02:00
import '@material/web/iconbutton/icon-button.js';
2023-08-04 16:13:48 +02:00
import {FilledTextField} from '@material/web/textfield/internal/filled-text-field';
import {mdiCalendarMonthOutline} from '@mdi/js';
import MdIcon from '@osm/Components/MdIcon';
import {Vnode} from 'mithril';
import {
Attributes,
Component
} from 'mithril-utilities';
import {KebabCasedProperties} from 'type-fest';
2023-07-14 11:45:27 +02:00
export interface FilledDateTextFieldAttributes extends Attributes, Partial<Omit<KebabCasedProperties<FilledTextField>, 'style'>> {}
export default class FilledDateTextField<A extends FilledDateTextFieldAttributes> extends Component<A> {
element!: FilledTextField;
view(vnode: Vnode<A>) {
vnode.attrs.type ??= 'date';
return (
<md-filled-text-field {...vnode.attrs}>
2023-08-04 16:13:48 +02:00
{/* @ts-ignore */}
{vnode.children}
<md-icon-button type="button" slot="trailingicon" onclick={this.openDatePicker.bind(this)}>
<MdIcon icon={mdiCalendarMonthOutline}/>
2023-08-17 15:36:30 +02:00
</md-icon-button>
</md-filled-text-field>
);
}
openDatePicker(event: MouseEvent & {redraw?: boolean}) {
event.redraw = false;
2023-08-04 17:50:34 +02:00
// @ts-expect-error - getInput() is private
(this.element.getInput() as HTMLInputElement).showPicker();
}
}