Skip to content

Commit b53ea77

Browse files
feat(ui,dashboard): Move InlineTip to UI package (medusajs#11462)
1 parent 63f0774 commit b53ea77

File tree

12 files changed

+163
-72
lines changed

12 files changed

+163
-72
lines changed

.changeset/seven-nails-sleep.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@medusajs/ui": patch
3+
"@medusajs/dashboard": patch
4+
---
5+
6+
feat(ui,dashboard): Move InlineTip to UI package

packages/admin/dashboard/src/components/common/inline-tip/inline-tip.tsx

-60
This file was deleted.

packages/admin/dashboard/src/components/forms/metadata-form/metadata-form.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
DropdownMenu,
55
Heading,
66
IconButton,
7+
InlineTip,
78
clx,
89
toast,
910
} from "@medusajs/ui"
@@ -21,7 +22,6 @@ import { FetchError } from "@medusajs/js-sdk"
2122
import { ComponentPropsWithoutRef, forwardRef } from "react"
2223
import { ConditionalTooltip } from "../../common/conditional-tooltip"
2324
import { Form } from "../../common/form"
24-
import { InlineTip } from "../../common/inline-tip"
2525
import { Skeleton } from "../../common/skeleton"
2626
import { RouteDrawer, useRouteModal } from "../../modals"
2727
import { KeyboundForm } from "../../utilities/keybound-form"

