You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -12,6 +12,12 @@ Plugins can be included individually (using CoreUI's individual `js/dist/*.js`),
12
12
13
13
If you use a bundler (Webpack, Rollup...), you can use `/js/dist/*.js` files which are UMD ready.
14
14
15
+
## Usage with JavaScript frameworks
16
+
17
+
- Angular: [CoreUI for Angular](https://coreui.io/angular/docs/getting-started/introduction)
18
+
- React: [CoreUI for React](https://coreui.io/react/docs/getting-started/introduction/)
19
+
- Vue: [CoreUI for Vue](https://coreui.io/vue/docs/getting-started/introduction.html)
20
+
15
21
## Using CoreUI for Bootstrap as a module
16
22
17
23
We provide a version of CoreUI for Bootstrap built as `ESM` (`coreui.esm.js` and `coreui.esm.min.js`) which allows you to use CoreUI for Bootstrap as a module in your browser, if your [targeted browsers support it](https://caniuse.com/es6-module).
@@ -26,32 +32,67 @@ We provide a version of CoreUI for Bootstrap built as `ESM` (`coreui.esm.js` and
26
32
</script>
27
33
```
28
34
29
-
{{< callout warning >}}
30
-
## Incompatible plugins
35
+
Compared to JS bundlers, using ESM in the browser requires you to use the full path and filename instead of the module name. [Read more about JS modules in the browser.](https://v8.dev/features/modules#specifiers) That's why we use `'coreui.esm.min.js'` instead of `'coreui'` above. However, this is further complicated by our Popper dependency, which imports Popper into our JavaScript like so:
36
+
37
+
<!-- eslint-skip -->
38
+
```js
39
+
import*asPopperfrom"@popperjs/core"
40
+
```
41
+
42
+
If you try this as-is, you'll see an error in the console like the following:
43
+
44
+
```text
45
+
Uncaught TypeError: Failed to resolve module specifier "@popperjs/core". Relative references must start with either "/", "./", or "../".
46
+
```
47
+
48
+
To fix this, you can use an `importmap` to resolve the arbitrary module names to complete paths. If your [targeted browsers](https://caniuse.com/?search=importmap) do not support `importmap`, you'll need to use the [es-module-shims](https://github.com/guybedford/es-module-shims) project. Here's how it works for Bootstrap and Popper:
31
49
32
-
Due to browser limitations, some of our plugins, namely Dropdown, Tooltip and Popover plugins, cannot be used in a `<script>` tag with `module` type because they depend on Popper. For more information about the issue see [here](https://v8.dev/features/modules#specifiers).
Some plugins and CSS components depend on other plugins. If you include plugins individually, make sure to check for these dependencies in the docs.
38
85
39
86
Our dropdowns, popovers and tooltips also depend on [Popper](https://popper.js.org/).
40
87
41
-
## Still want to use jQuery? It's possible!
42
-
43
-
CoreUI 4 for Bootstrap is designed to be used without jQuery, but it's still possible to use our components with jQuery. **If CoreUI for Bootstrap detects `jQuery` in the `window` object** it'll add all of our components in jQuery's plugin system; this means you'll be able to do `$('[data-coreui-toggle="tooltip"]').tooltip()` to enable tooltips. The same goes for our other components.
44
-
45
88
## Data attributes
46
89
47
90
Nearly all CoreUI for Bootstrap plugins can be enabled and configured through HTML alone with data attributes (our preferred way of using JavaScript functionality). Be sure to **only use one set of data attributes on a single element** (e.g., you cannot trigger a tooltip and modal from the same button.)
48
91
49
-
{{< callout warning >}}
50
92
## Selectors
51
93
52
94
Currently to query DOM elements we use the native methods `querySelector` and `querySelectorAll` for performance reasons, so you have to use [valid selectors](https://www.w3.org/TR/CSS21/syndata.html#value-def-identifier).
53
95
If you use special selectors, for example: `collapse:Example` be sure to escape them.
CoreUI for Bootstrap will detect jQuery if `jQuery` is present in the `window`object and there is no `data-coreui-no-jquery` attribute set on `<body>`. If jQuery is found, CoreUI for Bootstrap will emit events thanks to jQuery's event system. So if you want to listen to CoreUI's events, you'll have to use the jQuery methods (`.on`, `.one`) instead of `addEventListener`.
116
+
All constructors accept an optional options object or nothing (which initiates a plugin with its default behavior):
77
117
78
118
```js
79
-
$('#myTab a').on('shown.coreui.tab', () => {
80
-
// do something...
81
-
})
82
-
```
83
-
{{< /callout >}}
119
+
constmyModalEl=document.querySelector('#myModal')
120
+
constmodal=newcoreui.Modal(myModalEl) // initialized with defaults
84
121
85
-
## Programmatic API
122
+
constconfigObject= { keyboard:false }
123
+
constmodal1=newcoreui.Modal(myModalEl, configObject) // initialized with no keyboard
124
+
```
86
125
87
-
All constructors accept an optional options object or nothing (which initiates a plugin with its default behavior):
126
+
If you'd like to get a particular plugin instance, each plugin exposes a `getInstance` method. For example, to retrieve an instance directly from an element:
88
127
89
128
```js
90
-
constmyModalEl=document.getElementById('myModal')
129
+
coreui.Popover.getInstance(myPopoverEl)
130
+
```
91
131
92
-
constmodal=newcoreui.Modal(myModalEl) // initialized with defaults
93
-
constmodal1=newcoreui.Modal(myModalEl, { keyboard:false }) // initialized with no keyboard
132
+
This method will return `null` if an instance is not initiated over the requested element.
133
+
134
+
Alternatively, `getOrCreateInstance` can be used to get the instance associated with a DOM element, or create a new one in case it wasn't initialized.
If you'd like to get a particular plugin instance, each plugin exposes a `getInstance` method. In order to retrieve it directly from an element, do this: `coreui.Popover.getInstance(myPopoverEl)`.
140
+
In case an instance wasn't initialized, it may accept and use an optional configuration object as second argument.
97
141
98
142
### CSS selectors in constructors
99
143
100
-
You can also use a CSS selector as the first argument instead of a DOM element to initialize the plugin. Currently the element for the plugin is found by the `querySelector` method since our plugins support a single element only.
144
+
In addition to the `getInstance` and `getOrCreateInstance` methods, all plugin constructors can accept a DOM element or a valid [CSS selector](#selectors) as the first argument. Plugin elements are found with the `querySelector` method since our plugins only support a single element.
@@ -132,84 +178,55 @@ carousel.to('1') // Will start sliding to the slide 1 and returns to the caller
132
178
carousel.to('2') // !! Will be ignored, as the transition to the slide 1 is not finished !!
133
179
```
134
180
135
-
### Default settings
136
181
137
-
You can change the default settings for a plugin by modifying the plugin's `Constructor.Default` object:
182
+
#### `dispose` method
138
183
139
-
```js
140
-
// changes default for the modal plugin's `keyboard` option to false
141
-
coreui.Modal.Default.keyboard=false
142
-
```
143
-
144
-
## No conflict (only if you use jQuery)
145
-
146
-
Sometimes it is necessary to use CoreUI for Bootstrap plugins with other UI frameworks. In these circumstances, namespace collisions can occasionally occur. If this happens, you may call `.noConflict` on the plugin you wish to revert the value of.
184
+
While it may seem correct to use the `dispose` method immediately after `hide()`, it will lead to incorrect results. Here's an example of the problem use:
147
185
148
186
```js
149
-
constcoreuiButton=$.fn.button.noConflict() // return $.fn.button to previously assigned value
150
-
$.fn.coreuiBtn= coreuiButton // give $().coreuiBtn the CoreUI for Bootstrap functionality
// changes default for the modal plugin's `keyboard` option to false
201
+
coreui.Modal.Default.keyboard=false
159
202
```
160
203
161
-
## No special fallbacks when JavaScript is disabled
204
+
## Methods and properties
162
205
163
-
CoreUI's plugins don't fall back particularly gracefully when JavaScript is disabled. If you care about the user experience in this case, use [`<noscript>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript) to explain the situation (and how to re-enable JavaScript) to your users, and/or add your own custom fallbacks.
206
+
Every CoreUI for Bootstrap plugin exposes the following methods and static properties.
164
207
165
-
{{< callout warning >}}
166
-
##### Third-party libraries
208
+
{{< bs-table "table" >}}
209
+
| Method | Description |
210
+
| --- | --- |
211
+
|`dispose`| Destroys an element's modal. (Removes stored data on the DOM element) |
212
+
|`getInstance`|*Static* method which allows you to get the modal instance associated with a DOM element. |
213
+
|`getOrCreateInstance`|*Static* method which allows you to get the modal instance associated with a DOM element, or create a new one in case it wasn't initialized. |
214
+
{{< /bs-table >}}
167
215
168
-
**CoreUI for Bootstrap does not officially support third-party JavaScript libraries** like Prototype or jQuery UI. Despite `.noConflict` and namespaced events, there may be compatibility problems that you need to fix on your own.
169
-
{{< /callout >}}
216
+
{{< bs-table "table" >}}
217
+
| Static property | Description |
218
+
| --- | --- |
219
+
|`NAME`| Returns the plugin name. (Example: `coreui.Tooltip.NAME`) |
220
+
|`VERSION`| The version of each of CoreUI for Bootstrap's plugins can be accessed via the `VERSION` property of the plugin's constructor (Example: `coreui.Tooltip.VERSION`) |
221
+
{{< /bs-table >}}
170
222
171
223
## Sanitizer
172
224
173
225
Tooltips and Popovers use our built-in sanitizer to sanitize options which accept HTML.
174
226
175
227
The default `allowList` value is the following:
176
228
177
-
```js
178
-
constARIA_ATTRIBUTE_PATTERN=/^aria-[\w-]*$/i
179
-
constDefaultAllowlist= {
180
-
// Global attributes allowed on any supplied element below.
If you want to bypass our sanitizer because you prefer to use a dedicated library, for example [DOMPurify](https://www.npmjs.com/package/dompurify), you should do the following:
**You don't need jQuery in CoreUI for Bootstrap**, but it's still possible to use our components with jQuery. If CoreUI for Bootstrap detects `jQuery` in the `window` object, it'll add all of our components in jQuery's plugin system. This allows you to do the following:
262
+
263
+
```js
264
+
// to enable tooltips with the default configuration
265
+
$('[data-coreui-toggle="tooltip"]').tooltip()
266
+
267
+
// to initialize tooltips with given configuration
268
+
$('[data-coreui-toggle="tooltip"]').tooltip({
269
+
boundary:'clippingParents',
270
+
customClass:'myClass'
271
+
})
272
+
273
+
// to trigger the `show` method
274
+
$('#myTooltip').tooltip('show')
275
+
```
276
+
277
+
The same goes for our other components.
278
+
279
+
### No conflict
280
+
281
+
Sometimes it is necessary to use CoreUI for Bootstrap plugins with other UI frameworks. In these circumstances, namespace collisions can occasionally occur. If this happens, you may call `.noConflict` on the plugin you wish to revert the value of.
282
+
283
+
```js
284
+
constcoreuiButton=$.fn.button.noConflict() // return $.fn.button to previously assigned value
285
+
$.fn.coreuiBtn= coreuiButton // give $().coreuiBtn the CoreUI for Bootstrap functionality
286
+
```
287
+
288
+
CoreUI for Bootstrap does not officially support third-party JavaScript libraries like Prototype or jQuery UI. Despite `.noConflict` and namespaced events, there may be compatibility problems that you need to fix on your own.
289
+
290
+
### jQuery events
291
+
292
+
CoreUI for Bootstrap will detect jQuery if `jQuery` is present in the `window` object and there is no `data-coreui-no-jquery` attribute set on `<body>`. If jQuery is found, CoreUI for Bootstrap will emit events thanks to jQuery's event system. So if you want to listen to CoreUI for Bootstrap's events, you'll have to use the jQuery methods (`.on`, `.one`) instead of `addEventListener`.
293
+
294
+
```js
295
+
$('#myTab a').on('shown.coreui.tab', () => {
296
+
// do something...
297
+
})
298
+
```
299
+
300
+
## Disabled JavaScript
301
+
302
+
CoreUI for Bootstrap's plugins have no special fallback when JavaScript is disabled. If you care about the user experience in this case, use [`<noscript>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript) to explain the situation (and how to re-enable JavaScript) to your users, and/or add your own custom fallbacks.
0 commit comments