Skip to content

Commit

Permalink
feat: implement DatePickerInputSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed Nov 6, 2021
1 parent ab32816 commit 71eeb1a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/date-picker-input-surface/app-date-picker-input-surface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { customElement } from 'lit/decorators.js';

import { appDatePickerInputSurfaceName } from './constants.js';
import { DatePickerInputSurface } from './date-picker-input-surface.js';


@customElement(appDatePickerInputSurfaceName)
export class AppDatePickerInputSurface extends DatePickerInputSurface {}

declare global {
interface HTMLElementTagNameMap {
[appDatePickerInputSurfaceName]: AppDatePickerInputSurface;
}
}
1 change: 1 addition & 0 deletions src/date-picker-input-surface/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const appDatePickerInputSurfaceName = 'app-date-picker-input-surface';
22 changes: 22 additions & 0 deletions src/date-picker-input-surface/date-picker-input-surface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MenuSurface } from '@material/mwc-menu/mwc-menu-surface.js';

import { appDatePickerName } from '../date-picker/constants.js';
import { appDatePickerInputName } from '../date-picker-input/constants.js';
import { DatePickerInputSurfaceStyling } from './stylings.js';

export class DatePickerInputSurface extends MenuSurface {
public static override styles = [
...MenuSurface.styles,
DatePickerInputSurfaceStyling,
];

protected override onBodyClick(ev: MouseEvent) {
const elements = (ev.composedPath() as HTMLElement[]).filter(({ nodeType }) => nodeType === Node.ELEMENT_NODE);
const shouldClose =
elements.some(n => n.classList.contains('calendar-day')) ||
!elements.some(n => n.localName === appDatePickerName) ||
!elements.some(n => n.localName === appDatePickerInputName);

shouldClose && this.close();
}
}
12 changes: 12 additions & 0 deletions src/date-picker-input-surface/stylings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { css } from 'lit';

export const DatePickerInputSurfaceStyling = css`
:host {
display: block;
position: relative;
}
.mdc-menu-surface.mdc-menu-surface--open {
overflow: initial;
}
`;

0 comments on commit 71eeb1a

Please sign in to comment.