Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dialog): custom top position #1226

Merged
merged 9 commits into from
Mar 15, 2022
11 changes: 10 additions & 1 deletion components/dialog/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ This component is an extension of [<mwc-dialog>](https://github.com/material-com
| `defaultAction` | `string` | _Default: 'close'_ – Action to be emitted with the `closing` and `closed` events when `<mwc-dialog>.open` is toggled.
| `actionAttribute` | `string` | _Default: 'dialogAction'_ – Attribute to read in light dom of dialog for closing action value.
| `initialFocusAttribute` | `string` | _Default: 'dialogInitialFocus'_ – Attribute to search for in light dom for initial focus on dialog open.
| `closeButton` | `boolean` | _Default: 'false'_ - show/hide the dismiss button
| `closeButton` | `boolean` | _Default: 'false'_ - show/hide the dismiss button
| `topPosition` | `boolean` | _Default: 'false'_ - override the dialog centering to the screen and allow setting a unique top. Need to be used with defining value for `--dialog-top-position`


### Methods

Expand Down Expand Up @@ -55,3 +57,10 @@ This component is an extension of [<mwc-dialog>](https://github.com/material-com
| `opened` | `mwc-dialog` | `{}` | Fired once the dialog is finished opening (after animation).
| `closing` | `mwc-dialog` | `{action: string}` | Fired when the dialog is is beginning to close. Detail is the action that closed the dialog.
| `closed` | `mwc-dialog` | `{action: string}` | Fired once the dialog is finished closing (after animation). Detail is the action that closed the dialog.

## CSS Custom Properties

| Property | Default | Description |
|--------------------------------|-------|-----------------------------------------------------------------------------|
| `--dialog-top-position` | none | Sets the dialog top position. Need to be used with the `topPosition` property |

7 changes: 7 additions & 0 deletions components/dialog/src/vwc-dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@
width: 100%;
}
}

:host([topPosition]) {
.mdc-dialog {
top: var(--dialog-top-position);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a wild card? do we want to maybe limit it to pre-defined tokens?

Copy link
Contributor Author

@rachelbt rachelbt Feb 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean this?:
$dialog-top-position: 100px;
top: var(#{$dialog-top-position}, --dialog-top-position);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean be able to prevent arbitrary values. not sure what was the design decision eventually

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to 4 predefined sizes

height: auto;
}
}
7 changes: 7 additions & 0 deletions components/dialog/src/vwc-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export class VWCDialog extends MWCDialog {
})
closeButton?: boolean;

@property({
attribute: 'topPosition',
type: Boolean,
reflect: true
})
topPosition?: boolean;

rachelbt marked this conversation as resolved.
Show resolved Hide resolved
protected override firstUpdated() {
super.firstUpdated();
this.addDismissButton();
Expand Down
3 changes: 3 additions & 0 deletions components/dialog/stories/dialog.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Modal.args = { heading: 'This is a modal window', scrimClickAction: '' };
export const CloseButton = Template.bind({});
CloseButton.args = { 'close-button': 'true', heading: 'This is a modal window with a close button' };

export const topPosition = Template.bind({});
topPosition.args = { heading: 'Hello Modal!', topPosition: true, style: '--dialog-top-position: 50px'};

function handleOpenDialogClick(e) {
document.querySelector('vwc-dialog').show();
}