@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.
Files changed (124) hide show
  1. package/README.md +101 -7
  2. package/chunks/chunk.2LQSDOD4.js +29 -0
  3. package/chunks/chunk.2ND5EWHE.js +65 -0
  4. package/chunks/chunk.2OOTOCUG.js +420 -0
  5. package/chunks/chunk.2WO4NHJ2.js +34 -0
  6. package/chunks/chunk.2Y3BHFKO.js +154 -0
  7. package/chunks/chunk.375BWME4.js +29 -0
  8. package/chunks/chunk.5VURDMKE.js +75 -0
  9. package/chunks/chunk.63RKNI5K.js +244 -0
  10. package/chunks/chunk.6NM7ENKA.js +31 -0
  11. package/chunks/chunk.6UA66KQU.js +153 -0
  12. package/chunks/chunk.7TCXY7BP.js +0 -0
  13. package/chunks/chunk.AQGTMWG4.js +101 -0
  14. package/chunks/chunk.D7H7CUS4.js +55 -0
  15. package/chunks/chunk.DFYMYEGD.js +78 -0
  16. package/chunks/chunk.EUQ5DOQM.js +560 -0
  17. package/chunks/chunk.HS7ICQNA.js +0 -0
  18. package/chunks/chunk.IYCENQZG.js +28 -0
  19. package/chunks/chunk.KC32OWZE.js +274 -0
  20. package/chunks/chunk.LUHCF4BJ.js +64 -0
  21. package/chunks/chunk.MAD5DQMN.js +161 -0
  22. package/chunks/chunk.MI4A2C2A.js +0 -0
  23. package/chunks/chunk.Q2T57HE7.js +0 -0
  24. package/chunks/chunk.QONSFT2N.js +4653 -0
  25. package/chunks/chunk.TMBQL2RO.js +0 -0
  26. package/chunks/chunk.TN6ZYAH3.js +74 -0
  27. package/chunks/chunk.TSDZQZBY.js +0 -0
  28. package/chunks/chunk.TX64TTBN.js +0 -0
  29. package/chunks/chunk.U4DPJ4QU.js +96 -0
  30. package/chunks/chunk.UF6IEONX.js +0 -0
  31. package/chunks/chunk.VOYMQ322.js +61 -0
  32. package/chunks/chunk.VYK7D6QO.js +64 -0
  33. package/chunks/chunk.WDZ2JTCP.js +360 -0
  34. package/chunks/chunk.WJDR7FTS.js +193 -0
  35. package/chunks/chunk.WM7HBMMV.js +54 -0
  36. package/chunks/chunk.XD5R3ZU3.js +460 -0
  37. package/chunks/chunk.XHTJVQUJ.js +140 -0
  38. package/chunks/chunk.XI4H54TV.js +39 -0
  39. package/chunks/chunk.XMPBXAGB.js +80 -0
  40. package/chunks/chunk.XU4HZLJL.js +0 -0
  41. package/chunks/chunk.YIQIH4RW.js +139 -0
  42. package/chunks/chunk.YJHAKLGR.js +54 -0
  43. package/chunks/chunk.YO24ZYAD.js +0 -0
  44. package/chunks/chunk.ZTE73BY2.js +655 -0
  45. package/chunks/chunk.ZYQWZMVY.js +467 -0
  46. package/components/badge/badge.js +245 -0
  47. package/components/button/button.d.ts +5 -5
  48. package/components/button/button.js +18 -0
  49. package/components/button/button.trans.styles.d.ts +2 -0
  50. package/components/button/index.d.ts +1 -0
  51. package/components/button/index.js +18 -0
  52. package/components/checkbox/checkbox.js +219 -0
  53. package/components/context-menu/context-menu.d.ts +2 -1
  54. package/components/context-menu/context-menu.js +22 -0
  55. package/components/context-menu/index.d.ts +3 -0
  56. package/components/context-menu/index.js +29 -0
  57. package/components/datepicker/date-part-spinner.js +10 -0
  58. package/components/datepicker/datepicker.d.ts +3 -2
  59. package/components/datepicker/datepicker.js +29 -0
  60. package/components/datepicker/index.d.ts +1 -0
  61. package/components/datepicker/index.js +29 -0
  62. package/components/dropdown/dropdown.d.ts +2 -2
  63. package/components/dropdown/dropdown.js +22 -0
  64. package/components/dropdown/index.d.ts +3 -0
  65. package/components/dropdown/index.js +30 -0
  66. package/components/form-control.js +12 -0
  67. package/components/grid/grid.d.ts +2 -2
  68. package/components/grid/grid.js +11 -0
  69. package/components/grid/grid.style.css.js +7 -0
  70. package/components/grid/index.d.ts +1 -0
  71. package/components/grid/index.js +11 -0
  72. package/components/grouped-list/grouped-list.js +14 -0
  73. package/components/grouped-list/index.d.ts +2 -0
  74. package/components/grouped-list/index.js +17 -0
  75. package/components/grouped-list/list-item.js +10 -0
  76. package/components/icon/icon.d.ts +2 -2
  77. package/components/icon/icon.js +10 -0
  78. package/components/icon/index.d.ts +1 -0
  79. package/components/icon/index.js +10 -0
  80. package/components/index.d.ts +4 -3
  81. package/components/index.js +81 -0
  82. package/components/input/input.js +682 -0
  83. package/components/radio/radio-group.js +9 -0
  84. package/components/radio/radio.js +240 -0
  85. package/components/segmented-control/index.d.ts +1 -0
  86. package/components/segmented-control/index.js +15 -0
  87. package/components/segmented-control/segment/index.d.ts +1 -0
  88. package/components/segmented-control/segment/index.js +13 -0
  89. package/components/segmented-control/segment/segment.js +12 -0
  90. package/components/segmented-control/segmented-control.d.ts +1 -1
  91. package/components/segmented-control/segmented-control.js +15 -0
  92. package/components/switch/switch.js +164 -0
  93. package/components/theme/index.d.ts +1 -0
  94. package/components/theme/index.js +11 -0
  95. package/components/theme/theme.js +11 -0
  96. package/components/tooltip/tooltip.js +252 -0
  97. package/index.js +72 -4291
  98. package/localization.js +3 -5
  99. package/package.json +7 -16
  100. package/primitives/calendar/calendar.js +13 -0
  101. package/primitives/calendar/functions.js +7 -0
  102. package/primitives/calendar/index.d.ts +1 -0
  103. package/primitives/calendar/index.js +14 -0
  104. package/primitives/listbox/index.d.ts +0 -1
  105. package/primitives/listbox/index.js +17 -0
  106. package/primitives/listbox/listbox.d.ts +2 -1
  107. package/primitives/listbox/listbox.js +16 -0
  108. package/primitives/listbox/option.js +14 -0
  109. package/primitives/menu/index.d.ts +1 -0
  110. package/primitives/menu/index.js +15 -0
  111. package/primitives/menu/menu-heading.js +11 -0
  112. package/primitives/menu/menu-item.d.ts +1 -2
  113. package/primitives/menu/menu-item.js +12 -0
  114. package/primitives/menu/menu.d.ts +2 -1
  115. package/primitives/menu/menu.js +14 -0
  116. package/primitives/popover/index.js +14 -0
  117. package/primitives/popover/popover.js +13 -0
  118. package/primitives/ripple/index.d.ts +1 -0
  119. package/primitives/ripple/index.js +11 -0
  120. package/primitives/ripple/ripple.d.ts +1 -1
  121. package/primitives/ripple/ripple.js +10 -0
  122. package/scoping.d.ts +1 -0
  123. package/scoping.js +18 -0
  124. package/transitional-styles.js +6 -4275
