@sebgroup/green-core 1.5.1 → 1.6.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.
@@ -10,7 +10,7 @@ import { CSSResult } from 'lit';
10
10
  *
11
11
  * @status beta
12
12
  *
13
- * @slot - Options for the dropdown. Accepts `gds-option` elements.
13
+ * @slot - Options for the dropdown. Accepts `gds-option` and `gds-menu-heading` elements.
14
14
  * @slot button - The trigger button for the dropdown. Custom content for the button can be assigned through this slot.
15
15
  * @slot sub-label - Renders between the label and the trigger button.
16
16
  * @slot message - Renders below the trigger button. Will be red if there is a validation error.
@@ -1,5 +1,6 @@
1
1
  export * from './dropdown/dropdown';
2
2
  export * from '../primitives/listbox/option';
3
+ export * from '../primitives/menu/menu-heading';
3
4
  export * from './context-menu/context-menu';
4
5
  export * from '../primitives/menu/menu-item';
5
6
  export * from './datepicker/datepicker';
package/index.js CHANGED
@@ -143,10 +143,11 @@ function watchMediaQuery(q) {
143
143
  // libs/core/src/utils/helpers/custom-element-scoping.ts
144
144
  import { html as litHtml } from "lit";
145
145
  import { customElement } from "lit/decorators.js";
146
- var VER_SUFFIX = "-ea801b";
146
+ var VER_SUFFIX = "-f9a04d";
147
147
  var elementLookupTable = /* @__PURE__ */ new Map();
148
148
  var gdsCustomElement = (tagName) => {
149
149
  if (globalThis.GDS_DISABLE_VERSIONED_ELEMENTS) {
150
+ elementLookupTable.set(tagName, tagName);
150
151
  return customElement(tagName);
151
152
  }
152
153
  const versionedTagName = tagName + VER_SUFFIX;
@@ -419,7 +420,7 @@ var GdsListbox = class extends GdsElement {
419
420
  if (!__privateGet(this, _slotRef).value)
420
421
  return [];
421
422
  return unwrap(__privateGet(this, _slotRef).value).assignedElements().filter(
422
- (o) => !o.hasAttribute("isplaceholder")
423
+ (o) => !o.hasAttribute("isplaceholder") && o.gdsElementName === "gds-option"
423
424
  ) || [];
424
425
  }
425
426
  /**
@@ -1286,7 +1287,7 @@ var GdsDropdown = class extends GdsFormControlElement {
1286
1287
  @gds-focus="${__privateGet(this, _handleOptionFocusChange)}"
1287
1288
  @keydown=${__privateGet(this, _handleListboxKeyDown)}
1288
1289
  >
1289
- <slot gds-allow="gds-option"></slot>
1290
+ <slot gds-allow="gds-option gds-menu-heading"></slot>
1290
1291
  </gds-listbox>
1291
1292
  </gds-popover>
1292
1293
  `;
@@ -1434,6 +1435,44 @@ GdsDropdown = __decorateClass([
1434
1435
  gdsCustomElement("gds-dropdown")
1435
1436
  ], GdsDropdown);
1436
1437
 
1438
+ // libs/core/src/primitives/menu/menu-heading.ts
1439
+ import { html as html5 } from "lit";
1440
+
1441
+ // libs/core/src/primitives/menu/menu-heading.styles.ts
1442
+ import { css as css5 } from "lit";
1443
+ var style5 = css5`
1444
+ @layer base, reset, transitional-styles;
1445
+ @layer base {
1446
+ :host {
1447
+ padding: 0.5 1rem;
1448
+ cursor: pointer;
1449
+ }
1450
+
1451
+ :host(:hover) {
1452
+ background-color: grey;
1453
+ }
1454
+ }
1455
+ `;
1456
+ var menu_heading_styles_default = style5;
1457
+
1458
+ // libs/core/src/primitives/menu/menu-heading.ts
1459
+ var GdsMenuHeading = class extends GdsElement {
1460
+ connectedCallback() {
1461
+ super.connectedCallback();
1462
+ this.setAttribute("inert", "true");
1463
+ this.updateComplete.then(
1464
+ () => TransitionalStyles.instance.apply(this, "gds-menu-heading")
1465
+ );
1466
+ }
1467
+ render() {
1468
+ return html5`<slot></slot>`;
1469
+ }
1470
+ };
1471
+ GdsMenuHeading.styles = menu_heading_styles_default;
1472
+ GdsMenuHeading = __decorateClass([
1473
+ gdsCustomElement("gds-menu-heading")
1474
+ ], GdsMenuHeading);
1475
+
1437
1476
  // libs/core/src/components/context-menu/context-menu.ts
1438
1477
  import { nothing } from "lit";
1439
1478
  import { msg as msg3 } from "@lit/localize";
@@ -1459,7 +1498,7 @@ var GdsMenu = class extends GdsElement {
1459
1498
  if (!this.#slotRef.value)
1460
1499
  return [];
1461
1500
  return unwrap(this.#slotRef.value).assignedElements().filter(
1462
- (o) => !o.hasAttribute("isplaceholder")
1501
+ (o) => !o.hasAttribute("isplaceholder") && o.gdsElementName === "gds-menu-item"
1463
1502
  ) || [];
1464
1503
  }
1465
1504
  /**
@@ -1531,7 +1570,7 @@ var GdsContextMenu = class extends GdsElement {
1531
1570
  aria-label=${this.label ?? this.buttonLabel}
1532
1571
  @gds-menu-item-click=${__privateMethod(this, _handleItemClick, handleItemClick_fn)}
1533
1572
  >
1534
- <slot allow="gds-menu-item"></slot>
1573
+ <slot allow="gds-menu-item gds-menu-heading"></slot>
1535
1574
  </gds-menu>
1536
1575
  </gds-popover>`;
1537
1576
  }
@@ -1622,7 +1661,7 @@ import { nothing as nothing2 } from "lit";
1622
1661
  import { msg as msg5 } from "@lit/localize";
1623
1662
 
1624
1663
  // libs/core/src/primitives/calendar/calendar.ts
1625
- import { html as html6 } from "lit";
1664
+ import { html as html7 } from "lit";
1626
1665
  import { classMap as classMap4 } from "lit/directives/class-map.js";
1627
1666
  import { when as when3 } from "lit/directives/when.js";
1628
1667
  import { property as property7, query as query2, state as state8 } from "lit/decorators.js";
@@ -1644,7 +1683,7 @@ import {
1644
1683
  eachWeekOfInterval,
1645
1684
  eachDayOfInterval
1646
1685
  } from "date-fns";
1647
- import { html as html5 } from "lit-html";
1686
+ import { html as html6 } from "lit-html";
1648
1687
  function renderMonthGridView(date, template) {
1649
1688
  const monthStart = startOfMonth(date);
1650
1689
  const monthEnd = endOfMonth(date);
@@ -1652,7 +1691,7 @@ function renderMonthGridView(date, template) {
1652
1691
  { start: monthStart, end: monthEnd },
1653
1692
  { weekStartsOn: 1 }
1654
1693
  );
1655
- return html5`${template(
1694
+ return html6`${template(
1656
1695
  weeks.map((weekStartDay) => ({
1657
1696
  days: eachDayOfInterval({
1658
1697
  start: weekStartDay,
@@ -1663,8 +1702,8 @@ function renderMonthGridView(date, template) {
1663
1702
  }
1664
1703
 
1665
1704
  // libs/core/src/primitives/calendar/calendar.styles.ts
1666
- import { css as css5 } from "lit";
1667
- var style5 = css5`
1705
+ import { css as css6 } from "lit";
1706
+ var style6 = css6`
1668
1707
  @layer base, reset, transitional-styles;
1669
1708
  @layer base {
1670
1709
  td.disabled {
@@ -1676,7 +1715,7 @@ var style5 = css5`
1676
1715
  }
1677
1716
  }
1678
1717
  `;
1679
- var calendar_styles_default = style5;
1718
+ var calendar_styles_default = style6;
1680
1719
 
1681
1720
  // libs/core/src/primitives/calendar/calendar.ts
1682
1721
  var _setSelectedDate, setSelectedDate_fn, _handleKeyDown, handleKeyDown_fn;
@@ -1720,11 +1759,11 @@ var GdsCalendar = class extends GdsElement {
1720
1759
  }
1721
1760
  render() {
1722
1761
  const currentDate = /* @__PURE__ */ new Date();
1723
- return html6`${this._tStyles}
1762
+ return html7`${this._tStyles}
1724
1763
  <table>
1725
1764
  <thead>
1726
1765
  <tr>
1727
- ${when3(this.showWeekNumbers, () => html6`<th></th>`)}
1766
+ ${when3(this.showWeekNumbers, () => html7`<th></th>`)}
1728
1767
  <th>${msg4("Mon")}</th>
1729
1768
  <th>${msg4("Tue")}</th>
1730
1769
  <th>${msg4("Wed")}</th>
@@ -1737,19 +1776,19 @@ var GdsCalendar = class extends GdsElement {
1737
1776
  <tbody>
1738
1777
  ${renderMonthGridView(
1739
1778
  this.focusedDate,
1740
- (weeks) => html6`
1779
+ (weeks) => html7`
1741
1780
  ${weeks.map(
1742
- (week) => html6`
1781
+ (week) => html7`
1743
1782
  <tr>
1744
1783
  ${when3(
1745
1784
  this.showWeekNumbers,
1746
- () => html6`<td class="week-number">
1785
+ () => html7`<td class="week-number">
1747
1786
  ${getWeek(week.days[0])}
1748
1787
  </td>`
1749
1788
  )}
1750
1789
  ${week.days.map((day) => {
1751
1790
  const isDisabled = !isSameMonth(this.focusedDate, day) || day < this.min || day > this.max;
1752
- return html6`
1791
+ return html7`
1753
1792
  <td
1754
1793
  class="${classMap4({
1755
1794
  disabled: isDisabled,
@@ -1883,10 +1922,10 @@ GdsCalendar = __decorateClass([
1883
1922
  ], GdsCalendar);
1884
1923
 
1885
1924
  // libs/core/src/components/datepicker/date-part-spinner.ts
1886
- import { LitElement as LitElement7 } from "lit";
1925
+ import { LitElement as LitElement6 } from "lit";
1887
1926
  import { property as property8, state as state9 } from "lit/decorators.js";
1888
1927
  var _inputBuffer, _increment, _decrement, _handleClick, _handleFocus, _handleBlur, _handleWheel, _handleKeyDown2, _focusNextSpinner, focusNextSpinner_fn, _dispatchChangeEvent, dispatchChangeEvent_fn, _formatNumber, formatNumber_fn, _clamp, clamp_fn, _clearInputBuffer, clearInputBuffer_fn;
1889
- var GdsDatePartSpinner = class extends LitElement7 {
1928
+ var GdsDatePartSpinner = class extends LitElement6 {
1890
1929
  constructor() {
1891
1930
  super(...arguments);
1892
1931
  __privateAdd(this, _focusNextSpinner);
@@ -1928,7 +1967,6 @@ var GdsDatePartSpinner = class extends LitElement7 {
1928
1967
  __privateMethod(this, _clearInputBuffer, clearInputBuffer_fn).call(this);
1929
1968
  this.value = __privateMethod(this, _clamp, clamp_fn).call(this, parseInt(this.value.toString()));
1930
1969
  __privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
1931
- document.getSelection()?.removeAllRanges();
1932
1970
  });
1933
1971
  __privateAdd(this, _handleWheel, (e) => {
1934
1972
  e.stopPropagation();
@@ -2059,8 +2097,8 @@ GdsDatePartSpinner = __decorateClass([
2059
2097
  ], GdsDatePartSpinner);
2060
2098
 
2061
2099
  // libs/core/src/components/datepicker/datepicker.styles.ts
2062
- import { css as css6 } from "lit";
2063
- var styles = css6`
2100
+ import { css as css7 } from "lit";
2101
+ var styles = css7`
2064
2102
  @layer base, reset, transitional-styles;
2065
2103
  @layer base {
2066
2104
  label {
@@ -2078,7 +2116,7 @@ var dateConverter = {
2078
2116
  return value.toISOString();
2079
2117
  }
2080
2118
  };
2081
- var _valueOnOpen, _renderBackToValidRangeButton, renderBackToValidRangeButton_fn, _focusDate, focusDate_fn, _getSpinnerLabel, getSpinnerLabel_fn, _getMinSpinnerValue, getMinSpinnerValue_fn, _getMaxSpinnerValue, getMaxSpinnerValue_fn, _dispatchChangeEvent2, dispatchChangeEvent_fn2, _dispatchInputEvent, dispatchInputEvent_fn, _handleClipboardCopy, _handleClipboardPaste, _handleFieldClick, _handleCalendarChange, _handleMonthChange, _handleYearChange, _handleIncrementFocusedMonth, _handleDecrementFocusedMonth, _handleCalendarFocusChange, _handlePopoverStateChange, _handleSpinnerKeydown, _parseDateFormat, parseDateFormat_fn, _handleSpinnerChange, _spinnerState, _years, years_get, _isValueOutsideRange, isValueOutsideRange_get;
2119
+ var _valueOnOpen, _renderBackToValidRangeButton, renderBackToValidRangeButton_fn, _focusDate, focusDate_fn, _getSpinnerLabel, getSpinnerLabel_fn, _getMinSpinnerValue, getMinSpinnerValue_fn, _getMaxSpinnerValue, getMaxSpinnerValue_fn, _dispatchChangeEvent2, dispatchChangeEvent_fn2, _dispatchInputEvent, dispatchInputEvent_fn, _handleFieldFocusOut, _handleSpinnerFocus, _handleClipboardCopy, _handleClipboardPaste, _handleFieldClick, _handleCalendarChange, _handleMonthChange, _handleYearChange, _handleIncrementFocusedMonth, _handleDecrementFocusedMonth, _handleCalendarFocusChange, _handlePopoverStateChange, _handleSpinnerKeydown, _parseDateFormat, parseDateFormat_fn, _handleSpinnerChange, _spinnerState, _years, years_get, _isValueOutsideRange, isValueOutsideRange_get;
2082
2120
  var GdsDatepicker = class extends GdsFormControlElement {
2083
2121
  constructor() {
2084
2122
  super(...arguments);
@@ -2107,24 +2145,48 @@ var GdsDatepicker = class extends GdsFormControlElement {
2107
2145
  this._focusedYear = (/* @__PURE__ */ new Date()).getFullYear();
2108
2146
  this._dateFormatLayout = __privateMethod(this, _parseDateFormat, parseDateFormat_fn).call(this, "y-m-d");
2109
2147
  __privateAdd(this, _valueOnOpen, void 0);
2148
+ __privateAdd(this, _handleFieldFocusOut, (e) => {
2149
+ this._elTrigger.then((_) => {
2150
+ const parent = e.relatedTarget?.parentElement;
2151
+ if (parent === e.target)
2152
+ return;
2153
+ document.getSelection()?.removeAllRanges();
2154
+ });
2155
+ });
2156
+ __privateAdd(this, _handleSpinnerFocus, (e) => {
2157
+ this._elTrigger.then((field) => {
2158
+ document.getSelection()?.removeAllRanges();
2159
+ const range = new Range();
2160
+ range.setStart(field.firstChild, 0);
2161
+ range.setEnd(field.lastChild, 4);
2162
+ document.getSelection()?.addRange(range);
2163
+ });
2164
+ });
2110
2165
  __privateAdd(this, _handleClipboardCopy, (e) => {
2111
- e.preventDefault();
2112
- e.clipboardData?.setData("text/plain", this.displayValue);
2166
+ this._elTrigger.then((field) => {
2167
+ if (e.currentTarget !== field)
2168
+ return;
2169
+ e.preventDefault();
2170
+ e.clipboardData?.setData("text/plain", this.displayValue);
2171
+ });
2113
2172
  });
2114
2173
  __privateAdd(this, _handleClipboardPaste, (e) => {
2115
- e.preventDefault();
2116
- const pasted = e.clipboardData?.getData("text/plain");
2117
- if (!pasted)
2118
- return;
2119
- const pastedDate = new Date(pasted);
2120
- if (pastedDate.toString() === "Invalid Date")
2121
- return;
2122
- this.value = pastedDate;
2123
- __privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
2174
+ this._elTrigger.then((field) => {
2175
+ if (e.currentTarget !== field)
2176
+ return;
2177
+ e.preventDefault();
2178
+ const pasted = e.clipboardData?.getData("text/plain");
2179
+ if (!pasted)
2180
+ return;
2181
+ const pastedDate = new Date(pasted);
2182
+ if (pastedDate.toString() === "Invalid Date")
2183
+ return;
2184
+ this.value = pastedDate;
2185
+ __privateMethod(this, _dispatchChangeEvent2, dispatchChangeEvent_fn2).call(this);
2186
+ });
2124
2187
  });
2125
2188
  __privateAdd(this, _handleFieldClick, (e) => {
2126
2189
  this._elSpinners[0].focus();
2127
- window.getSelection()?.selectAllChildren(this._elSpinners[0]);
2128
2190
  });
2129
2191
  __privateAdd(this, _handleCalendarChange, (e) => {
2130
2192
  e.stopPropagation();
@@ -2254,7 +2316,7 @@ var GdsDatepicker = class extends GdsFormControlElement {
2254
2316
  @copy=${__privateGet(this, _handleClipboardCopy)}
2255
2317
  @paste=${__privateGet(this, _handleClipboardPaste)}
2256
2318
  >
2257
- <div class="input">
2319
+ <div class="input" @focusout=${__privateGet(this, _handleFieldFocusOut)}>
2258
2320
  ${join(
2259
2321
  map(
2260
2322
  this._dateFormatLayout.layout,
@@ -2268,6 +2330,7 @@ var GdsDatepicker = class extends GdsFormControlElement {
2268
2330
  aria-describedby="label"
2269
2331
  @keydown=${__privateGet(this, _handleSpinnerKeydown)}
2270
2332
  @change=${(e) => __privateGet(this, _handleSpinnerChange).call(this, e.detail.value, f.name)}
2333
+ @focus=${__privateGet(this, _handleSpinnerFocus)}
2271
2334
  ></gds-date-part-spinner>`
2272
2335
  ),
2273
2336
  html`<span>${this._dateFormatLayout.delimiter}</span>`
@@ -2476,6 +2539,8 @@ dispatchInputEvent_fn = function() {
2476
2539
  })
2477
2540
  );
2478
2541
  };
2542
+ _handleFieldFocusOut = new WeakMap();
2543
+ _handleSpinnerFocus = new WeakMap();
2479
2544
  _handleClipboardCopy = new WeakMap();
2480
2545
  _handleClipboardPaste = new WeakMap();
2481
2546
  _handleFieldClick = new WeakMap();
@@ -2592,6 +2657,7 @@ export {
2592
2657
  GdsContextMenu,
2593
2658
  GdsDatepicker,
2594
2659
  GdsDropdown,
2660
+ GdsMenuHeading,
2595
2661
  GdsMenuItem,
2596
2662
  GdsOption,
2597
2663
  VER_SUFFIX,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sebgroup/green-core",
3
3
  "description": "A carefully crafted set of Web Components, laying the foundation of the Green Design System.",
4
- "version": "1.5.1",
4
+ "version": "1.6.0",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
7
7
  "type": "module",
@@ -1,11 +1,10 @@
1
- import { LitElement } from 'lit';
2
1
  import { GdsElement } from '../../gds-element';
3
2
  import 'reflect-metadata';
4
3
  export interface OptionsContainer extends HTMLElement {
5
4
  options: GdsOption[];
6
5
  multiple: boolean;
7
6
  }
8
- declare const GdsOption_base: (new (...args: any[]) => LitElement) & typeof GdsElement;
7
+ declare const GdsOption_base: (new (...args: any[]) => import("lit").LitElement) & typeof GdsElement;
9
8
  /**
10
9
  * @element gds-option
11
10
  * @internal
@@ -0,0 +1,6 @@
1
+ import { GdsElement } from '../../gds-element';
2
+ export declare class GdsMenuHeading extends GdsElement {
3
+ static styles: import("lit").CSSResult;
4
+ connectedCallback(): void;
5
+ render(): import("lit").TemplateResult<1>;
6
+ }
@@ -0,0 +1,2 @@
1
+ declare const style: import("lit").CSSResult;
2
+ export default style;
@@ -146,10 +146,32 @@ var option_trans_styles_default = `/**
146
146
  }
147
147
  }`;
148
148
 
149
+ // libs/core/src/primitives/menu/menu-heading.trans.styles.scss
150
+ var menu_heading_trans_styles_default = `@layer base, reset, transitional-styles;
151
+ @layer transitional-styles {
152
+ :host {
153
+ padding: 0.5rem 1rem;
154
+ background-color: var(--gds-ref-pallet-base100);
155
+ color: var(--gds-ref-pallet-base800);
156
+ display: flex;
157
+ -webkit-user-select: none;
158
+ -moz-user-select: none;
159
+ user-select: none;
160
+ font-size: 0.875rem;
161
+ }
162
+ :host([aria-hidden=true]) {
163
+ display: none;
164
+ }
165
+ }`;
166
+
149
167
  // libs/core/src/primitives/listbox/listbox.trans.styles.ts
150
168
  function register() {
151
169
  TransitionalStyles.instance.register("gds-listbox", listbox_trans_styles_default.toString());
152
170
  TransitionalStyles.instance.register("gds-option", option_trans_styles_default.toString());
171
+ TransitionalStyles.instance.register(
172
+ "gds-menu-heading",
173
+ menu_heading_trans_styles_default.toString()
174
+ );
153
175
  }
154
176
 
155
177
  // libs/core/src/primitives/popover/popover.trans.styles.scss
@@ -1967,6 +1989,7 @@ a.button.tertiary.danger:focus-visible {
1967
1989
  width: 2rem;
1968
1990
  border-radius: 50%;
1969
1991
  position: relative;
1992
+ --color: var(--gds-sys-color-base);
1970
1993
  }
1971
1994
  .close:not(:disabled):not(.disabled) > div::after, .close:not(:disabled):not(.disabled) > div::before {
1972
1995
  height: 0.789375rem;
@@ -3071,16 +3094,22 @@ i.sg-icon.sg-icon-ellipsis::before {
3071
3094
  outline-width: 0.125rem;
3072
3095
  outline-offset: 0.125rem;
3073
3096
  }
3097
+ .field .input::-moz-selection {
3098
+ background: transparent;
3099
+ }
3100
+ .field .input::selection {
3101
+ background: transparent;
3102
+ }
3074
3103
  .field span {
3075
- cursor: default;
3104
+ cursor: text;
3076
3105
  }
3077
3106
  .field [role=spinbutton] {
3078
- cursor: default;
3107
+ cursor: text;
3079
3108
  display: inline-block;
3080
3109
  }
3081
3110
  .field [role=spinbutton]:focus {
3082
- background: color-mix(in srgb, var(--gds-sys-color-blue) 50%, transparent);
3083
3111
  outline: none;
3112
+ background: color-mix(in srgb, var(--gds-sys-color-blue) 50%, transparent);
3084
3113
  }
3085
3114
  .field [role=spinbutton]::-moz-selection {
3086
3115
  background: transparent;
@@ -3215,7 +3244,7 @@ function register6() {
3215
3244
  // libs/core/src/utils/helpers/custom-element-scoping.ts
3216
3245
  import { html as litHtml } from "lit";
3217
3246
  import { customElement } from "lit/decorators.js";
3218
- var VER_SUFFIX = "-ea801b";
3247
+ var VER_SUFFIX = "-f9a04d";
3219
3248
  var elementLookupTable = /* @__PURE__ */ new Map();
3220
3249
  var templateCache = /* @__PURE__ */ new WeakMap();
3221
3250
  function applyElementScoping(strings, ...values) {