Skip to content

Commit 54d9edc

Browse files
authored
docs: improve instructions to install Medusa UI in standalone projects (medusajs#13104)
1 parent f6736d9 commit 54d9edc

File tree

3 files changed

+206
-120
lines changed

3 files changed

+206
-120
lines changed

www/apps/book/public/llms-full.txt

Lines changed: 100 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -83074,7 +83074,7 @@ const data = [
8307483074
{
8307583075
id: "1",
8307683076
title: "Shirt",
83077-
price: 10
83077+
price: 10,
8307883078
},
8307983079
// other data...
8308083080
]
@@ -83113,7 +83113,7 @@ import {
8311383113
Then, inside the component that will render `DataTable`, create a table instance using the `useDataTable` hook:
8311483114

8311583115
```tsx
83116-
export default function ProductTable () {
83116+
export default function ProductTable() {
8311783117
const table = useDataTable({
8311883118
columns,
8311983119
data,
@@ -83137,7 +83137,7 @@ The `useDataTable` hook accepts an object with the following properties:
8313783137
Finally, render the `DataTable` component with the table instance created using the `useDataTable` hook:
8313883138

8313983139
```tsx
83140-
export default function ProductTable () {
83140+
export default function ProductTable() {
8314183141
// ...
8314283142
return (
8314383143
<DataTable instance={table}>
@@ -83376,14 +83376,14 @@ const products = [
8337683376
id: "1",
8337783377
title: "Shirt",
8337883378
price: 10,
83379-
is_active: true
83379+
is_active: true,
8338083380
},
8338183381
{
8338283382
id: "2",
8338383383
title: "Pants",
8338483384
price: 20,
83385-
is_active: true
83386-
}
83385+
is_active: true,
83386+
},
8338783387
]
8338883388

8338983389
const columnHelper = createDataTableColumnHelper<typeof products[0]>()
@@ -83398,7 +83398,7 @@ const columns = [
8339883398
{isActive ? "Active" : "Inactive"}
8339983399
</Badge>
8340083400
)
83401-
}
83401+
},
8340283402
}),
8340383403
// ...
8340483404
]
@@ -83483,8 +83483,8 @@ const table = useDataTable({
8348383483
// ...
8348483484
search: {
8348583485
state: search,
83486-
onSearchChange: setSearch
83487-
}
83486+
onSearchChange: setSearch,
83487+
},
8348883488
})
8348983489
```
8349083490

@@ -83513,8 +83513,8 @@ const table = useDataTable({
8351383513
// Pass the state and onSearchChange to the table instance.
8351483514
search: {
8351583515
state: search,
83516-
onSearchChange: setSearch
83517-
}
83516+
onSearchChange: setSearch,
83517+
},
8351883518
})
8351983519
```
8352083520

@@ -83755,7 +83755,7 @@ const table = useDataTable({
8375583755
onPaginationChange: setPagination,
8375683756
},
8375783757
isLoading: false,
83758-
});
83758+
})
8375983759
```
8376083760

8376183761
Finally, render the `DataTable.Pagination` component as part of the `DataTable`'s children:
@@ -83914,8 +83914,8 @@ const filters = [
8391483914
label: "Title",
8391583915
options: products.map((product) => ({
8391683916
label: product.title,
83917-
value: product.title.toLowerCase()
83918-
}))
83917+
value: product.title.toLowerCase(),
83918+
})),
8391983919
}),
8392083920
]
8392183921
```
@@ -84008,7 +84008,7 @@ const table = useDataTable({
8400884008
state: filtering,
8400984009
onFilteringChange: setFiltering,
8401084010
},
84011-
filters
84011+
filters,
8401284012
})
8401384013
```
8401484014

@@ -84196,24 +84196,24 @@ const filters = [
8419684196
label: "Today",
8419784197
value: {
8419884198
$gte: new Date(new Date().setHours(0, 0, 0, 0)).toString(),
84199-
$lte: new Date(new Date().setHours(23, 59, 59, 999)).toString()
84200-
}
84199+
$lte: new Date(new Date().setHours(23, 59, 59, 999)).toString(),
84200+
},
8420184201
},
8420284202
{
8420384203
label: "Yesterday",
8420484204
value: {
8420584205
$gte: new Date(new Date().setHours(0, 0, 0, 0) - 24 * 60 * 60 * 1000).toString(),
84206-
$lte: new Date(new Date().setHours(0, 0, 0, 0)).toString()
84207-
}
84206+
$lte: new Date(new Date().setHours(0, 0, 0, 0)).toString(),
84207+
},
8420884208
},
8420984209
{
8421084210
label: "Last Week",
8421184211
value: {
8421284212
$gte: new Date(new Date().setHours(0, 0, 0, 0) - 7 * 24 * 60 * 60 * 1000).toString(),
84213-
$lte: new Date(new Date().setHours(0, 0, 0, 0)).toString()
84213+
$lte: new Date(new Date().setHours(0, 0, 0, 0)).toString(),
8421484214
},
8421584215
},
84216-
]
84216+
],
8421784217
}),
8421884218
]
8421984219
```
@@ -84382,7 +84382,7 @@ If you want to set initial filter values, you can set the initial state of the `
8438284382

8438384383
```tsx
8438484384
const [filtering, setFiltering] = useState<DataTableFilteringState>({
84385-
title: ["shirt"]
84385+
title: ["shirt"],
8438684386
})
8438784387
```
8438884388

@@ -84510,11 +84510,11 @@ Next, in the component rendering the `DataTable` component, create a state varia
8451084510
```tsx
8451184511
import {
8451284512
// ...
84513-
DataTableSortingState
84513+
DataTableSortingState,
8451484514
} from "@medusajs/ui"
8451584515