packages/admin/dashboard/src/extensions/forms/form-extension-zone/form-extension-zone.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Input, Switch } from "@medusajs/ui"
1+
import { InlineTip, Input, Switch } from "@medusajs/ui"
22
import { ComponentType } from "react"
33
import { ControllerRenderProps, UseFormReturn } from "react-hook-form"
4+
import { useTranslation } from "react-i18next"
45
import { Form } from "../../../components/common/form"
5-
import { InlineTip } from "../../../components/common/inline-tip"
66
import { FormField } from "../../types"
77
import { FormFieldType } from "./types"
88
import { getFieldType } from "./utils"
@@ -86,6 +86,8 @@ const FormExtensionFieldComponent = ({
8686
component,
8787
placeholder,
8888
}: FormExtensionFieldComponentProps) => {
89+
const { t } = useTranslation()
90+
8991
if (component) {
9092
const Component = component
9193

@@ -104,7 +106,7 @@ const FormExtensionFieldComponent = ({
104106
}
105107
default: {
106108
return (
107-
<InlineTip variant="warning">
109+
<InlineTip variant="warning" label={t("general.warning")}>
108110
The field type does not support rendering a fallback component. Please
109111
provide a component prop.
110112
</InlineTip>

packages/admin/dashboard/src/routes/locations/location-service-zone-create/components/create-service-zone-form/create-service-zone-form.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { zodResolver } from "@hookform/resolvers/zod"
22
import { HttpTypes } from "@medusajs/types"
3-
import { Button, Heading, Input, toast } from "@medusajs/ui"
3+
import { Button, Heading, InlineTip, Input, toast } from "@medusajs/ui"
44
import { useForm } from "react-hook-form"
55
import { useTranslation } from "react-i18next"
66
import { z } from "zod"
77

88
import { Form } from "../../../../../components/common/form"
9-
import { InlineTip } from "../../../../../components/common/inline-tip"
109
import {
1110
RouteFocusModal,
1211
StackedFocusModal,
@@ -118,7 +117,7 @@ export function CreateServiceZoneForm({
118117
/>
119118
</div>
120119

121-
<InlineTip>
120+
<InlineTip label={t("general.tip")}>
122121
{t("stockLocations.serviceZones.fields.tip")}
123122
</InlineTip>
124123

packages/admin/dashboard/src/routes/locations/location-service-zone-edit/components/edit-region-form/edit-service-zone-form.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { HttpTypes } from "@medusajs/types"
2-
import { Button, Input, toast } from "@medusajs/ui"
2+
import { Button, InlineTip, Input, toast } from "@medusajs/ui"
33
import { useForm } from "react-hook-form"
44
import { useTranslation } from "react-i18next"
55
import * as zod from "zod"
66

77
import { Form } from "../../../../../components/common/form"
8-
import { InlineTip } from "../../../../../components/common/inline-tip"
98
import { RouteDrawer, useRouteModal } from "../../../../../components/modals"
109
import { KeyboundForm } from "../../../../../components/utilities/keybound-form"
1110
import { useUpdateFulfillmentSetServiceZone } from "../../../../../hooks/api/fulfillment-sets"
@@ -83,7 +82,9 @@ export const EditServiceZoneForm = ({
8382
}}
8483
/>
8584
</div>
86-
<InlineTip>{t("stockLocations.serviceZones.fields.tip")}</InlineTip>
85+
<InlineTip label={t("general.tip")}>
86+
{t("stockLocations.serviceZones.fields.tip")}
87+
</InlineTip>
8788
</div>
8889
</RouteDrawer.Body>
8990
<RouteDrawer.Footer>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Heading,
77
Hint,
88
IconButton,
9+
InlineTip,
910
Input,
1011
Label,
1112
Text,
@@ -21,7 +22,6 @@ import {
2122
import { useTranslation } from "react-i18next"
2223

2324
import { Form } from "../../../../../../../components/common/form"
24-
import { InlineTip } from "../../../../../../../components/common/inline-tip"
2525
import { SortableList } from "../../../../../../../components/common/sortable-list"
2626
import { SwitchBox } from "../../../../../../../components/common/switch-box"
2727
import { ChipInput } from "../../../../../../../components/inputs/chip-input"
@@ -522,7 +522,7 @@ export const ProductCreateVariantsSection = ({
522522
</Alert>
523523
)}
524524
{variants.fields.length > 0 && (
525-
<InlineTip variant="tip">
525+
<InlineTip label={t("general.tip")}>
526526
{t("products.create.variants.productVariants.tip")}
527527
</InlineTip>
528528
)}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { render, screen } from "@testing-library/react"
2+
import * as React from "react"
3+
import { InlineTip } from "./inline-tip"
4+
5+
describe("InlineTip", () => {
6+
it("renders a InlineTip", () => {
7+
render(<InlineTip label="Test">This is a test</InlineTip>)
8+
expect(screen.getByText("This is a test")).toBeInTheDocument()
9+
})
10+
11+
it("renders a InlineTip with a warning variant", () => {
12+
render(
13+
<InlineTip variant="warning" label="Test">
14+
This is a test
15+
</InlineTip>
16+
)
17+
expect(screen.getByText("This is a test")).toBeInTheDocument()
18+
})
19+
20+
it("renders a InlineTip with an error variant", () => {
21+
render(
22+
<InlineTip variant="error" label="Test">
23+
This is a test
24+
</InlineTip>
25+
)
26+
expect(screen.getByText("This is a test")).toBeInTheDocument()
27+
})
28+
29+
it("renders a InlineTip with a success variant", () => {
30+
render(
31+
<InlineTip variant="success" label="Test">
32+
This is a test
33+
</InlineTip>
34+
)
35+
expect(screen.getByText("This is a test")).toBeInTheDocument()
36+
})
37+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { Meta, StoryObj } from "@storybook/react"
2+
import * as React from "react"
3+
import { InlineTip } from "./inline-tip"
4+
5+
const meta: Meta<typeof InlineTip> = {
6+
title: "Components/InlineTip",
7+
component: InlineTip,
8+
parameters: {
9+
layout: "centered",
10+
},
11+
render: (args) => {
12+
return (
13+
<div className="flex max-w-md">
14+
<InlineTip {...args} />
15+
</div>
16+
)
17+
},
18+
}
19+
20+
export default meta
21+
22+
type Story = StoryObj<typeof InlineTip>
23+
24+
export const Info: Story = {
25+
args: {
26+
variant: "info",
27+
label: "Info",
28+
children:
29+
"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.",
30+
},
31+
}
32+
33+
export const Warning: Story = {
34+
args: {
35+
variant: "warning",
36+
label: "Warning",
37+
children:
38+
"If you have multiple storage plugins configured, the last plugin declared in the medusa-config.js file will be used.",
39+
},
40+
}
41+
42+
export const Error: Story = {
43+
args: {
44+
variant: "error",
45+
label: "Don'ts",
46+
children:
47+
"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.",
48+
},
49+
}
50+
51+
export const Success: Story = {
52+
args: {
53+
variant: "success",
54+
label: "Do's",
55+
children:
56+
"Use data models when you want to store data related to your customization in the database.",
57+
},
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { clx } from "@/utils/clx"
2+
import * as React from "react"
3+
4+
interface InlineTipProps extends React.ComponentPropsWithoutRef<"div"> {
5+
/**
6+
* The label to display in the tip.
7+
*/
8+
label: string
9+
/**
10+
* The variant of the tip.
11+
* @default "info"
12+
*/
13+
variant?: "info" | "warning" | "error" | "success"
14+
}
15+
16+
/**
17+
* This component is based on the `div` element and supports all of its props.
18+
*/
19+
export const InlineTip = React.forwardRef<HTMLDivElement, InlineTipProps>(
20+
({ variant = "info", label, className, children, ...props }, ref) => {
21+
return (
22+
<div
23+
ref={ref}
24+
className={clx(
25+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
26+
className
27+
)}
28+
{...props}
29+
>
30+
<div
31+
role="presentation"
32+
className={clx("bg-ui-tag-neutral-icon h-full w-1 rounded-full", {
33+
"bg-ui-tag-orange-icon": variant === "warning",
34+
"bg-ui-tag-red-icon": variant === "error",
35+
"bg-ui-tag-green-icon": variant === "success",
36+
})}
37+
/>
38+
<div className="text-pretty">
39+
<strong className="txt-small-plus text-ui-fg-base">{label}:</strong>{" "}
40+
{children}
41+
</div>
42+
</div>
43+
)
44+
}
45+
)
46+
47+
InlineTip.displayName = "InlineTip"

packages/design-system/ui/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export { Hint } from "./components/hint"
2222
export { I18nProvider } from "./components/i18n-provider"
2323
export { IconBadge } from "./components/icon-badge"
2424
export { IconButton } from "./components/icon-button"
25+
export { InlineTip } from "./components/inline-tip"
2526
export { Input } from "./components/input"
2627
export { Kbd } from "./components/kbd"
2728
export { Label } from "./components/label"

0 commit comments

Comments
 (0)