Skip to content

Commit

Permalink
allow custom colors
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Dec 13, 2021
1 parent 67e5b0d commit ec5dfb3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
8 changes: 4 additions & 4 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ <h1>Demo</h1>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="validationTagsShow" class="form-label">Tags (show all)</label>
<label for="validationTagsShow" class="form-label">Tags (show all + custom colors)</label>
<select class="form-select" id="validationTagsShow" name="tags_show[]" multiple data-show-all-suggestions="true">
<option disabled hidden value="">Choose a tag...</option>
<option value="1" selected="selected">Apple</option>
<option value="2">Banana</option>
<option value="3">Orange</option>
<option value="4">Blueberry</option>
<option value="2" data-badge-style="success" selected="selected">Banana</option>
<option value="3" data-badge-style="warning" data-badge-class="text-dark">Orange</option>
<option value="4" data-badge-style="secondary">Blueberry</option>
<option value="5">Strawberry</option>
<option value="6">Cranberry</option>
<option value="7">Huckleberry</option>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap5-tags",
"version": "1.2.2",
"version": "1.2.3",
"description": "Replace select[multiple] with nices badges",
"main": "tags",
"scripts": {
Expand Down
11 changes: 9 additions & 2 deletions tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,21 @@ class Tags {
// create span
let html = text;
let span = document.createElement("span");
let badgeStyle = this.badgeStyle;
span.classList.add("badge");
if (opt.dataset.badgeStyle) {
badgeStyle = opt.dataset.badgeStyle;
}
if (opt.dataset.badgeClass) {
span.classList.add(opt.dataset.badgeClass);
}
if (bver === 5) {
//https://getbootstrap.com/docs/5.1/components/badge/
span.classList.add("bg-" + this.badgeStyle);
span.classList.add("bg-" + badgeStyle);
span.classList.add("me-2");
} else {
// https://getbootstrap.com/docs/4.6/components/badge/
span.classList.add("badge-" + this.badgeStyle);
span.classList.add("badge-" + badgeStyle);
span.classList.add("mr-2");
}
span.setAttribute(VALUE_ATTRIBUTE, value);
Expand Down
2 changes: 1 addition & 1 deletion tags.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ec5dfb3

Please sign in to comment.