Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an Info Icon for Props with a Tooltip. #403

Merged
merged 14 commits into from
Oct 10, 2023
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion e2e-tests/src/components/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { HexColor } from "@yext/studio";

export interface BannerProps {
/** banner's title */
/**
* @tooltip Banner's title
* @displayName Title
*/
title?: string;
num?: number;
bool?: boolean;
Expand Down
13 changes: 10 additions & 3 deletions e2e-tests/tests/nested-props.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { studioTest } from "./infra/studioTest.js";
studioTest("renders nested props", async ({ page, studioPage }) => {
await studioPage.addElementSection.addComponent("Banner");
await studioPage.componentTreeSection.setActiveElement("Banner");
await expect(page.getByTestId("EditorSidebar")).toHaveScreenshot({
maxDiffPixelRatio: 0.015,
});

const editorSidebar = page.getByTestId("EditorSidebar");
const expectScreenshot = async () =>
await expect(editorSidebar).toHaveScreenshot({
maxDiffPixelRatio: 0.015,
});
await expectScreenshot();

await editorSidebar.getByTestId("prop-tooltip").hover();
await expectScreenshot();
});
13 changes: 13 additions & 0 deletions e2e-tests/tsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"tagDefinitions": [
{
"tagName": "@displayName",
"syntaxKind": "modifier"
},
{
"tagName": "@tooltip",
"syntaxKind": "modifier"
}
]
}
22 changes: 7 additions & 15 deletions packages/studio-ui/src/components/PropEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
PropValueKind,
PropValueType,
} from "@yext/studio-plugin";
import { Tooltip } from "react-tooltip";
import PropInput from "./PropInput";
import useOnPropChange from "../hooks/useOnPropChange";
import { v4 } from "uuid";
import classNames from "classnames";
import { useMemo } from "react";
import TooltipIcon from "./common/TooltipIcon";

interface PropEditorProps {
propName: string;
Expand All @@ -22,8 +22,6 @@ interface PropEditorProps {
isNested?: boolean;
}

const tooltipStyle = { backgroundColor: "black" };

/**
* Renders an input editor for a single prop of a component.
*/
Expand All @@ -38,7 +36,6 @@ export default function PropEditor({
const { type, tooltip } = propMetadata;
const onChange = useOnPropChange(propKind, propName, onPropChange, type);
const uniqueId = useMemo(() => v4(), []);
const labelTooltipId = `${uniqueId}-label`;
const inputId = `${uniqueId}-input`;
const inputContainerClass = classNames({
"ml-2": isNested,
Expand All @@ -48,9 +45,12 @@ export default function PropEditor({
<div className="flex mb-2 text-sm grow flex-col">
<div className="flex relative">
{isNested && renderBranchUI()}
<label className="pb-1" id={labelTooltipId} htmlFor={inputId}>
{propName}
</label>
<div className="flex flex-row">
<label className="pb-1" htmlFor={inputId}>
{propName}
</label>
{tooltip && <TooltipIcon content={tooltip} />}
</div>
</div>
<div className={inputContainerClass}>
<PropInput
Expand All @@ -66,14 +66,6 @@ export default function PropEditor({
}}
/>
</div>
{tooltip && (
<Tooltip
style={tooltipStyle}
anchorId={labelTooltipId}
content={tooltip}
place="left"
/>
)}
</div>
);
}
Expand Down
24 changes: 24 additions & 0 deletions packages/studio-ui/src/components/common/TooltipIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useMemo } from "react";
import { Tooltip } from "react-tooltip";
import { v4 } from "uuid";
import { ReactComponent as Info } from "../../icons/info.svg";

export interface TooltipIconProps {
content: string;
}

export default function TooltipIcon({ content }: TooltipIconProps) {
const tooltipId = useMemo(() => v4(), []);

return (
<div>
<Info id={tooltipId} className="ml-3 pb-1" data-testid="prop-tooltip" />
<Tooltip
className="bg-black z-20"
anchorId={tooltipId}
content={content}
place="left"
/>
</div>
);
}
Loading