2023-07-14 11:19:10 +02:00
|
|
|
import '@material/web/textfield/filled-text-field.js';
|
2023-08-17 15:36:30 +02:00
|
|
|
import '@material/web/iconbutton/icon-button.js';
|
2023-07-14 11:19:10 +02:00
|
|
|
|
2023-08-04 16:13:48 +02:00
|
|
|
import {FilledTextField} from '@material/web/textfield/internal/filled-text-field';
|
2023-07-14 11:19:10 +02:00
|
|
|
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'>> {}
|
2023-07-14 11:19:10 +02:00
|
|
|
|
|
|
|
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 */}
|
2023-07-14 11:19:10 +02:00
|
|
|
{vnode.children}
|
2023-08-18 14:23:49 +02:00
|
|
|
<md-icon-button type="button" slot="trailingicon" onclick={this.openDatePicker.bind(this)}>
|
2023-07-14 11:19:10 +02:00
|
|
|
<MdIcon icon={mdiCalendarMonthOutline}/>
|
2023-08-17 15:36:30 +02:00
|
|
|
</md-icon-button>
|
2023-07-14 11:19:10 +02:00
|
|
|
</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();
|
2023-07-14 11:19:10 +02:00
|
|
|
}
|
|
|
|
}
|