diff --git a/.changeset/seven-nails-sleep.md b/.changeset/seven-nails-sleep.md new file mode 100644 index 0000000000000..6f95ce104c802 --- /dev/null +++ b/.changeset/seven-nails-sleep.md @@ -0,0 +1,6 @@ +--- +"@medusajs/ui": patch +"@medusajs/dashboard": patch +--- + +feat(ui,dashboard): Move InlineTip to UI package diff --git a/packages/admin/dashboard/src/components/common/inline-tip/inline-tip.tsx b/packages/admin/dashboard/src/components/common/inline-tip/inline-tip.tsx deleted file mode 100644 index 352f8c537f84f..0000000000000 --- a/packages/admin/dashboard/src/components/common/inline-tip/inline-tip.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import { clx } from "@medusajs/ui" -import { ComponentPropsWithoutRef, forwardRef } from "react" -import { useTranslation } from "react-i18next" - -interface InlineTipProps extends ComponentPropsWithoutRef<"div"> { - /** - * The label to display in the tip. - */ - label?: string - /** - * The variant of the tip. - */ - variant?: "tip" | "warning" -} - -/** - * A component for rendering inline tips. Useful for providing additional information or context. - * - * @example - * ```tsx - * - * This is an info tip. - * - * ``` - * - * TODO: Move to `@medusajs/ui` package. - */ -export const InlineTip = forwardRef( - ({ variant = "tip", label, className, children, ...props }, ref) => { - const { t } = useTranslation() - const labelValue = - label || (variant === "warning" ? t("general.warning") : t("general.tip")) - - return ( -
-
-
- - {labelValue}: - {" "} - {children} -
-
- ) - } -) - -InlineTip.displayName = "InlineTip" diff --git a/packages/admin/dashboard/src/components/forms/metadata-form/metadata-form.tsx b/packages/admin/dashboard/src/components/forms/metadata-form/metadata-form.tsx index 0748c989d5b63..c106a687cea97 100644 --- a/packages/admin/dashboard/src/components/forms/metadata-form/metadata-form.tsx +++ b/packages/admin/dashboard/src/components/forms/metadata-form/metadata-form.tsx @@ -4,6 +4,7 @@ import { DropdownMenu, Heading, IconButton, + InlineTip, clx, toast, } from "@medusajs/ui" @@ -21,7 +22,6 @@ import { FetchError } from "@medusajs/js-sdk" import { ComponentPropsWithoutRef, forwardRef } from "react" import { ConditionalTooltip } from "../../common/conditional-tooltip" import { Form } from "../../common/form" -import { InlineTip } from "../../common/inline-tip" import { Skeleton } from "../../common/skeleton" import { RouteDrawer, useRouteModal } from "../../modals" import { KeyboundForm } from "../../utilities/keybound-form" diff --git a/packages/admin/dashboard/src/extensions/forms/form-extension-zone/form-extension-zone.tsx b/packages/admin/dashboard/src/extensions/forms/form-extension-zone/form-extension-zone.tsx index 75df02680027a..ea742de30eb23 100644 --- a/packages/admin/dashboard/src/extensions/forms/form-extension-zone/form-extension-zone.tsx +++ b/packages/admin/dashboard/src/extensions/forms/form-extension-zone/form-extension-zone.tsx @@ -1,8 +1,8 @@ -import { Input, Switch } from "@medusajs/ui" +import { InlineTip, Input, Switch } from "@medusajs/ui" import { ComponentType } from "react" import { ControllerRenderProps, UseFormReturn } from "react-hook-form" +import { useTranslation } from "react-i18next" import { Form } from "../../../components/common/form" -import { InlineTip } from "../../../components/common/inline-tip" import { FormField } from "../../types" import { FormFieldType } from "./types" import { getFieldType } from "./utils" @@ -86,6 +86,8 @@ const FormExtensionFieldComponent = ({ component, placeholder, }: FormExtensionFieldComponentProps) => { + const { t } = useTranslation() + if (component) { const Component = component @@ -104,7 +106,7 @@ const FormExtensionFieldComponent = ({ } default: { return ( - + The field type does not support rendering a fallback component. Please provide a component prop. diff --git a/packages/admin/dashboard/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx b/packages/admin/dashboard/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx index 5d4688025ff3e..f7d70a76c1404 100644 --- a/packages/admin/dashboard/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx +++ b/packages/admin/dashboard/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx @@ -1,12 +1,11 @@ import { zodResolver } from "@hookform/resolvers/zod" import { HttpTypes } from "@medusajs/types" -import { Button, Heading, Input, toast } from "@medusajs/ui" +import { Button, Heading, InlineTip, Input, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import { z } from "zod" import { Form } from "../../../../../components/common/form" -import { InlineTip } from "../../../../../components/common/inline-tip" import { RouteFocusModal, StackedFocusModal, @@ -118,7 +117,7 @@ export function CreateServiceZoneForm({ />
- + {t("stockLocations.serviceZones.fields.tip")} diff --git a/packages/admin/dashboard/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx b/packages/admin/dashboard/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx index 42f06af3920af..50aa6ecdbc9b2 100644 --- a/packages/admin/dashboard/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx +++ b/packages/admin/dashboard/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx @@ -1,11 +1,10 @@ import { HttpTypes } from "@medusajs/types" -import { Button, Input, toast } from "@medusajs/ui" +import { Button, InlineTip, Input, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import * as zod from "zod" import { Form } from "../../../../../components/common/form" -import { InlineTip } from "../../../../../components/common/inline-tip" import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { KeyboundForm } from "../../../../../components/utilities/keybound-form" import { useUpdateFulfillmentSetServiceZone } from "../../../../../hooks/api/fulfillment-sets" @@ -83,7 +82,9 @@ export const EditServiceZoneForm = ({ }} /> - {t("stockLocations.serviceZones.fields.tip")} + + {t("stockLocations.serviceZones.fields.tip")} + diff --git a/packages/admin/dashboard/src/routes/products/product-create/components/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx b/packages/admin/dashboard/src/routes/products/product-create/components/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx index 6361ac4d1a934..92dad7f0718c8 100644 --- a/packages/admin/dashboard/src/routes/products/product-create/components/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx +++ b/packages/admin/dashboard/src/routes/products/product-create/components/product-create-details-form/components/product-create-details-variant-section/product-create-details-variant-section.tsx @@ -6,6 +6,7 @@ import { Heading, Hint, IconButton, + InlineTip, Input, Label, Text, @@ -21,7 +22,6 @@ import { import { useTranslation } from "react-i18next" import { Form } from "../../../../../../../components/common/form" -import { InlineTip } from "../../../../../../../components/common/inline-tip" import { SortableList } from "../../../../../../../components/common/sortable-list" import { SwitchBox } from "../../../../../../../components/common/switch-box" import { ChipInput } from "../../../../../../../components/inputs/chip-input" @@ -522,7 +522,7 @@ export const ProductCreateVariantsSection = ({ )} {variants.fields.length > 0 && ( - + {t("products.create.variants.productVariants.tip")} )} diff --git a/packages/admin/dashboard/src/components/common/inline-tip/index.ts b/packages/design-system/ui/src/components/inline-tip/index.ts similarity index 100% rename from packages/admin/dashboard/src/components/common/inline-tip/index.ts rename to packages/design-system/ui/src/components/inline-tip/index.ts diff --git a/packages/design-system/ui/src/components/inline-tip/inline-tip.spec.tsx b/packages/design-system/ui/src/components/inline-tip/inline-tip.spec.tsx new file mode 100644 index 0000000000000..7f6b4b47ade27 --- /dev/null +++ b/packages/design-system/ui/src/components/inline-tip/inline-tip.spec.tsx @@ -0,0 +1,37 @@ +import { render, screen } from "@testing-library/react" +import * as React from "react" +import { InlineTip } from "./inline-tip" + +describe("InlineTip", () => { + it("renders a InlineTip", () => { + render(This is a test) + expect(screen.getByText("This is a test")).toBeInTheDocument() + }) + + it("renders a InlineTip with a warning variant", () => { + render( + + This is a test + + ) + expect(screen.getByText("This is a test")).toBeInTheDocument() + }) + + it("renders a InlineTip with an error variant", () => { + render( + + This is a test + + ) + expect(screen.getByText("This is a test")).toBeInTheDocument() + }) + + it("renders a InlineTip with a success variant", () => { + render( + + This is a test + + ) + expect(screen.getByText("This is a test")).toBeInTheDocument() + }) +}) diff --git a/packages/design-system/ui/src/components/inline-tip/inline-tip.stories.tsx b/packages/design-system/ui/src/components/inline-tip/inline-tip.stories.tsx new file mode 100644 index 0000000000000..4cf549b8881cb --- /dev/null +++ b/packages/design-system/ui/src/components/inline-tip/inline-tip.stories.tsx @@ -0,0 +1,58 @@ +import type { Meta, StoryObj } from "@storybook/react" +import * as React from "react" +import { InlineTip } from "./inline-tip" + +const meta: Meta = { + title: "Components/InlineTip", + component: InlineTip, + parameters: { + layout: "centered", + }, + render: (args) => { + return ( +
+ +
+ ) + }, +} + +export default meta + +type Story = StoryObj + +export const Info: Story = { + args: { + variant: "info", + label: "Info", + children: + "You can always install the storefront at a later point. Medusa is a headless backend, so it operates without a storefront by default. You can connect any storefront to it. The Next.js Starter storefront is a good option to use, but you can also build your own storefront later on.", + }, +} + +export const Warning: Story = { + args: { + variant: "warning", + label: "Warning", + children: + "If you have multiple storage plugins configured, the last plugin declared in the medusa-config.js file will be used.", + }, +} + +export const Error: Story = { + args: { + variant: "error", + label: "Don'ts", + children: + "Don’t use data models if you want to store simple key-value pairs related to a Medusa data model. Instead, use the metadata field that modles have, which is an object of custom key-value pairs.", + }, +} + +export const Success: Story = { + args: { + variant: "success", + label: "Do's", + children: + "Use data models when you want to store data related to your customization in the database.", + }, +} diff --git a/packages/design-system/ui/src/components/inline-tip/inline-tip.tsx b/packages/design-system/ui/src/components/inline-tip/inline-tip.tsx new file mode 100644 index 0000000000000..9020994bb25f1 --- /dev/null +++ b/packages/design-system/ui/src/components/inline-tip/inline-tip.tsx @@ -0,0 +1,47 @@ +import { clx } from "@/utils/clx" +import * as React from "react" + +interface InlineTipProps extends React.ComponentPropsWithoutRef<"div"> { + /** + * The label to display in the tip. + */ + label: string + /** + * The variant of the tip. + * @default "info" + */ + variant?: "info" | "warning" | "error" | "success" +} + +/** + * This component is based on the `div` element and supports all of its props. + */ +export const InlineTip = React.forwardRef( + ({ variant = "info", label, className, children, ...props }, ref) => { + return ( +
+
+
+ {label}:{" "} + {children} +
+
+ ) + } +) + +InlineTip.displayName = "InlineTip" diff --git a/packages/design-system/ui/src/index.ts b/packages/design-system/ui/src/index.ts index 7161a57395dee..e4077b648e23b 100644 --- a/packages/design-system/ui/src/index.ts +++ b/packages/design-system/ui/src/index.ts @@ -22,6 +22,7 @@ export { Hint } from "./components/hint" export { I18nProvider } from "./components/i18n-provider" export { IconBadge } from "./components/icon-badge" export { IconButton } from "./components/icon-button" +export { InlineTip } from "./components/inline-tip" export { Input } from "./components/input" export { Kbd } from "./components/kbd" export { Label } from "./components/label"