package/README.md CHANGED
@@ -15,19 +15,113 @@ npm install @sebgroup/green-core
15
15
 
16
16
  ## Use
17
17
 
18
- ```js
19
- import { GdsButton } from '@sebgroup/green-core'
20
- import { transitionalStyles } from '@sebgroup/green-core/transitional-styles'
18
+ There are three main ways you can use Green Core:
21
19
 
22
- //register transitional styles to get SEB's current visual design
23
- transitionalStyles()
20
+ - With Lit
21
+ - With Angular
22
+ - With React
23
+
24
+ But that said, the components in Green Core are just regular Web Components, so you can use them with or without any framework.
25
+
26
+ ### Using Lit
27
+
28
+ ```ts
29
+ import { css, customElement, LitElement } from 'lit'
30
+
31
+ // This custom `html` template literal tag from Green Core extends the default `lit-html` tag to handle element version scoping.
32
+ import { html } from '@sebgroup/green-core/scoping'
33
+
34
+ // Trtansitional styles applies the current 2016 design language to the components
35
+ import { registerTransitionalStyles } from '@sebgroup/green-core/transitional-styles'
36
+
37
+ // Import the components that you need
38
+ import '@sebgroup/green-core/components/button/index.js'
39
+
40
+ @customElement('my-app')
41
+ export class MyApp extends LitElement {
42
+ static styles = css``
43
+
44
+ connectedCallback() {
45
+ super.connectedCallback()
46
+
47
+ // Register transitional styles to get SEB's current visual design
48
+ registerTransitionalStyles()
49
+ }
50
+
51
+ render() {
52
+ return html`<gds-button>Click me!</gds-button>`
53
+ }
54
+ }
55
+ ```
56
+
57
+ ### Using Angular
58
+
59
+ Angular has support for using web components directly in the template. To enable it, you need to do the following:
60
+
61
+ Add the `CUSTOM_ELEMENTS_SCHEMA` in the module where you plan to use the components. It is recommended to add this as locally as possible, only on the moduls/components where you need it, and not in the app module.
62
+
63
+ You also need the `NggCoreWrapperModule` from `@sebgroup/green-angular`.
64
+
65
+ In your module:
66
+
67
+ ```ts
68
+ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
69
+ import { NggCoreWrapperModule } from '@sebgroup/green-angular'
70
+
71
+ @NgModule({
72
+ // Add the NggCoreWrapperModule to the `imports` array
73
+ imports: [NggCoreWrapperModule],
74
+ // Add the CUSTOM_ELEMENTS_SCHEMA to the `schemas` array
75
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
76
+ })
77
+ ```
78
+
79
+ In your component:
80
+
81
+ ```ts
82
+ import '@sebgroup/green-core/components/button/index.js'
83
+
84
+ // Transitional styles
85
+ import { registerTransitionalStyles } from '@sebgroup/green-core/transitional-styles'
86
+ registerTransitionalStyles()
24
87
  ```
25
88
 
89
+ Use the webcomponent in your template with the `*nggCoreElement` directive.
90
+
91
+ In your template:
92
+
26
93
  ```html
