bootstrap5-toggle 3.5.2

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 ADDED
@@ -0,0 +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.
package/README.md ADDED
@@ -0,0 +1,284 @@
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
+ [![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)
7
+ [![Funding](https://img.shields.io/badge/sponsor-30363D?style=flat&logo=GitHub-Sponsors&logoColor=#white)](https://github.com/sponsors/palcarazm)
8
+
9
+ [![Coverage Status](https://img.shields.io/coverallsCoverage/github/palcarazm/bootstrap5-toggle?branch=v5&logo=coveralls)](https://coveralls.io/github/palcarazm/bootstrap5-toggle?branch=v5)
10
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=palcarazm_bootstrap5-toggle&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=palcarazm_bootstrap5-toggle)
11
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=palcarazm_bootstrap5-toggle&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=palcarazm_bootstrap5-toggle)
12
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=palcarazm_bootstrap5-toggle&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=palcarazm_bootstrap5-toggle)
13
+ [![Security](https://img.shields.io/badge/security-monitored-informational?logo=snyk)](https://snyk.io/advisor/npm-package/bootstrap5-toggle)
14
+
15
+
16
+ # Bootstrap 5 Toggle
17
+
18
+ **Bootstrap 5 Toggle** is a bootstrap plugin/widget that converts checkboxes into toggles.
19
+
20
+ ---
21
+
22
+ #### Library Distributions
23
+
24
+ | Version | Bootstrap Support | Last Release | End of Life |
25
+ | :----------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
26
+ | [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) |
27
+ | [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) |
28
+ | [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) |
29
+
30
+ See EOL for each version in [Security Policy Page](https://github.com/palcarazm/bootstrap5-toggle/security/policy).
31
+
32
+ # Demos
33
+
34
+ **Demos and API Docs:** https://palcarazm.github.io/bootstrap5-toggle/
35
+
36
+ ---
37
+
38
+ <!-- To update TOC run .\node_modules\.bin\doctoc README.md --github -->
39
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
40
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
41
+
42
+
43
+ - [Installation](#installation)
44
+ - [CDN](#cdn)
45
+ - [ECMAS Interface](#ecmas-interface)
46
+ - [jQuery Interface](#jquery-interface)
47
+ - [Download](#download)
48
+ - [NPM](#npm)
49
+ - [Yarn](#yarn)
50
+ - [Usage](#usage)
51
+ - [Initialize With HTML](#initialize-with-html)
52
+ - [Initialize With Code](#initialize-with-code)
53
+ - [API](#api)
54
+ - [Options](#options)
55
+ - [Methods](#methods)
56
+ - [Events](#events)
57
+ - [Event Propagation](#event-propagation)
58
+ - [Stopping Event Propagation](#stopping-event-propagation)
59
+ - [API vs Input](#api-vs-input)
60
+ - [Collaborators welcom!](#collaborators-welcom)
61
+
62
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
63
+
64
+ ---
65
+
66
+ # Installation
67
+
68
+ ## CDN
69
+
70
+ [![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)
71
+
72
+ ### ECMAS Interface
73
+
74
+ ```html
75
+ <link
76
+ href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@3.5.2/css/bootstrap5-toggle.min.css"
77
+ rel="stylesheet" />
78
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@3.5.2/js/bootstrap5-toggle.ecmas.min.js"></script>
79
+ ```
80
+
81
+ ### jQuery Interface
82
+
83
+ ```html
84
+ <link
85
+ href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@3.5.2/css/bootstrap5-toggle.min.css"
86
+ rel="stylesheet" />
87
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@3.5.2/js/bootstrap5-toggle.jquery.min.js"></script>
88
+ ```
89
+
90
+ ## Download
91
+
92
+ [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases)
93
+
94
+ ## NPM
95
+
96
+ [![NPM Badge](https://img.shields.io/npm/dm/bootstrap5-toggle?logo=npm)](https://www.npmjs.com/package/bootstrap5-toggle)
97
+
98
+ ```ksh
99
+ npm install bootstrap5-toggle@3.5.2
100
+ ```
101
+
102
+ ## Yarn
103
+
104
+ ```ksh
105
+ yarn add bootstrap5-toggle@3.5.2
106
+ ```
107
+
108
+ # Usage
109
+
110
+ ## Initialize With HTML
111
+
112
+ Add `data-toggle="toggle"` to automatically convert a plain checkbox into a bootstrap 5 toggle.
113
+
114
+ ```html
115
+ <input id="chkToggle" type="checkbox" data-toggle="toggle" />
116
+ ```
117
+
118
+ ## Initialize With Code
119
+
120
+ Toggles can also be initialized via JavaScript code.
121
+
122
+ EX: Initialize id `chkToggle` with a single line of JavaScript.
123
+
124
+ ```html
125
+ <input id="chkToggle" type="checkbox" checked />
126
+ <script>
127
+ document.querySelector("#chkToggle").bootstrapToggle();
128
+ </script>
129
+ ```
130
+
131
+ # API
132
+
133
+ ## Options
134
+
135
+ - Options can be passed via data attributes or JavaScript
136
+ - For data attributes, append the option name to `data-` (ex: `data-on="Enabled"`)
137
+
138
+ ```html
139
+ <input
140
+ type="checkbox"
141
+ data-toggle="toggle"
142
+ data-onlabel="Enabled"
143
+ data-offlabel="Disabled" />
144
+ <input type="checkbox" id="toggle-two" />
145
+ <script>
146
+ document.querySelector("#toggle-two").bootstrapToggle({
147
+ on: "Enabled",
148
+ off: "Disabled",
149
+ });
150
+ </script>
151
+ ```
152
+
153
+ | Name | Type | Default | Description |
154
+ | ---------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
155
+ | `onlabel` | string/html | "On" | Text of the on toggle |
156
+ | `offlabel` | string/html | "Off" | Text of the off toggle |
157
+ | `size` | string | "normal" | Size of the toggle. Possible values are: `large`, `normal`, `small`, `mini`. |
158
+ | `onstyle` | string | "primary" | Style of the on toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
159
+ | `offstyle` | string | "secondary" | Style of the off toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
160
+ | `onvalue` | string | _null_ | Sets on state value |
161
+ | `offvalue` | string | _null_ | Sets off state value |
162
+ | `ontitle` | string | _null_ | Title of the on toggle |
163
+ | `offtitle` | string | _null_ | Title of the off toggle |
164
+ | `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. |
165
+ | `width` | integer | _null_ | Sets the width of the toggle. if set to _null_, width will be auto-calculated. |
166
+ | `height` | integer | _null_ | Sets the height of the toggle. if set to _null_, height will be auto-calculated. |
167
+ | `tabindex` | integer | 0 | Sets the tabindex of the toggle. |
168
+ | `tristate` | boolean | false | Sets tristate support |
169
+
170
+ ## Methods
171
+
172
+ Methods can be used to control toggles directly.
173
+
174
+ ```html
175
+ <input id="toggle-demo" type="checkbox" data-toggle="toggle" />
176
+ <script>
177
+ const toggleDemo = document.querySelector("#toggle-demo");
178
+ </script>
179
+ ```
180
+
181
+ | Method | Example | Description |
182
+ | ------------- | --------------------------------------------- | ------------------------------------------------------------------------------------- |
183
+ | initialize | `toggleDemo.bootstrapToggle()` | Initializes the toggle plugin with options |
184
+ | destroy | `toggleDemo.bootstrapToggle('destroy')` | Destroys the toggle |
185
+ | rerender | `toggleDemo.bootstrapToggle('rerender')` | Rerender toggle with the appropriated size. Useful when parent is collapsed at first. |
186
+ | on | `toggleDemo.bootstrapToggle('on')` | Sets the toggle to 'On' state |
187
+ | off | `toggleDemo.bootstrapToggle('off')` | Sets the toggle to 'Off' state |
188
+ | toggle | `toggleDemo.bootstrapToggle('toggle')` | Toggles the state of the toggle on/off |
189
+ | enable | `toggleDemo.bootstrapToggle('enable')` | Enables the toggle |
190
+ | disable | `toggleDemo.bootstrapToggle('disable')` | Disables the toggle |
191
+ | readonly | `toggleDemo.bootstrapToggle('readonly')` | Disables the toggle but preserve checkbox enabled |
192
+ | indeterminate | `toggleDemo.bootstrapToggle('indeterminate')` | Sets the toggle to 'indeterminate' state |
193
+ | determinate | `toggleDemo.bootstrapToggle('determinate')` | Sets the toggle to 'determinate' state |
194
+
195
+ # Events
196
+
197
+ ## Event Propagation
198
+
199
+ Note All events are propagated to and from input element to the toggle.
200
+
201
+ You should listen to events from the `<input type="checkbox">` directly rather than look for custom events.
202
+
203
+ ```html
204
+ <input id="toggle-event" type="checkbox" data-toggle="toggle" />
205
+ <div id="console-event"></div>
206
+ <script>
207
+ document.querySelector("#toggle-event").change(function (e) {
208
+ document
209
+ .querySelector("#console-event")
210
+ .html("Toggle: " + e.target.prop("checked"));
211
+ });
212
+ </script>
213
+ ```
214
+
215
+ ## Stopping Event Propagation
216
+
217
+ 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.
218
+
219
+ ```html
220
+ <input id="toggle-silent" type="checkbox" data-toggle="toggle" />
221
+ <button class="btn btn-success" onclick="toggleApiOnSilent()">
222
+ On by API (silent)
223
+ </button>
224
+ <button class="btn btn-success" onclick="toggleApiOffSilent()">
225
+ Off by API (silent)
226
+ </button>
227
+ <button class="btn btn-warning" onclick="toggleApiOnNotSilent()">
228
+ On by API (not silent)
229
+ </button>
230
+ <button class="btn btn-warning" onclick="toggleApiOffNotSilent()">
231
+ On by API (not silent)
232
+ </button>
233
+ <script>
234
+ function toggleApiOnSilent() {
235
+ document.querySelector("#toggle-silent").bootstrapToggle("on", true);
236
+ }
237
+ function toggleApiOffSilent() {
238
+ document.querySelector("#toggle-silent").bootstrapToggle("off", true);
239
+ }
240
+ function toggleApiOnNotSilent() {
241
+ document.querySelector("#toggle-silent").bootstrapToggle("on");
242
+ }
243
+ function toggleApiOffNotSilent() {
244
+ document.querySelector("#toggle-silent").bootstrapToggle("off");
245
+ }
246
+ </script>
247
+ ```
248
+
249
+ ## API vs Input
250
+
251
+ This also means that using the API or Input to trigger events will work both ways.
252
+
253
+ ```html
254
+ <input id="toggle-trigger" type="checkbox" data-toggle="toggle" />
255
+ <button class="btn btn-success" onclick="toggleApiOn()">On by API</button>
256
+ <button class="btn btn-danger" onclick="toggleApiOff()">Off by API</button>
257
+ <button class="btn btn-success" onclick="toggleInpOn()">On by Input</button>
258
+ <button class="btn btn-danger" onclick="toggleInpOff()">Off by Input</button>
259
+ <script>
260
+ function toggleApiOn() {
261
+ document.querySelector("#toggle-trigger").bootstrapToggle("on");
262
+ }
263
+ function toggleApiOff() {
264
+ document.querySelector("#toggle-trigger").bootstrapToggle("off");
265
+ }
266
+ function toggleInpOn() {
267
+ document.querySelector("#toggle-trigger").prop("checked", true).change();
268
+ }
269
+ function toggleInpOff() {
270
+ document.querySelector("#toggle-trigger").prop("checked", false).change();
271
+ }
272
+ </script>
273
+ ```
274
+
275
+ # Collaborators welcom!
276
+
277
+ - :sos: Do you need some help? Open a thread in [GitHub Discussions Q&A](https://github.com/palcarazm/bootstrap5-toggle/discussions/new?category=q-a)
278
+ - :bug: Do you find a bug? Open an issue in [GitHub bug report](https://github.com/palcarazm/bootstrap5-toggle/issues/new?template=01-BUG_REPORT.yml)
279
+ - :bulb: Do you have a great idea? Open an issue in [GitHub feature request](https://github.com/palcarazm/bootstrap5-toggle/issues/new?template=02-FEATURE_REQUEST.yml)
280
+ - :computer: Do you know how to fix a bug? Open a pull request in [GitHub pull request](https://github.com/palcarazm/bootstrap5-toggle/compare).
281
+
282
+ [![GitHub Contributors](https://contrib.rocks/image?repo=palcarazm/bootstrap5-toggle)](https://github.com/palcarazm/bootstrap5-toggle/graphs/contributors)
283
+
284
+ ¿Do you like the project? Give us a :star: in [GitHub](https://github.com/palcarazm/bootstrap5-toggle).
@@ -0,0 +1,286 @@
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
+ [![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)
7
+ [![Funding](https://img.shields.io/badge/sponsor-30363D?style=flat&logo=GitHub-Sponsors&logoColor=#white)](https://github.com/sponsors/palcarazm)
8
+
9
+ [![Coverage Status](https://img.shields.io/coverallsCoverage/github/palcarazm/bootstrap5-toggle?branch=v5&logo=coveralls)](https://coveralls.io/github/palcarazm/bootstrap5-toggle?branch=v5)
10
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=palcarazm_bootstrap5-toggle&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=palcarazm_bootstrap5-toggle)
11
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=palcarazm_bootstrap5-toggle&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=palcarazm_bootstrap5-toggle)
12
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=palcarazm_bootstrap5-toggle&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=palcarazm_bootstrap5-toggle)
13
+ [![Security](https://img.shields.io/badge/security-monitored-informational?logo=snyk)](https://snyk.io/advisor/npm-package/bootstrap5-toggle)
14
+
15
+
16
+ # Bootstrap 5 Toggle
17
+
18
+ **Bootstrap 5 Toggle** is a bootstrap plugin/widget that converts checkboxes into toggles.
19
+
20
+ ---
21
+
22
+ #### Library Distributions
23
+
24
+ | Version | Bootstrap Support | Last Release | End of Life |
25
+ | :----------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
26
+ | [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) |
27
+ | [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) |
28
+ | [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) |
29
+
30
+ See EOL for each version in [Security Policy Page](https://github.com/palcarazm/bootstrap5-toggle/security/policy).
31
+
32
+ # Demos
33
+
34
+ **Demos and API Docs:** https://palcarazm.github.io/bootstrap5-toggle/
35
+
36
+ ---
37
+
38
+ <!-- To update TOC run .\node_modules\.bin\doctoc README.md --github -->
39
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
40
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
41
+
42
+ - [Bootstrap 5 Toggle](#bootstrap-5-toggle) - [Library Distributions](#library-distributions)
43
+ - [Demos](#demos)
44
+ - [Related Bootstrap Plugins](#related-bootstrap-plugins)
45
+ - [Installation](#installation)
46
+ - [CDN](#cdn)
47
+ - [ECMAS Interface](#ecmas-interface)
48
+ - [jQuery Interface](#jquery-interface)
49
+ - [Download](#download)
50
+ - [NPM](#npm)
51
+ - [Yarn](#yarn)
52
+ - [Usage](#usage)
53
+ - [Initialize With HTML](#initialize-with-html)
54
+ - [Initialize With Code](#initialize-with-code)
55
+ - [API](#api)
56
+ - [Options](#options)
57
+ - [Methods](#methods)
58
+ - [Events](#events)
59
+ - [Event Propagation](#event-propagation)
60
+ - [Stopping Event Propagation](#stopping-event-propagation)
61
+ - [API vs Input](#api-vs-input)
62
+ - [Collaborators welcom!](#collaborators-welcom)
63
+
64
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
65
+
66
+ ---
67
+
68
+ # Installation
69
+
70
+ ## CDN
71
+
72
+ [![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)
73
+
74
+ ### ECMAS Interface
75
+
76
+ ```html
77
+ <link
78
+ href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/css/bootstrap5-toggle.min.css"
79
+ rel="stylesheet" />
80
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/js/bootstrap5-toggle.ecmas.min.js"></script>
81
+ ```
82
+
83
+ ### jQuery Interface
84
+
85
+ ```html
86
+ <link
87
+ href="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/css/bootstrap5-toggle.min.css"
88
+ rel="stylesheet" />
89
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap5-toggle@#version#/js/bootstrap5-toggle.jquery.min.js"></script>
90
+ ```
91
+
92
+ ## Download
93
+
94
+ [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases)
95
+
96
+ ## NPM
97
+
98
+ [![NPM Badge](https://img.shields.io/npm/dm/bootstrap5-toggle?logo=npm)](https://www.npmjs.com/package/bootstrap5-toggle)
99
+
100
+ ```ksh
101
+ npm install bootstrap5-toggle@#version#
102
+ ```
103
+
104
+ ## Yarn
105
+
106
+ ```ksh
107
+ yarn add bootstrap5-toggle@#version#
108
+ ```
109
+
110
+ # Usage
111
+
112
+ ## Initialize With HTML
113
+
114
+ Add `data-toggle="toggle"` to automatically convert a plain checkbox into a bootstrap 5 toggle.
115
+
116
+ ```html
117
+ <input id="chkToggle" type="checkbox" data-toggle="toggle" />
118
+ ```
119
+
120
+ ## Initialize With Code
121
+
122
+ Toggles can also be initialized via JavaScript code.
123
+
124
+ EX: Initialize id `chkToggle` with a single line of JavaScript.
125
+
126
+ ```html
127
+ <input id="chkToggle" type="checkbox" checked />
128
+ <script>
129
+ document.querySelector("#chkToggle").bootstrapToggle();
130
+ </script>
131
+ ```
132
+
133
+ # API
134
+
135
+ ## Options
136
+
137
+ - Options can be passed via data attributes or JavaScript
138
+ - For data attributes, append the option name to `data-` (ex: `data-on="Enabled"`)
139
+
140
+ ```html
141
+ <input
142
+ type="checkbox"
143
+ data-toggle="toggle"
144
+ data-onlabel="Enabled"
145
+ data-offlabel="Disabled" />
146
+ <input type="checkbox" id="toggle-two" />
147
+ <script>
148
+ document.querySelector("#toggle-two").bootstrapToggle({
149
+ on: "Enabled",
150
+ off: "Disabled",
151
+ });
152
+ </script>
153
+ ```
154
+
155
+ | Name | Type | Default | Description |
156
+ | ---------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
157
+ | `onlabel` | string/html | "On" | Text of the on toggle |
158
+ | `offlabel` | string/html | "Off" | Text of the off toggle |
159
+ | `size` | string | "normal" | Size of the toggle. Possible values are: `large`, `normal`, `small`, `mini`. |
160
+ | `onstyle` | string | "primary" | Style of the on toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
161
+ | `offstyle` | string | "secondary" | Style of the off toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |
162
+ | `onvalue` | string | _null_ | Sets on state value |
163
+ | `offvalue` | string | _null_ | Sets off state value |
164
+ | `ontitle` | string | _null_ | Title of the on toggle |
165
+ | `offtitle` | string | _null_ | Title of the off toggle |
166
+ | `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. |
167
+ | `width` | integer | _null_ | Sets the width of the toggle. if set to _null_, width will be auto-calculated. |
168
+ | `height` | integer | _null_ | Sets the height of the toggle. if set to _null_, height will be auto-calculated. |
169
+ | `tabindex` | integer | 0 | Sets the tabindex of the toggle. |
170
+ | `tristate` | boolean | false | Sets tristate support |
171
+
172
+ ## Methods
173
+
174
+ Methods can be used to control toggles directly.
175
+
176
+ ```html
177
+ <input id="toggle-demo" type="checkbox" data-toggle="toggle" />
178
+ <script>
179
+ const toggleDemo = document.querySelector("#toggle-demo");
180
+ </script>
181
+ ```
182
+
183
+ | Method | Example | Description |
184
+ | ------------- | --------------------------------------------- | ------------------------------------------------------------------------------------- |
185
+ | initialize | `toggleDemo.bootstrapToggle()` | Initializes the toggle plugin with options |
186
+ | destroy | `toggleDemo.bootstrapToggle('destroy')` | Destroys the toggle |
187
+ | rerender | `toggleDemo.bootstrapToggle('rerender')` | Rerender toggle with the appropriated size. Useful when parent is collapsed at first. |
188
+ | on | `toggleDemo.bootstrapToggle('on')` | Sets the toggle to 'On' state |
189
+ | off | `toggleDemo.bootstrapToggle('off')` | Sets the toggle to 'Off' state |
190
+ | toggle | `toggleDemo.bootstrapToggle('toggle')` | Toggles the state of the toggle on/off |
191
+ | enable | `toggleDemo.bootstrapToggle('enable')` | Enables the toggle |
192
+ | disable | `toggleDemo.bootstrapToggle('disable')` | Disables the toggle |
193
+ | readonly | `toggleDemo.bootstrapToggle('readonly')` | Disables the toggle but preserve checkbox enabled |
194
+ | indeterminate | `toggleDemo.bootstrapToggle('indeterminate')` | Sets the toggle to 'indeterminate' state |
195
+ | determinate | `toggleDemo.bootstrapToggle('determinate')` | Sets the toggle to 'determinate' state |
196
+
197
+ # Events
198
+
199
+ ## Event Propagation
200
+
201
+ Note All events are propagated to and from input element to the toggle.
202
+
203
+ You should listen to events from the `<input type="checkbox">` directly rather than look for custom events.
204
+
205
+ ```html
206
+ <input id="toggle-event" type="checkbox" data-toggle="toggle" />
207
+ <div id="console-event"></div>
208
+ <script>
209
+ document.querySelector("#toggle-event").change(function (e) {
210
+ document
211
+ .querySelector("#console-event")
212
+ .html("Toggle: " + e.target.prop("checked"));
213
+ });
214
+ </script>
215
+ ```
216
+
217
+ ## Stopping Event Propagation
218
+
219
+ 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.
220
+
221
+ ```html
222
+ <input id="toggle-silent" type="checkbox" data-toggle="toggle" />
223
+ <button class="btn btn-success" onclick="toggleApiOnSilent()">
224
+ On by API (silent)
225
+ </button>
226
+ <button class="btn btn-success" onclick="toggleApiOffSilent()">
227
+ Off by API (silent)
228
+ </button>
229
+ <button class="btn btn-warning" onclick="toggleApiOnNotSilent()">
230
+ On by API (not silent)
231
+ </button>
232
+ <button class="btn btn-warning" onclick="toggleApiOffNotSilent()">
233
+ On by API (not silent)
234
+ </button>
235
+ <script>
236
+ function toggleApiOnSilent() {
237
+ document.querySelector("#toggle-silent").bootstrapToggle("on", true);
238
+ }
239
+ function toggleApiOffSilent() {
240
+ document.querySelector("#toggle-silent").bootstrapToggle("off", true);
241
+ }
242
+ function toggleApiOnNotSilent() {
243
+ document.querySelector("#toggle-silent").bootstrapToggle("on");
244
+ }
245
+ function toggleApiOffNotSilent() {
246
+ document.querySelector("#toggle-silent").bootstrapToggle("off");
247
+ }
248
+ </script>
249
+ ```
250
+
251
+ ## API vs Input
252
+
253
+ This also means that using the API or Input to trigger events will work both ways.
254
+
255
+ ```html
256
+ <input id="toggle-trigger" type="checkbox" data-toggle="toggle" />
257
+ <button class="btn btn-success" onclick="toggleApiOn()">On by API</button>
258
+ <button class="btn btn-danger" onclick="toggleApiOff()">Off by API</button>
259
+ <button class="btn btn-success" onclick="toggleInpOn()">On by Input</button>
260
+ <button class="btn btn-danger" onclick="toggleInpOff()">Off by Input</button>
261
+ <script>
262
+ function toggleApiOn() {
263
+ document.querySelector("#toggle-trigger").bootstrapToggle("on");
264
+ }
265
+ function toggleApiOff() {
266
+ document.querySelector("#toggle-trigger").bootstrapToggle("off");
267
+ }
268
+ function toggleInpOn() {
269
+ document.querySelector("#toggle-trigger").prop("checked", true).change();
270
+ }
271
+ function toggleInpOff() {
272
+ document.querySelector("#toggle-trigger").prop("checked", false).change();
273
+ }
274
+ </script>
275
+ ```
276
+
277
+ # Collaborators welcom!
278
+
279
+ - :sos: Do you need some help? Open a thread in [GitHub Discussions Q&A](https://github.com/palcarazm/bootstrap5-toggle/discussions/new?category=q-a)
280
+ - :bug: Do you find a bug? Open an issue in [GitHub bug report](https://github.com/palcarazm/bootstrap5-toggle/issues/new?template=01-BUG_REPORT.yml)
281
+ - :bulb: Do you have a great idea? Open an issue in [GitHub feature request](https://github.com/palcarazm/bootstrap5-toggle/issues/new?template=02-FEATURE_REQUEST.yml)
282
+ - :computer: Do you know how to fix a bug? Open a pull request in [GitHub pull request](https://github.com/palcarazm/bootstrap5-toggle/compare).
283
+
284
+ [![GitHub Contributors](https://contrib.rocks/image?repo=palcarazm/bootstrap5-toggle)](https://github.com/palcarazm/bootstrap5-toggle/graphs/contributors)
285
+
286
+ ¿Do you like the project? Give us a :star: in [GitHub](https://github.com/palcarazm/bootstrap5-toggle).