forked from jarstone/dselect
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathicon-picker.html
More file actions
150 lines (138 loc) · 4.7 KB
/
icon-picker.html
File metadata and controls
150 lines (138 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!doctype html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="favicon.ico">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-LN+7fdVzj6u52u30Kp6M/trliBMCMKTyK833zpbD+pXdCLuTusPj697FH4R/5mcr" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="dist/css/dselect.css">
<title>Bootstrap Icon Picker with dselect</title>
<style>
body {
padding: 2rem;
}
.icon-preview {
font-size: 1.5rem;
margin-right: 0.5rem;
}
.selected-icon-display {
margin-top: 2rem;
padding: 2rem;
border: 2px solid var(--bs-border-color);
border-radius: 0.5rem;
background: var(--bs-secondary-bg-subtle);
}
.selected-icon-display i {
font-size: 3rem;
margin-bottom: 1rem;
}
</style>
</head>
<body class="bg-secondary-subtle">
<div class="container">
<div class="row">
<div class="col-12 col-lg-8 offset-lg-2">
<div class="card">
<div class="card-header">
<h1 class="h3 mb-0">Bootstrap Icon Picker</h1>
</div>
<div class="card-body">
<div class="mb-3">
<label for="icon-picker" class="form-label">Select an Icon</label>
<select class="form-select" id="icon-picker" data-dselect-search="true" data-dselect-clearable="true">
<option value="">Choose an icon...</option>
</select>
</div>
<div class="selected-icon-display text-center" id="icon-display">
<i class="bi" id="selected-icon-visual"></i>
<div>
<strong>Selected Icon Class:</strong>
<code id="selected-icon-class">None</code>
</div>
<div class="mt-2">
<strong>Value in Select:</strong>
<code id="selected-icon-value">None</code>
</div>
</div>
<div class="mt-4">
<h5>How it works:</h5>
<ul class="text-start">
<li>Search through 2000+ Bootstrap Icons</li>
<li>Icons are displayed with preview and class name</li>
<li>The select value contains the Bootstrap icon class (e.g., "bi-heart-fill")</li>
<li>Clearable option to reset selection</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js" integrity="sha384-ndDqU0Gzau9qJ1lfW4pNLlhNTkCfHzAVBReH9diLvGRem5+R9g2FzA8ZGN954O5Q" crossorigin="anonymous"></script>
<script src="dist/js/dselect.js"></script>
<script src="bootstrap-icons-data.js"></script>
<script>
const iconSelect = document.getElementById('icon-picker');
const selectedIconVisual = document.getElementById('selected-icon-visual');
const selectedIconClass = document.getElementById('selected-icon-class');
const selectedIconValue = document.getElementById('selected-icon-value');
bootstrapIcons.forEach(iconClass => {
const option = document.createElement('option');
option.value = iconClass;
option.textContent = iconClass;
iconSelect.appendChild(option);
});
dselect(iconSelect, {
search: true,
clearable: true,
maxHeight: '400px',
searchPlaceholder: 'Search icons...',
noResultsPlaceholder: 'No icons found'
});
iconSelect.addEventListener('change', function() {
const selectedValue = this.value;
if (selectedValue) {
selectedIconVisual.className = `bi ${selectedValue}`;
selectedIconClass.textContent = selectedValue;
selectedIconValue.textContent = selectedValue;
} else {
selectedIconVisual.className = 'bi';
selectedIconClass.textContent = 'None';
selectedIconValue.textContent = 'None';
}
});
function addIconsToDropdown() {
bootstrapIcons.forEach(iconClass => {
const items = document.querySelectorAll(`.dropdown-item[data-dselect-value="${iconClass}"]`);
items.forEach(item => {
if (!item.querySelector('.bi')) {
const icon = document.createElement('i');
icon.className = `bi ${iconClass}`;
icon.style.marginRight = '0.5rem';
icon.style.fontSize = '1.2rem';
icon.style.verticalAlign = 'middle';
item.insertBefore(icon, item.firstChild);
}
});
});
}
setTimeout(addIconsToDropdown, 100);
iconSelect.addEventListener('update', function() {
setTimeout(addIconsToDropdown, 50);
});
const observer = new MutationObserver(function() {
addIconsToDropdown();
});
setTimeout(() => {
const dropdownMenu = iconSelect.nextElementSibling?.querySelector('.dropdown-menu');
if (dropdownMenu) {
observer.observe(dropdownMenu, {
childList: true,
subtree: true
});
}
}, 200);
</script>
</body>
</html>