@nectary/components 4.6.5 → 4.6.6
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/package.json +4 -1
- package/popover/index.js +16 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nectary/components",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.6",
|
|
4
4
|
"files": [
|
|
5
5
|
"**/*/*.css",
|
|
6
6
|
"**/*/*.json",
|
|
@@ -32,5 +32,8 @@
|
|
|
32
32
|
"@types/react": "^18.2.21",
|
|
33
33
|
"babel-plugin-html-inline-minifier": "workspace:*",
|
|
34
34
|
"typescript": "^5.2.2"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@nectary/theme-base": "1.4.0"
|
|
35
38
|
}
|
|
36
39
|
}
|
package/popover/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '../pop';
|
|
2
2
|
import { defineCustomElement, getBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, updateBooleanAttribute, NectaryElement, updateAttribute, getReactEventHandler, isAttrTrue, setClass, rectOverlap, subscribeContext, isAttrEqual } from '../utils';
|
|
3
|
-
const templateHTML = '<style>:host{display:contents}#content-wrapper{position:relative;padding-top:4px}:host([tip]) #content-wrapper{padding-top:12px;filter:drop-shadow(var(--sinch-comp-popover-shadow))}:host([orientation^=top]) #content-wrapper{padding-top:0;padding-bottom:4px}:host([orientation^=top][tip]) #content-wrapper{padding-top:0;padding-bottom:12px}#content{background-color:var(--sinch-comp-popover-color-default-background-initial);border:1px solid var(--sinch-comp-popover-color-default-border-initial);border-radius:var(--sinch-comp-popover-shape-radius);box-shadow:var(--sinch-comp-popover-shadow);overflow:hidden}:host([tip]) #content{box-shadow:none}#tip{position:absolute;left:50%;top:13px;transform:translateX(-50%) rotate(180deg);transform-origin:top center;fill:var(--sinch-comp-popover-color-default-background-initial);stroke:var(--sinch-comp-popover-color-default-border-initial);stroke-linecap:square;pointer-events:none;display:none}:host([orientation^=top]) #tip{transform:translateX(-50%) rotate(0);top:calc(100% - 13px)}:host([tip]) #tip:not(.hidden){display:block}</style><sinch-pop id="pop" inset="4"><slot name="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content"><slot name="content"></slot></div><svg id="tip" width="16" height="9" aria-hidden="true"><path d="m0 0 8 8 8 -8"/></svg></div></sinch-pop>';
|
|
3
|
+
const templateHTML = '<style>:host{display:contents}#content-wrapper{position:relative;padding-top:4px;width:fit-content;min-width:100%}:host([tip]) #content-wrapper{padding-top:12px;filter:drop-shadow(var(--sinch-comp-popover-shadow))}:host([orientation^=top]) #content-wrapper{padding-top:0;padding-bottom:4px}:host([orientation^=top][tip]) #content-wrapper{padding-top:0;padding-bottom:12px}#content{background-color:var(--sinch-comp-popover-color-default-background-initial);border:1px solid var(--sinch-comp-popover-color-default-border-initial);border-radius:var(--sinch-comp-popover-shape-radius);box-shadow:var(--sinch-comp-popover-shadow);overflow:hidden}:host([tip]) #content{box-shadow:none}#tip{position:absolute;left:50%;top:13px;transform:translateX(-50%) rotate(180deg);transform-origin:top center;fill:var(--sinch-comp-popover-color-default-background-initial);stroke:var(--sinch-comp-popover-color-default-border-initial);stroke-linecap:square;pointer-events:none;display:none}:host([orientation^=top]) #tip{transform:translateX(-50%) rotate(0);top:calc(100% - 13px)}:host([tip]) #tip:not(.hidden){display:block}</style><sinch-pop id="pop" inset="4"><slot name="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content"><slot name="content"></slot></div><svg id="tip" width="16" height="9" aria-hidden="true"><path d="m0 0 8 8 8 -8"/></svg></div></sinch-pop>';
|
|
4
4
|
import { getPopOrientation, orientationValues } from './utils';
|
|
5
5
|
const TIP_SIZE = 16;
|
|
6
6
|
const template = document.createElement('template');
|
|
@@ -10,6 +10,7 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
10
10
|
#$content;
|
|
11
11
|
#$tip;
|
|
12
12
|
#controller = null;
|
|
13
|
+
#resizeObserver = null;
|
|
13
14
|
constructor() {
|
|
14
15
|
super();
|
|
15
16
|
const shadowRoot = this.attachShadow();
|
|
@@ -31,10 +32,18 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
31
32
|
});
|
|
32
33
|
subscribeContext(this.#$content, 'visibility', this.#onContextVisibility, signal);
|
|
33
34
|
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
35
|
+
this.#resizeObserver = new ResizeObserver(() => {
|
|
36
|
+
if (this.#$pop.open) {
|
|
37
|
+
this.#updateContentMaxWidth();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
this.#resizeObserver.observe(document.body);
|
|
34
41
|
}
|
|
35
42
|
disconnectedCallback() {
|
|
36
43
|
this.#controller.abort();
|
|
37
44
|
this.#controller = null;
|
|
45
|
+
this.#resizeObserver?.disconnect();
|
|
46
|
+
this.#resizeObserver = null;
|
|
38
47
|
}
|
|
39
48
|
static get observedAttributes() {
|
|
40
49
|
return ['orientation', 'open', 'modal', 'tip', 'aria-label', 'aria-description'];
|
|
@@ -119,6 +128,7 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
119
128
|
#onContextVisibility = e => {
|
|
120
129
|
if (e.detail) {
|
|
121
130
|
this.#updateTipOrientation();
|
|
131
|
+
this.#updateContentMaxWidth();
|
|
122
132
|
} else {
|
|
123
133
|
this.#resetTipOrientation();
|
|
124
134
|
}
|
|
@@ -143,4 +153,9 @@ defineCustomElement('sinch-popover', class extends NectaryElement {
|
|
|
143
153
|
this.#$tip.style.left = `${xPos}px`;
|
|
144
154
|
setClass(this.#$tip, 'hidden', rectOverlap(targetRect, contentRect));
|
|
145
155
|
};
|
|
156
|
+
#updateContentMaxWidth = () => {
|
|
157
|
+
const contentRect = this.#$content.getBoundingClientRect();
|
|
158
|
+
const availableSpace = window.innerWidth - contentRect.left - 16;
|
|
159
|
+
this.#$content.style.maxWidth = `${availableSpace}px`;
|
|
160
|
+
};
|
|
146
161
|
});
|