@quartzds/core 1.0.0-beta.12 → 1.0.0-beta.13
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/components/qds-dialog.js +1 -1
- package/components/qds-dialog.js.map +1 -1
- package/components/qds-dropdown.js +2 -2
- package/components/qds-dropdown.js.map +1 -1
- package/dist/cjs/qds-dialog.cjs.entry.js +1 -1
- package/dist/cjs/qds-dialog.cjs.entry.js.map +1 -1
- package/dist/cjs/qds-dropdown.cjs.entry.js +2 -2
- package/dist/cjs/qds-dropdown.cjs.entry.js.map +1 -1
- package/dist/custom-elements.json +2 -2
- package/dist/docs.json +2 -2
- package/dist/esm/qds-dialog.entry.js +1 -1
- package/dist/esm/qds-dialog.entry.js.map +1 -1
- package/dist/esm/qds-dropdown.entry.js +2 -2
- package/dist/esm/qds-dropdown.entry.js.map +1 -1
- package/dist/types/components/dialog/dialog.d.ts +1 -1
- package/dist/types/components/dropdown/dropdown.d.ts +1 -1
- package/dist/types/components.d.ts +2 -2
- package/dist/vscode.html-custom-data.json +1 -1
- package/hydrate/index.js +3 -3
- package/package.json +1 -1
package/components/qds-dialog.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
|
|
7
7
|
import { c as ignorePromise, a as invariant, i as inheritAriaAttributes } from './helpers.js';
|
|
8
8
|
|
|
9
|
-
const dialogCss = ":host{box-sizing:border-box}:host([hidden]){display:none !important}:host([hidden]){}:host *,:host *::before,:host *::after{box-sizing:inherit}:host{display:
|
|
9
|
+
const dialogCss = ":host{box-sizing:border-box}:host([hidden]){display:none !important}:host([hidden]){}:host *,:host *::before,:host *::after{box-sizing:inherit}:host{display:none;position:fixed;inset:0}:host([open]){display:block}.dialog{border-radius:var(--qds-popup-border-radius);border:none;box-shadow:var(--qds-theme-popup-elevation);padding:0}.dialog::backdrop{background:transparent none repeat 0 0 / auto auto padding-box border-box scroll;background:initial}.dialog[open]~.backdrop{-webkit-backdrop-filter:blur(var(--qds-theme-popup-overlay-blur));backdrop-filter:blur(var(--qds-theme-popup-overlay-blur));background-color:var(--qds-theme-popup-overlay-background);inset:0;opacity:var(--qds-theme-popup-overlay-opacity);position:fixed}.content{align-items:flex-start;background-color:var(--qds-theme-popup-background);display:flex;flex-direction:column;gap:var(--qds-popup-gap-children-related);padding:var(--qds-popup-padding)}::slotted(blockquote),::slotted(button),::slotted(dd),::slotted(dl),::slotted(fieldset),::slotted(figure),::slotted(h1),::slotted(h2),::slotted(h3),::slotted(h4),::slotted(h5),::slotted(h6),::slotted(hr),::slotted(input),::slotted(menu),::slotted(ol),::slotted(p),::slotted(pre),::slotted(select),::slotted(textarea),::slotted(ul){margin:0}";
|
|
10
10
|
|
|
11
11
|
const Dialog = /*@__PURE__*/ proxyCustomElement(class Dialog extends HTMLElement {
|
|
12
12
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"qds-dialog.js","mappings":";;;;;;;;AAAA,MAAM,SAAS,GAAG
|
|
1
|
+
{"file":"qds-dialog.js","mappings":";;;;;;;;AAAA,MAAM,SAAS,GAAG,8uCAA8uC;;MC8BnvC,MAAM;;;;;;;IA8BT,wBAAmB,GAAe,EAAE,CAAA;IA6E3B,gBAAW,GAAG,CAAC,KAAY;MAC1C,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;KACxC,CAAA;IAEgB,aAAQ,GAAG,CAAC,KAAY;MACvC,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,gBAAgB;QAAE,KAAK,CAAC,cAAc,EAAE,CAAA;KACvE,CAAA;IAEgB,YAAO,GAAG;MACzB,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;MAEtB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAA;MACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,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,CAAC,SAAS,YAAY,gBAAgB;UAC1C,KAAK,CAAC,SAAS,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC;OAC9C,KAAK,CAAC,MAAM,YAAY,eAAe;QACtC,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,EACnC;MACA,KAAK,CAAC,cAAc,EAAE,CAAA;MACtB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;KACnB;GACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/dialog/dialog.css?tag=qds-dialog&encapsulation=shadow","src/components/dialog/dialog.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n display: none;\n position: fixed;\n inset: 0;\n}\n\n:host([open]) {\n display: block;\n}\n\n.dialog {\n border-radius: var(--qds-popup-border-radius);\n border: none;\n box-shadow: var(--qds-theme-popup-elevation);\n padding: 0;\n\n &::backdrop {\n background: initial;\n }\n\n &[open] ~ .backdrop {\n backdrop-filter: blur(var(--qds-theme-popup-overlay-blur));\n background-color: var(--qds-theme-popup-overlay-background);\n inset: 0;\n opacity: var(--qds-theme-popup-overlay-opacity);\n position: fixed;\n }\n}\n\n.content {\n align-items: flex-start;\n background-color: var(--qds-theme-popup-background);\n display: flex;\n flex-direction: column;\n gap: var(--qds-popup-gap-children-related);\n padding: var(--qds-popup-padding);\n}\n\n::slotted(blockquote),\n::slotted(button),\n::slotted(dd),\n::slotted(dl),\n::slotted(fieldset),\n::slotted(figure),\n::slotted(h1),\n::slotted(h2),\n::slotted(h3),\n::slotted(h4),\n::slotted(h5),\n::slotted(h6),\n::slotted(hr),\n::slotted(input),\n::slotted(menu),\n::slotted(ol),\n::slotted(p),\n::slotted(pre),\n::slotted(select),\n::slotted(textarea),\n::slotted(ul) {\n margin: 0;\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Method,\n Prop,\n Watch,\n} from '@stencil/core'\n\nimport type { Attributes } from '../../helpers'\nimport { ignorePromise, inheritAriaAttributes, invariant } from '../../helpers'\n\n/**\n * The `<qds-dialog>` element represent a dialog box or other interactive\n * component, such as a dismissible alert, inspector, or subwindow.\n *\n * @see https://quartz.se.com/build/components/dialog\n */\n@Component({\n tag: 'qds-dialog',\n shadow: true,\n styleUrl: 'dialog.css',\n})\nexport class Dialog implements ComponentInterface {\n /**\n * Indicates whether or not the dialog is open. You can toggle this attribute\n * to show and hide the dialog, or you can use the `show()` and `close()`\n * methods and this attribute will reflect the dialog’s open state.\n */\n @Prop({ mutable: true, reflect: true }) public open = false\n\n @Element() private readonly element!: HTMLQdsDialogElement\n\n /**\n * Emitted when the user instructs the browser that they wish to dismiss the\n * currently open dialog. The browser fires this event when the user presses\n * the `Esc` key.\n *\n * When a dialog is dismissed with the `Esc` key, both the `qdsCancel` and\n * `qdsClose` events are fired.\n */\n @Event({ eventName: 'qdsCancel', bubbles: false, composed: false })\n private readonly cancelEmitter!: EventEmitter<void>\n\n /** Emitted when the dialog has been closed. */\n @Event({\n eventName: 'qdsClose',\n bubbles: false,\n cancelable: false,\n composed: false,\n })\n private readonly closeEmitter!: EventEmitter<void>\n\n private inheritedAttributes: Attributes = {}\n\n private dialog?: HTMLDialogElement\n\n /**\n * Displays the dialog over the top of any other dialogs that might be\n * present. Everything outside of the dialog is [inert][] with interactions\n * outside of the dialog being blocked.\n *\n * [inert]: https://developer.mozilla.org/docs/Web/API/HTMLElement/inert\n */\n @Method()\n public async show(): Promise<void> {\n invariant(this.dialog)\n\n this.dialog.showModal()\n this.open = this.dialog.open\n }\n\n /**\n * Closes the dialog.\n */\n @Method()\n public async close(): Promise<void> {\n invariant(this.dialog)\n\n this.dialog.close()\n }\n\n @Watch('open')\n protected async openChanged(): Promise<void> {\n await (this.open ? this.show() : this.close())\n }\n\n public componentWillLoad(): void {\n this.inheritedAttributes = inheritAriaAttributes(this.element)\n }\n\n public async componentDidLoad(): Promise<void> {\n if (this.open) await this.show()\n }\n\n public render() {\n return (\n <Host>\n <dialog\n class=\"dialog\"\n ref={this.ref}\n onSubmit={this.boundSubmit}\n onCancel={this.onCancel}\n onClose={this.onClose}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...this.inheritedAttributes}\n >\n <div class=\"content\">\n <slot />\n </div>\n </dialog>\n <div class=\"backdrop\" />\n </Host>\n )\n }\n\n private async handleSubmit(event: Event): Promise<void> {\n if (\n (event instanceof SubmitEvent &&\n (event.submitter instanceof HTMLButtonElement ||\n (event.submitter instanceof HTMLInputElement &&\n event.submitter.formMethod === 'dialog'))) ||\n (event.target instanceof HTMLFormElement &&\n event.target.method === 'dialog')\n ) {\n event.preventDefault()\n await this.close()\n }\n }\n\n private readonly boundSubmit = (event: Event): void => {\n ignorePromise(this.handleSubmit(event))\n }\n\n private readonly onCancel = (event: Event): void => {\n if (this.cancelEmitter.emit().defaultPrevented) event.preventDefault()\n }\n\n private readonly onClose = (): void => {\n invariant(this.dialog)\n\n this.closeEmitter.emit()\n this.open = this.dialog.open\n }\n\n private readonly ref = (dialog?: HTMLDialogElement): void => {\n this.dialog = dialog\n }\n}\n"],"version":3}
|
|
@@ -19,7 +19,7 @@ const Dropdown = /*@__PURE__*/ proxyCustomElement(class Dropdown extends HTMLEle
|
|
|
19
19
|
this.closeEmitter = createEvent(this, "qdsClose", 2);
|
|
20
20
|
this.open = false;
|
|
21
21
|
this.boundFocusout = (event) => {
|
|
22
|
-
ignorePromise(this.
|
|
22
|
+
ignorePromise(this.handleFocusout(event));
|
|
23
23
|
};
|
|
24
24
|
this.boundEscape = (event) => {
|
|
25
25
|
ignorePromise(this.handleEscape(event));
|
|
@@ -167,7 +167,7 @@ const Dropdown = /*@__PURE__*/ proxyCustomElement(class Dropdown extends HTMLEle
|
|
|
167
167
|
transform: this.hostTransform,
|
|
168
168
|
} }, h("slot", null)));
|
|
169
169
|
}
|
|
170
|
-
async
|
|
170
|
+
async handleFocusout(event) {
|
|
171
171
|
if (!(event instanceof FocusEvent))
|
|
172
172
|
return;
|
|
173
173
|
const { relatedTarget } = event;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"qds-dropdown.js","mappings":";;;;;;;;;AAAA,MAAM,WAAW,GAAG,2UAA2U;;AC4C/V,IAAI,kBAAkB,GAAG,CAAC,CAAA;MAYb,QAAQ;;;;;;;IA8HX,SAAI,GAAG,KAAK,CAAA;IAwLH,kBAAa,GAAG,CAAC,KAAY;MAC5C,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;KAC1C,CAAA;IAuBgB,gBAAW,GAAG,CAAC,KAAY;MAC1C,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;KACxC,CAAA;IAMgB,wBAAmB,GAAG;MACrC,aAAa,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAA;KAC3C,CAAA;;oBA5U0C,KAAK;;kBAoBN,KAAK;mBAMJ,KAAK;;qBAkBD,cAAc;;;;;;;;;;;;EA2EtD,MAAM,IAAI;IACf,IAAI,IAAI,CAAC,IAAI;MAAE,OAAM;IAErB,IAAI,IAAI,CAAC,gBAAgB,YAAY,UAAU,CAAC,OAAO,EAAE;MACvD,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAA;MAC3D,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;KACrE;IAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAChB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;IAC5B,IAAI,CAAC,eAAe,EAAE,CAAA;GACvB;;;;EAMM,MAAM,KAAK;IAChB,IAAI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AAC,gBAAgB,YAAY,UAAU,CAAC,WAAW;MACvD,IAAI,CAAC,gBAAgB,YAAY,UAAU,CAAC,UAAU;MAEtD,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAA;GAChC;EAMO,MAAM,oBAAoB;IAChC,IAAI,CAAC,IAAI,CAAC,QAAQ;MAAE,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;GACnE;EAMO,0BAA0B;IAChC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAA;IAEnC,IAAI,EAAE,IAAI,CAAC,gBAAgB,YAAY,UAAU,CAAC,OAAO,CAAC;MAAE,OAAM;IAElE,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAA;IAC5E,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IACzE,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACtE,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IACtD,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;GACvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/dropdown/dropdown.css?tag=qds-dropdown&encapsulation=shadow","src/components/dropdown/dropdown.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n background: var(--qds-theme-accessory-background);\n border-radius: var(--qds-accessory-border-radius);\n box-shadow: var(--qds-theme-accessory-elevation);\n display: inline-block;\n left: 0;\n top: 0;\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type {\n AutoUpdateOptions,\n DetectOverflowOptions,\n FlipOptions,\n Middleware,\n Placement,\n ReferenceElement,\n ShiftOptions,\n Strategy,\n} from '@floating-ui/dom'\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n} from '@floating-ui/dom'\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Listen,\n Method,\n Prop,\n State,\n Watch,\n} from '@stencil/core'\n\nimport type { OffsetOptions } from '../../helpers'\nimport {\n ignorePromise,\n invariant,\n propertyToPx,\n roundByDPR,\n} from '../../helpers'\n\nlet autoIncrementingId = 1\n\n/**\n * @experimental\n * @slot Content to display in the dropdown.\n * @see https://quartz.se.com/build/components/dropdown\n */\n@Component({\n tag: 'qds-dropdown',\n shadow: true,\n styleUrl: 'dropdown.css',\n})\nexport class Dropdown implements ComponentInterface {\n /**\n * Options to pass to Floating UI's\n * [`autoUpdate()` function](https://floating-ui.com/docs/autoUpdate).\n *\n * @see https://floating-ui.com/docs/autoupdate#options\n */\n @Prop() public readonly autoUpdateOptions?: AutoUpdateOptions\n\n /**\n * Prevents the dropdown from being shown by user interaction. The dropdown\n * can still be displayed by calling the `show()` method.\n */\n @Prop({ mutable: true }) public disabled = false\n\n /**\n * Options to pass to Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n *\n * The [`crossAxis` option](https://floating-ui.com/docs/flip#crossaxis) is\n * set to the value of the `noShift` property by default for interoperability\n * with the [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/flip#options\n */\n @Prop() public readonly flipOptions?: Partial<\n DetectOverflowOptions & FlipOptions\n >\n\n /**\n * Disable Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n */\n @Prop() public readonly noFlip: boolean = false\n\n /**\n * Disable Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n */\n @Prop() public readonly noShift: boolean = false\n\n /**\n * Options to pass to Floating UI's\n * [`offset` middleware](https://floating-ui.com/docs/offset).\n *\n * The [`mainAxis` option](https://floating-ui.com/docs/offset#mainaxis) is\n * not supported.\n *\n * @see https://floating-ui.com/docs/offset#options\n */\n @Prop() public readonly offsetOptions?: OffsetOptions\n\n /**\n * Where to place the dropdown relative to the `target`.\n *\n * @see https://floating-ui.com/docs/tutorial#placements\n */\n @Prop() public readonly placement: Placement = 'bottom-start'\n\n /**\n * Options to pass to Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/shift#options\n */\n @Prop() public readonly shiftOptions?: Partial<\n DetectOverflowOptions & ShiftOptions\n >\n\n /**\n * The CSS position strategy to use.\n *\n * @see https://floating-ui.com/docs/computeposition#strategy\n */\n @Prop() public readonly strategy?: Strategy\n\n /**\n * The trigger element that will trigger the dropdown. The target specified\n * can be any of the follow:\n *\n * - A CSS selector string\n * - A reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element) or\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements)\n * - A function returning a reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element),\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements),\n * or a CSS selector string\n */\n @Prop() public readonly target!:\n | ReferenceElement\n | string\n | (() => ReferenceElement | string)\n\n /**\n * Emitted when the user instructs the browser that they wish to dismiss the\n * current open dropdown by pressing the `Esc` key.\n *\n * When a dropdown is dismissed with the `Esc` key, both the `qdsCancel` and\n * `qdsClose` events are emitted.\n */\n @Event({ eventName: 'qdsCancel', bubbles: false })\n private readonly cancelEmitter!: EventEmitter<void>\n\n /**\n * Emitted when the dropdown is closed.\n */\n @Event({ eventName: 'qdsClose', bubbles: false, cancelable: false })\n private readonly closeEmitter!: EventEmitter<void>\n\n @Element() private readonly element!: HTMLQdsDropdownElement\n\n @State() private hostAriaLabelledBy?: string\n\n @State() private hostDisplay?: string\n\n @State() private hostPosition?: string\n\n @State() private hostTransform?: string\n\n private cleanup?: () => void\n\n private middleware?: Middleware[]\n\n private referenceElement?: ReferenceElement\n\n private open = false\n\n /**\n * Show the dropdown.\n */\n @Method()\n public async show(): Promise<void> {\n if (this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'true')\n this.referenceElement.setAttribute('aria-controls', this.element.id)\n }\n\n this.open = true\n this.hostDisplay = undefined\n this.startAutoUpdate()\n }\n\n /**\n * Close the dropdown.\n */\n @Method()\n public async close(): Promise<void> {\n if (!this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.removeAttribute('aria-controls')\n }\n\n this.open = false\n this.hostDisplay = 'none'\n if (this.cleanup) this.cleanup()\n\n this.closeEmitter.emit()\n }\n\n /**\n * Update the dropdown's middleware and position.\n */\n @Method()\n public async update(): Promise<void> {\n await this.updateMiddleware()\n }\n\n @Listen('click', { target: 'document' })\n protected async handleMouseDown(event: MouseEvent): Promise<void> {\n if (!this.open) return\n\n const composedPath = event.composedPath()\n const withinBounds =\n composedPath.includes(this.element) ||\n (this.referenceElement instanceof globalThis.Element &&\n composedPath.includes(this.referenceElement))\n if (!withinBounds) await this.close()\n }\n\n @Watch('target')\n private async updateReferenceElement(): Promise<void> {\n this.disconnectReferenceElement()\n\n const resolvedTarget =\n typeof this.target === 'function' ? this.target() : this.target\n if (typeof resolvedTarget === 'string') {\n const element = document.querySelector(resolvedTarget)\n if (element === null)\n throw new Error('String `target` must resolve to an Element.')\n this.referenceElement = element\n } else this.referenceElement = resolvedTarget\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.addEventListener('click', this.boundReferenceClick)\n this.referenceElement.addEventListener('focusout', this.boundFocusout)\n this.referenceElement.addEventListener('keydown', this.boundEscape)\n if (this.element.role === 'menu') {\n this.referenceElement.id ||= `qds-dropdown-trigger-${autoIncrementingId}`\n this.hostAriaLabelledBy = this.referenceElement.id\n }\n }\n\n @Watch('flipOptions')\n @Watch('noFlip')\n @Watch('noShift')\n @Watch('offsetOptions')\n @Watch('shiftOptions')\n private async updateMiddleware(): Promise<void> {\n this.middleware = [\n offset({\n ...this.offsetOptions,\n mainAxis:\n propertyToPx(this.element, '--qds-accessory-gap-floating') ?? 0,\n }),\n !this.noFlip &&\n flip({\n crossAxis: this.noShift,\n ...this.flipOptions,\n }),\n !this.noShift &&\n shift({\n limiter: limitShift(),\n ...this.shiftOptions,\n }),\n ].filter((middleware): middleware is Middleware => middleware !== false)\n await this.updatePosition()\n }\n\n @Watch('placement')\n @Watch('strategy')\n private async updatePosition(): Promise<void> {\n invariant(this.referenceElement)\n\n const { x, y, strategy } = await computePosition(\n this.referenceElement,\n this.element,\n {\n middleware: this.middleware,\n placement: this.placement,\n strategy: this.strategy,\n },\n )\n this.hostPosition = strategy\n this.hostTransform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`\n }\n\n @Watch('autoUpdateOptions')\n private startAutoUpdate(): void {\n invariant(this.referenceElement)\n\n if (this.cleanup) this.cleanup()\n this.cleanup = autoUpdate(\n this.referenceElement,\n this.element,\n () => {\n ignorePromise(this.updatePosition())\n },\n this.autoUpdateOptions,\n )\n }\n\n public async componentWillLoad(): Promise<void> {\n this.hostDisplay = 'none'\n this.element.role ??= 'menu'\n this.element.id ||= `qds-dropdown-${autoIncrementingId}`\n await this.updateReferenceElement()\n autoIncrementingId += 1\n await this.updateMiddleware()\n }\n\n public disconnectedCallback(): void {\n this.disconnectReferenceElement()\n }\n\n public render() {\n return (\n <Host\n aria-labelledby={this.hostAriaLabelledBy}\n onKeyDown={this.boundEscape}\n onFocusout={this.boundFocusout}\n style={{\n display: this.hostDisplay,\n position: this.hostPosition,\n transform: this.hostTransform,\n }}\n >\n <slot />\n </Host>\n )\n }\n\n private async handleFocusOut(event: Event): Promise<void> {\n if (!(event instanceof FocusEvent)) return\n const { relatedTarget } = event\n\n if (\n relatedTarget instanceof globalThis.Element &&\n !this.element.contains(relatedTarget) &&\n this.referenceElement !== relatedTarget\n )\n await this.close()\n }\n\n private readonly boundFocusout = (event: Event): void => {\n ignorePromise(this.handleFocusOut(event))\n }\n\n private async handleEscape(event: Event): Promise<void> {\n if (\n !(event instanceof KeyboardEvent) ||\n event.key !== 'Escape' ||\n (event.target !== this.referenceElement &&\n event.target instanceof globalThis.Element &&\n event.target.closest('qds-dropdown') !== this.element)\n )\n return\n\n const cancelEvent = this.cancelEmitter.emit()\n if (cancelEvent.defaultPrevented) return\n\n await this.close()\n if (\n this.referenceElement instanceof globalThis.HTMLElement ||\n this.referenceElement instanceof globalThis.SVGElement\n )\n this.referenceElement.focus()\n }\n\n private readonly boundEscape = (event: Event): void => {\n ignorePromise(this.handleEscape(event))\n }\n\n private async handleReferenceClick(): Promise<void> {\n if (!this.disabled) await (this.open ? this.close() : this.show())\n }\n\n private readonly boundReferenceClick = (): void => {\n ignorePromise(this.handleReferenceClick())\n }\n\n private disconnectReferenceElement(): void {\n this.hostAriaLabelledBy = undefined\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.removeEventListener('click', this.boundReferenceClick)\n this.referenceElement.removeEventListener('focusout', this.boundFocusout)\n this.referenceElement.removeEventListener('keydown', this.boundEscape)\n this.referenceElement.removeAttribute('aria-expanded')\n this.referenceElement.removeAttribute('aria-controls')\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"qds-dropdown.js","mappings":";;;;;;;;;AAAA,MAAM,WAAW,GAAG,2UAA2U;;AC4C/V,IAAI,kBAAkB,GAAG,CAAC,CAAA;MAYb,QAAQ;;;;;;;IA8HX,SAAI,GAAG,KAAK,CAAA;IAwLH,kBAAa,GAAG,CAAC,KAAY;MAC5C,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;KAC1C,CAAA;IAuBgB,gBAA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AO,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAA;IAC5E,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IACzE,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACtE,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IACtD,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;GACvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/dropdown/dropdown.css?tag=qds-dropdown&encapsulation=shadow","src/components/dropdown/dropdown.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n background: var(--qds-theme-accessory-background);\n border-radius: var(--qds-accessory-border-radius);\n box-shadow: var(--qds-theme-accessory-elevation);\n display: inline-block;\n left: 0;\n top: 0;\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type {\n AutoUpdateOptions,\n DetectOverflowOptions,\n FlipOptions,\n Middleware,\n Placement,\n ReferenceElement,\n ShiftOptions,\n Strategy,\n} from '@floating-ui/dom'\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n} from '@floating-ui/dom'\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Listen,\n Method,\n Prop,\n State,\n Watch,\n} from '@stencil/core'\n\nimport type { OffsetOptions } from '../../helpers'\nimport {\n ignorePromise,\n invariant,\n propertyToPx,\n roundByDPR,\n} from '../../helpers'\n\nlet autoIncrementingId = 1\n\n/**\n * @experimental\n * @slot Content to display in the dropdown.\n * @see https://quartz.se.com/build/components/dropdown\n */\n@Component({\n tag: 'qds-dropdown',\n shadow: true,\n styleUrl: 'dropdown.css',\n})\nexport class Dropdown implements ComponentInterface {\n /**\n * Options to pass to Floating UI's\n * [`autoUpdate()` function](https://floating-ui.com/docs/autoUpdate).\n *\n * @see https://floating-ui.com/docs/autoupdate#options\n */\n @Prop() public readonly autoUpdateOptions?: AutoUpdateOptions\n\n /**\n * Prevents the dropdown from being shown by user interaction. The dropdown\n * can still be displayed by calling the `show()` method.\n */\n @Prop({ mutable: true }) public disabled = false\n\n /**\n * Options to pass to Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n *\n * The [`crossAxis` option](https://floating-ui.com/docs/flip#crossaxis) is\n * set to the value of the `noShift` property by default for interoperability\n * with the [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/flip#options\n */\n @Prop() public readonly flipOptions?: Partial<\n DetectOverflowOptions & FlipOptions\n >\n\n /**\n * Disable Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n */\n @Prop() public readonly noFlip: boolean = false\n\n /**\n * Disable Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n */\n @Prop() public readonly noShift: boolean = false\n\n /**\n * Options to pass to Floating UI's\n * [`offset` middleware](https://floating-ui.com/docs/offset).\n *\n * The [`mainAxis` option](https://floating-ui.com/docs/offset#mainaxis) is\n * not supported.\n *\n * @see https://floating-ui.com/docs/offset#options\n */\n @Prop() public readonly offsetOptions?: OffsetOptions\n\n /**\n * Where to place the dropdown relative to the `target`.\n *\n * @see https://floating-ui.com/docs/tutorial#placements\n */\n @Prop() public readonly placement: Placement = 'bottom-start'\n\n /**\n * Options to pass to Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/shift#options\n */\n @Prop() public readonly shiftOptions?: Partial<\n DetectOverflowOptions & ShiftOptions\n >\n\n /**\n * The CSS position strategy to use.\n *\n * @see https://floating-ui.com/docs/computeposition#strategy\n */\n @Prop() public readonly strategy?: Strategy\n\n /**\n * The trigger element that will trigger the dropdown. The target specified\n * can be any of the follow:\n *\n * - A CSS selector string\n * - A reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element) or\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements)\n * - A function returning a reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element),\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements),\n * or a CSS selector string\n */\n @Prop() public readonly target!:\n | ReferenceElement\n | string\n | (() => ReferenceElement | string)\n\n /**\n * Emitted when the user instructs the browser that they wish to dismiss the\n * current open dropdown by pressing the `Esc` key.\n *\n * When a dropdown is dismissed with the `Esc` key, both the `qdsCancel` and\n * `qdsClose` events are emitted.\n */\n @Event({ eventName: 'qdsCancel', bubbles: false })\n private readonly cancelEmitter!: EventEmitter<void>\n\n /**\n * Emitted when the dropdown is closed.\n */\n @Event({ eventName: 'qdsClose', bubbles: false, cancelable: false })\n private readonly closeEmitter!: EventEmitter<void>\n\n @Element() private readonly element!: HTMLQdsDropdownElement\n\n @State() private hostAriaLabelledBy?: string\n\n @State() private hostDisplay?: string\n\n @State() private hostPosition?: string\n\n @State() private hostTransform?: string\n\n private cleanup?: () => void\n\n private middleware?: Middleware[]\n\n private referenceElement?: ReferenceElement\n\n private open = false\n\n /**\n * Show the dropdown.\n */\n @Method()\n public async show(): Promise<void> {\n if (this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'true')\n this.referenceElement.setAttribute('aria-controls', this.element.id)\n }\n\n this.open = true\n this.hostDisplay = undefined\n this.startAutoUpdate()\n }\n\n /**\n * Close the dropdown.\n */\n @Method()\n public async close(): Promise<void> {\n if (!this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.removeAttribute('aria-controls')\n }\n\n this.open = false\n this.hostDisplay = 'none'\n if (this.cleanup) this.cleanup()\n\n this.closeEmitter.emit()\n }\n\n /**\n * Update the dropdown's middleware and position.\n */\n @Method()\n public async update(): Promise<void> {\n await this.updateMiddleware()\n }\n\n @Listen('click', { target: 'document' })\n protected async handleMouseDown(event: MouseEvent): Promise<void> {\n if (!this.open) return\n\n const composedPath = event.composedPath()\n const withinBounds =\n composedPath.includes(this.element) ||\n (this.referenceElement instanceof globalThis.Element &&\n composedPath.includes(this.referenceElement))\n if (!withinBounds) await this.close()\n }\n\n @Watch('target')\n private async updateReferenceElement(): Promise<void> {\n this.disconnectReferenceElement()\n\n const resolvedTarget =\n typeof this.target === 'function' ? this.target() : this.target\n if (typeof resolvedTarget === 'string') {\n const element = document.querySelector(resolvedTarget)\n if (element === null)\n throw new Error('String `target` must resolve to an Element.')\n this.referenceElement = element\n } else this.referenceElement = resolvedTarget\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.addEventListener('click', this.boundReferenceClick)\n this.referenceElement.addEventListener('focusout', this.boundFocusout)\n this.referenceElement.addEventListener('keydown', this.boundEscape)\n if (this.element.role === 'menu') {\n this.referenceElement.id ||= `qds-dropdown-trigger-${autoIncrementingId}`\n this.hostAriaLabelledBy = this.referenceElement.id\n }\n }\n\n @Watch('flipOptions')\n @Watch('noFlip')\n @Watch('noShift')\n @Watch('offsetOptions')\n @Watch('shiftOptions')\n private async updateMiddleware(): Promise<void> {\n this.middleware = [\n offset({\n ...this.offsetOptions,\n mainAxis:\n propertyToPx(this.element, '--qds-accessory-gap-floating') ?? 0,\n }),\n !this.noFlip &&\n flip({\n crossAxis: this.noShift,\n ...this.flipOptions,\n }),\n !this.noShift &&\n shift({\n limiter: limitShift(),\n ...this.shiftOptions,\n }),\n ].filter((middleware): middleware is Middleware => middleware !== false)\n await this.updatePosition()\n }\n\n @Watch('placement')\n @Watch('strategy')\n private async updatePosition(): Promise<void> {\n invariant(this.referenceElement)\n\n const { x, y, strategy } = await computePosition(\n this.referenceElement,\n this.element,\n {\n middleware: this.middleware,\n placement: this.placement,\n strategy: this.strategy,\n },\n )\n this.hostPosition = strategy\n this.hostTransform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`\n }\n\n @Watch('autoUpdateOptions')\n private startAutoUpdate(): void {\n invariant(this.referenceElement)\n\n if (this.cleanup) this.cleanup()\n this.cleanup = autoUpdate(\n this.referenceElement,\n this.element,\n () => {\n ignorePromise(this.updatePosition())\n },\n this.autoUpdateOptions,\n )\n }\n\n public async componentWillLoad(): Promise<void> {\n this.hostDisplay = 'none'\n this.element.role ??= 'menu'\n this.element.id ||= `qds-dropdown-${autoIncrementingId}`\n await this.updateReferenceElement()\n autoIncrementingId += 1\n await this.updateMiddleware()\n }\n\n public disconnectedCallback(): void {\n this.disconnectReferenceElement()\n }\n\n public render() {\n return (\n <Host\n aria-labelledby={this.hostAriaLabelledBy}\n onKeyDown={this.boundEscape}\n onFocusout={this.boundFocusout}\n style={{\n display: this.hostDisplay,\n position: this.hostPosition,\n transform: this.hostTransform,\n }}\n >\n <slot />\n </Host>\n )\n }\n\n private async handleFocusout(event: Event): Promise<void> {\n if (!(event instanceof FocusEvent)) return\n const { relatedTarget } = event\n\n if (\n relatedTarget instanceof globalThis.Element &&\n !this.element.contains(relatedTarget) &&\n this.referenceElement !== relatedTarget\n )\n await this.close()\n }\n\n private readonly boundFocusout = (event: Event): void => {\n ignorePromise(this.handleFocusout(event))\n }\n\n private async handleEscape(event: Event): Promise<void> {\n if (\n !(event instanceof KeyboardEvent) ||\n event.key !== 'Escape' ||\n (event.target !== this.referenceElement &&\n event.target instanceof globalThis.Element &&\n event.target.closest('qds-dropdown') !== this.element)\n )\n return\n\n const cancelEvent = this.cancelEmitter.emit()\n if (cancelEvent.defaultPrevented) return\n\n await this.close()\n if (\n this.referenceElement instanceof globalThis.HTMLElement ||\n this.referenceElement instanceof globalThis.SVGElement\n )\n this.referenceElement.focus()\n }\n\n private readonly boundEscape = (event: Event): void => {\n ignorePromise(this.handleEscape(event))\n }\n\n private async handleReferenceClick(): Promise<void> {\n if (!this.disabled) await (this.open ? this.close() : this.show())\n }\n\n private readonly boundReferenceClick = (): void => {\n ignorePromise(this.handleReferenceClick())\n }\n\n private disconnectReferenceElement(): void {\n this.hostAriaLabelledBy = undefined\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.removeEventListener('click', this.boundReferenceClick)\n this.referenceElement.removeEventListener('focusout', this.boundFocusout)\n this.referenceElement.removeEventListener('keydown', this.boundEscape)\n this.referenceElement.removeAttribute('aria-expanded')\n this.referenceElement.removeAttribute('aria-controls')\n }\n}\n"],"version":3}
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
10
10
|
const index = require('./index-d181f952.js');
|
|
11
11
|
const helpers = require('./helpers-452256e8.js');
|
|
12
12
|
|
|
13
|
-
const dialogCss = ":host{box-sizing:border-box}:host([hidden]){display:none !important}:host([hidden]){}:host *,:host *::before,:host *::after{box-sizing:inherit}:host{display:
|
|
13
|
+
const dialogCss = ":host{box-sizing:border-box}:host([hidden]){display:none !important}:host([hidden]){}:host *,:host *::before,:host *::after{box-sizing:inherit}:host{display:none;position:fixed;inset:0}:host([open]){display:block}.dialog{border-radius:var(--qds-popup-border-radius);border:none;box-shadow:var(--qds-theme-popup-elevation);padding:0}.dialog::backdrop{background:transparent none repeat 0 0 / auto auto padding-box border-box scroll;background:initial}.dialog[open]~.backdrop{-webkit-backdrop-filter:blur(var(--qds-theme-popup-overlay-blur));backdrop-filter:blur(var(--qds-theme-popup-overlay-blur));background-color:var(--qds-theme-popup-overlay-background);inset:0;opacity:var(--qds-theme-popup-overlay-opacity);position:fixed}.content{align-items:flex-start;background-color:var(--qds-theme-popup-background);display:flex;flex-direction:column;gap:var(--qds-popup-gap-children-related);padding:var(--qds-popup-padding)}::slotted(blockquote),::slotted(button),::slotted(dd),::slotted(dl),::slotted(fieldset),::slotted(figure),::slotted(h1),::slotted(h2),::slotted(h3),::slotted(h4),::slotted(h5),::slotted(h6),::slotted(hr),::slotted(input),::slotted(menu),::slotted(ol),::slotted(p),::slotted(pre),::slotted(select),::slotted(textarea),::slotted(ul){margin:0}";
|
|
14
14
|
|
|
15
15
|
const Dialog = class {
|
|
16
16
|
constructor(hostRef) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"qds-dialog.entry.cjs.js","mappings":";;;;;;;;;;;;AAAA,MAAM,SAAS,GAAG
|
|
1
|
+
{"file":"qds-dialog.entry.cjs.js","mappings":";;;;;;;;;;;;AAAA,MAAM,SAAS,GAAG,8uCAA8uC;;MC8BnvC,MAAM;;;;;IA8BT,wBAAmB,GAAe,EAAE,CAAA;IA6E3B,gBAAW,GAAG,CAAC,KAAY;MAC1CA,qBAAa,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;KACxC,CAAA;IAEgB,aAAQ,GAAG,CAAC,KAAY;MACvC,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,gBAAgB;QAAE,KAAK,CAAC,cAAc,EAAE,CAAA;KACvE,CAAA;IAEgB,YAAO,GAAG;MACzBC,iBAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;MAEtB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAA;MACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAA;KAC7B,CAAA;IAEgB,QAAG,GAAG,CAAC,MAA0B;MAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;KACrB,CAAA;gBAtHqD,KAAK;;;;;;;;;EAoCpD,MAAM,IAAI;IACfA,iBAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAEtB,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAA;GAC7B;;;;EA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Attributes","h","Host"],"sources":["src/components/dialog/dialog.css?tag=qds-dialog&encapsulation=shadow","src/components/dialog/dialog.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n display: none;\n position: fixed;\n inset: 0;\n}\n\n:host([open]) {\n display: block;\n}\n\n.dialog {\n border-radius: var(--qds-popup-border-radius);\n border: none;\n box-shadow: var(--qds-theme-popup-elevation);\n padding: 0;\n\n &::backdrop {\n background: initial;\n }\n\n &[open] ~ .backdrop {\n backdrop-filter: blur(var(--qds-theme-popup-overlay-blur));\n background-color: var(--qds-theme-popup-overlay-background);\n inset: 0;\n opacity: var(--qds-theme-popup-overlay-opacity);\n position: fixed;\n }\n}\n\n.content {\n align-items: flex-start;\n background-color: var(--qds-theme-popup-background);\n display: flex;\n flex-direction: column;\n gap: var(--qds-popup-gap-children-related);\n padding: var(--qds-popup-padding);\n}\n\n::slotted(blockquote),\n::slotted(button),\n::slotted(dd),\n::slotted(dl),\n::slotted(fieldset),\n::slotted(figure),\n::slotted(h1),\n::slotted(h2),\n::slotted(h3),\n::slotted(h4),\n::slotted(h5),\n::slotted(h6),\n::slotted(hr),\n::slotted(input),\n::slotted(menu),\n::slotted(ol),\n::slotted(p),\n::slotted(pre),\n::slotted(select),\n::slotted(textarea),\n::slotted(ul) {\n margin: 0;\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Method,\n Prop,\n Watch,\n} from '@stencil/core'\n\nimport type { Attributes } from '../../helpers'\nimport { ignorePromise, inheritAriaAttributes, invariant } from '../../helpers'\n\n/**\n * The `<qds-dialog>` element represent a dialog box or other interactive\n * component, such as a dismissible alert, inspector, or subwindow.\n *\n * @see https://quartz.se.com/build/components/dialog\n */\n@Component({\n tag: 'qds-dialog',\n shadow: true,\n styleUrl: 'dialog.css',\n})\nexport class Dialog implements ComponentInterface {\n /**\n * Indicates whether or not the dialog is open. You can toggle this attribute\n * to show and hide the dialog, or you can use the `show()` and `close()`\n * methods and this attribute will reflect the dialog’s open state.\n */\n @Prop({ mutable: true, reflect: true }) public open = false\n\n @Element() private readonly element!: HTMLQdsDialogElement\n\n /**\n * Emitted when the user instructs the browser that they wish to dismiss the\n * currently open dialog. The browser fires this event when the user presses\n * the `Esc` key.\n *\n * When a dialog is dismissed with the `Esc` key, both the `qdsCancel` and\n * `qdsClose` events are fired.\n */\n @Event({ eventName: 'qdsCancel', bubbles: false, composed: false })\n private readonly cancelEmitter!: EventEmitter<void>\n\n /** Emitted when the dialog has been closed. */\n @Event({\n eventName: 'qdsClose',\n bubbles: false,\n cancelable: false,\n composed: false,\n })\n private readonly closeEmitter!: EventEmitter<void>\n\n private inheritedAttributes: Attributes = {}\n\n private dialog?: HTMLDialogElement\n\n /**\n * Displays the dialog over the top of any other dialogs that might be\n * present. Everything outside of the dialog is [inert][] with interactions\n * outside of the dialog being blocked.\n *\n * [inert]: https://developer.mozilla.org/docs/Web/API/HTMLElement/inert\n */\n @Method()\n public async show(): Promise<void> {\n invariant(this.dialog)\n\n this.dialog.showModal()\n this.open = this.dialog.open\n }\n\n /**\n * Closes the dialog.\n */\n @Method()\n public async close(): Promise<void> {\n invariant(this.dialog)\n\n this.dialog.close()\n }\n\n @Watch('open')\n protected async openChanged(): Promise<void> {\n await (this.open ? this.show() : this.close())\n }\n\n public componentWillLoad(): void {\n this.inheritedAttributes = inheritAriaAttributes(this.element)\n }\n\n public async componentDidLoad(): Promise<void> {\n if (this.open) await this.show()\n }\n\n public render() {\n return (\n <Host>\n <dialog\n class=\"dialog\"\n ref={this.ref}\n onSubmit={this.boundSubmit}\n onCancel={this.onCancel}\n onClose={this.onClose}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...this.inheritedAttributes}\n >\n <div class=\"content\">\n <slot />\n </div>\n </dialog>\n <div class=\"backdrop\" />\n </Host>\n )\n }\n\n private async handleSubmit(event: Event): Promise<void> {\n if (\n (event instanceof SubmitEvent &&\n (event.submitter instanceof HTMLButtonElement ||\n (event.submitter instanceof HTMLInputElement &&\n event.submitter.formMethod === 'dialog'))) ||\n (event.target instanceof HTMLFormElement &&\n event.target.method === 'dialog')\n ) {\n event.preventDefault()\n await this.close()\n }\n }\n\n private readonly boundSubmit = (event: Event): void => {\n ignorePromise(this.handleSubmit(event))\n }\n\n private readonly onCancel = (event: Event): void => {\n if (this.cancelEmitter.emit().defaultPrevented) event.preventDefault()\n }\n\n private readonly onClose = (): void => {\n invariant(this.dialog)\n\n this.closeEmitter.emit()\n this.open = this.dialog.open\n }\n\n private readonly ref = (dialog?: HTMLDialogElement): void => {\n this.dialog = dialog\n }\n}\n"],"version":3}
|
|
@@ -21,7 +21,7 @@ const Dropdown = class {
|
|
|
21
21
|
this.closeEmitter = index.createEvent(this, "qdsClose", 2);
|
|
22
22
|
this.open = false;
|
|
23
23
|
this.boundFocusout = (event) => {
|
|
24
|
-
helpers.ignorePromise(this.
|
|
24
|
+
helpers.ignorePromise(this.handleFocusout(event));
|
|
25
25
|
};
|
|
26
26
|
this.boundEscape = (event) => {
|
|
27
27
|
helpers.ignorePromise(this.handleEscape(event));
|
|
@@ -169,7 +169,7 @@ const Dropdown = class {
|
|
|
169
169
|
transform: this.hostTransform,
|
|
170
170
|
} }, index.h("slot", null)));
|
|
171
171
|
}
|
|
172
|
-
async
|
|
172
|
+
async handleFocusout(event) {
|
|
173
173
|
if (!(event instanceof FocusEvent))
|
|
174
174
|
return;
|
|
175
175
|
const { relatedTarget } = event;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"qds-dropdown.entry.cjs.js","mappings":";;;;;;;;;;;;;AAAA,MAAM,WAAW,GAAG,2UAA2U;;AC4C/V,IAAI,kBAAkB,GAAG,CAAC,CAAA;MAYb,QAAQ;;;;;IA8HX,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EAMO,0BAA0B;IAChC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAA;IAEnC,IAAI,EAAE,IAAI,CAAC,gBAAgB,YAAY,UAAU,CAAC,OAAO,CAAC;MAAE,OAAM;IAElE,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAA;IAC5E,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IACzE,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACtE,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IACtD,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;GACvD;;;;;;;;;;;;;;;;;;","names":["ignorePromise","offset","propertyToPx","flip","shift","limitShift","invariant","computePosition","roundByDPR","autoUpdate","h","Host"],"sources":["src/components/dropdown/dropdown.css?tag=qds-dropdown&encapsulation=shadow","src/components/dropdown/dropdown.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n background: var(--qds-theme-accessory-background);\n border-radius: var(--qds-accessory-border-radius);\n box-shadow: var(--qds-theme-accessory-elevation);\n display: inline-block;\n left: 0;\n top: 0;\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type {\n AutoUpdateOptions,\n DetectOverflowOptions,\n FlipOptions,\n Middleware,\n Placement,\n ReferenceElement,\n ShiftOptions,\n Strategy,\n} from '@floating-ui/dom'\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n} from '@floating-ui/dom'\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Listen,\n Method,\n Prop,\n State,\n Watch,\n} from '@stencil/core'\n\nimport type { OffsetOptions } from '../../helpers'\nimport {\n ignorePromise,\n invariant,\n propertyToPx,\n roundByDPR,\n} from '../../helpers'\n\nlet autoIncrementingId = 1\n\n/**\n * @experimental\n * @slot Content to display in the dropdown.\n * @see https://quartz.se.com/build/components/dropdown\n */\n@Component({\n tag: 'qds-dropdown',\n shadow: true,\n styleUrl: 'dropdown.css',\n})\nexport class Dropdown implements ComponentInterface {\n /**\n * Options to pass to Floating UI's\n * [`autoUpdate()` function](https://floating-ui.com/docs/autoUpdate).\n *\n * @see https://floating-ui.com/docs/autoupdate#options\n */\n @Prop() public readonly autoUpdateOptions?: AutoUpdateOptions\n\n /**\n * Prevents the dropdown from being shown by user interaction. The dropdown\n * can still be displayed by calling the `show()` method.\n */\n @Prop({ mutable: true }) public disabled = false\n\n /**\n * Options to pass to Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n *\n * The [`crossAxis` option](https://floating-ui.com/docs/flip#crossaxis) is\n * set to the value of the `noShift` property by default for interoperability\n * with the [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/flip#options\n */\n @Prop() public readonly flipOptions?: Partial<\n DetectOverflowOptions & FlipOptions\n >\n\n /**\n * Disable Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n */\n @Prop() public readonly noFlip: boolean = false\n\n /**\n * Disable Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n */\n @Prop() public readonly noShift: boolean = false\n\n /**\n * Options to pass to Floating UI's\n * [`offset` middleware](https://floating-ui.com/docs/offset).\n *\n * The [`mainAxis` option](https://floating-ui.com/docs/offset#mainaxis) is\n * not supported.\n *\n * @see https://floating-ui.com/docs/offset#options\n */\n @Prop() public readonly offsetOptions?: OffsetOptions\n\n /**\n * Where to place the dropdown relative to the `target`.\n *\n * @see https://floating-ui.com/docs/tutorial#placements\n */\n @Prop() public readonly placement: Placement = 'bottom-start'\n\n /**\n * Options to pass to Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/shift#options\n */\n @Prop() public readonly shiftOptions?: Partial<\n DetectOverflowOptions & ShiftOptions\n >\n\n /**\n * The CSS position strategy to use.\n *\n * @see https://floating-ui.com/docs/computeposition#strategy\n */\n @Prop() public readonly strategy?: Strategy\n\n /**\n * The trigger element that will trigger the dropdown. The target specified\n * can be any of the follow:\n *\n * - A CSS selector string\n * - A reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element) or\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements)\n * - A function returning a reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element),\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements),\n * or a CSS selector string\n */\n @Prop() public readonly target!:\n | ReferenceElement\n | string\n | (() => ReferenceElement | string)\n\n /**\n * Emitted when the user instructs the browser that they wish to dismiss the\n * current open dropdown by pressing the `Esc` key.\n *\n * When a dropdown is dismissed with the `Esc` key, both the `qdsCancel` and\n * `qdsClose` events are emitted.\n */\n @Event({ eventName: 'qdsCancel', bubbles: false })\n private readonly cancelEmitter!: EventEmitter<void>\n\n /**\n * Emitted when the dropdown is closed.\n */\n @Event({ eventName: 'qdsClose', bubbles: false, cancelable: false })\n private readonly closeEmitter!: EventEmitter<void>\n\n @Element() private readonly element!: HTMLQdsDropdownElement\n\n @State() private hostAriaLabelledBy?: string\n\n @State() private hostDisplay?: string\n\n @State() private hostPosition?: string\n\n @State() private hostTransform?: string\n\n private cleanup?: () => void\n\n private middleware?: Middleware[]\n\n private referenceElement?: ReferenceElement\n\n private open = false\n\n /**\n * Show the dropdown.\n */\n @Method()\n public async show(): Promise<void> {\n if (this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'true')\n this.referenceElement.setAttribute('aria-controls', this.element.id)\n }\n\n this.open = true\n this.hostDisplay = undefined\n this.startAutoUpdate()\n }\n\n /**\n * Close the dropdown.\n */\n @Method()\n public async close(): Promise<void> {\n if (!this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.removeAttribute('aria-controls')\n }\n\n this.open = false\n this.hostDisplay = 'none'\n if (this.cleanup) this.cleanup()\n\n this.closeEmitter.emit()\n }\n\n /**\n * Update the dropdown's middleware and position.\n */\n @Method()\n public async update(): Promise<void> {\n await this.updateMiddleware()\n }\n\n @Listen('click', { target: 'document' })\n protected async handleMouseDown(event: MouseEvent): Promise<void> {\n if (!this.open) return\n\n const composedPath = event.composedPath()\n const withinBounds =\n composedPath.includes(this.element) ||\n (this.referenceElement instanceof globalThis.Element &&\n composedPath.includes(this.referenceElement))\n if (!withinBounds) await this.close()\n }\n\n @Watch('target')\n private async updateReferenceElement(): Promise<void> {\n this.disconnectReferenceElement()\n\n const resolvedTarget =\n typeof this.target === 'function' ? this.target() : this.target\n if (typeof resolvedTarget === 'string') {\n const element = document.querySelector(resolvedTarget)\n if (element === null)\n throw new Error('String `target` must resolve to an Element.')\n this.referenceElement = element\n } else this.referenceElement = resolvedTarget\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.addEventListener('click', this.boundReferenceClick)\n this.referenceElement.addEventListener('focusout', this.boundFocusout)\n this.referenceElement.addEventListener('keydown', this.boundEscape)\n if (this.element.role === 'menu') {\n this.referenceElement.id ||= `qds-dropdown-trigger-${autoIncrementingId}`\n this.hostAriaLabelledBy = this.referenceElement.id\n }\n }\n\n @Watch('flipOptions')\n @Watch('noFlip')\n @Watch('noShift')\n @Watch('offsetOptions')\n @Watch('shiftOptions')\n private async updateMiddleware(): Promise<void> {\n this.middleware = [\n offset({\n ...this.offsetOptions,\n mainAxis:\n propertyToPx(this.element, '--qds-accessory-gap-floating') ?? 0,\n }),\n !this.noFlip &&\n flip({\n crossAxis: this.noShift,\n ...this.flipOptions,\n }),\n !this.noShift &&\n shift({\n limiter: limitShift(),\n ...this.shiftOptions,\n }),\n ].filter((middleware): middleware is Middleware => middleware !== false)\n await this.updatePosition()\n }\n\n @Watch('placement')\n @Watch('strategy')\n private async updatePosition(): Promise<void> {\n invariant(this.referenceElement)\n\n const { x, y, strategy } = await computePosition(\n this.referenceElement,\n this.element,\n {\n middleware: this.middleware,\n placement: this.placement,\n strategy: this.strategy,\n },\n )\n this.hostPosition = strategy\n this.hostTransform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`\n }\n\n @Watch('autoUpdateOptions')\n private startAutoUpdate(): void {\n invariant(this.referenceElement)\n\n if (this.cleanup) this.cleanup()\n this.cleanup = autoUpdate(\n this.referenceElement,\n this.element,\n () => {\n ignorePromise(this.updatePosition())\n },\n this.autoUpdateOptions,\n )\n }\n\n public async componentWillLoad(): Promise<void> {\n this.hostDisplay = 'none'\n this.element.role ??= 'menu'\n this.element.id ||= `qds-dropdown-${autoIncrementingId}`\n await this.updateReferenceElement()\n autoIncrementingId += 1\n await this.updateMiddleware()\n }\n\n public disconnectedCallback(): void {\n this.disconnectReferenceElement()\n }\n\n public render() {\n return (\n <Host\n aria-labelledby={this.hostAriaLabelledBy}\n onKeyDown={this.boundEscape}\n onFocusout={this.boundFocusout}\n style={{\n display: this.hostDisplay,\n position: this.hostPosition,\n transform: this.hostTransform,\n }}\n >\n <slot />\n </Host>\n )\n }\n\n private async handleFocusOut(event: Event): Promise<void> {\n if (!(event instanceof FocusEvent)) return\n const { relatedTarget } = event\n\n if (\n relatedTarget instanceof globalThis.Element &&\n !this.element.contains(relatedTarget) &&\n this.referenceElement !== relatedTarget\n )\n await this.close()\n }\n\n private readonly boundFocusout = (event: Event): void => {\n ignorePromise(this.handleFocusOut(event))\n }\n\n private async handleEscape(event: Event): Promise<void> {\n if (\n !(event instanceof KeyboardEvent) ||\n event.key !== 'Escape' ||\n (event.target !== this.referenceElement &&\n event.target instanceof globalThis.Element &&\n event.target.closest('qds-dropdown') !== this.element)\n )\n return\n\n const cancelEvent = this.cancelEmitter.emit()\n if (cancelEvent.defaultPrevented) return\n\n await this.close()\n if (\n this.referenceElement instanceof globalThis.HTMLElement ||\n this.referenceElement instanceof globalThis.SVGElement\n )\n this.referenceElement.focus()\n }\n\n private readonly boundEscape = (event: Event): void => {\n ignorePromise(this.handleEscape(event))\n }\n\n private async handleReferenceClick(): Promise<void> {\n if (!this.disabled) await (this.open ? this.close() : this.show())\n }\n\n private readonly boundReferenceClick = (): void => {\n ignorePromise(this.handleReferenceClick())\n }\n\n private disconnectReferenceElement(): void {\n this.hostAriaLabelledBy = undefined\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.removeEventListener('click', this.boundReferenceClick)\n this.referenceElement.removeEventListener('focusout', this.boundFocusout)\n this.referenceElement.removeEventListener('keydown', this.boundEscape)\n this.referenceElement.removeAttribute('aria-expanded')\n this.referenceElement.removeAttribute('aria-controls')\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"qds-dropdown.entry.cjs.js","mappings":";;;;;;;;;;;;;AAAA,MAAM,WAAW,GAAG,2UAA2U;;AC4C/V,IAAI,kBAAkB,GAAG,CAAC,CAAA;MAYb,QAAQ;;;;;IA8HX,SAAI,GAAG,KAAK,CAAA;IAwLH,kBAAa,GAAG,CAAC,KAAY;MAC5CA,qBAAa,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;KAC1C,CAAA;IAuBgB,gBAAW,GAAG,CAAC,KAAY;MAC1CA,qBAAa,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;KACxC,CAAA;IAMgB,wBAAmB,GAAG;MACrCA,qBAAa,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAA;KAC3C,CAAA;;oBA5U0C,KAAK;;kBAoBN,KAAK;mBAMJ,KAAK;;qBAkBD,cAAc;;;;;;;;;;;;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AAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IACtD,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;GACvD;;;;;;;;;;;;;;;;;;","names":["ignorePromise","offset","propertyToPx","flip","shift","limitShift","invariant","computePosition","roundByDPR","autoUpdate","h","Host"],"sources":["src/components/dropdown/dropdown.css?tag=qds-dropdown&encapsulation=shadow","src/components/dropdown/dropdown.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n background: var(--qds-theme-accessory-background);\n border-radius: var(--qds-accessory-border-radius);\n box-shadow: var(--qds-theme-accessory-elevation);\n display: inline-block;\n left: 0;\n top: 0;\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type {\n AutoUpdateOptions,\n DetectOverflowOptions,\n FlipOptions,\n Middleware,\n Placement,\n ReferenceElement,\n ShiftOptions,\n Strategy,\n} from '@floating-ui/dom'\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n} from '@floating-ui/dom'\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Listen,\n Method,\n Prop,\n State,\n Watch,\n} from '@stencil/core'\n\nimport type { OffsetOptions } from '../../helpers'\nimport {\n ignorePromise,\n invariant,\n propertyToPx,\n roundByDPR,\n} from '../../helpers'\n\nlet autoIncrementingId = 1\n\n/**\n * @experimental\n * @slot Content to display in the dropdown.\n * @see https://quartz.se.com/build/components/dropdown\n */\n@Component({\n tag: 'qds-dropdown',\n shadow: true,\n styleUrl: 'dropdown.css',\n})\nexport class Dropdown implements ComponentInterface {\n /**\n * Options to pass to Floating UI's\n * [`autoUpdate()` function](https://floating-ui.com/docs/autoUpdate).\n *\n * @see https://floating-ui.com/docs/autoupdate#options\n */\n @Prop() public readonly autoUpdateOptions?: AutoUpdateOptions\n\n /**\n * Prevents the dropdown from being shown by user interaction. The dropdown\n * can still be displayed by calling the `show()` method.\n */\n @Prop({ mutable: true }) public disabled = false\n\n /**\n * Options to pass to Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n *\n * The [`crossAxis` option](https://floating-ui.com/docs/flip#crossaxis) is\n * set to the value of the `noShift` property by default for interoperability\n * with the [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/flip#options\n */\n @Prop() public readonly flipOptions?: Partial<\n DetectOverflowOptions & FlipOptions\n >\n\n /**\n * Disable Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n */\n @Prop() public readonly noFlip: boolean = false\n\n /**\n * Disable Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n */\n @Prop() public readonly noShift: boolean = false\n\n /**\n * Options to pass to Floating UI's\n * [`offset` middleware](https://floating-ui.com/docs/offset).\n *\n * The [`mainAxis` option](https://floating-ui.com/docs/offset#mainaxis) is\n * not supported.\n *\n * @see https://floating-ui.com/docs/offset#options\n */\n @Prop() public readonly offsetOptions?: OffsetOptions\n\n /**\n * Where to place the dropdown relative to the `target`.\n *\n * @see https://floating-ui.com/docs/tutorial#placements\n */\n @Prop() public readonly placement: Placement = 'bottom-start'\n\n /**\n * Options to pass to Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/shift#options\n */\n @Prop() public readonly shiftOptions?: Partial<\n DetectOverflowOptions & ShiftOptions\n >\n\n /**\n * The CSS position strategy to use.\n *\n * @see https://floating-ui.com/docs/computeposition#strategy\n */\n @Prop() public readonly strategy?: Strategy\n\n /**\n * The trigger element that will trigger the dropdown. The target specified\n * can be any of the follow:\n *\n * - A CSS selector string\n * - A reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element) or\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements)\n * - A function returning a reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element),\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements),\n * or a CSS selector string\n */\n @Prop() public readonly target!:\n | ReferenceElement\n | string\n | (() => ReferenceElement | string)\n\n /**\n * Emitted when the user instructs the browser that they wish to dismiss the\n * current open dropdown by pressing the `Esc` key.\n *\n * When a dropdown is dismissed with the `Esc` key, both the `qdsCancel` and\n * `qdsClose` events are emitted.\n */\n @Event({ eventName: 'qdsCancel', bubbles: false })\n private readonly cancelEmitter!: EventEmitter<void>\n\n /**\n * Emitted when the dropdown is closed.\n */\n @Event({ eventName: 'qdsClose', bubbles: false, cancelable: false })\n private readonly closeEmitter!: EventEmitter<void>\n\n @Element() private readonly element!: HTMLQdsDropdownElement\n\n @State() private hostAriaLabelledBy?: string\n\n @State() private hostDisplay?: string\n\n @State() private hostPosition?: string\n\n @State() private hostTransform?: string\n\n private cleanup?: () => void\n\n private middleware?: Middleware[]\n\n private referenceElement?: ReferenceElement\n\n private open = false\n\n /**\n * Show the dropdown.\n */\n @Method()\n public async show(): Promise<void> {\n if (this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'true')\n this.referenceElement.setAttribute('aria-controls', this.element.id)\n }\n\n this.open = true\n this.hostDisplay = undefined\n this.startAutoUpdate()\n }\n\n /**\n * Close the dropdown.\n */\n @Method()\n public async close(): Promise<void> {\n if (!this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.removeAttribute('aria-controls')\n }\n\n this.open = false\n this.hostDisplay = 'none'\n if (this.cleanup) this.cleanup()\n\n this.closeEmitter.emit()\n }\n\n /**\n * Update the dropdown's middleware and position.\n */\n @Method()\n public async update(): Promise<void> {\n await this.updateMiddleware()\n }\n\n @Listen('click', { target: 'document' })\n protected async handleMouseDown(event: MouseEvent): Promise<void> {\n if (!this.open) return\n\n const composedPath = event.composedPath()\n const withinBounds =\n composedPath.includes(this.element) ||\n (this.referenceElement instanceof globalThis.Element &&\n composedPath.includes(this.referenceElement))\n if (!withinBounds) await this.close()\n }\n\n @Watch('target')\n private async updateReferenceElement(): Promise<void> {\n this.disconnectReferenceElement()\n\n const resolvedTarget =\n typeof this.target === 'function' ? this.target() : this.target\n if (typeof resolvedTarget === 'string') {\n const element = document.querySelector(resolvedTarget)\n if (element === null)\n throw new Error('String `target` must resolve to an Element.')\n this.referenceElement = element\n } else this.referenceElement = resolvedTarget\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.addEventListener('click', this.boundReferenceClick)\n this.referenceElement.addEventListener('focusout', this.boundFocusout)\n this.referenceElement.addEventListener('keydown', this.boundEscape)\n if (this.element.role === 'menu') {\n this.referenceElement.id ||= `qds-dropdown-trigger-${autoIncrementingId}`\n this.hostAriaLabelledBy = this.referenceElement.id\n }\n }\n\n @Watch('flipOptions')\n @Watch('noFlip')\n @Watch('noShift')\n @Watch('offsetOptions')\n @Watch('shiftOptions')\n private async updateMiddleware(): Promise<void> {\n this.middleware = [\n offset({\n ...this.offsetOptions,\n mainAxis:\n propertyToPx(this.element, '--qds-accessory-gap-floating') ?? 0,\n }),\n !this.noFlip &&\n flip({\n crossAxis: this.noShift,\n ...this.flipOptions,\n }),\n !this.noShift &&\n shift({\n limiter: limitShift(),\n ...this.shiftOptions,\n }),\n ].filter((middleware): middleware is Middleware => middleware !== false)\n await this.updatePosition()\n }\n\n @Watch('placement')\n @Watch('strategy')\n private async updatePosition(): Promise<void> {\n invariant(this.referenceElement)\n\n const { x, y, strategy } = await computePosition(\n this.referenceElement,\n this.element,\n {\n middleware: this.middleware,\n placement: this.placement,\n strategy: this.strategy,\n },\n )\n this.hostPosition = strategy\n this.hostTransform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`\n }\n\n @Watch('autoUpdateOptions')\n private startAutoUpdate(): void {\n invariant(this.referenceElement)\n\n if (this.cleanup) this.cleanup()\n this.cleanup = autoUpdate(\n this.referenceElement,\n this.element,\n () => {\n ignorePromise(this.updatePosition())\n },\n this.autoUpdateOptions,\n )\n }\n\n public async componentWillLoad(): Promise<void> {\n this.hostDisplay = 'none'\n this.element.role ??= 'menu'\n this.element.id ||= `qds-dropdown-${autoIncrementingId}`\n await this.updateReferenceElement()\n autoIncrementingId += 1\n await this.updateMiddleware()\n }\n\n public disconnectedCallback(): void {\n this.disconnectReferenceElement()\n }\n\n public render() {\n return (\n <Host\n aria-labelledby={this.hostAriaLabelledBy}\n onKeyDown={this.boundEscape}\n onFocusout={this.boundFocusout}\n style={{\n display: this.hostDisplay,\n position: this.hostPosition,\n transform: this.hostTransform,\n }}\n >\n <slot />\n </Host>\n )\n }\n\n private async handleFocusout(event: Event): Promise<void> {\n if (!(event instanceof FocusEvent)) return\n const { relatedTarget } = event\n\n if (\n relatedTarget instanceof globalThis.Element &&\n !this.element.contains(relatedTarget) &&\n this.referenceElement !== relatedTarget\n )\n await this.close()\n }\n\n private readonly boundFocusout = (event: Event): void => {\n ignorePromise(this.handleFocusout(event))\n }\n\n private async handleEscape(event: Event): Promise<void> {\n if (\n !(event instanceof KeyboardEvent) ||\n event.key !== 'Escape' ||\n (event.target !== this.referenceElement &&\n event.target instanceof globalThis.Element &&\n event.target.closest('qds-dropdown') !== this.element)\n )\n return\n\n const cancelEvent = this.cancelEmitter.emit()\n if (cancelEvent.defaultPrevented) return\n\n await this.close()\n if (\n this.referenceElement instanceof globalThis.HTMLElement ||\n this.referenceElement instanceof globalThis.SVGElement\n )\n this.referenceElement.focus()\n }\n\n private readonly boundEscape = (event: Event): void => {\n ignorePromise(this.handleEscape(event))\n }\n\n private async handleReferenceClick(): Promise<void> {\n if (!this.disabled) await (this.open ? this.close() : this.show())\n }\n\n private readonly boundReferenceClick = (): void => {\n ignorePromise(this.handleReferenceClick())\n }\n\n private disconnectReferenceElement(): void {\n this.hostAriaLabelledBy = undefined\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.removeEventListener('click', this.boundReferenceClick)\n this.referenceElement.removeEventListener('focusout', this.boundFocusout)\n this.referenceElement.removeEventListener('keydown', this.boundEscape)\n this.referenceElement.removeAttribute('aria-expanded')\n this.referenceElement.removeAttribute('aria-controls')\n }\n}\n"],"version":3}
|
|
@@ -828,7 +828,7 @@
|
|
|
828
828
|
},
|
|
829
829
|
"privacy": "public",
|
|
830
830
|
"default": "false",
|
|
831
|
-
"description": "Indicates whether or not the dialog is open. You can toggle this attribute\nto show and hide the dialog, or you can use the `show()` and `
|
|
831
|
+
"description": "Indicates whether or not the dialog is open. You can toggle this attribute\nto show and hide the dialog, or you can use the `show()` and `close()`\nmethods and this attribute will reflect the dialog’s open state."
|
|
832
832
|
},
|
|
833
833
|
{
|
|
834
834
|
"kind": "field",
|
|
@@ -1350,7 +1350,7 @@
|
|
|
1350
1350
|
},
|
|
1351
1351
|
{
|
|
1352
1352
|
"kind": "method",
|
|
1353
|
-
"name": "
|
|
1353
|
+
"name": "handleFocusout",
|
|
1354
1354
|
"privacy": "private",
|
|
1355
1355
|
"return": {
|
|
1356
1356
|
"type": {
|
package/dist/docs.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"timestamp": "2023-
|
|
2
|
+
"timestamp": "2023-08-04T18:28:14",
|
|
3
3
|
"compiler": {
|
|
4
4
|
"name": "@stencil/core",
|
|
5
5
|
"version": "4.0.1",
|
|
@@ -1148,7 +1148,7 @@
|
|
|
1148
1148
|
"mutable": true,
|
|
1149
1149
|
"attr": "open",
|
|
1150
1150
|
"reflectToAttr": true,
|
|
1151
|
-
"docs": "Indicates whether or not the dialog is open. You can toggle this attribute\nto show and hide the dialog, or you can use the `show()` and `
|
|
1151
|
+
"docs": "Indicates whether or not the dialog is open. You can toggle this attribute\nto show and hide the dialog, or you can use the `show()` and `close()`\nmethods and this attribute will reflect the dialog’s open state.",
|
|
1152
1152
|
"docsTags": [],
|
|
1153
1153
|
"default": "false",
|
|
1154
1154
|
"values": [
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { r as registerInstance, c as createEvent, h, H as Host, a as getElement } from './index-d7183092.js';
|
|
7
7
|
import { c as ignorePromise, a as invariant, i as inheritAriaAttributes } from './helpers-76b84f45.js';
|
|
8
8
|
|
|
9
|
-
const dialogCss = ":host{box-sizing:border-box}:host([hidden]){display:none !important}:host([hidden]){}:host *,:host *::before,:host *::after{box-sizing:inherit}:host{display:
|
|
9
|
+
const dialogCss = ":host{box-sizing:border-box}:host([hidden]){display:none !important}:host([hidden]){}:host *,:host *::before,:host *::after{box-sizing:inherit}:host{display:none;position:fixed;inset:0}:host([open]){display:block}.dialog{border-radius:var(--qds-popup-border-radius);border:none;box-shadow:var(--qds-theme-popup-elevation);padding:0}.dialog::backdrop{background:transparent none repeat 0 0 / auto auto padding-box border-box scroll;background:initial}.dialog[open]~.backdrop{-webkit-backdrop-filter:blur(var(--qds-theme-popup-overlay-blur));backdrop-filter:blur(var(--qds-theme-popup-overlay-blur));background-color:var(--qds-theme-popup-overlay-background);inset:0;opacity:var(--qds-theme-popup-overlay-opacity);position:fixed}.content{align-items:flex-start;background-color:var(--qds-theme-popup-background);display:flex;flex-direction:column;gap:var(--qds-popup-gap-children-related);padding:var(--qds-popup-padding)}::slotted(blockquote),::slotted(button),::slotted(dd),::slotted(dl),::slotted(fieldset),::slotted(figure),::slotted(h1),::slotted(h2),::slotted(h3),::slotted(h4),::slotted(h5),::slotted(h6),::slotted(hr),::slotted(input),::slotted(menu),::slotted(ol),::slotted(p),::slotted(pre),::slotted(select),::slotted(textarea),::slotted(ul){margin:0}";
|
|
10
10
|
|
|
11
11
|
const Dialog = class {
|
|
12
12
|
constructor(hostRef) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"qds-dialog.entry.js","mappings":";;;;;;;;AAAA,MAAM,SAAS,GAAG
|
|
1
|
+
{"file":"qds-dialog.entry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B;IAC3B,IAAI,IAAI,CAAC,IAAI;MAAE,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;GACjC;EAEM,MAAM;IACX,QACE,EAAC,IAAI,QACH,cACE,KAAK,EAAC,QAAQ,EACd,GAAG,EAAE,IAAI,CAAC,GAAG,EACb,QAAQ,EAAE,IAAI,CAAC,WAAW,EAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,OAAO,EAAE,IAAI,CAAC,OAAO,KAEjB,IAAI,CAAC,mBAAmB,IAE5B,WAAK,KAAK,EAAC,SAAS,IAClB,eAAQ,CACJ,CACC,EACT,WAAK,KAAK,EAAC,UAAU,GAAG,CACnB,EACR;GACF;EAEO,MAAM,YAAY,CAAC,KAAY;IACrC,IACE,CAAC,KAAK,YAAY,WAAW;OAC1B,KAAK,CAAC,SAAS,YAAY,iBAAiB;SAC1C,KAAK,CAAC,SAAS,YAAY,gBAAgB;UAC1C,KAAK,CAAC,SAAS,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC;OAC9C,KAAK,CAAC,MAAM,YAAY,eAAe;QACtC,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,EACnC;MACA,KAAK,CAAC,cAAc,EAAE,CAAA;MACtB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;KACnB;GACF;;;;;;;;;;","names":[],"sources":["src/components/dialog/dialog.css?tag=qds-dialog&encapsulation=shadow","src/components/dialog/dialog.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n display: none;\n position: fixed;\n inset: 0;\n}\n\n:host([open]) {\n display: block;\n}\n\n.dialog {\n border-radius: var(--qds-popup-border-radius);\n border: none;\n box-shadow: var(--qds-theme-popup-elevation);\n padding: 0;\n\n &::backdrop {\n background: initial;\n }\n\n &[open] ~ .backdrop {\n backdrop-filter: blur(var(--qds-theme-popup-overlay-blur));\n background-color: var(--qds-theme-popup-overlay-background);\n inset: 0;\n opacity: var(--qds-theme-popup-overlay-opacity);\n position: fixed;\n }\n}\n\n.content {\n align-items: flex-start;\n background-color: var(--qds-theme-popup-background);\n display: flex;\n flex-direction: column;\n gap: var(--qds-popup-gap-children-related);\n padding: var(--qds-popup-padding);\n}\n\n::slotted(blockquote),\n::slotted(button),\n::slotted(dd),\n::slotted(dl),\n::slotted(fieldset),\n::slotted(figure),\n::slotted(h1),\n::slotted(h2),\n::slotted(h3),\n::slotted(h4),\n::slotted(h5),\n::slotted(h6),\n::slotted(hr),\n::slotted(input),\n::slotted(menu),\n::slotted(ol),\n::slotted(p),\n::slotted(pre),\n::slotted(select),\n::slotted(textarea),\n::slotted(ul) {\n margin: 0;\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Method,\n Prop,\n Watch,\n} from '@stencil/core'\n\nimport type { Attributes } from '../../helpers'\nimport { ignorePromise, inheritAriaAttributes, invariant } from '../../helpers'\n\n/**\n * The `<qds-dialog>` element represent a dialog box or other interactive\n * component, such as a dismissible alert, inspector, or subwindow.\n *\n * @see https://quartz.se.com/build/components/dialog\n */\n@Component({\n tag: 'qds-dialog',\n shadow: true,\n styleUrl: 'dialog.css',\n})\nexport class Dialog implements ComponentInterface {\n /**\n * Indicates whether or not the dialog is open. You can toggle this attribute\n * to show and hide the dialog, or you can use the `show()` and `close()`\n * methods and this attribute will reflect the dialog’s open state.\n */\n @Prop({ mutable: true, reflect: true }) public open = false\n\n @Element() private readonly element!: HTMLQdsDialogElement\n\n /**\n * Emitted when the user instructs the browser that they wish to dismiss the\n * currently open dialog. The browser fires this event when the user presses\n * the `Esc` key.\n *\n * When a dialog is dismissed with the `Esc` key, both the `qdsCancel` and\n * `qdsClose` events are fired.\n */\n @Event({ eventName: 'qdsCancel', bubbles: false, composed: false })\n private readonly cancelEmitter!: EventEmitter<void>\n\n /** Emitted when the dialog has been closed. */\n @Event({\n eventName: 'qdsClose',\n bubbles: false,\n cancelable: false,\n composed: false,\n })\n private readonly closeEmitter!: EventEmitter<void>\n\n private inheritedAttributes: Attributes = {}\n\n private dialog?: HTMLDialogElement\n\n /**\n * Displays the dialog over the top of any other dialogs that might be\n * present. Everything outside of the dialog is [inert][] with interactions\n * outside of the dialog being blocked.\n *\n * [inert]: https://developer.mozilla.org/docs/Web/API/HTMLElement/inert\n */\n @Method()\n public async show(): Promise<void> {\n invariant(this.dialog)\n\n this.dialog.showModal()\n this.open = this.dialog.open\n }\n\n /**\n * Closes the dialog.\n */\n @Method()\n public async close(): Promise<void> {\n invariant(this.dialog)\n\n this.dialog.close()\n }\n\n @Watch('open')\n protected async openChanged(): Promise<void> {\n await (this.open ? this.show() : this.close())\n }\n\n public componentWillLoad(): void {\n this.inheritedAttributes = inheritAriaAttributes(this.element)\n }\n\n public async componentDidLoad(): Promise<void> {\n if (this.open) await this.show()\n }\n\n public render() {\n return (\n <Host>\n <dialog\n class=\"dialog\"\n ref={this.ref}\n onSubmit={this.boundSubmit}\n onCancel={this.onCancel}\n onClose={this.onClose}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...this.inheritedAttributes}\n >\n <div class=\"content\">\n <slot />\n </div>\n </dialog>\n <div class=\"backdrop\" />\n </Host>\n )\n }\n\n private async handleSubmit(event: Event): Promise<void> {\n if (\n (event instanceof SubmitEvent &&\n (event.submitter instanceof HTMLButtonElement ||\n (event.submitter instanceof HTMLInputElement &&\n event.submitter.formMethod === 'dialog'))) ||\n (event.target instanceof HTMLFormElement &&\n event.target.method === 'dialog')\n ) {\n event.preventDefault()\n await this.close()\n }\n }\n\n private readonly boundSubmit = (event: Event): void => {\n ignorePromise(this.handleSubmit(event))\n }\n\n private readonly onCancel = (event: Event): void => {\n if (this.cancelEmitter.emit().defaultPrevented) event.preventDefault()\n }\n\n private readonly onClose = (): void => {\n invariant(this.dialog)\n\n this.closeEmitter.emit()\n this.open = this.dialog.open\n }\n\n private readonly ref = (dialog?: HTMLDialogElement): void => {\n this.dialog = dialog\n }\n}\n"],"version":3}
|
|
@@ -17,7 +17,7 @@ const Dropdown = class {
|
|
|
17
17
|
this.closeEmitter = createEvent(this, "qdsClose", 2);
|
|
18
18
|
this.open = false;
|
|
19
19
|
this.boundFocusout = (event) => {
|
|
20
|
-
ignorePromise(this.
|
|
20
|
+
ignorePromise(this.handleFocusout(event));
|
|
21
21
|
};
|
|
22
22
|
this.boundEscape = (event) => {
|
|
23
23
|
ignorePromise(this.handleEscape(event));
|
|
@@ -165,7 +165,7 @@ const Dropdown = class {
|
|
|
165
165
|
transform: this.hostTransform,
|
|
166
166
|
} }, h("slot", null)));
|
|
167
167
|
}
|
|
168
|
-
async
|
|
168
|
+
async handleFocusout(event) {
|
|
169
169
|
if (!(event instanceof FocusEvent))
|
|
170
170
|
return;
|
|
171
171
|
const { relatedTarget } = event;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"qds-dropdown.entry.js","mappings":";;;;;;;;;AAAA,MAAM,WAAW,GAAG,2UAA2U;;AC4C/V,IAAI,kBAAkB,GAAG,CAAC,CAAA;MAYb,QAAQ;;;;;IA8HX,SAAI,GAAG,KAAK,CAAA;IAwLH,kBAAa,GAAG,CAAC,KAAY;MAC5C,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;KAC1C,CAAA;IAuBgB,gBAAW,GAAG,CAAC,KAAY;MAC1C,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;KACxC,CAAA;IAMgB,wBAAmB,GAAG;MACrC,aAAa,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAA;KAC3C,CAAA;;oBA5U0C,KAAK;;kBAoBN,KAAK;mBAMJ,KAAK;;qBAkBD,cAAc;;;;;;;;;;;;EA2EtD,MAAM,IAAI;I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,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;GACvD;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/dropdown/dropdown.css?tag=qds-dropdown&encapsulation=shadow","src/components/dropdown/dropdown.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n background: var(--qds-theme-accessory-background);\n border-radius: var(--qds-accessory-border-radius);\n box-shadow: var(--qds-theme-accessory-elevation);\n display: inline-block;\n left: 0;\n top: 0;\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type {\n AutoUpdateOptions,\n DetectOverflowOptions,\n FlipOptions,\n Middleware,\n Placement,\n ReferenceElement,\n ShiftOptions,\n Strategy,\n} from '@floating-ui/dom'\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n} from '@floating-ui/dom'\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Listen,\n Method,\n Prop,\n State,\n Watch,\n} from '@stencil/core'\n\nimport type { OffsetOptions } from '../../helpers'\nimport {\n ignorePromise,\n invariant,\n propertyToPx,\n roundByDPR,\n} from '../../helpers'\n\nlet autoIncrementingId = 1\n\n/**\n * @experimental\n * @slot Content to display in the dropdown.\n * @see https://quartz.se.com/build/components/dropdown\n */\n@Component({\n tag: 'qds-dropdown',\n shadow: true,\n styleUrl: 'dropdown.css',\n})\nexport class Dropdown implements ComponentInterface {\n /**\n * Options to pass to Floating UI's\n * [`autoUpdate()` function](https://floating-ui.com/docs/autoUpdate).\n *\n * @see https://floating-ui.com/docs/autoupdate#options\n */\n @Prop() public readonly autoUpdateOptions?: AutoUpdateOptions\n\n /**\n * Prevents the dropdown from being shown by user interaction. The dropdown\n * can still be displayed by calling the `show()` method.\n */\n @Prop({ mutable: true }) public disabled = false\n\n /**\n * Options to pass to Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n *\n * The [`crossAxis` option](https://floating-ui.com/docs/flip#crossaxis) is\n * set to the value of the `noShift` property by default for interoperability\n * with the [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/flip#options\n */\n @Prop() public readonly flipOptions?: Partial<\n DetectOverflowOptions & FlipOptions\n >\n\n /**\n * Disable Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n */\n @Prop() public readonly noFlip: boolean = false\n\n /**\n * Disable Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n */\n @Prop() public readonly noShift: boolean = false\n\n /**\n * Options to pass to Floating UI's\n * [`offset` middleware](https://floating-ui.com/docs/offset).\n *\n * The [`mainAxis` option](https://floating-ui.com/docs/offset#mainaxis) is\n * not supported.\n *\n * @see https://floating-ui.com/docs/offset#options\n */\n @Prop() public readonly offsetOptions?: OffsetOptions\n\n /**\n * Where to place the dropdown relative to the `target`.\n *\n * @see https://floating-ui.com/docs/tutorial#placements\n */\n @Prop() public readonly placement: Placement = 'bottom-start'\n\n /**\n * Options to pass to Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/shift#options\n */\n @Prop() public readonly shiftOptions?: Partial<\n DetectOverflowOptions & ShiftOptions\n >\n\n /**\n * The CSS position strategy to use.\n *\n * @see https://floating-ui.com/docs/computeposition#strategy\n */\n @Prop() public readonly strategy?: Strategy\n\n /**\n * The trigger element that will trigger the dropdown. The target specified\n * can be any of the follow:\n *\n * - A CSS selector string\n * - A reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element) or\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements)\n * - A function returning a reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element),\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements),\n * or a CSS selector string\n */\n @Prop() public readonly target!:\n | ReferenceElement\n | string\n | (() => ReferenceElement | string)\n\n /**\n * Emitted when the user instructs the browser that they wish to dismiss the\n * current open dropdown by pressing the `Esc` key.\n *\n * When a dropdown is dismissed with the `Esc` key, both the `qdsCancel` and\n * `qdsClose` events are emitted.\n */\n @Event({ eventName: 'qdsCancel', bubbles: false })\n private readonly cancelEmitter!: EventEmitter<void>\n\n /**\n * Emitted when the dropdown is closed.\n */\n @Event({ eventName: 'qdsClose', bubbles: false, cancelable: false })\n private readonly closeEmitter!: EventEmitter<void>\n\n @Element() private readonly element!: HTMLQdsDropdownElement\n\n @State() private hostAriaLabelledBy?: string\n\n @State() private hostDisplay?: string\n\n @State() private hostPosition?: string\n\n @State() private hostTransform?: string\n\n private cleanup?: () => void\n\n private middleware?: Middleware[]\n\n private referenceElement?: ReferenceElement\n\n private open = false\n\n /**\n * Show the dropdown.\n */\n @Method()\n public async show(): Promise<void> {\n if (this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'true')\n this.referenceElement.setAttribute('aria-controls', this.element.id)\n }\n\n this.open = true\n this.hostDisplay = undefined\n this.startAutoUpdate()\n }\n\n /**\n * Close the dropdown.\n */\n @Method()\n public async close(): Promise<void> {\n if (!this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.removeAttribute('aria-controls')\n }\n\n this.open = false\n this.hostDisplay = 'none'\n if (this.cleanup) this.cleanup()\n\n this.closeEmitter.emit()\n }\n\n /**\n * Update the dropdown's middleware and position.\n */\n @Method()\n public async update(): Promise<void> {\n await this.updateMiddleware()\n }\n\n @Listen('click', { target: 'document' })\n protected async handleMouseDown(event: MouseEvent): Promise<void> {\n if (!this.open) return\n\n const composedPath = event.composedPath()\n const withinBounds =\n composedPath.includes(this.element) ||\n (this.referenceElement instanceof globalThis.Element &&\n composedPath.includes(this.referenceElement))\n if (!withinBounds) await this.close()\n }\n\n @Watch('target')\n private async updateReferenceElement(): Promise<void> {\n this.disconnectReferenceElement()\n\n const resolvedTarget =\n typeof this.target === 'function' ? this.target() : this.target\n if (typeof resolvedTarget === 'string') {\n const element = document.querySelector(resolvedTarget)\n if (element === null)\n throw new Error('String `target` must resolve to an Element.')\n this.referenceElement = element\n } else this.referenceElement = resolvedTarget\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.addEventListener('click', this.boundReferenceClick)\n this.referenceElement.addEventListener('focusout', this.boundFocusout)\n this.referenceElement.addEventListener('keydown', this.boundEscape)\n if (this.element.role === 'menu') {\n this.referenceElement.id ||= `qds-dropdown-trigger-${autoIncrementingId}`\n this.hostAriaLabelledBy = this.referenceElement.id\n }\n }\n\n @Watch('flipOptions')\n @Watch('noFlip')\n @Watch('noShift')\n @Watch('offsetOptions')\n @Watch('shiftOptions')\n private async updateMiddleware(): Promise<void> {\n this.middleware = [\n offset({\n ...this.offsetOptions,\n mainAxis:\n propertyToPx(this.element, '--qds-accessory-gap-floating') ?? 0,\n }),\n !this.noFlip &&\n flip({\n crossAxis: this.noShift,\n ...this.flipOptions,\n }),\n !this.noShift &&\n shift({\n limiter: limitShift(),\n ...this.shiftOptions,\n }),\n ].filter((middleware): middleware is Middleware => middleware !== false)\n await this.updatePosition()\n }\n\n @Watch('placement')\n @Watch('strategy')\n private async updatePosition(): Promise<void> {\n invariant(this.referenceElement)\n\n const { x, y, strategy } = await computePosition(\n this.referenceElement,\n this.element,\n {\n middleware: this.middleware,\n placement: this.placement,\n strategy: this.strategy,\n },\n )\n this.hostPosition = strategy\n this.hostTransform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`\n }\n\n @Watch('autoUpdateOptions')\n private startAutoUpdate(): void {\n invariant(this.referenceElement)\n\n if (this.cleanup) this.cleanup()\n this.cleanup = autoUpdate(\n this.referenceElement,\n this.element,\n () => {\n ignorePromise(this.updatePosition())\n },\n this.autoUpdateOptions,\n )\n }\n\n public async componentWillLoad(): Promise<void> {\n this.hostDisplay = 'none'\n this.element.role ??= 'menu'\n this.element.id ||= `qds-dropdown-${autoIncrementingId}`\n await this.updateReferenceElement()\n autoIncrementingId += 1\n await this.updateMiddleware()\n }\n\n public disconnectedCallback(): void {\n this.disconnectReferenceElement()\n }\n\n public render() {\n return (\n <Host\n aria-labelledby={this.hostAriaLabelledBy}\n onKeyDown={this.boundEscape}\n onFocusout={this.boundFocusout}\n style={{\n display: this.hostDisplay,\n position: this.hostPosition,\n transform: this.hostTransform,\n }}\n >\n <slot />\n </Host>\n )\n }\n\n private async handleFocusOut(event: Event): Promise<void> {\n if (!(event instanceof FocusEvent)) return\n const { relatedTarget } = event\n\n if (\n relatedTarget instanceof globalThis.Element &&\n !this.element.contains(relatedTarget) &&\n this.referenceElement !== relatedTarget\n )\n await this.close()\n }\n\n private readonly boundFocusout = (event: Event): void => {\n ignorePromise(this.handleFocusOut(event))\n }\n\n private async handleEscape(event: Event): Promise<void> {\n if (\n !(event instanceof KeyboardEvent) ||\n event.key !== 'Escape' ||\n (event.target !== this.referenceElement &&\n event.target instanceof globalThis.Element &&\n event.target.closest('qds-dropdown') !== this.element)\n )\n return\n\n const cancelEvent = this.cancelEmitter.emit()\n if (cancelEvent.defaultPrevented) return\n\n await this.close()\n if (\n this.referenceElement instanceof globalThis.HTMLElement ||\n this.referenceElement instanceof globalThis.SVGElement\n )\n this.referenceElement.focus()\n }\n\n private readonly boundEscape = (event: Event): void => {\n ignorePromise(this.handleEscape(event))\n }\n\n private async handleReferenceClick(): Promise<void> {\n if (!this.disabled) await (this.open ? this.close() : this.show())\n }\n\n private readonly boundReferenceClick = (): void => {\n ignorePromise(this.handleReferenceClick())\n }\n\n private disconnectReferenceElement(): void {\n this.hostAriaLabelledBy = undefined\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.removeEventListener('click', this.boundReferenceClick)\n this.referenceElement.removeEventListener('focusout', this.boundFocusout)\n this.referenceElement.removeEventListener('keydown', this.boundEscape)\n this.referenceElement.removeAttribute('aria-expanded')\n this.referenceElement.removeAttribute('aria-controls')\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"qds-dropdown.entry.js","mappings":";;;;;;;;;AAAA,MAAM,WAAW,GAAG,2UAA2U;;AC4C/V,IAAI,kBAAkB,GAAG,CAAC,CAAA;MAYb,QAAQ;;;;;IA8HX,SAAI,GAAG,KAAK,CAAA;IAwLH,kBAAa,GAAG,CAAC,KAAY;MAC5C,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;KAC1C,CAAA;IAuBgB,gBAAW,GAAG,CAAC,KAAY;MAC1C,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;KACxC,CAAA;IAMgB,wBAAmB,GAAG;MACrC,aAAa,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAA;KAC3C,CAAA;;oBA5U0C,KAAK;;kBAoBN,KAAK;mBAMJ,KAAK;;qBAkBD,cAAc;;;;;;;;;;;;EA2EtD,MAAM,IAAI;IACf,IAAI,IAAI,CAAC,IAAI;MAAE,OAAM;IAErB,IAAI,IAAI,CAAC,gBAAgB,YAAY,UAAU,CAAC,OAAO,EAAE;MACvD,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAA;MAC3D,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;KACrE;IAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAChB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;IAC5B,IAAI,CAAC,eAAe,EAAE,CAAA;GACvB;;;;EAMM,MAAM,KAAK;IAChB,IAAI,CAAC,IAAI,CAAC,IAAI;MAAE,OAAM;IAEtB,IAAI,IAAI,CAAC,gBAAgB,YAAY,UAAU,CAAC,OAAO,EAAE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,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAA;GAChC;EAMO,MAAM,oBAAoB;IAChC,IAAI,CAAC,IAAI,CAAC,QAAQ;MAAE,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;GACnE;EAMO,0BAA0B;IAChC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAA;IAEnC,IAAI,EAAE,IAAI,CAAC,gBAAgB,YAAY,UAAU,CAAC,OAAO,CAAC;MAAE,OAAM;IAElE,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAA;IAC5E,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IACzE,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACtE,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IACtD,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;GACvD;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/dropdown/dropdown.css?tag=qds-dropdown&encapsulation=shadow","src/components/dropdown/dropdown.tsx"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: © 2023 Schneider Electric\n *\n * SPDX-License-Identifier: LGPL-2.1-only\n */\n\n@import url('../shared.css');\n\n:host {\n background: var(--qds-theme-accessory-background);\n border-radius: var(--qds-accessory-border-radius);\n box-shadow: var(--qds-theme-accessory-elevation);\n display: inline-block;\n left: 0;\n top: 0;\n}\n","// SPDX-FileCopyrightText: © 2023 Schneider Electric\n//\n// SPDX-License-Identifier: LGPL-2.1-only\n\nimport type {\n AutoUpdateOptions,\n DetectOverflowOptions,\n FlipOptions,\n Middleware,\n Placement,\n ReferenceElement,\n ShiftOptions,\n Strategy,\n} from '@floating-ui/dom'\nimport {\n autoUpdate,\n computePosition,\n flip,\n limitShift,\n offset,\n shift,\n} from '@floating-ui/dom'\nimport type { ComponentInterface, EventEmitter } from '@stencil/core'\nimport {\n Component,\n Element,\n Event,\n h,\n Host,\n Listen,\n Method,\n Prop,\n State,\n Watch,\n} from '@stencil/core'\n\nimport type { OffsetOptions } from '../../helpers'\nimport {\n ignorePromise,\n invariant,\n propertyToPx,\n roundByDPR,\n} from '../../helpers'\n\nlet autoIncrementingId = 1\n\n/**\n * @experimental\n * @slot Content to display in the dropdown.\n * @see https://quartz.se.com/build/components/dropdown\n */\n@Component({\n tag: 'qds-dropdown',\n shadow: true,\n styleUrl: 'dropdown.css',\n})\nexport class Dropdown implements ComponentInterface {\n /**\n * Options to pass to Floating UI's\n * [`autoUpdate()` function](https://floating-ui.com/docs/autoUpdate).\n *\n * @see https://floating-ui.com/docs/autoupdate#options\n */\n @Prop() public readonly autoUpdateOptions?: AutoUpdateOptions\n\n /**\n * Prevents the dropdown from being shown by user interaction. The dropdown\n * can still be displayed by calling the `show()` method.\n */\n @Prop({ mutable: true }) public disabled = false\n\n /**\n * Options to pass to Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n *\n * The [`crossAxis` option](https://floating-ui.com/docs/flip#crossaxis) is\n * set to the value of the `noShift` property by default for interoperability\n * with the [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/flip#options\n */\n @Prop() public readonly flipOptions?: Partial<\n DetectOverflowOptions & FlipOptions\n >\n\n /**\n * Disable Floating UI's\n * [`flip` middleware](https://floating-ui.com/docs/flip).\n */\n @Prop() public readonly noFlip: boolean = false\n\n /**\n * Disable Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n */\n @Prop() public readonly noShift: boolean = false\n\n /**\n * Options to pass to Floating UI's\n * [`offset` middleware](https://floating-ui.com/docs/offset).\n *\n * The [`mainAxis` option](https://floating-ui.com/docs/offset#mainaxis) is\n * not supported.\n *\n * @see https://floating-ui.com/docs/offset#options\n */\n @Prop() public readonly offsetOptions?: OffsetOptions\n\n /**\n * Where to place the dropdown relative to the `target`.\n *\n * @see https://floating-ui.com/docs/tutorial#placements\n */\n @Prop() public readonly placement: Placement = 'bottom-start'\n\n /**\n * Options to pass to Floating UI's\n * [`shift` middleware](https://floating-ui.com/docs/shift).\n *\n * @see https://floating-ui.com/docs/shift#options\n */\n @Prop() public readonly shiftOptions?: Partial<\n DetectOverflowOptions & ShiftOptions\n >\n\n /**\n * The CSS position strategy to use.\n *\n * @see https://floating-ui.com/docs/computeposition#strategy\n */\n @Prop() public readonly strategy?: Strategy\n\n /**\n * The trigger element that will trigger the dropdown. The target specified\n * can be any of the follow:\n *\n * - A CSS selector string\n * - A reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element) or\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements)\n * - A function returning a reference to an\n * [`Element`](https://developer.mozilla.org/docs/Web/API/Element),\n * [Virtual Element](https://floating-ui.com/docs/virtual-elements),\n * or a CSS selector string\n */\n @Prop() public readonly target!:\n | ReferenceElement\n | string\n | (() => ReferenceElement | string)\n\n /**\n * Emitted when the user instructs the browser that they wish to dismiss the\n * current open dropdown by pressing the `Esc` key.\n *\n * When a dropdown is dismissed with the `Esc` key, both the `qdsCancel` and\n * `qdsClose` events are emitted.\n */\n @Event({ eventName: 'qdsCancel', bubbles: false })\n private readonly cancelEmitter!: EventEmitter<void>\n\n /**\n * Emitted when the dropdown is closed.\n */\n @Event({ eventName: 'qdsClose', bubbles: false, cancelable: false })\n private readonly closeEmitter!: EventEmitter<void>\n\n @Element() private readonly element!: HTMLQdsDropdownElement\n\n @State() private hostAriaLabelledBy?: string\n\n @State() private hostDisplay?: string\n\n @State() private hostPosition?: string\n\n @State() private hostTransform?: string\n\n private cleanup?: () => void\n\n private middleware?: Middleware[]\n\n private referenceElement?: ReferenceElement\n\n private open = false\n\n /**\n * Show the dropdown.\n */\n @Method()\n public async show(): Promise<void> {\n if (this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'true')\n this.referenceElement.setAttribute('aria-controls', this.element.id)\n }\n\n this.open = true\n this.hostDisplay = undefined\n this.startAutoUpdate()\n }\n\n /**\n * Close the dropdown.\n */\n @Method()\n public async close(): Promise<void> {\n if (!this.open) return\n\n if (this.referenceElement instanceof globalThis.Element) {\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.removeAttribute('aria-controls')\n }\n\n this.open = false\n this.hostDisplay = 'none'\n if (this.cleanup) this.cleanup()\n\n this.closeEmitter.emit()\n }\n\n /**\n * Update the dropdown's middleware and position.\n */\n @Method()\n public async update(): Promise<void> {\n await this.updateMiddleware()\n }\n\n @Listen('click', { target: 'document' })\n protected async handleMouseDown(event: MouseEvent): Promise<void> {\n if (!this.open) return\n\n const composedPath = event.composedPath()\n const withinBounds =\n composedPath.includes(this.element) ||\n (this.referenceElement instanceof globalThis.Element &&\n composedPath.includes(this.referenceElement))\n if (!withinBounds) await this.close()\n }\n\n @Watch('target')\n private async updateReferenceElement(): Promise<void> {\n this.disconnectReferenceElement()\n\n const resolvedTarget =\n typeof this.target === 'function' ? this.target() : this.target\n if (typeof resolvedTarget === 'string') {\n const element = document.querySelector(resolvedTarget)\n if (element === null)\n throw new Error('String `target` must resolve to an Element.')\n this.referenceElement = element\n } else this.referenceElement = resolvedTarget\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.setAttribute('aria-expanded', 'false')\n this.referenceElement.addEventListener('click', this.boundReferenceClick)\n this.referenceElement.addEventListener('focusout', this.boundFocusout)\n this.referenceElement.addEventListener('keydown', this.boundEscape)\n if (this.element.role === 'menu') {\n this.referenceElement.id ||= `qds-dropdown-trigger-${autoIncrementingId}`\n this.hostAriaLabelledBy = this.referenceElement.id\n }\n }\n\n @Watch('flipOptions')\n @Watch('noFlip')\n @Watch('noShift')\n @Watch('offsetOptions')\n @Watch('shiftOptions')\n private async updateMiddleware(): Promise<void> {\n this.middleware = [\n offset({\n ...this.offsetOptions,\n mainAxis:\n propertyToPx(this.element, '--qds-accessory-gap-floating') ?? 0,\n }),\n !this.noFlip &&\n flip({\n crossAxis: this.noShift,\n ...this.flipOptions,\n }),\n !this.noShift &&\n shift({\n limiter: limitShift(),\n ...this.shiftOptions,\n }),\n ].filter((middleware): middleware is Middleware => middleware !== false)\n await this.updatePosition()\n }\n\n @Watch('placement')\n @Watch('strategy')\n private async updatePosition(): Promise<void> {\n invariant(this.referenceElement)\n\n const { x, y, strategy } = await computePosition(\n this.referenceElement,\n this.element,\n {\n middleware: this.middleware,\n placement: this.placement,\n strategy: this.strategy,\n },\n )\n this.hostPosition = strategy\n this.hostTransform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`\n }\n\n @Watch('autoUpdateOptions')\n private startAutoUpdate(): void {\n invariant(this.referenceElement)\n\n if (this.cleanup) this.cleanup()\n this.cleanup = autoUpdate(\n this.referenceElement,\n this.element,\n () => {\n ignorePromise(this.updatePosition())\n },\n this.autoUpdateOptions,\n )\n }\n\n public async componentWillLoad(): Promise<void> {\n this.hostDisplay = 'none'\n this.element.role ??= 'menu'\n this.element.id ||= `qds-dropdown-${autoIncrementingId}`\n await this.updateReferenceElement()\n autoIncrementingId += 1\n await this.updateMiddleware()\n }\n\n public disconnectedCallback(): void {\n this.disconnectReferenceElement()\n }\n\n public render() {\n return (\n <Host\n aria-labelledby={this.hostAriaLabelledBy}\n onKeyDown={this.boundEscape}\n onFocusout={this.boundFocusout}\n style={{\n display: this.hostDisplay,\n position: this.hostPosition,\n transform: this.hostTransform,\n }}\n >\n <slot />\n </Host>\n )\n }\n\n private async handleFocusout(event: Event): Promise<void> {\n if (!(event instanceof FocusEvent)) return\n const { relatedTarget } = event\n\n if (\n relatedTarget instanceof globalThis.Element &&\n !this.element.contains(relatedTarget) &&\n this.referenceElement !== relatedTarget\n )\n await this.close()\n }\n\n private readonly boundFocusout = (event: Event): void => {\n ignorePromise(this.handleFocusout(event))\n }\n\n private async handleEscape(event: Event): Promise<void> {\n if (\n !(event instanceof KeyboardEvent) ||\n event.key !== 'Escape' ||\n (event.target !== this.referenceElement &&\n event.target instanceof globalThis.Element &&\n event.target.closest('qds-dropdown') !== this.element)\n )\n return\n\n const cancelEvent = this.cancelEmitter.emit()\n if (cancelEvent.defaultPrevented) return\n\n await this.close()\n if (\n this.referenceElement instanceof globalThis.HTMLElement ||\n this.referenceElement instanceof globalThis.SVGElement\n )\n this.referenceElement.focus()\n }\n\n private readonly boundEscape = (event: Event): void => {\n ignorePromise(this.handleEscape(event))\n }\n\n private async handleReferenceClick(): Promise<void> {\n if (!this.disabled) await (this.open ? this.close() : this.show())\n }\n\n private readonly boundReferenceClick = (): void => {\n ignorePromise(this.handleReferenceClick())\n }\n\n private disconnectReferenceElement(): void {\n this.hostAriaLabelledBy = undefined\n\n if (!(this.referenceElement instanceof globalThis.Element)) return\n\n this.referenceElement.removeEventListener('click', this.boundReferenceClick)\n this.referenceElement.removeEventListener('focusout', this.boundFocusout)\n this.referenceElement.removeEventListener('keydown', this.boundEscape)\n this.referenceElement.removeAttribute('aria-expanded')\n this.referenceElement.removeAttribute('aria-controls')\n }\n}\n"],"version":3}
|
|
@@ -8,7 +8,7 @@ import type { ComponentInterface } from '../../stencil-public-runtime';
|
|
|
8
8
|
export declare class Dialog implements ComponentInterface {
|
|
9
9
|
/**
|
|
10
10
|
* Indicates whether or not the dialog is open. You can toggle this attribute
|
|
11
|
-
* to show and hide the dialog, or you can use the `show()` and `
|
|
11
|
+
* to show and hide the dialog, or you can use the `show()` and `close()`
|
|
12
12
|
* methods and this attribute will reflect the dialog’s open state.
|
|
13
13
|
*/
|
|
14
14
|
open: boolean;
|
|
@@ -124,7 +124,7 @@ export declare class Dropdown implements ComponentInterface {
|
|
|
124
124
|
componentWillLoad(): Promise<void>;
|
|
125
125
|
disconnectedCallback(): void;
|
|
126
126
|
render(): any;
|
|
127
|
-
private
|
|
127
|
+
private handleFocusout;
|
|
128
128
|
private readonly boundFocusout;
|
|
129
129
|
private handleEscape;
|
|
130
130
|
private readonly boundEscape;
|
|
@@ -209,7 +209,7 @@ export namespace Components {
|
|
|
209
209
|
*/
|
|
210
210
|
"close": () => Promise<void>;
|
|
211
211
|
/**
|
|
212
|
-
* Indicates whether or not the dialog is open. You can toggle this attribute to show and hide the dialog, or you can use the `show()` and `
|
|
212
|
+
* Indicates whether or not the dialog is open. You can toggle this attribute to show and hide the dialog, or you can use the `show()` and `close()` methods and this attribute will reflect the dialog’s open state.
|
|
213
213
|
*/
|
|
214
214
|
"open": boolean;
|
|
215
215
|
/**
|
|
@@ -1333,7 +1333,7 @@ declare namespace LocalJSX {
|
|
|
1333
1333
|
*/
|
|
1334
1334
|
"onQdsClose"?: (event: QdsDialogCustomEvent<void>) => void;
|
|
1335
1335
|
/**
|
|
1336
|
-
* Indicates whether or not the dialog is open. You can toggle this attribute to show and hide the dialog, or you can use the `show()` and `
|
|
1336
|
+
* Indicates whether or not the dialog is open. You can toggle this attribute to show and hide the dialog, or you can use the `show()` and `close()` methods and this attribute will reflect the dialog’s open state.
|
|
1337
1337
|
*/
|
|
1338
1338
|
"open"?: boolean;
|
|
1339
1339
|
}
|
|
@@ -226,7 +226,7 @@
|
|
|
226
226
|
"attributes": [
|
|
227
227
|
{
|
|
228
228
|
"name": "open",
|
|
229
|
-
"description": "Indicates whether or not the dialog is open. You can toggle this attribute\nto show and hide the dialog, or you can use the `show()` and `
|
|
229
|
+
"description": "Indicates whether or not the dialog is open. You can toggle this attribute\nto show and hide the dialog, or you can use the `show()` and `close()`\nmethods and this attribute will reflect the dialog’s open state."
|
|
230
230
|
}
|
|
231
231
|
]
|
|
232
232
|
},
|
package/hydrate/index.js
CHANGED
|
@@ -6202,7 +6202,7 @@ class Checkbox {
|
|
|
6202
6202
|
}; }
|
|
6203
6203
|
}
|
|
6204
6204
|
|
|
6205
|
-
const dialogCss = "/*!@:host*/.sc-qds-dialog-h{box-sizing:border-box}/*!@:host([hidden])*/[hidden].sc-qds-dialog-h{display:none !important}/*!@:host([hidden])*//*!@:host *,\n:host *::before,\n:host *::after*/.sc-qds-dialog-h *.sc-qds-dialog,.sc-qds-dialog-h *.sc-qds-dialog::before,.sc-qds-dialog-h *.sc-qds-dialog::after{box-sizing:inherit}/*!@:host*/.sc-qds-dialog-h{display:
|
|
6205
|
+
const dialogCss = "/*!@:host*/.sc-qds-dialog-h{box-sizing:border-box}/*!@:host([hidden])*/[hidden].sc-qds-dialog-h{display:none !important}/*!@:host([hidden])*//*!@:host *,\n:host *::before,\n:host *::after*/.sc-qds-dialog-h *.sc-qds-dialog,.sc-qds-dialog-h *.sc-qds-dialog::before,.sc-qds-dialog-h *.sc-qds-dialog::after{box-sizing:inherit}/*!@:host*/.sc-qds-dialog-h{display:none;position:fixed;inset:0}/*!@:host([open])*/[open].sc-qds-dialog-h{display:block}/*!@.dialog*/.dialog.sc-qds-dialog{border-radius:var(--qds-popup-border-radius);border:none;box-shadow:var(--qds-theme-popup-elevation);padding:0}/*!@.dialog::backdrop*/.dialog.sc-qds-dialog::backdrop{background:transparent none repeat 0 0 / auto auto padding-box border-box scroll;background:initial}/*!@.dialog[open] ~ .backdrop*/.dialog[open].sc-qds-dialog~.backdrop.sc-qds-dialog{-webkit-backdrop-filter:blur(var(--qds-theme-popup-overlay-blur));backdrop-filter:blur(var(--qds-theme-popup-overlay-blur));background-color:var(--qds-theme-popup-overlay-background);inset:0;opacity:var(--qds-theme-popup-overlay-opacity);position:fixed}/*!@.content*/.content.sc-qds-dialog{align-items:flex-start;background-color:var(--qds-theme-popup-background);display:flex;flex-direction:column;gap:var(--qds-popup-gap-children-related);padding:var(--qds-popup-padding)}/*!@::slotted(blockquote),\n::slotted(button),\n::slotted(dd),\n::slotted(dl),\n::slotted(fieldset),\n::slotted(figure),\n::slotted(h1),\n::slotted(h2),\n::slotted(h3),\n::slotted(h4),\n::slotted(h5),\n::slotted(h6),\n::slotted(hr),\n::slotted(input),\n::slotted(menu),\n::slotted(ol),\n::slotted(p),\n::slotted(pre),\n::slotted(select),\n::slotted(textarea),\n::slotted(ul)*/.sc-qds-dialog-s>blockquote,.sc-qds-dialog-s>button,.sc-qds-dialog-s>dd,.sc-qds-dialog-s>dl,.sc-qds-dialog-s>fieldset,.sc-qds-dialog-s>figure,.sc-qds-dialog-s>h1,.sc-qds-dialog-s>h2,.sc-qds-dialog-s>h3,.sc-qds-dialog-s>h4,.sc-qds-dialog-s>h5,.sc-qds-dialog-s>h6,.sc-qds-dialog-s>hr,.sc-qds-dialog-s>input,.sc-qds-dialog-s>menu,.sc-qds-dialog-s>ol,.sc-qds-dialog-s>p,.sc-qds-dialog-s>pre,.sc-qds-dialog-s>select,.sc-qds-dialog-s>textarea,.sc-qds-dialog-s>ul{margin:0}";
|
|
6206
6206
|
|
|
6207
6207
|
/**
|
|
6208
6208
|
* The `<qds-dialog>` element represent a dialog box or other interactive
|
|
@@ -7820,7 +7820,7 @@ class Dropdown {
|
|
|
7820
7820
|
this.closeEmitter = createEvent(this, "qdsClose", 2);
|
|
7821
7821
|
this.open = false;
|
|
7822
7822
|
this.boundFocusout = (event) => {
|
|
7823
|
-
ignorePromise(this.
|
|
7823
|
+
ignorePromise(this.handleFocusout(event));
|
|
7824
7824
|
};
|
|
7825
7825
|
this.boundEscape = (event) => {
|
|
7826
7826
|
ignorePromise(this.handleEscape(event));
|
|
@@ -7968,7 +7968,7 @@ class Dropdown {
|
|
|
7968
7968
|
transform: this.hostTransform,
|
|
7969
7969
|
} }, hAsync("slot", null)));
|
|
7970
7970
|
}
|
|
7971
|
-
async
|
|
7971
|
+
async handleFocusout(event) {
|
|
7972
7972
|
if (!(event instanceof FocusEvent))
|
|
7973
7973
|
return;
|
|
7974
7974
|
const { relatedTarget } = event;
|
package/package.json
CHANGED