@nectary/components 5.1.1 → 5.1.2

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/bundle.js CHANGED
@@ -5731,6 +5731,8 @@ const orientationValues = [
5731
5731
  "top-right",
5732
5732
  "bottom-left",
5733
5733
  "bottom-right",
5734
+ "left",
5735
+ "right",
5734
5736
  "bottom",
5735
5737
  "top"
5736
5738
  ];
@@ -5741,9 +5743,15 @@ const getPopOrientation = (orientation) => {
5741
5743
  if (orientation === "bottom") {
5742
5744
  return "bottom-stretch";
5743
5745
  }
5746
+ if (orientation === "left") {
5747
+ return "center-left";
5748
+ }
5749
+ if (orientation === "right") {
5750
+ return "center-right";
5751
+ }
5744
5752
  return orientation;
5745
5753
  };
5746
- const templateHTML$K = '<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>';
5754
+ const templateHTML$K = '<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=left]) #content-wrapper{padding-top:0;padding-right:4px}:host([orientation=right]) #content-wrapper{padding-top:0;padding-left:4px}:host([orientation^=top][tip]) #content-wrapper{padding-top:0;padding-bottom:12px}:host([orientation=left][tip]) #content-wrapper{padding-top:0;padding-right:12px}:host([orientation=right][tip]) #content-wrapper{padding-top:0;padding-left: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([orientation=left]) #tip{transform:translateX(-50%) rotate(-90deg);top:calc(50%);left:calc(100% - 13px)}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:calc(50%);left: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>';
5747
5755
  const TIP_SIZE = 16;
5748
5756
  const template$K = document.createElement("template");
5749
5757
  template$K.innerHTML = templateHTML$K;