84516-
export default function ProductTable () {
84517-
const [sorting, setSorting] = useState<DataTableSortingState | null>(null);
84516+
export default function ProductTable() {
84517+
const [sorting, setSorting] = useState<DataTableSortingState | null>(null)
8451884518

8451984519
const table = useDataTable({
8452084520
// ...
@@ -84540,7 +84540,7 @@ You must also implement the sorting logic, such as sending the sorting condition
8454084540
For example, when using a simple array as in the example above, this is how you sort the data based on the sorting conditions:
8454184541

8454284542
```tsx
84543-
const [sorting, setSorting] = useState<DataTableSortingState | null>(null);
84543+
const [sorting, setSorting] = useState<DataTableSortingState | null>(null)
8454484544

8454584545
const shownProducts = useMemo(() => {
8454684546
if (!sorting) {
@@ -84823,8 +84823,8 @@ const useCommands = () => {
8482384823
const productsToDeleteIds = Object.keys(selection)
8482484824

8482584825
// TODO remove products from the server
84826-
}
84827-
})
84826+
},
84827+
}),
8482884828
]
8482984829
}
8483084830
```
@@ -88429,50 +88429,60 @@ npm install @medusajs/ui
8842988429
The configuration of the UI package is handled by the `@medusajs/admin` package. Therefore, you do not need to any additional configuration to use the UI package in your Admin extensions.
8843088430

8843188431

88432-
# Standalone Project
88432+
# Medusa UI Installation in Standalone Projects
8843388433

88434-
How to install and use Medusa UI in a standalone project.
88434+
Learn how to install and use Medusa UI in a standalone project.
8843588435

88436-
## Installation
88436+
Medusa UI is a React UI library that, while intended for usage within Medusa projects, can also be used in any React project.
8843788437

88438-
***
88438+
The icons package is installed independently from Medusa UI. Learn how to install it in the [Icons](../icons/overview.mdx) guide.
8843988439

88440-
Medusa UI is a React UI library and while it's intended for usage within Medusa projects, it can also be used in any React project.
88440+
## Medusa UI Compatibility
8844188441

88442-
### Install Medusa UI
88442+
To use Medusa UI in your standalone project, you must have:
8844388443

88444-
Install the React UI library with the following command:
88444+
- React 18+ installed. Most React-based frameworks and libraries, such as Next.js and Vite, are compatible with this requirement.
88445+
- [Tailwind CSS](https://v3.tailwindcss.com/) installed. The components in Medusa UI are styled using Tailwind CSS, so you will need to install it in your project as well.
88446+
- Medusa UI was built with Tailwind CSS v3, but it may generally support v4 as well.
88447+
88448+
***
88449+
88450+
## Step 1: Install Medusa UI
88451+
88452+
In your standalone project, install the Medusa UI package with the following command:
8844588453

8844688454
```bash
8844788455
npm install @medusajs/ui
8844888456
```
8844988457

88450-
### Configuring Tailwind CSS
88458+
***
88459+
88460+
## Step 2: Install UI Presets
8845188461

88452-
The components are styled using Tailwind CSS, and in order to use them, you will need to install Tailwind CSS in your project as well.
88453-
For more information on how to install Tailwind CSS, please refer to the [Tailwind CSS documentation](https://tailwindcss.com/docs/installation).
88462+
Medusa UI customizes Tailwind CSS classes to implement its design system. So, you must also install the Medusa UI preset package.
8845488463

88455-
All of the classes used for Medusa UI are shipped as a Tailwind CSS customization.
88456-
You can install it with the following command:
88464+
To install the Medusa UI preset, run the following command:
8845788465

8845888466
```bash
8845988467
npm install @medusajs/ui-preset
8846088468
```
8846188469

88462-
After you have installed Tailwind CSS and the Medusa UI preset, you need to add the following to your `tailwind.config.js`file:
88470+
***
8846388471

88464-
```tsx
88465-
module.exports = {
88466-
presets: [require("@medusajs/ui-preset")],
88467-
// ...
88468-
}
88469-
```
88472+
## Step 3: Configure Tailwind CSS
8847088473

88471-
In order for the styles to be applied correctly to the components, you will also need to ensure that
88472-
`@medusajs/ui` is included in the content field of your `tailwind.config.js` file:
88474+
Next, you'll need to configure Tailwind CSS to use the Medusa UI preset and explicitly add the paths to the Medusa UI components as content files.
8847388475

88474-
```tsx
88476+
### Tailwind CSS v3 Configurations
88477+
88478+
In Tailwind CSS v3, which is the recommended version to use with Medusa UI, you need to add the following configurations to your `tailwind.config.js` or `tailwind.config.ts` file:
88479+
88480+
1. Add the Medusa UI preset to the `presets` array.
88481+
2. Ensure that the `content` field includes the path to the Medusa UI package.
88482+
88483+
```js title="tailwind.config.js"
8847588484
module.exports = {
88485+
presets: [require("@medusajs/ui-preset")],
8847688486
content: [
8847788487
// ...
8847888488
"./node_modules/@medusajs/ui/dist/**/*.{js,jsx,ts,tsx}",
@@ -88481,9 +88491,9 @@ module.exports = {
8848188491
}
8848288492
```
8848388493

88484-
If you are working within a monorepo, you may need to add the path to the `@medusajs/ui` package in your `tailwind.config.js` like so:
88494+
If your project is in a monorepo, you'll need to resolve the path to the `@medusajs/ui` package from the monorepo root:
8848588495

88486-
```tsx
88496+
```tsx title="tailwind.config.js"
8848788497
const path = require("path")
8848888498

8848988499
const uiPath = path.resolve(
@@ -88493,6 +88503,7 @@ const uiPath = path.resolve(
8849388503
)
8849488504

8849588505
module.exports = {
88506+
presets: [require("@medusajs/ui-preset")],
8849688507
content: [
8849788508
// ...
8849888509
uiPath,
@@ -88502,26 +88513,55 @@ module.exports = {
8850288513

8850388514
```
8850488515

88505-
## Start building
88516+
### Tailwind CSS v4 Configurations
88517+
88518+
Medusa UI isn't officially compatible with Tailwind CSS v4 yet, so use it with caution.
88519+
88520+
In your CSS file that imports Tailwind CSS, add the following `@config` and `@source` directives:
88521+
88522+
```css
88523+
@import "tailwindcss";
88524+
@source "../node_modules/@medusajs/ui";
88525+
@config "@medusajs/ui-preset";
88526+
```
88527+
88528+
This will explicitly include the Medusa UI preset and its components in your Tailwind CSS build, and will apply the preset styles to your project.
8850688529

8850788530
***
8850888531

88509-
You are now ready to start building your application with Medusa UI. You can import the components like so:
88532+
## Step 4: Use Medusa UI in Standalone Projects
88533+
88534+
You can now start building your application with Medusa UI.
88535+
88536+
For example, you can use the `Button` in your custom components:
8851088537

8851188538
```tsx
88512-
import { Button, Drawer } from "@medusajs/ui"
88539+
import { Button } from "@medusajs/ui"
88540+
88541+
export function ButtonDemo() {
88542+
return <Button>Button</Button>
88543+
}
8851388544
```
8851488545

88515-
## Updating UI Packages
88546+
Refer to the documentation of each component to learn about its props and usage.
8851688547

8851788548
***
8851888549

88519-
Medusa's design-system packages, including `@medusajs/ui`, `@medusajs/ui-preset`, and `@medusajs/ui-icons`, are versioned independently. However, they're still part of the latest Medusa release. So, you can browse the [release notes](https://github.com/medusajs/medusa/releases) to see if there are any breaking changes to these packages.
88550+
## Update UI Packages in Standalone Projects
8852088551

88521-
To update these packages, update their version in your `package.json` file and re-install dependencies. For example:
88552+
Medusa's design-system packages, including `@medusajs/ui` and `@medusajs/ui-preset`, are versioned independently from other `@medusajs/*` packages. However, they're still released as part of Medusa's releases.
8852288553

88523-
```bash
88524-
npm install @medusajs/ui
88554+
So, to find latest updates and breaking changes to any of these packages, refer to the [release notes in the Medusa GitHub repository](https://github.com/medusajs/medusa/releases).
88555+
88556+
To update these packages in your standalone project, update their version in your `package.json` file and re-install dependencies. For example:
88557+
88558+
```json title="package.json"
88559+
{
88560+
"dependencies": {
88561+
"@medusajs/ui": "4.0.0",
88562+
"@medusajs/ui-preset": "4.0.0"
88563+
}
88564+
}
8852588565
```
8852688566

8852788567

0 commit comments

Comments
 (0)