Skip to content

Commit ac8ef1d

Browse files
committed
Reorganize README for better understanding
1 parent 5fdc156 commit ac8ef1d

File tree

1 file changed

+37
-51
lines changed

1 file changed

+37
-51
lines changed

README.md

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ $ bower install angular-toastr
3737

3838
## Usage
3939

40-
### Basic usage
41-
4240
Toastr usage is very simple, by default it comes with four types of notification messages:
4341

4442
Success:
@@ -109,35 +107,57 @@ A toast has a `isOpened` flag to see whether it is opened or not.
109107

110108
### Toastr customization
111109

112-
You can customize the entire library like:
110+
This library has two parts, a `container` and the `toasts` you put in it.
111+
112+
To configure the `container` you need to modify the `toastrConfig`, for example:
113113

114114
```javascript
115115
app.config(function(toastrConfig) {
116116
angular.extend(toastrConfig, {
117-
allowHtml: false,
118117
autoDismiss: false,
118+
containerId: 'toast-container',
119+
maxOpened: 0,
120+
newestOnTop: true,
121+
positionClass: 'toast-top-right',
122+
preventDuplicates: false,
123+
preventOpenDuplicates: false,
124+
target: 'body'
125+
});
126+
});
127+
```
128+
129+
Those are the default values, you can pick what you need from it and override with your values.
130+
131+
* **autoDismiss** If set, show only the most recent `maxOpened` toast(s)
132+
* **containerId**: The name of the container where you want to append your toasts (the container will be created for you).
133+
* **maxOpened**: Maximum number of toasts displayed at once.
134+
* **newestOnTop**: Add new toasts on top of the old one. Put on false to put them on the bottom.
135+
* **positionClass**: The position where the toasts are added.
136+
* **preventDuplicates**: Prevent duplicates of the last toast.
137+
* **preventOpenDuplicates**: Prevent duplicates of open toasts.
138+
* **target**: The element to put the toastr container.
139+
140+
To customize a `toast` you have two options. First, you can set a default option to be applied globally to all `toasts` in the same way you modified the `container`:
141+
142+
```javascript
143+
app.config(function(toastrConfig) {
144+
angular.extend(toastrConfig, {
145+
allowHtml: false,
119146
closeButton: false,
120147
closeHtml: '<button>&times;</button>',
121-
containerId: 'toast-container',
122148
extendedTimeOut: 1000,
123149
iconClasses: {
124150
error: 'toast-error',
125151
info: 'toast-info',
126152
success: 'toast-success',
127153
warning: 'toast-warning'
128-
},
129-
maxOpened: 0,
154+
},
130155
messageClass: 'toast-message',
131-
newestOnTop: true,
132156
onHidden: null,
133157
onShown: null,
134158
onTap: null,
135-
positionClass: 'toast-top-right',
136-
preventDuplicates: false,
137-
preventOpenDuplicates: false,
138159
progressBar: false,
139160
tapToDismiss: true,
140-
target: 'body',
141161
templates: {
142162
toast: 'directives/toast/toast.html',
143163
progressbar: 'directives/progressbar/progressbar.html'
@@ -149,42 +169,30 @@ app.config(function(toastrConfig) {
149169
});
150170
```
151171

152-
Those are the default values, you can pick what you need from it and override with your values.
153-
154172
* **allowHtml**: Your toast can use custom HTML here (See [Issue 3](https://github.com/Foxandxss/angular-toastr/issues/3))
155-
* **autoDismiss** If set, show only the most recent `maxOpened` toast(s)
156173
* **closeButton**: Whether to display an "X" close button on the toast.
157174
* **closeHtml**: Html element to be used as a close button.
158-
* **containerId**: The name of the container where you want to append your toasts (the container will be created for you).
159175
* **extendedTimeOut**: The timeout after you hover a toast.
160176
* **extraData**: If you override the template, you can pass global extra data to your toasts.
161177
* **iconClasses**: The default type classes for the different toasts.
162-
* **maxOpened**: Maximum number of toasts displayed at once.
163178
* **messageClass**: The class for the toast's message.
164-
* **newestOnTop**: Add new toasts on top of the old one. Put on false to put them on the bottom.
165179
* **onHidden**: A callback function called when a toast gets hidden. It receives a boolean parameter to see whether it was closed via click or not.
166180
* **onShown**: A callback function called when a toast is shown.
167181
* **onTap**: A callback function called when it is clicked.
168-
* **positionClass**: The position where the toasts are added.
169-
* **preventDuplicates**: Prevent duplicates of the last toast.
170-
* **preventOpenDuplicates**: Prevent duplicates of open toasts.
171182
* **progressBar**: A progress bar to see the timeout in real time.
172183
* **tapToDismiss**: Whether the toast should be dismissed when it is clicked.
173-
* **target**: The element to put the toastr container.
174184
* **templates**: To override the default path of the templates.
175185
* **timeOut**: The timeout before the toasts disappear.
176186
* **titleClass**: The class for the toast's title.
177187
* **toastClass**: Base class for toasts.
178188

179-
You can also override options per toast, for example:
189+
The second option is to pass a third parameter (or second if you don't need a **title**). Let see some examples:
180190

181191
Toast with custom HTML (available in both title and message):
182192

183193
```javascript
184-
app.controller('foo', function($scope, toastr) {
185-
toastr.info('<input type="checkbox" checked> Success!', 'With HTML', {
186-
allowHtml: true
187-
});
194+
toastr.info('<input type="checkbox" checked> Success!', 'With HTML', {
195+
allowHtml: true
188196
});
189197
```
190198

@@ -214,10 +222,8 @@ toastr.info('What a nice apple button', 'Button spree', {
214222
A pinky custom style (you can also create here new types with `$decorate`):
215223

216224
```javascript
217-
app.controller('foo', function($scope, toastr) {
218-
toastr.info('I am totally custom!', 'Happy toast', {
219-
iconClass: 'toast-pink'
220-
});
225+
toastr.info('I am totally custom!', 'Happy toast', {
226+
iconClass: 'toast-pink'
221227
});
222228
```
223229

@@ -232,26 +238,6 @@ app.controller('foo', function($scope, toastr) {
232238

233239
![Pink image](http://i.imgur.com/jur31Zd.png)
234240

235-
See how we passed a third parameter to the `toast`.
236-
237-
There you can override:
238-
239-
* **allowHtml**: Whether to allow HTML or not in a concrete toast.
240-
* **closeButton**: Putting a close button on the toast.
241-
* **closeHtml**: If you need to override how the close button looks like.
242-
* **extendedTimeOut**: The timeout after you hover it.
243-
* **extraData**: If you override the template, you can pass concrete extra data per toast.
244-
* **iconClass**: For the type class you want to use for the toast.
245-
* **messageClass**: If you want to modify the message look.
246-
* **onHidden**: Function to call when the toast gets hidden. It receives a boolean parameter to see whether it was closed via click or not.
247-
* **onShown**: Function to call when the toast is shown.
248-
* **onTap**: A callback function called when it is clicked.
249-
* **progressBar** Show a progress bar for the toast.
250-
* **tapToDismiss**: If you want a concrete toast to toggle the close on click.
251-
* **timeOut**: For that concrete toast timeout.
252-
* **titleClass**: To override the title class of the toast.
253-
* **toastClass**: For the main toast class.
254-
255241
### Toast template
256242

257243
If you want to use the built-in template, you can use the `angular-toastr.tpls.js` file.

0 commit comments

Comments
 (0)