bareframe 0.1.0 → 0.1.1
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/README.md +179 -0
- package/dist/bareframe.min.js +119 -0
- package/dist/components/accordion.js +66 -0
- package/dist/components/autocomplete.css +78 -15
- package/dist/components/autocomplete.js +220 -10
- package/dist/components/avatar.css +129 -17
- package/dist/components/avatar.js +47 -10
- package/dist/components/breadcrumb.css +63 -17
- package/dist/components/breadcrumb.js +140 -5
- package/dist/components/button.css +4 -0
- package/dist/components/button.js +95 -15
- package/dist/components/chart.css +163 -14
- package/dist/components/chart.js +59 -4
- package/dist/components/checkbox.css +43 -1
- package/dist/components/checkbox.js +98 -5
- package/dist/components/dialog.css +95 -0
- package/dist/components/dialog.js +172 -4
- package/dist/components/divider.css +18 -22
- package/dist/components/divider.js +31 -3
- package/dist/components/drawer.css +68 -18
- package/dist/components/drawer.js +84 -4
- package/dist/components/edge.css +54 -0
- package/dist/components/edge.js +55 -0
- package/dist/components/file-upload.css +72 -3
- package/dist/components/file-upload.js +186 -4
- package/dist/components/input.css +59 -0
- package/dist/components/input.js +369 -4
- package/dist/components/list.css +11 -0
- package/dist/components/list.js +45 -0
- package/dist/components/menu.css +20 -0
- package/dist/components/menu.js +144 -0
- package/dist/components/modal.css +30 -17
- package/dist/components/modal.js +68 -4
- package/dist/components/nav.css +39 -0
- package/dist/components/progress.css +196 -0
- package/dist/components/progress.js +304 -0
- package/dist/components/radio.css +35 -1
- package/dist/components/radio.js +86 -5
- package/dist/components/range.css +91 -0
- package/dist/components/range.js +250 -0
- package/dist/components/select.css +35 -1
- package/dist/components/select.js +255 -4
- package/dist/components/skeleton.css +108 -21
- package/dist/components/skeleton.js +57 -4
- package/dist/components/tab.css +9 -1
- package/dist/components/tab.js +66 -1
- package/dist/components/tag.css +36 -3
- package/dist/components/tag.js +32 -0
- package/dist/components/toast.css +113 -0
- package/dist/components/toast.js +265 -4
- package/dist/components/toggle.css +53 -0
- package/dist/components/toggle.js +73 -5
- package/dist/components/wizard.css +79 -14
- package/dist/components/wizard.js +141 -4
- package/dist/index.js +5147 -110
- package/dist/manifest.json +5 -42
- package/dist/themes/aurora.css +47 -0
- package/dist/themes/dark.css +12 -2
- package/dist/themes/desert.css +37 -0
- package/dist/themes/future.css +47 -0
- package/dist/themes/layout.css +191 -0
- package/dist/themes/light.css +12 -0
- package/dist/themes/matrix.css +37 -0
- package/dist/themes/modern.css +64 -0
- package/dist/themes/nature.css +47 -0
- package/dist/themes/nebula.css +37 -0
- package/dist/themes/noir.css +37 -0
- package/dist/themes/oceanic.css +37 -0
- package/dist/themes/retro.css +47 -0
- package/dist/themes/simple.css +47 -0
- package/dist/themes/sprint.css +12 -0
- package/dist/themes/sunrise.css +37 -0
- package/dist/themes/system.css +13 -0
- package/package.json +9 -2
- package/dist/components/alert.css +0 -30
- package/dist/components/alert.js +0 -31
- package/dist/components/badge.css +0 -30
- package/dist/components/badge.js +0 -31
- package/dist/components/banner.css +0 -30
- package/dist/components/banner.js +0 -31
- package/dist/components/bar-chart.css +0 -30
- package/dist/components/bar-chart.js +0 -31
- package/dist/components/bottom-sheet.css +0 -30
- package/dist/components/bottom-sheet.js +0 -31
- package/dist/components/button-group.css +0 -30
- package/dist/components/button-group.js +0 -31
- package/dist/components/chip.css +0 -30
- package/dist/components/chip.js +0 -31
- package/dist/components/color-picker.css +0 -30
- package/dist/components/color-picker.js +0 -31
- package/dist/components/context-menu.css +0 -30
- package/dist/components/context-menu.js +0 -31
- package/dist/components/donut-chart.css +0 -30
- package/dist/components/donut-chart.js +0 -31
- package/dist/components/expanded-panel.css +0 -30
- package/dist/components/expanded-panel.js +0 -31
- package/dist/components/footer.css +0 -30
- package/dist/components/footer.js +0 -31
- package/dist/components/gantt-chart.css +0 -30
- package/dist/components/gantt-chart.js +0 -31
- package/dist/components/gauge.css +0 -30
- package/dist/components/gauge.js +0 -31
- package/dist/components/graph.css +0 -30
- package/dist/components/graph.js +0 -31
- package/dist/components/header.css +0 -30
- package/dist/components/header.js +0 -31
- package/dist/components/heatmap.css +0 -30
- package/dist/components/heatmap.js +0 -31
- package/dist/components/line-chart.css +0 -30
- package/dist/components/line-chart.js +0 -31
- package/dist/components/list-item.css +0 -30
- package/dist/components/list-item.js +0 -31
- package/dist/components/menu-item.css +0 -30
- package/dist/components/menu-item.js +0 -31
- package/dist/components/multi-select.css +0 -30
- package/dist/components/multi-select.js +0 -31
- package/dist/components/notification.css +0 -30
- package/dist/components/notification.js +0 -31
- package/dist/components/pie-chart.css +0 -30
- package/dist/components/pie-chart.js +0 -31
- package/dist/components/popover.css +0 -30
- package/dist/components/popover.js +0 -31
- package/dist/components/progress-bar.css +0 -30
- package/dist/components/progress-bar.js +0 -31
- package/dist/components/progress-circle.css +0 -30
- package/dist/components/progress-circle.js +0 -31
- package/dist/components/radio-group.css +0 -30
- package/dist/components/radio-group.js +0 -31
- package/dist/components/range-slider.css +0 -30
- package/dist/components/range-slider.js +0 -31
- package/dist/components/rating.css +0 -30
- package/dist/components/rating.js +0 -31
- package/dist/components/sheet.css +0 -30
- package/dist/components/sheet.js +0 -31
- package/dist/components/slider.css +0 -30
- package/dist/components/slider.js +0 -31
- package/dist/components/snackbar.css +0 -30
- package/dist/components/snackbar.js +0 -31
- package/dist/components/sparkline.css +0 -30
- package/dist/components/sparkline.js +0 -31
- package/dist/components/stepper.css +0 -30
- package/dist/components/stepper.js +0 -31
- package/dist/components/switch.css +0 -30
- package/dist/components/switch.js +0 -31
- package/dist/components/tab-group.css +0 -30
- package/dist/components/tab-group.js +0 -31
- package/dist/components/textfield.css +0 -30
- package/dist/components/textfield.js +0 -31
- package/dist/components/tooltip.css +0 -30
- package/dist/components/tooltip.js +0 -31
- package/dist/components/treemap.css +0 -30
- package/dist/components/treemap.js +0 -31
- package/dist/components/upload-dropzone.css +0 -30
- package/dist/components/upload-dropzone.js +0 -31
package/dist/components/radio.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
class BfRadio extends HTMLElement {
|
|
2
|
+
static observedAttributes = ['checked', 'disabled', 'label', 'value', 'group'];
|
|
3
|
+
|
|
2
4
|
constructor() {
|
|
3
5
|
super();
|
|
4
6
|
this.attachShadow({ mode: 'open' });
|
|
7
|
+
this._onInputChange = this._onInputChange.bind(this);
|
|
5
8
|
}
|
|
6
9
|
|
|
7
10
|
connectedCallback() {
|
|
8
11
|
if (this._initialized) {
|
|
12
|
+
this._syncState();
|
|
9
13
|
return;
|
|
10
14
|
}
|
|
11
15
|
this._initialized = true;
|
|
@@ -15,16 +19,93 @@ class BfRadio extends HTMLElement {
|
|
|
15
19
|
link.rel = 'stylesheet';
|
|
16
20
|
link.href = cssUrl.href;
|
|
17
21
|
|
|
18
|
-
const root = document.createElement('
|
|
22
|
+
const root = document.createElement('label');
|
|
19
23
|
root.className = 'root';
|
|
20
24
|
root.setAttribute('part', 'root');
|
|
21
|
-
root.innerHTML =
|
|
25
|
+
root.innerHTML = `
|
|
26
|
+
<input type="radio" part="input" />
|
|
27
|
+
<span class="dot" part="dot"></span>
|
|
28
|
+
<span class="text" part="text"><slot></slot></span>
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
this.shadowRoot.replaceChildren(link, root);
|
|
32
|
+
this._input = this.shadowRoot.querySelector('input');
|
|
33
|
+
this._input.addEventListener('change', this._onInputChange);
|
|
34
|
+
this._syncState();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
attributeChangedCallback() {
|
|
38
|
+
this._syncState();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get checked() {
|
|
42
|
+
return this.hasAttribute('checked');
|
|
43
|
+
}
|
|
22
44
|
|
|
23
|
-
|
|
24
|
-
|
|
45
|
+
set checked(value) {
|
|
46
|
+
if (value) {
|
|
47
|
+
this.setAttribute('checked', '');
|
|
48
|
+
return;
|
|
25
49
|
}
|
|
50
|
+
this.removeAttribute('checked');
|
|
51
|
+
}
|
|
26
52
|
|
|
27
|
-
|
|
53
|
+
_onInputChange() {
|
|
54
|
+
if (this._input.checked) {
|
|
55
|
+
this.checked = true;
|
|
56
|
+
this._uncheckPeers();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.dispatchEvent(
|
|
60
|
+
new CustomEvent('bf-change', {
|
|
61
|
+
bubbles: true,
|
|
62
|
+
composed: true,
|
|
63
|
+
detail: {
|
|
64
|
+
group: this._effectiveGroup(),
|
|
65
|
+
value: this.value,
|
|
66
|
+
checked: this.checked,
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_uncheckPeers() {
|
|
73
|
+
const group = this._effectiveGroup();
|
|
74
|
+
if (!group) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const peers = document.querySelectorAll(`bf-radio[group="${CSS.escape(group)}"]`);
|
|
78
|
+
for (const peer of peers) {
|
|
79
|
+
if (peer !== this) {
|
|
80
|
+
peer.checked = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_effectiveGroup() {
|
|
86
|
+
return this.getAttribute('group') || '';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get value() {
|
|
90
|
+
return this.getAttribute('value') || this.textContent?.trim() || '';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
_syncState() {
|
|
94
|
+
if (!this._input) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const group = this._effectiveGroup();
|
|
98
|
+
this._input.name = group;
|
|
99
|
+
this._input.value = this.value;
|
|
100
|
+
this._input.checked = this.checked;
|
|
101
|
+
this._input.disabled = this.hasAttribute('disabled');
|
|
102
|
+
const hasLabelText = (this.textContent || '').trim().length > 0;
|
|
103
|
+
if (!hasLabelText && !this.getAttribute('label')) {
|
|
104
|
+
this.setAttribute('label', 'radio');
|
|
105
|
+
}
|
|
106
|
+
if (this.getAttribute('label')) {
|
|
107
|
+
this.setAttribute('aria-label', this.getAttribute('label'));
|
|
108
|
+
}
|
|
28
109
|
}
|
|
29
110
|
}
|
|
30
111
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
--bf-range-font: var(--bf-theme-font-family, inherit);
|
|
3
|
+
--bf-range-track: var(--bf-theme-surface-2, #e2e8f0);
|
|
4
|
+
--bf-range-fill: var(--bf-theme-button-primary-bg, #2563eb);
|
|
5
|
+
--bf-range-rating-active: var(--bf-theme-button-primary-bg, #2563eb);
|
|
6
|
+
--bf-range-rating-muted: var(--bf-theme-border-1, #cbd5e1);
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
font: var(--bf-range-font);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.root {
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
gap: 0.4rem;
|
|
15
|
+
min-width: 12rem;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.single,
|
|
19
|
+
.dual,
|
|
20
|
+
.rating {
|
|
21
|
+
display: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.root[data-mode='slider'] .single {
|
|
25
|
+
display: block;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.root[data-mode='range'] .dual {
|
|
29
|
+
display: block;
|
|
30
|
+
position: relative;
|
|
31
|
+
padding-block: 0.35rem;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.root[data-mode='rating'] .rating {
|
|
35
|
+
display: inline-flex;
|
|
36
|
+
gap: 0.25rem;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
input[type='range'] {
|
|
40
|
+
width: 100%;
|
|
41
|
+
accent-color: var(--bf-range-fill);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.dual-track {
|
|
45
|
+
position: absolute;
|
|
46
|
+
inset: 50% 0 auto;
|
|
47
|
+
height: 0.35rem;
|
|
48
|
+
transform: translateY(-50%);
|
|
49
|
+
background: var(--bf-range-track);
|
|
50
|
+
border-radius: 999px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.dual-fill {
|
|
54
|
+
position: absolute;
|
|
55
|
+
height: 100%;
|
|
56
|
+
background: var(--bf-range-fill);
|
|
57
|
+
border-radius: inherit;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.dual input[type='range'] {
|
|
61
|
+
position: absolute;
|
|
62
|
+
left: 0;
|
|
63
|
+
right: 0;
|
|
64
|
+
top: 50%;
|
|
65
|
+
transform: translateY(-50%);
|
|
66
|
+
background: transparent;
|
|
67
|
+
pointer-events: none;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.dual input[type='range']::-webkit-slider-thumb {
|
|
71
|
+
pointer-events: auto;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.dual input[type='range']::-moz-range-thumb {
|
|
75
|
+
pointer-events: auto;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.star {
|
|
79
|
+
border: 0;
|
|
80
|
+
background: transparent;
|
|
81
|
+
color: var(--bf-range-rating-muted);
|
|
82
|
+
font: inherit;
|
|
83
|
+
font-size: 1.1rem;
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
padding: 0;
|
|
86
|
+
line-height: 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.star.is-active {
|
|
90
|
+
color: var(--bf-range-rating-active);
|
|
91
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
class BfRange extends HTMLElement {
|
|
2
|
+
static observedAttributes = [
|
|
3
|
+
'mode',
|
|
4
|
+
'slider',
|
|
5
|
+
'range',
|
|
6
|
+
'rating',
|
|
7
|
+
'value',
|
|
8
|
+
'low',
|
|
9
|
+
'high',
|
|
10
|
+
'min',
|
|
11
|
+
'max',
|
|
12
|
+
'step',
|
|
13
|
+
'count',
|
|
14
|
+
'disabled',
|
|
15
|
+
'label',
|
|
16
|
+
'name',
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
this.attachShadow({ mode: 'open' });
|
|
22
|
+
this._onSingleInput = this._onSingleInput.bind(this);
|
|
23
|
+
this._onRangeInput = this._onRangeInput.bind(this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
connectedCallback() {
|
|
27
|
+
if (this._initialized) {
|
|
28
|
+
this._sync();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this._initialized = true;
|
|
32
|
+
|
|
33
|
+
const cssUrl = new URL('./range.css', import.meta.url);
|
|
34
|
+
const link = document.createElement('link');
|
|
35
|
+
link.rel = 'stylesheet';
|
|
36
|
+
link.href = cssUrl.href;
|
|
37
|
+
|
|
38
|
+
const root = document.createElement('div');
|
|
39
|
+
root.className = 'root';
|
|
40
|
+
root.setAttribute('part', 'root');
|
|
41
|
+
root.innerHTML = `
|
|
42
|
+
<div class="single" part="single">
|
|
43
|
+
<input class="single-input" type="range" part="input" />
|
|
44
|
+
</div>
|
|
45
|
+
<div class="dual" part="dual">
|
|
46
|
+
<div class="dual-track" part="track">
|
|
47
|
+
<div class="dual-fill" part="fill"></div>
|
|
48
|
+
</div>
|
|
49
|
+
<input class="dual-low" type="range" part="low" />
|
|
50
|
+
<input class="dual-high" type="range" part="high" />
|
|
51
|
+
</div>
|
|
52
|
+
<div class="rating" part="rating"></div>
|
|
53
|
+
<div class="meta" part="meta"><slot></slot></div>
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
this.shadowRoot.replaceChildren(link, root);
|
|
57
|
+
this._root = root;
|
|
58
|
+
this._single = root.querySelector('.single-input');
|
|
59
|
+
this._dualLow = root.querySelector('.dual-low');
|
|
60
|
+
this._dualHigh = root.querySelector('.dual-high');
|
|
61
|
+
this._dualFill = root.querySelector('.dual-fill');
|
|
62
|
+
this._rating = root.querySelector('.rating');
|
|
63
|
+
|
|
64
|
+
this._single.addEventListener('input', this._onSingleInput);
|
|
65
|
+
this._single.addEventListener('change', this._onSingleInput);
|
|
66
|
+
this._dualLow.addEventListener('input', this._onRangeInput);
|
|
67
|
+
this._dualLow.addEventListener('change', this._onRangeInput);
|
|
68
|
+
this._dualHigh.addEventListener('input', this._onRangeInput);
|
|
69
|
+
this._dualHigh.addEventListener('change', this._onRangeInput);
|
|
70
|
+
|
|
71
|
+
this._sync();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
attributeChangedCallback() {
|
|
75
|
+
this._sync();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_mode() {
|
|
79
|
+
const explicit = (this.getAttribute('mode') || '').toLowerCase();
|
|
80
|
+
if (['slider', 'range', 'rating'].includes(explicit)) {
|
|
81
|
+
return explicit;
|
|
82
|
+
}
|
|
83
|
+
if (this.hasAttribute('rating')) {
|
|
84
|
+
return 'rating';
|
|
85
|
+
}
|
|
86
|
+
if (this.hasAttribute('range')) {
|
|
87
|
+
return 'range';
|
|
88
|
+
}
|
|
89
|
+
return 'slider';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_min() {
|
|
93
|
+
const parsed = Number.parseFloat(this.getAttribute('min') || '0');
|
|
94
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_max() {
|
|
98
|
+
const parsed = Number.parseFloat(this.getAttribute('max') || '100');
|
|
99
|
+
return Number.isFinite(parsed) && parsed > this._min() ? parsed : this._min() + 100;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
_step() {
|
|
103
|
+
const parsed = Number.parseFloat(this.getAttribute('step') || '1');
|
|
104
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_parseValue(attrName, fallback) {
|
|
108
|
+
const parsed = Number.parseFloat(this.getAttribute(attrName) || `${fallback}`);
|
|
109
|
+
if (!Number.isFinite(parsed)) {
|
|
110
|
+
return fallback;
|
|
111
|
+
}
|
|
112
|
+
return Math.min(this._max(), Math.max(this._min(), parsed));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_count() {
|
|
116
|
+
const parsed = Number.parseInt(this.getAttribute('count') || '5', 10);
|
|
117
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 5;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
_setValueAttr(attrName, value) {
|
|
121
|
+
const next = `${value}`;
|
|
122
|
+
if (this.getAttribute(attrName) === next) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.setAttribute(attrName, next);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_emit(kind) {
|
|
129
|
+
const mode = this._mode();
|
|
130
|
+
this.dispatchEvent(
|
|
131
|
+
new CustomEvent(kind, {
|
|
132
|
+
bubbles: true,
|
|
133
|
+
composed: true,
|
|
134
|
+
detail: {
|
|
135
|
+
mode,
|
|
136
|
+
value: mode === 'range'
|
|
137
|
+
? [this._parseValue('low', this._min()), this._parseValue('high', this._max())]
|
|
138
|
+
: this._parseValue('value', this._min()),
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
_onSingleInput(event) {
|
|
145
|
+
this._setValueAttr('value', event.target.value);
|
|
146
|
+
this._emit(event.type === 'change' ? 'bf-change' : 'bf-input');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
_onRangeInput(event) {
|
|
150
|
+
let low = this._parseValue('low', this._min());
|
|
151
|
+
let high = this._parseValue('high', this._max());
|
|
152
|
+
const next = Number.parseFloat(event.target.value);
|
|
153
|
+
|
|
154
|
+
if (event.target === this._dualLow) {
|
|
155
|
+
low = Math.min(next, high);
|
|
156
|
+
} else {
|
|
157
|
+
high = Math.max(next, low);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this._setValueAttr('low', low);
|
|
161
|
+
this._setValueAttr('high', high);
|
|
162
|
+
this._sync();
|
|
163
|
+
this._emit(event.type === 'change' ? 'bf-change' : 'bf-input');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_renderRating() {
|
|
167
|
+
this._rating.replaceChildren();
|
|
168
|
+
const count = this._count();
|
|
169
|
+
const current = this._parseValue('value', 0);
|
|
170
|
+
const disabled = this.hasAttribute('disabled');
|
|
171
|
+
|
|
172
|
+
for (let i = 1; i <= count; i += 1) {
|
|
173
|
+
const button = document.createElement('button');
|
|
174
|
+
button.type = 'button';
|
|
175
|
+
button.className = 'star';
|
|
176
|
+
button.textContent = '*';
|
|
177
|
+
button.disabled = disabled;
|
|
178
|
+
button.setAttribute('aria-label', `${i}`);
|
|
179
|
+
if (i <= current) {
|
|
180
|
+
button.classList.add('is-active');
|
|
181
|
+
}
|
|
182
|
+
button.addEventListener('click', () => {
|
|
183
|
+
this._setValueAttr('value', i);
|
|
184
|
+
this._sync();
|
|
185
|
+
this._emit('bf-change');
|
|
186
|
+
});
|
|
187
|
+
this._rating.append(button);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
_syncDualFill() {
|
|
192
|
+
const min = this._min();
|
|
193
|
+
const max = this._max();
|
|
194
|
+
const low = this._parseValue('low', min);
|
|
195
|
+
const high = this._parseValue('high', max);
|
|
196
|
+
const left = ((low - min) / (max - min)) * 100;
|
|
197
|
+
const width = ((high - low) / (max - min)) * 100;
|
|
198
|
+
this._dualFill.style.left = `${left}%`;
|
|
199
|
+
this._dualFill.style.width = `${width}%`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
_sync() {
|
|
203
|
+
if (!this._root) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const mode = this._mode();
|
|
208
|
+
const min = this._min();
|
|
209
|
+
const max = this._max();
|
|
210
|
+
const step = this._step();
|
|
211
|
+
const disabled = this.hasAttribute('disabled');
|
|
212
|
+
const label = this.getAttribute('label') || '';
|
|
213
|
+
const name = this.getAttribute('name') || '';
|
|
214
|
+
|
|
215
|
+
this._root.setAttribute('data-mode', mode);
|
|
216
|
+
|
|
217
|
+
this._single.min = `${min}`;
|
|
218
|
+
this._single.max = `${max}`;
|
|
219
|
+
this._single.step = `${step}`;
|
|
220
|
+
this._single.value = `${this._parseValue('value', min)}`;
|
|
221
|
+
this._single.disabled = disabled;
|
|
222
|
+
this._single.name = name;
|
|
223
|
+
|
|
224
|
+
this._dualLow.min = `${min}`;
|
|
225
|
+
this._dualLow.max = `${max}`;
|
|
226
|
+
this._dualLow.step = `${step}`;
|
|
227
|
+
this._dualLow.value = `${this._parseValue('low', min)}`;
|
|
228
|
+
this._dualLow.disabled = disabled;
|
|
229
|
+
this._dualLow.name = `${name ? `${name}-` : ''}low`;
|
|
230
|
+
|
|
231
|
+
this._dualHigh.min = `${min}`;
|
|
232
|
+
this._dualHigh.max = `${max}`;
|
|
233
|
+
this._dualHigh.step = `${step}`;
|
|
234
|
+
this._dualHigh.value = `${this._parseValue('high', max)}`;
|
|
235
|
+
this._dualHigh.disabled = disabled;
|
|
236
|
+
this._dualHigh.name = `${name ? `${name}-` : ''}high`;
|
|
237
|
+
|
|
238
|
+
this._syncDualFill();
|
|
239
|
+
this._renderRating();
|
|
240
|
+
|
|
241
|
+
if (label) {
|
|
242
|
+
this._single.setAttribute('aria-label', label);
|
|
243
|
+
this._dualLow.setAttribute('aria-label', `${label} low`);
|
|
244
|
+
this._dualHigh.setAttribute('aria-label', `${label} high`);
|
|
245
|
+
this._rating.setAttribute('aria-label', label);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
customElements.define('bf-range', BfRange);
|
|
@@ -19,12 +19,46 @@
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
.root {
|
|
22
|
+
position: relative;
|
|
22
23
|
background: var(--bf-select-bg);
|
|
23
24
|
color: var(--bf-select-color);
|
|
24
25
|
border-width: var(--bf-select-border-width);
|
|
25
26
|
border-style: var(--bf-select-border-style);
|
|
26
27
|
border-color: var(--bf-select-border-color);
|
|
27
28
|
border-radius: var(--bf-select-radius);
|
|
28
|
-
padding: var(--bf-select-padding-y) var(--bf-select-padding-x);
|
|
29
29
|
transition: var(--bf-select-transition);
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
select {
|
|
33
|
+
appearance: none;
|
|
34
|
+
-webkit-appearance: none;
|
|
35
|
+
width: 100%;
|
|
36
|
+
border: 0;
|
|
37
|
+
outline: 0;
|
|
38
|
+
background: transparent;
|
|
39
|
+
color: inherit;
|
|
40
|
+
font: inherit;
|
|
41
|
+
padding: var(--bf-select-padding-y) calc(var(--bf-select-padding-x) * 2.1)
|
|
42
|
+
var(--bf-select-padding-y) var(--bf-select-padding-x);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.root.is-multi select {
|
|
46
|
+
padding-right: var(--bf-select-padding-x);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.chevron {
|
|
50
|
+
position: absolute;
|
|
51
|
+
top: 50%;
|
|
52
|
+
right: var(--bf-select-padding-x);
|
|
53
|
+
width: 0.6rem;
|
|
54
|
+
height: 0.6rem;
|
|
55
|
+
transform: translateY(-60%) rotate(45deg);
|
|
56
|
+
border-right: 2px solid currentColor;
|
|
57
|
+
border-bottom: 2px solid currentColor;
|
|
58
|
+
opacity: 0.7;
|
|
59
|
+
pointer-events: none;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.root.is-multi .chevron {
|
|
63
|
+
display: none;
|
|
64
|
+
}
|