@sebgroup/green-core 1.12.0 → 1.14.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 +22 -79
- package/components/badge/badge.d.ts +43 -0
- package/components/button/button.d.ts +46 -0
- package/components/checkbox/checkbox.d.ts +12 -0
- package/components/datepicker/datepicker.d.ts +1 -0
- package/components/dropdown/dropdown.d.ts +1 -0
- package/components/form-control.d.ts +0 -1
- package/components/icon/icon.d.ts +16 -0
- package/components/index.d.ts +2 -0
- package/components/input/input.d.ts +69 -0
- package/components/radio/radio-group.d.ts +13 -0
- package/components/radio/radio.d.ts +14 -0
- package/components/segmented-control/segment/segment.d.ts +19 -0
- package/components/segmented-control/segment/segment.trans.styles.d.ts +2 -0
- package/components/segmented-control/segmented-control.d.ts +50 -0
- package/components/segmented-control/segmented-control.trans.styles.d.ts +2 -0
- package/components/switch/switch.d.ts +12 -0
- package/components/tooltip/tooltip.d.ts +14 -0
- package/gds-element.d.ts +1 -0
- package/generated/locales/sv.d.ts +2 -0
- package/green-jest-config.cjs +24 -0
- package/index.js +668 -11
- package/localization.js +2 -0
- package/package.json +4 -1
- package/primitives/ripple/ripple.d.ts +7 -0
- package/setup-jest.js +34 -0
- package/transitional-styles.js +171 -1
- package/utils/directives/forward-attributes.d.ts +9 -0
- package/utils/directives/index.d.ts +1 -0
- package/utils/helpers/strip-white-space.d.ts +13 -0
package/index.js
CHANGED
|
@@ -9,9 +9,9 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
9
9
|
__defProp(target, key, result);
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
|
-
var __accessCheck = (obj, member,
|
|
12
|
+
var __accessCheck = (obj, member, msg7) => {
|
|
13
13
|
if (!member.has(obj))
|
|
14
|
-
throw TypeError("Cannot " +
|
|
14
|
+
throw TypeError("Cannot " + msg7);
|
|
15
15
|
};
|
|
16
16
|
var __privateGet = (obj, member, getter) => {
|
|
17
17
|
__accessCheck(obj, member, "read from private field");
|
|
@@ -27,6 +27,14 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
27
27
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
28
28
|
return value;
|
|
29
29
|
};
|
|
30
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
31
|
+
set _(value) {
|
|
32
|
+
__privateSet(obj, member, value, setter);
|
|
33
|
+
},
|
|
34
|
+
get _() {
|
|
35
|
+
return __privateGet(obj, member, getter);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
30
38
|
var __privateMethod = (obj, member, method) => {
|
|
31
39
|
__accessCheck(obj, member, "access private method");
|
|
32
40
|
return method;
|
|
@@ -77,8 +85,8 @@ function watch(propertyName, options) {
|
|
|
77
85
|
const { update } = proto;
|
|
78
86
|
const watchedProperties = Array.isArray(propertyName) ? propertyName : [propertyName];
|
|
79
87
|
proto.update = function(changedProps) {
|
|
80
|
-
watchedProperties.forEach((
|
|
81
|
-
const key =
|
|
88
|
+
watchedProperties.forEach((property14) => {
|
|
89
|
+
const key = property14;
|
|
82
90
|
if (changedProps.has(key)) {
|
|
83
91
|
const oldValue = changedProps.get(key);
|
|
84
92
|
const newValue = this[key];
|
|
@@ -144,7 +152,7 @@ function watchMediaQuery(q) {
|
|
|
144
152
|
// libs/core/src/utils/helpers/custom-element-scoping.ts
|
|
145
153
|
import { html as litHtml } from "lit";
|
|
146
154
|
import { customElement } from "lit/decorators.js";
|
|
147
|
-
var VER_SUFFIX = "-
|
|
155
|
+
var VER_SUFFIX = "-791bd2";
|
|
148
156
|
var elementLookupTable = /* @__PURE__ */ new Map();
|
|
149
157
|
var gdsCustomElement = (tagName) => {
|
|
150
158
|
if (globalThis.GDS_DISABLE_VERSIONED_ELEMENTS) {
|
|
@@ -241,6 +249,7 @@ var TransitionalStyles = class {
|
|
|
241
249
|
if (!element || !element.shadowRoot)
|
|
242
250
|
return;
|
|
243
251
|
element.shadowRoot.adoptedStyleSheets = [sheet];
|
|
252
|
+
element.isUsingTransitionalStyles = true;
|
|
244
253
|
}
|
|
245
254
|
// This is a fallback for browsers that don't support constructed stylesheets.
|
|
246
255
|
// Primarily, this is here to support Safari/iOS 15.x
|
|
@@ -294,6 +303,7 @@ var GdsElement = class extends LitElement2 {
|
|
|
294
303
|
* The unscoped name of this element.
|
|
295
304
|
*/
|
|
296
305
|
this.gdsElementName = "";
|
|
306
|
+
this.isUsingTransitionalStyles = false;
|
|
297
307
|
}
|
|
298
308
|
connectedCallback() {
|
|
299
309
|
super.connectedCallback();
|
|
@@ -1046,9 +1056,6 @@ var GdsFormControlElement = class extends GdsElement {
|
|
|
1046
1056
|
get form() {
|
|
1047
1057
|
return __privateGet(this, _internals).form;
|
|
1048
1058
|
}
|
|
1049
|
-
get type() {
|
|
1050
|
-
return getUnscopedTagName(this.localName) || "gds-form-control";
|
|
1051
|
-
}
|
|
1052
1059
|
get validity() {
|
|
1053
1060
|
return __privateGet(this, _internals).validity;
|
|
1054
1061
|
}
|
|
@@ -1231,6 +1238,9 @@ var GdsDropdown = class extends GdsFormControlElement {
|
|
|
1231
1238
|
getScopedTagName("gds-option")
|
|
1232
1239
|
));
|
|
1233
1240
|
}
|
|
1241
|
+
get type() {
|
|
1242
|
+
return "gds-dropdown";
|
|
1243
|
+
}
|
|
1234
1244
|
/**
|
|
1235
1245
|
* Get the options of the dropdown.
|
|
1236
1246
|
*/
|
|
@@ -2379,6 +2389,9 @@ var GdsDatepicker = class extends GdsFormControlElement {
|
|
|
2379
2389
|
day: "dd"
|
|
2380
2390
|
});
|
|
2381
2391
|
}
|
|
2392
|
+
get type() {
|
|
2393
|
+
return "gds-datepicker";
|
|
2394
|
+
}
|
|
2382
2395
|
get dateformat() {
|
|
2383
2396
|
return this._dateFormatLayout.layout.map((f) => f.token).join(this._dateFormatLayout.delimiter);
|
|
2384
2397
|
}
|
|
@@ -2808,7 +2821,7 @@ import { unsafeCSS as unsafeCSS2 } from "lit";
|
|
|
2808
2821
|
// dist/libs/tokens/internal/pallet.css
|
|
2809
2822
|
var pallet_default = `/**
|
|
2810
2823
|
* Do not edit directly
|
|
2811
|
-
* Generated on Wed,
|
|
2824
|
+
* Generated on Wed, 17 Apr 2024 14:10:00 GMT
|
|
2812
2825
|
*/
|
|
2813
2826
|
|
|
2814
2827
|
:host {
|
|
@@ -2969,7 +2982,7 @@ var pallet_default = `/**
|
|
|
2969
2982
|
// dist/libs/tokens/internal/theme/light.css
|
|
2970
2983
|
var light_default = `/**
|
|
2971
2984
|
* Do not edit directly
|
|
2972
|
-
* Generated on Wed,
|
|
2985
|
+
* Generated on Wed, 17 Apr 2024 14:10:00 GMT
|
|
2973
2986
|
*/
|
|
2974
2987
|
|
|
2975
2988
|
:host {
|
|
@@ -3090,7 +3103,7 @@ var light_default = `/**
|
|
|
3090
3103
|
// dist/libs/tokens/internal/size.css
|
|
3091
3104
|
var size_default = `/**
|
|
3092
3105
|
* Do not edit directly
|
|
3093
|
-
* Generated on Wed,
|
|
3106
|
+
* Generated on Wed, 17 Apr 2024 14:10:00 GMT
|
|
3094
3107
|
*/
|
|
3095
3108
|
|
|
3096
3109
|
:host {
|
|
@@ -3590,15 +3603,659 @@ __decorateClass([
|
|
|
3590
3603
|
GdsGroupedList = __decorateClass([
|
|
3591
3604
|
gdsCustomElement("gds-grouped-list")
|
|
3592
3605
|
], GdsGroupedList);
|
|
3606
|
+
|
|
3607
|
+
// libs/core/src/components/segmented-control/segmented-control.ts
|
|
3608
|
+
import { unsafeCSS as unsafeCSS5 } from "lit";
|
|
3609
|
+
import { query as query4, state as state13, property as property13 } from "lit/decorators.js";
|
|
3610
|
+
import { when as when6 } from "lit/directives/when.js";
|
|
3611
|
+
import { msg as msg6 } from "@lit/localize";
|
|
3612
|
+
|
|
3613
|
+
// libs/core/src/components/segmented-control/segment/segment.ts
|
|
3614
|
+
import { property as property12 } from "lit/decorators.js";
|
|
3615
|
+
import { unsafeCSS as unsafeCSS4 } from "lit";
|
|
3616
|
+
|
|
3617
|
+
// libs/core/src/components/segmented-control/segment/segment.style.css
|
|
3618
|
+
var segment_style_default = `:host {
|
|
3619
|
+
z-index: 1;
|
|
3620
|
+
display: flex;
|
|
3621
|
+
transition: 0.2s;
|
|
3622
|
+
}
|
|
3623
|
+
|
|
3624
|
+
button {
|
|
3625
|
+
flex-shrink: 0;
|
|
3626
|
+
flex-grow: 1;
|
|
3627
|
+
font-family: inherit;
|
|
3628
|
+
padding: 0 1rem;
|
|
3629
|
+
text-align: center;
|
|
3630
|
+
cursor: pointer;
|
|
3631
|
+
border-radius: calc(infinity * 1px);
|
|
3632
|
+
-webkit-appearance: none;
|
|
3633
|
+
-moz-appearance: none;
|
|
3634
|
+
appearance: none;
|
|
3635
|
+
background: transparent;
|
|
3636
|
+
border-width: 0;
|
|
3637
|
+
font-size: inherit;
|
|
3638
|
+
overflow: hidden;
|
|
3639
|
+
white-space: nowrap;
|
|
3640
|
+
text-overflow: ellipsis;
|
|
3641
|
+
width: 100%;
|
|
3642
|
+
color: var(--gds-sys-color-content-content);
|
|
3643
|
+
}
|
|
3644
|
+
|
|
3645
|
+
@media (pointer: fine) {
|
|
3646
|
+
button:hover {
|
|
3647
|
+
background-color: color-mix(
|
|
3648
|
+
in srgb,
|
|
3649
|
+
var(--gds-sys-color-state-layers-state-black-dim1),
|
|
3650
|
+
transparent
|
|
3651
|
+
);
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
|
|
3655
|
+
button:focus-visible {
|
|
3656
|
+
outline: 2px solid #000;
|
|
3657
|
+
outline-offset: -2px;
|
|
3658
|
+
}
|
|
3659
|
+
`;
|
|
3660
|
+
|
|
3661
|
+
// libs/core/src/components/segmented-control/segment/segment.ts
|
|
3662
|
+
var GdsSegment = class extends GdsElement {
|
|
3663
|
+
constructor() {
|
|
3664
|
+
super(...arguments);
|
|
3665
|
+
this.selected = false;
|
|
3666
|
+
}
|
|
3667
|
+
connectedCallback() {
|
|
3668
|
+
super.connectedCallback();
|
|
3669
|
+
TransitionalStyles.instance.apply(this, "gds-segmented");
|
|
3670
|
+
this.setAttribute("role", "listitem");
|
|
3671
|
+
}
|
|
3672
|
+
render() {
|
|
3673
|
+
return html`<button aria-current=${String(this.selected)}>
|
|
3674
|
+
<slot></slot>
|
|
3675
|
+
</button>`;
|
|
3676
|
+
}
|
|
3677
|
+
};
|
|
3678
|
+
GdsSegment.styles = [...tokens, unsafeCSS4(segment_style_default)];
|
|
3679
|
+
__decorateClass([
|
|
3680
|
+
property12({ type: Boolean, reflect: true })
|
|
3681
|
+
], GdsSegment.prototype, "selected", 2);
|
|
3682
|
+
__decorateClass([
|
|
3683
|
+
property12()
|
|
3684
|
+
], GdsSegment.prototype, "value", 2);
|
|
3685
|
+
GdsSegment = __decorateClass([
|
|
3686
|
+
gdsCustomElement("gds-segment")
|
|
3687
|
+
], GdsSegment);
|
|
3688
|
+
|
|
3689
|
+
// libs/core/src/components/segmented-control/segmented-control.style.css
|
|
3690
|
+
var segmented_control_style_default = `:host {
|
|
3691
|
+
box-sizing: border-box;
|
|
3692
|
+
display: inline-flex;
|
|
3693
|
+
background-color: var(--gds-sys-color-container-container-dim1);
|
|
3694
|
+
border: 0.25rem solid var(--gds-sys-color-container-container-dim1);
|
|
3695
|
+
gap: 0.25rem;
|
|
3696
|
+
border-radius: calc(infinity * 1px);
|
|
3697
|
+
contain: layout;
|
|
3698
|
+
max-width: 100%;
|
|
3699
|
+
overflow: hidden;
|
|
3700
|
+
height: 3rem;
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
:host([size='small']) {
|
|
3704
|
+
height: 2.5rem;
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
#track {
|
|
3708
|
+
box-sizing: border-box;
|
|
3709
|
+
display: flex;
|
|
3710
|
+
flex-grow: 0;
|
|
3711
|
+
flex-shrink: 1;
|
|
3712
|
+
width: 100%;
|
|
3713
|
+
position: relative;
|
|
3714
|
+
overflow: hidden;
|
|
3715
|
+
}
|
|
3716
|
+
|
|
3717
|
+
#segments {
|
|
3718
|
+
box-sizing: border-box;
|
|
3719
|
+
display: inline-flex;
|
|
3720
|
+
transition: 0.2s;
|
|
3721
|
+
position: relative;
|
|
3722
|
+
z-index: 1;
|
|
3723
|
+
gap: 0.25rem;
|
|
3724
|
+
}
|
|
3725
|
+
|
|
3726
|
+
#btn-prev,
|
|
3727
|
+
#btn-next {
|
|
3728
|
+
display: flex;
|
|
3729
|
+
align-items: center;
|
|
3730
|
+
justify-content: center;
|
|
3731
|
+
font-size: 1rem;
|
|
3732
|
+
border-radius: calc(infinity * 1px);
|
|
3733
|
+
background-color: var(--gds-sys-color-container-container-dim1);
|
|
3734
|
+
border-width: 0;
|
|
3735
|
+
-webkit-appearance: none;
|
|
3736
|
+
-moz-appearance: none;
|
|
3737
|
+
appearance: none;
|
|
3738
|
+
aspect-ratio: 1;
|
|
3739
|
+
height: 100%;
|
|
3740
|
+
width: 2.5rem;
|
|
3741
|
+
cursor: pointer;
|
|
3742
|
+
color: var(--gds-sys-color-content-content);
|
|
3743
|
+
|
|
3744
|
+
@media (pointer: fine) {
|
|
3745
|
+
&:hover {
|
|
3746
|
+
background-color: color-mix(
|
|
3747
|
+
in srgb,
|
|
3748
|
+
var(--gds-sys-color-state-layers-state-black-dim1),
|
|
3749
|
+
var(--gds-sys-color-container-container-dim1)
|
|
3750
|
+
);
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
}
|
|
3754
|
+
|
|
3755
|
+
:host([size='small']) #btn-prev,
|
|
3756
|
+
:host([size='small']) #btn-next {
|
|
3757
|
+
width: 2rem;
|
|
3758
|
+
}
|
|
3759
|
+
|
|
3760
|
+
::slotted(*) {
|
|
3761
|
+
flex-shrink: 0;
|
|
3762
|
+
flex-grow: 1;
|
|
3763
|
+
z-index: 1;
|
|
3764
|
+
}
|
|
3765
|
+
|
|
3766
|
+
#indicator {
|
|
3767
|
+
position: absolute;
|
|
3768
|
+
left: 0;
|
|
3769
|
+
height: 100%;
|
|
3770
|
+
background-color: var(--gds-sys-color-container-container-bright);
|
|
3771
|
+
border-radius: calc(infinity * 1px);
|
|
3772
|
+
transition: transform 0.2s, width 0.2s;
|
|
3773
|
+
z-index: 0;
|
|
3774
|
+
}
|
|
3775
|
+
`;
|
|
3776
|
+
|
|
3777
|
+
// libs/core/src/components/segmented-control/segmented-control.ts
|
|
3778
|
+
var BTN_SIZE = {
|
|
3779
|
+
small: 36,
|
|
3780
|
+
medium: 44
|
|
3781
|
+
};
|
|
3782
|
+
var getSegmentGap = (transitionalStyles) => transitionalStyles ? 0 : 4;
|
|
3783
|
+
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;
|
|
3784
|
+
var GdsSegmentedControl = class extends GdsElement {
|
|
3785
|
+
constructor() {
|
|
3786
|
+
super(...arguments);
|
|
3787
|
+
__privateAdd(this, _handleSlotChange);
|
|
3788
|
+
this.segMinWidth = 100;
|
|
3789
|
+
this.size = "medium";
|
|
3790
|
+
__privateAdd(this, _value, void 0);
|
|
3791
|
+
this._showPrevButton = false;
|
|
3792
|
+
this._showNextButton = false;
|
|
3793
|
+
__privateAdd(this, _tid, void 0);
|
|
3794
|
+
__privateAdd(this, _resizeObserver, new ResizeObserver(() => {
|
|
3795
|
+
__privateGet(this, _tid) && clearTimeout(__privateGet(this, _tid));
|
|
3796
|
+
__privateSet(this, _tid, setTimeout(() => {
|
|
3797
|
+
__privateGet(this, _calcLayout).call(this);
|
|
3798
|
+
}, 20));
|
|
3799
|
+
}));
|
|
3800
|
+
__privateAdd(this, _firstVisibleIndex, 0);
|
|
3801
|
+
__privateAdd(this, _calculatedSegmentWidth, 0);
|
|
3802
|
+
__privateAdd(this, _segmentWidth, 0);
|
|
3803
|
+
__privateAdd(this, _segmentsContainerLeft, 0);
|
|
3804
|
+
__privateAdd(this, _focusedIndex, 0);
|
|
3805
|
+
__privateAdd(this, _dragStartX, 0);
|
|
3806
|
+
__privateAdd(this, _dragStartLeft, 0);
|
|
3807
|
+
__privateAdd(this, _isDragging, false);
|
|
3808
|
+
__privateAdd(this, _startDrag, (event) => {
|
|
3809
|
+
__privateSet(this, _dragStartX, event.clientX);
|
|
3810
|
+
__privateSet(this, _dragStartLeft, __privateGet(this, _segmentsContainerLeft));
|
|
3811
|
+
__privateSet(this, _isDragging, true);
|
|
3812
|
+
});
|
|
3813
|
+
__privateAdd(this, _drag, (event) => {
|
|
3814
|
+
if (!__privateGet(this, _isDragging))
|
|
3815
|
+
return;
|
|
3816
|
+
event.preventDefault();
|
|
3817
|
+
const delta = event.clientX - __privateGet(this, _dragStartX);
|
|
3818
|
+
if (Math.abs(delta) < 5)
|
|
3819
|
+
return;
|
|
3820
|
+
try {
|
|
3821
|
+
if (!this._elSegments.hasPointerCapture(event.pointerId))
|
|
3822
|
+
this._elSegments.setPointerCapture(event.pointerId);
|
|
3823
|
+
__privateSet(this, _segmentsContainerLeft, __privateGet(this, _dragStartLeft) + delta);
|
|
3824
|
+
__privateGet(this, _applySegmentsTransform).call(this);
|
|
3825
|
+
} catch {
|
|
3826
|
+
}
|
|
3827
|
+
});
|
|
3828
|
+
__privateAdd(this, _endDrag, (event) => {
|
|
3829
|
+
if (!__privateGet(this, _isDragging))
|
|
3830
|
+
return;
|
|
3831
|
+
__privateSet(this, _isDragging, false);
|
|
3832
|
+
try {
|
|
3833
|
+
this._elSegments.releasePointerCapture(event.pointerId);
|
|
3834
|
+
__privateGet(this, _calcVisibleAfterDrag).call(this);
|
|
3835
|
+
} catch {
|
|
3836
|
+
}
|
|
3837
|
+
});
|
|
3838
|
+
__privateAdd(this, _calcVisibleAfterDrag, () => {
|
|
3839
|
+
__privateSet(this, _firstVisibleIndex, Math.round(
|
|
3840
|
+
-__privateGet(this, _segmentsContainerLeft) / __privateGet(this, _calculatedSegmentWidth)
|
|
3841
|
+
));
|
|
3842
|
+
__privateGet(this, _calcLayout).call(this);
|
|
3843
|
+
});
|
|
3844
|
+
// Calculates the layout based on the configured min width
|
|
3845
|
+
// and the available space in the track
|
|
3846
|
+
__privateAdd(this, _calcLayout, (followFocus = false) => {
|
|
3847
|
+
const calcNumVisibleSegments = () => {
|
|
3848
|
+
const numSegments = this.segments.length;
|
|
3849
|
+
const availableWidth = this._elTrack.offsetWidth;
|
|
3850
|
+
if (availableWidth / numSegments > this.segMinWidth) {
|
|
3851
|
+
return {
|
|
3852
|
+
count: numSegments,
|
|
3853
|
+
segmentWidth: (availableWidth - getSegmentGap(this.isUsingTransitionalStyles) * (numSegments - 1)) / numSegments
|
|
3854
|
+
};
|
|
3855
|
+
}
|
|
3856
|
+
const availableWidthIncBtns = this.offsetWidth - BTN_SIZE[this.size] * 2;
|
|
3857
|
+
const maxVisibleSegments = Math.floor(
|
|
3858
|
+
availableWidthIncBtns / this.segMinWidth
|
|
3859
|
+
);
|
|
3860
|
+
const segmentWidth = (availableWidth - getSegmentGap(this.isUsingTransitionalStyles) * (maxVisibleSegments - 1)) / maxVisibleSegments;
|
|
3861
|
+
return {
|
|
3862
|
+
count: maxVisibleSegments,
|
|
3863
|
+
segmentWidth
|
|
3864
|
+
};
|
|
3865
|
+
};
|
|
3866
|
+
const { count } = calcNumVisibleSegments();
|
|
3867
|
+
if (followFocus) {
|
|
3868
|
+
if (__privateGet(this, _focusedIndex) >= __privateGet(this, _firstVisibleIndex) + count) {
|
|
3869
|
+
__privateSet(this, _firstVisibleIndex, __privateGet(this, _focusedIndex) - count + 1);
|
|
3870
|
+
}
|
|
3871
|
+
if (__privateGet(this, _focusedIndex) < __privateGet(this, _firstVisibleIndex)) {
|
|
3872
|
+
__privateSet(this, _firstVisibleIndex, __privateGet(this, _focusedIndex));
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
const endFirstIndex = this.segments.length - count;
|
|
3876
|
+
const hasReachedEnd = __privateGet(this, _firstVisibleIndex) >= endFirstIndex;
|
|
3877
|
+
const isAtStart = __privateGet(this, _firstVisibleIndex) <= 0;
|
|
3878
|
+
if (hasReachedEnd) {
|
|
3879
|
+
__privateSet(this, _firstVisibleIndex, endFirstIndex);
|
|
3880
|
+
}
|
|
3881
|
+
if (isAtStart) {
|
|
3882
|
+
__privateSet(this, _firstVisibleIndex, 0);
|
|
3883
|
+
}
|
|
3884
|
+
__privateGet(this, _updateScrollBtnState).call(this, count);
|
|
3885
|
+
this.updateComplete.then(() => {
|
|
3886
|
+
const { segmentWidth, count: count2 } = calcNumVisibleSegments();
|
|
3887
|
+
this.segments.forEach((segment) => {
|
|
3888
|
+
segment.style.width = segmentWidth + "px";
|
|
3889
|
+
});
|
|
3890
|
+
__privateSet(this, _segmentsContainerLeft, -__privateGet(this, _firstVisibleIndex) * segmentWidth - getSegmentGap(this.isUsingTransitionalStyles) * __privateGet(this, _firstVisibleIndex));
|
|
3891
|
+
__privateGet(this, _applySegmentsTransform).call(this);
|
|
3892
|
+
__privateSet(this, _calculatedSegmentWidth, segmentWidth);
|
|
3893
|
+
__privateSet(this, _segmentWidth, segmentWidth);
|
|
3894
|
+
__privateGet(this, _updateIndicator).call(this);
|
|
3895
|
+
});
|
|
3896
|
+
});
|
|
3897
|
+
__privateAdd(this, _applySegmentsTransform, () => {
|
|
3898
|
+
window.requestAnimationFrame(() => {
|
|
3899
|
+
this._elSegments.style.transform = `translateX(${__privateGet(this, _segmentsContainerLeft)}px)`;
|
|
3900
|
+
});
|
|
3901
|
+
});
|
|
3902
|
+
__privateAdd(this, _scrollLeft, () => {
|
|
3903
|
+
__privateWrapper(this, _firstVisibleIndex)._--;
|
|
3904
|
+
__privateGet(this, _calcLayout).call(this);
|
|
3905
|
+
});
|
|
3906
|
+
__privateAdd(this, _scrollRight, () => {
|
|
3907
|
+
__privateWrapper(this, _firstVisibleIndex)._++;
|
|
3908
|
+
__privateGet(this, _calcLayout).call(this);
|
|
3909
|
+
});
|
|
3910
|
+
// Updates the visibility of the scroll buttons
|
|
3911
|
+
__privateAdd(this, _updateScrollBtnState, (numVisibleSegments) => {
|
|
3912
|
+
this._showPrevButton = __privateGet(this, _firstVisibleIndex) > 0;
|
|
3913
|
+
this._showNextButton = __privateGet(this, _firstVisibleIndex) < this.segments.length - numVisibleSegments;
|
|
3914
|
+
});
|
|
3915
|
+
// Updates the selection indicator position
|
|
3916
|
+
__privateAdd(this, _updateIndicator, () => {
|
|
3917
|
+
const segment = this.segments.find((s) => s.selected);
|
|
3918
|
+
if (segment) {
|
|
3919
|
+
const selectedSegmentIndex = this.segments.indexOf(segment);
|
|
3920
|
+
const offset2 = selectedSegmentIndex * __privateGet(this, _segmentWidth) + getSegmentGap(this.isUsingTransitionalStyles) * selectedSegmentIndex;
|
|
3921
|
+
this._elIndicator.style.transform = `translateX(${offset2}px)`;
|
|
3922
|
+
this._elIndicator.style.width = `${__privateGet(this, _segmentWidth)}px`;
|
|
3923
|
+
} else {
|
|
3924
|
+
this._elIndicator.style.transform = `translateX(-100%)`;
|
|
3925
|
+
this._elIndicator.style.width = `0px`;
|
|
3926
|
+
}
|
|
3927
|
+
});
|
|
3928
|
+
__privateAdd(this, _handleSegmentClick, (event) => {
|
|
3929
|
+
const selectedSegment = this.segments.find(
|
|
3930
|
+
(s) => s === event.target || s.contains(event.target)
|
|
3931
|
+
);
|
|
3932
|
+
if (selectedSegment) {
|
|
3933
|
+
this.segments.forEach((s) => s.selected = false);
|
|
3934
|
+
selectedSegment.selected = true;
|
|
3935
|
+
__privateSet(this, _value, selectedSegment.value);
|
|
3936
|
+
__privateGet(this, _updateIndicator).call(this);
|
|
3937
|
+
this.dispatchEvent(
|
|
3938
|
+
new CustomEvent("change", {
|
|
3939
|
+
detail: { segment: selectedSegment },
|
|
3940
|
+
bubbles: true,
|
|
3941
|
+
composed: true
|
|
3942
|
+
})
|
|
3943
|
+
);
|
|
3944
|
+
}
|
|
3945
|
+
});
|
|
3946
|
+
__privateAdd(this, _updateSelectedFromValue, () => {
|
|
3947
|
+
if (!__privateGet(this, _value))
|
|
3948
|
+
return;
|
|
3949
|
+
this.updateComplete.then(() => {
|
|
3950
|
+
const selectedSegment = this.segments.find((s) => s.value === __privateGet(this, _value));
|
|
3951
|
+
if (selectedSegment) {
|
|
3952
|
+
this.segments.forEach((s) => s.selected = false);
|
|
3953
|
+
selectedSegment.selected = true;
|
|
3954
|
+
__privateSet(this, _focusedIndex, this.segments.indexOf(selectedSegment));
|
|
3955
|
+
__privateGet(this, _calcLayout).call(this, true);
|
|
3956
|
+
}
|
|
3957
|
+
});
|
|
3958
|
+
});
|
|
3959
|
+
}
|
|
3960
|
+
get value() {
|
|
3961
|
+
return __privateGet(this, _value);
|
|
3962
|
+
}
|
|
3963
|
+
set value(val) {
|
|
3964
|
+
__privateSet(this, _value, val);
|
|
3965
|
+
__privateGet(this, _updateSelectedFromValue).call(this);
|
|
3966
|
+
}
|
|
3967
|
+
/**
|
|
3968
|
+
* Returns the segments in the control
|
|
3969
|
+
* @readonly
|
|
3970
|
+
*/
|
|
3971
|
+
get segments() {
|
|
3972
|
+
return this._elSlot ? this._elSlot.assignedElements() : [];
|
|
3973
|
+
}
|
|
3974
|
+
connectedCallback() {
|
|
3975
|
+
super.connectedCallback();
|
|
3976
|
+
TransitionalStyles.instance.apply(this, "gds-segmented-control");
|
|
3977
|
+
__privateGet(this, _resizeObserver).observe(this);
|
|
3978
|
+
this.addEventListener("focusin", (e) => {
|
|
3979
|
+
if (e.target instanceof GdsSegment) {
|
|
3980
|
+
__privateSet(this, _focusedIndex, this.segments.indexOf(e.target));
|
|
3981
|
+
__privateGet(this, _calcLayout).call(this, true);
|
|
3982
|
+
}
|
|
3983
|
+
});
|
|
3984
|
+
}
|
|
3985
|
+
disconnectedCallback() {
|
|
3986
|
+
super.disconnectedCallback();
|
|
3987
|
+
__privateGet(this, _resizeObserver).unobserve(this);
|
|
3988
|
+
}
|
|
3989
|
+
render() {
|
|
3990
|
+
return html`${this._tStyles}
|
|
3991
|
+
${when6(
|
|
3992
|
+
this._showPrevButton,
|
|
3993
|
+
() => html`<button
|
|
3994
|
+
id="btn-prev"
|
|
3995
|
+
@click=${__privateGet(this, _scrollLeft)}
|
|
3996
|
+
aria-label=${msg6("Scroll right")}
|
|
3997
|
+
>
|
|
3998
|
+
<gds-icon name="chevron-left"></gds-icon>
|
|
3999
|
+
</button>`
|
|
4000
|
+
)}
|
|
4001
|
+
<div
|
|
4002
|
+
id="track"
|
|
4003
|
+
@scroll=${() => {
|
|
4004
|
+
this._elTrack.scrollLeft = 0;
|
|
4005
|
+
}}
|
|
4006
|
+
>
|
|
4007
|
+
<div
|
|
4008
|
+
id="segments"
|
|
4009
|
+
@pointerdown=${__privateGet(this, _startDrag)}
|
|
4010
|
+
@pointermove=${__privateGet(this, _drag)}
|
|
4011
|
+
@touchmove=${__privateGet(this, _drag)}
|
|
4012
|
+
@pointerup=${__privateGet(this, _endDrag)}
|
|
4013
|
+
@pointercancel=${__privateGet(this, _endDrag)}
|
|
4014
|
+
role="list"
|
|
4015
|
+
>
|
|
4016
|
+
<slot
|
|
4017
|
+
gds-allow="gds-segment"
|
|
4018
|
+
@click=${__privateGet(this, _handleSegmentClick)}
|
|
4019
|
+
@slotchange=${__privateMethod(this, _handleSlotChange, handleSlotChange_fn)}
|
|
4020
|
+
role="none"
|
|
4021
|
+
></slot>
|
|
4022
|
+
<div id="indicator" role="none"></div>
|
|
4023
|
+
</div>
|
|
4024
|
+
</div>
|
|
4025
|
+
${when6(
|
|
4026
|
+
this._showNextButton,
|
|
4027
|
+
() => html`<button
|
|
4028
|
+
id="btn-next"
|
|
4029
|
+
@click=${__privateGet(this, _scrollRight)}
|
|
4030
|
+
aria-label=${msg6("Scroll right")}
|
|
4031
|
+
>
|
|
4032
|
+
<gds-icon name="chevron-right"></gds-icon>
|
|
4033
|
+
</button>`
|
|
4034
|
+
)}`;
|
|
4035
|
+
}
|
|
4036
|
+
_recalculateMinWidth() {
|
|
4037
|
+
this.updateComplete.then(() => __privateGet(this, _calcLayout).call(this));
|
|
4038
|
+
}
|
|
4039
|
+
};
|
|
4040
|
+
_value = new WeakMap();
|
|
4041
|
+
_tid = new WeakMap();
|
|
4042
|
+
_resizeObserver = new WeakMap();
|
|
4043
|
+
_firstVisibleIndex = new WeakMap();
|
|
4044
|
+
_calculatedSegmentWidth = new WeakMap();
|
|
4045
|
+
_segmentWidth = new WeakMap();
|
|
4046
|
+
_segmentsContainerLeft = new WeakMap();
|
|
4047
|
+
_focusedIndex = new WeakMap();
|
|
4048
|
+
_dragStartX = new WeakMap();
|
|
4049
|
+
_dragStartLeft = new WeakMap();
|
|
4050
|
+
_isDragging = new WeakMap();
|
|
4051
|
+
_startDrag = new WeakMap();
|
|
4052
|
+
_drag = new WeakMap();
|
|
4053
|
+
_endDrag = new WeakMap();
|
|
4054
|
+
_calcVisibleAfterDrag = new WeakMap();
|
|
4055
|
+
_calcLayout = new WeakMap();
|
|
4056
|
+
_applySegmentsTransform = new WeakMap();
|
|
4057
|
+
_handleSlotChange = new WeakSet();
|
|
4058
|
+
handleSlotChange_fn = function() {
|
|
4059
|
+
const selSegmentValue = this.segments.find((s) => s.selected)?.value;
|
|
4060
|
+
if (selSegmentValue) {
|
|
4061
|
+
__privateSet(this, _value, selSegmentValue);
|
|
4062
|
+
}
|
|
4063
|
+
__privateGet(this, _calcLayout).call(this);
|
|
4064
|
+
};
|
|
4065
|
+
_scrollLeft = new WeakMap();
|
|
4066
|
+
_scrollRight = new WeakMap();
|
|
4067
|
+
_updateScrollBtnState = new WeakMap();
|
|
4068
|
+
_updateIndicator = new WeakMap();
|
|
4069
|
+
_handleSegmentClick = new WeakMap();
|
|
4070
|
+
_updateSelectedFromValue = new WeakMap();
|
|
4071
|
+
GdsSegmentedControl.styles = [tokens, unsafeCSS5(segmented_control_style_default)];
|
|
4072
|
+
__decorateClass([
|
|
4073
|
+
property13({ type: Number, attribute: "seg-min-width" })
|
|
4074
|
+
], GdsSegmentedControl.prototype, "segMinWidth", 2);
|
|
4075
|
+
__decorateClass([
|
|
4076
|
+
property13()
|
|
4077
|
+
], GdsSegmentedControl.prototype, "size", 2);
|
|
4078
|
+
__decorateClass([
|
|
4079
|
+
property13()
|
|
4080
|
+
], GdsSegmentedControl.prototype, "value", 1);
|
|
4081
|
+
__decorateClass([
|
|
4082
|
+
state13()
|
|
4083
|
+
], GdsSegmentedControl.prototype, "_tStyles", 2);
|
|
4084
|
+
__decorateClass([
|
|
4085
|
+
query4("slot")
|
|
4086
|
+
], GdsSegmentedControl.prototype, "_elSlot", 2);
|
|
4087
|
+
__decorateClass([
|
|
4088
|
+
query4("#indicator")
|
|
4089
|
+
], GdsSegmentedControl.prototype, "_elIndicator", 2);
|
|
4090
|
+
__decorateClass([
|
|
4091
|
+
query4("#track")
|
|
4092
|
+
], GdsSegmentedControl.prototype, "_elTrack", 2);
|
|
4093
|
+
__decorateClass([
|
|
4094
|
+
query4("#segments")
|
|
4095
|
+
], GdsSegmentedControl.prototype, "_elSegments", 2);
|
|
4096
|
+
__decorateClass([
|
|
4097
|
+
state13()
|
|
4098
|
+
], GdsSegmentedControl.prototype, "_showPrevButton", 2);
|
|
4099
|
+
__decorateClass([
|
|
4100
|
+
state13()
|
|
4101
|
+
], GdsSegmentedControl.prototype, "_showNextButton", 2);
|
|
4102
|
+
__decorateClass([
|
|
4103
|
+
watch("segMinWidth")
|
|
4104
|
+
], GdsSegmentedControl.prototype, "_recalculateMinWidth", 1);
|
|
4105
|
+
GdsSegmentedControl = __decorateClass([
|
|
4106
|
+
gdsCustomElement("gds-segmented-control")
|
|
4107
|
+
], GdsSegmentedControl);
|
|
4108
|
+
|
|
4109
|
+
// libs/core/src/components/icon/icon.ts
|
|
4110
|
+
import { LitElement as LitElement8, unsafeCSS as unsafeCSS6 } from "lit";
|
|
4111
|
+
|
|
4112
|
+
// libs/core/src/components/icon/stem.styles.scss
|
|
4113
|
+
var stem_styles_default = `svg:not([display=none]) {
|
|
4114
|
+
contain: layout style;
|
|
4115
|
+
display: flex;
|
|
4116
|
+
height: 1lh;
|
|
4117
|
+
isolation: isolate;
|
|
4118
|
+
overflow: hidden;
|
|
4119
|
+
width: auto;
|
|
4120
|
+
}
|
|
4121
|
+
|
|
4122
|
+
symbol {
|
|
4123
|
+
fill: none;
|
|
4124
|
+
height: 24px;
|
|
4125
|
+
stroke: currentColor;
|
|
4126
|
+
stroke-linecap: round;
|
|
4127
|
+
stroke-linejoin: round;
|
|
4128
|
+
stroke-width: 2px;
|
|
4129
|
+
width: 24px;
|
|
4130
|
+
}`;
|
|
4131
|
+
|
|
4132
|
+
// libs/core/src/components/icon/icon.ts
|
|
4133
|
+
var GdsIcon = class extends LitElement8 {
|
|
4134
|
+
constructor() {
|
|
4135
|
+
super(...arguments);
|
|
4136
|
+
this.open = false;
|
|
4137
|
+
this.name = "";
|
|
4138
|
+
}
|
|
4139
|
+
static get styles() {
|
|
4140
|
+
return unsafeCSS6(stem_styles_default);
|
|
4141
|
+
}
|
|
4142
|
+
render() {
|
|
4143
|
+
const { name } = this;
|
|
4144
|
+
return html`
|
|
4145
|
+
<svg display="none">
|
|
4146
|
+
<symbol id="plus">
|
|
4147
|
+
<line x1="12" y1="5" x2="12" y2="19" />
|
|
4148
|
+
<line x1="5" y1="12" x2="19" y2="12" />
|
|
4149
|
+
</symbol>
|
|
4150
|
+
<symbol id="x">
|
|
4151
|
+
<line x1="18" y1="6" x2="6" y2="18" />
|
|
4152
|
+
<line x1="6" y1="6" x2="18" y2="18" />
|
|
4153
|
+
</symbol>
|
|
4154
|
+
<symbol id="chevron-right">
|
|
4155
|
+
<polyline points="9 18 15 12 9 6" />
|
|
4156
|
+
</symbol>
|
|
4157
|
+
<symbol id="chevron-left">
|
|
4158
|
+
<polyline points="15 18 9 12 15 6" />
|
|
4159
|
+
</symbol>
|
|
4160
|
+
<symbol id="chevron-down">
|
|
4161
|
+
<polyline points="6 9 12 15 18 9" />
|
|
4162
|
+
</symbol>
|
|
4163
|
+
<symbol id="arrow">
|
|
4164
|
+
<line x1="5" y1="12" x2="19" y2="12" />
|
|
4165
|
+
<polyline points="12 5 19 12 12 19" />
|
|
4166
|
+
</symbol>
|
|
4167
|
+
<symbol id="bell">
|
|
4168
|
+
<path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9" />
|
|
4169
|
+
<path d="M13.73 21a2 2 0 0 1-3.46 0" />
|
|
4170
|
+
</symbol>
|
|
4171
|
+
<symbol id="calendar">
|
|
4172
|
+
<rect x="3" y="4" width="18" height="18" rx="2" ry="2" />
|
|
4173
|
+
<line x1="16" y1="2" x2="16" y2="6" />
|
|
4174
|
+
<line x1="8" y1="2" x2="8" y2="6" />
|
|
4175
|
+
<line x1="3" y1="10" x2="21" y2="10" />
|
|
4176
|
+
</symbol>
|
|
4177
|
+
<symbol id="lock">
|
|
4178
|
+
<rect x="3" y="11" width="18" height="11" rx="2" ry="2" />
|
|
4179
|
+
<path d="M7 11V7a5 5 0 0 1 10 0v4" />
|
|
4180
|
+
</symbol>
|
|
4181
|
+
<symbol id="eye">
|
|
4182
|
+
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
|
4183
|
+
<circle cx="12" cy="12" r="3" />
|
|
4184
|
+
</symbol>
|
|
4185
|
+
<symbol id="hash">
|
|
4186
|
+
<line x1="4" y1="9" x2="20" y2="9" />
|
|
4187
|
+
<line x1="4" y1="15" x2="20" y2="15" />
|
|
4188
|
+
<line x1="10" y1="3" x2="8" y2="21" />
|
|
4189
|
+
<line x1="16" y1="3" x2="14" y2="21" />
|
|
4190
|
+
</symbol>
|
|
4191
|
+
<symbol id="mail">
|
|
4192
|
+
<path
|
|
4193
|
+
d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"
|
|
4194
|
+
/>
|
|
4195
|
+
<polyline points="22,6 12,13 2,6" />
|
|
4196
|
+
</symbol>
|
|
4197
|
+
<symbol id="send">
|
|
4198
|
+
<line x1="22" y1="2" x2="11" y2="13" />
|
|
4199
|
+
<polygon points="22 2 15 22 11 13 2 9 22 2" />
|
|
4200
|
+
</symbol>
|
|
4201
|
+
<symbol id="info">
|
|
4202
|
+
<circle cx="12" cy="12" r="10" />
|
|
4203
|
+
<line x1="12" y1="16" x2="12" y2="12" />
|
|
4204
|
+
<line x1="12" y1="8" x2="12.01" y2="8" />
|
|
4205
|
+
</symbol>
|
|
4206
|
+
<symbol id="tel">
|
|
4207
|
+
<path
|
|
4208
|
+
d="M15.05 5A5 5 0 0 1 19 8.95M15.05 1A9 9 0 0 1 23 8.94m-1 7.98v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"
|
|
4209
|
+
/>
|
|
4210
|
+
</symbol>
|
|
4211
|
+
<symbol id="search">
|
|
4212
|
+
<circle cx="11" cy="11" r="8" />
|
|
4213
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
4214
|
+
</symbol>
|
|
4215
|
+
<symbol id="user">
|
|
4216
|
+
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
|
|
4217
|
+
<circle cx="12" cy="7" r="4" />
|
|
4218
|
+
</symbol>
|
|
4219
|
+
<symbol id="arrow-up">
|
|
4220
|
+
<line x1="12" y1="19" x2="12" y2="5" />
|
|
4221
|
+
<polyline points="5 12 12 5 19 12" />
|
|
4222
|
+
</symbol>
|
|
4223
|
+
<symbol id="arrow-down">
|
|
4224
|
+
<line x1="12" y1="5" x2="12" y2="19" />
|
|
4225
|
+
<polyline points="19 12 12 19 5 12" />
|
|
4226
|
+
</symbol>
|
|
4227
|
+
<symbol id="warning">
|
|
4228
|
+
<path
|
|
4229
|
+
d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"
|
|
4230
|
+
/>
|
|
4231
|
+
<line x1="12" y1="9" x2="12" y2="13" />
|
|
4232
|
+
<path x1="12" y1="17" x2="12.01" y2="17" />
|
|
4233
|
+
</symbol>
|
|
4234
|
+
</svg>
|
|
4235
|
+
<svg viewBox="0 0 24 24">
|
|
4236
|
+
<use href="#${name}"></use>
|
|
4237
|
+
</svg>
|
|
4238
|
+
`;
|
|
4239
|
+
}
|
|
4240
|
+
};
|
|
4241
|
+
GdsIcon.properties = {
|
|
4242
|
+
open: { type: String, reflect: true },
|
|
4243
|
+
name: { type: String }
|
|
4244
|
+
};
|
|
4245
|
+
GdsIcon = __decorateClass([
|
|
4246
|
+
gdsCustomElement("gds-icon")
|
|
4247
|
+
], GdsIcon);
|
|
3593
4248
|
export {
|
|
3594
4249
|
GdsContextMenu,
|
|
3595
4250
|
GdsDatepicker,
|
|
3596
4251
|
GdsDropdown,
|
|
3597
4252
|
GdsGrid,
|
|
3598
4253
|
GdsGroupedList,
|
|
4254
|
+
GdsIcon,
|
|
3599
4255
|
GdsMenuHeading,
|
|
3600
4256
|
GdsMenuItem,
|
|
3601
4257
|
GdsOption,
|
|
4258
|
+
GdsSegmentedControl,
|
|
3602
4259
|
VER_SUFFIX,
|
|
3603
4260
|
gdsCustomElement,
|
|
3604
4261
|
getScopedTagName,
|