@@ -5912,16 +5920,23 @@ class Popover extends NectaryElement {
5912
5920
  const orientation = this.orientation;
5913
5921
  const targetRect = this.#$pop.footprintRect;
5914
5922
  const contentRect = this.#$content.getBoundingClientRect();
5915
- const diffX = targetRect.x - contentRect.x;
5916
- let desiredX = diffX + targetRect.width / 2;
5917
- if (orientation === "bottom-left" || orientation === "top-left") {
5918
- desiredX = Math.max(desiredX, contentRect.width * 0.75);
5919
- }
5920
- if (orientation === "bottom-right" || orientation === "top-right") {
5921
- desiredX = Math.min(desiredX, contentRect.width * 0.25);
5923
+ if (orientation.startsWith("top") || orientation.startsWith("bottom")) {
5924
+ const diffX = targetRect.x - contentRect.x;
5925
+ let desiredX = diffX + targetRect.width / 2;
5926
+ if (orientation === "bottom-left" || orientation === "top-left") {
5927
+ desiredX = Math.max(desiredX, contentRect.width * 0.75);
5928
+ }
5929
+ if (orientation === "bottom-right" || orientation === "top-right") {
5930
+ desiredX = Math.min(desiredX, contentRect.width * 0.25);
5931
+ }
5932
+ const xPos = Math.max(TIP_SIZE, Math.min(desiredX, contentRect.width - TIP_SIZE));
5933
+ this.#$tip.style.left = `${xPos}px`;
5934
+ } else if (orientation.startsWith("left") || orientation.startsWith("right")) {
5935
+ const diffY = targetRect.y - contentRect.y;
5936
+ const desiredY = diffY + targetRect.height / 2;
5937
+ const yPos = Math.max(TIP_SIZE, Math.min(desiredY, contentRect.height - TIP_SIZE));
5938
+ this.#$tip.style.top = `${yPos}px`;
5922
5939
  }
5923
- const xPos = Math.max(TIP_SIZE, Math.min(desiredX, contentRect.width - TIP_SIZE));
5924
- this.#$tip.style.left = `${xPos}px`;
5925
5940
  setClass(this.#$tip, "hidden", rectOverlap(targetRect, contentRect));
5926
5941
  };
5927
5942
  // Prevent content from overflowing the viewport
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "files": [
5
5
  "**/*/*.css",
6
6
  "**/*/*.json",
package/popover/index.js CHANGED
@@ -5,7 +5,7 @@ import { defineCustomElement, NectaryElement } from "../utils/element.js";
5
5
  import { rectOverlap } from "../utils/rect.js";
6
6
  import { getReactEventHandler } from "../utils/get-react-event-handler.js";
7
7
  import { getPopOrientation, orientationValues } from "./utils.js";
8
- 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>';
8
+ 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=left]) #content-wrapper{padding-top:0;padding-right:4px}:host([orientation=right]) #content-wrapper{padding-top:0;padding-left:4px}:host([orientation^=top][tip]) #content-wrapper{padding-top:0;padding-bottom:12px}:host([orientation=left][tip]) #content-wrapper{padding-top:0;padding-right:12px}:host([orientation=right][tip]) #content-wrapper{padding-top:0;padding-left: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([orientation=left]) #tip{transform:translateX(-50%) rotate(-90deg);top:calc(50%);left:calc(100% - 13px)}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:calc(50%);left: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>';
9
9
  const TIP_SIZE = 16;
10
10
  const template = document.createElement("template");
11
11
  template.innerHTML = templateHTML;
@@ -174,16 +174,23 @@ class Popover extends NectaryElement {
174
174
  const orientation = this.orientation;
175
175
  const targetRect = this.#$pop.footprintRect;
176
176
  const contentRect = this.#$content.getBoundingClientRect();
177
- const diffX = targetRect.x - contentRect.x;
178
- let desiredX = diffX + targetRect.width / 2;
179
- if (orientation === "bottom-left" || orientation === "top-left") {
180
- desiredX = Math.max(desiredX, contentRect.width * 0.75);
181
- }
182
- if (orientation === "bottom-right" || orientation === "top-right") {
183
- desiredX = Math.min(desiredX, contentRect.width * 0.25);
177
+ if (orientation.startsWith("top") || orientation.startsWith("bottom")) {
178
+ const diffX = targetRect.x - contentRect.x;
179
+ let desiredX = diffX + targetRect.width / 2;
180
+ if (orientation === "bottom-left" || orientation === "top-left") {
181
+ desiredX = Math.max(desiredX, contentRect.width * 0.75);
182
+ }
183
+ if (orientation === "bottom-right" || orientation === "top-right") {
184
+ desiredX = Math.min(desiredX, contentRect.width * 0.25);
185
+ }
186
+ const xPos = Math.max(TIP_SIZE, Math.min(desiredX, contentRect.width - TIP_SIZE));
187
+ this.#$tip.style.left = `${xPos}px`;
188
+ } else if (orientation.startsWith("left") || orientation.startsWith("right")) {
189
+ const diffY = targetRect.y - contentRect.y;
190
+ const desiredY = diffY + targetRect.height / 2;
191
+ const yPos = Math.max(TIP_SIZE, Math.min(desiredY, contentRect.height - TIP_SIZE));
192
+ this.#$tip.style.top = `${yPos}px`;
184
193
  }
185
- const xPos = Math.max(TIP_SIZE, Math.min(desiredX, contentRect.width - TIP_SIZE));
186
- this.#$tip.style.left = `${xPos}px`;
187
194
  setClass(this.#$tip, "hidden", rectOverlap(targetRect, contentRect));
188
195
  };
189
196
  // Prevent content from overflowing the viewport
@@ -1,5 +1,5 @@
1
1
  import type { NectaryComponentReactByType, NectaryComponentVanillaByType, TRect, NectaryComponentReact, NectaryComponentVanilla } from '../types';
2
- export type TSinchPopoverOrientation = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'bottom' | 'top';
2
+ export type TSinchPopoverOrientation = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'bottom' | 'top' | 'left' | 'right';
3
3
  export type TSinchPopoverProps = {
4
4
  /** Open/close state */
5
5
  open: boolean;
package/popover/utils.js CHANGED
@@ -3,6 +3,8 @@ const orientationValues = [
3
3
  "top-right",
4
4
  "bottom-left",
5
5
  "bottom-right",
6
+ "left",
7
+ "right",
6
8
  "bottom",
7
9
  "top"
8
10
  ];
@@ -13,6 +15,12 @@ const getPopOrientation = (orientation) => {
13
15
  if (orientation === "bottom") {
14
16
  return "bottom-stretch";
15
17
  }
18
+ if (orientation === "left") {
19
+ return "center-left";
20
+ }
21
+ if (orientation === "right") {
22
+ return "center-right";
23
+ }
16
24
  return orientation;
17
25
  };
18
26
  export {