-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement DatePickerInputSurface
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/date-picker-input-surface/app-date-picker-input-surface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
src/date-picker-input-surface/date-picker-input-surface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
`; |