@nectary/components 2.9.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/accordion/index.d.ts +11 -0
- package/accordion/index.js +86 -0
- package/accordion/types.d.ts +21 -0
- package/accordion/types.js +1 -0
- package/accordion-item/index.d.ts +14 -0
- package/accordion-item/index.js +95 -0
- package/accordion-item/types.d.ts +36 -0
- package/accordion-item/types.js +1 -0
- package/accordion-item/utils.d.ts +2 -0
- package/accordion-item/utils.js +1 -0
- package/action-menu/index.d.ts +11 -0
- package/action-menu/index.js +195 -0
- package/action-menu/types.d.ts +13 -0
- package/action-menu/types.js +1 -0
- package/action-menu-option/index.d.ts +12 -0
- package/action-menu-option/index.js +82 -0
- package/action-menu-option/types.d.ts +23 -0
- package/action-menu-option/types.js +1 -0
- package/action-menu-option/utils.d.ts +2 -0
- package/action-menu-option/utils.js +3 -0
- package/alert/index.d.ts +14 -0
- package/alert/index.js +48 -0
- package/alert/types.d.ts +18 -0
- package/alert/types.js +1 -0
- package/alert/utils.d.ts +2 -0
- package/alert/utils.js +1 -0
- package/avatar/index.d.ts +11 -0
- package/avatar/index.js +94 -0
- package/avatar/types.d.ts +37 -0
- package/avatar/types.js +1 -0
- package/avatar/utils.d.ts +4 -0
- package/avatar/utils.js +7 -0
- package/badge/index.d.ts +11 -0
- package/badge/index.js +114 -0
- package/badge/types.d.ts +34 -0
- package/badge/types.js +1 -0
- package/badge/utils.d.ts +2 -0
- package/badge/utils.js +1 -0
- package/button/index.d.ts +11 -0
- package/button/index.js +182 -0
- package/button/types.d.ts +53 -0
- package/button/types.js +1 -0
- package/button/utils.d.ts +2 -0
- package/button/utils.js +1 -0
- package/card/index.d.ts +13 -0
- package/card/index.js +133 -0
- package/card/types.d.ts +28 -0
- package/card/types.js +1 -0
- package/card-container/index.d.ts +11 -0
- package/card-container/index.js +11 -0
- package/card-container/types.d.ts +3 -0
- package/card-container/types.js +1 -0
- package/chat/index.d.ts +11 -0
- package/chat/index.js +11 -0
- package/chat/types.d.ts +3 -0
- package/chat/types.js +1 -0
- package/chat-block/index.d.ts +11 -0
- package/chat-block/index.js +86 -0
- package/chat-block/types.d.ts +30 -0
- package/chat-block/types.js +1 -0
- package/chat-bubble/index.d.ts +11 -0
- package/chat-bubble/index.js +41 -0
- package/chat-bubble/types.d.ts +20 -0
- package/chat-bubble/types.js +1 -0
- package/chat-bubble/utils.d.ts +3 -0
- package/chat-bubble/utils.js +2 -0
- package/checkbox/index.d.ts +11 -0
- package/checkbox/index.js +126 -0
- package/checkbox/types.d.ts +49 -0
- package/checkbox/types.js +1 -0
- package/chip/index.d.ts +13 -0
- package/chip/index.js +144 -0
- package/chip/types.d.ts +37 -0
- package/chip/types.js +1 -0
- package/chip/utils.d.ts +2 -0
- package/chip/utils.js +6 -0
- package/code-tag/index.d.ts +11 -0
- package/code-tag/index.js +31 -0
- package/code-tag/types.d.ts +11 -0
- package/code-tag/types.js +1 -0
- package/color-menu/index.d.ts +11 -0
- package/color-menu/index.js +308 -0
- package/color-menu/types.d.ts +32 -0
- package/color-menu/types.js +1 -0
- package/color-menu/utils.d.ts +1 -0
- package/color-menu/utils.js +11 -0
- package/color-menu-option/index.d.ts +13 -0
- package/color-menu-option/index.js +48 -0
- package/color-menu-option/types.d.ts +11 -0
- package/color-menu-option/types.js +1 -0
- package/color-menu-option/utils.d.ts +1 -0
- package/color-menu-option/utils.js +11 -0
- package/color-swatch/index.d.ts +12 -0
- package/color-swatch/index.js +54 -0
- package/color-swatch/types.d.ts +11 -0
- package/color-swatch/types.js +1 -0
- package/color-swatch/utils.d.ts +2 -0
- package/color-swatch/utils.js +6 -0
- package/date-picker/index.d.ts +14 -0
- package/date-picker/index.js +381 -0
- package/date-picker/types.d.ts +70 -0
- package/date-picker/types.js +1 -0
- package/date-picker/utils.d.ts +28 -0
- package/date-picker/utils.js +142 -0
- package/dialog/index.d.ts +15 -0
- package/dialog/index.js +144 -0
- package/dialog/types.d.ts +28 -0
- package/dialog/types.js +1 -0
- package/dialog/utils.d.ts +2 -0
- package/dialog/utils.js +18 -0
- package/emoji/index.d.ts +11 -0
- package/emoji/index.js +46 -0
- package/emoji/types.d.ts +11 -0
- package/emoji/types.js +1 -0
- package/emoji/utils.d.ts +3 -0
- package/emoji/utils.js +47 -0
- package/emoji-picker/index.d.ts +22 -0
- package/emoji-picker/index.js +308 -0
- package/emoji-picker/types.d.ts +26 -0
- package/emoji-picker/types.js +1 -0
- package/field/index.d.ts +11 -0
- package/field/index.js +120 -0
- package/field/types.d.ts +35 -0
- package/field/types.js +1 -0
- package/file-drop/index.d.ts +13 -0
- package/file-drop/index.js +205 -0
- package/file-drop/types.d.ts +50 -0
- package/file-drop/types.js +1 -0
- package/file-drop/utils.d.ts +2 -0
- package/file-drop/utils.js +31 -0
- package/file-picker/index.d.ts +11 -0
- package/file-picker/index.js +103 -0
- package/file-picker/types.d.ts +32 -0
- package/file-picker/types.js +1 -0
- package/file-picker/utils.d.ts +1 -0
- package/file-picker/utils.js +8 -0
- package/file-status/index.d.ts +14 -0
- package/file-status/index.js +61 -0
- package/file-status/types.d.ts +18 -0
- package/file-status/types.js +1 -0
- package/file-status/utils.d.ts +2 -0
- package/file-status/utils.js +1 -0
- package/flag/index.d.ts +11 -0
- package/flag/index.js +46 -0
- package/flag/types.d.ts +11 -0
- package/flag/types.js +1 -0
- package/flag/utils.d.ts +1 -0
- package/flag/utils.js +17 -0
- package/grid/index.d.ts +11 -0
- package/grid/index.js +11 -0
- package/grid/types.d.ts +3 -0
- package/grid/types.js +1 -0
- package/grid-item/index.d.ts +11 -0
- package/grid-item/index.js +35 -0
- package/grid-item/types.d.ts +17 -0
- package/grid-item/types.js +1 -0
- package/help-tooltip/index.d.ts +13 -0
- package/help-tooltip/index.js +74 -0
- package/help-tooltip/types.d.ts +3 -0
- package/help-tooltip/types.js +1 -0
- package/horizontal-stepper/index.d.ts +11 -0
- package/horizontal-stepper/index.js +61 -0
- package/horizontal-stepper/types.d.ts +13 -0
- package/horizontal-stepper/types.js +1 -0
- package/horizontal-stepper-item/index.d.ts +14 -0
- package/horizontal-stepper-item/index.js +61 -0
- package/horizontal-stepper-item/types.d.ts +24 -0
- package/horizontal-stepper-item/types.js +1 -0
- package/horizontal-stepper-item/utils.d.ts +2 -0
- package/horizontal-stepper-item/utils.js +1 -0
- package/icon/index.d.ts +11 -0
- package/icon/index.js +32 -0
- package/icon/types.d.ts +11 -0
- package/icon/types.js +1 -0
- package/icon-button/index.d.ts +12 -0
- package/icon-button/index.js +175 -0
- package/icon-button/types.d.ts +44 -0
- package/icon-button/types.js +1 -0
- package/icon-button/utils.d.ts +2 -0
- package/icon-button/utils.js +1 -0
- package/inline-alert/index.d.ts +15 -0
- package/inline-alert/index.js +83 -0
- package/inline-alert/types.d.ts +15 -0
- package/inline-alert/types.js +1 -0
- package/inline-alert/utils.d.ts +2 -0
- package/inline-alert/utils.js +1 -0
- package/input/index.d.ts +11 -0
- package/input/index.js +642 -0
- package/input/types.d.ts +86 -0
- package/input/types.js +1 -0
- package/input/utils.d.ts +26 -0
- package/input/utils.js +302 -0
- package/link/index.d.ts +12 -0
- package/link/index.js +150 -0
- package/link/types.d.ts +59 -0
- package/link/types.js +1 -0
- package/list/index.d.ts +11 -0
- package/list/index.js +14 -0
- package/list/types.d.ts +3 -0
- package/list/types.js +1 -0
- package/list-item/index.d.ts +11 -0
- package/list-item/index.js +14 -0
- package/list-item/types.d.ts +3 -0
- package/list-item/types.js +1 -0
- package/package.json +1 -1
- package/pagination/index.d.ts +12 -0
- package/pagination/index.js +147 -0
- package/pagination/types.d.ts +16 -0
- package/pagination/types.js +1 -0
- package/pop/index.d.ts +11 -0
- package/pop/index.js +425 -0
- package/pop/types.d.ts +35 -0
- package/pop/types.js +1 -0
- package/pop/utils.d.ts +4 -0
- package/pop/utils.js +16 -0
- package/popover/index.d.ts +12 -0
- package/popover/index.js +146 -0
- package/popover/types.d.ts +38 -0
- package/popover/types.js +1 -0
- package/popover/utils.d.ts +4 -0
- package/popover/utils.js +10 -0
- package/progress/index.d.ts +12 -0
- package/progress/index.js +58 -0
- package/progress/types.d.ts +12 -0
- package/progress/types.js +1 -0
- package/progress-stepper/index.d.ts +11 -0
- package/progress-stepper/index.js +206 -0
- package/progress-stepper/types.d.ts +22 -0
- package/progress-stepper/types.js +1 -0
- package/progress-stepper-item/index.d.ts +12 -0
- package/progress-stepper-item/index.js +82 -0
- package/progress-stepper-item/types.d.ts +23 -0
- package/progress-stepper-item/types.js +1 -0
- package/progress-stepper-item/utils.d.ts +11 -0
- package/progress-stepper-item/utils.js +13 -0
- package/radio/index.d.ts +11 -0
- package/radio/index.js +154 -0
- package/radio/types.d.ts +14 -0
- package/radio/types.js +1 -0
- package/radio-option/index.d.ts +11 -0
- package/radio-option/index.js +79 -0
- package/radio-option/types.d.ts +18 -0
- package/radio-option/types.js +1 -0
- package/rich-text/index.d.ts +14 -0
- package/rich-text/index.js +75 -0
- package/rich-text/types.d.ts +12 -0
- package/rich-text/types.js +1 -0
- package/rich-text/utils.d.ts +7 -0
- package/rich-text/utils.js +107 -0
- package/rich-textarea/index.d.ts +11 -0
- package/rich-textarea/index.js +464 -0
- package/rich-textarea/types.d.ts +48 -0
- package/rich-textarea/types.js +1 -0
- package/rich-textarea/utils.d.ts +39 -0
- package/rich-textarea/utils.js +1730 -0
- package/segment/index.d.ts +12 -0
- package/segment/index.js +109 -0
- package/segment/types.d.ts +16 -0
- package/segment/types.js +1 -0
- package/segment/utils.d.ts +3 -0
- package/segment/utils.js +16 -0
- package/segment-collapse/index.d.ts +13 -0
- package/segment-collapse/index.js +60 -0
- package/segment-collapse/types.d.ts +11 -0
- package/segment-collapse/types.js +1 -0
- package/segmented-control/index.d.ts +11 -0
- package/segmented-control/index.js +85 -0
- package/segmented-control/types.d.ts +11 -0
- package/segmented-control/types.js +1 -0
- package/segmented-control-option/index.d.ts +11 -0
- package/segmented-control-option/index.js +95 -0
- package/segmented-control-option/types.d.ts +19 -0
- package/segmented-control-option/types.js +1 -0
- package/segmented-icon-control/index.d.ts +11 -0
- package/segmented-icon-control/index.js +101 -0
- package/segmented-icon-control/types.d.ts +14 -0
- package/segmented-icon-control/types.js +1 -0
- package/segmented-icon-control-option/index.d.ts +11 -0
- package/segmented-icon-control-option/index.js +82 -0
- package/segmented-icon-control-option/types.d.ts +16 -0
- package/segmented-icon-control-option/types.js +1 -0
- package/select-button/index.d.ts +13 -0
- package/select-button/index.js +202 -0
- package/select-button/types.d.ts +50 -0
- package/select-button/types.js +1 -0
- package/select-menu/index.d.ts +15 -0
- package/select-menu/index.js +339 -0
- package/select-menu/types.d.ts +41 -0
- package/select-menu/types.js +1 -0
- package/select-menu-option/index.d.ts +28 -0
- package/select-menu-option/index.js +65 -0
- package/select-menu-option/types.d.ts +26 -0
- package/select-menu-option/types.js +1 -0
- package/skeleton/index.d.ts +11 -0
- package/skeleton/index.js +108 -0
- package/skeleton/types.d.ts +9 -0
- package/skeleton/types.js +1 -0
- package/skeleton-item/index.d.ts +11 -0
- package/skeleton-item/index.js +11 -0
- package/skeleton-item/types.d.ts +13 -0
- package/skeleton-item/types.js +1 -0
- package/spinner/index.d.ts +11 -0
- package/spinner/index.js +58 -0
- package/spinner/types.d.ts +12 -0
- package/spinner/types.js +1 -0
- package/standalone.d.ts +85 -0
- package/standalone.js +87 -0
- package/stop-events/index.d.ts +1 -0
- package/stop-events/index.js +27 -0
- package/table/index.d.ts +11 -0
- package/table/index.js +14 -0
- package/table/types.d.ts +3 -0
- package/table/types.js +1 -0
- package/table-body/index.d.ts +11 -0
- package/table-body/index.js +14 -0
- package/table-body/types.d.ts +3 -0
- package/table-body/types.js +1 -0
- package/table-cell/index.d.ts +11 -0
- package/table-cell/index.js +21 -0
- package/table-cell/types.d.ts +9 -0
- package/table-cell/types.js +1 -0
- package/table-cell/utils.d.ts +2 -0
- package/table-cell/utils.js +1 -0
- package/table-head/index.d.ts +11 -0
- package/table-head/index.js +14 -0
- package/table-head/types.d.ts +3 -0
- package/table-head/types.js +1 -0
- package/table-head-cell/index.d.ts +12 -0
- package/table-head-cell/index.js +57 -0
- package/table-head-cell/types.d.ts +15 -0
- package/table-head-cell/types.js +1 -0
- package/table-row/index.d.ts +11 -0
- package/table-row/index.js +42 -0
- package/table-row/types.d.ts +11 -0
- package/table-row/types.js +1 -0
- package/tabs/index.d.ts +11 -0
- package/tabs/index.js +80 -0
- package/tabs/types.d.ts +18 -0
- package/tabs/types.js +1 -0
- package/tabs-icon-option/index.d.ts +11 -0
- package/tabs-icon-option/index.js +79 -0
- package/tabs-icon-option/types.d.ts +19 -0
- package/tabs-icon-option/types.js +1 -0
- package/tabs-option/index.d.ts +12 -0
- package/tabs-option/index.js +86 -0
- package/tabs-option/types.d.ts +25 -0
- package/tabs-option/types.js +1 -0
- package/tag/index.d.ts +12 -0
- package/tag/index.js +84 -0
- package/tag/types.d.ts +23 -0
- package/tag/types.js +1 -0
- package/tag/utils.d.ts +2 -0
- package/tag/utils.js +6 -0
- package/text/index.d.ts +11 -0
- package/text/index.js +64 -0
- package/text/types.d.ts +30 -0
- package/text/types.js +1 -0
- package/text/utils.d.ts +2 -0
- package/text/utils.js +1 -0
- package/textarea/index.d.ts +11 -0
- package/textarea/index.js +322 -0
- package/textarea/types.d.ts +60 -0
- package/textarea/types.js +1 -0
- package/tile-control/index.d.ts +11 -0
- package/tile-control/index.js +110 -0
- package/tile-control/types.d.ts +37 -0
- package/tile-control/types.js +1 -0
- package/tile-control-option/index.d.ts +11 -0
- package/tile-control-option/index.js +98 -0
- package/tile-control-option/types.d.ts +37 -0
- package/tile-control-option/types.js +1 -0
- package/time-picker/index.d.ts +15 -0
- package/time-picker/index.js +337 -0
- package/time-picker/types.d.ts +34 -0
- package/time-picker/types.js +1 -0
- package/time-picker/utils.d.ts +11 -0
- package/time-picker/utils.js +75 -0
- package/title/index.d.ts +11 -0
- package/title/index.js +60 -0
- package/title/types.d.ts +31 -0
- package/title/types.js +1 -0
- package/title/utils.d.ts +3 -0
- package/title/utils.js +17 -0
- package/toast/index.d.ts +13 -0
- package/toast/index.js +86 -0
- package/toast/types.d.ts +28 -0
- package/toast/types.js +1 -0
- package/toast/utils.d.ts +2 -0
- package/toast/utils.js +1 -0
- package/toast-manager/index.d.ts +13 -0
- package/toast-manager/index.js +170 -0
- package/toast-manager/types.d.ts +13 -0
- package/toast-manager/types.js +1 -0
- package/toast-manager/utils.d.ts +2 -0
- package/toast-manager/utils.js +1 -0
- package/toggle/index.d.ts +11 -0
- package/toggle/index.js +141 -0
- package/toggle/types.d.ts +23 -0
- package/toggle/types.js +1 -0
- package/tooltip/index.d.ts +13 -0
- package/tooltip/index.js +275 -0
- package/tooltip/tooltip-state.d.ts +19 -0
- package/tooltip/tooltip-state.js +126 -0
- package/tooltip/types.d.ts +42 -0
- package/tooltip/types.js +1 -0
- package/tooltip/utils.d.ts +6 -0
- package/tooltip/utils.js +18 -0
- package/utils/context.d.ts +20 -0
- package/utils/context.js +84 -0
- package/utils/countries.d.ts +6 -0
- package/utils/countries.js +2 -0
- package/utils/csv.d.ts +5 -0
- package/utils/csv.js +22 -0
- package/utils/debounce.d.ts +8 -0
- package/utils/debounce.js +22 -0
- package/utils/dom.d.ts +34 -0
- package/utils/dom.js +154 -0
- package/utils/element.d.ts +16 -0
- package/utils/element.js +48 -0
- package/utils/event-target.d.ts +4 -0
- package/utils/event-target.js +26 -0
- package/utils/get-react-event-handler.d.ts +1 -0
- package/utils/get-react-event-handler.js +8 -0
- package/utils/index.d.ts +12 -0
- package/utils/index.js +12 -0
- package/utils/markdown.d.ts +19 -0
- package/utils/markdown.js +143 -0
- package/utils/rect.d.ts +4 -0
- package/utils/rect.js +28 -0
- package/utils/size.d.ts +5 -0
- package/utils/size.js +3 -0
- package/utils/slot.d.ts +4 -0
- package/utils/slot.js +38 -0
- package/utils/throttle.d.ts +4 -0
- package/utils/throttle.js +20 -0
- package/utils/uid.d.ts +1 -0
- package/utils/uid.js +13 -0
- package/vertical-stepper/index.d.ts +11 -0
- package/vertical-stepper/index.js +57 -0
- package/vertical-stepper/types.d.ts +13 -0
- package/vertical-stepper/types.js +1 -0
- package/vertical-stepper-item/index.d.ts +14 -0
- package/vertical-stepper-item/index.js +61 -0
- package/vertical-stepper-item/types.d.ts +24 -0
- package/vertical-stepper-item/types.js +1 -0
- package/vertical-stepper-item/utils.d.ts +2 -0
- package/vertical-stepper-item/utils.js +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSinchListItemElement, TSinchListItemReact } from './types';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace JSX {
|
|
4
|
+
interface IntrinsicElements {
|
|
5
|
+
'sinch-list-item': TSinchListItemReact;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface HTMLElementTagNameMap {
|
|
9
|
+
'sinch-list-item': TSinchListItemElement;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineCustomElement, NectaryElement } from '../utils';
|
|
2
|
+
const templateHTML = '<style>:host{display:block;outline:0}#wrapper{width:100%;height:100%;box-sizing:border-box;overflow:hidden;padding:8px 0;background-color:var(--sinch-comp-list-color-default-background-initial);border-bottom:1px solid var(--sinch-comp-list-color-default-border-initial)}:host(:last-child)>#wrapper{border-bottom:none}:host(:hover)>#wrapper{background-color:var(--sinch-comp-list-color-default-background-hover)}</style><div id="wrapper"><slot name="content"></slot></div>';
|
|
3
|
+
const template = document.createElement('template');
|
|
4
|
+
template.innerHTML = templateHTML;
|
|
5
|
+
defineCustomElement('sinch-list-item', class extends NectaryElement {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
const shadowRoot = this.attachShadow();
|
|
9
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
10
|
+
}
|
|
11
|
+
connectedCallback() {
|
|
12
|
+
this.setAttribute('role', 'listitem');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import '../icon';
|
|
2
|
+
import type { TSinchPaginationElement, TSinchPaginationReact } from './types';
|
|
3
|
+
declare global {
|
|
4
|
+
namespace JSX {
|
|
5
|
+
interface IntrinsicElements {
|
|
6
|
+
'sinch-pagination': TSinchPaginationReact;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
interface HTMLElementTagNameMap {
|
|
10
|
+
'sinch-pagination': TSinchPaginationElement;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import '../icon';
|
|
2
|
+
import { defineCustomElement, updateAttribute, getIntegerAttribute, setClass, NectaryElement, getRect, getReactEventHandler, isTargetEqual, getTargetIndexInParent } from '../utils';
|
|
3
|
+
const templateHTML = '<style>:host{display:inline-block;vertical-align:middle;outline:0}#wrapper{display:flex;justify-content:center;gap:8px;width:100%;height:var(--sinch-local-size);--sinch-local-size:24px}button{all:initial;position:relative;display:flex;justify-content:center;align-items:center;min-width:var(--sinch-local-size);height:var(--sinch-local-size);cursor:pointer;border-radius:var(--sinch-comp-pagination-shape-radius);user-select:none;--sinch-global-color-icon:var(--sinch-comp-pagination-color-default-icon-default)}button:focus-visible::before{content:"";position:absolute;inset:-3px;border:2px solid var(--sinch-comp-pagination-color-default-outline-focus);border-radius:calc(var(--sinch-comp-pagination-shape-radius) + 3px);pointer-events:none}button:disabled{--sinch-global-color-icon:var(--sinch-comp-pagination-color-disabled-icon-initial);cursor:initial}button:enabled:hover{background-color:var(--sinch-comp-pagination-color-default-background-hover)}button>*{display:block;overflow:hidden;pointer-events:none}.page{font:var(--sinch-comp-pagination-font-default-page-number);color:var(--sinch-comp-pagination-color-default-text-initial);background-color:var(--sinch-comp-pagination-color-default-background-initial);padding:0 4px;box-sizing:border-box}.page.dots>span{display:none}.page.dots::after{content:"..."}.page.active{font:var(--sinch-comp-pagination-font-checked-page-number);background-color:var(--sinch-comp-pagination-color-checked-background-initial);pointer-events:none;cursor:initial}.page.active:hover{background-color:var(--sinch-comp-pagination-color-checked-background-hover)}.page.hidden{display:none}#left,#right{--sinch-icon-size:24px}</style><div id="wrapper"><button id="left"><sinch-icon id="icon-left" name="keyboard_arrow_left"></sinch-icon></button><button class="page"><span>1</span></button><button class="page active"><span>2</span></button><button class="page"><span>3</span></button><button class="page"><span>4</span></button><button class="page"><span>5</span></button><button class="page dots"><span>6</span></button><button class="page"><span>20</span></button><button id="right"><sinch-icon id="icon-right" name="keyboard_arrow_right"></sinch-icon></button></div>';
|
|
4
|
+
const NUM_BUTTONS = 7;
|
|
5
|
+
const MIDDLE_BTN_INDEX = Math.floor(NUM_BUTTONS / 2);
|
|
6
|
+
const FIRST_BTN_INDEX = 0;
|
|
7
|
+
const LAST_BTN_INDEX = NUM_BUTTONS - 1;
|
|
8
|
+
const DOTS_LEFT_INDEX = 1;
|
|
9
|
+
const DOTS_RIGHT_INDEX = LAST_BTN_INDEX - 1;
|
|
10
|
+
const template = document.createElement('template');
|
|
11
|
+
template.innerHTML = templateHTML;
|
|
12
|
+
defineCustomElement('sinch-pagination', class extends NectaryElement {
|
|
13
|
+
#$left;
|
|
14
|
+
#$right;
|
|
15
|
+
#$buttons;
|
|
16
|
+
#$wrapper;
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
const shadowRoot = this.attachShadow();
|
|
20
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
21
|
+
this.#$left = shadowRoot.querySelector('#left');
|
|
22
|
+
this.#$right = shadowRoot.querySelector('#right');
|
|
23
|
+
this.#$buttons = shadowRoot.querySelectorAll('.page');
|
|
24
|
+
this.#$wrapper = shadowRoot.querySelector('#wrapper');
|
|
25
|
+
}
|
|
26
|
+
connectedCallback() {
|
|
27
|
+
this.#onValueChange();
|
|
28
|
+
this.#$wrapper.addEventListener('click', this.#onButtonClick);
|
|
29
|
+
this.addEventListener('-change', this.#onChangeReactHandler);
|
|
30
|
+
}
|
|
31
|
+
disconnectedCallback() {
|
|
32
|
+
this.#$wrapper.removeEventListener('click', this.#onButtonClick);
|
|
33
|
+
this.removeEventListener('-change', this.#onChangeReactHandler);
|
|
34
|
+
}
|
|
35
|
+
static get observedAttributes() {
|
|
36
|
+
return ['max', 'value'];
|
|
37
|
+
}
|
|
38
|
+
attributeChangedCallback(name) {
|
|
39
|
+
switch (name) {
|
|
40
|
+
case 'value':
|
|
41
|
+
case 'max':
|
|
42
|
+
{
|
|
43
|
+
this.#onValueChange();
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
set value(val) {
|
|
49
|
+
updateAttribute(this, 'value', val);
|
|
50
|
+
}
|
|
51
|
+
get value() {
|
|
52
|
+
return getIntegerAttribute(this, 'value', 0);
|
|
53
|
+
}
|
|
54
|
+
set max(val) {
|
|
55
|
+
updateAttribute(this, 'max', val);
|
|
56
|
+
}
|
|
57
|
+
get max() {
|
|
58
|
+
return getIntegerAttribute(this, 'value', 0);
|
|
59
|
+
}
|
|
60
|
+
#onValueChange() {
|
|
61
|
+
const value = getIntegerAttribute(this, 'value', 0) - 1;
|
|
62
|
+
const max = Math.max(0, getIntegerAttribute(this, 'max', 0));
|
|
63
|
+
const valueOffset = Math.min(Math.max(0, value - MIDDLE_BTN_INDEX), Math.max(0, max - NUM_BUTTONS));
|
|
64
|
+
for (let i = 0; i < this.#$buttons.length; i++) {
|
|
65
|
+
const $b = this.#$buttons[i];
|
|
66
|
+
if (value < 3) {
|
|
67
|
+
setClass($b, 'active', value === i);
|
|
68
|
+
} else if (value >= max - MIDDLE_BTN_INDEX) {
|
|
69
|
+
setClass($b, 'active', i + valueOffset === value);
|
|
70
|
+
} else {
|
|
71
|
+
setClass($b, 'active', i === MIDDLE_BTN_INDEX);
|
|
72
|
+
}
|
|
73
|
+
if (max > NUM_BUTTONS) {
|
|
74
|
+
setClass($b, 'dots', i === DOTS_LEFT_INDEX && value > MIDDLE_BTN_INDEX || i === DOTS_RIGHT_INDEX && value <= max - DOTS_RIGHT_INDEX);
|
|
75
|
+
}
|
|
76
|
+
setClass($b, 'hidden', i >= max);
|
|
77
|
+
const btnText = $b.firstElementChild;
|
|
78
|
+
if (btnText != null) {
|
|
79
|
+
btnText.textContent = i === FIRST_BTN_INDEX ? '1' : i === LAST_BTN_INDEX ? String(max) : String(i + 1 + valueOffset);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const isValueBad = value < 0 || value >= max;
|
|
83
|
+
this.#$left.disabled = isValueBad || value === 0;
|
|
84
|
+
this.#$right.disabled = isValueBad || value === max - 1;
|
|
85
|
+
}
|
|
86
|
+
#onButtonClick = e => {
|
|
87
|
+
e.stopPropagation();
|
|
88
|
+
const value = Math.max(getIntegerAttribute(this, 'value', 0) - 1);
|
|
89
|
+
const max = Math.max(0, getIntegerAttribute(this, 'max', 0));
|
|
90
|
+
if (isTargetEqual(e, this.#$left)) {
|
|
91
|
+
return this.#dispatchChangeEvent(Math.max(value - 1, 0));
|
|
92
|
+
}
|
|
93
|
+
if (isTargetEqual(e, this.#$right)) {
|
|
94
|
+
return this.#dispatchChangeEvent(Math.min(value + 1, max));
|
|
95
|
+
}
|
|
96
|
+
const btnIndex = getTargetIndexInParent(e, this.#$wrapper) - 1;
|
|
97
|
+
if (btnIndex >= FIRST_BTN_INDEX && btnIndex <= LAST_BTN_INDEX) {
|
|
98
|
+
if (btnIndex === FIRST_BTN_INDEX) {
|
|
99
|
+
return this.#dispatchChangeEvent(0);
|
|
100
|
+
}
|
|
101
|
+
if (btnIndex === LAST_BTN_INDEX) {
|
|
102
|
+
return this.#dispatchChangeEvent(max);
|
|
103
|
+
}
|
|
104
|
+
if (btnIndex === DOTS_LEFT_INDEX && max > NUM_BUTTONS && value > MIDDLE_BTN_INDEX) {
|
|
105
|
+
return this.#dispatchChangeEvent(Math.floor(value / 2));
|
|
106
|
+
}
|
|
107
|
+
if (btnIndex === DOTS_RIGHT_INDEX && max > NUM_BUTTONS && value <= max - DOTS_RIGHT_INDEX) {
|
|
108
|
+
return this.#dispatchChangeEvent(Math.floor((max - value) / 2 + value));
|
|
109
|
+
}
|
|
110
|
+
return this.#dispatchChangeEvent(btnIndex + Math.min(Math.max(0, value - MIDDLE_BTN_INDEX), Math.max(0, max - NUM_BUTTONS)));
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
#clamp(value) {
|
|
114
|
+
const max = getIntegerAttribute(this, 'max', 0);
|
|
115
|
+
return Math.max(0, Math.min(max - 1, value)) + 1;
|
|
116
|
+
}
|
|
117
|
+
#dispatchChangeEvent(value) {
|
|
118
|
+
const detail = this.#clamp(value);
|
|
119
|
+
this.dispatchEvent(new CustomEvent('-change', {
|
|
120
|
+
detail
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
#onChangeReactHandler = e => {
|
|
124
|
+
getReactEventHandler(this, 'on-change')?.(e);
|
|
125
|
+
};
|
|
126
|
+
get focusable() {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
focus() {
|
|
130
|
+
this.#$left.focus();
|
|
131
|
+
}
|
|
132
|
+
blur() {
|
|
133
|
+
this.#$left.blur();
|
|
134
|
+
this.#$right.blur();
|
|
135
|
+
this.#$buttons.forEach($b => $b.blur());
|
|
136
|
+
}
|
|
137
|
+
get prevButtonRect() {
|
|
138
|
+
return getRect(this.#$left);
|
|
139
|
+
}
|
|
140
|
+
get nextButtonRect() {
|
|
141
|
+
return getRect(this.#$right);
|
|
142
|
+
}
|
|
143
|
+
nthButtonRect(index) {
|
|
144
|
+
const btn = this.#$buttons[index];
|
|
145
|
+
return btn == null ? null : getRect(btn);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TRect, TSinchElementReact } from '../types';
|
|
2
|
+
export type TSinchPaginationElement = HTMLElement & {
|
|
3
|
+
value: number;
|
|
4
|
+
max: number;
|
|
5
|
+
readonly prevButtonRect: TRect;
|
|
6
|
+
readonly nextButtonRect: TRect;
|
|
7
|
+
nthButtonRect(index: number): TRect | null;
|
|
8
|
+
addEventListener(type: '-change', listener: (e: CustomEvent<number>) => void): void;
|
|
9
|
+
setAttribute(name: 'value', value: string): void;
|
|
10
|
+
setAttribute(name: 'max', value: string): void;
|
|
11
|
+
};
|
|
12
|
+
export type TSinchPaginationReact = TSinchElementReact<TSinchPaginationElement> & {
|
|
13
|
+
value: number;
|
|
14
|
+
max: number;
|
|
15
|
+
'on-change': (e: CustomEvent<number>) => void;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/pop/index.d.ts
ADDED
package/pop/index.js
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, getRect, isAttrTrue, updateLiteralAttribute, getReactEventHandler, updateBooleanAttribute, NectaryElement, throttleAnimationFrame, isElementFocused, updateIntegerAttribute, getIntegerAttribute, getFirstFocusableElement, getFirstSlotElement, Context, subscribeContext, isTargetEqual, isAttrEqual } from '../utils';
|
|
2
|
+
const templateHTML = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:1;background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#content{position:relative;z-index:1}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
|
|
3
|
+
import { disableOverscroll, enableOverscroll, orientationValues } from './utils';
|
|
4
|
+
const template = document.createElement('template');
|
|
5
|
+
template.innerHTML = templateHTML;
|
|
6
|
+
defineCustomElement('sinch-pop', class extends NectaryElement {
|
|
7
|
+
#$targetWrapper;
|
|
8
|
+
#$focus;
|
|
9
|
+
#$dialog;
|
|
10
|
+
#resizeThrottle;
|
|
11
|
+
#$targetSlot;
|
|
12
|
+
#$targetOpenSlot;
|
|
13
|
+
#$contentSlot;
|
|
14
|
+
#$targetOpenWrapper;
|
|
15
|
+
#targetActiveElement = null;
|
|
16
|
+
#controller;
|
|
17
|
+
#keydownContext;
|
|
18
|
+
#visibilityContext;
|
|
19
|
+
#targetStyleValue = null;
|
|
20
|
+
#modalWidth = 0;
|
|
21
|
+
#modalHeight = 0;
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
const shadowRoot = this.attachShadow();
|
|
25
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
26
|
+
this.#$targetWrapper = shadowRoot.querySelector('#target');
|
|
27
|
+
this.#$focus = shadowRoot.querySelector('#focus');
|
|
28
|
+
this.#$dialog = shadowRoot.querySelector('#dialog');
|
|
29
|
+
this.#$targetSlot = shadowRoot.querySelector('slot[name="target"]');
|
|
30
|
+
this.#$targetOpenSlot = shadowRoot.querySelector('slot[name="target-open"]');
|
|
31
|
+
this.#$contentSlot = shadowRoot.querySelector('slot[name="content"]');
|
|
32
|
+
this.#$targetOpenWrapper = shadowRoot.querySelector('#target-open');
|
|
33
|
+
this.#resizeThrottle = throttleAnimationFrame(this.#updateOrientation);
|
|
34
|
+
this.#keydownContext = new Context(this.#$contentSlot, 'keydown');
|
|
35
|
+
this.#visibilityContext = new Context(this.#$contentSlot, 'visibility');
|
|
36
|
+
this.#controller = new AbortController();
|
|
37
|
+
}
|
|
38
|
+
connectedCallback() {
|
|
39
|
+
super.connectedCallback();
|
|
40
|
+
if (this.#controller === null) {
|
|
41
|
+
this.#controller = new AbortController();
|
|
42
|
+
}
|
|
43
|
+
const {
|
|
44
|
+
signal
|
|
45
|
+
} = this.#controller;
|
|
46
|
+
this.#keydownContext.listen(signal);
|
|
47
|
+
this.#visibilityContext.listen(signal);
|
|
48
|
+
this.role = 'dialog';
|
|
49
|
+
this.#$dialog.addEventListener('cancel', this.#onCancel, {
|
|
50
|
+
signal
|
|
51
|
+
});
|
|
52
|
+
this.#$dialog.addEventListener('mousedown', this.#onBackdropMouseDown, {
|
|
53
|
+
signal
|
|
54
|
+
});
|
|
55
|
+
this.addEventListener('-close', this.#onCloseReactHandler, {
|
|
56
|
+
signal
|
|
57
|
+
});
|
|
58
|
+
subscribeContext(this, 'visibility', this.#onContextVisibility, signal);
|
|
59
|
+
if (getBooleanAttribute(this, 'open')) {
|
|
60
|
+
this.#onExpand();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
disconnectedCallback() {
|
|
64
|
+
super.disconnectedCallback();
|
|
65
|
+
this.#controller.abort();
|
|
66
|
+
this.#controller = null;
|
|
67
|
+
this.#resizeThrottle.cancel();
|
|
68
|
+
this.#onCollapse();
|
|
69
|
+
}
|
|
70
|
+
static get observedAttributes() {
|
|
71
|
+
return ['orientation', 'open'];
|
|
72
|
+
}
|
|
73
|
+
set modal(isModal) {
|
|
74
|
+
updateBooleanAttribute(this, 'modal', isModal);
|
|
75
|
+
}
|
|
76
|
+
get modal() {
|
|
77
|
+
return getBooleanAttribute(this, 'modal');
|
|
78
|
+
}
|
|
79
|
+
set open(isOpen) {
|
|
80
|
+
updateBooleanAttribute(this, 'open', isOpen);
|
|
81
|
+
}
|
|
82
|
+
get open() {
|
|
83
|
+
return getBooleanAttribute(this, 'open');
|
|
84
|
+
}
|
|
85
|
+
get orientation() {
|
|
86
|
+
return getLiteralAttribute(this, orientationValues, 'orientation');
|
|
87
|
+
}
|
|
88
|
+
set orientation(value) {
|
|
89
|
+
updateLiteralAttribute(this, orientationValues, 'orientation', value);
|
|
90
|
+
}
|
|
91
|
+
set inset(inset) {
|
|
92
|
+
updateIntegerAttribute(this, 'inset', inset);
|
|
93
|
+
}
|
|
94
|
+
get inset() {
|
|
95
|
+
return getIntegerAttribute(this, 'inset', 0);
|
|
96
|
+
}
|
|
97
|
+
get footprintRect() {
|
|
98
|
+
return this.#getTargetRect();
|
|
99
|
+
}
|
|
100
|
+
get popoverRect() {
|
|
101
|
+
return getRect(this.#$dialog);
|
|
102
|
+
}
|
|
103
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
104
|
+
if (isAttrEqual(oldVal, newVal)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
switch (name) {
|
|
108
|
+
case 'open':
|
|
109
|
+
{
|
|
110
|
+
const shouldOpen = isAttrTrue(newVal);
|
|
111
|
+
if (shouldOpen) {
|
|
112
|
+
requestAnimationFrame(() => {
|
|
113
|
+
if (this.isDomConnected && getBooleanAttribute(this, 'open')) {
|
|
114
|
+
this.#onExpand();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
this.#onCollapse();
|
|
119
|
+
}
|
|
120
|
+
updateBooleanAttribute(this, 'open', shouldOpen);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case 'orientation':
|
|
124
|
+
{
|
|
125
|
+
if (this.#$dialog.open) {
|
|
126
|
+
this.#updateOrientation();
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
#getTargetRect() {
|
|
133
|
+
let item = getFirstSlotElement(this.#$targetSlot, true);
|
|
134
|
+
if (item === null && this.#$dialog.open) {
|
|
135
|
+
item = getFirstSlotElement(this.#$targetOpenSlot, true);
|
|
136
|
+
}
|
|
137
|
+
if (item === null) {
|
|
138
|
+
return getRect(this.#$targetWrapper);
|
|
139
|
+
}
|
|
140
|
+
if (Reflect.has(item, 'footprintRect')) {
|
|
141
|
+
return item.footprintRect;
|
|
142
|
+
}
|
|
143
|
+
return getRect(item);
|
|
144
|
+
}
|
|
145
|
+
#getFirstTargetElement(slot) {
|
|
146
|
+
const item = getFirstSlotElement(slot, true);
|
|
147
|
+
if (item === null) {
|
|
148
|
+
return this.#$targetWrapper;
|
|
149
|
+
}
|
|
150
|
+
return item;
|
|
151
|
+
}
|
|
152
|
+
#onExpand() {
|
|
153
|
+
if (!this.isDomConnected || this.#$dialog.open) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this.#$targetSlot.addEventListener('blur', this.#stopEventPropagation, true);
|
|
157
|
+
this.#$focus.setAttribute('tabindex', '-1');
|
|
158
|
+
this.#$focus.style.display = 'block';
|
|
159
|
+
this.#$focus.addEventListener('focus', this.#captureRelatedActiveElement);
|
|
160
|
+
this.#$focus.focus();
|
|
161
|
+
this.#$focus.removeEventListener('focus', this.#captureRelatedActiveElement);
|
|
162
|
+
this.#$targetSlot.removeEventListener('blur', this.#stopEventPropagation, true);
|
|
163
|
+
this.#$focus.removeAttribute('tabindex');
|
|
164
|
+
this.#$focus.removeAttribute('style');
|
|
165
|
+
this.#$dialog.showModal();
|
|
166
|
+
this.#$targetWrapper.setAttribute('aria-expanded', 'true');
|
|
167
|
+
this.#updateOrientation();
|
|
168
|
+
if (this.modal) {
|
|
169
|
+
getFirstFocusableElement(this.#$contentSlot)?.focus();
|
|
170
|
+
} else {
|
|
171
|
+
const $targetEl = this.#getFirstTargetElement(this.#$targetSlot);
|
|
172
|
+
const targetElComputedStyle = getComputedStyle($targetEl);
|
|
173
|
+
const marginLeft = parseInt(targetElComputedStyle.marginLeft);
|
|
174
|
+
const marginRight = parseInt(targetElComputedStyle.marginRight);
|
|
175
|
+
const marginTop = parseInt(targetElComputedStyle.marginTop);
|
|
176
|
+
const marginBottom = parseInt(targetElComputedStyle.marginBottom);
|
|
177
|
+
const targetRect = this.#getTargetRect();
|
|
178
|
+
this.#$targetWrapper.style.setProperty('display', 'block');
|
|
179
|
+
this.#$targetWrapper.style.setProperty('width', `${targetRect.width + marginLeft + marginRight}px`);
|
|
180
|
+
this.#$targetWrapper.style.setProperty('height', `${targetRect.height + marginTop + marginBottom}px`);
|
|
181
|
+
this.#$targetOpenWrapper.style.setProperty('width', `${targetRect.width}px`);
|
|
182
|
+
this.#$targetOpenWrapper.style.setProperty('height', `${targetRect.height}px`);
|
|
183
|
+
this.#targetStyleValue = $targetEl.getAttribute('style');
|
|
184
|
+
$targetEl.style.setProperty('margin', '0');
|
|
185
|
+
$targetEl.style.setProperty('position', 'static');
|
|
186
|
+
if (targetElComputedStyle.transform !== 'none') {
|
|
187
|
+
const matrix = new DOMMatrixReadOnly(targetElComputedStyle.transform);
|
|
188
|
+
$targetEl.style.setProperty('transform', matrix.translate(-matrix.e, -matrix.f).toString());
|
|
189
|
+
}
|
|
190
|
+
getFirstSlotElement(this.#$targetSlot)?.setAttribute('slot', 'target-open');
|
|
191
|
+
this.#$targetOpenSlot.addEventListener('keydown', this.#onTargetKeydown);
|
|
192
|
+
if (this.#targetActiveElement !== null) {
|
|
193
|
+
this.#$targetOpenSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
|
194
|
+
this.#targetActiveElement.focus();
|
|
195
|
+
this.#$targetOpenSlot.removeEventListener('focus', this.#stopEventPropagation, true);
|
|
196
|
+
if (!isElementFocused(this.#targetActiveElement)) {
|
|
197
|
+
requestAnimationFrame(() => {
|
|
198
|
+
if (this.isDomConnected && this.#$dialog.open) {
|
|
199
|
+
this.#$targetOpenSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
|
200
|
+
this.#targetActiveElement.focus();
|
|
201
|
+
this.#$targetOpenSlot.removeEventListener('focus', this.#stopEventPropagation, true);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
disableOverscroll();
|
|
208
|
+
window.addEventListener('scroll', this.#updatePosition, {
|
|
209
|
+
passive: false
|
|
210
|
+
});
|
|
211
|
+
window.addEventListener('resize', this.#onResize);
|
|
212
|
+
requestAnimationFrame(() => {
|
|
213
|
+
if (this.isDomConnected && this.#$dialog.open) {
|
|
214
|
+
this.#$contentSlot.addEventListener('slotchange', this.#onContentSlotChange);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
this.#dispatchContentVisibility(true);
|
|
218
|
+
}
|
|
219
|
+
#onCollapse() {
|
|
220
|
+
if (!this.#$dialog.open) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const isNonModal = !this.modal;
|
|
224
|
+
this.#dispatchContentVisibility(false);
|
|
225
|
+
this.#$targetOpenSlot.removeEventListener('keydown', this.#onTargetKeydown);
|
|
226
|
+
if (isNonModal) {
|
|
227
|
+
this.#$targetOpenSlot.addEventListener('blur', this.#captureActiveElement, true);
|
|
228
|
+
}
|
|
229
|
+
this.#$dialog.close();
|
|
230
|
+
this.#$targetWrapper.setAttribute('aria-expanded', 'false');
|
|
231
|
+
if (isNonModal) {
|
|
232
|
+
this.#$targetOpenSlot.removeEventListener('blur', this.#captureActiveElement, true);
|
|
233
|
+
}
|
|
234
|
+
if (isNonModal) {
|
|
235
|
+
const targetEl = this.#getFirstTargetElement(this.#$targetOpenSlot);
|
|
236
|
+
targetEl.style.removeProperty('margin');
|
|
237
|
+
targetEl.style.removeProperty('position');
|
|
238
|
+
targetEl.style.removeProperty('transform');
|
|
239
|
+
if (this.#targetStyleValue !== null) {
|
|
240
|
+
targetEl.setAttribute('style', this.#targetStyleValue);
|
|
241
|
+
this.#targetStyleValue = null;
|
|
242
|
+
}
|
|
243
|
+
getFirstSlotElement(this.#$targetOpenSlot)?.setAttribute('slot', 'target');
|
|
244
|
+
this.#$targetWrapper.style.removeProperty('display');
|
|
245
|
+
this.#$targetWrapper.style.removeProperty('width');
|
|
246
|
+
this.#$targetWrapper.style.removeProperty('height');
|
|
247
|
+
}
|
|
248
|
+
if (this.#targetActiveElement !== null) {
|
|
249
|
+
if (!isElementFocused(this.#targetActiveElement)) {
|
|
250
|
+
this.#$targetSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
|
251
|
+
this.#targetActiveElement.focus({
|
|
252
|
+
preventScroll: true
|
|
253
|
+
});
|
|
254
|
+
this.#$targetSlot.removeEventListener('focus', this.#stopEventPropagation, true);
|
|
255
|
+
if (!isElementFocused(this.#targetActiveElement)) {
|
|
256
|
+
const $targetEl = this.#targetActiveElement;
|
|
257
|
+
requestAnimationFrame(() => {
|
|
258
|
+
if (this.isDomConnected && !this.#$dialog.open) {
|
|
259
|
+
this.#$targetSlot.addEventListener('focus', this.#stopEventPropagation, true);
|
|
260
|
+
$targetEl.focus({
|
|
261
|
+
preventScroll: true
|
|
262
|
+
});
|
|
263
|
+
this.#$targetSlot.removeEventListener('focus', this.#stopEventPropagation, true);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
this.#targetActiveElement = null;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
enableOverscroll();
|
|
271
|
+
this.#resizeThrottle.cancel();
|
|
272
|
+
window.removeEventListener('resize', this.#onResize);
|
|
273
|
+
window.removeEventListener('scroll', this.#updatePosition);
|
|
274
|
+
this.#$contentSlot.removeEventListener('slotchange', this.#onContentSlotChange);
|
|
275
|
+
}
|
|
276
|
+
#onResize = () => {
|
|
277
|
+
this.#resizeThrottle.fn();
|
|
278
|
+
};
|
|
279
|
+
#updatePosition = () => {
|
|
280
|
+
const targetRect = this.modal ? this.#getTargetRect() : this.#$targetWrapper.getBoundingClientRect();
|
|
281
|
+
const orient = this.orientation;
|
|
282
|
+
const modalWidth = this.#modalWidth;
|
|
283
|
+
const modalHeight = this.#modalHeight;
|
|
284
|
+
const inset = this.inset;
|
|
285
|
+
let xPos = 0;
|
|
286
|
+
let yPos = 0;
|
|
287
|
+
if (orient === 'bottom-right' || orient === 'top-right' || orient === 'top-stretch' || orient === 'bottom-stretch') {
|
|
288
|
+
xPos = targetRect.x;
|
|
289
|
+
}
|
|
290
|
+
if (orient === 'bottom-left' || orient === 'top-left') {
|
|
291
|
+
xPos = targetRect.x + targetRect.width - modalWidth;
|
|
292
|
+
}
|
|
293
|
+
if (orient === 'bottom-center' || orient === 'top-center') {
|
|
294
|
+
xPos = targetRect.x + targetRect.width / 2 - modalWidth / 2;
|
|
295
|
+
}
|
|
296
|
+
if (orient === 'center-right') {
|
|
297
|
+
xPos = targetRect.x + targetRect.width;
|
|
298
|
+
}
|
|
299
|
+
if (orient === 'center-left') {
|
|
300
|
+
xPos = targetRect.x - modalWidth;
|
|
301
|
+
}
|
|
302
|
+
if (orient === 'bottom-left' || orient === 'bottom-right' || orient === 'bottom-stretch' || orient === 'bottom-center') {
|
|
303
|
+
yPos = targetRect.y + targetRect.height;
|
|
304
|
+
}
|
|
305
|
+
if (orient === 'top-left' || orient === 'top-right' || orient === 'top-stretch' || orient === 'top-center') {
|
|
306
|
+
yPos = targetRect.y - modalHeight;
|
|
307
|
+
}
|
|
308
|
+
if (orient === 'center-left' || orient === 'center-right') {
|
|
309
|
+
yPos = targetRect.y + targetRect.height / 2 - modalHeight / 2;
|
|
310
|
+
}
|
|
311
|
+
const clampedXPos = Math.max(inset, Math.min(xPos, window.innerWidth - modalWidth - inset));
|
|
312
|
+
const clampedYPos = Math.max(inset, Math.min(yPos, window.innerHeight - modalHeight - inset));
|
|
313
|
+
this.#$dialog.style.setProperty('left', `${clampedXPos}px`);
|
|
314
|
+
this.#$dialog.style.setProperty('top', `${clampedYPos}px`);
|
|
315
|
+
if (!this.modal) {
|
|
316
|
+
const targetLeftPos = targetRect.x - clampedXPos;
|
|
317
|
+
const targetTopPos = targetRect.y - clampedYPos;
|
|
318
|
+
this.#$targetOpenWrapper.style.setProperty('left', `${targetLeftPos}px`);
|
|
319
|
+
this.#$targetOpenWrapper.style.setProperty('top', `${targetTopPos}px`);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
#updateOrientation = () => {
|
|
323
|
+
this.#$dialog.style.setProperty('width', 'max-content');
|
|
324
|
+
const targetRect = this.#getTargetRect();
|
|
325
|
+
const modalRect = this.#$dialog.getBoundingClientRect();
|
|
326
|
+
const orient = this.orientation;
|
|
327
|
+
const shouldSetWidthToTarget = orient === 'top-stretch' || orient === 'bottom-stretch';
|
|
328
|
+
const modalHeight = modalRect.height;
|
|
329
|
+
const modalWidth = shouldSetWidthToTarget ? targetRect.width : modalRect.width;
|
|
330
|
+
const inset = this.inset;
|
|
331
|
+
let xPos = 0;
|
|
332
|
+
let yPos = 0;
|
|
333
|
+
this.#modalHeight = modalHeight;
|
|
334
|
+
this.#modalWidth = modalWidth;
|
|
335
|
+
if (orient === 'bottom-right' || orient === 'top-right' || orient === 'top-stretch' || orient === 'bottom-stretch') {
|
|
336
|
+
xPos = targetRect.x;
|
|
337
|
+
}
|
|
338
|
+
if (orient === 'bottom-left' || orient === 'top-left') {
|
|
339
|
+
xPos = targetRect.x + targetRect.width - modalWidth;
|
|
340
|
+
}
|
|
341
|
+
if (orient === 'bottom-center' || orient === 'top-center') {
|
|
342
|
+
xPos = targetRect.x + targetRect.width / 2 - modalWidth / 2;
|
|
343
|
+
}
|
|
344
|
+
if (orient === 'center-right') {
|
|
345
|
+
xPos = targetRect.x + targetRect.width;
|
|
346
|
+
}
|
|
347
|
+
if (orient === 'center-left') {
|
|
348
|
+
xPos = targetRect.x - modalWidth;
|
|
349
|
+
}
|
|
350
|
+
if (orient === 'bottom-left' || orient === 'bottom-right' || orient === 'bottom-stretch' || orient === 'bottom-center') {
|
|
351
|
+
yPos = targetRect.y + targetRect.height;
|
|
352
|
+
}
|
|
353
|
+
if (orient === 'top-left' || orient === 'top-right' || orient === 'top-stretch' || orient === 'top-center') {
|
|
354
|
+
yPos = targetRect.y - modalHeight;
|
|
355
|
+
}
|
|
356
|
+
if (orient === 'center-left' || orient === 'center-right') {
|
|
357
|
+
yPos = targetRect.y + targetRect.height / 2 - modalHeight / 2;
|
|
358
|
+
}
|
|
359
|
+
xPos = Math.round(Math.max(inset, Math.min(xPos, window.innerWidth - modalWidth - inset)));
|
|
360
|
+
yPos = Math.round(Math.max(inset, Math.min(yPos, window.innerHeight - modalHeight - inset)));
|
|
361
|
+
this.#$dialog.style.setProperty('left', `${xPos}px`);
|
|
362
|
+
this.#$dialog.style.setProperty('top', `${yPos}px`);
|
|
363
|
+
this.#$dialog.style.setProperty('width', `${modalWidth}px`);
|
|
364
|
+
if (!this.modal) {
|
|
365
|
+
const targetLeftPos = targetRect.x - xPos;
|
|
366
|
+
const targetTopPos = targetRect.y - yPos;
|
|
367
|
+
this.#$targetOpenWrapper.style.setProperty('left', `${targetLeftPos}px`);
|
|
368
|
+
this.#$targetOpenWrapper.style.setProperty('top', `${targetTopPos}px`);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
#onBackdropMouseDown = e => {
|
|
372
|
+
if (isTargetEqual(e, this.#$dialog)) {
|
|
373
|
+
const rect = this.popoverRect;
|
|
374
|
+
const isInside = e.x >= rect.x && e.x < rect.x + rect.width && e.y >= rect.y && e.y < rect.y + rect.height;
|
|
375
|
+
if (!isInside) {
|
|
376
|
+
e.stopPropagation();
|
|
377
|
+
this.#dispatchCloseEvent();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
#onCancel = e => {
|
|
382
|
+
e.preventDefault();
|
|
383
|
+
e.stopPropagation();
|
|
384
|
+
this.#dispatchCloseEvent();
|
|
385
|
+
};
|
|
386
|
+
#onCloseReactHandler = e => {
|
|
387
|
+
getReactEventHandler(this, 'on-close')?.(e);
|
|
388
|
+
};
|
|
389
|
+
#dispatchCloseEvent() {
|
|
390
|
+
this.dispatchEvent(new CustomEvent('-close'));
|
|
391
|
+
}
|
|
392
|
+
#captureRelatedActiveElement = e => {
|
|
393
|
+
e.stopPropagation();
|
|
394
|
+
this.#targetActiveElement = e.relatedTarget;
|
|
395
|
+
};
|
|
396
|
+
#captureActiveElement = e => {
|
|
397
|
+
e.stopPropagation();
|
|
398
|
+
this.#targetActiveElement = e.target;
|
|
399
|
+
};
|
|
400
|
+
#stopEventPropagation = e => {
|
|
401
|
+
e.stopPropagation();
|
|
402
|
+
};
|
|
403
|
+
#dispatchContentVisibility(isVisible) {
|
|
404
|
+
this.#visibilityContext.dispatch(isVisible);
|
|
405
|
+
}
|
|
406
|
+
#onTargetKeydown = e => {
|
|
407
|
+
this.#keydownContext.dispatch({
|
|
408
|
+
code: e.code,
|
|
409
|
+
preventDefault: () => {
|
|
410
|
+
e.preventDefault();
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
#onContextVisibility = e => {
|
|
415
|
+
if (!e.detail) {
|
|
416
|
+
this.#dispatchCloseEvent();
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
#onContentSlotChange = e => {
|
|
420
|
+
e.stopPropagation();
|
|
421
|
+
if (this.#$dialog.open) {
|
|
422
|
+
this.#updateOrientation();
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
});
|