Skip to content

Commit

Permalink
fix(popover): storybook examples have correct offset
Browse files Browse the repository at this point in the history
  • Loading branch information
mdt2 committed Oct 30, 2023
1 parent 522c248 commit 89206a2
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions components/popover/stories/template.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { html } from "lit";
import { classMap } from "lit/directives/class-map.js";
import { styleMap } from "lit/directives/style-map.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { styleMap } from "lit/directives/style-map.js";
import { when } from "lit/directives/when.js";

import { useArgs } from "@storybook/client-api";
Expand All @@ -19,7 +19,6 @@ export const Template = ({
testId,
triggerId = "trigger",
customStyles = {
"--spectrum-popover-offset": "8px",
"inset-inline-start": "0px",
"inset-block-start": "0px",
},
Expand Down Expand Up @@ -72,31 +71,31 @@ export const Template = ({
let yOffset = "+ 0px";
if (position.includes("top") || position.includes("bottom") && !(position.includes("-top") || position.includes("-bottom"))) {
x = triggerXCenter - (popWidth > 0 ? popWidth / 2 : popWidth);
}
}
if (position.includes("left") || position.includes("right")) {
y = triggerYCenter - (popHeight > 0 ? popHeight / 2 : popHeight);
}
if (position.includes("top") && !position.includes("-top")) {
y = rect.top - popHeight;
yOffset = "- var(--spectrum-popover-offset)";
yOffset = withTip ? "- (var(--spectrum-popover-offset) + var(--spectrum-popover-pointer-height))" : "- var(--spectrum-popover-offset)";
} else if (position.includes("bottom") && !position.includes("-bottom")) {
y = rect.bottom;
yOffset = "+ var(--spectrum-popover-offset)";
yOffset = "+ 0px";
} else if (position.includes("left")) {
if (textDir == 'rtl') {
x = rect.right;
xOffset = "+ var(--spectrum-popover-offset)";
xOffset = withTip ? "+ (var(--spectrum-popover-offset) + (var(--spectrum-popover-pointer-width) / 2))" : "+ var(--spectrum-popover-offset)";
} else {
x = rect.left - popWidth;
xOffset = "- var(--spectrum-popover-offset)";
xOffset = withTip ? "- (var(--spectrum-popover-offset) + (var(--spectrum-popover-pointer-width) / 2))" : "- var(--spectrum-popover-offset)";
}
} else if (position.includes("right")) {
if (textDir == 'rtl') {
x = rect.left - popWidth;
xOffset = "- var(--spectrum-popover-offset)";
xOffset = withTip ? "- (var(--spectrum-popover-offset) + (var(--spectrum-popover-pointer-width) / 2))" : "- var(--spectrum-popover-offset)";
} else {
x = rect.right;
xOffset = "+ var(--spectrum-popover-offset)";
xOffset = withTip? "+ 0px" : "+ 0px";
}
}
Expand Down

0 comments on commit 89206a2

Please sign in to comment.