Skip to content

Commit 4ee933d

Browse files
authored
V1.0.0 (#1)
* v1.0.0 - initial commit * Update README.md
1 parent e005391 commit 4ee933d

19 files changed

+1045
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
node_modules

README.md

Lines changed: 317 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,317 @@
1-
# bs5-utils
1+
# Bs5Utils - A JavaScript utility package for Bootstrap 5 components
2+
3+
---
4+
5+
A simple package to make the usage of various components within Bootstrap 5 easier to use.
6+
7+
If this package has helped you, and you're feeling particularly generous:
8+
- **ETH/MATIC:** 0x6515654c8e931052ab17a63311411D475D503e59
9+
- **ADA:** addr1qxaqvghsr8lu3wrmql4fcvg6txj5083s2a9rr5dmrrtjt0yn8t0x4yav3ma2flg3tzcu9767s7senydcumnf6c4krnnspn949q
10+
11+
---
12+
13+
Contents
14+
-
15+
16+
- [Configuration](#configuration)
17+
- [Theming](#theming)
18+
- [API](#api)
19+
- [Support & Contribute](#support--contribute)
20+
21+
Configuration
22+
-
23+
24+
There are several defaults which you can customize:
25+
26+
```javascript
27+
Bs5Utils.defaults.toasts.position = 'top-right';
28+
Bs5Utils.defaults.toasts.container = 'toast-container';
29+
Bs5Utils.defaults.toasts.stacking = false;
30+
```
31+
32+
As `bs5Utils.Snack` is a subset of `bs5Utils.Toast`, the configuration for toasts will also apply to `bs5Utils.Sanck`.
33+
34+
Theming
35+
-
36+
37+
You can register your own custom styles by passing classes to specific components by using the static
38+
method `Bs5Utils.registerStyle`. The components you can customise are:
39+
40+
- `btnClose` - The dismiss button
41+
- `main` - The area of the toast, snack, or modal which will display the `type` color
42+
- `border` - The border of the component
43+
44+
These components have been clearly illustrated below. For the time being, the `border` style for `bs5Utils.Snack` cannot
45+
be overridden.
46+
47+
**Note:** All of these keys _must_ be passed in the `styles` parameter object.
48+
49+
**Method Overview**
50+
51+
```javascript
52+
/**
53+
* Register a style for the components
54+
* @param key - To reference your style
55+
* @param styles - The style object
56+
*/
57+
Bs5Utils.registerStyle(key, styles)
58+
```
59+
60+
**Usage**
61+
62+
You first define your CSS classes:
63+
64+
```css
65+
.bg-pink {
66+
background-color: pink;
67+
}
68+
69+
.text-purple {
70+
color: purple;
71+
}
72+
73+
.border-pink {
74+
border-color: pink !important;
75+
}
76+
```
77+
78+
Then you register the style:
79+
80+
```javascript
81+
Bs5Utils.registerStyle('pink', {
82+
btnClose: ['btn-close-white'],
83+
main: ['bg-pink', 'text-purple'],
84+
border: ['border-pink']
85+
});
86+
```
87+
88+
Pass empty arrays if you wish to leave the default styles e.g.
89+
90+
```javascript
91+
Bs5Utils.registerStyle('pink', {
92+
btnClose: [],
93+
main: ['bg-pink', 'text-purple'],
94+
border: ['border-pink']
95+
});
96+
```
97+
98+
Now, `pink` can be used as a `type` when displaying snacks, toasts, or modals e.g.
99+
100+
**Snack**
101+
102+
![Theming Snack](example/img/theming-snack.png)
103+
104+
**Toast**
105+
106+
![Theming Snack](example/img/theming-toast.png)
107+
108+
**Modal**
109+
110+
![Theming Modal](example/img/theming-modal.png)
111+
112+
API
113+
-
114+
115+
This package is based around the `Bs5Utils` class, so first things first, construct the object:
116+
117+
```javascript
118+
const bs5Utils = new Bs5Utils();
119+
```
120+
121+
Thereafter you'll be able to use the methods outlined below.
122+
123+
### Snacks
124+
125+
**Method Overview**
126+
127+
```javascript
128+
/**
129+
* Display a lightweight toast for simple alerts
130+
* @param - type the theme of the snack
131+
* @param - title the title of the of the snack
132+
* @param - delay in ms, if specified the snack will autohide after the specified amount
133+
* @param - dismissible set whether the dismiss button should show
134+
*/
135+
bs5Utils.Snack.show(
136+
type,
137+
title,
138+
delay = 0,
139+
dismissible = true
140+
);
141+
```
142+
143+
**Usage**
144+
145+
```javascript
146+
bs5Utils.Snack.show('secondary', 'Hello World!', delay = 0, dismissible = true);
147+
bs5Utils.Snack.show('light', 'Hello World!', delay = 0, dismissible = true);
148+
bs5Utils.Snack.show('white', 'Hello World!', delay = 0, dismissible = true);
149+
bs5Utils.Snack.show('dark', 'Hello World!', delay = 0, dismissible = true);
150+
bs5Utils.Snack.show('info', 'Hello World!', delay = 0, dismissible = true);
151+
bs5Utils.Snack.show('primary', 'Hello World!', delay = 0, dismissible = true);
152+
bs5Utils.Snack.show('success', 'Hello World!', delay = 0, dismissible = true);
153+
bs5Utils.Snack.show('warning', 'Hello World!', delay = 0, dismissible = true);
154+
bs5Utils.Snack.show('danger', 'Hello World!', delay = 0, dismissible = true);
155+
```
156+
157+
**Example**
158+
159+
![img.png](example/img/api-snacks.png)
160+
161+
### Toasts
162+
163+
**Method Overview**
164+
165+
```javascript
166+
/**
167+
* Display a toast for alerts
168+
* @param type - the theme of the snack
169+
* @param icon - Set an icon in the top-left corner, you can pass HTML directly
170+
* @param title - the title of the of the toast
171+
* @param subtitle - the subtitle of the toast
172+
* @param content - the content of the toast
173+
* @param buttons - the action buttons of the toast
174+
* @param delay - in ms, if specified the snack will autohide after the specified amount
175+
* @param dismissible - set whether the dismiss button should show
176+
*/
177+
bs5Utils.Toast.show({
178+
type,
179+
icon = '',
180+
title,
181+
subtitle = '',
182+
content = '',
183+
buttons = [],
184+
delay = 0,
185+
dismissible = true,
186+
});
187+
```
188+
189+
**Usage**
190+
191+
```javascript
192+
bs5Utils.Toast.show({
193+
type: 'primary',
194+
icon: `<i class="far fa-check-circle fa-lg me-2"></i>`,
195+
title: 'Notification!',
196+
subtitle: '23 secs ago',
197+
content: 'Hello World!',
198+
buttons: [
199+
{
200+
text: 'Click Me!',
201+
class: 'btn btn-sm btn-primary',
202+
handler: () => {
203+
alert(`Button #1 has been clicked!`);
204+
}
205+
},
206+
{
207+
text: 'Click Me Too!',
208+
class: 'btn btn-sm btn-warning',
209+
handler: () => {
210+
alert(`You clicked me too!`);
211+
}
212+
},
213+
{
214+
type: 'dismiss',
215+
text: 'Hide',
216+
class: 'btn btn-sm btn-secondary'
217+
}
218+
],
219+
delay: 0,
220+
dismissible: true
221+
});
222+
```
223+
224+
**Example**
225+
226+
![img.png](example/img/api-toasts.png)
227+
228+
### Modals
229+
230+
**Method Overview**
231+
232+
```javascript
233+
/**
234+
* Display a modal
235+
* @param type - the theme of the snack
236+
* @param title - the title of the modal, if omitted, the modal-header element is removed
237+
* @param content - the content of the modal, if omitted, the modal-body element is removed
238+
* @param buttons - any action buttons, if omitted, the the modal-footer element is removed
239+
* @param centered - set whether the modal is centered
240+
* @param dismissible - set whether the dismiss button should show
241+
* @param backdrop - set the type of backdrop: true, false, static
242+
* @param keyboard - set whether the escape key closes the modal
243+
* @param focus - set whether the modal is autofocussed when initialized
244+
* @param fullscreen - set whether the modal is fullscreen
245+
* @param modalSize - set the size of the modal: sm, lg, xl by default, it's an empty string
246+
*/
247+
bs5Utils.Modal.show({
248+
type,
249+
title = '',
250+
content = '',
251+
buttons = [],
252+
centered = false,
253+
dismissible = true,
254+
backdrop = dismissible ? true : 'static',
255+
keyboard = dismissible,
256+
focus = true,
257+
fullscreen = false,
258+
size = ''
259+
})
260+
```
261+
262+
**Usage**
263+
264+
```javascript
265+
bs5Utils.Modal.show({
266+
type: 'primary',
267+
title: `Hello World!`,
268+
content: `<p class="text-center fw-bold">Hello World!</p>`,
269+
buttons: [
270+
{
271+
text: 'Click Me!',
272+
class: 'btn btn-sm btn-primary',
273+
handler: () => {
274+
alert(`Button #1 has been clicked!`);
275+
}
276+
},
277+
{
278+
text: 'Click Me Too!',
279+
class: 'btn btn-sm btn-warning',
280+
handler: () => {
281+
alert(`You clicked me too!`);
282+
}
283+
},
284+
{
285+
type: 'dismiss',
286+
text: 'Hide',
287+
class: 'btn btn-sm btn-secondary'
288+
}
289+
],
290+
centered: true,
291+
dismissible: true,
292+
backdrop: 'static',
293+
keyboard: false,
294+
focus: false
295+
});
296+
```
297+
298+
**Example**
299+
300+
![img.png](example/img/api-modal-1.png)
301+
302+
![img.png](example/img/api-modal-2.png)
303+
304+
![img_1.png](example/img/api-modal-3.png)
305+
306+
![img.png](example/img/api-modal-4.png)
307+
308+
Support & Contribute
309+
-
310+
311+
- Use: [Babel Repl](https://babeljs.io/repl) and [JavaScript Minifier](https://javascript-minifier.com/) to build the
312+
app to transpile and minify your changes
313+
- Submit issues and PRs
314+
- Let's know how you're using this package in your project
315+
- If this package has helped you, and you're feeling particularly generous:
316+
- **ETH/MATIC:** 0x6515654c8e931052ab17a63311411D475D503e59
317+
- **ADA:** addr1qxaqvghsr8lu3wrmql4fcvg6txj5083s2a9rr5dmrrtjt0yn8t0x4yav3ma2flg3tzcu9767s7senydcumnf6c4krnnspn949q

dist/js/Bs5Utils.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/img/api-modal-1.png

5.36 KB
Loading

example/img/api-modal-2.png

4.08 KB
Loading

example/img/api-modal-3.png

2.1 KB
Loading

example/img/api-modal-4.png

3.35 KB
Loading

example/img/api-snacks.png

15.4 KB
Loading

example/img/api-toasts.png

4.96 KB
Loading

example/img/theming-modal.png

6.37 KB
Loading

0 commit comments

Comments
 (0)