@sebgroup/green-core 1.15.1 → 1.17.0
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 +101 -7
- package/chunks/chunk.2LQSDOD4.js +29 -0
- package/chunks/chunk.2ND5EWHE.js +65 -0
- package/chunks/chunk.2OOTOCUG.js +420 -0
- package/chunks/chunk.2WO4NHJ2.js +34 -0
- package/chunks/chunk.2Y3BHFKO.js +154 -0
- package/chunks/chunk.375BWME4.js +29 -0
- package/chunks/chunk.5VURDMKE.js +75 -0
- package/chunks/chunk.63RKNI5K.js +244 -0
- package/chunks/chunk.6NM7ENKA.js +31 -0
- package/chunks/chunk.6UA66KQU.js +153 -0
- package/chunks/chunk.7TCXY7BP.js +0 -0
- package/chunks/chunk.AQGTMWG4.js +101 -0
- package/chunks/chunk.D7H7CUS4.js +55 -0
- package/chunks/chunk.DFYMYEGD.js +78 -0
- package/chunks/chunk.EUQ5DOQM.js +560 -0
- package/chunks/chunk.HS7ICQNA.js +0 -0
- package/chunks/chunk.IYCENQZG.js +28 -0
- package/chunks/chunk.KC32OWZE.js +274 -0
- package/chunks/chunk.LUHCF4BJ.js +64 -0
- package/chunks/chunk.MAD5DQMN.js +161 -0
- package/chunks/chunk.MI4A2C2A.js +0 -0
- package/chunks/chunk.Q2T57HE7.js +0 -0
- package/chunks/chunk.QONSFT2N.js +4653 -0
- package/chunks/chunk.TMBQL2RO.js +0 -0
- package/chunks/chunk.TN6ZYAH3.js +74 -0
- package/chunks/chunk.TSDZQZBY.js +0 -0
- package/chunks/chunk.TX64TTBN.js +0 -0
- package/chunks/chunk.U4DPJ4QU.js +96 -0
- package/chunks/chunk.UF6IEONX.js +0 -0
- package/chunks/chunk.VOYMQ322.js +61 -0
- package/chunks/chunk.VYK7D6QO.js +64 -0
- package/chunks/chunk.WDZ2JTCP.js +360 -0
- package/chunks/chunk.WJDR7FTS.js +193 -0
- package/chunks/chunk.WM7HBMMV.js +54 -0
- package/chunks/chunk.XD5R3ZU3.js +460 -0
- package/chunks/chunk.XHTJVQUJ.js +140 -0
- package/chunks/chunk.XI4H54TV.js +39 -0
- package/chunks/chunk.XMPBXAGB.js +80 -0
- package/chunks/chunk.XU4HZLJL.js +0 -0
- package/chunks/chunk.YIQIH4RW.js +139 -0
- package/chunks/chunk.YJHAKLGR.js +54 -0
- package/chunks/chunk.YO24ZYAD.js +0 -0
- package/chunks/chunk.ZTE73BY2.js +655 -0
- package/chunks/chunk.ZYQWZMVY.js +467 -0
- package/components/badge/badge.js +245 -0
- package/components/button/button.d.ts +5 -5
- package/components/button/button.js +18 -0
- package/components/button/button.trans.styles.d.ts +2 -0
- package/components/button/index.d.ts +1 -0
- package/components/button/index.js +18 -0
- package/components/checkbox/checkbox.js +219 -0
- package/components/context-menu/context-menu.d.ts +2 -1
- package/components/context-menu/context-menu.js +22 -0
- package/components/context-menu/index.d.ts +3 -0
- package/components/context-menu/index.js +29 -0
- package/components/datepicker/date-part-spinner.js +10 -0
- package/components/datepicker/datepicker.d.ts +3 -2
- package/components/datepicker/datepicker.js +29 -0
- package/components/datepicker/index.d.ts +1 -0
- package/components/datepicker/index.js +29 -0
- package/components/dropdown/dropdown.d.ts +2 -2
- package/components/dropdown/dropdown.js +22 -0
- package/components/dropdown/index.d.ts +3 -0
- package/components/dropdown/index.js +30 -0
- package/components/form-control.js +12 -0
- package/components/grid/grid.d.ts +2 -2
- package/components/grid/grid.js +11 -0
- package/components/grid/grid.style.css.js +7 -0
- package/components/grid/index.d.ts +1 -0
- package/components/grid/index.js +11 -0
- package/components/grouped-list/grouped-list.js +14 -0
- package/components/grouped-list/index.d.ts +2 -0
- package/components/grouped-list/index.js +17 -0
- package/components/grouped-list/list-item.js +10 -0
- package/components/icon/icon.d.ts +2 -2
- package/components/icon/icon.js +10 -0
- package/components/icon/index.d.ts +1 -0
- package/components/icon/index.js +10 -0
- package/components/index.d.ts +4 -3
- package/components/index.js +81 -0
- package/components/input/input.js +682 -0
- package/components/radio/radio-group.js +9 -0
- package/components/radio/radio.js +240 -0
- package/components/segmented-control/index.d.ts +1 -0
- package/components/segmented-control/index.js +15 -0
- package/components/segmented-control/segment/index.d.ts +1 -0
- package/components/segmented-control/segment/index.js +13 -0
- package/components/segmented-control/segment/segment.js +12 -0
- package/components/segmented-control/segmented-control.d.ts +1 -1
- package/components/segmented-control/segmented-control.js +15 -0
- package/components/switch/switch.js +164 -0
- package/components/theme/index.d.ts +1 -0
- package/components/theme/index.js +11 -0
- package/components/theme/theme.js +11 -0
- package/components/tooltip/tooltip.js +252 -0
- package/index.js +72 -4291
- package/localization.js +3 -5
- package/package.json +7 -16
- package/primitives/calendar/calendar.js +13 -0
- package/primitives/calendar/functions.js +7 -0
- package/primitives/calendar/index.d.ts +1 -0
- package/primitives/calendar/index.js +14 -0
- package/primitives/listbox/index.d.ts +0 -1
- package/primitives/listbox/index.js +17 -0
- package/primitives/listbox/listbox.d.ts +2 -1
- package/primitives/listbox/listbox.js +16 -0
- package/primitives/listbox/option.js +14 -0
- package/primitives/menu/index.d.ts +1 -0
- package/primitives/menu/index.js +15 -0
- package/primitives/menu/menu-heading.js +11 -0
- package/primitives/menu/menu-item.d.ts +1 -2
- package/primitives/menu/menu-item.js +12 -0
- package/primitives/menu/menu.d.ts +2 -1
- package/primitives/menu/menu.js +14 -0
- package/primitives/popover/index.js +14 -0
- package/primitives/popover/popover.js +13 -0
- package/primitives/ripple/index.d.ts +1 -0
- package/primitives/ripple/index.js +11 -0
- package/primitives/ripple/ripple.d.ts +1 -1
- package/primitives/ripple/ripple.js +10 -0
- package/scoping.d.ts +1 -0
- package/scoping.js +18 -0
- package/transitional-styles.js +6 -4275
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
watch
|
|
3
|
+
} from "./chunk.2WO4NHJ2.js";
|
|
4
|
+
import {
|
|
5
|
+
gdsCustomElement,
|
|
6
|
+
html
|
|
7
|
+
} from "./chunk.VOYMQ322.js";
|
|
8
|
+
import {
|
|
9
|
+
__decorateClass,
|
|
10
|
+
__privateAdd,
|
|
11
|
+
__privateGet,
|
|
12
|
+
__privateMethod,
|
|
13
|
+
__privateSet
|
|
14
|
+
} from "./chunk.5VURDMKE.js";
|
|
15
|
+
|
|
16
|
+
// libs/core/src/components/datepicker/date-part-spinner.ts
|
|
17
|
+
import { LitElement } from "lit";
|
|
18
|
+
import { property, state } from "lit/decorators.js";
|
|
19
|
+
var _inputBuffer, _increment, _decrement, _handleClick, _handleFocus, _handleBlur, _handleWheel, _handleKeyDown, _focusNextSpinner, focusNextSpinner_fn, _dispatchChangeEvent, dispatchChangeEvent_fn, _formatNumber, formatNumber_fn, _clamp, clamp_fn, _clearInputBuffer, clearInputBuffer_fn;
|
|
20
|
+
var GdsDatePartSpinner = class extends LitElement {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(...arguments);
|
|
23
|
+
__privateAdd(this, _focusNextSpinner);
|
|
24
|
+
__privateAdd(this, _dispatchChangeEvent);
|
|
25
|
+
__privateAdd(this, _formatNumber);
|
|
26
|
+
__privateAdd(this, _clamp);
|
|
27
|
+
__privateAdd(this, _clearInputBuffer);
|
|
28
|
+
this.value = 0;
|
|
29
|
+
this.length = 2;
|
|
30
|
+
this.min = 0;
|
|
31
|
+
this.max = Number.MAX_SAFE_INTEGER;
|
|
32
|
+
this.displayValue = __privateMethod(this, _formatNumber, formatNumber_fn).call(this, this.value, this.length);
|
|
33
|
+
__privateAdd(this, _inputBuffer, "");
|
|
34
|
+
__privateAdd(this, _increment, () => {
|
|
35
|
+
let current = parseInt(this.value.toString());
|
|
36
|
+
if (Number.isNaN(current))
|
|
37
|
+
current = this.length === 2 ? this.min : (/* @__PURE__ */ new Date()).getFullYear() - 1;
|
|
38
|
+
this.value = __privateMethod(this, _clamp, clamp_fn).call(this, current + 1);
|
|
39
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
40
|
+
});
|
|
41
|
+
__privateAdd(this, _decrement, () => {
|
|
42
|
+
let current = parseInt(this.value.toString());
|
|
43
|
+
if (Number.isNaN(current))
|
|
44
|
+
current = this.length === 2 ? this.max : (/* @__PURE__ */ new Date()).getFullYear() + 1;
|
|
45
|
+
this.value = __privateMethod(this, _clamp, clamp_fn).call(this, current - 1);
|
|
46
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
47
|
+
});
|
|
48
|
+
__privateAdd(this, _handleClick, (e) => {
|
|
49
|
+
e.stopPropagation();
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
this.focus();
|
|
52
|
+
});
|
|
53
|
+
__privateAdd(this, _handleFocus, () => {
|
|
54
|
+
__privateMethod(this, _clearInputBuffer, clearInputBuffer_fn).call(this);
|
|
55
|
+
});
|
|
56
|
+
__privateAdd(this, _handleBlur, () => {
|
|
57
|
+
if (__privateGet(this, _inputBuffer) === "")
|
|
58
|
+
return;
|
|
59
|
+
__privateMethod(this, _clearInputBuffer, clearInputBuffer_fn).call(this);
|
|
60
|
+
this.value = __privateMethod(this, _clamp, clamp_fn).call(this, parseInt(this.value.toString()));
|
|
61
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
62
|
+
});
|
|
63
|
+
__privateAdd(this, _handleWheel, (e) => {
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
if (e.deltaY > 0) {
|
|
67
|
+
__privateGet(this, _decrement).call(this);
|
|
68
|
+
} else {
|
|
69
|
+
__privateGet(this, _increment).call(this);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
__privateAdd(this, _handleKeyDown, (e) => {
|
|
73
|
+
let handled = false;
|
|
74
|
+
if (e.key === "ArrowUp") {
|
|
75
|
+
__privateGet(this, _increment).call(this);
|
|
76
|
+
handled = true;
|
|
77
|
+
} else if (e.key === "ArrowDown") {
|
|
78
|
+
__privateGet(this, _decrement).call(this);
|
|
79
|
+
handled = true;
|
|
80
|
+
} else {
|
|
81
|
+
const key = parseInt(e.key);
|
|
82
|
+
if (!isNaN(key)) {
|
|
83
|
+
if (__privateGet(this, _inputBuffer).length < this.length) {
|
|
84
|
+
__privateSet(this, _inputBuffer, __privateGet(this, _inputBuffer) + key.toString());
|
|
85
|
+
this.value = parseInt(__privateGet(this, _inputBuffer));
|
|
86
|
+
}
|
|
87
|
+
if (__privateGet(this, _inputBuffer).length === this.length) {
|
|
88
|
+
this.value = __privateMethod(this, _clamp, clamp_fn).call(this, this.value);
|
|
89
|
+
__privateMethod(this, _clearInputBuffer, clearInputBuffer_fn).call(this);
|
|
90
|
+
__privateMethod(this, _focusNextSpinner, focusNextSpinner_fn).call(this);
|
|
91
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
92
|
+
}
|
|
93
|
+
handled = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (handled) {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
e.stopPropagation();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// No need for a shadow root here
|
|
103
|
+
createRenderRoot() {
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
connectedCallback() {
|
|
107
|
+
super.connectedCallback();
|
|
108
|
+
this.setAttribute("role", "spinbutton");
|
|
109
|
+
this.setAttribute("tabindex", "0");
|
|
110
|
+
this.addEventListener("wheel", __privateGet(this, _handleWheel));
|
|
111
|
+
this.addEventListener("keydown", __privateGet(this, _handleKeyDown));
|
|
112
|
+
this.addEventListener("blur", __privateGet(this, _handleBlur));
|
|
113
|
+
this.addEventListener("focus", __privateGet(this, _handleFocus));
|
|
114
|
+
this.addEventListener("click", __privateGet(this, _handleClick));
|
|
115
|
+
this.addEventListener("mousedown", __privateGet(this, _handleClick));
|
|
116
|
+
}
|
|
117
|
+
focus(options) {
|
|
118
|
+
super.focus(options);
|
|
119
|
+
__privateGet(this, _handleFocus).call(this);
|
|
120
|
+
}
|
|
121
|
+
render() {
|
|
122
|
+
return html`${this.displayValue}`;
|
|
123
|
+
}
|
|
124
|
+
_refreshDisplayValue() {
|
|
125
|
+
this.displayValue = __privateMethod(this, _formatNumber, formatNumber_fn).call(this, this.value, this.length);
|
|
126
|
+
this.setAttribute("aria-valuetext", this.value.toString());
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
_inputBuffer = new WeakMap();
|
|
130
|
+
_increment = new WeakMap();
|
|
131
|
+
_decrement = new WeakMap();
|
|
132
|
+
_handleClick = new WeakMap();
|
|
133
|
+
_handleFocus = new WeakMap();
|
|
134
|
+
_handleBlur = new WeakMap();
|
|
135
|
+
_handleWheel = new WeakMap();
|
|
136
|
+
_handleKeyDown = new WeakMap();
|
|
137
|
+
_focusNextSpinner = new WeakSet();
|
|
138
|
+
focusNextSpinner_fn = function() {
|
|
139
|
+
let nextSpinner = this.nextElementSibling;
|
|
140
|
+
while (nextSpinner) {
|
|
141
|
+
if (nextSpinner instanceof GdsDatePartSpinner) {
|
|
142
|
+
nextSpinner.focus();
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
nextSpinner = nextSpinner.nextElementSibling;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
_dispatchChangeEvent = new WeakSet();
|
|
149
|
+
dispatchChangeEvent_fn = function() {
|
|
150
|
+
this.dispatchEvent(
|
|
151
|
+
new CustomEvent("change", {
|
|
152
|
+
detail: { value: this.value.toString() }
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
_formatNumber = new WeakSet();
|
|
157
|
+
formatNumber_fn = function(num, padZeros) {
|
|
158
|
+
return String(num).padStart(padZeros, "0");
|
|
159
|
+
};
|
|
160
|
+
_clamp = new WeakSet();
|
|
161
|
+
clamp_fn = function(value) {
|
|
162
|
+
return Math.max(this.min, Math.min(this.max, value));
|
|
163
|
+
};
|
|
164
|
+
_clearInputBuffer = new WeakSet();
|
|
165
|
+
clearInputBuffer_fn = function() {
|
|
166
|
+
__privateSet(this, _inputBuffer, "");
|
|
167
|
+
};
|
|
168
|
+
GdsDatePartSpinner.formAssociated = true;
|
|
169
|
+
__decorateClass([
|
|
170
|
+
property({ type: Number })
|
|
171
|
+
], GdsDatePartSpinner.prototype, "value", 2);
|
|
172
|
+
__decorateClass([
|
|
173
|
+
property({ type: Number })
|
|
174
|
+
], GdsDatePartSpinner.prototype, "length", 2);
|
|
175
|
+
__decorateClass([
|
|
176
|
+
property({ type: Number, attribute: "aria-valuemin" })
|
|
177
|
+
], GdsDatePartSpinner.prototype, "min", 2);
|
|
178
|
+
__decorateClass([
|
|
179
|
+
property({ type: Number, attribute: "aria-valuemax" })
|
|
180
|
+
], GdsDatePartSpinner.prototype, "max", 2);
|
|
181
|
+
__decorateClass([
|
|
182
|
+
state()
|
|
183
|
+
], GdsDatePartSpinner.prototype, "displayValue", 2);
|
|
184
|
+
__decorateClass([
|
|
185
|
+
watch("value")
|
|
186
|
+
], GdsDatePartSpinner.prototype, "_refreshDisplayValue", 1);
|
|
187
|
+
GdsDatePartSpinner = __decorateClass([
|
|
188
|
+
gdsCustomElement("gds-date-part-spinner")
|
|
189
|
+
], GdsDatePartSpinner);
|
|
190
|
+
|
|
191
|
+
export {
|
|
192
|
+
GdsDatePartSpinner
|
|
193
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// libs/core/src/utils/decorators/observe-light-dom.ts
|
|
2
|
+
function observeLightDOM(observerConfig = {
|
|
3
|
+
attributes: true,
|
|
4
|
+
childList: true,
|
|
5
|
+
subtree: false,
|
|
6
|
+
characterData: true
|
|
7
|
+
}) {
|
|
8
|
+
return (proto, _propertyKey, descriptor) => {
|
|
9
|
+
let observer;
|
|
10
|
+
const connectedCallback = proto.connectedCallback;
|
|
11
|
+
const disconnectedCallback = proto.disconnectedCallback;
|
|
12
|
+
proto.connectedCallback = function() {
|
|
13
|
+
connectedCallback == null ? void 0 : connectedCallback.call(this);
|
|
14
|
+
const callback = (_mutationList, _observer) => {
|
|
15
|
+
var _a;
|
|
16
|
+
(_a = descriptor.value) == null ? void 0 : _a.call(this);
|
|
17
|
+
};
|
|
18
|
+
observer = new MutationObserver(callback);
|
|
19
|
+
observer.observe(this, observerConfig);
|
|
20
|
+
};
|
|
21
|
+
proto.disconnectedCallback = function() {
|
|
22
|
+
disconnectedCallback == null ? void 0 : disconnectedCallback.call(this);
|
|
23
|
+
observer.disconnect();
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// libs/core/src/utils/decorators/watch-media-query.ts
|
|
29
|
+
function watchMediaQuery(q) {
|
|
30
|
+
return (proto, _propertyKey, descriptor) => {
|
|
31
|
+
const mediaQuery = window.matchMedia(q);
|
|
32
|
+
const connectedCallback = proto.connectedCallback;
|
|
33
|
+
const disconnectedCallback = proto.disconnectedCallback;
|
|
34
|
+
proto.connectedCallback = function() {
|
|
35
|
+
var _a;
|
|
36
|
+
connectedCallback == null ? void 0 : connectedCallback.call(this);
|
|
37
|
+
const listener = (e) => {
|
|
38
|
+
var _a2;
|
|
39
|
+
(_a2 = descriptor.value) == null ? void 0 : _a2.call(this, e.matches);
|
|
40
|
+
};
|
|
41
|
+
mediaQuery.addEventListener("change", listener);
|
|
42
|
+
this.disconnectedCallback = function() {
|
|
43
|
+
disconnectedCallback == null ? void 0 : disconnectedCallback.call(this);
|
|
44
|
+
mediaQuery.removeEventListener("change", listener);
|
|
45
|
+
};
|
|
46
|
+
(_a = descriptor.value) == null ? void 0 : _a.call(this, mediaQuery.matches);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
observeLightDOM,
|
|
53
|
+
watchMediaQuery
|
|
54
|
+
};
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GdsSegment
|
|
3
|
+
} from "./chunk.U4DPJ4QU.js";
|
|
4
|
+
import {
|
|
5
|
+
tokens
|
|
6
|
+
} from "./chunk.EUQ5DOQM.js";
|
|
7
|
+
import {
|
|
8
|
+
TransitionalStyles
|
|
9
|
+
} from "./chunk.QONSFT2N.js";
|
|
10
|
+
import {
|
|
11
|
+
GdsElement
|
|
12
|
+
} from "./chunk.2LQSDOD4.js";
|
|
13
|
+
import {
|
|
14
|
+
watch
|
|
15
|
+
} from "./chunk.2WO4NHJ2.js";
|
|
16
|
+
import {
|
|
17
|
+
gdsCustomElement,
|
|
18
|
+
html
|
|
19
|
+
} from "./chunk.VOYMQ322.js";
|
|
20
|
+
import {
|
|
21
|
+
__decorateClass,
|
|
22
|
+
__privateAdd,
|
|
23
|
+
__privateGet,
|
|
24
|
+
__privateMethod,
|
|
25
|
+
__privateSet,
|
|
26
|
+
__privateWrapper
|
|
27
|
+
} from "./chunk.5VURDMKE.js";
|
|
28
|
+
|
|
29
|
+
// libs/core/src/components/segmented-control/segmented-control.ts
|
|
30
|
+
import { unsafeCSS } from "lit";
|
|
31
|
+
import { query, state, property } from "lit/decorators.js";
|
|
32
|
+
import { when } from "lit/directives/when.js";
|
|
33
|
+
import { msg } from "@lit/localize";
|
|
34
|
+
|
|
35
|
+
// libs/core/src/components/segmented-control/segmented-control.style.css
|
|
36
|
+
var segmented_control_style_default = `:host {
|
|
37
|
+
background-color: var(--gds-sys-color-container-container-dim1);
|
|
38
|
+
border: 0.25rem solid var(--gds-sys-color-container-container-dim1);
|
|
39
|
+
border-radius: calc(infinity * 1px);
|
|
40
|
+
box-sizing: border-box;
|
|
41
|
+
contain: layout;
|
|
42
|
+
display: inline-flex;
|
|
43
|
+
gap: 0.25rem;
|
|
44
|
+
height: 3rem;
|
|
45
|
+
max-width: 100%;
|
|
46
|
+
overflow: hidden;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
:host([size='small']) {
|
|
50
|
+
height: 2.5rem;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#track {
|
|
54
|
+
box-sizing: border-box;
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-grow: 0;
|
|
57
|
+
flex-shrink: 1;
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
position: relative;
|
|
60
|
+
width: 100%;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#segments {
|
|
64
|
+
box-sizing: border-box;
|
|
65
|
+
display: inline-flex;
|
|
66
|
+
gap: 0.25rem;
|
|
67
|
+
position: relative;
|
|
68
|
+
transition: 0.2s;
|
|
69
|
+
z-index: 1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#btn-prev,
|
|
73
|
+
#btn-next {
|
|
74
|
+
align-items: center;
|
|
75
|
+
-webkit-appearance: none;
|
|
76
|
+
-moz-appearance: none;
|
|
77
|
+
appearance: none;
|
|
78
|
+
aspect-ratio: 1;
|
|
79
|
+
background-color: var(--gds-sys-color-container-container-dim1);
|
|
80
|
+
border-radius: calc(infinity * 1px);
|
|
81
|
+
border-width: 0;
|
|
82
|
+
color: var(--gds-sys-color-content-content);
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
display: flex;
|
|
85
|
+
font-size: 1rem;
|
|
86
|
+
height: 100%;
|
|
87
|
+
justify-content: center;
|
|
88
|
+
width: 2.5rem;
|
|
89
|
+
|
|
90
|
+
@media (pointer: fine) {
|
|
91
|
+
&:hover {
|
|
92
|
+
background-color: color-mix(
|
|
93
|
+
in srgb,
|
|
94
|
+
var(--gds-sys-color-state-layers-state-black-dim1),
|
|
95
|
+
var(--gds-sys-color-container-container-dim1)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
:host([size='small']) #btn-prev,
|
|
102
|
+
:host([size='small']) #btn-next {
|
|
103
|
+
width: 2rem;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
::slotted(*) {
|
|
107
|
+
flex-grow: 1;
|
|
108
|
+
flex-shrink: 0;
|
|
109
|
+
z-index: 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#indicator {
|
|
113
|
+
background-color: var(--gds-sys-color-container-container-bright);
|
|
114
|
+
border-radius: calc(infinity * 1px);
|
|
115
|
+
height: 100%;
|
|
116
|
+
left: 0;
|
|
117
|
+
position: absolute;
|
|
118
|
+
transition:
|
|
119
|
+
transform 0.2s,
|
|
120
|
+
width 0.2s;
|
|
121
|
+
z-index: 0;
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
|
|
125
|
+
// libs/core/src/components/segmented-control/segmented-control.ts
|
|
126
|
+
var BTN_SIZE = {
|
|
127
|
+
small: 36,
|
|
128
|
+
medium: 44
|
|
129
|
+
};
|
|
130
|
+
var getSegmentGap = (transitionalStyles) => transitionalStyles ? 0 : 4;
|
|
131
|
+
var _value, _tid, _resizeObserver, _firstVisibleIndex, _calculatedSegmentWidth, _segmentWidth, _segmentsContainerLeft, _focusedIndex, _dragStartX, _dragStartLeft, _isDragging, _startDrag, _drag, _endDrag, _calcVisibleAfterDrag, _calcLayout, _applySegmentsTransform, _handleSlotChange, handleSlotChange_fn, _scrollLeft, _scrollRight, _updateScrollBtnState, _updateIndicator, _handleSegmentClick, _updateSelectedFromValue;
|
|
132
|
+
var GdsSegmentedControl = class extends GdsElement {
|
|
133
|
+
constructor() {
|
|
134
|
+
super(...arguments);
|
|
135
|
+
__privateAdd(this, _handleSlotChange);
|
|
136
|
+
this.segMinWidth = 100;
|
|
137
|
+
this.size = "medium";
|
|
138
|
+
__privateAdd(this, _value, void 0);
|
|
139
|
+
this._showPrevButton = false;
|
|
140
|
+
this._showNextButton = false;
|
|
141
|
+
__privateAdd(this, _tid, void 0);
|
|
142
|
+
__privateAdd(this, _resizeObserver, new ResizeObserver(() => {
|
|
143
|
+
__privateGet(this, _tid) && clearTimeout(__privateGet(this, _tid));
|
|
144
|
+
__privateSet(this, _tid, setTimeout(() => {
|
|
145
|
+
__privateGet(this, _calcLayout).call(this);
|
|
146
|
+
}, 20));
|
|
147
|
+
}));
|
|
148
|
+
__privateAdd(this, _firstVisibleIndex, 0);
|
|
149
|
+
__privateAdd(this, _calculatedSegmentWidth, 0);
|
|
150
|
+
__privateAdd(this, _segmentWidth, 0);
|
|
151
|
+
__privateAdd(this, _segmentsContainerLeft, 0);
|
|
152
|
+
__privateAdd(this, _focusedIndex, 0);
|
|
153
|
+
__privateAdd(this, _dragStartX, 0);
|
|
154
|
+
__privateAdd(this, _dragStartLeft, 0);
|
|
155
|
+
__privateAdd(this, _isDragging, false);
|
|
156
|
+
__privateAdd(this, _startDrag, (event) => {
|
|
157
|
+
__privateSet(this, _dragStartX, event.clientX);
|
|
158
|
+
__privateSet(this, _dragStartLeft, __privateGet(this, _segmentsContainerLeft));
|
|
159
|
+
__privateSet(this, _isDragging, true);
|
|
160
|
+
});
|
|
161
|
+
__privateAdd(this, _drag, (event) => {
|
|
162
|
+
if (!__privateGet(this, _isDragging))
|
|
163
|
+
return;
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
const delta = event.clientX - __privateGet(this, _dragStartX);
|
|
166
|
+
if (Math.abs(delta) < 5)
|
|
167
|
+
return;
|
|
168
|
+
try {
|
|
169
|
+
if (!this._elSegments.hasPointerCapture(event.pointerId))
|
|
170
|
+
this._elSegments.setPointerCapture(event.pointerId);
|
|
171
|
+
__privateSet(this, _segmentsContainerLeft, __privateGet(this, _dragStartLeft) + delta);
|
|
172
|
+
__privateGet(this, _applySegmentsTransform).call(this);
|
|
173
|
+
} catch (e) {
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
__privateAdd(this, _endDrag, (event) => {
|
|
177
|
+
if (!__privateGet(this, _isDragging))
|
|
178
|
+
return;
|
|
179
|
+
__privateSet(this, _isDragging, false);
|
|
180
|
+
try {
|
|
181
|
+
this._elSegments.releasePointerCapture(event.pointerId);
|
|
182
|
+
__privateGet(this, _calcVisibleAfterDrag).call(this);
|
|
183
|
+
} catch (e) {
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
__privateAdd(this, _calcVisibleAfterDrag, () => {
|
|
187
|
+
__privateSet(this, _firstVisibleIndex, Math.round(
|
|
188
|
+
-__privateGet(this, _segmentsContainerLeft) / __privateGet(this, _calculatedSegmentWidth)
|
|
189
|
+
));
|
|
190
|
+
__privateGet(this, _calcLayout).call(this);
|
|
191
|
+
});
|
|
192
|
+
// Calculates the layout based on the configured min width
|
|
193
|
+
// and the available space in the track
|
|
194
|
+
__privateAdd(this, _calcLayout, (followFocus = false) => {
|
|
195
|
+
const calcNumVisibleSegments = () => {
|
|
196
|
+
const numSegments = this.segments.length;
|
|
197
|
+
const availableWidth = this._elTrack.offsetWidth;
|
|
198
|
+
if (availableWidth / numSegments > this.segMinWidth) {
|
|
199
|
+
return {
|
|
200
|
+
count: numSegments,
|
|
201
|
+
segmentWidth: (availableWidth - getSegmentGap(this._isUsingTransitionalStyles) * (numSegments - 1)) / numSegments
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
const availableWidthIncBtns = this.offsetWidth - BTN_SIZE[this.size] * 2;
|
|
205
|
+
const maxVisibleSegments = Math.floor(
|
|
206
|
+
availableWidthIncBtns / this.segMinWidth
|
|
207
|
+
);
|
|
208
|
+
const segmentWidth = (availableWidth - getSegmentGap(this._isUsingTransitionalStyles) * (maxVisibleSegments - 1)) / maxVisibleSegments;
|
|
209
|
+
return {
|
|
210
|
+
count: maxVisibleSegments,
|
|
211
|
+
segmentWidth
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
const { count } = calcNumVisibleSegments();
|
|
215
|
+
if (followFocus) {
|
|
216
|
+
if (__privateGet(this, _focusedIndex) >= __privateGet(this, _firstVisibleIndex) + count) {
|
|
217
|
+
__privateSet(this, _firstVisibleIndex, __privateGet(this, _focusedIndex) - count + 1);
|
|
218
|
+
}
|
|
219
|
+
if (__privateGet(this, _focusedIndex) < __privateGet(this, _firstVisibleIndex)) {
|
|
220
|
+
__privateSet(this, _firstVisibleIndex, __privateGet(this, _focusedIndex));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const endFirstIndex = this.segments.length - count;
|
|
224
|
+
const hasReachedEnd = __privateGet(this, _firstVisibleIndex) >= endFirstIndex;
|
|
225
|
+
const isAtStart = __privateGet(this, _firstVisibleIndex) <= 0;
|
|
226
|
+
if (hasReachedEnd) {
|
|
227
|
+
__privateSet(this, _firstVisibleIndex, endFirstIndex);
|
|
228
|
+
}
|
|
229
|
+
if (isAtStart) {
|
|
230
|
+
__privateSet(this, _firstVisibleIndex, 0);
|
|
231
|
+
}
|
|
232
|
+
__privateGet(this, _updateScrollBtnState).call(this, count);
|
|
233
|
+
this.updateComplete.then(() => {
|
|
234
|
+
const { segmentWidth, count: count2 } = calcNumVisibleSegments();
|
|
235
|
+
this.segments.forEach((segment) => {
|
|
236
|
+
segment.style.width = segmentWidth + "px";
|
|
237
|
+
});
|
|
238
|
+
__privateSet(this, _segmentsContainerLeft, -__privateGet(this, _firstVisibleIndex) * segmentWidth - getSegmentGap(this._isUsingTransitionalStyles) * __privateGet(this, _firstVisibleIndex));
|
|
239
|
+
__privateGet(this, _applySegmentsTransform).call(this);
|
|
240
|
+
__privateSet(this, _calculatedSegmentWidth, segmentWidth);
|
|
241
|
+
__privateSet(this, _segmentWidth, segmentWidth);
|
|
242
|
+
__privateGet(this, _updateIndicator).call(this);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
__privateAdd(this, _applySegmentsTransform, () => {
|
|
246
|
+
window.requestAnimationFrame(() => {
|
|
247
|
+
this._elSegments.style.transform = `translateX(${__privateGet(this, _segmentsContainerLeft)}px)`;
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
__privateAdd(this, _scrollLeft, () => {
|
|
251
|
+
__privateWrapper(this, _firstVisibleIndex)._--;
|
|
252
|
+
__privateGet(this, _calcLayout).call(this);
|
|
253
|
+
});
|
|
254
|
+
__privateAdd(this, _scrollRight, () => {
|
|
255
|
+
__privateWrapper(this, _firstVisibleIndex)._++;
|
|
256
|
+
__privateGet(this, _calcLayout).call(this);
|
|
257
|
+
});
|
|
258
|
+
// Updates the visibility of the scroll buttons
|
|
259
|
+
__privateAdd(this, _updateScrollBtnState, (numVisibleSegments) => {
|
|
260
|
+
this._showPrevButton = __privateGet(this, _firstVisibleIndex) > 0;
|
|
261
|
+
this._showNextButton = __privateGet(this, _firstVisibleIndex) < this.segments.length - numVisibleSegments;
|
|
262
|
+
});
|
|
263
|
+
// Updates the selection indicator position
|
|
264
|
+
__privateAdd(this, _updateIndicator, () => {
|
|
265
|
+
const segment = this.segments.find((s) => s.selected);
|
|
266
|
+
if (segment) {
|
|
267
|
+
const selectedSegmentIndex = this.segments.indexOf(segment);
|
|
268
|
+
const offset = selectedSegmentIndex * __privateGet(this, _segmentWidth) + getSegmentGap(this._isUsingTransitionalStyles) * selectedSegmentIndex;
|
|
269
|
+
this._elIndicator.style.transform = `translateX(${offset}px)`;
|
|
270
|
+
this._elIndicator.style.width = `${__privateGet(this, _segmentWidth)}px`;
|
|
271
|
+
} else {
|
|
272
|
+
this._elIndicator.style.transform = `translateX(-100%)`;
|
|
273
|
+
this._elIndicator.style.width = `0px`;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
__privateAdd(this, _handleSegmentClick, (event) => {
|
|
277
|
+
const selectedSegment = this.segments.find(
|
|
278
|
+
(s) => s === event.target || s.contains(event.target)
|
|
279
|
+
);
|
|
280
|
+
if (selectedSegment) {
|
|
281
|
+
this.segments.forEach((s) => s.selected = false);
|
|
282
|
+
selectedSegment.selected = true;
|
|
283
|
+
__privateSet(this, _value, selectedSegment.value);
|
|
284
|
+
__privateGet(this, _updateIndicator).call(this);
|
|
285
|
+
this.dispatchEvent(
|
|
286
|
+
new CustomEvent("change", {
|
|
287
|
+
detail: { segment: selectedSegment },
|
|
288
|
+
bubbles: true,
|
|
289
|
+
composed: true
|
|
290
|
+
})
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
__privateAdd(this, _updateSelectedFromValue, () => {
|
|
295
|
+
if (!__privateGet(this, _value))
|
|
296
|
+
return;
|
|
297
|
+
this.updateComplete.then(() => {
|
|
298
|
+
const selectedSegment = this.segments.find((s) => s.value === __privateGet(this, _value));
|
|
299
|
+
if (selectedSegment) {
|
|
300
|
+
this.segments.forEach((s) => s.selected = false);
|
|
301
|
+
selectedSegment.selected = true;
|
|
302
|
+
__privateSet(this, _focusedIndex, this.segments.indexOf(selectedSegment));
|
|
303
|
+
__privateGet(this, _calcLayout).call(this, true);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
get value() {
|
|
309
|
+
return __privateGet(this, _value);
|
|
310
|
+
}
|
|
311
|
+
set value(val) {
|
|
312
|
+
__privateSet(this, _value, val);
|
|
313
|
+
__privateGet(this, _updateSelectedFromValue).call(this);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Returns the segments in the control
|
|
317
|
+
* @readonly
|
|
318
|
+
*/
|
|
319
|
+
get segments() {
|
|
320
|
+
return this._elSlot ? this._elSlot.assignedElements() : [];
|
|
321
|
+
}
|
|
322
|
+
connectedCallback() {
|
|
323
|
+
super.connectedCallback();
|
|
324
|
+
TransitionalStyles.instance.apply(this, "gds-segmented-control");
|
|
325
|
+
__privateGet(this, _resizeObserver).observe(this);
|
|
326
|
+
this.addEventListener("focusin", (e) => {
|
|
327
|
+
if (e.target instanceof GdsSegment) {
|
|
328
|
+
__privateSet(this, _focusedIndex, this.segments.indexOf(e.target));
|
|
329
|
+
__privateGet(this, _calcLayout).call(this, true);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
disconnectedCallback() {
|
|
334
|
+
super.disconnectedCallback();
|
|
335
|
+
__privateGet(this, _resizeObserver).unobserve(this);
|
|
336
|
+
}
|
|
337
|
+
render() {
|
|
338
|
+
return html`${this._tStyles}
|
|
339
|
+
${when(
|
|
340
|
+
this._showPrevButton,
|
|
341
|
+
() => html`<button
|
|
342
|
+
id="btn-prev"
|
|
343
|
+
@click=${__privateGet(this, _scrollLeft)}
|
|
344
|
+
aria-label=${msg("Scroll right")}
|
|
345
|
+
>
|
|
346
|
+
<gds-icon name="chevron-left"></gds-icon>
|
|
347
|
+
</button>`
|
|
348
|
+
)}
|
|
349
|
+
<div
|
|
350
|
+
id="track"
|
|
351
|
+
@scroll=${() => {
|
|
352
|
+
this._elTrack.scrollLeft = 0;
|
|
353
|
+
}}
|
|
354
|
+
>
|
|
355
|
+
<div
|
|
356
|
+
id="segments"
|
|
357
|
+
@pointerdown=${__privateGet(this, _startDrag)}
|
|
358
|
+
@pointermove=${__privateGet(this, _drag)}
|
|
359
|
+
@touchmove=${__privateGet(this, _drag)}
|
|
360
|
+
@pointerup=${__privateGet(this, _endDrag)}
|
|
361
|
+
@pointercancel=${__privateGet(this, _endDrag)}
|
|
362
|
+
role="list"
|
|
363
|
+
>
|
|
364
|
+
<slot
|
|
365
|
+
gds-allow="gds-segment"
|
|
366
|
+
@click=${__privateGet(this, _handleSegmentClick)}
|
|
367
|
+
@slotchange=${__privateMethod(this, _handleSlotChange, handleSlotChange_fn)}
|
|
368
|
+
role="none"
|
|
369
|
+
></slot>
|
|
370
|
+
<div id="indicator" role="none"></div>
|
|
371
|
+
</div>
|
|
372
|
+
</div>
|
|
373
|
+
${when(
|
|
374
|
+
this._showNextButton,
|
|
375
|
+
() => html`<button
|
|
376
|
+
id="btn-next"
|
|
377
|
+
@click=${__privateGet(this, _scrollRight)}
|
|
378
|
+
aria-label=${msg("Scroll right")}
|
|
379
|
+
>
|
|
380
|
+
<gds-icon name="chevron-right"></gds-icon>
|
|
381
|
+
</button>`
|
|
382
|
+
)}`;
|
|
383
|
+
}
|
|
384
|
+
_recalculateMinWidth() {
|
|
385
|
+
this.updateComplete.then(() => __privateGet(this, _calcLayout).call(this));
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
_value = new WeakMap();
|
|
389
|
+
_tid = new WeakMap();
|
|
390
|
+
_resizeObserver = new WeakMap();
|
|
391
|
+
_firstVisibleIndex = new WeakMap();
|
|
392
|
+
_calculatedSegmentWidth = new WeakMap();
|
|
393
|
+
_segmentWidth = new WeakMap();
|
|
394
|
+
_segmentsContainerLeft = new WeakMap();
|
|
395
|
+
_focusedIndex = new WeakMap();
|
|
396
|
+
_dragStartX = new WeakMap();
|
|
397
|
+
_dragStartLeft = new WeakMap();
|
|
398
|
+
_isDragging = new WeakMap();
|
|
399
|
+
_startDrag = new WeakMap();
|
|
400
|
+
_drag = new WeakMap();
|
|
401
|
+
_endDrag = new WeakMap();
|
|
402
|
+
_calcVisibleAfterDrag = new WeakMap();
|
|
403
|
+
_calcLayout = new WeakMap();
|
|
404
|
+
_applySegmentsTransform = new WeakMap();
|
|
405
|
+
_handleSlotChange = new WeakSet();
|
|
406
|
+
handleSlotChange_fn = function() {
|
|
407
|
+
var _a;
|
|
408
|
+
const selSegmentValue = (_a = this.segments.find((s) => s.selected)) == null ? void 0 : _a.value;
|
|
409
|
+
if (selSegmentValue) {
|
|
410
|
+
__privateSet(this, _value, selSegmentValue);
|
|
411
|
+
}
|
|
412
|
+
__privateGet(this, _calcLayout).call(this);
|
|
413
|
+
};
|
|
414
|
+
_scrollLeft = new WeakMap();
|
|
415
|
+
_scrollRight = new WeakMap();
|
|
416
|
+
_updateScrollBtnState = new WeakMap();
|
|
417
|
+
_updateIndicator = new WeakMap();
|
|
418
|
+
_handleSegmentClick = new WeakMap();
|
|
419
|
+
_updateSelectedFromValue = new WeakMap();
|
|
420
|
+
GdsSegmentedControl.styles = [tokens, unsafeCSS(segmented_control_style_default)];
|
|
421
|
+
__decorateClass([
|
|
422
|
+
property({ type: Number, attribute: "seg-min-width" })
|
|
423
|
+
], GdsSegmentedControl.prototype, "segMinWidth", 2);
|
|
424
|
+
__decorateClass([
|
|
425
|
+
property()
|
|
426
|
+
], GdsSegmentedControl.prototype, "size", 2);
|
|
427
|
+
__decorateClass([
|
|
428
|
+
property()
|
|
429
|
+
], GdsSegmentedControl.prototype, "value", 1);
|
|
430
|
+
__decorateClass([
|
|
431
|
+
state()
|
|
432
|
+
], GdsSegmentedControl.prototype, "_tStyles", 2);
|
|
433
|
+
__decorateClass([
|
|
434
|
+
query("slot")
|
|
435
|
+
], GdsSegmentedControl.prototype, "_elSlot", 2);
|
|
436
|
+
__decorateClass([
|
|
437
|
+
query("#indicator")
|
|
438
|
+
], GdsSegmentedControl.prototype, "_elIndicator", 2);
|
|
439
|
+
__decorateClass([
|
|
440
|
+
query("#track")
|
|
441
|
+
], GdsSegmentedControl.prototype, "_elTrack", 2);
|
|
442
|
+
__decorateClass([
|
|
443
|
+
query("#segments")
|
|
444
|
+
], GdsSegmentedControl.prototype, "_elSegments", 2);
|
|
445
|
+
__decorateClass([
|
|
446
|
+
state()
|
|
447
|
+
], GdsSegmentedControl.prototype, "_showPrevButton", 2);
|
|
448
|
+
__decorateClass([
|
|
449
|
+
state()
|
|
450
|
+
], GdsSegmentedControl.prototype, "_showNextButton", 2);
|
|
451
|
+
__decorateClass([
|
|
452
|
+
watch("segMinWidth")
|
|
453
|
+
], GdsSegmentedControl.prototype, "_recalculateMinWidth", 1);
|
|
454
|
+
GdsSegmentedControl = __decorateClass([
|
|
455
|
+
gdsCustomElement("gds-segmented-control")
|
|
456
|
+
], GdsSegmentedControl);
|
|
457
|
+
|
|
458
|
+
export {
|
|
459
|
+
GdsSegmentedControl
|
|
460
|
+
};
|