bootstrap5-toggle 5.0.6 → 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.
@@ -1,291 +1,292 @@
1
- [![GitHub license](https://img.shields.io/github/license/palcarazm/bootstrap5-toggle.svg?color=informational)](https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE)
2
- [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases)
3
- [![Bootstrap 5](https://img.shields.io/static/v1?label=bootstrap&message=%5E5.0.0&color=informational&logo=bootstrap&logoColor=white)](https://getbootstrap.com/docs/5.0)
4
- [![JSDelivr Badge](https://img.shields.io/jsdelivr/npm/hm/bootstrap5-toggle?label=hits&logo=jsdelivr&logoColor=white)](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)
5
- [![NPM Badge](https://img.shields.io/npm/dm/bootstrap5-toggle?logo=npm)](https://www.npmjs.com/package/bootstrap5-toggle)
6
- [![Build](https://img.shields.io/github/actions/workflow/status/palcarazm/bootstrap5-toggle/build.yml?branch=v5&logo=npm)](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Build+Check%22)
7
- [![Test](https://img.shields.io/github/actions/workflow/status/palcarazm/bootstrap5-toggle/cypress.yml?branch=v5&label=tests&logo=cypress)](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Cypress+Tests%22)
8
- [![Security](https://img.shields.io/snyk/vulnerabilities/npm/bootstrap5-toggle@#version#?logo=snyk)](https://snyk.io/advisor/npm-package/bootstrap5-toggle)
9
- [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv5)](https://github.com/palcarazm/bootstrap5-toggle/security/policy)
10
- [![Funding](https://img.shields.io/badge/sponsor-30363D?style=flat&logo=GitHub-Sponsors&logoColor=#white)](https://github.com/sponsors/palcarazm)
11
- [![Rate this package](https://badges.openbase.com/js/rating/bootstrap5-toggle.svg?token=rNvznTVToo+EmX5g+KTvfYqI9+YTWJeUWTxPj7tLA6o=)](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) | [![Bootstrap 5](https://img.shields.io/static/v1?label=bootstrap&message=%5E5.0.0&color=informational&logo=bootstrap&logoColor=white)](https://getbootstrap.com/docs/5.0) | [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases) | [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv5)](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
24
- | [v4](https://github.com/palcarazm/bootstrap5-toggle/tree/v4) | [![Bootstrap 5](https://img.shields.io/static/v1?label=bootstrap&message=%5E5.0.0&color=informational&logo=bootstrap&logoColor=white)](https://getbootstrap.com/docs/5.0) | [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v4?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases) | [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv4)](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
25
- | [v3](https://github.com/palcarazm/bootstrap5-toggle/tree/v3) | [![Bootstrap 4](https://img.shields.io/static/v1?label=bootstrap&message=%5E4.0.0&color=informational&logo=bootstrap&logoColor=white)](https://getbootstrap.com/docs/4.0) | [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v3?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases) | [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv3)](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
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
46
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
47
-
48
- - [Bootstrap 5 Toggle](#bootstrap-5-toggle) - [Library Distributions](#library-distributions)
49
- - [Demos](#demos)
50
- - [Related Bootstrap Plugins](#related-bootstrap-plugins)
51
- - [Installation](#installation)
52
- - [CDN](#cdn)
53
- - [ECMAS Interface](#ecmas-interface)
54
- - [jQuery Interface](#jquery-interface)
55
- - [Download](#download)
56
- - [NPM](#npm)
57
- - [Yarn](#yarn)
58
- - [Usage](#usage)
59
- - [Initialize With HTML](#initialize-with-html)
60
- - [Initialize With Code](#initialize-with-code)
61
- - [API](#api)
62
- - [Options](#options)
63
- - [Methods](#methods)
64
- - [Events](#events)
65
- - [Event Propagation](#event-propagation)
66
- - [Stopping Event Propagation](#stopping-event-propagation)
67
- - [API vs Input](#api-vs-input)
68
- - [Collaborators welcom!](#collaborators-welcom)
69
-
70
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
71
-
72
- ---
73
-
74
- # Installation
75
-
76
- ## CDN
77
-
78
- [![JSDelivr Badge](https://img.shields.io/jsdelivr/npm/hm/bootstrap5-toggle?label=hits&logo=jsdelivr&logoColor=white)](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)
79
-
80
- ### ECMAS Interface
81
-
82
- ```html
83
- <link
84
- href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/css/bootstrap5-toggle.min.css"
85
- rel="stylesheet" />
86
- <script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/js/bootstrap5-toggle.ecmas.min.js"></script>
87
- ```
88
-
89
- ### jQuery Interface
90
-
91
- ```html
92
- <link
93
- href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/css/bootstrap5-toggle.min.css"
94
- rel="stylesheet" />
95
- <script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/js/bootstrap5-toggle.jquery.min.js"></script>
96
- ```
97
-
98
- ## Download
99
-
100
- [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases)
101
-
102
- ## NPM
103
-
104
- [![NPM Badge](https://img.shields.io/npm/dm/bootstrap5-toggle?logo=npm)](https://www.npmjs.com/package/bootstrap5-toggle)
105
-
106
- ```ksh
107
- npm install bootstrap5-toggle@#version#
108
- ```
109
-
110
- ## Yarn
111
-
112
- ```ksh
113
- yarn add bootstrap5-toggle@#version#
114
- ```
115
-
116
- # Usage
117
-
118
- ## Initialize With HTML
119
-
120
- Simply add `data-toggle="toggle"` to automatically convert a plain checkbox into a bootstrap 5 toggle.
121
-
122
- ```html
123
- <input id="chkToggle" type="checkbox" data-toggle="toggle" />
124
- ```
125
-
126
- ## Initialize With Code
127
-
128
- Toggles can also be initialized via JavaScript code.
129
-
130
- EX: Initialize id `chkToggle` with a single line of JavaScript.
131
-
132
- ```html
133
- <input id="chkToggle" type="checkbox" checked />
134
- <script>
135
- document.querySelector("#chkToggle").bootstrapToggle();
136
- </script>
137
- ```
138
-
139
- # API
140
-
141
- ## Options
142
-
143
- - Options can be passed via data attributes or JavaScript
144
- - For data attributes, append the option name to `data-` (ex: `data-on="Enabled"`)
145
-
146
- ```html
147
- <input
148
- type="checkbox"
149
- data-toggle="toggle"
150
- data-onlabel="Enabled"
151
- data-offlabel="Disabled" />
152
- <input type="checkbox" id="toggle-two" />
153
- <script>
154
- document.querySelector("#toggle-two").bootstrapToggle({
155
- on: "Enabled",
156
- off: "Disabled",
157
- });
158
- </script>
159
- ```
160
-
161
- | Name | Type | Default | Description |
162
- | ---------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
163
- | `onlabel` | string/html | "On" | Text of the on toggle |
164
- | `offlabel` | string/html | "Off" | Text of the off toggle |
165
- | `size` | string | "normal" | Size of the toggle. Possible values are: `large`, `normal`, `small`, `mini`. |
166
- | `onstyle` | string | "primary" | Style of the on toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
167
- | `offstyle` | string | "secondary" | Style of the off toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
168
- | `onvalue` | string | _null_ | Sets on state value |
169
- | `offvalue` | string | _null_ | Sets off state value |
170
- | `ontitle` | string | _null_ | Title of the on toggle |
171
- | `offtitle` | string | _null_ | Title of the off toggle |
172
- | `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. |
173
- | `width` | integer | _null_ | Sets the width of the toggle. if set to _null_, width will be auto-calculated. |
174
- | `height` | integer | _null_ | Sets the height of the toggle. if set to _null_, height will be auto-calculated. |
175
- | `tabindex` | integer | 0 | Sets the tabindex of the toggle. |
176
- | `tristate` | boolean | false | Sets tristate support |
177
-
178
- ## Methods
179
-
180
- Methods can be used to control toggles directly.
181
-
182
- ```html
183
- <input id="toggle-demo" type="checkbox" data-toggle="toggle" />
184
- <script>
185
- const toggleDemo = document.querySelector("#toggle-demo");
186
- </script>
187
- ```
188
-
189
- | Method | Example | Description |
190
- | ------------- | --------------------------------------------- | ------------------------------------------------- |
191
- | initialize | `toggleDemo.bootstrapToggle()` | Initializes the toggle plugin with options |
192
- | destroy | `toggleDemo.bootstrapToggle('destroy')` | Destroys the toggle |
193
- | on | `toggleDemo.bootstrapToggle('on')` | Sets the toggle to 'On' state |
194
- | off | `toggleDemo.bootstrapToggle('off')` | Sets the toggle to 'Off' state |
195
- | toggle | `toggleDemo.bootstrapToggle('toggle')` | Toggles the state of the toggle on/off |
196
- | enable | `toggleDemo.bootstrapToggle('enable')` | Enables the toggle |
197
- | disable | `toggleDemo.bootstrapToggle('disable')` | Disables the toggle |
198
- | readonly | `toggleDemo.bootstrapToggle('readonly')` | Disables the toggle but preserve checkbox enabled |
199
- | indeterminate | `toggleDemo.bootstrapToggle('indeterminate')` | Sets the toggle to 'indeterminate' state |
200
- | determinate | `toggleDemo.bootstrapToggle('determinate')` | Sets the toggle to 'determinate' state |
201
-
202
- # Events
203
-
204
- ## Event Propagation
205
-
206
- Note All events are propagated to and from input element to the toggle.
207
-
208
- You should listen to events from the `<input type="checkbox">` directly rather than look for custom events.
209
-
210
- ```html
211
- <input id="toggle-event" type="checkbox" data-toggle="toggle" />
212
- <div id="console-event"></div>
213
- <script>
214
- document.querySelector("#toggle-event").change(function (e) {
215
- document
216
- .querySelector("#console-event")
217
- .html("Toggle: " + e.target.prop("checked"));
218
- });
219
- </script>
220
- ```
221
-
222
- ## Stopping Event Propagation
223
-
224
- 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.
225
-
226
- ```html
227
- <input id="toggle-silent" type="checkbox" data-toggle="toggle" />
228
- <button class="btn btn-success" onclick="toggleApiOnSilent()">
229
- On by API (silent)
230
- </button>
231
- <button class="btn btn-success" onclick="toggleApiOffSilent()">
232
- Off by API (silent)
233
- </button>
234
- <button class="btn btn-warning" onclick="toggleApiOnNotSilent()">
235
- On by API (not silent)
236
- </button>
237
- <button class="btn btn-warning" onclick="toggleApiOffNotSilent()">
238
- On by API (not silent)
239
- </button>
240
- <script>
241
- function toggleApiOnSilent() {
242
- document.querySelector("#toggle-silent").bootstrapToggle("on", true);
243
- }
244
- function toggleApiOffSilent() {
245
- document.querySelector("#toggle-silent").bootstrapToggle("off", true);
246
- }
247
- function toggleApiOnNotSilent() {
248
- document.querySelector("#toggle-silent").bootstrapToggle("on");
249
- }
250
- function toggleApiOffNotSilent() {
251
- document.querySelector("#toggle-silent").bootstrapToggle("off");
252
- }
253
- </script>
254
- ```
255
-
256
- ## API vs Input
257
-
258
- This also means that using the API or Input to trigger events will work both ways.
259
-
260
- ```html
261
- <input id="toggle-trigger" type="checkbox" data-toggle="toggle" />
262
- <button class="btn btn-success" onclick="toggleApiOn()">On by API</button>
263
- <button class="btn btn-danger" onclick="toggleApiOff()">Off by API</button>
264
- <button class="btn btn-success" onclick="toggleInpOn()">On by Input</button>
265
- <button class="btn btn-danger" onclick="toggleInpOff()">Off by Input</button>
266
- <script>
267
- function toggleApiOn() {
268
- document.querySelector("#toggle-trigger").bootstrapToggle("on");
269
- }
270
- function toggleApiOff() {
271
- document.querySelector("#toggle-trigger").bootstrapToggle("off");
272
- }
273
- function toggleInpOn() {
274
- document.querySelector("#toggle-trigger").prop("checked", true).change();
275
- }
276
- function toggleInpOff() {
277
- document.querySelector("#toggle-trigger").prop("checked", false).change();
278
- }
279
- </script>
280
- ```
281
-
282
- # Collaborators welcom!
283
-
284
- - :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)
285
- - :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)
286
- - :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)
287
- - :computer: ¿Do you know how to fix a bug? Open a pull request in [GitHub pull repuest](https://github.com/palcarazm/bootstrap5-toggle/compare).
288
-
289
- [![GitHub Contributors](https://contrib.rocks/image?repo=palcarazm/bootstrap5-toggle)](https://github.com/palcarazm/bootstrap5-toggle/graphs/contributors)
290
-
291
- ¿Do you like the project? Give us a :star: in [GitHub](https://github.com/palcarazm/bootstrap5-toggle).
1
+ [![GitHub license](https://img.shields.io/github/license/palcarazm/bootstrap5-toggle.svg?color=informational)](https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE)
2
+ [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases)
3
+ [![Bootstrap 5](https://img.shields.io/static/v1?label=bootstrap&message=%5E5.0.0&color=informational&logo=bootstrap&logoColor=white)](https://getbootstrap.com/docs/5.0)
4
+ [![JSDelivr Badge](https://img.shields.io/jsdelivr/npm/hm/bootstrap5-toggle?label=hits&logo=jsdelivr&logoColor=white)](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)
5
+ [![NPM Badge](https://img.shields.io/npm/dm/bootstrap5-toggle?logo=npm)](https://www.npmjs.com/package/bootstrap5-toggle)
6
+ [![Build](https://img.shields.io/github/actions/workflow/status/palcarazm/bootstrap5-toggle/build.yml?branch=v5&logo=npm)](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Build+Check%22)
7
+ [![Test](https://img.shields.io/github/actions/workflow/status/palcarazm/bootstrap5-toggle/cypress.yml?branch=v5&label=tests&logo=cypress)](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Cypress+Tests%22)
8
+ [![Security](https://img.shields.io/snyk/vulnerabilities/npm/bootstrap5-toggle@#version#?logo=snyk)](https://snyk.io/advisor/npm-package/bootstrap5-toggle)
9
+ [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv5)](https://github.com/palcarazm/bootstrap5-toggle/security/policy)
10
+ [![Funding](https://img.shields.io/badge/sponsor-30363D?style=flat&logo=GitHub-Sponsors&logoColor=#white)](https://github.com/sponsors/palcarazm)
11
+ [![Rate this package](https://badges.openbase.com/js/rating/bootstrap5-toggle.svg?token=rNvznTVToo+EmX5g+KTvfYqI9+YTWJeUWTxPj7tLA6o=)](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) | [![Bootstrap 5](https://img.shields.io/static/v1?label=bootstrap&message=%5E5.0.0&color=informational&logo=bootstrap&logoColor=white)](https://getbootstrap.com/docs/5.0) | [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases) | [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv5)](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
24
+ | [v4](https://github.com/palcarazm/bootstrap5-toggle/tree/v4) | [![Bootstrap 5](https://img.shields.io/static/v1?label=bootstrap&message=%5E5.0.0&color=informational&logo=bootstrap&logoColor=white)](https://getbootstrap.com/docs/5.0) | [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v4?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases) | [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv4)](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |
25
+ | [v3](https://github.com/palcarazm/bootstrap5-toggle/tree/v3) | [![Bootstrap 4](https://img.shields.io/static/v1?label=bootstrap&message=%5E4.0.0&color=informational&logo=bootstrap&logoColor=white)](https://getbootstrap.com/docs/4.0) | [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v3?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases) | [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv3)](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
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
46
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
47
+
48
+ - [Bootstrap 5 Toggle](#bootstrap-5-toggle) - [Library Distributions](#library-distributions)
49
+ - [Demos](#demos)
50
+ - [Related Bootstrap Plugins](#related-bootstrap-plugins)
51
+ - [Installation](#installation)
52
+ - [CDN](#cdn)
53
+ - [ECMAS Interface](#ecmas-interface)
54
+ - [jQuery Interface](#jquery-interface)
55
+ - [Download](#download)
56
+ - [NPM](#npm)
57
+ - [Yarn](#yarn)
58
+ - [Usage](#usage)
59
+ - [Initialize With HTML](#initialize-with-html)
60
+ - [Initialize With Code](#initialize-with-code)
61
+ - [API](#api)
62
+ - [Options](#options)
63
+ - [Methods](#methods)
64
+ - [Events](#events)
65
+ - [Event Propagation](#event-propagation)
66
+ - [Stopping Event Propagation](#stopping-event-propagation)
67
+ - [API vs Input](#api-vs-input)
68
+ - [Collaborators welcom!](#collaborators-welcom)
69
+
70
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
71
+
72
+ ---
73
+
74
+ # Installation
75
+
76
+ ## CDN
77
+
78
+ [![JSDelivr Badge](https://img.shields.io/jsdelivr/npm/hm/bootstrap5-toggle?label=hits&logo=jsdelivr&logoColor=white)](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)
79
+
80
+ ### ECMAS Interface
81
+
82
+ ```html
83
+ <link
84
+ href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/css/bootstrap5-toggle.min.css"
85
+ rel="stylesheet" />
86
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/js/bootstrap5-toggle.ecmas.min.js"></script>
87
+ ```
88
+
89
+ ### jQuery Interface
90
+
91
+ ```html
92
+ <link
93
+ href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/css/bootstrap5-toggle.min.css"
94
+ rel="stylesheet" />
95
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/js/bootstrap5-toggle.jquery.min.js"></script>
96
+ ```
97
+
98
+ ## Download
99
+
100
+ [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases)
101
+
102
+ ## NPM
103
+
104
+ [![NPM Badge](https://img.shields.io/npm/dm/bootstrap5-toggle?logo=npm)](https://www.npmjs.com/package/bootstrap5-toggle)
105
+
106
+ ```ksh
107
+ npm install bootstrap5-toggle@#version#
108
+ ```
109
+
110
+ ## Yarn
111
+
112
+ ```ksh
113
+ yarn add bootstrap5-toggle@#version#
114
+ ```
115
+
116
+ # Usage
117
+
118
+ ## Initialize With HTML
119
+
120
+ Simply add `data-toggle="toggle"` to automatically convert a plain checkbox into a bootstrap 5 toggle.
121
+
122
+ ```html
123
+ <input id="chkToggle" type="checkbox" data-toggle="toggle" />
124
+ ```
125
+
126
+ ## Initialize With Code
127
+
128
+ Toggles can also be initialized via JavaScript code.
129
+
130
+ EX: Initialize id `chkToggle` with a single line of JavaScript.
131
+
132
+ ```html
133
+ <input id="chkToggle" type="checkbox" checked />
134
+ <script>
135
+ document.querySelector("#chkToggle").bootstrapToggle();
136
+ </script>
137
+ ```
138
+
139
+ # API
140
+
141
+ ## Options
142
+
143
+ - Options can be passed via data attributes or JavaScript
144
+ - For data attributes, append the option name to `data-` (ex: `data-on="Enabled"`)
145
+
146
+ ```html
147
+ <input
148
+ type="checkbox"
149
+ data-toggle="toggle"
150
+ data-onlabel="Enabled"
151
+ data-offlabel="Disabled" />
152
+ <input type="checkbox" id="toggle-two" />
153
+ <script>
154
+ document.querySelector("#toggle-two").bootstrapToggle({
155
+ on: "Enabled",
156
+ off: "Disabled",
157
+ });
158
+ </script>
159
+ ```
160
+
161
+ | Name | Type | Default | Description |
162
+ | ---------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
163
+ | `onlabel` | string/html | "On" | Text of the on toggle |
164
+ | `offlabel` | string/html | "Off" | Text of the off toggle |
165
+ | `size` | string | "normal" | Size of the toggle. Possible values are: `large`, `normal`, `small`, `mini`. |
166
+ | `onstyle` | string | "primary" | Style of the on toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
167
+ | `offstyle` | string | "secondary" | Style of the off toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
168
+ | `onvalue` | string | _null_ | Sets on state value |
169
+ | `offvalue` | string | _null_ | Sets off state value |
170
+ | `ontitle` | string | _null_ | Title of the on toggle |
171
+ | `offtitle` | string | _null_ | Title of the off toggle |
172
+ | `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. |
173
+ | `width` | integer | _null_ | Sets the width of the toggle. if set to _null_, width will be auto-calculated. |
174
+ | `height` | integer | _null_ | Sets the height of the toggle. if set to _null_, height will be auto-calculated. |
175
+ | `tabindex` | integer | 0 | Sets the tabindex of the toggle. |
176
+ | `tristate` | boolean | false | Sets tristate support |
177
+
178
+ ## Methods
179
+
180
+ Methods can be used to control toggles directly.
181
+
182
+ ```html
183
+ <input id="toggle-demo" type="checkbox" data-toggle="toggle" />
184
+ <script>
185
+ const toggleDemo = document.querySelector("#toggle-demo");
186
+ </script>
187
+ ```
188
+
189
+ | Method | Example | Description |
190
+ | ------------- | --------------------------------------------- | ------------------------------------------------------------------------------------- |
191
+ | initialize | `toggleDemo.bootstrapToggle()` | Initializes the toggle plugin with options |
192
+ | destroy | `toggleDemo.bootstrapToggle('destroy')` | Destroys the toggle |
193
+ | rerender | `toggleDemo.bootstrapToggle('rerender')` | Rerender toggle with the appropriated size. Useful when parent is collapsed at first. |
194
+ | on | `toggleDemo.bootstrapToggle('on')` | Sets the toggle to 'On' state |
195
+ | off | `toggleDemo.bootstrapToggle('off')` | Sets the toggle to 'Off' state |
196
+ | toggle | `toggleDemo.bootstrapToggle('toggle')` | Toggles the state of the toggle on/off |
197
+ | enable | `toggleDemo.bootstrapToggle('enable')` | Enables the toggle |
198
+ | disable | `toggleDemo.bootstrapToggle('disable')` | Disables the toggle |
199
+ | readonly | `toggleDemo.bootstrapToggle('readonly')` | Disables the toggle but preserve checkbox enabled |
200
+ | indeterminate | `toggleDemo.bootstrapToggle('indeterminate')` | Sets the toggle to 'indeterminate' state |
201
+ | determinate | `toggleDemo.bootstrapToggle('determinate')` | Sets the toggle to 'determinate' state |
202
+
203
+ # Events
204
+
205
+ ## Event Propagation
206
+
207
+ Note All events are propagated to and from input element to the toggle.
208
+
209
+ You should listen to events from the `<input type="checkbox">` directly rather than look for custom events.
210
+
211
+ ```html
212
+ <input id="toggle-event" type="checkbox" data-toggle="toggle" />
213
+ <div id="console-event"></div>
214
+ <script>
215
+ document.querySelector("#toggle-event").change(function (e) {
216
+ document
217
+ .querySelector("#console-event")
218
+ .html("Toggle: " + e.target.prop("checked"));
219
+ });
220
+ </script>
221
+ ```
222
+
223
+ ## Stopping Event Propagation
224
+
225
+ 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.
226
+
227
+ ```html
228
+ <input id="toggle-silent" type="checkbox" data-toggle="toggle" />
229
+ <button class="btn btn-success" onclick="toggleApiOnSilent()">
230
+ On by API (silent)
231
+ </button>
232
+ <button class="btn btn-success" onclick="toggleApiOffSilent()">
233
+ Off by API (silent)
234
+ </button>
235
+ <button class="btn btn-warning" onclick="toggleApiOnNotSilent()">
236
+ On by API (not silent)
237
+ </button>
238
+ <button class="btn btn-warning" onclick="toggleApiOffNotSilent()">
239
+ On by API (not silent)
240
+ </button>
241
+ <script>
242
+ function toggleApiOnSilent() {
243
+ document.querySelector("#toggle-silent").bootstrapToggle("on", true);
244
+ }
245
+ function toggleApiOffSilent() {
246
+ document.querySelector("#toggle-silent").bootstrapToggle("off", true);
247
+ }
248
+ function toggleApiOnNotSilent() {
249
+ document.querySelector("#toggle-silent").bootstrapToggle("on");
250
+ }
251
+ function toggleApiOffNotSilent() {
252
+ document.querySelector("#toggle-silent").bootstrapToggle("off");
253
+ }
254
+ </script>
255
+ ```
256
+
257
+ ## API vs Input
258
+
259
+ This also means that using the API or Input to trigger events will work both ways.
260
+
261
+ ```html
262
+ <input id="toggle-trigger" type="checkbox" data-toggle="toggle" />
263
+ <button class="btn btn-success" onclick="toggleApiOn()">On by API</button>
264
+ <button class="btn btn-danger" onclick="toggleApiOff()">Off by API</button>
265
+ <button class="btn btn-success" onclick="toggleInpOn()">On by Input</button>
266
+ <button class="btn btn-danger" onclick="toggleInpOff()">Off by Input</button>
267
+ <script>
268
+ function toggleApiOn() {
269
+ document.querySelector("#toggle-trigger").bootstrapToggle("on");
270
+ }
271
+ function toggleApiOff() {
272
+ document.querySelector("#toggle-trigger").bootstrapToggle("off");
273
+ }
274
+ function toggleInpOn() {
275
+ document.querySelector("#toggle-trigger").prop("checked", true).change();
276
+ }
277
+ function toggleInpOff() {
278
+ document.querySelector("#toggle-trigger").prop("checked", false).change();
279
+ }
280
+ </script>
281
+ ```
282
+
283
+ # Collaborators welcom!
284
+
285
+ - :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)
286
+ - :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)
287
+ - :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)
288
+ - :computer: ¿Do you know how to fix a bug? Open a pull request in [GitHub pull repuest](https://github.com/palcarazm/bootstrap5-toggle/compare).
289
+
290
+ [![GitHub Contributors](https://contrib.rocks/image?repo=palcarazm/bootstrap5-toggle)](https://github.com/palcarazm/bootstrap5-toggle/graphs/contributors)
291
+
292
+ ¿Do you like the project? Give us a :star: in [GitHub](https://github.com/palcarazm/bootstrap5-toggle).