Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wittjosiah/elm-alerts
Alert system with several customization options build purely in elm
https://github.com/wittjosiah/elm-alerts
alertmanager alerts elm elm-css elm-lang
Last synced: about 1 month ago
JSON representation
Alert system with several customization options build purely in elm
- Host: GitHub
- URL: https://github.com/wittjosiah/elm-alerts
- Owner: wittjosiah
- License: bsd-3-clause
- Created: 2017-07-06T21:58:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-30T00:57:08.000Z (about 7 years ago)
- Last Synced: 2024-10-13T20:21:03.963Z (2 months ago)
- Topics: alertmanager, alerts, elm, elm-css, elm-lang
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/wittjosiah/elm-alerts/latest
- Size: 109 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-alerts
This is an alert message library for Elm.
Currently it forces use to use default Html for alerts, perhaps at some point I will separate the default into a submodule and allow custom Html.
## Usage
Add alerts to your model
```
type alias Model =
{ ...
, alerts : Alert.Model
}
```Initialize alerts in your model
```
initModel : Model
initModel =
{ ...
, alerts = Alert.initModel True
}
```Add alerts in your messages
```
type Msg
= ...
| AlertMsg Alert.Msg
```Add alerts to your view
```
view : Model -> Html Msg
view model =
div []
[ ...
, Html.map AlertMsg <| Alert.view model.alerts
]
```Add alerts subscriptions
```
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ ...
, Sub.map AlertMsg <| Alert.subscriptions model.alerts
]
```Handle alert updates
```
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
... ->
AlertMsg alertMsg ->
let
( alerts, cmd ) =
Alert.update alertMsg model.alerts
in
( { model | alerts = alerts }
, Cmd.map AlertMsg cmd
)
```## Examples
Example of how to display an alert
```
button
[ onClick <|
AlertMsg <|
Alert.AddAlert
{ type_ = Alert.Error
, message = model.message
, untilRemove = model.untilRemove
, icon = model.icon
}
]
[ text "Error" ]
```For a more complete example see the [examples folder](https://github.com/wittjosiah/elm-alerts/tree/master/examples).