@hashicorp/design-system-components 4.23.1 → 4.24.0-rc-20250923215537
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/declarations/components/hds/advanced-table/index.d.ts +13 -3
- package/declarations/components/hds/advanced-table/models/column.d.ts +9 -2
- package/declarations/components/hds/advanced-table/models/row.d.ts +5 -1
- package/declarations/components/hds/advanced-table/models/table.d.ts +13 -2
- package/declarations/components/hds/advanced-table/td.d.ts +1 -1
- package/declarations/components/hds/advanced-table/th-context-menu.d.ts +16 -7
- package/declarations/components/hds/advanced-table/th-reorder-drop-target.d.ts +32 -0
- package/declarations/components/hds/advanced-table/th-reorder-handle.d.ts +24 -0
- package/declarations/components/hds/advanced-table/th-resize-handle.d.ts +2 -1
- package/declarations/components/hds/advanced-table/th-sort.d.ts +11 -3
- package/declarations/components/hds/advanced-table/th.d.ts +11 -4
- package/declarations/components/hds/advanced-table/tr.d.ts +7 -1
- package/declarations/components/hds/advanced-table/types.d.ts +15 -0
- package/declarations/components/hds/advanced-table/utils.d.ts +5 -0
- package/declarations/components/hds/dropdown/toggle/icon.d.ts +1 -1
- package/declarations/components/hds/flyout/index.d.ts +4 -1
- package/declarations/components/hds/form/index.d.ts +1 -1
- package/declarations/components/hds/form/key-value-inputs/index.d.ts +4 -4
- package/declarations/components/hds/form/radio-card/index.d.ts +2 -2
- package/declarations/components/hds/modal/index.d.ts +4 -2
- package/declarations/components/hds/popover-primitive/index.d.ts +3 -0
- package/declarations/components/hds/separator/index.d.ts +1 -1
- package/declarations/components/hds/stepper/list/step.d.ts +1 -1
- package/declarations/components/hds/stepper/task/indicator.d.ts +1 -1
- package/declarations/components/hds/table/index.d.ts +5 -5
- package/declarations/components/hds/table/td.d.ts +1 -1
- package/declarations/components/hds/table/th-sort.d.ts +1 -1
- package/declarations/components/hds/table/th.d.ts +1 -1
- package/declarations/template-registry.d.ts +6 -0
- package/dist/_app_/components/hds/advanced-table/th-reorder-drop-target.js +1 -0
- package/dist/_app_/components/hds/advanced-table/th-reorder-handle.js +1 -0
- package/dist/_app_/components/hds/advanced-table/utils.js +1 -0
- package/dist/components/hds/advanced-table/index.js +77 -17
- package/dist/components/hds/advanced-table/index.js.map +1 -1
- package/dist/components/hds/advanced-table/models/column.js +58 -13
- package/dist/components/hds/advanced-table/models/column.js.map +1 -1
- package/dist/components/hds/advanced-table/models/row.js +38 -3
- package/dist/components/hds/advanced-table/models/row.js.map +1 -1
- package/dist/components/hds/advanced-table/models/table.js +146 -2
- package/dist/components/hds/advanced-table/models/table.js.map +1 -1
- package/dist/components/hds/advanced-table/td.js.map +1 -1
- package/dist/components/hds/advanced-table/th-context-menu.js +124 -50
- package/dist/components/hds/advanced-table/th-context-menu.js.map +1 -1
- package/dist/components/hds/advanced-table/th-reorder-drop-target.js +133 -0
- package/dist/components/hds/advanced-table/th-reorder-drop-target.js.map +1 -0
- package/dist/components/hds/advanced-table/th-reorder-handle.js +104 -0
- package/dist/components/hds/advanced-table/th-reorder-handle.js.map +1 -0
- package/dist/components/hds/advanced-table/th-resize-handle.js +44 -21
- package/dist/components/hds/advanced-table/th-resize-handle.js.map +1 -1
- package/dist/components/hds/advanced-table/th-sort.js +20 -8
- package/dist/components/hds/advanced-table/th-sort.js.map +1 -1
- package/dist/components/hds/advanced-table/th.js +19 -7
- package/dist/components/hds/advanced-table/th.js.map +1 -1
- package/dist/components/hds/advanced-table/tr.js +1 -1
- package/dist/components/hds/advanced-table/tr.js.map +1 -1
- package/dist/components/hds/advanced-table/types.js +6 -1
- package/dist/components/hds/advanced-table/types.js.map +1 -1
- package/dist/components/hds/advanced-table/utils.js +23 -0
- package/dist/components/hds/advanced-table/utils.js.map +1 -0
- package/dist/components/hds/dropdown/toggle/icon.js.map +1 -1
- package/dist/components/hds/flyout/index.js +29 -6
- package/dist/components/hds/flyout/index.js.map +1 -1
- package/dist/components/hds/form/index.js.map +1 -1
- package/dist/components/hds/form/key-value-inputs/index.js.map +1 -1
- package/dist/components/hds/form/radio-card/index.js.map +1 -1
- package/dist/components/hds/modal/index.js +51 -37
- package/dist/components/hds/modal/index.js.map +1 -1
- package/dist/components/hds/popover-primitive/index.js +51 -35
- package/dist/components/hds/popover-primitive/index.js.map +1 -1
- package/dist/components/hds/separator/index.js.map +1 -1
- package/dist/components/hds/stepper/list/step.js.map +1 -1
- package/dist/components/hds/table/index.js.map +1 -1
- package/dist/components/hds/table/td.js.map +1 -1
- package/dist/components/hds/table/th-sort.js.map +1 -1
- package/dist/components/hds/table/th.js.map +1 -1
- package/dist/components.js +1 -1
- package/dist/styles/@hashicorp/design-system-components.css +196 -62
- package/dist/styles/components/advanced-table.scss +155 -6
- package/dist/styles/mixins/_focus-ring.scss +43 -0
- package/package.json +5 -2
- package/translations/hds/components/advanced-table/en-us.yaml +1 -0
- package/translations/hds/components/advanced-table/th-context-menu/en-us.yaml +3 -0
- package/translations/hds/components/advanced-table/th-reorder-handle/en-us.yaml +2 -0
|
@@ -4,6 +4,8 @@ import { action } from '@ember/object';
|
|
|
4
4
|
import { assert } from '@ember/debug';
|
|
5
5
|
import { getElementId } from '../../../utils/hds-get-element-id.js';
|
|
6
6
|
import { buildWaiter } from '@ember/test-waiters';
|
|
7
|
+
import { registerDestructor } from '@ember/destroyable';
|
|
8
|
+
import { modifier } from 'ember-modifier';
|
|
7
9
|
import '../dialog-primitive/header.js';
|
|
8
10
|
import '../dialog-primitive/body.js';
|
|
9
11
|
import '../dialog-primitive/footer.js';
|
|
@@ -12,7 +14,7 @@ import { precompileTemplate } from '@ember/template-compilation';
|
|
|
12
14
|
import { g, i, n } from 'decorator-transforms/runtime';
|
|
13
15
|
import { setComponentTemplate } from '@ember/component';
|
|
14
16
|
|
|
15
|
-
var TEMPLATE = precompileTemplate("{{!\n Copyright (c) HashiCorp, Inc.\n SPDX-License-Identifier: MPL-2.0\n}}\n<Hds::DialogPrimitive::Wrapper\n class={{this.classNames}}\n ...attributes\n aria-labelledby={{this.id}}\n {{
|
|
17
|
+
var TEMPLATE = precompileTemplate("{{!\n Copyright (c) HashiCorp, Inc.\n SPDX-License-Identifier: MPL-2.0\n}}\n<Hds::DialogPrimitive::Wrapper\n class={{this.classNames}}\n ...attributes\n aria-labelledby={{this.id}}\n {{this._registerDialog}}\n {{! @glint-expect-error - https://github.com/josemarluedke/ember-focus-trap/issues/86 }}\n {{focus-trap isActive=this._isOpen focusTrapOptions=(hash onDeactivate=this.onDismiss)}}\n>\n <:header>\n {{yield\n (hash\n Header=(component\n \"hds/dialog-primitive/header\"\n id=this.id\n onDismiss=this.onDismiss\n contextualClassPrefix=\"hds-modal\"\n titleTag=\"h1\"\n )\n )\n }}\n </:header>\n <:body>\n {{yield (hash Body=(component \"hds/dialog-primitive/body\" contextualClass=\"hds-modal__body\"))}}\n </:body>\n <:footer>\n {{yield\n (hash\n Footer=(component \"hds/dialog-primitive/footer\" onDismiss=this.onDismiss contextualClass=\"hds-modal__footer\")\n )\n }}\n </:footer>\n</Hds::DialogPrimitive::Wrapper>\n\n{{#if this._isOpen}}\n <Hds::DialogPrimitive::Overlay @contextualClass=\"hds-modal__overlay\" />\n{{/if}}");
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Copyright (c) HashiCorp, Inc.
|
|
@@ -34,6 +36,20 @@ class HdsModal extends Component {
|
|
|
34
36
|
_element;
|
|
35
37
|
_body;
|
|
36
38
|
_bodyInitialOverflowValue = '';
|
|
39
|
+
_clickHandler;
|
|
40
|
+
constructor(owner, args) {
|
|
41
|
+
super(owner, args);
|
|
42
|
+
registerDestructor(this, () => {
|
|
43
|
+
// if the <dialog> is removed from the dom while open we emulate the close event
|
|
44
|
+
if (this._element && this._isOpen) {
|
|
45
|
+
this._element.dispatchEvent(new Event('close'));
|
|
46
|
+
this._element.removeEventListener('close',
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
48
|
+
this.registerOnCloseCallback, true);
|
|
49
|
+
}
|
|
50
|
+
document.removeEventListener('click', this._clickHandler, true);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
37
53
|
get isDismissDisabled() {
|
|
38
54
|
return this.args.isDismissDisabled ?? false;
|
|
39
55
|
}
|
|
@@ -80,12 +96,32 @@ class HdsModal extends Component {
|
|
|
80
96
|
}
|
|
81
97
|
} else {
|
|
82
98
|
this._isOpen = false;
|
|
99
|
+
|
|
100
|
+
// Reset page `overflow` property
|
|
101
|
+
if (this._body) {
|
|
102
|
+
this._body.style.removeProperty('overflow');
|
|
103
|
+
if (this._bodyInitialOverflowValue === '') {
|
|
104
|
+
if (this._body.style.length === 0) {
|
|
105
|
+
this._body.removeAttribute('style');
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
this._body.style.setProperty('overflow', this._bodyInitialOverflowValue);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Return focus to a specific element (if provided)
|
|
113
|
+
if (this.args.returnFocusTo) {
|
|
114
|
+
const initiator = document.getElementById(this.args.returnFocusTo);
|
|
115
|
+
if (initiator) {
|
|
116
|
+
initiator.focus();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
83
119
|
}
|
|
84
120
|
}
|
|
85
121
|
static {
|
|
86
122
|
n(this.prototype, "registerOnCloseCallback", [action]);
|
|
87
123
|
}
|
|
88
|
-
|
|
124
|
+
_registerDialog = modifier(element => {
|
|
89
125
|
// Store references of `<dialog>` and `<body>` elements
|
|
90
126
|
this._element = element;
|
|
91
127
|
this._body = document.body;
|
|
@@ -102,20 +138,19 @@ class HdsModal extends Component {
|
|
|
102
138
|
if (!this._element.open) {
|
|
103
139
|
this.open();
|
|
104
140
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
141
|
+
this._clickHandler = event => {
|
|
142
|
+
// check if the click is outside the modal and the modal is open
|
|
143
|
+
if (!this._element.contains(event.target) && this._isOpen) {
|
|
144
|
+
if (!this.isDismissDisabled) {
|
|
145
|
+
void this.onDismiss();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
document.addEventListener('click', this._clickHandler, {
|
|
150
|
+
capture: true,
|
|
151
|
+
passive: false
|
|
152
|
+
});
|
|
153
|
+
});
|
|
119
154
|
open() {
|
|
120
155
|
// Make modal dialog visible using the native `showModal` method
|
|
121
156
|
this._element.showModal();
|
|
@@ -135,7 +170,6 @@ class HdsModal extends Component {
|
|
|
135
170
|
async onDismiss() {
|
|
136
171
|
// allow ember test helpers to be aware of when the `close` event fires
|
|
137
172
|
// when using `click` or other helpers from '@ember/test-helpers'
|
|
138
|
-
// Notice: this code will get stripped out in production builds (DEBUG evaluates to `true` in dev/test builds, but `false` in prod builds)
|
|
139
173
|
if (this._element.open) {
|
|
140
174
|
const token = waiter.beginAsync();
|
|
141
175
|
const listener = () => {
|
|
@@ -147,26 +181,6 @@ class HdsModal extends Component {
|
|
|
147
181
|
|
|
148
182
|
// Make modal dialog invisible using the native `close` method
|
|
149
183
|
this._element.close();
|
|
150
|
-
|
|
151
|
-
// Reset page `overflow` property
|
|
152
|
-
if (this._body) {
|
|
153
|
-
this._body.style.removeProperty('overflow');
|
|
154
|
-
if (this._bodyInitialOverflowValue === '') {
|
|
155
|
-
if (this._body.style.length === 0) {
|
|
156
|
-
this._body.removeAttribute('style');
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
this._body.style.setProperty('overflow', this._bodyInitialOverflowValue);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Return focus to a specific element (if provided)
|
|
164
|
-
if (this.args.returnFocusTo) {
|
|
165
|
-
const initiator = document.getElementById(this.args.returnFocusTo);
|
|
166
|
-
if (initiator) {
|
|
167
|
-
initiator.focus();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
184
|
}
|
|
171
185
|
static {
|
|
172
186
|
n(this.prototype, "onDismiss", [action]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/hds/modal/index.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { action } from '@ember/object';\nimport { assert } from '@ember/debug';\nimport { getElementId } from '../../../utils/hds-get-element-id.ts';\nimport { buildWaiter } from '@ember/test-waiters';\n\nimport type { WithBoundArgs } from '@glint/template';\nimport type { HdsModalSizes, HdsModalColors } from './types.ts';\n\nimport HdsDialogPrimitiveHeaderComponent from '../dialog-primitive/header.ts';\nimport HdsDialogPrimitiveBodyComponent from '../dialog-primitive/body.ts';\nimport HdsDialogPrimitiveFooterComponent from '../dialog-primitive/footer.ts';\nimport { HdsModalSizeValues, HdsModalColorValues } from './types.ts';\n\nconst waiter = buildWaiter('@hashicorp/design-system-components:modal');\n\nexport const DEFAULT_SIZE = HdsModalSizeValues.Medium;\nexport const DEFAULT_COLOR = HdsModalColorValues.Neutral;\n\nexport const SIZES: HdsModalSizes[] = Object.values(HdsModalSizeValues);\nexport const COLORS: HdsModalColors[] = Object.values(HdsModalColorValues);\n\nexport interface HdsModalSignature {\n Args: {\n isDismissDisabled?: boolean;\n size?: HdsModalSizes;\n color?: HdsModalColors;\n returnFocusTo?: string;\n onOpen?: () => void;\n onClose?: (event: Event) => void;\n };\n Blocks: {\n default: [\n {\n Header?: WithBoundArgs<\n typeof HdsDialogPrimitiveHeaderComponent,\n 'id' | 'onDismiss' | 'contextualClassPrefix'\n >;\n Body?: WithBoundArgs<\n typeof HdsDialogPrimitiveBodyComponent,\n 'contextualClass'\n >;\n Footer?: WithBoundArgs<\n typeof HdsDialogPrimitiveFooterComponent,\n 'onDismiss' | 'contextualClass'\n >;\n },\n ];\n };\n Element: HTMLDialogElement;\n}\n\nexport default class HdsModal extends Component<HdsModalSignature> {\n @tracked private _isOpen = false;\n private _element!: HTMLDialogElement;\n private _body!: HTMLElement;\n private _bodyInitialOverflowValue = '';\n\n get isDismissDisabled(): boolean {\n return this.args.isDismissDisabled ?? false;\n }\n\n get size(): HdsModalSizes {\n const { size = DEFAULT_SIZE } = this.args;\n\n assert(\n `@size for \"Hds::Modal\" must be one of the following: ${SIZES.join(\n ', '\n )}; received: ${size}`,\n SIZES.includes(size)\n );\n\n return size;\n }\n\n get color(): HdsModalColors {\n const { color = DEFAULT_COLOR } = this.args;\n\n assert(\n `@color for \"Hds::Modal\" must be one of the following: ${COLORS.join(\n ', '\n )}; received: ${color}`,\n COLORS.includes(color)\n );\n\n return color;\n }\n\n get id(): string {\n return getElementId(this);\n }\n\n get classNames(): string {\n const classes = ['hds-modal'];\n\n // add a class based on the @size argument\n classes.push(`hds-modal--size-${this.size}`);\n\n // add a class based on the @color argument\n classes.push(`hds-modal--color-${this.color}`);\n\n return classes.join(' ');\n }\n\n @action registerOnCloseCallback(event: Event): void {\n if (\n !this.isDismissDisabled &&\n this.args.onClose &&\n typeof this.args.onClose === 'function'\n ) {\n this.args.onClose(event);\n }\n\n // If the dismissal of the modal is disabled, we keep the modal open/visible otherwise we mark it as closed\n if (this.isDismissDisabled) {\n // If, in a chain of events, the element is not attached to the DOM, the `showModal` would fail\n // so we add this safeguard condition that checks for the `<dialog>` to have a parent\n if (this._element.parentElement) {\n // As there is no way to `preventDefault` on `close` events, we call the `showModal` function\n // preserving the state of the modal dialog\n this._element.showModal();\n }\n } else {\n this._isOpen = false;\n }\n }\n\n @action\n didInsert(element: HTMLDialogElement): void {\n // Store references of `<dialog>` and `<body>` elements\n this._element = element;\n this._body = document.body;\n\n if (this._body) {\n // Store the initial `overflow` value of `<body>` so we can reset to it\n this._bodyInitialOverflowValue =\n this._body.style.getPropertyValue('overflow');\n }\n\n // Register \"onClose\" callback function to be called when a native 'close' event is dispatched\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this._element.addEventListener('close', this.registerOnCloseCallback, true);\n\n // If the modal dialog is not already open\n if (!this._element.open) {\n this.open();\n }\n }\n\n @action\n willDestroyNode(): void {\n if (this._element) {\n this._element.removeEventListener(\n 'close',\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.registerOnCloseCallback,\n true\n );\n }\n }\n\n @action\n open(): void {\n // Make modal dialog visible using the native `showModal` method\n this._element.showModal();\n this._isOpen = true;\n\n // Prevent page from scrolling when the dialog is open\n if (this._body) this._body.style.setProperty('overflow', 'hidden');\n\n // Call \"onOpen\" callback function\n if (this.args.onOpen && typeof this.args.onOpen === 'function') {\n this.args.onOpen();\n }\n }\n\n @action\n // eslint-disable-next-line @typescript-eslint/require-await\n async onDismiss(): Promise<void> {\n // allow ember test helpers to be aware of when the `close` event fires\n // when using `click` or other helpers from '@ember/test-helpers'\n // Notice: this code will get stripped out in production builds (DEBUG evaluates to `true` in dev/test builds, but `false` in prod builds)\n if (this._element.open) {\n const token = waiter.beginAsync();\n const listener = () => {\n waiter.endAsync(token);\n this._element.removeEventListener('close', listener);\n };\n this._element.addEventListener('close', listener);\n }\n\n // Make modal dialog invisible using the native `close` method\n this._element.close();\n\n // Reset page `overflow` property\n if (this._body) {\n this._body.style.removeProperty('overflow');\n if (this._bodyInitialOverflowValue === '') {\n if (this._body.style.length === 0) {\n this._body.removeAttribute('style');\n }\n } else {\n this._body.style.setProperty(\n 'overflow',\n this._bodyInitialOverflowValue\n );\n }\n }\n\n // Return focus to a specific element (if provided)\n if (this.args.returnFocusTo) {\n const initiator = document.getElementById(this.args.returnFocusTo);\n if (initiator) {\n initiator.focus();\n }\n }\n }\n}\n"],"names":["waiter","buildWaiter","DEFAULT_SIZE","HdsModalSizeValues","Medium","DEFAULT_COLOR","HdsModalColorValues","Neutral","SIZES","Object","values","COLORS","HdsModal","Component","g","prototype","tracked","i","void 0","_element","_body","_bodyInitialOverflowValue","isDismissDisabled","args","size","assert","join","includes","color","id","getElementId","classNames","classes","push","registerOnCloseCallback","event","onClose","parentElement","showModal","_isOpen","n","action","didInsert","element","document","body","style","getPropertyValue","addEventListener","open","willDestroyNode","removeEventListener","setProperty","onOpen","onDismiss","token","beginAsync","listener","endAsync","close","removeProperty","length","removeAttribute","returnFocusTo","initiator","getElementById","focus","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;;AAiBA,MAAMA,MAAM,GAAGC,WAAW,CAAC,2CAA2C,CAAC;AAEhE,MAAMC,YAAY,GAAGC,kBAAkB,CAACC;AACxC,MAAMC,aAAa,GAAGC,mBAAmB,CAACC;AAE1C,MAAMC,KAAsB,GAAGC,MAAM,CAACC,MAAM,CAACP,kBAAkB;AAC/D,MAAMQ,MAAwB,GAAGF,MAAM,CAACC,MAAM,CAACJ,mBAAmB;AAgC1D,MAAMM,QAAQ,SAASC,SAAS,CAAoB;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,SAAA,EAAA,CAChEC,OAAO,CAAA,EAAA,YAAA;AAAA,MAAA,OAAmB,KAAK;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA,EAAA,QAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,SAAA,CAAA,EAAAC,MAAA;EACxBC,QAAQ;EACRC,KAAK;AACLC,EAAAA,yBAAyB,GAAG,EAAE;EAEtC,IAAIC,iBAAiBA,GAAY;AAC/B,IAAA,OAAO,IAAI,CAACC,IAAI,CAACD,iBAAiB,IAAI,KAAK;AAC7C,EAAA;EAEA,IAAIE,IAAIA,GAAkB;IACxB,MAAM;AAAEA,MAAAA,IAAI,GAAGtB;KAAc,GAAG,IAAI,CAACqB,IAAI;AAEzCE,IAAAA,MAAM,CACJ,CAAA,qDAAA,EAAwDjB,KAAK,CAACkB,IAAI,CAChE,IACF,CAAC,CAAA,YAAA,EAAeF,IAAI,CAAA,CAAE,EACtBhB,KAAK,CAACmB,QAAQ,CAACH,IAAI,CACrB,CAAC;AAED,IAAA,OAAOA,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,KAAK,CAAC0B,KAAK,CAACM,WAAW,CAC1B,UAAU,EACV,IAAI,CAAC/B,yBACP,CAAC;AACH,MAAA;AACF,IAAA;;AAEA;AACA,IAAA,IAAI,IAAI,CAACE,IAAI,CAACwC,aAAa,EAAE;MAC3B,MAAMC,SAAS,GAAGpB,QAAQ,CAACqB,cAAc,CAAC,IAAI,CAAC1C,IAAI,CAACwC,aAAa,CAAC;AAClE,MAAA,IAAIC,SAAS,EAAE;QACbA,SAAS,CAACE,KAAK,EAAE;AACnB,MAAA;AACF,IAAA;AACF,EAAA;AAAC,EAAA;IAAA1B,CAAA,CAAA,IAAA,CAAAzB,SAAA,EAAA,WAAA,EAAA,CAxCA0B,MAAM,CAAA,CAAA;AAAA;AAyCT;AAAC0B,oBAAA,CAAAC,QAAA,EArKoBxD,QAAQ,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/hds/modal/index.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { action } from '@ember/object';\nimport { assert } from '@ember/debug';\nimport { getElementId } from '../../../utils/hds-get-element-id.ts';\nimport { buildWaiter } from '@ember/test-waiters';\nimport { registerDestructor } from '@ember/destroyable';\nimport { modifier } from 'ember-modifier';\n\nimport type { WithBoundArgs } from '@glint/template';\nimport type Owner from '@ember/owner';\nimport type { HdsModalSizes, HdsModalColors } from './types.ts';\n\nimport HdsDialogPrimitiveHeaderComponent from '../dialog-primitive/header.ts';\nimport HdsDialogPrimitiveBodyComponent from '../dialog-primitive/body.ts';\nimport HdsDialogPrimitiveFooterComponent from '../dialog-primitive/footer.ts';\nimport { HdsModalSizeValues, HdsModalColorValues } from './types.ts';\n\nconst waiter = buildWaiter('@hashicorp/design-system-components:modal');\n\nexport const DEFAULT_SIZE = HdsModalSizeValues.Medium;\nexport const DEFAULT_COLOR = HdsModalColorValues.Neutral;\n\nexport const SIZES: HdsModalSizes[] = Object.values(HdsModalSizeValues);\nexport const COLORS: HdsModalColors[] = Object.values(HdsModalColorValues);\n\nexport interface HdsModalSignature {\n Args: {\n isDismissDisabled?: boolean;\n size?: HdsModalSizes;\n color?: HdsModalColors;\n returnFocusTo?: string;\n onOpen?: () => void;\n onClose?: (event: Event) => void;\n };\n Blocks: {\n default: [\n {\n Header?: WithBoundArgs<\n typeof HdsDialogPrimitiveHeaderComponent,\n 'id' | 'onDismiss' | 'contextualClassPrefix'\n >;\n Body?: WithBoundArgs<\n typeof HdsDialogPrimitiveBodyComponent,\n 'contextualClass'\n >;\n Footer?: WithBoundArgs<\n typeof HdsDialogPrimitiveFooterComponent,\n 'onDismiss' | 'contextualClass'\n >;\n },\n ];\n };\n Element: HTMLDialogElement;\n}\n\nexport default class HdsModal extends Component<HdsModalSignature> {\n @tracked private _isOpen = false;\n private _element!: HTMLDialogElement;\n private _body!: HTMLElement;\n private _bodyInitialOverflowValue = '';\n private _clickHandler!: (event: MouseEvent) => void;\n\n constructor(owner: Owner, args: HdsModalSignature['Args']) {\n super(owner, args);\n\n registerDestructor(this, (): void => {\n // if the <dialog> is removed from the dom while open we emulate the close event\n if (this._element && this._isOpen) {\n this._element.dispatchEvent(new Event('close'));\n\n this._element.removeEventListener(\n 'close',\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.registerOnCloseCallback,\n true\n );\n }\n\n document.removeEventListener('click', this._clickHandler, true);\n });\n }\n\n get isDismissDisabled(): boolean {\n return this.args.isDismissDisabled ?? false;\n }\n\n get size(): HdsModalSizes {\n const { size = DEFAULT_SIZE } = this.args;\n\n assert(\n `@size for \"Hds::Modal\" must be one of the following: ${SIZES.join(\n ', '\n )}; received: ${size}`,\n SIZES.includes(size)\n );\n\n return size;\n }\n\n get color(): HdsModalColors {\n const { color = DEFAULT_COLOR } = this.args;\n\n assert(\n `@color for \"Hds::Modal\" must be one of the following: ${COLORS.join(\n ', '\n )}; received: ${color}`,\n COLORS.includes(color)\n );\n\n return color;\n }\n\n get id(): string {\n return getElementId(this);\n }\n\n get classNames(): string {\n const classes = ['hds-modal'];\n\n // add a class based on the @size argument\n classes.push(`hds-modal--size-${this.size}`);\n\n // add a class based on the @color argument\n classes.push(`hds-modal--color-${this.color}`);\n\n return classes.join(' ');\n }\n\n @action registerOnCloseCallback(event: Event): void {\n if (\n !this.isDismissDisabled &&\n this.args.onClose &&\n typeof this.args.onClose === 'function'\n ) {\n this.args.onClose(event);\n }\n\n // If the dismissal of the modal is disabled, we keep the modal open/visible otherwise we mark it as closed\n if (this.isDismissDisabled) {\n // If, in a chain of events, the element is not attached to the DOM, the `showModal` would fail\n // so we add this safeguard condition that checks for the `<dialog>` to have a parent\n if (this._element.parentElement) {\n // As there is no way to `preventDefault` on `close` events, we call the `showModal` function\n // preserving the state of the modal dialog\n this._element.showModal();\n }\n } else {\n this._isOpen = false;\n\n // Reset page `overflow` property\n if (this._body) {\n this._body.style.removeProperty('overflow');\n if (this._bodyInitialOverflowValue === '') {\n if (this._body.style.length === 0) {\n this._body.removeAttribute('style');\n }\n } else {\n this._body.style.setProperty(\n 'overflow',\n this._bodyInitialOverflowValue\n );\n }\n }\n\n // Return focus to a specific element (if provided)\n if (this.args.returnFocusTo) {\n const initiator = document.getElementById(this.args.returnFocusTo);\n if (initiator) {\n initiator.focus();\n }\n }\n }\n }\n\n private _registerDialog = modifier((element: HTMLDialogElement) => {\n // Store references of `<dialog>` and `<body>` elements\n this._element = element;\n this._body = document.body;\n\n if (this._body) {\n // Store the initial `overflow` value of `<body>` so we can reset to it\n this._bodyInitialOverflowValue =\n this._body.style.getPropertyValue('overflow');\n }\n\n // Register \"onClose\" callback function to be called when a native 'close' event is dispatched\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this._element.addEventListener('close', this.registerOnCloseCallback, true);\n\n // If the modal dialog is not already open\n if (!this._element.open) {\n this.open();\n }\n\n this._clickHandler = (event: MouseEvent) => {\n // check if the click is outside the modal and the modal is open\n if (!this._element.contains(event.target as Node) && this._isOpen) {\n if (!this.isDismissDisabled) {\n void this.onDismiss();\n }\n }\n };\n\n document.addEventListener('click', this._clickHandler, {\n capture: true,\n passive: false,\n });\n });\n\n @action\n open(): void {\n // Make modal dialog visible using the native `showModal` method\n this._element.showModal();\n this._isOpen = true;\n\n // Prevent page from scrolling when the dialog is open\n if (this._body) this._body.style.setProperty('overflow', 'hidden');\n\n // Call \"onOpen\" callback function\n if (this.args.onOpen && typeof this.args.onOpen === 'function') {\n this.args.onOpen();\n }\n }\n\n @action\n // eslint-disable-next-line @typescript-eslint/require-await\n async onDismiss(): Promise<void> {\n // allow ember test helpers to be aware of when the `close` event fires\n // when using `click` or other helpers from '@ember/test-helpers'\n if (this._element.open) {\n const token = waiter.beginAsync();\n const listener = () => {\n waiter.endAsync(token);\n this._element.removeEventListener('close', listener);\n };\n this._element.addEventListener('close', listener);\n }\n\n // Make modal dialog invisible using the native `close` method\n this._element.close();\n }\n}\n"],"names":["waiter","buildWaiter","DEFAULT_SIZE","HdsModalSizeValues","Medium","DEFAULT_COLOR","HdsModalColorValues","Neutral","SIZES","Object","values","COLORS","HdsModal","Component","g","prototype","tracked","i","void 0","_element","_body","_bodyInitialOverflowValue","_clickHandler","constructor","owner","args","registerDestructor","_isOpen","dispatchEvent","Event","removeEventListener","registerOnCloseCallback","document","isDismissDisabled","size","assert","join","includes","color","id","getElementId","classNames","classes","push","event","onClose","parentElement","showModal","style","removeProperty","length","removeAttribute","setProperty","returnFocusTo","initiator","getElementById","focus","n","action","_registerDialog","modifier","element","body","getPropertyValue","addEventListener","open","contains","target","onDismiss","capture","passive","onOpen","token","beginAsync","listener","endAsync","close","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;;AAoBA,MAAMA,MAAM,GAAGC,WAAW,CAAC,2CAA2C,CAAC;AAEhE,MAAMC,YAAY,GAAGC,kBAAkB,CAACC;AACxC,MAAMC,aAAa,GAAGC,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MAAA,IAAI,CAAC9C,IAAI,CAAC8C,MAAM,EAAE;AACpB,IAAA;AACF,EAAA;AAAC,EAAA;IAAAd,CAAA,CAAA,IAAA,CAAA1C,SAAA,EAAA,MAAA,EAAA,CAbA2C,MAAM,CAAA,CAAA;AAAA;EAeP,MAEMU,SAASA,GAAkB;AAC/B;AACA;AACA,IAAA,IAAI,IAAI,CAACjD,QAAQ,CAAC8C,IAAI,EAAE;AACtB,MAAA,MAAMO,KAAK,GAAGxE,MAAM,CAACyE,UAAU,EAAE;MACjC,MAAMC,QAAQ,GAAGA,MAAM;AACrB1E,QAAAA,MAAM,CAAC2E,QAAQ,CAACH,KAAK,CAAC;QACtB,IAAI,CAACrD,QAAQ,CAACW,mBAAmB,CAAC,OAAO,EAAE4C,QAAQ,CAAC;MACtD,CAAC;MACD,IAAI,CAACvD,QAAQ,CAAC6C,gBAAgB,CAAC,OAAO,EAAEU,QAAQ,CAAC;AACnD,IAAA;;AAEA;AACA,IAAA,IAAI,CAACvD,QAAQ,CAACyD,KAAK,EAAE;AACvB,EAAA;AAAC,EAAA;IAAAnB,CAAA,CAAA,IAAA,CAAA1C,SAAA,EAAA,WAAA,EAAA,CAhBA2C,MAAM,CAAA,CAAA;AAAA;AAiBT;AAACmB,oBAAA,CAAAC,QAAA,EA1LoBlE,QAAQ,CAAA;;;;"}
|
|
@@ -29,6 +29,10 @@ class HdsPopoverPrimitive extends Component {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
#_isClosing = (i(this, "_isClosing"), void 0);
|
|
32
|
+
static {
|
|
33
|
+
g(this.prototype, "_anchoredPositionOptions", [tracked]);
|
|
34
|
+
}
|
|
35
|
+
#_anchoredPositionOptions = (i(this, "_anchoredPositionOptions"), void 0);
|
|
32
36
|
_containerElement;
|
|
33
37
|
_toggleElement;
|
|
34
38
|
_popoverElement;
|
|
@@ -66,29 +70,23 @@ class HdsPopoverPrimitive extends Component {
|
|
|
66
70
|
setupPrimitiveToggle = modifier(element => {
|
|
67
71
|
this._toggleElement = element;
|
|
68
72
|
assert(`The toggle element of "Hds::PopoverPrimitive" must be a <button>; element received: <${element.tagName.toLowerCase()}>`, element instanceof HTMLButtonElement);
|
|
73
|
+
this._linkToggleAndPopover();
|
|
74
|
+
|
|
75
|
+
// Return a teardown function to clean up the modifier's side effects.
|
|
76
|
+
// This is a safeguard against bugs where this element might be
|
|
77
|
+
// cached and re-parented in the DOM, rather than being fully destroyed.
|
|
78
|
+
return () => {
|
|
79
|
+
element.removeAttribute('aria-controls');
|
|
80
|
+
element.removeAttribute('popovertarget');
|
|
81
|
+
};
|
|
69
82
|
});
|
|
70
83
|
setupPrimitivePopover = modifier((element, _positional, named) => {
|
|
71
84
|
this._popoverElement = element;
|
|
72
85
|
|
|
73
86
|
// We need to create a popoverId in order to connect the popover and the toggle with aria-controls
|
|
74
87
|
// and an id is needed to implement `onclick` event listeners
|
|
75
|
-
if (this.
|
|
76
|
-
|
|
77
|
-
if (this._popoverElement.id) {
|
|
78
|
-
popoverId = this._popoverElement.id;
|
|
79
|
-
} else {
|
|
80
|
-
// we need a DOM id for the `aria-controls` and `popovertarget` attributes
|
|
81
|
-
popoverId = guidFor(this);
|
|
82
|
-
this._popoverElement.id = popoverId;
|
|
83
|
-
}
|
|
84
|
-
this._toggleElement.setAttribute('aria-controls', popoverId);
|
|
85
|
-
|
|
86
|
-
// for the click events we don't use `onclick` event listeners, but we rely on the `popovertarget` attribute
|
|
87
|
-
// provided by the Popover API which does all the magic for us without needing JS code
|
|
88
|
-
// (important: to work it needs to be applied to a button)
|
|
89
|
-
if (this.enableClickEvents) {
|
|
90
|
-
this._toggleElement.setAttribute('popovertarget', popoverId);
|
|
91
|
-
}
|
|
88
|
+
if (!this._popoverElement.id) {
|
|
89
|
+
this._popoverElement.id = guidFor(this);
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
// this should be an extremely edge case, but in the case the popover needs to be initially forced to be open
|
|
@@ -111,27 +109,45 @@ class HdsPopoverPrimitive extends Component {
|
|
|
111
109
|
registerEvent(this._popoverElement, ['toggle', this.onTogglePopover]);
|
|
112
110
|
|
|
113
111
|
// we need to spread the argument because if it's set via `{{ hash … }}` Ember complains when we overwrite one of its values
|
|
114
|
-
|
|
112
|
+
this._anchoredPositionOptions = {
|
|
115
113
|
...named.anchoredPositionOptions
|
|
116
114
|
};
|
|
117
|
-
|
|
118
|
-
// Apply the `hds-anchored-position` modifier to the "popover" element
|
|
119
|
-
// (notice: this function runs the first time when the element the modifier was applied to is inserted into the DOM, and it autotracks while running.
|
|
120
|
-
// Any tracked values that it accesses will be tracked, including the arguments it receives, and if any of them changes, the function will run again)
|
|
121
|
-
// This modifiers uses the Floating UI library to provide:
|
|
122
|
-
// - positioning of the "popover" in relation to the "toggle"
|
|
123
|
-
// - collision detection (optional)
|
|
124
|
-
// eslint-disable-next-line ember/no-runloop
|
|
125
|
-
next(() => {
|
|
126
|
-
// @ts-expect-error: known issue with type of invocation
|
|
127
|
-
anchoredPositionModifier(this._popoverElement,
|
|
128
|
-
// element the modifier is attached to
|
|
129
|
-
[this._toggleElement],
|
|
130
|
-
// positional arguments
|
|
131
|
-
anchoredPositionOptions // named arguments
|
|
132
|
-
);
|
|
133
|
-
});
|
|
115
|
+
this._linkToggleAndPopover();
|
|
134
116
|
});
|
|
117
|
+
|
|
118
|
+
// Apply the `hds-anchored-position` modifier to the "popover" element
|
|
119
|
+
// (notice: this function runs the first time when the element the modifier was applied to is inserted into the DOM, and it autotracks while running.
|
|
120
|
+
// Any tracked values that it accesses will be tracked, including the arguments it receives, and if any of them changes, the function will run again)
|
|
121
|
+
// This modifiers uses the Floating UI library to provide:
|
|
122
|
+
// - positioning of the "popover" in relation to the "toggle"
|
|
123
|
+
// - collision detection (optional)
|
|
124
|
+
_applyAnchoredPositionModifier() {
|
|
125
|
+
if (this._toggleElement !== undefined && this._popoverElement !== undefined && this._anchoredPositionOptions !== undefined) {
|
|
126
|
+
// eslint-disable-next-line ember/no-runloop
|
|
127
|
+
next(() => {
|
|
128
|
+
// @ts-expect-error: known issue with type of invocation
|
|
129
|
+
anchoredPositionModifier(this._popoverElement,
|
|
130
|
+
// element the modifier is attached to
|
|
131
|
+
[this._toggleElement],
|
|
132
|
+
// positional arguments
|
|
133
|
+
this._anchoredPositionOptions // named arguments
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
_linkToggleAndPopover() {
|
|
139
|
+
if (this._toggleElement === undefined || this._popoverElement === undefined) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const popoverId = this._popoverElement.id;
|
|
143
|
+
this._toggleElement.setAttribute('aria-controls', popoverId);
|
|
144
|
+
if (this.enableClickEvents) {
|
|
145
|
+
this._toggleElement.setAttribute('popovertarget', popoverId);
|
|
146
|
+
} else {
|
|
147
|
+
this._toggleElement.removeAttribute('popovertarget');
|
|
148
|
+
}
|
|
149
|
+
this._applyAnchoredPositionModifier();
|
|
150
|
+
}
|
|
135
151
|
showPopover() {
|
|
136
152
|
try {
|
|
137
153
|
if (this._popoverElement) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/hds/popover-primitive/index.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { action } from '@ember/object';\nimport { assert, warn } from '@ember/debug';\nimport { next } from '@ember/runloop';\nimport { guidFor } from '@ember/object/internals';\nimport { modifier } from 'ember-modifier';\n\nimport registerEvent from '../../../modifiers/hds-register-event.ts';\nimport anchoredPositionModifier from '../../../modifiers/hds-anchored-position.ts';\n\nimport type { HdsAnchoredPositionOptions } from '../../../modifiers/hds-anchored-position.ts';\nimport type { ModifierLike } from '@glint/template';\nimport type Owner from '@ember/owner';\n\nexport interface HdsPopoverPrimitiveSignature {\n Args: {\n isOpen?: boolean;\n enableSoftEvents?: boolean;\n enableClickEvents?: boolean;\n onOpen?: () => void;\n onClose?: () => void;\n };\n Blocks: {\n default: [\n {\n setupPrimitiveContainer: ModifierLike<SetupPrimitiveContainerModifier>;\n setupPrimitiveToggle: ModifierLike<SetupPrimitiveToggleModifier>;\n setupPrimitivePopover: ModifierLike<SetupPrimitivePopoverModifier>;\n toggleElement?: HTMLButtonElement;\n popoverElement?: HTMLElement;\n isOpen: boolean;\n showPopover: () => void;\n hidePopover: (event?: Event) => void;\n togglePopover: () => void;\n },\n ];\n };\n}\n\ninterface SetupPrimitiveContainerModifier {\n Element: HTMLElement;\n}\n\nexport interface SetupPrimitiveToggleModifier {\n Element: HTMLButtonElement;\n}\n\nexport interface SetupPrimitivePopoverModifier {\n Element: HTMLElement;\n Args: {\n Positional: [];\n Named: { anchoredPositionOptions: HdsAnchoredPositionOptions };\n };\n}\n\nexport default class HdsPopoverPrimitive extends Component<HdsPopoverPrimitiveSignature> {\n @tracked private _isOpen;\n @tracked private _isClosing = false;\n private _containerElement?: HTMLElement;\n private _toggleElement?: HTMLButtonElement;\n private _popoverElement?: HTMLElement;\n // this will enable \"soft\" events for the toggle (\"hover\" and \"focus\")\n enableSoftEvents = this.args.enableSoftEvents ?? false;\n // this will enable \"click\" events for the toggle\n enableClickEvents = this.args.enableClickEvents ?? false;\n private _timer?: ReturnType<typeof setTimeout> | null;\n\n constructor(owner: Owner, args: HdsPopoverPrimitiveSignature['Args']) {\n super(owner, args);\n this._isOpen = this.args.isOpen ?? false;\n }\n\n setupPrimitiveContainer = modifier<SetupPrimitiveContainerModifier>(\n (element: HTMLElement): void => {\n this._containerElement = element;\n\n // we register the \"soft\" events\n if (this.enableSoftEvents) {\n // @ts-expect-error: known issue with type of invocation\n registerEvent(this._containerElement, [\n 'mouseenter',\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.onMouseEnter,\n ]);\n // @ts-expect-error: known issue with type of invocation\n registerEvent(this._containerElement, [\n 'mouseleave',\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.onMouseLeave,\n ]);\n // @ts-expect-error: known issue with type of invocation\n // eslint-disable-next-line @typescript-eslint/unbound-method\n registerEvent(this._containerElement, ['focusin', this.onFocusIn]);\n }\n // we always want the focusOut event\n // @ts-expect-error: known issue with type of invocation\n // eslint-disable-next-line @typescript-eslint/unbound-method\n registerEvent(this._containerElement, ['focusout', this.onFocusOut]);\n }\n );\n\n setupPrimitiveToggle = modifier<SetupPrimitiveToggleModifier>(\n (element: HTMLButtonElement): void => {\n this._toggleElement = element;\n\n assert(\n `The toggle element of \"Hds::PopoverPrimitive\" must be a <button>; element received: <${element.tagName.toLowerCase()}>`,\n element instanceof HTMLButtonElement\n );\n }\n );\n\n setupPrimitivePopover = modifier(\n (\n element: HTMLElement,\n _positional,\n named: { anchoredPositionOptions: HdsAnchoredPositionOptions }\n ): void => {\n this._popoverElement = element;\n\n // We need to create a popoverId in order to connect the popover and the toggle with aria-controls\n // and an id is needed to implement `onclick` event listeners\n if (this._toggleElement) {\n let popoverId;\n if (this._popoverElement.id) {\n popoverId = this._popoverElement.id;\n } else {\n // we need a DOM id for the `aria-controls` and `popovertarget` attributes\n popoverId = guidFor(this);\n this._popoverElement.id = popoverId;\n }\n this._toggleElement.setAttribute('aria-controls', popoverId);\n\n // for the click events we don't use `onclick` event listeners, but we rely on the `popovertarget` attribute\n // provided by the Popover API which does all the magic for us without needing JS code\n // (important: to work it needs to be applied to a button)\n if (this.enableClickEvents) {\n this._toggleElement.setAttribute('popovertarget', popoverId);\n }\n }\n\n // this should be an extremely edge case, but in the case the popover needs to be initially forced to be open\n // we need to use the \"manual\" state to support the case of multiple \"menus\" opened at the same time\n // IMPORTANT! if a \"popover\" is set to \"open\" with a \"manual\" state, then it can't be closed via `esc` and `click outside`\n if (this.args.isOpen) {\n this._popoverElement.popover = 'manual';\n this._popoverElement.showPopover();\n } else {\n this._popoverElement.popover = 'auto';\n }\n\n // Register \"onBeforeToggle\" + \"onToggle\" callback functions to be called when a native 'toggle' event is dispatched\n // @ts-expect-error: known issue with type of invocation\n registerEvent(this._popoverElement, [\n 'beforetoggle',\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.onBeforeTogglePopover,\n ]);\n // @ts-expect-error: known issue with type of invocation\n // eslint-disable-next-line @typescript-eslint/unbound-method\n registerEvent(this._popoverElement, ['toggle', this.onTogglePopover]);\n\n // we need to spread the argument because if it's set via `{{ hash … }}` Ember complains when we overwrite one of its values\n const anchoredPositionOptions: HdsAnchoredPositionOptions = {\n ...named.anchoredPositionOptions,\n };\n\n // Apply the `hds-anchored-position` modifier to the \"popover\" element\n // (notice: this function runs the first time when the element the modifier was applied to is inserted into the DOM, and it autotracks while running.\n // Any tracked values that it accesses will be tracked, including the arguments it receives, and if any of them changes, the function will run again)\n // This modifiers uses the Floating UI library to provide:\n // - positioning of the \"popover\" in relation to the \"toggle\"\n // - collision detection (optional)\n // eslint-disable-next-line ember/no-runloop\n next((): void => {\n // @ts-expect-error: known issue with type of invocation\n anchoredPositionModifier(\n this._popoverElement, // element the modifier is attached to\n [this._toggleElement], // positional arguments\n anchoredPositionOptions // named arguments\n );\n });\n }\n );\n\n @action\n showPopover(): void {\n try {\n if (this._popoverElement) {\n this._popoverElement.showPopover();\n }\n } catch (error) {\n warn(\n `The invocation of \\`showPopover\\` for the popover element caused an unexpected error: ${JSON.stringify(\n error\n )}`,\n {\n id: 'hds-popover.show-popover-action.invocation-failed',\n }\n );\n }\n }\n\n @action\n // the event may be passed by the `on` modifier, so we need to keep it as an argument here\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n hidePopover(_event?: Event): void {\n try {\n if (this._popoverElement) {\n this._popoverElement.hidePopover();\n }\n } catch (error) {\n warn(\n `The invocation of \\`hidePopover\\` for the popover element caused an unexpected error: ${JSON.stringify(\n error\n )}`,\n {\n id: 'hds-popover.hide-popover-action.invocation-failed',\n }\n );\n }\n }\n\n @action\n togglePopover(): void {\n try {\n if (this._popoverElement) {\n this._popoverElement.togglePopover();\n }\n } catch (error) {\n warn(\n `The invocation of \\`togglePopover\\` for the popover element caused an unexpected error: ${JSON.stringify(\n error\n )}`,\n {\n id: 'hds-popover.toggle-popover-action.invocation-failed',\n }\n );\n }\n }\n\n // fired just _before_ the \"popover\" is shown or hidden\n @action\n onBeforeTogglePopover(event: ToggleEvent): void {\n if (event.newState === 'closed') {\n // we need this flag to check if it's in the \"closing\" process,\n // because the browser automatically returns the focus to the \"trigger\" button\n // and this would re-open immediately the popover because of the `focusin` event\n this._isClosing = true;\n }\n }\n\n // fired just _after_ the \"popover\" is shown or hidden\n @action\n onTogglePopover(event: ToggleEvent): void {\n if (event.newState === 'open') {\n this._isOpen = true;\n\n // we call the \"onOpen\" callback if it exists (and is a function)\n const { onOpen } = this.args;\n if (typeof onOpen === 'function') {\n onOpen();\n }\n } else {\n this._isOpen = false;\n\n // reset the \"isClosing\" flag (the `toggle` event is fired _after_ the popover is closed)\n this._isClosing = false;\n\n // if the popover was initially forced to be open (using the \"manual\" state) then revert its status to `auto` once the user interacts with it\n if (this.args.isOpen) {\n if (this._popoverElement) {\n this._popoverElement.popover = 'auto';\n }\n }\n\n // we call the \"onClose\" callback if it exists (and is a function)\n const { onClose } = this.args;\n if (typeof onClose === 'function') {\n onClose();\n }\n }\n }\n\n @action\n onMouseEnter(): void {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n this.showPopover();\n }\n\n @action\n onFocusIn(): void {\n // don't re-open the popover if the focus is returned because the closing\n if (!this._isClosing) {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n this.showPopover();\n }\n }\n\n @action\n onMouseLeave(): void {\n this._timer = setTimeout((): void => this.hidePopover(), 500);\n }\n\n @action\n onFocusOut(event: FocusEvent): void {\n if (this._containerElement) {\n let isFocusStillInside = false;\n if (\n event.relatedTarget &&\n // if the related target is not part of the disclosed content we close the disclosed container\n this._containerElement.contains(event.relatedTarget as Node)\n ) {\n isFocusStillInside = true;\n } else if (\n document.activeElement &&\n // due to inconsistent implementation of relatedTarget across browsers we use the activeElement as a fallback\n this._containerElement.contains(document.activeElement)\n ) {\n isFocusStillInside = true;\n }\n // if the target receiving the focus is _not_ part of the disclosed content we close the disclosed container\n if (!isFocusStillInside) {\n this.hidePopover();\n }\n }\n }\n}\n"],"names":["HdsPopoverPrimitive","Component","g","prototype","tracked","i","void 0","_containerElement","_toggleElement","_popoverElement","enableSoftEvents","args","enableClickEvents","_timer","constructor","owner","_isOpen","isOpen","setupPrimitiveContainer","modifier","element","registerEvent","onMouseEnter","onMouseLeave","onFocusIn","onFocusOut","setupPrimitiveToggle","assert","tagName","toLowerCase","HTMLButtonElement","setupPrimitivePopover","_positional","named","popoverId","id","guidFor","setAttribute","popover","showPopover","onBeforeTogglePopover","onTogglePopover","anchoredPositionOptions","next","anchoredPositionModifier","error","warn","JSON","stringify","n","action","hidePopover","_event","togglePopover","event","newState","_isClosing","onOpen","onClose","clearTimeout","setTimeout","isFocusStillInside","relatedTarget","contains","document","activeElement","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;;AA0De,MAAMA,mBAAmB,SAASC,SAAS,CAA+B;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,SAAA,EAAA,CACtFC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,QAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,SAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAJ,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,YAAA,EAAA,CACPC,OAAO,CAAA,EAAA,YAAA;AAAA,MAAA,OAAsB,KAAK;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA,EAAA,WAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,YAAA,CAAA,EAAAC,MAAA;EAC3BC,iBAAiB;EACjBC,cAAc;EACdC,eAAe;AACvB;AACAC,EAAAA,gBAAgB,GAAG,IAAI,CAACC,IAAI,CAACD,gBAAgB,IAAI,KAAK;AACtD;AACAE,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Q,aAAqB,CAAC,EAC5D;AACAD,QAAAA,kBAAkB,GAAG,IAAI;AAC3B,MAAA,CAAC,MAAM,IACLG,QAAQ,CAACC,aAAa;AACtB;MACA,IAAI,CAAC1D,iBAAiB,CAACwD,QAAQ,CAACC,QAAQ,CAACC,aAAa,CAAC,EACvD;AACAJ,QAAAA,kBAAkB,GAAG,IAAI;AAC3B,MAAA;AACA;MACA,IAAI,CAACA,kBAAkB,EAAE;QACvB,IAAI,CAACV,WAAW,EAAE;AACpB,MAAA;AACF,IAAA;AACF,EAAA;AAAC,EAAA;IAAAF,CAAA,CAAA,IAAA,CAAA9C,SAAA,EAAA,YAAA,EAAA,CAtBA+C,MAAM,CAAA,CAAA;AAAA;AAuBT;AAACgB,oBAAA,CAAAC,QAAA,EApRoBnE,mBAAmB,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/hds/popover-primitive/index.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { action } from '@ember/object';\nimport { assert, warn } from '@ember/debug';\nimport { next } from '@ember/runloop';\nimport { guidFor } from '@ember/object/internals';\nimport { modifier } from 'ember-modifier';\n\nimport registerEvent from '../../../modifiers/hds-register-event.ts';\nimport anchoredPositionModifier from '../../../modifiers/hds-anchored-position.ts';\n\nimport type { HdsAnchoredPositionOptions } from '../../../modifiers/hds-anchored-position.ts';\nimport type { ModifierLike } from '@glint/template';\nimport type Owner from '@ember/owner';\n\nexport interface HdsPopoverPrimitiveSignature {\n Args: {\n isOpen?: boolean;\n enableSoftEvents?: boolean;\n enableClickEvents?: boolean;\n onOpen?: () => void;\n onClose?: () => void;\n };\n Blocks: {\n default: [\n {\n setupPrimitiveContainer: ModifierLike<SetupPrimitiveContainerModifier>;\n setupPrimitiveToggle: ModifierLike<SetupPrimitiveToggleModifier>;\n setupPrimitivePopover: ModifierLike<SetupPrimitivePopoverModifier>;\n toggleElement?: HTMLButtonElement;\n popoverElement?: HTMLElement;\n isOpen: boolean;\n showPopover: () => void;\n hidePopover: (event?: Event) => void;\n togglePopover: () => void;\n },\n ];\n };\n}\n\ninterface SetupPrimitiveContainerModifier {\n Element: HTMLElement;\n}\n\nexport interface SetupPrimitiveToggleModifier {\n Element: HTMLButtonElement;\n}\n\nexport interface SetupPrimitivePopoverModifier {\n Element: HTMLElement;\n Args: {\n Positional: [];\n Named: { anchoredPositionOptions: HdsAnchoredPositionOptions };\n };\n}\n\nexport default class HdsPopoverPrimitive extends Component<HdsPopoverPrimitiveSignature> {\n @tracked private _isOpen;\n @tracked private _isClosing = false;\n @tracked private _anchoredPositionOptions?: HdsAnchoredPositionOptions;\n private _containerElement?: HTMLElement;\n private _toggleElement?: HTMLButtonElement;\n private _popoverElement?: HTMLElement;\n // this will enable \"soft\" events for the toggle (\"hover\" and \"focus\")\n enableSoftEvents = this.args.enableSoftEvents ?? false;\n // this will enable \"click\" events for the toggle\n enableClickEvents = this.args.enableClickEvents ?? false;\n private _timer?: ReturnType<typeof setTimeout> | null;\n\n constructor(owner: Owner, args: HdsPopoverPrimitiveSignature['Args']) {\n super(owner, args);\n this._isOpen = this.args.isOpen ?? false;\n }\n\n setupPrimitiveContainer = modifier<SetupPrimitiveContainerModifier>(\n (element: HTMLElement): void => {\n this._containerElement = element;\n\n // we register the \"soft\" events\n if (this.enableSoftEvents) {\n // @ts-expect-error: known issue with type of invocation\n registerEvent(this._containerElement, [\n 'mouseenter',\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.onMouseEnter,\n ]);\n // @ts-expect-error: known issue with type of invocation\n registerEvent(this._containerElement, [\n 'mouseleave',\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.onMouseLeave,\n ]);\n // @ts-expect-error: known issue with type of invocation\n // eslint-disable-next-line @typescript-eslint/unbound-method\n registerEvent(this._containerElement, ['focusin', this.onFocusIn]);\n }\n // we always want the focusOut event\n // @ts-expect-error: known issue with type of invocation\n // eslint-disable-next-line @typescript-eslint/unbound-method\n registerEvent(this._containerElement, ['focusout', this.onFocusOut]);\n }\n );\n\n setupPrimitiveToggle = modifier<SetupPrimitiveToggleModifier>(\n (element: HTMLButtonElement) => {\n this._toggleElement = element;\n\n assert(\n `The toggle element of \"Hds::PopoverPrimitive\" must be a <button>; element received: <${element.tagName.toLowerCase()}>`,\n element instanceof HTMLButtonElement\n );\n\n this._linkToggleAndPopover();\n\n // Return a teardown function to clean up the modifier's side effects.\n // This is a safeguard against bugs where this element might be\n // cached and re-parented in the DOM, rather than being fully destroyed.\n return () => {\n element.removeAttribute('aria-controls');\n element.removeAttribute('popovertarget');\n };\n }\n );\n\n setupPrimitivePopover = modifier(\n (\n element: HTMLElement,\n _positional,\n named: { anchoredPositionOptions: HdsAnchoredPositionOptions }\n ): void => {\n this._popoverElement = element;\n\n // We need to create a popoverId in order to connect the popover and the toggle with aria-controls\n // and an id is needed to implement `onclick` event listeners\n if (!this._popoverElement.id) {\n this._popoverElement.id = guidFor(this);\n }\n\n // this should be an extremely edge case, but in the case the popover needs to be initially forced to be open\n // we need to use the \"manual\" state to support the case of multiple \"menus\" opened at the same time\n // IMPORTANT! if a \"popover\" is set to \"open\" with a \"manual\" state, then it can't be closed via `esc` and `click outside`\n if (this.args.isOpen) {\n this._popoverElement.popover = 'manual';\n this._popoverElement.showPopover();\n } else {\n this._popoverElement.popover = 'auto';\n }\n\n // Register \"onBeforeToggle\" + \"onToggle\" callback functions to be called when a native 'toggle' event is dispatched\n // @ts-expect-error: known issue with type of invocation\n registerEvent(this._popoverElement, [\n 'beforetoggle',\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.onBeforeTogglePopover,\n ]);\n // @ts-expect-error: known issue with type of invocation\n // eslint-disable-next-line @typescript-eslint/unbound-method\n registerEvent(this._popoverElement, ['toggle', this.onTogglePopover]);\n\n // we need to spread the argument because if it's set via `{{ hash … }}` Ember complains when we overwrite one of its values\n this._anchoredPositionOptions = {\n ...named.anchoredPositionOptions,\n };\n\n this._linkToggleAndPopover();\n }\n );\n\n // Apply the `hds-anchored-position` modifier to the \"popover\" element\n // (notice: this function runs the first time when the element the modifier was applied to is inserted into the DOM, and it autotracks while running.\n // Any tracked values that it accesses will be tracked, including the arguments it receives, and if any of them changes, the function will run again)\n // This modifiers uses the Floating UI library to provide:\n // - positioning of the \"popover\" in relation to the \"toggle\"\n // - collision detection (optional)\n private _applyAnchoredPositionModifier(): void {\n if (\n this._toggleElement !== undefined &&\n this._popoverElement !== undefined &&\n this._anchoredPositionOptions !== undefined\n ) {\n // eslint-disable-next-line ember/no-runloop\n next((): void => {\n // @ts-expect-error: known issue with type of invocation\n anchoredPositionModifier(\n this._popoverElement, // element the modifier is attached to\n [this._toggleElement], // positional arguments\n this._anchoredPositionOptions // named arguments\n );\n });\n }\n }\n\n private _linkToggleAndPopover(): void {\n if (\n this._toggleElement === undefined ||\n this._popoverElement === undefined\n ) {\n return;\n }\n\n const popoverId = this._popoverElement.id;\n\n this._toggleElement.setAttribute('aria-controls', popoverId);\n\n if (this.enableClickEvents) {\n this._toggleElement.setAttribute('popovertarget', popoverId);\n } else {\n this._toggleElement.removeAttribute('popovertarget');\n }\n\n this._applyAnchoredPositionModifier();\n }\n\n @action\n showPopover(): void {\n try {\n if (this._popoverElement) {\n this._popoverElement.showPopover();\n }\n } catch (error) {\n warn(\n `The invocation of \\`showPopover\\` for the popover element caused an unexpected error: ${JSON.stringify(\n error\n )}`,\n {\n id: 'hds-popover.show-popover-action.invocation-failed',\n }\n );\n }\n }\n\n @action\n // the event may be passed by the `on` modifier, so we need to keep it as an argument here\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n hidePopover(_event?: Event): void {\n try {\n if (this._popoverElement) {\n this._popoverElement.hidePopover();\n }\n } catch (error) {\n warn(\n `The invocation of \\`hidePopover\\` for the popover element caused an unexpected error: ${JSON.stringify(\n error\n )}`,\n {\n id: 'hds-popover.hide-popover-action.invocation-failed',\n }\n );\n }\n }\n\n @action\n togglePopover(): void {\n try {\n if (this._popoverElement) {\n this._popoverElement.togglePopover();\n }\n } catch (error) {\n warn(\n `The invocation of \\`togglePopover\\` for the popover element caused an unexpected error: ${JSON.stringify(\n error\n )}`,\n {\n id: 'hds-popover.toggle-popover-action.invocation-failed',\n }\n );\n }\n }\n\n // fired just _before_ the \"popover\" is shown or hidden\n @action\n onBeforeTogglePopover(event: ToggleEvent): void {\n if (event.newState === 'closed') {\n // we need this flag to check if it's in the \"closing\" process,\n // because the browser automatically returns the focus to the \"trigger\" button\n // and this would re-open immediately the popover because of the `focusin` event\n this._isClosing = true;\n }\n }\n\n // fired just _after_ the \"popover\" is shown or hidden\n @action\n onTogglePopover(event: ToggleEvent): void {\n if (event.newState === 'open') {\n this._isOpen = true;\n\n // we call the \"onOpen\" callback if it exists (and is a function)\n const { onOpen } = this.args;\n if (typeof onOpen === 'function') {\n onOpen();\n }\n } else {\n this._isOpen = false;\n\n // reset the \"isClosing\" flag (the `toggle` event is fired _after_ the popover is closed)\n this._isClosing = false;\n\n // if the popover was initially forced to be open (using the \"manual\" state) then revert its status to `auto` once the user interacts with it\n if (this.args.isOpen) {\n if (this._popoverElement) {\n this._popoverElement.popover = 'auto';\n }\n }\n\n // we call the \"onClose\" callback if it exists (and is a function)\n const { onClose } = this.args;\n if (typeof onClose === 'function') {\n onClose();\n }\n }\n }\n\n @action\n onMouseEnter(): void {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n this.showPopover();\n }\n\n @action\n onFocusIn(): void {\n // don't re-open the popover if the focus is returned because the closing\n if (!this._isClosing) {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n this.showPopover();\n }\n }\n\n @action\n onMouseLeave(): void {\n this._timer = setTimeout((): void => this.hidePopover(), 500);\n }\n\n @action\n onFocusOut(event: FocusEvent): void {\n if (this._containerElement) {\n let isFocusStillInside = false;\n if (\n event.relatedTarget &&\n // if the related target is not part of the disclosed content we close the disclosed container\n this._containerElement.contains(event.relatedTarget as Node)\n ) {\n isFocusStillInside = true;\n } else if (\n document.activeElement &&\n // due to inconsistent implementation of relatedTarget across browsers we use the activeElement as a fallback\n this._containerElement.contains(document.activeElement)\n ) {\n isFocusStillInside = true;\n }\n // if the target receiving the focus is _not_ part of the disclosed content we close the disclosed container\n if (!isFocusStillInside) {\n this.hidePopover();\n }\n }\n }\n}\n"],"names":["HdsPopoverPrimitive","Component","g","prototype","tracked","i","void 0","_containerElement","_toggleElement","_popoverElement","enableSoftEvents","args","enableClickEvents","_timer","constructor","owner","_isOpen","isOpen","setupPrimitiveContainer","modifier","element","registerEvent","onMouseEnter","onMouseLeave","onFocusIn","onFocusOut","setupPrimitiveToggle","assert","tagName","toLowerCase","HTMLButtonElement","_linkToggleAndPopover","removeAttribute","setupPrimitivePopover","_positional","named","id","guidFor","popover","showPopover","onBeforeTogglePopover","onTogglePopover","_anchoredPositionOptions","anchoredPositionOptions","_applyAnchoredPositionModifier","undefined","next","anchoredPositionModifier","popoverId","setAttribute","error","warn","JSON","stringify","n","action","hidePopover","_event","togglePopover","event","newState","_isClosing","onOpen","onClose","clearTimeout","setTimeout","isFocusStillInside","relatedTarget","contains","document","activeElement","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;;AA0De,MAAMA,mBAAmB,SAASC,SAAS,CAA+B;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,SAAA,EAAA,CACtFC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,QAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,SAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAJ,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,YAAA,EAAA,CACPC,OAAO,CAAA,EAAA,YAAA;AAAA,MAAA,OAAsB,KAAK;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA,EAAA,WAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,YAAA,CA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,CAAA,IAAA,CAAAnD,SAAA,EAAA,YAAA,EAAA,CAtBAoD,MAAM,CAAA,CAAA;AAAA;AAuBT;AAACgB,oBAAA,CAAAC,QAAA,EA/SoBxE,mBAAmB,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/hds/separator/index.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { assert } from '@ember/debug';\n\nimport { HdsSeparatorSpacingValues } from './types.ts';\nimport type { HdsSeparatorSpacing } from './types.ts';\n\nexport const DEFAULT_SPACING = HdsSeparatorSpacingValues.TwentyFour;\nexport const SPACING:
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/hds/separator/index.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { assert } from '@ember/debug';\n\nimport { HdsSeparatorSpacingValues } from './types.ts';\nimport type { HdsSeparatorSpacing } from './types.ts';\n\nexport const DEFAULT_SPACING = HdsSeparatorSpacingValues.TwentyFour;\nexport const SPACING: HdsSeparatorSpacing[] = Object.values(\n HdsSeparatorSpacingValues\n);\n\nexport interface HdsSeparatorSignature {\n Args: {\n spacing?: HdsSeparatorSpacing;\n };\n Element: HTMLElement;\n}\n\nexport default class HdsSeparator extends Component<HdsSeparatorSignature> {\n /**\n * Sets the margin for the separator\n * Accepted values: 24, 0\n *\n * @param spacing\n * @type {HdsSeparatorSpacing}\n * @default 24\n */\n get spacing(): HdsSeparatorSpacing {\n const { spacing = DEFAULT_SPACING } = this.args;\n\n assert(\n `@spacing for \"Hds::Separator\" must be one of the following: ${SPACING.join(\n ', '\n )}; received: ${spacing}`,\n SPACING.includes(spacing)\n );\n\n return spacing;\n }\n\n /**\n * Get the class names to apply to the component.\n * @method classNames\n * @return {string} The \"class\" attribute to apply to the component.\n */\n get classNames(): string {\n const classes = ['hds-separator'];\n\n // add a class based on the @spacing argument\n classes.push(`hds-separator--spacing-${this.spacing}`);\n\n return classes.join(' ');\n }\n}\n"],"names":["DEFAULT_SPACING","HdsSeparatorSpacingValues","TwentyFour","SPACING","Object","values","HdsSeparator","Component","spacing","args","assert","join","includes","classNames","classes","push","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;;AAQO,MAAMA,eAAe,GAAGC,yBAAyB,CAACC;AAClD,MAAMC,OAA8B,GAAGC,MAAM,CAACC,MAAM,CACzDJ,yBACF;AASe,MAAMK,YAAY,SAASC,SAAS,CAAwB;AACzE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,IAAIC,OAAOA,GAAwB;IACjC,MAAM;AAAEA,MAAAA,OAAO,GAAGR;KAAiB,GAAG,IAAI,CAACS,IAAI;AAE/CC,IAAAA,MAAM,CACJ,CAAA,4DAAA,EAA+DP,OAAO,CAACQ,IAAI,CACzE,IACF,CAAC,CAAA,YAAA,EAAeH,OAAO,CAAA,CAAE,EACzBL,OAAO,CAACS,QAAQ,CAACJ,OAAO,CAC1B,CAAC;AAED,IAAA,OAAOA,OAAO;AAChB,EAAA;;AAEA;AACF;AACA;AACA;AACA;EACE,IAAIK,UAAUA,GAAW;AACvB,IAAA,MAAMC,OAAO,GAAG,CAAC,eAAe,CAAC;;AAEjC;IACAA,OAAO,CAACC,IAAI,CAAC,CAAA,uBAAA,EAA0B,IAAI,CAACP,OAAO,EAAE,CAAC;AAEtD,IAAA,OAAOM,OAAO,CAACH,IAAI,CAAC,GAAG,CAAC;AAC1B,EAAA;AACF;AAACK,oBAAA,CAAAC,QAAA,EAnCoBX,YAAY,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step.js","sources":["../../../../../src/components/hds/stepper/list/step.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { assert } from '@ember/debug';\nimport { guidFor } from '@ember/object/internals';\nimport { modifier } from 'ember-modifier';\n\nimport {\n HdsStepperStatusesValues,\n HdsStepperStatusToSrOnlyText,\n HdsStepperTitleTagValues,\n} from '../types.ts';\n\nimport type {\n HdsStepperListStepIds,\n HdsStepperStatuses,\n HdsStepperTitleTags,\n} from '../types.ts';\n\nexport const DEFAULT_STATUS = HdsStepperStatusesValues.Incomplete;\nexport const STATUSES:
|
|
1
|
+
{"version":3,"file":"step.js","sources":["../../../../../src/components/hds/stepper/list/step.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { assert } from '@ember/debug';\nimport { guidFor } from '@ember/object/internals';\nimport { modifier } from 'ember-modifier';\n\nimport {\n HdsStepperStatusesValues,\n HdsStepperStatusToSrOnlyText,\n HdsStepperTitleTagValues,\n} from '../types.ts';\n\nimport type {\n HdsStepperListStepIds,\n HdsStepperStatuses,\n HdsStepperTitleTags,\n} from '../types.ts';\n\nexport const DEFAULT_STATUS = HdsStepperStatusesValues.Incomplete;\nexport const STATUSES: HdsStepperStatuses[] = Object.values(\n HdsStepperStatusesValues\n);\nexport const MAPPING_STATUS_TO_SR_ONLY_TEXT = HdsStepperStatusToSrOnlyText;\n\nexport interface HdsStepperListStepSignature {\n Args: {\n status?: HdsStepperStatuses;\n titleTag?: HdsStepperTitleTags;\n stepIds?: HdsStepperListStepIds;\n didInsertNode?: (element: HTMLElement) => void;\n willDestroyNode?: (element: HTMLElement) => void;\n };\n Blocks: {\n title: [];\n description?: [];\n content?: [];\n };\n Element: HTMLElement;\n}\n\nexport default class HdsStepperListStep extends Component<HdsStepperListStepSignature> {\n private _stepId = 'step-' + guidFor(this);\n\n private _setUpStep = modifier(\n (\n element: HTMLElement,\n [insertCallbackFunction, destroyCallbackFunction]\n ) => {\n if (typeof insertCallbackFunction === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n insertCallbackFunction(element);\n }\n\n return () => {\n if (typeof destroyCallbackFunction === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n destroyCallbackFunction(element);\n }\n };\n }\n );\n\n get stepNumber(): number | undefined {\n return this.args.stepIds\n ? this.args.stepIds.indexOf(this._stepId) + 1\n : undefined;\n }\n\n get status(): HdsStepperStatuses {\n const { status = DEFAULT_STATUS } = this.args;\n\n assert(\n `@status for \"Hds::Stepper::List::Step\" must be one of the following: ${STATUSES.join(\n ', '\n )}; received: ${status}`,\n STATUSES.includes(status)\n );\n\n return status;\n }\n\n get statusSrOnlyText(): string {\n return MAPPING_STATUS_TO_SR_ONLY_TEXT[this.status];\n }\n\n get titleTag(): HdsStepperTitleTags {\n return this.args.titleTag ?? HdsStepperTitleTagValues.Div;\n }\n\n get classNames(): string {\n const classes = ['hds-stepper-list__step'];\n\n classes.push(`hds-stepper-list__step--${this.status}`);\n\n return classes.join(' ');\n }\n}\n"],"names":["DEFAULT_STATUS","HdsStepperStatusesValues","Incomplete","STATUSES","Object","values","MAPPING_STATUS_TO_SR_ONLY_TEXT","HdsStepperStatusToSrOnlyText","HdsStepperListStep","Component","_stepId","guidFor","_setUpStep","modifier","element","insertCallbackFunction","destroyCallbackFunction","stepNumber","args","stepIds","indexOf","undefined","status","assert","join","includes","statusSrOnlyText","titleTag","HdsStepperTitleTagValues","Div","classNames","classes","push","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;;AAmBO,MAAMA,cAAc,GAAGC,wBAAwB,CAACC;AAChD,MAAMC,QAA8B,GAAGC,MAAM,CAACC,MAAM,CACzDJ,wBACF;AACO,MAAMK,8BAA8B,GAAGC;AAkB/B,MAAMC,kBAAkB,SAASC,SAAS,CAA8B;AAC7EC,EAAAA,OAAO,GAAG,OAAO,GAAGC,OAAO,CAAC,IAAI,CAAC;EAEjCC,UAAU,GAAGC,QAAQ,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AACP,IAAI,CAAC,GAAG,CAAC;AAC1B,EAAA;AACF;AAACS,oBAAA,CAAAC,QAAA,EAxDoB1B,kBAAkB,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/hds/table/index.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { action } from '@ember/object';\nimport { assert } from '@ember/debug';\nimport { service } from '@ember/service';\nimport { tracked } from '@glimmer/tracking';\nimport type { ComponentLike } from '@glint/template';\n\nimport type HdsIntlService from '../../../services/hds-intl.ts';\nimport {\n HdsTableDensityValues,\n HdsTableThSortOrderValues,\n HdsTableVerticalAlignmentValues,\n} from './types.ts';\nimport type {\n HdsTableColumn,\n HdsTableDensities,\n HdsTableHorizontalAlignment,\n HdsTableOnSelectionChangeSignature,\n HdsTableSelectableRow,\n HdsTableSortingFunction,\n HdsTableThSortOrder,\n HdsTableVerticalAlignment,\n HdsTableModel,\n} from './types';\nimport type { HdsFormCheckboxBaseSignature } from '../form/checkbox/base';\nimport type { HdsTableTdSignature } from './td.ts';\nimport type { HdsTableThSignature } from './th.ts';\nimport type { HdsTableThSortSignature } from './th-sort.ts';\nimport type { HdsTableTrSignature } from './tr.ts';\nimport type Owner from '@ember/owner';\n\nexport const DENSITIES: HdsTableDensities[] = Object.values(\n HdsTableDensityValues\n);\nexport const DEFAULT_DENSITY = HdsTableDensityValues.Medium;\n\nexport const VALIGNMENTS: HdsTableVerticalAlignment[] = Object.values(\n HdsTableVerticalAlignmentValues\n);\nexport const DEFAULT_VALIGN = HdsTableVerticalAlignmentValues.Top;\n\nexport interface HdsTableSignature {\n Args: {\n align?: HdsTableHorizontalAlignment;\n caption?: string;\n columns?: HdsTableColumn[];\n density?: HdsTableDensities;\n identityKey?: string;\n isFixedLayout?: boolean;\n isSelectable?: boolean;\n isStriped?: boolean;\n model?: HdsTableModel;\n onSelectionChange?: (selection: HdsTableOnSelectionChangeSignature) => void;\n onSort?: (sortBy: string, sortOrder: HdsTableThSortOrder) => void;\n selectionAriaLabelSuffix?: string;\n sortBy?: string;\n selectableColumnKey?: string;\n sortedMessageText?: string;\n sortOrder?: HdsTableThSortOrder;\n valign?: HdsTableVerticalAlignment;\n };\n Blocks: {\n head?: [\n {\n Tr?: ComponentLike<HdsTableTrSignature>;\n Th?: ComponentLike<HdsTableThSignature>;\n ThSort?: ComponentLike<HdsTableThSortSignature>;\n sortBy?: string;\n sortOrder?: HdsTableThSortOrder;\n setSortBy?: (column: string) => void;\n },\n ];\n body?: [\n {\n Td?: ComponentLike<HdsTableTdSignature>;\n Tr?: ComponentLike<HdsTableTrSignature>;\n Th?: ComponentLike<HdsTableThSignature>;\n data?: Record<string, unknown>;\n rowIndex?: number;\n sortBy?: string;\n sortOrder?: HdsTableThSortOrder;\n },\n ];\n };\n Element: HTMLTableElement;\n}\n\nexport default class HdsTable extends Component<HdsTableSignature> {\n @service hdsIntl!: HdsIntlService;\n\n @tracked sortBy;\n @tracked sortOrder;\n @tracked\n private _selectAllCheckbox?: HdsFormCheckboxBaseSignature['Element'] =\n undefined;\n private _selectableRows: HdsTableSelectableRow[] = [];\n @tracked private _isSelectAllCheckboxSelected?: boolean = undefined;\n\n constructor(owner: Owner, args: HdsTableSignature['Args']) {\n super(owner, args);\n this.sortBy = this.args.sortBy ?? undefined;\n this.sortOrder = this.args.sortOrder ?? HdsTableThSortOrderValues.Asc;\n }\n\n get getSortCriteria(): string | HdsTableSortingFunction<unknown> {\n // get the current column\n const currentColumn = this.args?.columns?.find(\n (column) => column.key === this.sortBy\n );\n if (\n // check if there is a custom sorting function associated with the current `sortBy` column (we assume the column has `isSortable`)\n currentColumn?.sortingFunction &&\n typeof currentColumn.sortingFunction === 'function'\n ) {\n return currentColumn.sortingFunction;\n } else {\n // otherwise fallback to the default format \"sortBy:sortOrder\"\n return `${this.sortBy}:${this.sortOrder}`;\n }\n }\n\n get identityKey(): string | undefined {\n // we have to provide a way for the consumer to pass undefined because Ember tries to interpret undefined as missing an arg and therefore falls back to the default\n if (this.args.identityKey === 'none') {\n return undefined;\n } else {\n return this.args.identityKey ?? '@identity';\n }\n }\n\n get sortedMessageText(): string {\n if (this.args.sortedMessageText) {\n return this.args.sortedMessageText;\n } else if (this.sortBy && this.sortOrder) {\n // we should allow the user to define a custom value here (e.g., for i18n) - tracked with HDS-965\n const translatedSortOrder = {\n [HdsTableThSortOrderValues.Asc]: this.hdsIntl.t(\n 'hds.components.common.ascending',\n { default: 'ascending' }\n ),\n [HdsTableThSortOrderValues.Desc]: this.hdsIntl.t(\n 'hds.components.common.descending',\n { default: 'descending' }\n ),\n }[this.sortOrder];\n const lowerCaseTranslatedSortOrder = translatedSortOrder.toLowerCase();\n\n return this.hdsIntl.t('hds.components.table.sorted-message-text', {\n sortBy: this.sortBy,\n sortOrder: lowerCaseTranslatedSortOrder,\n default: `Sorted by ${this.sortBy} ${lowerCaseTranslatedSortOrder}`,\n });\n } else {\n return '';\n }\n }\n\n get isStriped(): boolean {\n return this.args.isStriped ?? false;\n }\n\n get isFixedLayout(): boolean {\n return this.args.isFixedLayout ?? false;\n }\n\n get density(): HdsTableDensities {\n const { density = DEFAULT_DENSITY } = this.args;\n\n assert(\n `@density for \"Hds::Table\" must be one of the following: ${DENSITIES.join(\n ', '\n )}; received: ${density}`,\n DENSITIES.includes(density)\n );\n\n return density;\n }\n\n get valign(): HdsTableVerticalAlignment {\n const { valign = DEFAULT_VALIGN } = this.args;\n\n assert(\n `@valign for \"Hds::Table\" must be one of the following: ${VALIGNMENTS.join(\n ', '\n )}; received: ${valign}`,\n VALIGNMENTS.includes(valign)\n );\n\n return valign;\n }\n\n get classNames(): string {\n const classes = ['hds-table'];\n\n // add a class based on the @isStriped argument\n if (this.isStriped) {\n classes.push('hds-table--striped');\n }\n\n // add a class based on the @isFixedLayout argument\n if (this.isFixedLayout) {\n classes.push('hds-table--layout-fixed');\n }\n\n // add a class based on the @density argument\n if (this.density) {\n classes.push(`hds-table--density-${this.density}`);\n }\n\n // add a class based on the @valign argument\n if (this.valign) {\n classes.push(`hds-table--valign-${this.valign}`);\n }\n\n return classes.join(' ');\n }\n\n @action\n setSortBy(column: string): void {\n if (this.sortBy === column) {\n // check to see if the column is already sorted and invert the sort order if so\n this.sortOrder =\n this.sortOrder === HdsTableThSortOrderValues.Asc\n ? HdsTableThSortOrderValues.Desc\n : HdsTableThSortOrderValues.Asc;\n } else {\n // otherwise, set the sort order to ascending\n this.sortBy = column;\n this.sortOrder = HdsTableThSortOrderValues.Asc;\n }\n\n const { onSort } = this.args;\n\n if (typeof onSort === 'function') {\n onSort(this.sortBy, this.sortOrder);\n }\n }\n\n onSelectionChangeCallback(\n checkbox?: HdsFormCheckboxBaseSignature['Element'],\n selectionKey?: string\n ): void {\n const { onSelectionChange } = this.args;\n if (typeof onSelectionChange === 'function') {\n onSelectionChange({\n selectionKey: selectionKey,\n selectionCheckboxElement: checkbox,\n selectedRowsKeys: this._selectableRows.reduce<string[]>((acc, row) => {\n if (row.checkbox.checked) {\n acc.push(row.selectionKey);\n }\n return acc;\n }, []),\n selectableRowsStates: this._selectableRows.reduce(\n (\n acc: { selectionKey: string; isSelected: boolean | undefined }[],\n row\n ) => {\n acc.push({\n selectionKey: row.selectionKey,\n isSelected: row.checkbox.checked,\n });\n return acc;\n },\n []\n ),\n });\n }\n }\n\n @action\n onSelectionAllChange(): void {\n this._selectableRows.forEach((row) => {\n row.checkbox.checked = this._selectAllCheckbox?.checked ?? false;\n });\n this._isSelectAllCheckboxSelected =\n this._selectAllCheckbox?.checked ?? false;\n this.onSelectionChangeCallback(this._selectAllCheckbox, 'all');\n }\n\n @action\n onSelectionRowChange(\n checkbox?: HdsFormCheckboxBaseSignature['Element'],\n selectionKey?: string\n ): void {\n this.setSelectAllState();\n this.onSelectionChangeCallback(checkbox, selectionKey);\n }\n\n @action\n didInsertSelectAllCheckbox(\n checkbox: HdsFormCheckboxBaseSignature['Element']\n ): void {\n this._selectAllCheckbox = checkbox;\n }\n\n @action\n willDestroySelectAllCheckbox(): void {\n this._selectAllCheckbox = undefined;\n }\n\n @action\n didInsertRowCheckbox(\n checkbox: HdsFormCheckboxBaseSignature['Element'],\n selectionKey?: string\n ): void {\n if (selectionKey) {\n this._selectableRows.push({ selectionKey, checkbox });\n }\n this.setSelectAllState();\n }\n\n @action\n willDestroyRowCheckbox(selectionKey?: string): void {\n this._selectableRows = this._selectableRows.filter(\n (row) => row.selectionKey !== selectionKey\n );\n this.setSelectAllState();\n }\n\n @action\n setSelectAllState(): void {\n if (this._selectAllCheckbox) {\n const selectableRowsCount = this._selectableRows.length;\n const selectedRowsCount = this._selectableRows.filter(\n (row) => row.checkbox.checked\n ).length;\n\n this._selectAllCheckbox.checked =\n selectedRowsCount === selectableRowsCount;\n this._selectAllCheckbox.indeterminate =\n selectedRowsCount > 0 && selectedRowsCount < selectableRowsCount;\n this._isSelectAllCheckboxSelected = this._selectAllCheckbox.checked;\n }\n }\n}\n"],"names":["DENSITIES","Object","values","HdsTableDensityValues","DEFAULT_DENSITY","Medium","VALIGNMENTS","HdsTableVerticalAlignmentValues","DEFAULT_VALIGN","Top","HdsTable","Component","g","prototype","service","i","void 0","tracked","undefined","_selectableRows","constructor","owner","args","sortBy","sortOrder","HdsTableThSortOrderValues","Asc","getSortCriteria","currentColumn","columns","find","column","key","sortingFunction","identityKey","sortedMessageText","translatedSortOrder","hdsIntl","t","default","Desc","lowerCaseTranslatedSortOrder","toLowerCase","isStriped","isFixedLayout","density","assert","join","includes","valign","classNames","classes","push","setSortBy","onSort","n","action","onSelectionChangeCallback","checkbox","selectionKey","onSelectionChange","selectionCheckboxElement","selectedRowsKeys","reduce","acc","row","checked","selectableRowsStates","isSelected","onSelectionAllChange","forEach","_selectAllCheckbox","_isSelectAllCheckboxSelected","onSelectionRowChange","setSelectAllState","didInsertSelectAllCheckbox","willDestroySelectAllCheckbox","didInsertRowCheckbox","willDestroyRowCheckbox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A;IAAAX,CAAA,CAAA,IAAA,CAAA1C,SAAA,EAAA,mBAAA,EAAA,CAdA2C,MAAM,CAAA,CAAA;AAAA;AAeT;AAAC4B,oBAAA,CAAAC,QAAA,EAxPoB3E,QAAQ,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/hds/table/index.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { action } from '@ember/object';\nimport { assert } from '@ember/debug';\nimport { service } from '@ember/service';\nimport { tracked } from '@glimmer/tracking';\nimport type { ComponentLike } from '@glint/template';\n\nimport type HdsIntlService from '../../../services/hds-intl.ts';\nimport {\n HdsTableDensityValues,\n HdsTableThSortOrderValues,\n HdsTableVerticalAlignmentValues,\n} from './types.ts';\nimport type {\n HdsTableColumn,\n HdsTableDensities,\n HdsTableHorizontalAlignment,\n HdsTableOnSelectionChangeSignature,\n HdsTableSelectableRow,\n HdsTableSortingFunction,\n HdsTableThSortOrder,\n HdsTableVerticalAlignment,\n HdsTableModel,\n} from './types';\nimport type { HdsFormCheckboxBaseSignature } from '../form/checkbox/base';\nimport type { HdsTableTdSignature } from './td.ts';\nimport type { HdsTableThSignature } from './th.ts';\nimport type { HdsTableThSortSignature } from './th-sort.ts';\nimport type { HdsTableTrSignature } from './tr.ts';\nimport type Owner from '@ember/owner';\n\nexport const DENSITIES: HdsTableDensities[] = Object.values(\n HdsTableDensityValues\n);\nexport const DEFAULT_DENSITY = HdsTableDensityValues.Medium;\n\nexport const VALIGNMENTS: HdsTableVerticalAlignment[] = Object.values(\n HdsTableVerticalAlignmentValues\n);\nexport const DEFAULT_VALIGN = HdsTableVerticalAlignmentValues.Top;\n\nexport interface HdsTableSignature<T = HdsTableModel> {\n Args: {\n align?: HdsTableHorizontalAlignment;\n caption?: string;\n columns?: HdsTableColumn[];\n density?: HdsTableDensities;\n identityKey?: string;\n isFixedLayout?: boolean;\n isSelectable?: boolean;\n isStriped?: boolean;\n model?: T[];\n onSelectionChange?: (selection: HdsTableOnSelectionChangeSignature) => void;\n onSort?: (sortBy: string, sortOrder: HdsTableThSortOrder) => void;\n selectionAriaLabelSuffix?: string;\n sortBy?: string;\n selectableColumnKey?: string;\n sortedMessageText?: string;\n sortOrder?: HdsTableThSortOrder;\n valign?: HdsTableVerticalAlignment;\n };\n Blocks: {\n head?: [\n {\n Tr?: ComponentLike<HdsTableTrSignature>;\n Th?: ComponentLike<HdsTableThSignature>;\n ThSort?: ComponentLike<HdsTableThSortSignature>;\n sortBy?: string;\n sortOrder?: HdsTableThSortOrder;\n setSortBy?: (column: string) => void;\n },\n ];\n body?: [\n {\n Td?: ComponentLike<HdsTableTdSignature>;\n Tr?: ComponentLike<HdsTableTrSignature>;\n Th?: ComponentLike<HdsTableThSignature>;\n data?: T;\n rowIndex?: number;\n sortBy?: string;\n sortOrder?: HdsTableThSortOrder;\n },\n ];\n };\n Element: HTMLTableElement;\n}\n\nexport default class HdsTable<T = HdsTableModel> extends Component<\n HdsTableSignature<T>\n> {\n @service hdsIntl!: HdsIntlService;\n\n @tracked sortBy;\n @tracked sortOrder;\n @tracked\n private _selectAllCheckbox?: HdsFormCheckboxBaseSignature['Element'] =\n undefined;\n private _selectableRows: HdsTableSelectableRow[] = [];\n @tracked private _isSelectAllCheckboxSelected?: boolean = undefined;\n\n constructor(owner: Owner, args: HdsTableSignature<T>['Args']) {\n super(owner, args);\n this.sortBy = this.args.sortBy ?? undefined;\n this.sortOrder = this.args.sortOrder ?? HdsTableThSortOrderValues.Asc;\n }\n\n get getSortCriteria(): string | HdsTableSortingFunction<unknown> {\n // get the current column\n const currentColumn = this.args?.columns?.find(\n (column) => column.key === this.sortBy\n );\n if (\n // check if there is a custom sorting function associated with the current `sortBy` column (we assume the column has `isSortable`)\n currentColumn?.sortingFunction &&\n typeof currentColumn.sortingFunction === 'function'\n ) {\n return currentColumn.sortingFunction;\n } else {\n // otherwise fallback to the default format \"sortBy:sortOrder\"\n return `${this.sortBy}:${this.sortOrder}`;\n }\n }\n\n get identityKey(): string | undefined {\n // we have to provide a way for the consumer to pass undefined because Ember tries to interpret undefined as missing an arg and therefore falls back to the default\n if (this.args.identityKey === 'none') {\n return undefined;\n } else {\n return this.args.identityKey ?? '@identity';\n }\n }\n\n get sortedMessageText(): string {\n if (this.args.sortedMessageText) {\n return this.args.sortedMessageText;\n } else if (this.sortBy && this.sortOrder) {\n // we should allow the user to define a custom value here (e.g., for i18n) - tracked with HDS-965\n const translatedSortOrder = {\n [HdsTableThSortOrderValues.Asc]: this.hdsIntl.t(\n 'hds.components.common.ascending',\n { default: 'ascending' }\n ),\n [HdsTableThSortOrderValues.Desc]: this.hdsIntl.t(\n 'hds.components.common.descending',\n { default: 'descending' }\n ),\n }[this.sortOrder];\n const lowerCaseTranslatedSortOrder = translatedSortOrder.toLowerCase();\n\n return this.hdsIntl.t('hds.components.table.sorted-message-text', {\n sortBy: this.sortBy,\n sortOrder: lowerCaseTranslatedSortOrder,\n default: `Sorted by ${this.sortBy} ${lowerCaseTranslatedSortOrder}`,\n });\n } else {\n return '';\n }\n }\n\n get isStriped(): boolean {\n return this.args.isStriped ?? false;\n }\n\n get isFixedLayout(): boolean {\n return this.args.isFixedLayout ?? false;\n }\n\n get density(): HdsTableDensities {\n const { density = DEFAULT_DENSITY } = this.args;\n\n assert(\n `@density for \"Hds::Table\" must be one of the following: ${DENSITIES.join(\n ', '\n )}; received: ${density}`,\n DENSITIES.includes(density)\n );\n\n return density;\n }\n\n get valign(): HdsTableVerticalAlignment {\n const { valign = DEFAULT_VALIGN } = this.args;\n\n assert(\n `@valign for \"Hds::Table\" must be one of the following: ${VALIGNMENTS.join(\n ', '\n )}; received: ${valign}`,\n VALIGNMENTS.includes(valign)\n );\n\n return valign;\n }\n\n get classNames(): string {\n const classes = ['hds-table'];\n\n // add a class based on the @isStriped argument\n if (this.isStriped) {\n classes.push('hds-table--striped');\n }\n\n // add a class based on the @isFixedLayout argument\n if (this.isFixedLayout) {\n classes.push('hds-table--layout-fixed');\n }\n\n // add a class based on the @density argument\n if (this.density) {\n classes.push(`hds-table--density-${this.density}`);\n }\n\n // add a class based on the @valign argument\n if (this.valign) {\n classes.push(`hds-table--valign-${this.valign}`);\n }\n\n return classes.join(' ');\n }\n\n @action\n setSortBy(column: string): void {\n if (this.sortBy === column) {\n // check to see if the column is already sorted and invert the sort order if so\n this.sortOrder =\n this.sortOrder === HdsTableThSortOrderValues.Asc\n ? HdsTableThSortOrderValues.Desc\n : HdsTableThSortOrderValues.Asc;\n } else {\n // otherwise, set the sort order to ascending\n this.sortBy = column;\n this.sortOrder = HdsTableThSortOrderValues.Asc;\n }\n\n const { onSort } = this.args;\n\n if (typeof onSort === 'function') {\n onSort(this.sortBy, this.sortOrder);\n }\n }\n\n onSelectionChangeCallback(\n checkbox?: HdsFormCheckboxBaseSignature['Element'],\n selectionKey?: string\n ): void {\n const { onSelectionChange } = this.args;\n if (typeof onSelectionChange === 'function') {\n onSelectionChange({\n selectionKey: selectionKey,\n selectionCheckboxElement: checkbox,\n selectedRowsKeys: this._selectableRows.reduce<string[]>((acc, row) => {\n if (row.checkbox.checked) {\n acc.push(row.selectionKey);\n }\n return acc;\n }, []),\n selectableRowsStates: this._selectableRows.reduce(\n (\n acc: { selectionKey: string; isSelected: boolean | undefined }[],\n row\n ) => {\n acc.push({\n selectionKey: row.selectionKey,\n isSelected: row.checkbox.checked,\n });\n return acc;\n },\n []\n ),\n });\n }\n }\n\n @action\n onSelectionAllChange(): void {\n this._selectableRows.forEach((row) => {\n row.checkbox.checked = this._selectAllCheckbox?.checked ?? false;\n });\n this._isSelectAllCheckboxSelected =\n this._selectAllCheckbox?.checked ?? false;\n this.onSelectionChangeCallback(this._selectAllCheckbox, 'all');\n }\n\n @action\n onSelectionRowChange(\n checkbox?: HdsFormCheckboxBaseSignature['Element'],\n selectionKey?: string\n ): void {\n this.setSelectAllState();\n this.onSelectionChangeCallback(checkbox, selectionKey);\n }\n\n @action\n didInsertSelectAllCheckbox(\n checkbox: HdsFormCheckboxBaseSignature['Element']\n ): void {\n this._selectAllCheckbox = checkbox;\n }\n\n @action\n willDestroySelectAllCheckbox(): void {\n this._selectAllCheckbox = undefined;\n }\n\n @action\n didInsertRowCheckbox(\n checkbox: HdsFormCheckboxBaseSignature['Element'],\n selectionKey?: string\n ): void {\n if (selectionKey) {\n this._selectableRows.push({ selectionKey, checkbox });\n }\n this.setSelectAllState();\n }\n\n @action\n willDestroyRowCheckbox(selectionKey?: string): void {\n this._selectableRows = this._selectableRows.filter(\n (row) => row.selectionKey !== selectionKey\n );\n this.setSelectAllState();\n }\n\n @action\n setSelectAllState(): void {\n if (this._selectAllCheckbox) {\n const selectableRowsCount = this._selectableRows.length;\n const selectedRowsCount = this._selectableRows.filter(\n (row) => row.checkbox.checked\n ).length;\n\n this._selectAllCheckbox.checked =\n selectedRowsCount === selectableRowsCount;\n this._selectAllCheckbox.indeterminate =\n selectedRowsCount > 0 && selectedRowsCount < selectableRowsCount;\n this._isSelectAllCheckboxSelected = this._selectAllCheckbox.checked;\n }\n }\n}\n"],"names":["DENSITIES","Object","values","HdsTableDensityValues","DEFAULT_DENSITY","Medium","VALIGNMENTS","HdsTableVerticalAlignmentValues","DEFAULT_VALIGN","Top","HdsTable","Component","g","prototype","service","i","void 0","tracked","undefined","_selectableRows","constructor","owner","args","sortBy","sortOrder","HdsTableThSortOrderValues","Asc","getSortCriteria","currentColumn","columns","find","column","key","sortingFunction","identityKey","sortedMessageText","translatedSortOrder","hdsIntl","t","default","Desc","lowerCaseTranslatedSortOrder","toLowerCase","isStriped","isFixedLayout","density","assert","join","includes","valign","classNames","classes","push","setSortBy","onSort","n","action","onSelectionChangeCallback","checkbox","selectionKey","onSelectionChange","selectionCheckboxElement","selectedRowsKeys","reduce","acc","row","checked","selectableRowsStates","isSelected","onSelectionAllChange","forEach","_selectAllCheckbox","_isSelectAllCheckboxSelected","onSelectionRowChange","setSelectAllState","didInsertSelectAllCheckbox","willDestroySelectAllCheckbox","didInsertRowCheckbox","willDestroyRowCheckbox","filter","selectableRowsCount","length","selectedRowsCount","indeterminate","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;;;;;AAAA;AACA;AACA;AACA;;AAiCO,MAAMA,SAA8B,GAAGC,MAAM,CAACC,MAAM,CACzDC,qBACF;AACO,MAAMC,eAAe,GAAGD,qBAAqB,CAACE;AAE9C,MAAMC,WAAwC,GAAGL,MAAM,CAACC,MAAM,CACnEK,+BACF;AACO,MAAMC,cAAc,GAAGD,+BAA+B,CAACE;AAgD/C,MAAMC,QAAQ,SAA4BC,SAAS,CAEhE;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,SAAA,EAAA,CACCC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,QAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,SAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAJ,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAEPI,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAF,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAJ,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,WAAA,EAAA,CACPI,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,UAAA,IAAAF,CAAA,CAAA,IAAA,EAAA,WAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAJ,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,oBAAA,EAAA,CACPI,OAAO,CAAA,EAAA,YAAA;AAAA,MAAA,OAENC,SAAS;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA,EAAA,mBAAA,IAAAH,CAAA,CAAA,IAAA,EAAA,oBAAA,CAAA,EAAAC,MAAA;AACHG,EAAAA,eAAe,GAA4B,EAAE;AAAC,EAAA;IAAAP,CAAA,CAAA,IAAA,CAAAC,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AACD,kBAAkB,CAACL,OAAO;AACrE,IAAA;AACF,EAAA;AAAC,EAAA;IAAAX,CAAA,CAAA,IAAA,CAAA1C,SAAA,EAAA,mBAAA,EAAA,CAdA2C,MAAM,CAAA,CAAA;AAAA;AAeT;AAAC4B,oBAAA,CAAAC,QAAA,EA1PoB3E,QAAQ,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"td.js","sources":["../../../../src/components/hds/table/td.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { assert } from '@ember/debug';\n\nimport type { HdsTableHorizontalAlignment } from './types.ts';\nimport { HdsTableHorizontalAlignmentValues } from './types.ts';\n\nexport const ALIGNMENTS:
|
|
1
|
+
{"version":3,"file":"td.js","sources":["../../../../src/components/hds/table/td.ts"],"sourcesContent":["/**\n * Copyright (c) HashiCorp, Inc.\n * SPDX-License-Identifier: MPL-2.0\n */\n\nimport Component from '@glimmer/component';\nimport { assert } from '@ember/debug';\n\nimport type { HdsTableHorizontalAlignment } from './types.ts';\nimport { HdsTableHorizontalAlignmentValues } from './types.ts';\n\nexport const ALIGNMENTS: HdsTableHorizontalAlignment[] = Object.values(\n HdsTableHorizontalAlignmentValues\n);\nexport const DEFAULT_ALIGN = HdsTableHorizontalAlignmentValues.Left;\n\nexport interface HdsTableTdSignature {\n Args: {\n align?: HdsTableHorizontalAlignment;\n };\n Blocks: {\n default: [];\n };\n Element: HTMLTableCellElement;\n}\nexport default class HdsTableTd extends Component<HdsTableTdSignature> {\n /**\n * @param align\n * @type {string}\n * @default left\n * @description Determines the text alignment of the header or cell content. Options are: \"left\", \"center\", \"right\". If no align is defined, \"left\" is used.\n */\n get align(): HdsTableHorizontalAlignment {\n const { align = DEFAULT_ALIGN } = this.args;\n\n assert(\n `@align for \"Hds::Table::Td\" must be one of the following: ${ALIGNMENTS.join(\n ', '\n )}; received: ${align}`,\n ALIGNMENTS.includes(align)\n );\n return align;\n }\n\n /**\n * Get the class names to apply to the component.\n * @method classNames\n * @return {string} The \"class\" attribute to apply to the component.\n */\n get classNames(): string {\n const classes = [\n 'hds-table__td',\n 'hds-typography-body-200',\n 'hds-font-weight-regular',\n ];\n\n // add a class based on the @align argument\n if (this.align) {\n classes.push(`hds-table__td--align-${this.align}`);\n }\n\n return classes.join(' ');\n }\n}\n"],"names":["ALIGNMENTS","Object","values","HdsTableHorizontalAlignmentValues","DEFAULT_ALIGN","Left","HdsTableTd","Component","align","args","assert","join","includes","classNames","classes","push","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;;AAQO,MAAMA,UAAyC,GAAGC,MAAM,CAACC,MAAM,CACpEC,iCACF;AACO,MAAMC,aAAa,GAAGD,iCAAiC,CAACE;AAWhD,MAAMC,UAAU,SAASC,SAAS,CAAsB;AACrE;AACF;AACA;AACA;AACA;AACA;EACE,IAAIC,KAAKA,GAAgC;IACvC,MAAM;AAAEA,MAAAA,KAAK,GAAGJ;KAAe,GAAG,IAAI,CAACK,IAAI;AAE3CC,IAAAA,MAAM,CACJ,CAAA,0DAAA,EAA6DV,UAAU,CAACW,IAAI,CAC1E,IACF,CAAC,CAAA,YAAA,EAAeH,KAAK,CAAA,CAAE,EACvBR,UAAU,CAACY,QAAQ,CAACJ,KAAK,CAC3B,CAAC;AACD,IAAA,OAAOA,KAAK;AACd,EAAA;;AAEA;AACF;AACA;AACA;AACA;EACE,IAAIK,UAAUA,GAAW;IACvB,MAAMC,OAAO,GAAG,CACd,eAAe,EACf,yBAAyB,EACzB,yBAAyB,CAC1B;;AAED;IACA,IAAI,IAAI,CAACN,KAAK,EAAE;MACdM,OAAO,CAACC,IAAI,CAAC,CAAA,qBAAA,EAAwB,IAAI,CAACP,KAAK,EAAE,CAAC;AACpD,IAAA;AAEA,IAAA,OAAOM,OAAO,CAACH,IAAI,CAAC,GAAG,CAAC;AAC1B,EAAA;AACF;AAACK,oBAAA,CAAAC,QAAA,EAtCoBX,UAAU,CAAA;;;;"}
|