1 | # ng2 - flashbox
|
2 | [![npm version](https://img.shields.io/npm/v/ng2-flashbox.svg)](https://www.npmjs.com/package/ng2-flashbox) [![npm downloads-monthly](https://img.shields.io/npm/dm/ng2-flashbox.svg)](https://www.npmjs.com/package/ng2-flashbox) [![npm downloads-total](https://img.shields.io/npm/dt/ng2-flashbox.svg)](https://www.npmjs.com/package/ng2-flashbox)
|
3 |
|
4 | FlashBox component is angular2 component provided to display simple user information messages.
|
5 |
|
6 | GitHub repository for component module can be found here [ng2-flashbox](https://github.com/vladimirpavk/ng2-flashbox/).
|
7 |
|
8 | GitHub repository for sample application(Angular4, SystemJS) can be found here [Angular4-FlashBoxComponent](https://github.com/vladimirpavk/Angular4-FlashBoxComponent).
|
9 |
|
10 | Online sample application can be found at github pages [online-demo](https://vladimirpavk.github.io/Angular4-FlashBoxComponent/).
|
11 |
|
12 | ### Dependencies
|
13 | FlashBox is angular2 component dependent on only **@angular/core** and **@angular/platform-browser** modules.
|
14 |
|
15 | ### Installation
|
16 | ```
|
17 | npm install ng2-flashbox --save
|
18 | ```
|
19 |
|
20 | ### How to use FlashBox component
|
21 | FlashBox component is (for now only) part of the CommonComponents module.
|
22 |
|
23 | In order to use the module you must configure your module loader. In case you use **systemjs** module loader add the following mapings:
|
24 | ```
|
25 | System.config({
|
26 | ...
|
27 | paths: {
|
28 | ...
|
29 | 'npm:': 'node_modules/'
|
30 | ...
|
31 | },
|
32 | map: {
|
33 | ...
|
34 | 'ng2-flashbox': 'npm:ng2-flashbox'
|
35 | ...
|
36 | },
|
37 | packages: {
|
38 | ...
|
39 | 'ng2-flashbox': {
|
40 | main: 'index',
|
41 | defaultExtension: 'js'
|
42 | }
|
43 | ...
|
44 | }
|
45 | ...
|
46 | })
|
47 | ```
|
48 |
|
49 | In your application module definition file import CommonComponents module.
|
50 | ```
|
51 | ...
|
52 | Import { CommonComponentsModule } from 'ng2-flashbox';
|
53 | ...
|
54 | @NgModule({
|
55 | ...
|
56 | imports: [ ...
|
57 | CommonComponentsModule
|
58 | ...
|
59 | ],
|
60 | ...
|
61 | })
|
62 | ```
|
63 |
|
64 | Now we can use FlashBox component in our module declared components templates with ```<flash-box>``` element.
|
65 | Place your HTML based user information message inside element.
|
66 |
|
67 | ```
|
68 | <flash-box>
|
69 | <!-- HTML Message -->
|
70 | <div style="border-type: solid; border-width:2px">
|
71 | <label style="color: rgb(0,0,0); text-decoration: underline;">Information message</label>
|
72 | <label>
|
73 | Any message
|
74 | </label>
|
75 | </div>
|
76 | </flash-box>
|
77 |
|
78 | ```
|
79 |
|
80 | ### Attributes
|
81 |
|
82 | ```
|
83 | <flash-box type="type_value" position="position_value" max-width="maxwidth_value" setTimeout="setTimeout_value">
|
84 | <!-- HTML message -->
|
85 | </flash-box>
|
86 | ```
|
87 |
|
88 | 1. **type_value**: *string*, default: **primary**
|
89 | Specify FlashBox type.
|
90 |
|
91 | Available types: **default**, **primary**, **success**, **info**, **warning**, **danger**
|
92 | based on default bootstrap label types
|
93 |
|
94 | 2. **position_value**: *string*, default: **tr**.
|
95 | Specify FlashBox position.
|
96 |
|
97 | Available values:
|
98 | * **tr** - top-right,
|
99 | * **tm** - top-middle,
|
100 | * **tl** - top-left,
|
101 | * **cr** - center-right,
|
102 | * **cm** - center-middle,
|
103 | * **cl** - center-left,
|
104 | * **br** - bottom-right,
|
105 | * **bm** - bottom-middle,
|
106 | * **bl** - bottom-left
|
107 |
|
108 | 3. **max-width_value**: *string*, default: **300px**
|
109 | Specify FlashBox component maximum width.
|
110 |
|
111 | 4. **setTimeout_value**: *number*, default: **2000**
|
112 | Specify the amount of time the component is visible in *ms*. Default is **2 sec**.
|
113 |
|
114 |
|
115 | ### Actions
|
116 |
|
117 | In order to cause an flashbox control action use angular2 template local variable system or controler method invokation.
|
118 |
|
119 | #### **Template local variable example**
|
120 | ```
|
121 | <flash-box .... #tlv_name>
|
122 | ....
|
123 | </flash-box>
|
124 |
|
125 | <button (click)="tlv_name.available_action()">Cause flashbox action</button>
|
126 | ```
|
127 |
|
128 | #### **Controller method invokation example**
|
129 |
|
130 | reference component source
|
131 | ```
|
132 | import { FlashBoxComponent } from 'ng2-flashbox';
|
133 | ```
|
134 |
|
135 | reference component from template local variable using
|
136 | ```
|
137 | @ViewChild("tlv_name") tlv:FlashBoxComponent;
|
138 | tlv.available_action();
|
139 | ```
|
140 |
|
141 | ##### **Available actions(available_action())**:
|
142 | 1. **flashOnce():void** - Show flashbox only once for **setTimeout** amount of time
|
143 | 2. **show():void** - Make control visible for unlimited amount of time (or untill some other action happens)
|
144 | 3. **hide():void** - Make control hidden for unlimited amount of time (or untill some other action happens)
|
145 | 4. **startFlashing():void** - Start flashing for unlimited amount of time (or untill some other action happens).
|
146 | Transition period from unvisible to visible is set to **0,5 sec** and is currently unconfigurable. The flashbox control us shown for **setTimeout** amount of time.
|
147 | 5. **stopFlashing():void** - Stop flashing
|
148 | 6. **toogle():void** - Toggle show/hide control |
\ | No newline at end of file |