27
- <!-- Then use the component in your html -->
28
- <gds-button>Click me</gds-button>
94
+ <gds-button *nggCoreElement>Click me!</gds-button>
29
95
  ```
30
96
 
97
+ The `*nggCoreElement` directive comes from the `NggCoreWrapperModule` you imported above. It has the same pupose as the custom html template tag mentioned in the Lit example above: It handles custom element scoping for you.
98
+
99
+ ### Using React
100
+
101
+ In most cases, we already exort React wrappers for these components from the `@sebgroup/green-react` package. In those cases you can just use those. But you can also easily create your own wrappers using `@lit/react`.
102
+
103
+ Here is an example:
104
+
105
+ ```ts
106
+ import React from 'react'
107
+ import { createComponent } from '@lit/react'
108
+
109
+ import { GdsButton } from '@sebgroup/green-core/component/button/index.js'
110
+ import { getScopedTagName } from '@sebgroup/green-core/scoping'
111
+ import { registerTransitionalStyles } from '@sebgroup/green-core/transitional-styles'
112
+
113
+ registerTransitionalStyles()
114
+
115
+ export const Button = createComponent({
116
+ tagName: getScopedTagName('gds-button'),
117
+ elementClass: GdsButton,
118
+ react: React,
119
+ events: { onClick: 'click' }, // Event callbacks need to be explicitly mapped to DOM events
120
+ })
121
+ ```
122
+
123
+ Then you can just use `<Button />` like a regular React component.
124
+
31
125
  ## Documentation
32
126
 
33
127
  Check out the [Storybook (@sebgroup/core)](https://sebgroup.github.io/green/latest/core/) for components and documentation.
@@ -0,0 +1,29 @@
1
+ import {
2
+ getUnscopedTagName
3
+ } from "./chunk.VOYMQ322.js";
4
+
5
+ // libs/core/src/gds-element.ts
6
+ import { LitElement } from "lit";
7
+ var GdsElement = class extends LitElement {
8
+ constructor() {
9
+ super(...arguments);
10
+ /**
11
+ * The unscoped name of this element.
12
+ */
13
+ this.gdsElementName = "";
14
+ /**
15
+ * Whether the element is using transitional styles.
16
+ * @internal
17
+ */
18
+ this._isUsingTransitionalStyles = false;
19
+ }
20
+ connectedCallback() {
21
+ super.connectedCallback();
22
+ this.gdsElementName = getUnscopedTagName(this.tagName.toLowerCase()) || this.gdsElementName;
23
+ this.setAttribute("gds-element", this.gdsElementName);
24
+ }
25
+ };
26
+
27
+ export {
28
+ GdsElement
29
+ };
@@ -0,0 +1,65 @@
1
+ // libs/core/src/primitives/listbox/option.styles.ts
2
+ import { css } from "lit";
3
+ var style = css`
4
+ @layer base, reset, transitional-styles;
5
+ @layer base {
6
+ :host {
7
+ display: block;
8
+ padding: 1rem 1.5rem;
9
+ cursor: pointer;
10
+ }
11
+
12
+ :host(:not(:last-child)) {
13
+ border-bottom: 1px solid #e0e0e0;
14
+ }
15
+
16
+ :host(:hover) {
17
+ background-color: #ededed;
18
+ }
19
+
20
+ :host(:focus-visible) {
21
+ outline: auto;
22
+ outline-offset: -6px;
23
+ outline-color: #666;
24
+ }
25
+ }
26
+ `;
27
+ var option_styles_default = style;
28
+
29
+ // libs/core/src/mixins/focusable.ts
30
+ var Focusable = (superClass) => {
31
+ class HighlightableElement extends superClass {
32
+ constructor() {
33
+ super(...arguments);
34
+ this.onblur = (e) => {
35
+ this.setAttribute("tabindex", "-1");
36
+ this.dispatchEvent(
37
+ new FocusEvent("gds-blur", {
38
+ bubbles: true,
39
+ composed: true,
40
+ relatedTarget: e.relatedTarget
41
+ })
42
+ );
43
+ };
44
+ this.onfocus = (e) => {
45
+ this.dispatchEvent(
46
+ new FocusEvent("gds-focus", {
47
+ bubbles: true,
48
+ composed: true,
49
+ relatedTarget: e.relatedTarget
50
+ })
51
+ );
52
+ };
53
+ }
54
+ focus(options) {
55
+ this.setAttribute("tabindex", "0");
56
+ super.focus(options);
57
+ }
58
+ }
59
+ return HighlightableElement;
60
+ };
61
+
62
+ export {
63
+ option_styles_default,
64
+ Focusable
65
+ };
@@ -0,0 +1,420 @@
1
+ import {
2
+ GdsFormControlElement
3
+ } from "./chunk.YIQIH4RW.js";
4
+ import {
5
+ TransitionalStyles
6
+ } from "./chunk.QONSFT2N.js";
7
+ import {
8
+ observeLightDOM
9
+ } from "./chunk.WM7HBMMV.js";
10
+ import {
11
+ constrainSlots
12
+ } from "./chunk.6NM7ENKA.js";
13
+ import {
14
+ watch
15
+ } from "./chunk.2WO4NHJ2.js";
16
+ import {
17
+ gdsCustomElement,
18
+ getScopedTagName,
19
+ html
20
+ } from "./chunk.VOYMQ322.js";
21
+ import {
22
+ __decorateClass,
23
+ __privateAdd,
24
+ __privateGet,
25
+ __privateMethod,
26
+ __privateSet
27
+ } from "./chunk.5VURDMKE.js";
28
+
29
+ // libs/core/src/components/dropdown/dropdown.ts
30
+ import { property, query, queryAsync, state } from "lit/decorators.js";
31
+ import { unsafeHTML } from "lit/directives/unsafe-html.js";
32
+ import { when } from "lit/directives/when.js";
33
+ import { ifDefined } from "lit/directives/if-defined.js";
34
+ import { classMap } from "lit/directives/class-map.js";
35
+ import { msg, str, updateWhenLocaleChanges } from "@lit/localize";
36
+ import "reflect-metadata";
37
+
38
+ // libs/core/src/components/dropdown/dropdown.styles.ts
39
+ import { css } from "lit";
40
+ var style = css`
41
+ @layer base, reset, transitional-styles;
42
+
43
+ @layer base {
44
+ button {
45
+ appearance: none;
46
+ display: block;
47
+ background-color: black;
48
+ border-radius: 2rem;
49
+ border: none;
50
+ color: white;
51
+ padding: 0.7rem 2rem;
52
+ margin: 0.5rem 0;
53
+ box-sizing: border-box;
54
+ }
55
+ }
56
+ `;
57
+ var dropdown_styles_default = style;
58
+
59
+ // libs/core/src/components/dropdown/dropdown.ts
60
+ var _optionElements, _handleSearchFieldKeyUp, _handleSearchFieldKeyDown, _handleListboxKeyDown, _handleOptionFocusChange, _handleSelectionChange, handleSelectionChange_fn, _registerAutoCloseListener, registerAutoCloseListener_fn, _unregisterAutoCloseListener, unregisterAutoCloseListener_fn, _blurCloseListener, _tabCloseListener;
61
+ var GdsDropdown = class extends GdsFormControlElement {
62
+ constructor() {
63
+ super();
64
+ /**
65
+ * Selects an option in the dropdown.
66
+ *
67
+ * @fires change
68
+ */
69
+ __privateAdd(this, _handleSelectionChange);
70
+ __privateAdd(this, _registerAutoCloseListener);
71
+ __privateAdd(this, _unregisterAutoCloseListener);
72
+ this.label = "";
73
+ this.open = false;
74
+ this.searchable = false;
75
+ this.multiple = false;
76
+ this.compareWith = (a, b) => a === b;
77
+ this.searchFilter = (q, o) => o.innerHTML.toLowerCase().includes(q.toLowerCase());
78
+ this.syncPopoverWidth = false;
79
+ this.maxHeight = 500;
80
+ this.size = "medium";
81
+ this.hideLabel = false;
82
+ __privateAdd(this, _optionElements, void 0);
83
+ /**
84
+ * Event handler for filtering the options in the dropdown.
85
+ *
86
+ * @param e The keyboard event.
87
+ */
88
+ __privateAdd(this, _handleSearchFieldKeyUp, (e) => {
89
+ const input = this._elSearchInput;
90
+ const options = Array.from(__privateGet(this, _optionElements));
91
+ options.forEach((o) => o.hidden = false);
92
+ if (!input.value)
93
+ return;
94
+ const filteredOptions = options.filter(
95
+ (o) => !this.searchFilter(input.value, o)
96
+ );
97
+ filteredOptions.forEach((o) => o.hidden = true);
98
+ });
99
+ /**
100
+ * Check for ArrowDown or Tab in the search field.
101
+ * If found, focus should be moved to the listbox.
102
+ */
103
+ __privateAdd(this, _handleSearchFieldKeyDown, (e) => {
104
+ var _a;
105
+ (_a = this._elListbox) == null ? void 0 : _a.then((listbox) => {
106
+ if (e.key === "ArrowDown" || e.key === "Tab") {
107
+ e.preventDefault();
108
+ listbox.focus();
109
+ return;
110
+ }
111
+ });
112
+ });
113
+ /**
114
+ * Check for Tab in the listbox.
115
+ * If found, focus should be moved to the search field.
116
+ */
117
+ __privateAdd(this, _handleListboxKeyDown, (e) => {
118
+ var _a;
119
+ if (e.key === "Tab" && this.searchable) {
120
+ e.preventDefault();
121
+ (_a = this._elSearchInput) == null ? void 0 : _a.focus();
122
+ return;
123
+ }
124
+ });
125
+ __privateAdd(this, _handleOptionFocusChange, (e) => {
126
+ const triggerButton = this._elTriggerBtn;
127
+ if (triggerButton)
128
+ triggerButton.ariaActiveDescendantElement = e.target;
129
+ });
130
+ /**
131
+ * A listener to close the dropdown when any other element is focused.
132
+ */
133
+ __privateAdd(this, _blurCloseListener, (e) => {
134
+ const isFocusOutside = e instanceof FocusEvent && e.relatedTarget && !this.contains(e.relatedTarget);
135
+ if (isFocusOutside)
136
+ this.open = false;
137
+ });
138
+ __privateAdd(this, _tabCloseListener, (e) => {
139
+ var _a;
140
+ if (e.key === "Tab" && !this.searchable) {
141
+ e.preventDefault();
142
+ this.open = false;
143
+ (_a = this._elTriggerBtn) == null ? void 0 : _a.focus();
144
+ }
145
+ });
146
+ constrainSlots(this);
147
+ updateWhenLocaleChanges(this);
148
+ __privateSet(this, _optionElements, this.getElementsByTagName(
149
+ getScopedTagName("gds-option")
150
+ ));
151
+ }
152
+ get type() {
153
+ return "gds-dropdown";
154
+ }
155
+ /**
156
+ * Get the options of the dropdown.
157
+ */
158
+ get options() {
159
+ return Array.from(__privateGet(this, _optionElements)).filter(
160
+ (o) => !o.hasAttribute("isplaceholder")
161
+ );
162
+ }
163
+ /**
164
+ * Return the first option with a isPlaceholder attribute.
165
+ * If no placeholder is found, this will be undefined.
166
+ */
167
+ get placeholder() {
168
+ return Array.from(__privateGet(this, _optionElements)).find(
169
+ (o) => o.hasAttribute("isplaceholder")
170
+ );
171
+ }
172
+ /**
173
+ * Returns the display value as a string.
174
+ * If the dropdown is in multiple mode, this will be a comma separated list of the selected values.
175
+ */
176
+ get displayValue() {
177
+ var _a, _b;
178
+ let displayValue;
179
+ if (Array.isArray(this.value)) {
180
+ this.value.length > 2 ? displayValue = msg(str`${this.value.length} selected`) : displayValue = this.value.reduce(
181
+ (acc, cur) => {
182
+ var _a2;
183
+ return acc + ((_a2 = this.options.find((v) => v.value === cur)) == null ? void 0 : _a2.innerHTML) + ", ";
184
+ },
185
+ ""
186
+ ).slice(0, -2);
187
+ } else {
188
+ displayValue = (_a = this.options.find((v) => v.selected)) == null ? void 0 : _a.innerHTML;
189
+ }
190
+ return displayValue || ((_b = this.placeholder) == null ? void 0 : _b.innerHTML) || "";
191
+ }
192
+ connectedCallback() {
193
+ super.connectedCallback();
194
+ TransitionalStyles.instance.apply(this, "gds-dropdown");
195
+ this.updateComplete.then(() => {
196
+ this._handleLightDOMChange();
197
+ this._handleValueChange();
198
+ });
199
+ }
200
+ render() {
201
+ return html`
202
+ ${this._tStyles}
203
+ ${when(
204
+ this.label && !this.hideLabel,
205
+ () => html`<label for="trigger">${this.label}</label>`
206
+ )}
207
+
208
+ <span class="form-info"><slot name="sub-label"></slot></span>
209
+
210
+ <button
211
+ id="trigger"
212
+ @click="${() => this.open = !this.open}"
213
+ aria-haspopup="listbox"
214
+ role="combobox"
215
+ aria-owns="listbox"
216
+ aria-controls="listbox"
217
+ aria-expanded="${this.open}"
218
+ aria-label="${this.label}"
219
+ class=${classMap({ small: this.size === "small" })}
220
+ >
221
+ <slot name="trigger">
222
+ <span>${unsafeHTML(this.displayValue)}</span>
223
+ </slot>
224
+ </button>
225
+
226
+ <span class="form-info"><slot name="message"></slot></span>
227
+
228
+ <gds-popover
229
+ .label=${this.label}
230
+ .open=${this.open}
231
+ .triggerRef=${this._elTriggerBtnAsync}
232
+ .calcMaxWidth=${(trigger) => this.syncPopoverWidth ? `${trigger.offsetWidth}px` : `auto`}
233
+ .calcMaxHeight=${(_trigger) => `${this.maxHeight}px`}
234
+ @gds-ui-state=${(e) => this.open = e.detail.open}
235
+ >
236
+ ${when(
237
+ this.searchable,
238
+ () => html`<input
239
+ id="searchinput"
240
+ type="text"
241
+ aria-label="${msg("Filter available options")}"
242
+ placeholder="${msg("Search")}"
243
+ @keydown=${__privateGet(this, _handleSearchFieldKeyDown)}
244
+ @keyup=${__privateGet(this, _handleSearchFieldKeyUp)}
245
+ />`
246
+ )}
247
+
248
+ <gds-listbox
249
+ id="listbox"
250
+ .multiple="${ifDefined(this.multiple)}"
251
+ .compareWith="${this.compareWith}"
252
+ @change="${__privateMethod(this, _handleSelectionChange, handleSelectionChange_fn)}"
253
+ @gds-focus="${__privateGet(this, _handleOptionFocusChange)}"
254
+ @keydown=${__privateGet(this, _handleListboxKeyDown)}
255
+ >
256
+ <slot gds-allow="gds-option gds-menu-heading"></slot>
257
+ </gds-listbox>
258
+ </gds-popover>
259
+ `;
260
+ }
261
+ _handleLightDOMChange() {
262
+ var _a, _b;
263
+ this.requestUpdate();
264
+ if (this.multiple) {
265
+ this._handleValueChange();
266
+ return;
267
+ }
268
+ if (this.value === void 0) {
269
+ if (this.placeholder)
270
+ this.value = this.placeholder.value;
271
+ else
272
+ this.value = (_a = this.options[0]) == null ? void 0 : _a.value;
273
+ } else if (!this.placeholder && this.options.find(
274
+ (o) => this.compareWith(o.value, this.value)
275
+ ) === void 0) {
276
+ this.options[0] && (this.options[0].selected = true);
277
+ this.value = (_b = this.options[0]) == null ? void 0 : _b.value;
278
+ }
279
+ }
280
+ _handleValueChange() {
281
+ this._elListbox.then((listbox) => {
282
+ if (listbox) {
283
+ if (Array.isArray(this.value))
284
+ listbox.selection = this.value;
285
+ else
286
+ listbox.selection = [this.value];
287
+ }
288
+ });
289
+ }
290
+ _onOpenChange() {
291
+ const open = this.open;
292
+ Array.from(__privateGet(this, _optionElements)).forEach((o) => o.hidden = !open);
293
+ if (open)
294
+ __privateMethod(this, _registerAutoCloseListener, registerAutoCloseListener_fn).call(this);
295
+ else {
296
+ __privateMethod(this, _unregisterAutoCloseListener, unregisterAutoCloseListener_fn).call(this);
297
+ this._elSearchInput && (this._elSearchInput.value = "");
298
+ }
299
+ this.dispatchEvent(
300
+ new CustomEvent("gds-ui-state", {
301
+ detail: { open },
302
+ bubbles: true,
303
+ composed: true
304
+ })
305
+ );
306
+ }
307
+ };
308
+ _optionElements = new WeakMap();
309
+ _handleSearchFieldKeyUp = new WeakMap();
310
+ _handleSearchFieldKeyDown = new WeakMap();
311
+ _handleListboxKeyDown = new WeakMap();
312
+ _handleOptionFocusChange = new WeakMap();
313
+ _handleSelectionChange = new WeakSet();
314
+ handleSelectionChange_fn = function() {
315
+ this._elListbox.then((listbox) => {
316
+ var _a;
317
+ if (this.multiple)
318
+ this.value = listbox.selection.map((s) => s.value);
319
+ else {
320
+ this.value = (_a = listbox.selection[0]) == null ? void 0 : _a.value;
321
+ this.open = false;
322
+ setTimeout(() => {
323
+ var _a2;
324
+ return (_a2 = this._elTriggerBtn) == null ? void 0 : _a2.focus();
325
+ }, 0);
326
+ }
327
+ this.dispatchEvent(
328
+ new CustomEvent("change", {
329
+ detail: { value: this.value },
330
+ bubbles: true,
331
+ composed: true
332
+ })
333
+ );
334
+ });
335
+ };
336
+ _registerAutoCloseListener = new WeakSet();
337
+ registerAutoCloseListener_fn = function() {
338
+ this.addEventListener("blur", __privateGet(this, _blurCloseListener));
339
+ this.addEventListener("gds-blur", __privateGet(this, _blurCloseListener));
340
+ this.addEventListener("keydown", __privateGet(this, _tabCloseListener));
341
+ };
342
+ _unregisterAutoCloseListener = new WeakSet();
343
+ unregisterAutoCloseListener_fn = function() {
344
+ this.removeEventListener("blur", __privateGet(this, _blurCloseListener));
345
+ this.removeEventListener("gds-blur", __privateGet(this, _blurCloseListener));
346
+ this.removeEventListener("keydown", __privateGet(this, _tabCloseListener));
347
+ };
348
+ _blurCloseListener = new WeakMap();
349
+ _tabCloseListener = new WeakMap();
350
+ GdsDropdown.styles = dropdown_styles_default;
351
+ GdsDropdown.shadowRootOptions = {
352
+ mode: "open",
353
+ delegatesFocus: true
354
+ };
355
+ __decorateClass([
356
+ property()
357
+ ], GdsDropdown.prototype, "label", 2);
358
+ __decorateClass([
359
+ property({ type: Boolean, reflect: true })
360
+ ], GdsDropdown.prototype, "open", 2);
361
+ __decorateClass([
362
+ property({ type: Boolean, reflect: true })
363
+ ], GdsDropdown.prototype, "searchable", 2);
364
+ __decorateClass([
365
+ property({ type: Boolean, reflect: true })
366
+ ], GdsDropdown.prototype, "multiple", 2);
367
+ __decorateClass([
368
+ property()
369
+ ], GdsDropdown.prototype, "compareWith", 2);
370
+ __decorateClass([
371
+ property()
372
+ ], GdsDropdown.prototype, "searchFilter", 2);
373
+ __decorateClass([
374
+ property({ type: Boolean, attribute: "sync-popover-width" })
375
+ ], GdsDropdown.prototype, "syncPopoverWidth", 2);
376
+ __decorateClass([
377
+ property({ type: Number, attribute: "max-height" })
378
+ ], GdsDropdown.prototype, "maxHeight", 2);
379
+ __decorateClass([
380
+ property()
381
+ ], GdsDropdown.prototype, "size", 2);
382
+ __decorateClass([
383
+ property({ type: Boolean, attribute: "hide-label" })
384
+ ], GdsDropdown.prototype, "hideLabel", 2);
385
+ __decorateClass([
386
+ state()
387
+ ], GdsDropdown.prototype, "_tStyles", 2);
388
+ __decorateClass([
389
+ query("#trigger")
390
+ ], GdsDropdown.prototype, "_elTriggerBtn", 2);
391
+ __decorateClass([
392
+ queryAsync("#trigger")
393
+ ], GdsDropdown.prototype, "_elTriggerBtnAsync", 2);
394
+ __decorateClass([
395
+ queryAsync("#listbox")
396
+ ], GdsDropdown.prototype, "_elListbox", 2);
397
+ __decorateClass([
398
+ query("#searchinput")
399
+ ], GdsDropdown.prototype, "_elSearchInput", 2);
400
+ __decorateClass([
401
+ observeLightDOM({
402
+ attributes: true,
403
+ childList: true,
404
+ subtree: true,
405
+ characterData: true
406
+ })
407
+ ], GdsDropdown.prototype, "_handleLightDOMChange", 1);
408
+ __decorateClass([
409
+ watch("value")
410
+ ], GdsDropdown.prototype, "_handleValueChange", 1);
411
+ __decorateClass([
412
+ watch("open")
413
+ ], GdsDropdown.prototype, "_onOpenChange", 1);
414
+ GdsDropdown = __decorateClass([
415
+ gdsCustomElement("gds-dropdown")
416
+ ], GdsDropdown);
417
+
418
+ export {
419
+ GdsDropdown
420
+ };
@@ -0,0 +1,34 @@
1
+ import {
2
+ __spreadValues
3
+ } from "./chunk.5VURDMKE.js";
4
+
5
+ // libs/core/src/utils/decorators/watch.ts
6
+ function watch(propertyName, options) {
7
+ const resolvedOptions = __spreadValues({
8
+ waitUntilFirstUpdate: false
9
+ }, options);
10
+ return (proto, propertyKey, descriptor) => {
11
+ const { update } = proto;
12
+ const watchedProperties = Array.isArray(propertyName) ? propertyName : [propertyName];
13
+ proto.update = function(changedProps) {
14
+ watchedProperties.forEach((property) => {
15
+ var _a;
16
+ const key = property;
17
+ if (changedProps.has(key)) {
18
+ const oldValue = changedProps.get(key);
19
+ const newValue = this[key];
20
+ if (oldValue !== newValue) {
21
+ if (!resolvedOptions.waitUntilFirstUpdate || this.hasUpdated) {
22
+ (_a = descriptor.value) == null ? void 0 : _a.call(this, oldValue, newValue);
23
+ }
24
+ }
25
+ }
26
+ });
27
+ update.call(this, changedProps);
28
+ };
29
+ };
30
+ }
31
+
32
+ export {
33
+ watch
34
+ };