@felleslosninger/minid-elements 0.0.97 → 0.0.99
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/dist/components/alert.component.d.ts.map +1 -1
- package/dist/components/alert.js +44 -25
- package/dist/components/alert.js.map +1 -1
- package/dist/components/button.component.d.ts +4 -5
- package/dist/components/button.component.d.ts.map +1 -1
- package/dist/components/button.js +58 -53
- package/dist/components/button.js.map +1 -1
- package/dist/components/combobox.component.d.ts +1 -13
- package/dist/components/combobox.component.d.ts.map +1 -1
- package/dist/components/combobox.js +6 -17
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/{modal.component.d.ts → dialog.component.d.ts} +15 -16
- package/dist/components/dialog.component.d.ts.map +1 -0
- package/dist/components/{modal.js → dialog.js} +41 -77
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/dropdown.component.d.ts +4 -5
- package/dist/components/dropdown.component.d.ts.map +1 -1
- package/dist/components/dropdown.js +37 -57
- package/dist/components/dropdown.js.map +1 -1
- package/dist/components/heading.component.d.ts.map +1 -1
- package/dist/components/heading.js +9 -10
- package/dist/components/heading.js.map +1 -1
- package/dist/components/helptext.component.d.ts +1 -25
- package/dist/components/helptext.component.d.ts.map +1 -1
- package/dist/components/helptext.js +20 -48
- package/dist/components/helptext.js.map +1 -1
- package/dist/components/icon/icon.component.d.ts +1 -4
- package/dist/components/icon/icon.component.d.ts.map +1 -1
- package/dist/components/icon/icon.js +3 -12
- package/dist/components/icon/icon.js.map +1 -1
- package/dist/components/link.component.d.ts +0 -4
- package/dist/components/link.component.d.ts.map +1 -1
- package/dist/components/link.js +3 -22
- package/dist/components/link.js.map +1 -1
- package/dist/components/menu-item.component.d.ts +0 -3
- package/dist/components/menu-item.component.d.ts.map +1 -1
- package/dist/components/menu-item.js +25 -57
- package/dist/components/menu-item.js.map +1 -1
- package/dist/components/menu.component.d.ts +2 -11
- package/dist/components/menu.component.d.ts.map +1 -1
- package/dist/components/menu.js +12 -48
- package/dist/components/menu.js.map +1 -1
- package/dist/components/paragraph.component.d.ts.map +1 -1
- package/dist/components/paragraph.js +5 -6
- package/dist/components/paragraph.js.map +1 -1
- package/dist/components/phone-input.component.d.ts +3 -4
- package/dist/components/phone-input.component.d.ts.map +1 -1
- package/dist/components/phone-input.js +23 -62
- package/dist/components/phone-input.js.map +1 -1
- package/dist/components/popup.component.d.ts +2 -1
- package/dist/components/popup.component.d.ts.map +1 -1
- package/dist/components/popup.js +4 -0
- package/dist/components/popup.js.map +1 -1
- package/dist/components/radio-button.component.d.ts +0 -3
- package/dist/components/radio-button.component.d.ts.map +1 -1
- package/dist/components/radio-button.js.map +1 -1
- package/dist/components/radio.component.d.ts +0 -3
- package/dist/components/radio.component.d.ts.map +1 -1
- package/dist/components/radio.js +2 -5
- package/dist/components/radio.js.map +1 -1
- package/dist/components/textfield.component.d.ts +6 -29
- package/dist/components/textfield.component.d.ts.map +1 -1
- package/dist/components/textfield.js +55 -131
- package/dist/components/textfield.js.map +1 -1
- package/dist/components/tooltip.component.d.ts +4 -37
- package/dist/components/tooltip.component.d.ts.map +1 -1
- package/dist/components/tooltip.js +18 -34
- package/dist/components/tooltip.js.map +1 -1
- package/dist/designsystemet-tailwind.css +293 -474
- package/dist/index.css +0 -1355
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/mixins/tailwind.mixin.d.ts.map +1 -1
- package/dist/mixins/tailwind.mixin.js +3 -4
- package/dist/mixins/tailwind.mixin.js.map +1 -1
- package/dist/types/animation-name.d.ts +1 -1
- package/dist/types/animation-name.d.ts.map +1 -1
- package/dist/utilities/country-labels-no.d.ts +4 -0
- package/dist/utilities/country-labels-no.d.ts.map +1 -0
- package/dist/utilities/{countries.js → country-labels-no.js} +3 -3
- package/dist/utilities/{countries.js.map → country-labels-no.js.map} +1 -1
- package/package.json +10 -4
- package/dist/components/modal.component.d.ts.map +0 -1
- package/dist/components/modal.js.map +0 -1
- package/dist/utilities/countries.d.ts +0 -3
- package/dist/utilities/countries.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combobox.js","sources":["../../src/components/combobox.component.ts"],"sourcesContent":["import { css, html, LitElement, PropertyValues } from 'lit';\nimport {\n customElement,\n property,\n query,\n queryAssignedElements,\n state,\n} from 'lit/decorators.js';\nimport './popup.component';\nimport { styled } from '../mixins/tailwind.mixin.ts';\nimport { MinidPopup } from './popup.component';\nimport { waitForEvent } from '../internal/event';\nimport { watch } from '../internal/watch';\nimport {\n getAnimation,\n setDefaultAnimation,\n} from '../utilities/animation-registry';\nimport { animateTo, stopAnimations } from '../internal/animate';\nimport { getTabbableBoundary } from '../internal/tabbable';\nimport { MinidButton } from './button.component';\nimport { MinidMenu } from '../components/menu.component';\nimport { MinidPhoneInput } from '../components/phone-input.component';\nimport { MinidTextfield } from '../components/textfield.component';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-combobox': MinidCombobox;\n }\n}\n\nconst styles = [\n css`\n :host {\n display: flex;\n }\n `,\n];\n\n/**\n * @slot -- Default slot for content of the dropdown panel\n * @slot trigger - Used for the button element that will be used to open the dropdown menu\n * @part panel - Select the dropdown panel host element\n */\n@customElement('mid-combobox')\nexport class MinidCombobox extends styled(LitElement, styles) {\n /**\n * @ignore\n */\n #closeWatcher?: CloseWatcher;\n\n /**\n * @ignore\n */\n @query('#combobox')\n popup!: MinidPopup;\n\n /**\n * @ignore\n */\n @query('.combobox__trigger')\n trigger!: HTMLSlotElement;\n\n /**\n * @ignore\n */\n @query('.combobox__panel')\n panel!: HTMLSlotElement;\n\n /**\n * @ignore\n */\n @queryAssignedElements({ slot: 'trigger' })\n triggerElements!: (MinidTextfield | MinidPhoneInput | HTMLInputElement)[];\n\n /**\n * By default, the combobox is closed when an item is selected. This attribute will keep it open instead. Useful for\n * comboboxs that allow for multiple interactions.\n */\n @property({ type: Boolean, reflect: true })\n stayopenonselect = false;\n\n /**\n * Indicates wether the combobox panel is open. You can use this or the show/hide methods.\n */\n @property({ type: Boolean, reflect: true })\n open = false;\n\n @property()\n size: 'sm' | 'md' | 'lg' = 'md';\n\n /**\n * Distance between trigger and combobox panel\n */\n @property({ type: Number })\n distance = 4;\n\n /**\n * Nudge the combobox panel position. Accepts a negative or positive number.\n */\n @property({ type: Number })\n skidding = 0;\n\n /**\n * Choose if position is `fixed` or `absolute`. `absolute` is more performant,\n * but `fixed` can solve issues with overflow clipping\n */\n @property({ type: Boolean })\n hoist = false;\n\n @property({ type: Boolean })\n disabled = false;\n\n @state()\n triggerElement: 'mid-textfield' | 'mid-phone-input' = 'mid-textfield';\n\n /**\n * The combobox will close when the user interacts outside of this element (e.g. clicking). Useful for composing other\n * components that use a combobox internally.\n */\n @property({ attribute: false })\n containingElement?: HTMLElement;\n\n connectedCallback() {\n super.connectedCallback();\n\n if (!this.containingElement) {\n this.containingElement = this;\n }\n }\n\n protected firstUpdated(_changedProperties: PropertyValues): void {\n const input = this.triggerElements[0];\n if (input.tagName.toLowerCase() === 'mid-phone-input') {\n this.triggerElement = 'mid-phone-input';\n } else if (input.tagName.toLowerCase() === 'mid-textfield') {\n this.triggerElement = 'mid-textfield';\n }\n\n this.panel.hidden = !this.open;\n\n const menu = this.getMenu();\n if (menu) {\n menu.variant = 'combobox';\n }\n\n // If the combobox panel is visible on init, update its position\n if (this.open) {\n this.addOpenListeners();\n this.popup.active = true;\n }\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this.removeOpenListeners();\n this.hide();\n }\n\n focusOnTrigger() {\n const trigger = this.trigger.assignedElements({ flatten: true })[0] as\n | HTMLElement\n | undefined;\n\n if (typeof trigger?.focus === 'function') {\n trigger.focus();\n }\n }\n\n getMenu() {\n return this.panel\n .assignedElements({ flatten: true })\n .find((el) => el.tagName.toLowerCase() === 'mid-menu') as\n | MinidMenu\n | undefined;\n }\n\n private handleCountryClick = () => {\n const menu = this.getMenu();\n\n this.open ? this.hide() : this.show();\n if (this.open && menu && menu.searchable) {\n // Delay focus slightly to win the focus battle\n setTimeout(() => {\n menu.clearFilter();\n menu.focusSearchField();\n }, 1);\n }\n };\n\n private handleKeyDown = (event: KeyboardEvent) => {\n // Close when escape is pressed inside an open combobox. We need to listen on the panel itself and stop propagation\n // in case any ancestors are also listening for this key.\n if (this.open && event.key === 'Escape') {\n event.stopPropagation();\n this.hide();\n this.focusOnTrigger();\n return;\n }\n };\n\n private handleDocumentKeyDown = (event: KeyboardEvent) => {\n // Close when escape or tab is pressed\n if (event.key === 'Escape' && this.open && !this.#closeWatcher) {\n event.stopPropagation();\n this.focusOnTrigger();\n this.hide();\n return;\n }\n\n // Handle tabbing\n if (event.key === 'Tab') {\n // Tabbing within an open menu should close the combobox and refocus the trigger\n if (\n this.open &&\n (document.activeElement?.tagName.toLowerCase() === 'mid-menu-item' ||\n document.activeElement?.tagName.toLowerCase() === 'mid-menu')\n ) {\n event.preventDefault();\n this.hide();\n this.focusOnTrigger();\n return;\n }\n\n // Tabbing outside of the containing element closes the panel\n //\n // If the combobox is used within a shadow DOM, we need to obtain the activeElement within that shadowRoot,\n // otherwise `document.activeElement` will only return the name of the parent shadow DOM element.\n setTimeout(() => {\n const activeElement =\n this.containingElement?.getRootNode() instanceof ShadowRoot\n ? document.activeElement?.shadowRoot?.activeElement\n : document.activeElement;\n\n if (\n !this.containingElement ||\n activeElement?.closest(\n this.containingElement.tagName.toLowerCase()\n ) !== this.containingElement\n ) {\n this.hide();\n }\n });\n }\n };\n\n private handleDocumentMouseDown = (event: MouseEvent) => {\n // Close when clicking outside of the containing element\n const path = event.composedPath();\n if (this.containingElement && !path.includes(this.containingElement)) {\n this.hide();\n }\n };\n\n private handlePanelSelect = (event: CustomEvent) => {\n if (this.triggerElement !== 'mid-phone-input') {\n return;\n }\n\n // Transfer selected country from panel to input field\n const input = this.triggerElements[0] as MinidPhoneInput;\n const country = event.detail.item.value;\n input.country = country;\n\n const target = event.target as HTMLElement;\n\n // Hide the combobox when a menu item is selected\n if (!this.stayopenonselect && target.tagName.toLowerCase() === 'mid-menu') {\n this.hide();\n this.focusOnTrigger();\n }\n };\n\n handleTriggerClick() {\n if (this.triggerElement === 'mid-phone-input') {\n return;\n }\n\n if (this.open) {\n this.hide();\n } else {\n this.show();\n this.focusOnTrigger();\n }\n }\n\n async handleTriggerKeyDown(event: KeyboardEvent) {\n // When spacebar/enter is pressed, show the panel but don't focus on the menu. This let's the user press the same\n // key again to hide the menu in case they don't want to make a selection.\n if ([' ', 'Enter'].includes(event.key)) {\n event.preventDefault();\n if (this.triggerElement === 'mid-textfield') {\n this.handleTriggerClick();\n }\n return;\n }\n\n const menu = this.getMenu();\n\n if (menu) {\n const menuItems = menu.getAllSelectableItems();\n const firstMenuItem = menuItems[0];\n const lastMenuItem = menuItems[menuItems.length - 1];\n\n // When up/down is pressed, we make the assumption that the user is familiar with the menu and plans to make a\n // selection. Rather than toggle the panel, we focus on the menu (if one exists) and activate the first item for\n // faster navigation.\n if (['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) {\n event.preventDefault();\n\n // Show the menu if it's not already open\n if (!this.open) {\n this.show();\n\n // Wait for the combobox to open before focusing, but not the animation\n await this.updateComplete;\n }\n\n if (menuItems.length > 0) {\n // Focus on the first/last menu item after showing\n this.updateComplete.then(() => {\n if (event.key === 'ArrowDown' || event.key === 'Home') {\n menu.setCurrentItem(firstMenuItem);\n if (this.triggerElement === 'mid-textfield') {\n firstMenuItem.focus();\n } else {\n menu.clearFilter();\n menu.focusSearchField();\n }\n }\n\n if (event.key === 'ArrowUp' || event.key === 'End') {\n menu.setCurrentItem(lastMenuItem);\n if (this.triggerElement === 'mid-textfield') {\n lastMenuItem.focus();\n } else {\n menu.clearFilter();\n menu.focusSearchField();\n }\n }\n });\n }\n }\n }\n }\n\n handleTriggerKeyUp(event: KeyboardEvent) {\n // Prevent space from triggering a click event in Firefox\n if (event.key === ' ') {\n event.preventDefault();\n }\n }\n\n handleTriggerSlotChange() {\n this.updateAccessibleTrigger();\n }\n\n /**\n * Instructs the combobox menu to reposition. Useful when the position or size of the trigger changes when the menu\n * is activated.\n */\n reposition() {\n this.popup.reposition();\n }\n\n addOpenListeners() {\n if ('CloseWatcher' in window) {\n this.#closeWatcher?.destroy();\n this.#closeWatcher = new CloseWatcher();\n this.#closeWatcher.onclose = () => {\n this.hide();\n this.focusOnTrigger();\n };\n }\n\n document.addEventListener('keydown', this.handleDocumentKeyDown);\n document.addEventListener('mousedown', this.handleDocumentMouseDown);\n }\n\n removeOpenListeners() {\n document.removeEventListener('keydown', this.handleDocumentKeyDown);\n document.removeEventListener('mousedown', this.handleDocumentMouseDown);\n this.#closeWatcher?.destroy();\n }\n\n /**\n * Shows the combobox panel.\n */\n async show() {\n if (this.open) {\n return undefined;\n }\n\n this.open = true;\n return waitForEvent(this, 'mid-after-show');\n }\n\n /**\n * Hides the combobox panel\n */\n async hide() {\n if (!this.open) {\n return undefined;\n }\n\n this.open = false;\n return waitForEvent(this, 'mid-after-hide');\n }\n\n //\n // Slotted triggers can be arbitrary content, but we need to link them to the combobox panel with `aria-haspopup` and\n // `aria-expanded`. These must be applied to the \"accessible trigger\" (the tabbable portion of the trigger element\n // that gets slotted in) so screen readers will understand them. The accessible trigger could be the slotted element,\n // a child of the slotted element, or an element in the slotted element's shadow root.\n //\n // For example, the accessible trigger of an <sl-button> is a <button> located inside its shadow root.\n //\n // To determine this, we assume the first tabbable element in the trigger slot is the \"accessible trigger.\"\n //\n updateAccessibleTrigger() {\n const assignedElements = this.trigger.assignedElements({\n flatten: true,\n }) as HTMLElement[];\n const accessibleTrigger = assignedElements.find(\n (el) => getTabbableBoundary(el).start\n );\n let target: HTMLElement;\n\n if (accessibleTrigger) {\n switch (accessibleTrigger.tagName.toLowerCase()) {\n // buttons have to update the internal button so it's announced correctly by screen readers\n case 'mid-button':\n target = (accessibleTrigger as MinidButton).button;\n break;\n\n default:\n target = accessibleTrigger;\n }\n\n target.setAttribute('aria-haspopup', 'true');\n target.setAttribute('aria-expanded', this.open ? 'true' : 'false');\n }\n }\n\n @watch('open', { waitUntilFirstUpdate: true })\n async handleOpenChange() {\n if (this.disabled) {\n this.open = false;\n return;\n }\n\n this.updateAccessibleTrigger();\n\n if (this.open) {\n // Show\n this.dispatchEvent(\n new Event('mid-show', { bubbles: true, composed: true })\n );\n this.addOpenListeners();\n\n await stopAnimations(this);\n this.panel.hidden = false;\n this.popup.active = true;\n const { keyframes, options } = getAnimation(this, 'combobox.show');\n await animateTo(this.popup.popup, keyframes, options);\n\n this.dispatchEvent(\n new Event('mid-after-show', { bubbles: true, composed: true })\n );\n } else {\n // Hide\n this.dispatchEvent(\n new Event('mid-hide', { bubbles: true, composed: true })\n );\n this.removeOpenListeners();\n await stopAnimations(this);\n const { keyframes, options } = getAnimation(this, 'combobox.hide');\n await animateTo(this.popup.popup, keyframes, options);\n this.panel.hidden = true;\n this.popup.active = false;\n\n this.dispatchEvent(\n new Event('mid-after-hide', { bubbles: true, composed: true })\n );\n }\n }\n\n override render() {\n return html`\n <mid-popup\n id=\"combobox\"\n distance=${this.distance}\n placement=\"bottom-end\"\n skidding=${this.skidding}\n strategy=${this.hoist ? 'fixed' : 'absolute'}\n flip\n shift\n auto-size=\"vertical\"\n auto-size-padding=\"10\"\n sync=\"width\"\n ?active=${this.open}\n >\n <slot\n class=\"combobox__trigger\"\n slot=\"anchor\"\n name=\"trigger\"\n @click=${this.handleTriggerClick}\n @keydown=${this.handleTriggerKeyDown}\n @keyup=${this.handleTriggerKeyUp}\n @slotchange=${this.handleTriggerSlotChange}\n @mid-country-click=${this.handleCountryClick}\n >\n </slot>\n <div\n aria-hidden=${this.open ? 'false' : 'true'}\n aria-labelledby=\"combobox\"\n >\n <slot\n class=\"combobox__panel\"\n part=\"panel\"\n @keydown=${this.handleKeyDown}\n @mid-select=${this.handlePanelSelect}\n ></slot>\n </div>\n </mid-popup>\n `;\n }\n}\n\nsetDefaultAnimation('combobox.show', {\n keyframes: [\n { opacity: 0, scale: 0.9 },\n { opacity: 1, scale: 1 },\n ],\n options: { duration: 100, easing: 'ease' },\n});\n\nsetDefaultAnimation('combobox.hide', {\n keyframes: [\n { opacity: 1, scale: 1 },\n { opacity: 0, scale: 0.9 },\n ],\n options: { duration: 100, easing: 'ease' },\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AA8BA,MAAM,SAAS;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAKF;AAQO,IAAM,gBAAN,cAA4B,OAAO,YAAY,MAAM,EAAE;AAAA,EAAvD,cAAA;AAAA,UAAA,GAAA,SAAA;AAIL,iBAAA,MAAA,aAAA;AA+BmB,SAAA,mBAAA;AAMZ,SAAA,OAAA;AAGoB,SAAA,OAAA;AAMhB,SAAA,WAAA;AAMA,SAAA,WAAA;AAOH,SAAA,QAAA;AAGG,SAAA,WAAA;AAG2C,SAAA,iBAAA;AA+DtD,SAAQ,qBAAqB,MAAM;AAC3B,YAAA,OAAO,KAAK,QAAQ;AAE1B,WAAK,OAAO,KAAK,KAAK,IAAI,KAAK,KAAK;AACpC,UAAI,KAAK,QAAQ,QAAQ,KAAK,YAAY;AAExC,mBAAW,MAAM;AACf,eAAK,YAAY;AACjB,eAAK,iBAAiB;AAAA,WACrB,CAAC;AAAA,MAAA;AAAA,IAER;AAEQ,SAAA,gBAAgB,CAAC,UAAyB;AAGhD,UAAI,KAAK,QAAQ,MAAM,QAAQ,UAAU;AACvC,cAAM,gBAAgB;AACtB,aAAK,KAAK;AACV,aAAK,eAAe;AACpB;AAAA,MAAA;AAAA,IAEJ;AAEQ,SAAA,wBAAwB,CAAC,UAAyB;AAExD,UAAI,MAAM,QAAQ,YAAY,KAAK,QAAQ,CAAC,mBAAK,aAAe,GAAA;AAC9D,cAAM,gBAAgB;AACtB,aAAK,eAAe;AACpB,aAAK,KAAK;AACV;AAAA,MAAA;AAIE,UAAA,MAAM,QAAQ,OAAO;AAEvB,YACE,KAAK,SACJ,SAAS,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A;AAAA,GA/YlC,cAgZL,WAAA,oBAAA,CAAA;AAhZK,gBAAN,gBAAA;AAAA,EADN,cAAc,cAAc;AAAA,GAChB,aAAA;AAoeb,oBAAoB,iBAAiB;AAAA,EACnC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,OAAO,IAAI;AAAA,IACzB,EAAE,SAAS,GAAG,OAAO,EAAE;AAAA,EACzB;AAAA,EACA,SAAS,EAAE,UAAU,KAAK,QAAQ,OAAO;AAC3C,CAAC;AAED,oBAAoB,iBAAiB;AAAA,EACnC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,OAAO,EAAE;AAAA,IACvB,EAAE,SAAS,GAAG,OAAO,IAAI;AAAA,EAC3B;AAAA,EACA,SAAS,EAAE,UAAU,KAAK,QAAQ,OAAO;AAC3C,CAAC;"}
|
|
1
|
+
{"version":3,"file":"combobox.js","sources":["../../src/components/combobox.component.ts"],"sourcesContent":["import { css, html, LitElement, PropertyValues } from 'lit';\nimport {\n customElement,\n property,\n query,\n queryAssignedElements,\n state,\n} from 'lit/decorators.js';\nimport './popup.component';\nimport { styled } from '../mixins/tailwind.mixin.ts';\nimport { MinidPopup } from './popup.component';\nimport { waitForEvent } from '../internal/event';\nimport { watch } from '../internal/watch';\nimport {\n getAnimation,\n setDefaultAnimation,\n} from '../utilities/animation-registry';\nimport { animateTo, stopAnimations } from '../internal/animate';\nimport { getTabbableBoundary } from '../internal/tabbable';\nimport { MinidButton } from './button.component';\nimport { MinidMenu } from '../components/menu.component';\nimport { MinidPhoneInput } from '../components/phone-input.component';\nimport { MinidTextfield } from '../components/textfield.component';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-combobox': MinidCombobox;\n }\n}\n\nconst styles = [\n css`\n :host {\n display: flex;\n }\n `,\n];\n\n/**\n * @slot -- Default slot for content of the dropdown panel\n * @slot trigger - Used for the button element that will be used to open the dropdown menu\n * @part panel - Select the dropdown panel host element\n */\n@customElement('mid-combobox')\nexport class MinidCombobox extends styled(LitElement, styles) {\n private closeWatcher?: CloseWatcher;\n\n @query('#combobox')\n popup!: MinidPopup;\n\n @query('.combobox__trigger')\n trigger!: HTMLSlotElement;\n\n @query('.combobox__panel')\n panel!: HTMLSlotElement;\n\n @queryAssignedElements({ slot: 'trigger' })\n triggerElements!: (MinidTextfield | MinidPhoneInput | HTMLInputElement)[];\n\n /**\n * By default, the combobox is closed when an item is selected. This attribute will keep it open instead. Useful for\n * comboboxs that allow for multiple interactions.\n */\n @property({ type: Boolean, reflect: true })\n stayopenonselect = false;\n\n /**\n * Indicates wether the combobox panel is open. You can use this or the show/hide methods.\n */\n @property({ type: Boolean, reflect: true })\n open = false;\n\n @property()\n size: 'sm' | 'md' | 'lg' = 'md';\n\n /**\n * Distance between trigger and combobox panel\n */\n @property({ type: Number })\n distance = 4;\n\n /**\n * Nudge the combobox panel position. Accepts a negative or positive number.\n */\n @property({ type: Number })\n skidding = 0;\n\n /**\n * Choose if position is `fixed` or `absolute`. `absolute` is more performant,\n * but `fixed` can solve issues with overflow clipping\n */\n @property({ type: Boolean })\n hoist = false;\n\n @property({ type: Boolean })\n disabled = false;\n\n @state()\n triggerElement: 'mid-textfield' | 'mid-phone-input' = 'mid-textfield';\n\n /**\n * The combobox will close when the user interacts outside of this element (e.g. clicking). Useful for composing other\n * components that use a combobox internally.\n */\n @property({ attribute: false })\n containingElement?: HTMLElement;\n\n connectedCallback() {\n super.connectedCallback();\n\n if (!this.containingElement) {\n this.containingElement = this;\n }\n }\n\n protected firstUpdated(_changedProperties: PropertyValues): void {\n const input = this.triggerElements[0];\n if (input.tagName.toLowerCase() === 'mid-phone-input') {\n this.triggerElement = 'mid-phone-input';\n } else if (input.tagName.toLowerCase() === 'mid-textfield') {\n this.triggerElement = 'mid-textfield';\n }\n\n this.panel.hidden = !this.open;\n\n const menu = this.getMenu();\n if (menu) {\n menu.variant = 'combobox';\n }\n\n // If the combobox panel is visible on init, update its position\n if (this.open) {\n this.addOpenListeners();\n this.popup.active = true;\n }\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this.removeOpenListeners();\n this.hide();\n }\n\n focusOnTrigger() {\n const trigger = this.trigger.assignedElements({ flatten: true })[0] as\n | HTMLElement\n | undefined;\n\n if (typeof trigger?.focus === 'function') {\n trigger.focus();\n }\n }\n\n getMenu() {\n return this.panel\n .assignedElements({ flatten: true })\n .find((el) => el.tagName.toLowerCase() === 'mid-menu') as\n | MinidMenu\n | undefined;\n }\n\n private handleCountryClick = () => {\n const menu = this.getMenu();\n\n this.open ? this.hide() : this.show();\n if (this.open && menu && menu.searchable) {\n // Delay focus slightly to win the focus battle\n setTimeout(() => {\n menu.clearFilter();\n menu.focusSearchField();\n }, 1);\n }\n };\n\n private handleKeyDown = (event: KeyboardEvent) => {\n // Close when escape is pressed inside an open combobox. We need to listen on the panel itself and stop propagation\n // in case any ancestors are also listening for this key.\n if (this.open && event.key === 'Escape') {\n event.stopPropagation();\n this.hide();\n this.focusOnTrigger();\n return;\n }\n };\n\n private handleDocumentKeyDown = (event: KeyboardEvent) => {\n // Close when escape or tab is pressed\n if (event.key === 'Escape' && this.open && !this.closeWatcher) {\n event.stopPropagation();\n this.focusOnTrigger();\n this.hide();\n return;\n }\n\n // Handle tabbing\n if (event.key === 'Tab') {\n // Tabbing within an open menu should close the combobox and refocus the trigger\n if (\n this.open &&\n (document.activeElement?.tagName.toLowerCase() === 'mid-menu-item' ||\n document.activeElement?.tagName.toLowerCase() === 'mid-menu')\n ) {\n event.preventDefault();\n this.hide();\n this.focusOnTrigger();\n return;\n }\n\n // Tabbing outside of the containing element closes the panel\n //\n // If the combobox is used within a shadow DOM, we need to obtain the activeElement within that shadowRoot,\n // otherwise `document.activeElement` will only return the name of the parent shadow DOM element.\n setTimeout(() => {\n const activeElement =\n this.containingElement?.getRootNode() instanceof ShadowRoot\n ? document.activeElement?.shadowRoot?.activeElement\n : document.activeElement;\n\n if (\n !this.containingElement ||\n activeElement?.closest(\n this.containingElement.tagName.toLowerCase()\n ) !== this.containingElement\n ) {\n this.hide();\n }\n });\n }\n };\n\n private handleDocumentMouseDown = (event: MouseEvent) => {\n // Close when clicking outside of the containing element\n const path = event.composedPath();\n if (this.containingElement && !path.includes(this.containingElement)) {\n this.hide();\n }\n };\n\n private handlePanelSelect = (event: CustomEvent) => {\n if (this.triggerElement !== 'mid-phone-input') {\n return;\n }\n\n // Transfer selected country from panel to input field\n const input = this.triggerElements[0] as MinidPhoneInput;\n const country = event.detail.item.value;\n input.country = country;\n\n const target = event.target as HTMLElement;\n\n // Hide the combobox when a menu item is selected\n if (!this.stayopenonselect && target.tagName.toLowerCase() === 'mid-menu') {\n this.hide();\n this.focusOnTrigger();\n }\n };\n\n handleTriggerClick() {\n if (this.triggerElement === 'mid-phone-input') {\n return;\n }\n\n if (this.open) {\n this.hide();\n } else {\n this.show();\n this.focusOnTrigger();\n }\n }\n\n async handleTriggerKeyDown(event: KeyboardEvent) {\n // When spacebar/enter is pressed, show the panel but don't focus on the menu. This let's the user press the same\n // key again to hide the menu in case they don't want to make a selection.\n if ([' ', 'Enter'].includes(event.key)) {\n event.preventDefault();\n if (this.triggerElement === 'mid-textfield') {\n this.handleTriggerClick();\n }\n return;\n }\n\n const menu = this.getMenu();\n\n if (menu) {\n const menuItems = menu.getAllSelectableItems();\n const firstMenuItem = menuItems[0];\n const lastMenuItem = menuItems[menuItems.length - 1];\n\n // When up/down is pressed, we make the assumption that the user is familiar with the menu and plans to make a\n // selection. Rather than toggle the panel, we focus on the menu (if one exists) and activate the first item for\n // faster navigation.\n if (['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) {\n event.preventDefault();\n\n // Show the menu if it's not already open\n if (!this.open) {\n this.show();\n\n // Wait for the combobox to open before focusing, but not the animation\n await this.updateComplete;\n }\n\n if (menuItems.length > 0) {\n // Focus on the first/last menu item after showing\n this.updateComplete.then(() => {\n if (event.key === 'ArrowDown' || event.key === 'Home') {\n menu.setCurrentItem(firstMenuItem);\n if (this.triggerElement === 'mid-textfield') {\n firstMenuItem.focus();\n } else {\n menu.clearFilter();\n menu.focusSearchField();\n }\n }\n\n if (event.key === 'ArrowUp' || event.key === 'End') {\n menu.setCurrentItem(lastMenuItem);\n if (this.triggerElement === 'mid-textfield') {\n lastMenuItem.focus();\n } else {\n menu.clearFilter();\n menu.focusSearchField();\n }\n }\n });\n }\n }\n }\n }\n\n handleTriggerKeyUp(event: KeyboardEvent) {\n // Prevent space from triggering a click event in Firefox\n if (event.key === ' ') {\n event.preventDefault();\n }\n }\n\n handleTriggerSlotChange() {\n this.updateAccessibleTrigger();\n }\n\n /**\n * Instructs the combobox menu to reposition. Useful when the position or size of the trigger changes when the menu\n * is activated.\n */\n reposition() {\n this.popup.reposition();\n }\n\n addOpenListeners() {\n if ('CloseWatcher' in window) {\n this.closeWatcher?.destroy();\n this.closeWatcher = new CloseWatcher();\n this.closeWatcher.onclose = () => {\n this.hide();\n this.focusOnTrigger();\n };\n }\n\n document.addEventListener('keydown', this.handleDocumentKeyDown);\n document.addEventListener('mousedown', this.handleDocumentMouseDown);\n }\n\n removeOpenListeners() {\n document.removeEventListener('keydown', this.handleDocumentKeyDown);\n document.removeEventListener('mousedown', this.handleDocumentMouseDown);\n this.closeWatcher?.destroy();\n }\n\n /**\n * Shows the combobox panel.\n */\n async show() {\n if (this.open) {\n return undefined;\n }\n\n this.open = true;\n return waitForEvent(this, 'mid-after-show');\n }\n\n /**\n * Hides the combobox panel\n */\n async hide() {\n if (!this.open) {\n return undefined;\n }\n\n this.open = false;\n return waitForEvent(this, 'mid-after-hide');\n }\n\n //\n // Slotted triggers can be arbitrary content, but we need to link them to the combobox panel with `aria-haspopup` and\n // `aria-expanded`. These must be applied to the \"accessible trigger\" (the tabbable portion of the trigger element\n // that gets slotted in) so screen readers will understand them. The accessible trigger could be the slotted element,\n // a child of the slotted element, or an element in the slotted element's shadow root.\n //\n // For example, the accessible trigger of an <sl-button> is a <button> located inside its shadow root.\n //\n // To determine this, we assume the first tabbable element in the trigger slot is the \"accessible trigger.\"\n //\n updateAccessibleTrigger() {\n const assignedElements = this.trigger.assignedElements({\n flatten: true,\n }) as HTMLElement[];\n const accessibleTrigger = assignedElements.find(\n (el) => getTabbableBoundary(el).start\n );\n let target: HTMLElement;\n\n if (accessibleTrigger) {\n switch (accessibleTrigger.tagName.toLowerCase()) {\n // buttons have to update the internal button so it's announced correctly by screen readers\n case 'mid-button':\n target = (accessibleTrigger as MinidButton).button;\n break;\n\n default:\n target = accessibleTrigger;\n }\n\n target.setAttribute('aria-haspopup', 'true');\n target.setAttribute('aria-expanded', this.open ? 'true' : 'false');\n }\n }\n\n @watch('open', { waitUntilFirstUpdate: true })\n async handleOpenChange() {\n if (this.disabled) {\n this.open = false;\n return;\n }\n\n this.updateAccessibleTrigger();\n\n if (this.open) {\n // Show\n this.dispatchEvent(\n new Event('mid-show', { bubbles: true, composed: true })\n );\n this.addOpenListeners();\n\n await stopAnimations(this);\n this.panel.hidden = false;\n this.popup.active = true;\n const { keyframes, options } = getAnimation(this, 'combobox.show');\n await animateTo(this.popup.popup, keyframes, options);\n\n this.dispatchEvent(\n new Event('mid-after-show', { bubbles: true, composed: true })\n );\n } else {\n // Hide\n this.dispatchEvent(\n new Event('mid-hide', { bubbles: true, composed: true })\n );\n this.removeOpenListeners();\n await stopAnimations(this);\n const { keyframes, options } = getAnimation(this, 'combobox.hide');\n await animateTo(this.popup.popup, keyframes, options);\n this.panel.hidden = true;\n this.popup.active = false;\n\n this.dispatchEvent(\n new Event('mid-after-hide', { bubbles: true, composed: true })\n );\n }\n }\n\n override render() {\n return html`\n <mid-popup\n id=\"combobox\"\n distance=${this.distance}\n placement=\"bottom-end\"\n skidding=${this.skidding}\n strategy=${this.hoist ? 'fixed' : 'absolute'}\n flip\n shift\n auto-size=\"vertical\"\n auto-size-padding=\"10\"\n sync=\"width\"\n ?active=${this.open}\n >\n <slot\n class=\"combobox__trigger\"\n slot=\"anchor\"\n name=\"trigger\"\n @click=${this.handleTriggerClick}\n @keydown=${this.handleTriggerKeyDown}\n @keyup=${this.handleTriggerKeyUp}\n @slotchange=${this.handleTriggerSlotChange}\n @mid-country-click=${this.handleCountryClick}\n ></slot>\n <div\n aria-hidden=${this.open ? 'false' : 'true'}\n aria-labelledby=\"combobox\"\n >\n <slot\n class=\"combobox__panel\"\n part=\"panel\"\n @keydown=${this.handleKeyDown}\n @mid-select=${this.handlePanelSelect}\n ></slot>\n </div>\n </mid-popup>\n `;\n }\n}\n\nsetDefaultAnimation('combobox.show', {\n keyframes: [\n { opacity: 0, scale: 0.9 },\n { opacity: 1, scale: 1 },\n ],\n options: { duration: 100, easing: 'ease' },\n});\n\nsetDefaultAnimation('combobox.hide', {\n keyframes: [\n { opacity: 1, scale: 1 },\n { opacity: 0, scale: 0.9 },\n ],\n options: { duration: 100, easing: 'ease' },\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,MAAM,SAAS;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAKF;AAQO,IAAM,gBAAN,cAA4B,OAAO,YAAY,MAAM,EAAE;AAAA,EAAvD,cAAA;AAAA,UAAA,GAAA,SAAA;AAoBc,SAAA,mBAAA;AAMZ,SAAA,OAAA;AAGoB,SAAA,OAAA;AAMhB,SAAA,WAAA;AAMA,SAAA,WAAA;AAOH,SAAA,QAAA;AAGG,SAAA,WAAA;AAG2C,SAAA,iBAAA;AA+DtD,SAAQ,qBAAqB,MAAM;AAC3B,YAAA,OAAO,KAAK,QAAQ;AAE1B,WAAK,OAAO,KAAK,KAAK,IAAI,KAAK,KAAK;AACpC,UAAI,KAAK,QAAQ,QAAQ,KAAK,YAAY;AAExC,mBAAW,MAAM;AACf,eAAK,YAAY;AACjB,eAAK,iBAAiB;AAAA,WACrB,CAAC;AAAA,MAAA;AAAA,IAER;AAEQ,SAAA,gBAAgB,CAAC,UAAyB;AAGhD,UAAI,KAAK,QAAQ,MAAM,QAAQ,UAAU;AACvC,cAAM,gBAAgB;AACtB,aAAK,KAAK;AACV,aAAK,eAAe;A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sDX,WAAA,kBAAA,CAAA;AAOA,gBAAA;AAAA,EADC,SAAS,EAAE,WAAW,MAAO,CAAA;AAAA,GA5DnB,cA6DX,WAAA,qBAAA,CAAA;AAoUM,gBAAA;AAAA,EADL,MAAM,QAAQ,EAAE,sBAAsB,KAAM,CAAA;AAAA,GAhYlC,cAiYL,WAAA,oBAAA,CAAA;AAjYK,gBAAN,gBAAA;AAAA,EADN,cAAc,cAAc;AAAA,GAChB,aAAA;AAodb,oBAAoB,iBAAiB;AAAA,EACnC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,OAAO,IAAI;AAAA,IACzB,EAAE,SAAS,GAAG,OAAO,EAAE;AAAA,EACzB;AAAA,EACA,SAAS,EAAE,UAAU,KAAK,QAAQ,OAAO;AAC3C,CAAC;AAED,oBAAoB,iBAAiB;AAAA,EACnC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,OAAO,EAAE;AAAA,IACvB,EAAE,SAAS,GAAG,OAAO,IAAI;AAAA,EAC3B;AAAA,EACA,SAAS,EAAE,UAAU,KAAK,QAAQ,OAAO;AAC3C,CAAC;"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
2
|
declare global {
|
|
3
3
|
interface HTMLElementTagNameMap {
|
|
4
|
-
'mid-
|
|
4
|
+
'mid-dialog': MinidDialog;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
-
declare const
|
|
7
|
+
declare const MinidDialog_base: typeof LitElement;
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
|
-
* @event mid-show - Emitted when the
|
|
11
|
-
* @event mid-after-show - Emitted after the
|
|
12
|
-
* @event mid-hide - Emitted when the
|
|
13
|
-
* @event mid-after-hide - Emitted after the
|
|
10
|
+
* @event mid-show - Emitted when the dialog opens.
|
|
11
|
+
* @event mid-after-show - Emitted after the dialog opens and all animations are complete.
|
|
12
|
+
* @event mid-hide - Emitted when the dialog closes.
|
|
13
|
+
* @event mid-after-hide - Emitted after the dialog closes and all animations are complete.
|
|
14
14
|
* @event {{ source: 'close-button' | 'keyboard' | 'overlay' }} mid-request-close - Emitted when the user attempts to
|
|
15
|
-
* close the
|
|
15
|
+
* close the dialog by clicking the close button, clicking the overlay, or pressing escape. Calling
|
|
16
16
|
* `event.preventDefault()` will keep the dialog open. Avoid using this unless closing the dialog will result in
|
|
17
17
|
* destructive behavior such as data loss.
|
|
18
18
|
*
|
|
@@ -21,18 +21,17 @@ declare const MinidModal_base: typeof LitElement;
|
|
|
21
21
|
* @csspart body - Select the `article` element
|
|
22
22
|
* @csspart footer - Select the `footer` element
|
|
23
23
|
*
|
|
24
|
-
* @slot -- The default slot for the body content of the
|
|
24
|
+
* @slot -- The default slot for the body content of the dialog
|
|
25
25
|
* @slot heading - The content inside the `h2` element
|
|
26
26
|
* @slot footer - The content inside the `footer` element
|
|
27
27
|
*
|
|
28
|
-
* @animation
|
|
29
|
-
* @animation
|
|
30
|
-
* @animation
|
|
28
|
+
* @animation dialog.show - The animation to use when showing the dialog.
|
|
29
|
+
* @animation dialog.hide - The animation to use when hiding the dialog.
|
|
30
|
+
* @animation dialog.denyClose - The animation to use when closing the dialog is prevented.
|
|
31
31
|
*
|
|
32
32
|
*/
|
|
33
|
-
export declare class
|
|
33
|
+
export declare class MinidDialog extends MinidDialog_base {
|
|
34
34
|
dialog: HTMLDialogElement;
|
|
35
|
-
panel: HTMLElement;
|
|
36
35
|
/**
|
|
37
36
|
* Indicates whether or not the dialog is open. You can toggle this attribute to show and hide the dialog, or you can
|
|
38
37
|
* use the `show()` and `hide()` methods and this attribute will reflect the dialog's open state.
|
|
@@ -48,14 +47,14 @@ export declare class MinidModal extends MinidModal_base {
|
|
|
48
47
|
private handleBackdropClick;
|
|
49
48
|
handleOpenChange(): Promise<void>;
|
|
50
49
|
/**
|
|
51
|
-
* Shows the
|
|
50
|
+
* Shows the dialog.
|
|
52
51
|
*/
|
|
53
52
|
show(): Promise<void>;
|
|
54
53
|
/**
|
|
55
|
-
* Hides the
|
|
54
|
+
* Hides the dialog
|
|
56
55
|
*/
|
|
57
56
|
hide(): Promise<void>;
|
|
58
57
|
render(): import('lit-html').TemplateResult<1>;
|
|
59
58
|
}
|
|
60
59
|
export {};
|
|
61
|
-
//# sourceMappingURL=
|
|
60
|
+
//# sourceMappingURL=dialog.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.component.d.ts","sourceRoot":"","sources":["../../src/components/dialog.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAK5C,OAAO,uBAAuB,CAAC;AAQ/B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,YAAY,EAAE,WAAW,CAAC;KAC3B;CACF;;AAWD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBACa,WAAY,SAAQ,gBAA0B;IAEzD,MAAM,EAAG,iBAAiB,CAAC;IAE3B;;;OAGG;IAEH,IAAI,UAAS;IAEb;;;OAGG;IAEH,OAAO,SAAM;IAEb,OAAO,CAAC,YAAY;IAkBpB,kBAAkB,GAAI,OAAO,KAAK,UAQhC;IAEF,OAAO,CAAC,mBAAmB;IAQrB,gBAAgB;IA+CtB;;OAEG;IACG,IAAI;IASV;;OAEG;IACG,IAAI;IASD,MAAM;CA8BhB"}
|
|
@@ -20,45 +20,12 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
20
20
|
const styles = [
|
|
21
21
|
css`
|
|
22
22
|
:host {
|
|
23
|
-
--
|
|
24
|
-
|
|
25
|
-
display: contents;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.dialog {
|
|
29
|
-
max-width: var(--max-width);
|
|
30
|
-
max-height: unset;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.dialog[open] {
|
|
34
|
-
animation: none;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.dialog.closing::backdrop {
|
|
38
|
-
animation: fade-out 200ms ease-in forwards;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.modal-content {
|
|
42
|
-
max-height: calc(90vh - var(--footer-and-header-height));
|
|
43
|
-
overflow: auto;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.footer {
|
|
47
|
-
justify-content: flex-end;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@keyframes fade-out {
|
|
51
|
-
from {
|
|
52
|
-
opacity: 1;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
to {
|
|
56
|
-
opacity: 0;
|
|
57
|
-
}
|
|
23
|
+
--width: 40rem;
|
|
24
|
+
display: block;
|
|
58
25
|
}
|
|
59
26
|
`
|
|
60
27
|
];
|
|
61
|
-
let
|
|
28
|
+
let MinidDialog = class extends styled(LitElement, styles) {
|
|
62
29
|
constructor() {
|
|
63
30
|
super(...arguments);
|
|
64
31
|
this.open = false;
|
|
@@ -81,8 +48,8 @@ let MinidModal = class extends styled(LitElement, styles) {
|
|
|
81
48
|
});
|
|
82
49
|
this.dispatchEvent(requestCloseEvent);
|
|
83
50
|
if (requestCloseEvent.defaultPrevented) {
|
|
84
|
-
const { keyframes, options } = getAnimation(this, "
|
|
85
|
-
animateTo(this.
|
|
51
|
+
const { keyframes, options } = getAnimation(this, "dialog.denyClose");
|
|
52
|
+
animateTo(this.dialog, keyframes, options);
|
|
86
53
|
return;
|
|
87
54
|
}
|
|
88
55
|
this.hide();
|
|
@@ -99,9 +66,9 @@ let MinidModal = class extends styled(LitElement, styles) {
|
|
|
99
66
|
);
|
|
100
67
|
this.dialog.showModal();
|
|
101
68
|
lockBodyScrolling(this);
|
|
102
|
-
const panelAnimation = getAnimation(this, "
|
|
69
|
+
const panelAnimation = getAnimation(this, "dialog.show");
|
|
103
70
|
await animateTo(
|
|
104
|
-
this.
|
|
71
|
+
this.dialog,
|
|
105
72
|
panelAnimation.keyframes,
|
|
106
73
|
panelAnimation.options
|
|
107
74
|
), this.dispatchEvent(
|
|
@@ -112,16 +79,16 @@ let MinidModal = class extends styled(LitElement, styles) {
|
|
|
112
79
|
new Event("mid-hide", { bubbles: true, composed: true })
|
|
113
80
|
);
|
|
114
81
|
await Promise.all([stopAnimations(this.dialog)]);
|
|
115
|
-
const panelAnimation = getAnimation(this, "
|
|
116
|
-
this.
|
|
82
|
+
const panelAnimation = getAnimation(this, "dialog.hide");
|
|
83
|
+
this.dialog.classList.add("backdrop:animate-fade-out");
|
|
117
84
|
await animateTo(
|
|
118
|
-
this.
|
|
85
|
+
this.dialog,
|
|
119
86
|
panelAnimation.keyframes,
|
|
120
87
|
panelAnimation.options
|
|
121
88
|
);
|
|
122
|
-
this.
|
|
89
|
+
this.dialog.classList.remove("backdrop:animate-fade-out");
|
|
123
90
|
this.dialog.close();
|
|
124
|
-
this.
|
|
91
|
+
this.dialog.hidden = false;
|
|
125
92
|
unlockBodyScrolling(this);
|
|
126
93
|
this.dispatchEvent(
|
|
127
94
|
new Event("mid-after-hide", { composed: true, bubbles: true })
|
|
@@ -129,7 +96,7 @@ let MinidModal = class extends styled(LitElement, styles) {
|
|
|
129
96
|
}
|
|
130
97
|
}
|
|
131
98
|
/**
|
|
132
|
-
* Shows the
|
|
99
|
+
* Shows the dialog.
|
|
133
100
|
*/
|
|
134
101
|
async show() {
|
|
135
102
|
if (this.open) {
|
|
@@ -139,7 +106,7 @@ let MinidModal = class extends styled(LitElement, styles) {
|
|
|
139
106
|
return waitForEvent(this, "mid-after-show");
|
|
140
107
|
}
|
|
141
108
|
/**
|
|
142
|
-
* Hides the
|
|
109
|
+
* Hides the dialog
|
|
143
110
|
*/
|
|
144
111
|
async hide() {
|
|
145
112
|
if (!this.open) {
|
|
@@ -153,26 +120,26 @@ let MinidModal = class extends styled(LitElement, styles) {
|
|
|
153
120
|
<dialog
|
|
154
121
|
part="base"
|
|
155
122
|
id="dialog"
|
|
156
|
-
class="
|
|
123
|
+
class="text-body-md text-neutral m-auto max-h-[calc(100%---spacing(8))] w-(--width) max-w-[calc(100%---spacing(8))] flex-col rounded-lg p-6 shadow-xl backdrop:bg-black/50 open:flex open:animate-none"
|
|
157
124
|
@cancel=${this.handleDialogCancel}
|
|
158
125
|
@click=${this.handleBackdropClick}
|
|
159
126
|
>
|
|
160
|
-
<header part="header" class="
|
|
161
|
-
<
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
</
|
|
127
|
+
<header part="header" class="text-heading-sm flex justify-between">
|
|
128
|
+
<slot name="heading"></slot>
|
|
129
|
+
<div class="h-0">
|
|
130
|
+
<button
|
|
131
|
+
autofocus
|
|
132
|
+
@click="${() => this.requestClose("close-button")}"
|
|
133
|
+
class="text-body-md focus-visible:focus-ring text-neutral hover:bg-neutral-surface-hover float-right flex size-12 -translate-y-3 translate-x-3 items-center justify-center rounded"
|
|
134
|
+
>
|
|
135
|
+
<mid-icon class="size-6" name="xmark"></mid-icon>
|
|
136
|
+
</button>
|
|
137
|
+
</div>
|
|
171
138
|
</header>
|
|
172
|
-
<
|
|
139
|
+
<div part="body" class="overflow-auto">
|
|
173
140
|
<slot> </slot>
|
|
174
|
-
</
|
|
175
|
-
<footer part="footer"
|
|
141
|
+
</div>
|
|
142
|
+
<footer part="footer">
|
|
176
143
|
<slot name="footer"> </slot>
|
|
177
144
|
</footer>
|
|
178
145
|
</dialog>
|
|
@@ -181,41 +148,38 @@ let MinidModal = class extends styled(LitElement, styles) {
|
|
|
181
148
|
};
|
|
182
149
|
__decorateClass([
|
|
183
150
|
query("#dialog")
|
|
184
|
-
],
|
|
185
|
-
__decorateClass([
|
|
186
|
-
query(".dialog")
|
|
187
|
-
], MinidModal.prototype, "panel", 2);
|
|
151
|
+
], MinidDialog.prototype, "dialog", 2);
|
|
188
152
|
__decorateClass([
|
|
189
153
|
property({ type: Boolean, reflect: true })
|
|
190
|
-
],
|
|
154
|
+
], MinidDialog.prototype, "open", 2);
|
|
191
155
|
__decorateClass([
|
|
192
156
|
property({ reflect: true })
|
|
193
|
-
],
|
|
157
|
+
], MinidDialog.prototype, "heading", 2);
|
|
194
158
|
__decorateClass([
|
|
195
159
|
watch("open", { waitUntilFirstUpdate: true })
|
|
196
|
-
],
|
|
197
|
-
|
|
198
|
-
customElement("mid-
|
|
199
|
-
],
|
|
200
|
-
setDefaultAnimation("
|
|
160
|
+
], MinidDialog.prototype, "handleOpenChange", 1);
|
|
161
|
+
MinidDialog = __decorateClass([
|
|
162
|
+
customElement("mid-dialog")
|
|
163
|
+
], MinidDialog);
|
|
164
|
+
setDefaultAnimation("dialog.show", {
|
|
201
165
|
keyframes: [
|
|
202
166
|
{ opacity: 0, scale: 0.8 },
|
|
203
167
|
{ opacity: 1, scale: 1 }
|
|
204
168
|
],
|
|
205
169
|
options: { duration: 250, easing: "ease" }
|
|
206
170
|
});
|
|
207
|
-
setDefaultAnimation("
|
|
171
|
+
setDefaultAnimation("dialog.hide", {
|
|
208
172
|
keyframes: [
|
|
209
173
|
{ opacity: 1, scale: 1 },
|
|
210
174
|
{ opacity: 0, scale: 0.8 }
|
|
211
175
|
],
|
|
212
176
|
options: { duration: 250, easing: "ease" }
|
|
213
177
|
});
|
|
214
|
-
setDefaultAnimation("
|
|
178
|
+
setDefaultAnimation("dialog.denyClose", {
|
|
215
179
|
keyframes: [{ scale: 1 }, { scale: 1.03 }, { scale: 1 }],
|
|
216
180
|
options: { duration: 100 }
|
|
217
181
|
});
|
|
218
182
|
export {
|
|
219
|
-
|
|
183
|
+
MinidDialog
|
|
220
184
|
};
|
|
221
|
-
//# sourceMappingURL=
|
|
185
|
+
//# sourceMappingURL=dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.js","sources":["../../src/components/dialog.component.ts"],"sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { waitForEvent } from '../internal/event';\nimport { watch } from '../internal/watch';\nimport { styled } from '../mixins/tailwind.mixin';\nimport './icon/icon.component';\nimport {\n getAnimation,\n setDefaultAnimation,\n} from '../utilities/animation-registry';\nimport { animateTo, stopAnimations } from '../internal/animate';\nimport { lockBodyScrolling, unlockBodyScrolling } from '../internal/scroll';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mid-dialog': MinidDialog;\n }\n}\n\nconst styles = [\n css`\n :host {\n --width: 40rem;\n display: block;\n }\n `,\n];\n\n/**\n *\n * @event mid-show - Emitted when the dialog opens.\n * @event mid-after-show - Emitted after the dialog opens and all animations are complete.\n * @event mid-hide - Emitted when the dialog closes.\n * @event mid-after-hide - Emitted after the dialog closes and all animations are complete.\n * @event {{ source: 'close-button' | 'keyboard' | 'overlay' }} mid-request-close - Emitted when the user attempts to\n * close the dialog by clicking the close button, clicking the overlay, or pressing escape. Calling\n * `event.preventDefault()` will keep the dialog open. Avoid using this unless closing the dialog will result in\n * destructive behavior such as data loss.\n *\n * @csspart base - Select the base `dialog` element\n * @csspart header - Select the `header` element\n * @csspart body - Select the `article` element\n * @csspart footer - Select the `footer` element\n *\n * @slot -- The default slot for the body content of the dialog\n * @slot heading - The content inside the `h2` element\n * @slot footer - The content inside the `footer` element\n *\n * @animation dialog.show - The animation to use when showing the dialog.\n * @animation dialog.hide - The animation to use when hiding the dialog.\n * @animation dialog.denyClose - The animation to use when closing the dialog is prevented.\n *\n */\n@customElement('mid-dialog')\nexport class MinidDialog extends styled(LitElement, styles) {\n @query('#dialog')\n dialog!: HTMLDialogElement;\n\n /**\n * Indicates whether or not the dialog is open. You can toggle this attribute to show and hide the dialog, or you can\n * use the `show()` and `hide()` methods and this attribute will reflect the dialog's open state.\n */\n @property({ type: Boolean, reflect: true })\n open = false;\n\n /**\n * The dialog's label as displayed in the header. You should always include a relevant label even when using\n * `no-header`, as it is required for proper accessibility. If you need to display HTML, use the `label` slot instead.\n */\n @property({ reflect: true })\n heading = '';\n\n private requestClose(source: 'close-button' | 'keyboard' | 'overlay') {\n const requestCloseEvent = new CustomEvent('mid-request-close', {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail: { source },\n });\n this.dispatchEvent(requestCloseEvent);\n\n if (requestCloseEvent.defaultPrevented) {\n const { keyframes, options } = getAnimation(this, 'dialog.denyClose');\n animateTo(this.dialog, keyframes, options);\n return;\n }\n\n this.hide();\n }\n\n handleDialogCancel = (event: Event) => {\n event.preventDefault();\n\n if (event.defaultPrevented) {\n this.requestClose('keyboard');\n } else {\n this.hide();\n }\n };\n\n private handleBackdropClick({ target }: Event) {\n // if the target is the dialog, the backdrop was clicked\n if (target === this.dialog) {\n this.requestClose('overlay');\n }\n }\n\n @watch('open', { waitUntilFirstUpdate: true })\n async handleOpenChange() {\n if (this.open) {\n // Show\n this.dispatchEvent(\n new Event('mid-show', { composed: true, bubbles: true })\n );\n // this.addOpenListeners();\n this.dialog.showModal();\n\n lockBodyScrolling(this);\n\n const panelAnimation = getAnimation(this, 'dialog.show');\n await animateTo(\n this.dialog,\n panelAnimation.keyframes,\n panelAnimation.options\n ),\n this.dispatchEvent(\n new Event('mid-after-show', { bubbles: true, composed: true })\n );\n } else {\n // Hide\n this.dispatchEvent(\n new Event('mid-hide', { bubbles: true, composed: true })\n );\n\n await Promise.all([stopAnimations(this.dialog)]);\n const panelAnimation = getAnimation(this, 'dialog.hide');\n\n // The backdrop can only be animated with css because it's a pseudo element\n // so we add a animation class to trigger it at the same time as the dialog animation\n this.dialog.classList.add('backdrop:animate-fade-out');\n await animateTo(\n this.dialog,\n panelAnimation.keyframes,\n panelAnimation.options\n );\n this.dialog.classList.remove('backdrop:animate-fade-out');\n this.dialog.close();\n this.dialog.hidden = false;\n unlockBodyScrolling(this);\n this.dispatchEvent(\n new Event('mid-after-hide', { composed: true, bubbles: true })\n );\n }\n }\n\n /**\n * Shows the dialog.\n */\n async show() {\n if (this.open) {\n return undefined;\n }\n\n this.open = true;\n return waitForEvent(this, 'mid-after-show');\n }\n\n /**\n * Hides the dialog\n */\n async hide() {\n if (!this.open) {\n return undefined;\n }\n\n this.open = false;\n return waitForEvent(this, 'mid-after-hide');\n }\n\n override render() {\n return html`\n <dialog\n part=\"base\"\n id=\"dialog\"\n class=\"text-body-md text-neutral m-auto max-h-[calc(100%---spacing(8))] w-(--width) max-w-[calc(100%---spacing(8))] flex-col rounded-lg p-6 shadow-xl backdrop:bg-black/50 open:flex open:animate-none\"\n @cancel=${this.handleDialogCancel}\n @click=${this.handleBackdropClick}\n >\n <header part=\"header\" class=\"text-heading-sm flex justify-between\">\n <slot name=\"heading\"></slot>\n <div class=\"h-0\">\n <button\n autofocus\n @click=\"${() => this.requestClose('close-button')}\"\n class=\"text-body-md focus-visible:focus-ring text-neutral hover:bg-neutral-surface-hover float-right flex size-12 -translate-y-3 translate-x-3 items-center justify-center rounded\"\n >\n <mid-icon class=\"size-6\" name=\"xmark\"></mid-icon>\n </button>\n </div>\n </header>\n <div part=\"body\" class=\"overflow-auto\">\n <slot> </slot>\n </div>\n <footer part=\"footer\">\n <slot name=\"footer\"> </slot>\n </footer>\n </dialog>\n `;\n }\n}\n\nsetDefaultAnimation('dialog.show', {\n keyframes: [\n { opacity: 0, scale: 0.8 },\n { opacity: 1, scale: 1 },\n ],\n options: { duration: 250, easing: 'ease' },\n});\n\nsetDefaultAnimation('dialog.hide', {\n keyframes: [\n { opacity: 1, scale: 1 },\n { opacity: 0, scale: 0.8 },\n ],\n options: { duration: 250, easing: 'ease' },\n});\n\nsetDefaultAnimation('dialog.denyClose', {\n keyframes: [{ scale: 1 }, { scale: 1.03 }, { scale: 1 }],\n options: { duration: 100 },\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,MAAM,SAAS;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAMF;AA4BO,IAAM,cAAN,cAA0B,OAAO,YAAY,MAAM,EAAE;AAAA,EAArD,cAAA;AAAA,UAAA,GAAA,SAAA;AASE,SAAA,OAAA;AAOG,SAAA,UAAA;AAoBV,SAAA,qBAAqB,CAAC,UAA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AAQ,EAAE,sBAAsB,KAAM,CAAA;AAAA,GArDlC,YAsDL,WAAA,oBAAA,CAAA;AAtDK,cAAN,gBAAA;AAAA,EADN,cAAc,YAAY;AAAA,GACd,WAAA;AA6Jb,oBAAoB,eAAe;AAAA,EACjC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,OAAO,IAAI;AAAA,IACzB,EAAE,SAAS,GAAG,OAAO,EAAE;AAAA,EACzB;AAAA,EACA,SAAS,EAAE,UAAU,KAAK,QAAQ,OAAO;AAC3C,CAAC;AAED,oBAAoB,eAAe;AAAA,EACjC,WAAW;AAAA,IACT,EAAE,SAAS,GAAG,OAAO,EAAE;AAAA,IACvB,EAAE,SAAS,GAAG,OAAO,IAAI;AAAA,EAC3B;AAAA,EACA,SAAS,EAAE,UAAU,KAAK,QAAQ,OAAO;AAC3C,CAAC;AAED,oBAAoB,oBAAoB;AAAA,EACtC,WAAW,CAAC,EAAE,OAAO,KAAK,EAAE,OAAO,QAAQ,EAAE,OAAO,GAAG;AAAA,EACvD,SAAS,EAAE,UAAU,IAAI;AAC3B,CAAC;"}
|
|
@@ -11,8 +11,7 @@ declare const MinidDropdown_base: typeof LitElement;
|
|
|
11
11
|
* @part panel - Select the dropdown panel host element
|
|
12
12
|
*/
|
|
13
13
|
export declare class MinidDropdown extends MinidDropdown_base {
|
|
14
|
-
|
|
15
|
-
popupId: string;
|
|
14
|
+
private readonly popupId;
|
|
16
15
|
open: boolean;
|
|
17
16
|
size: 'sm' | 'md' | 'lg';
|
|
18
17
|
placement: 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'right' | 'right-start' | 'right-end' | 'left' | 'left-start' | 'left-end';
|
|
@@ -34,9 +33,9 @@ export declare class MinidDropdown extends MinidDropdown_base {
|
|
|
34
33
|
* but `fixed` can solve issues with overflow clipping
|
|
35
34
|
*/
|
|
36
35
|
hoist: boolean;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
private handleClickOutside;
|
|
37
|
+
private toggleDropdownOpen;
|
|
38
|
+
private handleAnchorClick;
|
|
40
39
|
render(): import('lit-html').TemplateResult<1>;
|
|
41
40
|
}
|
|
42
41
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown.component.d.ts","sourceRoot":"","sources":["../../src/components/dropdown.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAI5C,OAAO,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"dropdown.component.d.ts","sourceRoot":"","sources":["../../src/components/dropdown.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAI5C,OAAO,mBAAmB,CAAC;AAG3B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,cAAc,EAAE,aAAa,CAAC;KAC/B;CACF;;AAYD;;;;GAIG;AACH,qBACa,aAAc,SAAQ,kBAA0B;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAG5D,IAAI,UAAS;IAGb,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAQ;IAGhC,SAAS,EACL,KAAK,GACL,WAAW,GACX,SAAS,GACT,QAAQ,GACR,cAAc,GACd,YAAY,GACZ,OAAO,GACP,aAAa,GACb,WAAW,GACX,MAAM,GACN,YAAY,GACZ,UAAU,CAAgB;IAE9B;;OAEG;IAEH,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IAEnC;;OAEG;IAEH,QAAQ,SAAK;IAEb;;OAEG;IAEH,QAAQ,SAAK;IAGb,KAAK,UAAS;IAEd;;;OAGG;IAEH,KAAK,UAAS;IAEd,OAAO,CAAC,kBAAkB,CAIxB;IAEF,OAAO,CAAC,kBAAkB;IAyB1B,OAAO,CAAC,iBAAiB,CAKvB;IAEO,MAAM;CAgChB"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { css, LitElement, html } from "lit";
|
|
2
|
-
import {
|
|
2
|
+
import { property, customElement } from "lit/decorators.js";
|
|
3
3
|
import { ifDefined } from "lit/directives/if-defined.js";
|
|
4
4
|
import { styled } from "../mixins/tailwind.mixin.js";
|
|
5
5
|
import "./popup.js";
|
|
6
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
7
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
-
var __typeError = (msg) => {
|
|
9
|
-
throw TypeError(msg);
|
|
10
|
-
};
|
|
11
9
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
12
10
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
13
11
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -16,35 +14,18 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
16
14
|
if (kind && result) __defProp(target, key, result);
|
|
17
15
|
return result;
|
|
18
16
|
};
|
|
19
|
-
|
|
20
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), member.get(obj));
|
|
21
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
22
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
23
|
-
var _handleClickOutside, _MinidDropdown_instances, toggleDropdownOpen_fn;
|
|
24
|
-
let nextUniqueID = 0;
|
|
17
|
+
let nextUniqueId = 0;
|
|
25
18
|
const styles = [
|
|
26
19
|
css`
|
|
27
20
|
:host {
|
|
28
|
-
display: flex;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.popup {
|
|
32
|
-
--arrow-size: 8px;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.popup::part(arrow) {
|
|
36
|
-
z-index: 1501;
|
|
37
|
-
border: 1px solid #cbcbcb;
|
|
38
|
-
border-left: 0;
|
|
39
|
-
border-top: 0;
|
|
21
|
+
display: inline-flex;
|
|
40
22
|
}
|
|
41
23
|
`
|
|
42
24
|
];
|
|
43
25
|
let MinidDropdown = class extends styled(LitElement, styles) {
|
|
44
26
|
constructor() {
|
|
45
27
|
super(...arguments);
|
|
46
|
-
|
|
47
|
-
this.popupId = `mid-dropdown-${nextUniqueID++}`;
|
|
28
|
+
this.popupId = `mid-dropdown-${nextUniqueId++}`;
|
|
48
29
|
this.open = false;
|
|
49
30
|
this.size = "md";
|
|
50
31
|
this.placement = "bottom-end";
|
|
@@ -52,22 +33,48 @@ let MinidDropdown = class extends styled(LitElement, styles) {
|
|
|
52
33
|
this.skidding = 0;
|
|
53
34
|
this.arrow = false;
|
|
54
35
|
this.hoist = false;
|
|
55
|
-
|
|
36
|
+
this.handleClickOutside = (event) => {
|
|
56
37
|
if (!event.composedPath().includes(this)) {
|
|
57
|
-
|
|
38
|
+
this.toggleDropdownOpen(event, false);
|
|
58
39
|
}
|
|
59
|
-
}
|
|
40
|
+
};
|
|
60
41
|
this.handleAnchorClick = (event) => {
|
|
61
42
|
if (event.detail.id !== this.popupId) {
|
|
62
|
-
|
|
43
|
+
this.toggleDropdownOpen(event, false);
|
|
63
44
|
}
|
|
64
45
|
};
|
|
65
46
|
}
|
|
47
|
+
toggleDropdownOpen(event, open) {
|
|
48
|
+
event.stopPropagation();
|
|
49
|
+
if (open !== void 0) {
|
|
50
|
+
this.open = open;
|
|
51
|
+
} else {
|
|
52
|
+
this.open = !this.open;
|
|
53
|
+
}
|
|
54
|
+
if (this.open) {
|
|
55
|
+
addEventListener("click", this.handleClickOutside);
|
|
56
|
+
addEventListener(
|
|
57
|
+
"mid-anchor-click",
|
|
58
|
+
this.handleAnchorClick
|
|
59
|
+
);
|
|
60
|
+
} else {
|
|
61
|
+
this.blur();
|
|
62
|
+
removeEventListener(
|
|
63
|
+
"mid-anchor-click",
|
|
64
|
+
this.handleAnchorClick
|
|
65
|
+
);
|
|
66
|
+
removeEventListener("click", this.handleClickOutside);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
66
69
|
render() {
|
|
67
70
|
return html`
|
|
68
71
|
<mid-popup
|
|
69
72
|
id="${this.popupId}"
|
|
70
|
-
class="
|
|
73
|
+
class="${classMap({
|
|
74
|
+
"text-body-sm": this.size === "sm",
|
|
75
|
+
"text-body-md": this.size === "md",
|
|
76
|
+
"text-body-lg": this.size === "lg"
|
|
77
|
+
})} [--arrow-border-color:var(--border-color-neutral-subtle)] [--arrow-size:8px]"
|
|
71
78
|
distance=${this.distance}
|
|
72
79
|
placement="${this.placement}"
|
|
73
80
|
skidding=${this.skidding}
|
|
@@ -79,7 +86,7 @@ let MinidDropdown = class extends styled(LitElement, styles) {
|
|
|
79
86
|
sync=${ifDefined(this.sync)}
|
|
80
87
|
?active=${this.open}
|
|
81
88
|
?arrow=${this.arrow}
|
|
82
|
-
@click=${
|
|
89
|
+
@click=${this.toggleDropdownOpen}
|
|
83
90
|
>
|
|
84
91
|
<slot slot="anchor" name="trigger"> </slot>
|
|
85
92
|
<div
|
|
@@ -92,33 +99,6 @@ let MinidDropdown = class extends styled(LitElement, styles) {
|
|
|
92
99
|
`;
|
|
93
100
|
}
|
|
94
101
|
};
|
|
95
|
-
_handleClickOutside = /* @__PURE__ */ new WeakMap();
|
|
96
|
-
_MinidDropdown_instances = /* @__PURE__ */ new WeakSet();
|
|
97
|
-
toggleDropdownOpen_fn = function(event, open) {
|
|
98
|
-
event.stopPropagation();
|
|
99
|
-
if (open !== void 0) {
|
|
100
|
-
this.open = open;
|
|
101
|
-
} else {
|
|
102
|
-
this.open = !this.open;
|
|
103
|
-
}
|
|
104
|
-
if (this.open) {
|
|
105
|
-
addEventListener("click", __privateGet(this, _handleClickOutside));
|
|
106
|
-
addEventListener(
|
|
107
|
-
"mid-anchor-click",
|
|
108
|
-
this.handleAnchorClick
|
|
109
|
-
);
|
|
110
|
-
} else {
|
|
111
|
-
this.blur();
|
|
112
|
-
removeEventListener(
|
|
113
|
-
"mid-anchor-click",
|
|
114
|
-
this.handleAnchorClick
|
|
115
|
-
);
|
|
116
|
-
removeEventListener("click", __privateGet(this, _handleClickOutside));
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
__decorateClass([
|
|
120
|
-
state()
|
|
121
|
-
], MinidDropdown.prototype, "popupId", 2);
|
|
122
102
|
__decorateClass([
|
|
123
103
|
property({ type: Boolean, reflect: true })
|
|
124
104
|
], MinidDropdown.prototype, "open", 2);
|