Skip to content

Commit

Permalink
feat(notification-toast): add auto-hide prop, closes #948 (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinLaubenstein authored Apr 13, 2022
1 parent a073dfb commit aa1c3be
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export class NotificationToast {
@Prop() positionVertical?: number = 12;
/** (optional) Toast position right */
@Prop() positionHorizontal?: number = 12;
/** (optional) Toast auto hide */
@Prop() autoHide?: boolean = false;
/** (optional) Toast auto hide duration */
@Prop() autoHideDuration?: number = 3000;
/** (optional) Toast fade duration */
@Prop() fadeDuration?: number = 500;
/** (optional) Injected CSS styles */
Expand All @@ -69,6 +73,12 @@ export class NotificationToast {
this.alignmentHorizontal = alignmentParts[1];
}

componentDidRender() {
if (this.autoHide === true) {
setTimeout(this.close, this.autoHideDuration);
}
}

close = () => {
this.hideToast = true;
setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
| -------------------- | --------------------- | ---------------------------------------------- | -------------------------------------------------------------- | ----------------- |
| `alignment` | `alignment` | (optional) Alignment choose for top and bottom | `"bottom-left" \| "bottom-right" \| "top-left" \| "top-right"` | `'top-right'` |
| `animated` | `animated` | (optional) Animated toast | `boolean` | `true` |
| `autoHide` | `auto-hide` | (optional) Toast auto hide | `boolean` | `false` |
| `autoHideDuration` | `auto-hide-duration` | (optional) Toast auto hide duration | `number` | `3000` |
| `fadeDuration` | `fade-duration` | (optional) Toast fade duration | `number` | `500` |
| `opened` | `opened` | (optional) Toast opened | `boolean` | `undefined` |
| `positionHorizontal` | `position-horizontal` | (optional) Toast position right | `number` | `12` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const Template = (args, { argTypes }) => ({
:variant="variant"
:alignment="alignment"
:opened="opened"
:auto-hide-duration="autoHideDuration"
:auto-hide="autoHide"
><p slot="header">Informational toast headline</p>
</scale-notification-toast>
</div>
Expand Down Expand Up @@ -191,6 +193,29 @@ export const TemplateLink = (args, { argTypes }) => ({
</scale-notification-toast>
```

## Timeout

<Canvas withSource="none">
<Story
name="Timeout"
args={{
opened: true,
autoHide: true,
autHideDuration: '4000',
}}
>
{Template.bind({})}
</Story>
</Canvas>

```html
<scale-notification-toast opened>
<p slot="header" auto-hide auto-hide-duration="4000">
Informational toast headline
</p>
</scale-notification-toast>
```

## With Text

<Canvas withSource="none">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default {
positionVertical: { type: Number, default: 12 },
positionHorizontal: { type: Number, default: 12 },
fadeDuration: { type: Number, default: 500 },
autoHideDuration: { type: Number, default: 3000 },
autoHide: { type: Boolean, default: false },
styles: { type: String },
},
};
Expand Down

0 comments on commit aa1c3be

Please sign in to comment.