From 38db96c2bb24ed80689b78b77c06806abdfb4e66 Mon Sep 17 00:00:00 2001 From: Melissa Thompson Date: Mon, 13 May 2024 13:02:26 -0400 Subject: [PATCH] docs(popover): increase chromatic coverage for tip position --- components/popover/stories/popover.stories.js | 57 ++++++++++++++++++- components/popover/stories/template.js | 36 ++++++++++++ 2 files changed, 90 insertions(+), 3 deletions(-) diff --git a/components/popover/stories/popover.stories.js b/components/popover/stories/popover.stories.js index e14d0e5f04..0f21879a50 100644 --- a/components/popover/stories/popover.stories.js +++ b/components/popover/stories/popover.stories.js @@ -1,7 +1,9 @@ +import { Template as Typography } from "@spectrum-css/typography/stories/template.js"; import { userEvent, within } from "@storybook/testing-library"; import { html } from "lit"; +import { when } from "lit/directives/when.js"; -import { Template } from "./template"; +import { SourcelessTemplate, Template } from "./template"; import { Template as ActionButton } from "@spectrum-css/actionbutton/stories/template.js"; import { Template as Menu } from "@spectrum-css/menu/stories/template.js"; @@ -125,10 +127,57 @@ export default { }, }, decorators: [ - (Story, context) => html`
${Story(context)}
` + (Story, context) => html` + +
${Story(context)}
+ `, ], }; + +const ChromaticTipPlacementVariants = (args) => html` + ${placementOptions.map(option => { + const optionDescription = () => { + if (option.startsWith("start") || option.startsWith("end")) + return "Changes side with text direction (like a logical property)"; + if (option.startsWith("left") || option.startsWith("right")) + return "Text direction does not effect the position"; + return null; + }; + + return html` +
+ ${Typography({ + semantics: "detail", + size: "l", + content: [`${option}`], + })} +
+ ${when(optionDescription() !== null, () => html` + ${Typography({ + semantics: "detail", + size: "s", + content: [`${optionDescription()}`], + })} + `)} +
+
+ ${SourcelessTemplate({ + ...args, + position: option, + })} +
+
+ `; + })} +`; + export const Default = Template.bind({}); Default.play = async ({ canvasElement }) => { const canvas = within(canvasElement); @@ -136,7 +185,9 @@ Default.play = async ({ canvasElement }) => { }; Default.args = {}; -export const WithTip = Template.bind({}); +export const WithTip = (args) => html` + ${window.isChromatic() ? ChromaticTipPlacementVariants(args) : Template(args)} +`; WithTip.play = async ({ canvasElement }) => { const canvas = within(canvasElement); await userEvent.click(canvas.getByRole("button")); diff --git a/components/popover/stories/template.js b/components/popover/stories/template.js index 6eb9366c89..48555bc9d8 100644 --- a/components/popover/stories/template.js +++ b/components/popover/stories/template.js @@ -171,3 +171,39 @@ export const Template = ({ `; }; + +export const SourcelessTemplate = ({ + rootClass = "spectrum-Popover", + size = "m", + isOpen = false, + withTip = false, + position = "top", + customClasses = [], + id = "popover-1", + testId, + customStyles = {}, + content = [], +}) => html` +
({ ...a, [c]: true }), {}), + })} + style=${ifDefined(styleMap(customStyles))} + role="presentation" + id=${ifDefined(id)} + data-testid=${ifDefined(testId)} + > + ${content.map((c) => (typeof c === "function" ? c({}) : c))} + ${withTip + ? position && ["top", "bottom"].some((e) => position.startsWith(e)) + ? html`` + : html`` + : ""} +
+`;