Skip to content

Commit

Permalink
fix: fix useInstillForm field's description tooltip break words issue (
Browse files Browse the repository at this point in the history
…#937)

Because

- The fields of useInstillForm are using the same tooltip to show
complicated description, there break-words rule is not correct
- close https://github.com/instill-ai/community/issues/533

This commit

- fix useInstillForm field's description tooltip break words issue
  • Loading branch information
EiffelFly committed Feb 5, 2024
1 parent d70120f commit 6e43839
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 290 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Icons, ParagraphWithHTML, Tooltip } from "@instill-ai/design-system";
import { Nullable } from "../../../type";

export const FieldDescriptionTooltip = ({
description,
}: {
description: Nullable<string>;
}) => {
return description ? (
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Icons.HelpCircle className="my-auto h-[14px] w-[14px] cursor-pointer stroke-semantic-fg-secondary" />
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content className="w-[360px]" sideOffset={5} side="top">
<div className="!rounded-sm !bg-semantic-bg-primary !px-3 !py-2">
<ParagraphWithHTML
text={description}
className="break-words text-semantic-fg-primary product-body-text-4-semibold"
/>
</div>
<Tooltip.Arrow
className="fill-white"
offset={5}
width={9}
height={6}
/>
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
) : null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./FieldDescriptionTooltip";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Form, Icons, Switch, Tooltip } from "@instill-ai/design-system";
import { ParagraphWithHTML } from "@instill-ai/design-system";
import { Form, Switch } from "@instill-ai/design-system";
import type { AutoFormFieldBaseProps } from "../../type";
import { FieldDescriptionTooltip } from "../common";

export const BooleanField = ({
form,
Expand Down Expand Up @@ -29,35 +29,7 @@ export const BooleanField = ({
>
{title}
</Form.Label>
{description ? (
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Icons.HelpCircle className="my-auto h-[14px] w-[14px] cursor-pointer stroke-semantic-fg-secondary" />
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content
className="w-[360px]"
sideOffset={5}
side="top"
>
<div className="!rounded-sm !bg-semantic-bg-primary !px-3 !py-2">
<ParagraphWithHTML
text={description}
className="break-all text-semantic-fg-primary product-body-text-4-semibold"
/>
</div>
<Tooltip.Arrow
className="fill-white"
offset={5}
width={9}
height={6}
/>
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
) : null}
<FieldDescriptionTooltip description={description} />
</div>
<Form.Control>
<Switch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import cn from "clsx";
import * as React from "react";
import {
Form,
Icons,
Input,
ParagraphWithHTML,
Tooltip,
} from "@instill-ai/design-system";
import { Form, Input } from "@instill-ai/design-system";
import { AutoFormFieldBaseProps } from "../../type";
import { FieldDescriptionTooltip } from "../common";

export const CredentialTextField = ({
form,
Expand Down Expand Up @@ -38,35 +33,7 @@ export const CredentialTextField = ({
>
{title}
</Form.Label>
{description ? (
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Icons.HelpCircle className="my-auto h-[14px] w-[14px] cursor-pointer stroke-semantic-fg-secondary" />
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content
className="w-[360px]"
sideOffset={5}
side="top"
>
<div className="!rounded-sm !bg-semantic-bg-primary !px-3 !py-2">
<ParagraphWithHTML
text={description}
className="break-all text-semantic-fg-primary product-body-text-4-semibold"
/>
</div>
<Tooltip.Arrow
className="fill-white"
offset={5}
width={9}
height={6}
/>
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
) : null}
<FieldDescriptionTooltip description={description} />
</div>
<Form.Control>
<Input.Root>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import cn from "clsx";
import {
Form,
Icons,
ParagraphWithHTML,
Select,
Tooltip,
} from "@instill-ai/design-system";
import { Form, Select } from "@instill-ai/design-system";
import * as React from "react";
import { recursivelyResetFormData } from "../../transform";
import { Nullable } from "../../../type";
Expand All @@ -14,6 +8,7 @@ import {
InstillFormTree,
SelectedConditionMap,
} from "../../type";
import { FieldDescriptionTooltip } from "../common";

export const OneOfConditionField = ({
form,
Expand Down Expand Up @@ -84,35 +79,7 @@ export const OneOfConditionField = ({
>
{title}
</Form.Label>
{description ? (
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Icons.HelpCircle className="my-auto h-[14px] w-[14px] cursor-pointer stroke-semantic-fg-secondary" />
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content
className="w-[360px]"
sideOffset={5}
side="top"
>
<div className="!rounded-sm !bg-semantic-bg-primary !px-3 !py-2">
<ParagraphWithHTML
text={description}
className="break-all text-semantic-fg-primary product-body-text-4-semibold"
/>
</div>
<Tooltip.Arrow
className="fill-white"
offset={5}
width={9}
height={6}
/>
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
) : null}
<FieldDescriptionTooltip description={description} />
</div>
<Select.Root
onValueChange={(event) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import cn from "clsx";
import {
Form,
Icons,
ParagraphWithHTML,
Select,
Tooltip,
} from "@instill-ai/design-system";
import { Form, Select } from "@instill-ai/design-system";
import { AutoFormFieldBaseProps } from "../../type";
import { FieldDescriptionTooltip } from "../common";

export const SingleSelectField = ({
form,
Expand Down Expand Up @@ -37,35 +32,7 @@ export const SingleSelectField = ({
>
{title}
</Form.Label>
{description ? (
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Icons.HelpCircle className="my-auto h-[14px] w-[14px] cursor-pointer stroke-semantic-fg-secondary" />
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content
className="w-[360px]"
sideOffset={5}
side="top"
>
<div className="!rounded-sm !bg-semantic-bg-primary !px-3 !py-2">
<ParagraphWithHTML
text={description}
className="break-all text-semantic-fg-primary product-body-text-4-semibold"
/>
</div>
<Tooltip.Arrow
className="fill-white"
offset={5}
width={9}
height={6}
/>
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
) : null}
<FieldDescriptionTooltip description={description} />
</div>
<Select.Root
onValueChange={(e) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import cn from "clsx";
import {
Form,
Icons,
ParagraphWithHTML,
Textarea,
Tooltip,
} from "@instill-ai/design-system";
import { Form, Textarea } from "@instill-ai/design-system";
import { AutoFormFieldBaseProps } from "../../type";
import { FieldDescriptionTooltip } from "../common";

export const TextAreaField = ({
form,
Expand Down Expand Up @@ -34,35 +29,7 @@ export const TextAreaField = ({
>
{title}
</Form.Label>
{description ? (
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Icons.HelpCircle className="my-auto h-[14px] w-[14px] cursor-pointer stroke-semantic-fg-secondary" />
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content
className="w-[360px]"
sideOffset={5}
side="top"
>
<div className="!rounded-sm !bg-semantic-bg-primary !px-3 !py-2">
<ParagraphWithHTML
text={description}
className="break-all text-semantic-fg-primary product-body-text-4-semibold"
/>
</div>
<Tooltip.Arrow
className="fill-white"
offset={5}
width={9}
height={6}
/>
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
) : null}
<FieldDescriptionTooltip description={description} />
</div>
<Form.Control>
<Textarea
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import cn from "clsx";
import {
Form,
Icons,
Input,
ParagraphWithHTML,
Tooltip,
} from "@instill-ai/design-system";
import { Form, Input } from "@instill-ai/design-system";
import { AutoFormFieldBaseProps } from "../../type";
import { FieldDescriptionTooltip } from "../common";

export const TextField = ({
form,
Expand Down Expand Up @@ -35,35 +30,7 @@ export const TextField = ({
>
{title}
</Form.Label>
{description ? (
<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Icons.HelpCircle className="my-auto h-[14px] w-[14px] cursor-pointer stroke-semantic-fg-secondary" />
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content
className="w-[360px]"
sideOffset={5}
side="top"
>
<div className="!rounded-sm !bg-semantic-bg-primary !px-3 !py-2">
<ParagraphWithHTML
text={description}
className="break-all text-semantic-fg-primary product-body-text-4-semibold"
/>
</div>
<Tooltip.Arrow
className="fill-white"
offset={5}
width={9}
height={6}
/>
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>
</Tooltip.Provider>
) : null}
<FieldDescriptionTooltip description={description} />
</div>
<Form.Control>
<Input.Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Nullable } from "../../../type";
import { Tag } from "@instill-ai/design-system";
import { SmartHintWarning } from "../../type";
import { SmartHint } from "../../../use-smart-hint";
import { transformInstillFormatToHumanReadableFormat } from "../../transform";

export const SmartHintInfoCard = ({
className,
Expand All @@ -28,11 +29,13 @@ export const SmartHintInfoCard = ({

return (
<div className={cn("flex min-h-8 w-full flex-col", className)}>
<div className="flex flex-col gap-y-4 p-2">
<p className="text-semantic-fg-secondary product-body-text-3-semibold">
{highlightedHint ? ` type:${highlightedHint.instillFormat}` : null}
</p>
</div>
{highlightedHint ? (
<div className="flex flex-col gap-y-4 p-2">
<p className="text-semantic-fg-secondary product-body-text-3-semibold">
{`type: ${highlightedHint.instillFormat}`}
</p>
</div>
) : null}
{error ? (
<div className="flex w-full flex-col gap-y-1 bg-semantic-error-bg p-2">
<p className="text-semantic-error-default product-body-text-3-semibold">
Expand Down
Loading

0 comments on commit 6e43839

Please sign in to comment.