Skip to content

Commit

Permalink
Alert docs (#137)
Browse files Browse the repository at this point in the history
* Update README.md

* Use `v3`'s default values

* Update README.md

* remove getters. rely on Values API.

Co-authored-by: Chris Oliver <[email protected]>
  • Loading branch information
rockwellll and excid3 authored Feb 2, 2022
1 parent 5e138ab commit 0f6fed2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ Alerts are set up to slide into view from the top-right side of the
screen. Clicking on the "X" button will cause the alert to slide back
out of view and be removed from the DOM.

- `data-alert-dismiss-after-value` can be provided to make the alert dimiss after x miliseconds. Default is `undefined`.
- `data-alert-show-delay-value` can be set to tell the alert to show itself after x miliseconds. Defaults to `200` miliseconds.
- `data-alert-remove-delay-value` can be set to tell the alert to hide itself after x milisconds. Defaults to `1100` miliseconds.
- `data-alert-show-class` is a set of all classes to apply on the alert when it's shown.
- `data-alert-hide-class` is a set of all classes to apply on the alert when it's hidden.

### Dropdowns

![Dropdowns](https://d3vv6lp55qjaqc.cloudfront.net/items/3X1m1v1w2g1M3P0F2p2C/Screen%20Shot%202018-12-07%20at%201.23.52%20PM.png?X-CloudApp-Visitor-Id=bcd17e7039e393c836f30de901088b96&v=4c0ae15f)
Expand Down
25 changes: 4 additions & 21 deletions src/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
static values = {
dismissAfter: Number,
showDelay: Number,
removeDelay: Number

showDelay: { type: Number, default: 200 },
removeDelay: { type: Number, default: 1100 }
}
static classes = ["show", "hide"]

Expand All @@ -44,7 +43,7 @@ export default class extends Controller {
connect() {
setTimeout(() => {
this.show()
}, this.showAfter)
}, this.showDelayValue)

// Auto dimiss if defined
if (this.hasDismissAfterValue) {
Expand All @@ -59,7 +58,7 @@ export default class extends Controller {

setTimeout(() => {
this.element.remove()
}, this.removeAfter)
}, this.removeDelayValue)
}

show() {
Expand All @@ -71,20 +70,4 @@ export default class extends Controller {
this.element.classList.add(...this.hideClasses)
this.element.classList.remove(...this.showClasses)
}

get removeAfter() {
if (this.hasRemoveDelayValue) {
return this.removeDelayValue
} else {
return 1100
}
}

get showAfter() {
if (this.hasShowDelayValue) {
return this.showDelayValue
} else {
return 200
}
}
}

0 comments on commit 0f6fed2

Please sign in to comment.