bootstrap5-toggle 5.0.5 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -23
- package/README.md +267 -265
- package/README.template.md +292 -291
- package/css/bootstrap5-toggle.css +211 -211
- package/css/bootstrap5-toggle.min.css +12 -12
- package/css/bootstrap5-toggle.min.css.map +1 -1
- package/js/bootstrap5-toggle.ecmas.js +531 -504
- package/js/bootstrap5-toggle.ecmas.min.js +13 -13
- package/js/bootstrap5-toggle.ecmas.min.js.map +1 -1
- package/js/bootstrap5-toggle.jquery.js +491 -464
- package/js/bootstrap5-toggle.jquery.min.js +13 -13
- package/js/bootstrap5-toggle.jquery.min.js.map +1 -1
- package/package.json +65 -65
- package/debug/.gitignore +0 -2
package/LICENSE
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
- Copyright (c) 2011-2014 Min Hur, The New York Times Company
|
|
4
|
-
- Copyright (c) 2018-2019 Brent Ely
|
|
5
|
-
- Copyright (c) 2022 Pablo Alcaraz Martínez
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in
|
|
15
|
-
all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
-
THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
- Copyright (c) 2011-2014 Min Hur, The New York Times Company
|
|
4
|
+
- Copyright (c) 2018-2019 Brent Ely
|
|
5
|
+
- Copyright (c) 2022 Pablo Alcaraz Martínez
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,49 +1,50 @@
|
|
|
1
|
-
[](https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE)
|
|
2
|
-
[](https://github.com/palcarazm/bootstrap5-toggle/releases)
|
|
3
|
-
[](https://getbootstrap.com/docs/5.0)
|
|
4
|
-
[](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)
|
|
5
|
-
[](https://www.npmjs.com/package/bootstrap5-toggle)
|
|
6
|
-
[](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Build+Check%22)
|
|
7
|
-
[](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Cypress+Tests%22)
|
|
8
|
-
[](https://github.com/palcarazm/bootstrap5-toggle/security/policy)
|
|
10
|
-
[](https://github.com/sponsors/palcarazm)
|
|
11
|
-
[](https://openbase.com/js/bootstrap5-toggle?utm_source=embedded&utm_medium=badge&utm_campaign=rating-badge&utm_term=js/bootstrap5-toggle)
|
|
12
|
-
|
|
13
|
-
# Bootstrap 5 Toggle
|
|
14
|
-
|
|
15
|
-
**Bootstrap 5 Toggle** is a bootstrap plugin/widget that converts checkboxes into toggles.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
#### Library Distributions
|
|
20
|
-
|
|
21
|
-
| Version | Bootstrap Support | Last Release | End of Life |
|
|
22
|
-
| :----------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
23
|
-
| [v5](https://github.com/palcarazm/bootstrap5-toggle/tree/v5) | [](https://getbootstrap.com/docs/5.0) | [](https://github.com/palcarazm/bootstrap5-toggle/releases) | [](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
|
|
24
|
-
| [v4](https://github.com/palcarazm/bootstrap5-toggle/tree/v4) | [](https://getbootstrap.com/docs/5.0) | [](https://github.com/palcarazm/bootstrap5-toggle/releases) | [](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
|
|
25
|
-
| [v3](https://github.com/palcarazm/bootstrap5-toggle/tree/v3) | [](https://getbootstrap.com/docs/4.0) | [](https://github.com/palcarazm/bootstrap5-toggle/releases) | [](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
|
|
26
|
-
|
|
27
|
-
See EOL for each version in [Security Policy Page](https://github.com/palcarazm/bootstrap5-toggle/security/policy).
|
|
28
|
-
|
|
29
|
-
# Demos
|
|
30
|
-
|
|
31
|
-
**Demos and API Docs:** https://palcarazm.github.io/bootstrap5-toggle/
|
|
32
|
-
|
|
33
|
-
# Related Bootstrap Plugins
|
|
34
|
-
|
|
35
|
-
<div align="center">
|
|
36
|
-
<a href="https://github.com/palcarazm/bs-darkmode" title="Boostrap Darkmode"
|
|
37
|
-
><img
|
|
38
|
-
src="https://github-readme-stats.vercel.app/api/pin/?username=palcarazm&repo=bs-darkmode&border_radius=10&show_owner=true"
|
|
39
|
-
/></a>
|
|
40
|
-
</div>
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
<!-- To update TOC run .\node_modules\.bin\doctoc README.md --github -->
|
|
1
|
+
[](https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE)
|
|
2
|
+
[](https://github.com/palcarazm/bootstrap5-toggle/releases)
|
|
3
|
+
[](https://getbootstrap.com/docs/5.0)
|
|
4
|
+
[](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)
|
|
5
|
+
[](https://www.npmjs.com/package/bootstrap5-toggle)
|
|
6
|
+
[](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Build+Check%22)
|
|
7
|
+
[](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Cypress+Tests%22)
|
|
8
|
+
[](https://snyk.io/advisor/npm-package/bootstrap5-toggle)
|
|
9
|
+
[](https://github.com/palcarazm/bootstrap5-toggle/security/policy)
|
|
10
|
+
[](https://github.com/sponsors/palcarazm)
|
|
11
|
+
[](https://openbase.com/js/bootstrap5-toggle?utm_source=embedded&utm_medium=badge&utm_campaign=rating-badge&utm_term=js/bootstrap5-toggle)
|
|
12
|
+
|
|
13
|
+
# Bootstrap 5 Toggle
|
|
14
|
+
|
|
15
|
+
**Bootstrap 5 Toggle** is a bootstrap plugin/widget that converts checkboxes into toggles.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
#### Library Distributions
|
|
20
|
+
|
|
21
|
+
| Version | Bootstrap Support | Last Release | End of Life |
|
|
22
|
+
| :----------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
23
|
+
| [v5](https://github.com/palcarazm/bootstrap5-toggle/tree/v5) | [](https://getbootstrap.com/docs/5.0) | [](https://github.com/palcarazm/bootstrap5-toggle/releases) | [](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
|
|
24
|
+
| [v4](https://github.com/palcarazm/bootstrap5-toggle/tree/v4) | [](https://getbootstrap.com/docs/5.0) | [](https://github.com/palcarazm/bootstrap5-toggle/releases) | [](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
|
|
25
|
+
| [v3](https://github.com/palcarazm/bootstrap5-toggle/tree/v3) | [](https://getbootstrap.com/docs/4.0) | [](https://github.com/palcarazm/bootstrap5-toggle/releases) | [](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
|
|
26
|
+
|
|
27
|
+
See EOL for each version in [Security Policy Page](https://github.com/palcarazm/bootstrap5-toggle/security/policy).
|
|
28
|
+
|
|
29
|
+
# Demos
|
|
30
|
+
|
|
31
|
+
**Demos and API Docs:** https://palcarazm.github.io/bootstrap5-toggle/
|
|
32
|
+
|
|
33
|
+
# Related Bootstrap Plugins
|
|
34
|
+
|
|
35
|
+
<div align="center">
|
|
36
|
+
<a href="https://github.com/palcarazm/bs-darkmode" title="Boostrap Darkmode"
|
|
37
|
+
><img
|
|
38
|
+
src="https://github-readme-stats.vercel.app/api/pin/?username=palcarazm&repo=bs-darkmode&border_radius=10&show_owner=true"
|
|
39
|
+
/></a>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
<!-- To update TOC run .\node_modules\.bin\doctoc README.md --github -->
|
|
45
45
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
46
46
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
47
|
+
|
|
47
48
|
|
|
48
49
|
- [Installation](#installation)
|
|
49
50
|
- [CDN](#cdn)
|
|
@@ -65,224 +66,225 @@ See EOL for each version in [Security Policy Page](https://github.com/palcarazm/
|
|
|
65
66
|
- [Collaborators welcom!](#collaborators-welcom)
|
|
66
67
|
|
|
67
68
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
68
|
-
|
|
69
|
-
---
|
|
70
|
-
|
|
71
|
-
# Installation
|
|
72
|
-
|
|
73
|
-
## CDN
|
|
74
|
-
|
|
75
|
-
[](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)
|
|
76
|
-
|
|
77
|
-
### ECMAS Interface
|
|
78
|
-
|
|
79
|
-
```html
|
|
80
|
-
<link
|
|
81
|
-
href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.0
|
|
82
|
-
rel="stylesheet" />
|
|
83
|
-
<script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.0
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### jQuery Interface
|
|
87
|
-
|
|
88
|
-
```html
|
|
89
|
-
<link
|
|
90
|
-
href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.0
|
|
91
|
-
rel="stylesheet" />
|
|
92
|
-
<script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.0
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## Download
|
|
96
|
-
|
|
97
|
-
[](https://github.com/palcarazm/bootstrap5-toggle/releases)
|
|
98
|
-
|
|
99
|
-
## NPM
|
|
100
|
-
|
|
101
|
-
[](https://www.npmjs.com/package/bootstrap5-toggle)
|
|
102
|
-
|
|
103
|
-
```ksh
|
|
104
|
-
npm install bootstrap5-toggle@5.0
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Yarn
|
|
108
|
-
|
|
109
|
-
```ksh
|
|
110
|
-
yarn add bootstrap5-toggle@5.0
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
# Usage
|
|
114
|
-
|
|
115
|
-
## Initialize With HTML
|
|
116
|
-
|
|
117
|
-
Simply add `data-toggle="toggle"` to automatically convert a plain checkbox into a bootstrap 5 toggle.
|
|
118
|
-
|
|
119
|
-
```html
|
|
120
|
-
<input id="chkToggle" type="checkbox" data-toggle="toggle" />
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Initialize With Code
|
|
124
|
-
|
|
125
|
-
Toggles can also be initialized via JavaScript code.
|
|
126
|
-
|
|
127
|
-
EX: Initialize id `chkToggle` with a single line of JavaScript.
|
|
128
|
-
|
|
129
|
-
```html
|
|
130
|
-
<input id="chkToggle" type="checkbox" checked />
|
|
131
|
-
<script>
|
|
132
|
-
document.querySelector("#chkToggle").bootstrapToggle();
|
|
133
|
-
</script>
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
# API
|
|
137
|
-
|
|
138
|
-
## Options
|
|
139
|
-
|
|
140
|
-
- Options can be passed via data attributes or JavaScript
|
|
141
|
-
- For data attributes, append the option name to `data-` (ex: `data-on="Enabled"`)
|
|
142
|
-
|
|
143
|
-
```html
|
|
144
|
-
<input
|
|
145
|
-
type="checkbox"
|
|
146
|
-
data-toggle="toggle"
|
|
147
|
-
data-onlabel="Enabled"
|
|
148
|
-
data-offlabel="Disabled" />
|
|
149
|
-
<input type="checkbox" id="toggle-two" />
|
|
150
|
-
<script>
|
|
151
|
-
document.querySelector("#toggle-two").bootstrapToggle({
|
|
152
|
-
on: "Enabled",
|
|
153
|
-
off: "Disabled",
|
|
154
|
-
});
|
|
155
|
-
</script>
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
| Name | Type | Default | Description |
|
|
159
|
-
| ---------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
160
|
-
| `onlabel` | string/html | "On" | Text of the on toggle |
|
|
161
|
-
| `offlabel` | string/html | "Off" | Text of the off toggle |
|
|
162
|
-
| `size` | string | "normal" | Size of the toggle. Possible values are: `large`, `normal`, `small`, `mini`. |
|
|
163
|
-
| `onstyle` | string | "primary" | Style of the on toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
|
|
164
|
-
| `offstyle` | string | "secondary" | Style of the off toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
|
|
165
|
-
| `onvalue` | string | _null_ | Sets on state value |
|
|
166
|
-
| `offvalue` | string | _null_ | Sets off state value |
|
|
167
|
-
| `ontitle` | string | _null_ | Title of the on toggle |
|
|
168
|
-
| `offtitle` | string | _null_ | Title of the off toggle |
|
|
169
|
-
| `style` | string | | Appends the value to the class attribute of the toggle. This can be used to apply custom styles. Refer to Custom Styles for reference. |
|
|
170
|
-
| `width` | integer | _null_ | Sets the width of the toggle. if set to _null_, width will be auto-calculated. |
|
|
171
|
-
| `height` | integer | _null_ | Sets the height of the toggle. if set to _null_, height will be auto-calculated. |
|
|
172
|
-
| `tabindex` | integer | 0 | Sets the tabindex of the toggle. |
|
|
173
|
-
| `tristate` | boolean | false | Sets tristate support |
|
|
174
|
-
|
|
175
|
-
## Methods
|
|
176
|
-
|
|
177
|
-
Methods can be used to control toggles directly.
|
|
178
|
-
|
|
179
|
-
```html
|
|
180
|
-
<input id="toggle-demo" type="checkbox" data-toggle="toggle" />
|
|
181
|
-
<script>
|
|
182
|
-
const toggleDemo = document.querySelector("#toggle-demo");
|
|
183
|
-
</script>
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
| Method | Example | Description
|
|
187
|
-
| ------------- | --------------------------------------------- |
|
|
188
|
-
| initialize | `toggleDemo.bootstrapToggle()` | Initializes the toggle plugin with options
|
|
189
|
-
| destroy | `toggleDemo.bootstrapToggle('destroy')` | Destroys the toggle
|
|
190
|
-
|
|
|
191
|
-
|
|
|
192
|
-
|
|
|
193
|
-
|
|
|
194
|
-
|
|
|
195
|
-
|
|
|
196
|
-
|
|
|
197
|
-
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
<
|
|
210
|
-
<
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
<
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
<
|
|
260
|
-
<button class="btn btn-
|
|
261
|
-
<button class="btn btn-
|
|
262
|
-
<button class="btn btn-
|
|
263
|
-
<
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
- :
|
|
283
|
-
- :
|
|
284
|
-
- :
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
# Installation
|
|
73
|
+
|
|
74
|
+
## CDN
|
|
75
|
+
|
|
76
|
+
[](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)
|
|
77
|
+
|
|
78
|
+
### ECMAS Interface
|
|
79
|
+
|
|
80
|
+
```html
|
|
81
|
+
<link
|
|
82
|
+
href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.1.0/css/bootstrap5-toggle.min.css"
|
|
83
|
+
rel="stylesheet" />
|
|
84
|
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.1.0/js/bootstrap5-toggle.ecmas.min.js"></script>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### jQuery Interface
|
|
88
|
+
|
|
89
|
+
```html
|
|
90
|
+
<link
|
|
91
|
+
href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.1.0/css/bootstrap5-toggle.min.css"
|
|
92
|
+
rel="stylesheet" />
|
|
93
|
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.1.0/js/bootstrap5-toggle.jquery.min.js"></script>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Download
|
|
97
|
+
|
|
98
|
+
[](https://github.com/palcarazm/bootstrap5-toggle/releases)
|
|
99
|
+
|
|
100
|
+
## NPM
|
|
101
|
+
|
|
102
|
+
[](https://www.npmjs.com/package/bootstrap5-toggle)
|
|
103
|
+
|
|
104
|
+
```ksh
|
|
105
|
+
npm install bootstrap5-toggle@5.1.0
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Yarn
|
|
109
|
+
|
|
110
|
+
```ksh
|
|
111
|
+
yarn add bootstrap5-toggle@5.1.0
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
# Usage
|
|
115
|
+
|
|
116
|
+
## Initialize With HTML
|
|
117
|
+
|
|
118
|
+
Simply add `data-toggle="toggle"` to automatically convert a plain checkbox into a bootstrap 5 toggle.
|
|
119
|
+
|
|
120
|
+
```html
|
|
121
|
+
<input id="chkToggle" type="checkbox" data-toggle="toggle" />
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Initialize With Code
|
|
125
|
+
|
|
126
|
+
Toggles can also be initialized via JavaScript code.
|
|
127
|
+
|
|
128
|
+
EX: Initialize id `chkToggle` with a single line of JavaScript.
|
|
129
|
+
|
|
130
|
+
```html
|
|
131
|
+
<input id="chkToggle" type="checkbox" checked />
|
|
132
|
+
<script>
|
|
133
|
+
document.querySelector("#chkToggle").bootstrapToggle();
|
|
134
|
+
</script>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
# API
|
|
138
|
+
|
|
139
|
+
## Options
|
|
140
|
+
|
|
141
|
+
- Options can be passed via data attributes or JavaScript
|
|
142
|
+
- For data attributes, append the option name to `data-` (ex: `data-on="Enabled"`)
|
|
143
|
+
|
|
144
|
+
```html
|
|
145
|
+
<input
|
|
146
|
+
type="checkbox"
|
|
147
|
+
data-toggle="toggle"
|
|
148
|
+
data-onlabel="Enabled"
|
|
149
|
+
data-offlabel="Disabled" />
|
|
150
|
+
<input type="checkbox" id="toggle-two" />
|
|
151
|
+
<script>
|
|
152
|
+
document.querySelector("#toggle-two").bootstrapToggle({
|
|
153
|
+
on: "Enabled",
|
|
154
|
+
off: "Disabled",
|
|
155
|
+
});
|
|
156
|
+
</script>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| Name | Type | Default | Description |
|
|
160
|
+
| ---------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
161
|
+
| `onlabel` | string/html | "On" | Text of the on toggle |
|
|
162
|
+
| `offlabel` | string/html | "Off" | Text of the off toggle |
|
|
163
|
+
| `size` | string | "normal" | Size of the toggle. Possible values are: `large`, `normal`, `small`, `mini`. |
|
|
164
|
+
| `onstyle` | string | "primary" | Style of the on toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
|
|
165
|
+
| `offstyle` | string | "secondary" | Style of the off toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
|
|
166
|
+
| `onvalue` | string | _null_ | Sets on state value |
|
|
167
|
+
| `offvalue` | string | _null_ | Sets off state value |
|
|
168
|
+
| `ontitle` | string | _null_ | Title of the on toggle |
|
|
169
|
+
| `offtitle` | string | _null_ | Title of the off toggle |
|
|
170
|
+
| `style` | string | | Appends the value to the class attribute of the toggle. This can be used to apply custom styles. Refer to Custom Styles for reference. |
|
|
171
|
+
| `width` | integer | _null_ | Sets the width of the toggle. if set to _null_, width will be auto-calculated. |
|
|
172
|
+
| `height` | integer | _null_ | Sets the height of the toggle. if set to _null_, height will be auto-calculated. |
|
|
173
|
+
| `tabindex` | integer | 0 | Sets the tabindex of the toggle. |
|
|
174
|
+
| `tristate` | boolean | false | Sets tristate support |
|
|
175
|
+
|
|
176
|
+
## Methods
|
|
177
|
+
|
|
178
|
+
Methods can be used to control toggles directly.
|
|
179
|
+
|
|
180
|
+
```html
|
|
181
|
+
<input id="toggle-demo" type="checkbox" data-toggle="toggle" />
|
|
182
|
+
<script>
|
|
183
|
+
const toggleDemo = document.querySelector("#toggle-demo");
|
|
184
|
+
</script>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
| Method | Example | Description |
|
|
188
|
+
| ------------- | --------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
189
|
+
| initialize | `toggleDemo.bootstrapToggle()` | Initializes the toggle plugin with options |
|
|
190
|
+
| destroy | `toggleDemo.bootstrapToggle('destroy')` | Destroys the toggle |
|
|
191
|
+
| rerender | `toggleDemo.bootstrapToggle('rerender')` | Rerender toggle with the appropriated size. Useful when parent is collapsed at first. |
|
|
192
|
+
| on | `toggleDemo.bootstrapToggle('on')` | Sets the toggle to 'On' state |
|
|
193
|
+
| off | `toggleDemo.bootstrapToggle('off')` | Sets the toggle to 'Off' state |
|
|
194
|
+
| toggle | `toggleDemo.bootstrapToggle('toggle')` | Toggles the state of the toggle on/off |
|
|
195
|
+
| enable | `toggleDemo.bootstrapToggle('enable')` | Enables the toggle |
|
|
196
|
+
| disable | `toggleDemo.bootstrapToggle('disable')` | Disables the toggle |
|
|
197
|
+
| readonly | `toggleDemo.bootstrapToggle('readonly')` | Disables the toggle but preserve checkbox enabled |
|
|
198
|
+
| indeterminate | `toggleDemo.bootstrapToggle('indeterminate')` | Sets the toggle to 'indeterminate' state |
|
|
199
|
+
| determinate | `toggleDemo.bootstrapToggle('determinate')` | Sets the toggle to 'determinate' state |
|
|
200
|
+
|
|
201
|
+
# Events
|
|
202
|
+
|
|
203
|
+
## Event Propagation
|
|
204
|
+
|
|
205
|
+
Note All events are propagated to and from input element to the toggle.
|
|
206
|
+
|
|
207
|
+
You should listen to events from the `<input type="checkbox">` directly rather than look for custom events.
|
|
208
|
+
|
|
209
|
+
```html
|
|
210
|
+
<input id="toggle-event" type="checkbox" data-toggle="toggle" />
|
|
211
|
+
<div id="console-event"></div>
|
|
212
|
+
<script>
|
|
213
|
+
document.querySelector("#toggle-event").change(function (e) {
|
|
214
|
+
document
|
|
215
|
+
.querySelector("#console-event")
|
|
216
|
+
.html("Toggle: " + e.target.prop("checked"));
|
|
217
|
+
});
|
|
218
|
+
</script>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Stopping Event Propagation
|
|
222
|
+
|
|
223
|
+
Passing `true` to the on, off, toggle, determinate and indeterminate methods will enable the silent option to prevent the control from propagating the change event in cases where you want to update the controls on/off state, but do not want to fire the onChange event.
|
|
224
|
+
|
|
225
|
+
```html
|
|
226
|
+
<input id="toggle-silent" type="checkbox" data-toggle="toggle" />
|
|
227
|
+
<button class="btn btn-success" onclick="toggleApiOnSilent()">
|
|
228
|
+
On by API (silent)
|
|
229
|
+
</button>
|
|
230
|
+
<button class="btn btn-success" onclick="toggleApiOffSilent()">
|
|
231
|
+
Off by API (silent)
|
|
232
|
+
</button>
|
|
233
|
+
<button class="btn btn-warning" onclick="toggleApiOnNotSilent()">
|
|
234
|
+
On by API (not silent)
|
|
235
|
+
</button>
|
|
236
|
+
<button class="btn btn-warning" onclick="toggleApiOffNotSilent()">
|
|
237
|
+
On by API (not silent)
|
|
238
|
+
</button>
|
|
239
|
+
<script>
|
|
240
|
+
function toggleApiOnSilent() {
|
|
241
|
+
document.querySelector("#toggle-silent").bootstrapToggle("on", true);
|
|
242
|
+
}
|
|
243
|
+
function toggleApiOffSilent() {
|
|
244
|
+
document.querySelector("#toggle-silent").bootstrapToggle("off", true);
|
|
245
|
+
}
|
|
246
|
+
function toggleApiOnNotSilent() {
|
|
247
|
+
document.querySelector("#toggle-silent").bootstrapToggle("on");
|
|
248
|
+
}
|
|
249
|
+
function toggleApiOffNotSilent() {
|
|
250
|
+
document.querySelector("#toggle-silent").bootstrapToggle("off");
|
|
251
|
+
}
|
|
252
|
+
</script>
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## API vs Input
|
|
256
|
+
|
|
257
|
+
This also means that using the API or Input to trigger events will work both ways.
|
|
258
|
+
|
|
259
|
+
```html
|
|
260
|
+
<input id="toggle-trigger" type="checkbox" data-toggle="toggle" />
|
|
261
|
+
<button class="btn btn-success" onclick="toggleApiOn()">On by API</button>
|
|
262
|
+
<button class="btn btn-danger" onclick="toggleApiOff()">Off by API</button>
|
|
263
|
+
<button class="btn btn-success" onclick="toggleInpOn()">On by Input</button>
|
|
264
|
+
<button class="btn btn-danger" onclick="toggleInpOff()">Off by Input</button>
|
|
265
|
+
<script>
|
|
266
|
+
function toggleApiOn() {
|
|
267
|
+
document.querySelector("#toggle-trigger").bootstrapToggle("on");
|
|
268
|
+
}
|
|
269
|
+
function toggleApiOff() {
|
|
270
|
+
document.querySelector("#toggle-trigger").bootstrapToggle("off");
|
|
271
|
+
}
|
|
272
|
+
function toggleInpOn() {
|
|
273
|
+
document.querySelector("#toggle-trigger").prop("checked", true).change();
|
|
274
|
+
}
|
|
275
|
+
function toggleInpOff() {
|
|
276
|
+
document.querySelector("#toggle-trigger").prop("checked", false).change();
|
|
277
|
+
}
|
|
278
|
+
</script>
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
# Collaborators welcom!
|
|
282
|
+
|
|
283
|
+
- :sos: ¿Do you need some help? Open a issue in [GitHub help wanted](https://github.com/palcarazm/bootstrap5-toggle/issues/new?assignees=&labels=help+wanted&template=help-wanted.md&title=%5BHELP%5D)
|
|
284
|
+
- :bug: ¿Do you find a bug? Open a issue in [GitHub bug report](https://github.com/palcarazm/bootstrap5-toggle/issues/new?assignees=&labels=bug&template=bug_report.md&title=%5BBUG%5D)
|
|
285
|
+
- :bulb: ¿Do you have a great idea? Open a issue in [GitHub feature request](https://github.com/palcarazm/bootstrap5-toggle/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=%5BFEATURE%5D)
|
|
286
|
+
- :computer: ¿Do you know how to fix a bug? Open a pull request in [GitHub pull repuest](https://github.com/palcarazm/bootstrap5-toggle/compare).
|
|
287
|
+
|
|
288
|
+
[](https://github.com/palcarazm/bootstrap5-toggle/graphs/contributors)
|
|
289
|
+
|
|
290
|
+
¿Do you like the project? Give us a :star: in [GitHub](https://github.com/palcarazm/bootstrap5-toggle).
|