Documentation for the Get Started of Yamada UI v2.
# Overview
## Pick your framework
- [Next.js (App)](https://yamada-ui.com/docs/get-started/frameworks/next-app.md): A guide for installing and using Yamada UI with Next.js app directory.
- [Next.js (Pages)](https://yamada-ui.com/docs/get-started/frameworks/next-pages.md): A guide for installing and using Yamada UI with Next.js pages directory.
- [Vite](https://yamada-ui.com/docs/get-started/frameworks/vite.md): A guide for installing and using Yamada UI with Vite.js projects.
- [React Router](https://yamada-ui.com/docs/get-started/frameworks/react-router.md): A guide for installing and using Yamada UI with React Router projects.
## Installation
To install Yamada UI in your project, you can either set it up using the [CLI](https://yamada-ui.com/docs/get-started/cli.md) or install it via [npm](https://www.npmjs.com).
:::warning
Yamada UI is compatible with React 19. If you are using React 18 or earlier, please upgrade to React 19.
:::
### CLI
#### Setup
Running the command will create the necessary files and folders in your project.
```bash
pnpm dlx @yamada-ui/cli init
```
```bash
npx @yamada-ui/cli init
```
```bash
yarn dlx @yamada-ui/cli init
```
```bash
bunx @yamada-ui/cli init
```
#### Install the package
Install `@workspaces/ui` to your application.
```bash
pnpm add "@workspaces/ui@workspace:*"
```
```bash
npm install "@workspaces/ui@workspace:*"
```
```bash
yarn add "@workspaces/ui@workspace:*"
```
```bash
bun add "@workspaces/ui@workspace:*"
```
#### Add provider
After installing, add `UIProvider` to the root of your application.
```tsx
import { UIProvider } from "@workspaces/ui"
const App = () => {
return (
)
}
```
#### Use components
After adding `UIProvider`, you can use the components in your application.
```tsx
import { Button } from "@workspaces/ui"
const App = () => {
return
}
```
That's it! You've successfully set up Yamada UI.
### npm
#### Install the package
Yamada UI can be installed with `@yamada-ui/react` only, and all components and hooks can be used.
```bash
pnpm add @yamada-ui/react
```
```bash
npm install @yamada-ui/react
```
```bash
yarn add @yamada-ui/react
```
```bash
bun add @yamada-ui/react
```
#### Add provider
After installing, add `UIProvider` to the root of your application.
```tsx
import { UIProvider } from "@yamada-ui/react"
const App = () => {
return (
)
}
```
#### Use components
After adding `UIProvider`, you can use the components in your application.
```tsx
import { Button } from "@yamada-ui/react"
const App = () => {
return
}
```
That's it! You've successfully set up Yamada UI.
# Accessibility
We take care of many of the difficult implementation details related to accessibility, including `aria` and `role` attributes, focus management, and keyboard navigation. That means that users should be able to use our components as-is in most contexts and rely on functionality to follow the expected accessibility design patterns.
## WAI-ARIA
[WAI-ARIA](https://www.w3.org/TR/wai-aria-1.2) is developed by [W3C](https://www.w3.org) and defines the semantics of many common UI patterns seen in Yamada UI. This is designed to give meaning to controls built without using the browser-provided elements. For example, if you were to create a button using `div` instead of `button`, there are attributes that you would need to add to `div` to inform screen readers and speech recognition tools that it is a button.
In addition to semantics, there are also expected behaviors for different types of components. `button` is an example of a component that needs to be reimplemented using JavaScript because it has interactions that do not exist on `div`. [WAI-ARIA authoring practices](https://www.w3.org/WAI/ARIA/apg) provides additional guidance for implementing the behaviors of many of the controls that come with Yamada UI.
## Accessible Label
Many components are designed to provide semantic meaning and context to the corresponding input or select elements. For components that Yamada UI does not provide, [WAI-ARIA provides a specification](https://www.w3.org/TR/wai-aria-1.2/#namecalculation) that provides a specification for providing accessible names and descriptions for those components.
Yamada UI is as abstracted as possible and simplifies the labeling of components. [Field.Label](https://yamada-ui.com/docs/components/field.md) is designed to work with many of our components. Ultimately, it is your responsibility to provide labels so that users have the appropriate context when navigating your application.
## Keyboard Navigation
[Tabs](https://yamada-ui.com/docs/components/tabs.md) and [Modal](https://yamada-ui.com/docs/components/modal.md) are examples of complex components that require users to interact with content using keyboard and other non-mouse input modalities. Yamada UI provides basic keyboard support following the [WAI-ARIA authoring practices](https://www.w3.org/WAI/ARIA/apg).
## Focus Management
Proper keyboard navigation and proper labeling are closely related to focus management. It is often helpful to move focus in response to an action when a user interacts with an element, and the result of that interaction changes something in the application, and the next focus should logically function according to the new context of the application. For users who use screen readers, moving focus is often accompanied by an announcement that conveys the new context, which is essential for proper labeling.
Many of Yamada UI's components move focus based on the actions that users typically perform on the components.
# Learn the Advanced
This guide will help you understand the concepts of Yamada UI. We recommend reading this guide before you start developing with Yamada UI.
:::tip
This guide is basic and is intended to give you a sense of the **fun** of developing with Yamada UI. Therefore, it does not explain each concept and feature in depth. If you want to know more, please check the links within the page.
:::
## Theme
Yamada UI has the same concept as other UI libraries, which is theme.
Theme is an object that can be changed and has [colors](https://yamada-ui.com/docs/theming/tokens/colors.md), [spaces](https://yamada-ui.com/docs/theming/tokens/spaces.md), [font sizes](https://yamada-ui.com/docs/theming/tokens/font-sizes.md), and many other tokens defined.
[Breakpoints](https://yamada-ui.com/docs/theming/breakpoints.md) and [color modes](https://yamada-ui.com/docs/theming/color-mode.md) used in applications can also be easily changed.
Also, [theme switching](https://yamada-ui.com/docs/theming/switching-themes.md) that is not implemented in other UI libraries is supported.
```tsx
const { themeScheme, changeThemeScheme } = useTheme()
return (
The current scheme is "{themeScheme}"PrimarySecondaryPrimarySecondary
)
```
:::note
If you want to know more about the theme, please check [this](https://yamada-ui.com/docs/theming.md).
:::
### Layer Styles
Layer styles are tokens used to reuse visual styles across the project.
```tsx preview
{(token, index) => (
{toTitleCase(token)}
)}
```
:::note
If you want to know more about the layer styles, please check [this](https://yamada-ui.com/docs/styling/layer-styles.md).
:::
### Text Styles
Text styles are tokens used to reuse text styles across the project.
```tsx
Mono
```
:::note
If you want to know more about the text styles, please check [this](https://yamada-ui.com/docs/styling/text-styles.md).
:::
## Loading
Yamada UI supports loading animations needed for applications.
To execute the loading animation, use [useLoading](https://yamada-ui.com/docs/hooks/use-loading.md). [useLoading](https://yamada-ui.com/docs/hooks/use-loading.md) returns instances of `screen`, `page`, and `background`. The instances include several methods.
- `start`: Start the loading animation.
- `update`: Update the loading animation.
- `finish`: Finish the loading animation.
- `force`: Force update the loading animation.
```tsx
const { screen, page, background } = useLoading()
const onLoadingScreen = async () => {
try {
screen.start()
await wait(3000)
} finally {
screen.finish()
}
}
const onLoadingPage = async () => {
try {
page.start()
await wait(3000)
} finally {
page.finish()
}
}
const onLoadingBackground = async () => {
try {
background.start()
await wait(3000)
} finally {
background.finish()
}
}
return (
)
```
### Use useAsyncCallback
When executing asynchronous callbacks in applications, [useAsyncCallback](https://yamada-ui.com/docs/hooks/use-async-callback.md) is useful to indicate whether a button or other elements are loading.
```tsx
const [loading, onClick] = useAsyncCallback(async () => {
await wait(3000)
}, [])
return (
)
```
`screen` and `page` can also be executed together.
```tsx
const [loading, onClick] = useAsyncCallback(
async () => {
await wait(3000)
},
[],
{ loading: "page" },
)
return (
)
```
:::note
If you want to know more about the loading animation, please check [this](https://yamada-ui.com/docs/hooks/use-loading.md).
:::
## Notice
Yamada UI supports notices needed for applications.
To display the notice, use [useNotice](https://yamada-ui.com/docs/hooks/use-notice.md). [useNotice](https://yamada-ui.com/docs/hooks/use-notice.md) returns an instance that displays and controls the notice.
```tsx
const notice = useNotice()
return (
)
```
:::note
If you want to know more about the notice, please check [this](https://yamada-ui.com/docs/hooks/use-notice.md).
:::
## Animation
Yamada UI provides components specialized in CSS animations and animations.
### CSS Animation
[@keyframes](https://developer.mozilla.org/ja/docs/Web/CSS/@keyframes) to apply intermediate states of animations, use `_keyframes`.
```tsx
Box
```
Also, you can apply common keyframes throughout your application by using [theme](https://yamada-ui.com/docs/theming.md) [keyframes](https://yamada-ui.com/docs/theming/tokens/keyframes.md). Set the value to `animationName` or `_keyframes`.
```tsx
Box
```
:::note
If you want to know more about the animation, please check [this](https://yamada-ui.com/docs/styling/animation.md).
:::
### Motion
Yamada UI provides a convenient component that extends the Yamada UI [Style Props](https://yamada-ui.com/docs/styling/style-props.md) to [Motion](https://motion.dev).
```tsx
```
[Motion](https://yamada-ui.com/docs/components/motion.md) supports gesture animations.
- `whileHover`: The animation executed when the pointer is moved over the component.
- `whileTap`: The animation executed when the pointer is clicked or tapped on the component.
- `whileFocus`: The animation executed when the component is focused.
```tsx
Click me!
```
:::note
If you want to know more about the `Motion` component, please check [this](https://yamada-ui.com/docs/components/motion.md).
:::
## Congratulations!
Congratulations!🎉
This means you've become a **Wonderful Yamada**🥳
## Learn more
Want to learn more about Yamada UI?😎
- [Learn the Theme](https://yamada-ui.com/docs/theming.md): Yamada UI's theme is customizable and ensures consistency in the application's design.
- [Explore the Components](https://yamada-ui.com/docs/components.md): Yamada UI provides over 130 flexible components. All components support animations and dark mode.
- [Learn the Styling](https://yamada-ui.com/docs/styling.md): All components are designed to be styled using props.
- [Explore the Source Code](https://github.com/yamada-ui/yamada-ui): Yamada UI's package and documentation site are open source. If you like Yamada UI, please star it.
# Learn the Basics
This guide will help you understand the concepts of Yamada UI. We recommend reading this guide before you start developing with Yamada UI.
:::tip
This guide is basic and is intended to give you a sense of the **fun** of developing with Yamada UI. Therefore, it does not explain each concept and feature in depth. If you want to know more, please check the links within the page.
:::
## Components
Yamada UI provides components in two ways. One is a new method of downloading components locally from [CLI](https://yamada-ui.com/docs/components/cli.md). The other is the traditional method of importing components from modules.
### Download
The cases for downloading components locally from [CLI](https://yamada-ui.com/docs/components/cli.md) are as follows.
- Customize the [variant](https://yamada-ui.com/docs/components/styled.md#variant-style) or [size](https://yamada-ui.com/docs/components/styled.md#size-style) styles of the component.
- Customize the initial value or logic of the component.
- Fix a bug in the component's style or logic by directly modifying it.
```bash
pnpm yamada-cli add button
```
```bash
npm yamada-cli add button
```
```bash
yarn yamada-cli add button
```
```bash
bun yamada-cli add button
```
:::note
Yamada UI updates the components, you can easily update the components by checking the [Check Differences](https://yamada-ui.com/docs/components/cli.md#check-differences) or [Update Components](https://yamada-ui.com/docs/components/cli.md#update-components) in [CLI](https://yamada-ui.com/docs/components/cli.md). If your changes conflict with the updates, they will be displayed in the same way as the [HOW CONFLICTS ARE PRESENTED](https://git-scm.com/docs/git-merge#_how_conflicts_are_presented) of [Git](https://git-scm.com), and you can easily resolve them.
:::
### Import
If you want to use the component without making any changes, you can simply import the component from the module.
```tsx
import { Button } from "@yamada-ui/react"
```
```tsx
import { Button } from "@/components/ui"
```
```tsx
import { Button } from "@workspaces/ui"
```
:::note
If you want to know more about the components, please check [this](https://yamada-ui.com/docs/components.md).
:::
## Styling
[Style Props](https://yamada-ui.com/docs/styling/style-props.md) is a prop that applies styles to elements using props. Style Props follows the [CSS properties](https://developer.mozilla.org/ja/docs/Web/CSS/Properties) and provides all properties in camelCase.
```tsx
Box
```
:::note
[Style Props](https://yamada-ui.com/docs/styling/style-props.md) uses [@mdn/browser-compat-data](https://github.com/mdn/browser-compat-data). When the library is updated, Style Props is also updated periodically.
:::
### Conditional Styles
Conditional styles allow you to apply styles to [pseudo-elements](https://yamada-ui.com/docs/styling/style-props.md#pseudo-elements), [pseudo-classes](https://yamada-ui.com/docs/styling/style-props.md#pseudo-classes), and [selectors](https://yamada-ui.com/docs/styling/style-props.md#selectors).
```tsx
Hover me
```
:::note
If you want to know more about the styling, please check [this](https://yamada-ui.com/docs/styling.md).
:::
### Color Schemes
Color schemes generate a color context for the component based on the values. This improves consistency in colors.
```tsx
Solid
Subtle
```
Color schemes inherit the color scheme of the parent element.
```tsx
Provided by Parent
Child
```
:::note
If you want to know more about the color schemes, please check [this](https://yamada-ui.com/docs/styling/color-scheme.md).
:::
## Responsive Design
Responsive design refers to the breakpoints defined in the theme. Yamada UI has a default theme, and [breakpoints](https://yamada-ui.com/docs/theming/tokens/breakpoints.md) are defined.
To apply responsive design to [Style Props](https://yamada-ui.com/docs/styling/style-props.md), set an object with the breakpoints as the key.
- The keys of the object define the keys set in the theme's [breakpoints](https://yamada-ui.com/docs/theming/tokens/breakpoints.md).
- The values of the object define the values of the styles set by the key.
```tsx
Box
```
:::note
If you want to know more about the responsive design, please check [this](https://yamada-ui.com/docs/styling/responsive-design.md).
:::
## Color Mode
Yamada UI has built-in support for managing the application's color mode, allowing you to easily switch between light and dark modes. All provided components also support dark mode.
To apply color mode to [Style Props](https://yamada-ui.com/docs/styling/style-props.md), set an array.
- Set the value for light mode as the first element.
- Set the value for dark mode as the last element.
```tsx
Box
```
:::note
If you want to know more about the color mode, please check [this](https://yamada-ui.com/docs/styling/color-mode.md).
:::
## Congratulations!
Congratulations!🎉
This means you've become a **Regular Yamada**🥳
To the **Regular Yamada**, I'd like to give you this word.
"Next, I'm waiting for you in [Learn the Advanced](https://yamada-ui.com/docs/get-started/advanced.md)///"😘
## Learn more
Want to learn more about Yamada UI?😎
- [Learn the Advanced](https://yamada-ui.com/docs/get-started/advanced.md): Learn the applications of styling, responsiveness, dark mode, and animations of Yamada UI.
- [Explore the Components](https://yamada-ui.com/docs/components.md): Yamada UI provides over 130 flexible components. All components support animations and dark mode.
- [Learn the Styling](https://yamada-ui.com/docs/styling.md): All components are designed to be styled using props.
- [Explore the Source Code](https://github.com/yamada-ui/yamada-ui): Yamada UI's package and documentation site are open source. If you like Yamada UI, please star it.
# CLI
## Installation
To use CLI, you need to install `@yamada-ui/cli` in your project.
```bash
pnpm add -D @yamada-ui/cli
```
```bash
npm i -D @yamada-ui/cli
```
```bash
yarn add -D @yamada-ui/cli
```
```bash
bun add -D @yamada-ui/cli
```
## Commands
### init
When you run the `init` command, the necessary files and folders for your project will be created.
```bash
pnpm yamada-cli init
```
```bash
npm yamada-cli init
```
```bash
yarn yamada-cli init
```
```bash
bun yamada-cli init
```
```bash
Usage: pnpm yamada-cli init [options]
initialize your project and install dependencies
Options:
--cwd current working directory
-c, --config path to the config file (default: "ui.json")
-o, --overwrite overwrite existing files. (default: false)
-j, --jsx use jsx instead of tsx (default: false)
-h, --help display help for command
```
After running the `init` command, you will see the following prompts.
```txt
Would you like to use monorepo? (recommended) … No / Yes
What is the path to the monorepo? … ./workspaces/ui
What is the package name? … @workspaces/ui
Would you like your code inside a `src/` directory? … No / Yes
Would you like to use Prettier? … No / Yes
Would you like to use ESLint? … No / Yes
```
After the prompts, the config and required dependencies will be installed.
### add
When you run the `add` command, the specified component and its dependencies will be added to your project.
```bash
pnpm yamada-cli add box
```
```bash
npm yamada-cli add box
```
```bash
yarn yamada-cli add box
```
```bash
bun yamada-cli add box
```
:::note
All components that the specified component depends on will also be added.
:::
If you don't specify a component, all available components will be added.
```bash
pnpm yamada-cli add
```
```bash
npm yamada-cli add
```
```bash
yarn yamada-cli add
```
```bash
bun yamada-cli add
```
```bash
Usage: pnpm yamada-cli add [options] [components...]
add a component to your project
Arguments:
components components to add
Options:
--cwd current working directory
-c, --config path to the config file (default: "ui.json")
-o, --overwrite overwrite existing files. (default: false)
-i, --install install dependencies (default: false)
-s, --sequential run tasks sequentially. (default: false)
-f, --format format the output files.
-l, --lint lint the output files.
-h, --help display help for command
```
### diff
When you run the `diff` command, you can check the difference between the local and remote components.
```bash
pnpm yamada-cli diff box
```
```bash
npm yamada-cli diff box
```
```bash
yarn yamada-cli diff box
```
```bash
bun yamada-cli diff box
```
If you don't specify a component, you can check the difference for all components in your project.
```bash
pnpm yamada-cli diff
```
```bash
npm yamada-cli diff
```
```bash
yarn yamada-cli diff
```
```bash
bun yamada-cli diff
```
```bash
Usage: pnpm yamada-cli diff [options] [component]
check for updates against the registry
Arguments:
component component to check
Options:
--cwd current working directory
-c, --config path to the config file (default: "ui.json")
-s, --sequential run tasks sequentially. (default: false)
-d, --detail show detailed changes (default: false)
-h, --help display help for command
```
### update
When you run the `update` command, the specified component will be updated.
```bash
pnpm yamada-cli update box
```
```bash
npm yamada-cli update box
```
```bash
yarn yamada-cli update box
```
```bash
bun yamada-cli update box
```
If you don't specify a component, all components in your project will be updated.
```bash
pnpm yamada-cli update
```
```bash
npm yamada-cli update
```
```bash
yarn yamada-cli update
```
```bash
bun yamada-cli update
```
```bash
Usage: pnpm yamada-cli update [options] [components...]
update components in your project
Arguments:
components components to update
Options:
--cwd current working directory
-c, --config path to the config file (default: "ui.json")
-i, --install install dependencies (default: false)
-s, --sequential run tasks sequentially. (default: false)
-f, --format format the output files.
-l, --lint lint the output files.
-h, --help display help for command
```
### theme
When you run the `theme` command, the theme will be generated at the specified path.
```bash
pnpm yamada-cli theme
```
```bash
npm yamada-cli theme
```
```bash
yarn yamada-cli theme
```
```bash
bun yamada-cli theme
```
:::note
If you don't specify a path, the theme will be generated in `./theme`.
:::
```bash
Usage: pnpm yamada-cli theme [options] [path]
generate theme to your project
Arguments:
path path to the theme directory
Options:
--cwd current working directory
-c, --config path to the config file (default: "ui.json")
-o, --overwrite overwrite existing directory. (default: false)
-j, --js use js instead of ts
-f, --format format the output files.
-l, --lint lint the output files.
-h, --help display help for command
```
### tokens
When you run the `tokens` command, you can update the customized theme typings.
This typings are used for [Style Props](https://yamada-ui.com/docs/styling/style-props.md).
```bash
pnpm yamada-cli tokens
```
```bash
npm yamada-cli tokens
```
```bash
yarn yamada-cli tokens
```
```bash
bun yamada-cli tokens
```
:::note
If you don't specify a path, the `theme.path` will be used.
:::
```bash
Usage: pnpm yamada-cli tokens [options] [path]
generate theme typings
Arguments:
path path to the theme file
Options:
--cwd current working directory
-c, --config path to the config file (default: "ui.json")
-o, --out output path
-f, --format format the output file
-l, --lint lint the output file
--internal generate internal tokens (default: false)
-h, --help display help for command
```
## Configuration
After running the `init` command, a `ui.json` will be generated in your project. You can customize it in various ways.
| Property | Default | Description |
| ------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------ |
| `path` | `./ui` | The path to the workspace. |
| `monorepo` | `false` | Whether to use a monorepo. |
| `jsx` | `false` | Whether to use JSX. |
| `theme.path` | `./theme` | The path to the theme directory. |
| `components.path` | `./components` | The path to the components directory. |
| `components.overwrite` | `true` | Whether to update the local references of existing components when components are added. |
| `components.dependents` | `true` | Whether to add dependents of components when components are added. |
| `components.dependencies` | `false` | Whether to add dependencies of components when components are added. |
| `hooks.path` | `./hooks` | The path to the hooks directory. |
| `hooks.overwrite` | `false` | Whether to update the local references of existing hooks when components are added. |
| `hooks.dependents` | `true` | Whether to add dependents of hooks when hooks are added. |
| `hooks.dependencies` | `false` | Whether to add dependencies of hooks when hooks are added. |
| `providers.path` | `./providers` | The path to the providers directory. |
| `providers.overwrite` | `false` | Whether to update the local references of existing providers when components are added. |
| `providers.dependents` | `true` | Whether to add dependents of providers when providers are added. |
| `providers.dependencies` | `false` | Whether to add dependencies of providers when providers are added. |
| `format.configPath` | - | The path to the config file for [Prettier](https://prettier.io). |
| `format.enabled` | `false` | Whether to run the `--write` option of [Prettier](https://prettier.io) when components are added or updated. |
| `lint.enabled` | `false` | Whether to run the `--fix` option of [ESLint](https://eslint.org) when components are added or updated. |
# Legacy Documentation
This is the documentation for Yamada UI v2.x. If you are looking for the documentation for v1.x, please see [this link](https://v1.yamada-ui.com).
# LLMs.txt
Yamada UI's documentation supports [LLMs.txt](https://llmstxt.org) to make it available for large language models.
## Files
- [/llms.txt](https://yamada-ui.com/llms.txt): The documentation site map.
- [/llms-full.txt](https://yamada-ui.com/llms-full.txt): All documentation.
- [/llms/get-started.txt](https://yamada-ui.com/llms/get-started.txt): Only the documentation for the Get Started.
- [/llms/components.txt](https://yamada-ui.com/llms/components.txt): Only the documentation for the Components.
- [/llms/hooks.txt](https://yamada-ui.com/llms/hooks.txt): Only the documentation for the Hooks.
- [/llms/styling.txt](https://yamada-ui.com/llms/styling.txt): Only the documentation for the Styling.
- [/llms/theming.txt](https://yamada-ui.com/llms/theming.txt): Only the documentation for the Theming.
## Usage
### Cursor
Use the [@Docs](https://cursor.com/docs/context/symbols#docs) of [Cursor](https://cursor.com) to add [llms.txt](https://yamada-ui.com/llms.txt) or [llms-full.txt](https://yamada-ui.com/llms-full.txt) to your project.
# Migration
## New Features
### Setup
Using [CLI](https://yamada-ui.com/docs/get-started/cli.md), you can easily set up Yamada UI in your project.
```bash
pnpm yamada-cli init
```
```bash
npm yamada-cli init
```
```bash
yarn yamada-cli init
```
```bash
bun yamada-cli init
```
`init` command will display the following prompts.
```txt
Would you like to use monorepo? (recommended) … No / Yes
What is the path to the monorepo? … ./workspaces/ui
What is the package name? … @workspaces/ui
Would you like your code inside a `src/` directory? … No / Yes
Would you like to use Prettier? … No / Yes
Would you like to use ESLint? … No / Yes
```
### Download
From v2.x onwards, there are two ways to use components and hooks. One is the new method of downloading components and hooks locally via the [CLI](https://yamada-ui.com/docs/components/cli.md), and the other is the conventional method of importing them from the module.
By downloading the source code, you can customize the initial value or logic of the component or hook, and if there is a bug in the logic, you can fix it directly.
```bash
pnpm yamada-cli add button
```
```bash
npm yamada-cli add button
```
```bash
yarn yamada-cli add button
```
```bash
bun yamada-cli add button
```
:::note
By downloading the source code and customizing it, you can easily update the source code by checking the [Check Differences](https://yamada-ui.com/docs/components/cli.md#check-differences) or [Update Components](https://yamada-ui.com/docs/components/cli.md#update-components) in [CLI](https://yamada-ui.com/docs/components/cli.md). If your changes conflict with the updates, they will be displayed in the same way as the [HOW CONFLICTS ARE PRESENTED](https://git-scm.com/docs/git-merge#_how_conflicts_are_presented) of [Git](https://git-scm.com), and you can easily resolve them.
:::
### Namespace Import
You can now import components using namespaces.
```tsx
```
:::note
You can still import components individually, but there are components whose names have changed due to the namespace. For example, in the case of `Accordion`, it has been changed to `AccordionRoot`.
:::
### createComponent
Using [createComponent](https://yamada-ui.com/docs/components/create-component.md), you can create components that support conditional styles such as variants.
```tsx
const componentStyle = defineComponentStyle({
base: {
/* base style */
},
variants: {
/* variant style */
},
sizes: {
/* size style */
},
props: {
/* props style */
},
compounds: {
/* compound style */
},
defaultProps: {
/* default props */
},
})
type ComponentStyle = typeof componentStyle
export interface ComponentProps
extends HTMLStyledProps<"div">,
ThemeProps {}
const {
component,
ComponentContext,
PropsContext: ComponentPropsContext,
useComponentContext,
usePropsContext: useComponentPropsContext,
withContext,
useComponentProps,
} = createComponent("component", componentStyle)
export { ComponentPropsContext, useComponentPropsContext }
```
```tsx
export const Component = withContext("div")()
```
### mergeProps
Using `mergeProps`, you can easily merge props while preventing props from disappearing. Previously, you had to create components while considering the provided props. Using `mergeProps`, you can focus on creating components without considering the provided props.
**Before**
```tsx
export const Component: FC = ({
ref: forwardedRef,
className,
onClick: onClickProp,
...rest
}) => {
const ref = useRef(null)
const onClick = useCallback(() => {}, [])
return (
)
}
```
**After**
```tsx
export const Component: FC = (props) => {
const ref = useRef(null)
const onClick = useCallback(() => {}, [])
return
}
```
### PropsContext
Using the `PropsContext` provided by each component, you can set the props of the components in the child elements in bulk.
```tsx
const value = useMemo(() => ({ variant: "outline" }), [])
return (
)
```
In the above example, the `Badge` in the child elements of `BadgePropsContext` will all have `variant` set to `"outline"`.
### Polymorphism
In addition to the traditional `as`, `asChild` has been added. `as` is used to change the element of the component itself, while `asChild` is used to incorporate the functionality and style of the component into the child elements.
**as**
```tsx
```
**asChild**
```tsx
```
### Cascade Layers
Using the [Cascade Layers](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer) of CSS, [Theme](https://yamada-ui.com/docs/theming.md) and [Style Props](https://yamada-ui.com/docs/styling/style-props.md) now have priority. Please refer to [Cascade Layers](https://yamada-ui.com/docs/styling/cascade-layers.md) for more details.
### Focus Ring
[Style Props](https://yamada-ui.com/docs/styling/style-props.md) has been added [Focus Ring](https://yamada-ui.com/docs/styling/focus-ring.md). Focus Ring is a style used to identify the focused element. Please refer to [Focus Ring](https://yamada-ui.com/docs/styling/focus-ring.md) for more details.
```tsx
```
```tsx
```
### Interpolation
[Style Props](https://yamada-ui.com/docs/styling/style-props.md) now allows you to easily reference [CSS Custom Properties](https://yamada-ui.com/docs/styling/css-custom-properties.md) using its values. Please refer to [Interpolation](https://yamada-ui.com/docs/styling/interpolation.md) for more details.
```tsx
```
### CSS Custom Properties
[Style Props](https://yamada-ui.com/docs/styling/style-props.md) now allows you to easily set [CSS Custom Properties](https://developer.mozilla.org/en-US/docs/Web/CSS/var). Please refer to [CSS Custom Properties](https://yamada-ui.com/docs/styling/css-custom-properties.md) for more details.
```tsx
```
You can also reference the tokens of [Theme](https://yamada-ui.com/docs/theming.md).
```tsx
```
### CSS Value Functions
[Style Props](https://yamada-ui.com/docs/styling/style-props.md) now allows you to use [CSS Value Functions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Values_and_Units/CSS_Value_Functions) and reference the corresponding [Theme](https://yamada-ui.com/docs/theming.md) tokens. Please refer to [CSS Value Functions](https://yamada-ui.com/docs/styling/css-value-functions.md) for more details.
```tsx
```
```tsx
```
### At-rules
[Style Props](https://yamada-ui.com/docs/styling/style-props.md) has been added [At-rules](https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule). Please refer to [At-rules](https://yamada-ui.com/docs/styling/at-rules.md) for more details.
```tsx
```
[Container Queries](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_containment/Container_queries) are also supported.
```tsx
```
### Internationalization
To improve accessibility, we have supported 30 or more languages, including strings embedded in all components, date and number formats. Please refer to [Internationalization](https://yamada-ui.com/docs/components/internationalization.md) for more details.
### Icons
New icons have been added. Please refer to [Icons](https://yamada-ui.com/icons.md) for more details.
### Style Props
New CSS properties have been added. Please refer to [Style Props](https://yamada-ui.com/docs/styling/style-props.md) for more details.
### Theme
- New [keyframes](https://yamada-ui.com/docs/theming/tokens/keyframes.md), [aspectRatios](https://yamada-ui.com/docs/theming/tokens/aspect-ratios.md), [easings](https://yamada-ui.com/docs/theming/tokens/easings.md), and [durations](https://yamada-ui.com/docs/theming/tokens/durations.md) have been added to the theme tokens.
- `"mono"` has been added to the [Color Schemes](https://yamada-ui.com/docs/theming/tokens/color-schemes.md).
- New tokens have been added to the [Layer Styles](https://yamada-ui.com/docs/theming/styles/layer-styles.md).
- New tokens have been added to the [Text Styles](https://yamada-ui.com/docs/theming/styles/text-styles.md).
- New tokens have been added to the [Colors](https://yamada-ui.com/docs/theming/tokens/colors.md).
- You can now set `className` in the style object of the components.
## Improvements
### styled
[ui](https://v1.yamada-ui.com/styled-system/ui) has been renamed to [styled](https://yamada-ui.com/docs/components/styled.md). Also, since only the base style of the component could be set until now, it is now possible to set styles that vary depending on conditions, such as `variants` and `sizes`.
**Before**
```tsx
const Button = styled("button", {
base: {
alignItems: "center",
appearance: "none",
cursor: "pointer",
display: "inline-flex",
fontWeight: "medium",
justifyContent: "center",
overflow: "hidden",
position: "relative",
rounded: "l2",
transitionDuration: "moderate",
transitionProperty: "common",
userSelect: "none",
verticalAlign: "middle",
whiteSpace: "nowrap",
_readOnly: { layerStyle: "readOnly" },
_disabled: { layerStyle: "disabled" },
},
})
```
**After**
```tsx
const Button = styled("button", {
base: {
alignItems: "center",
appearance: "none",
cursor: "pointer",
display: "inline-flex",
fontWeight: "medium",
justifyContent: "center",
overflow: "hidden",
position: "relative",
rounded: "l2",
transitionDuration: "moderate",
transitionProperty: "common",
userSelect: "none",
verticalAlign: "middle",
whiteSpace: "nowrap",
_readOnly: { layerStyle: "readOnly" },
_disabled: { layerStyle: "disabled" },
},
variants: {
outline: {
layerStyle: "outline",
_hover: { layerStyle: "outline.hover" },
},
solid: {
layerStyle: "solid",
_hover: { layerStyle: "solid.hover" },
},
subtle: {
layerStyle: "subtle",
_hover: { layerStyle: "subtle.hover" },
},
},
})
```
### Conditional Styles
Conditional style setting has been simplified. The traditional setting can still be used.
**Before**
```tsx
```
**After**
```tsx
```
### Color Scheme
Previously, the [Color Scheme](https://yamada-ui.com/docs/styling/color-scheme.md) was set as props for each component. By integrating `colorScheme` into [Style Props](https://yamada-ui.com/docs/styling/style-props.md), it is now available for components other than components.
```tsx
```
Also, since `colorScheme` uses [CSS Custom Properties](https://yamada-ui.com/docs/styling/css-custom-properties.md) to generate a context, it is now also applied to the child elements.
```tsx
```
### Animation
Previously, the [Animation](https://yamada-ui.com/docs/styling/animation.md) used the [useAnimation](https://yamada-ui.com/docs/hooks/use-animation.md) hook. Now, you can set it directly from [Style Props](https://yamada-ui.com/docs/styling/style-props.md).
**Before**
```tsx
const animation = useAnimation({
_keyframes: {
from: { translate: "0 0" },
to: { translate: "100% 0" },
},
duration: "1s",
iterationCount: "infinite",
timingFunction: "linear",
})
return
```
**After**
```tsx
```
### Components
- The styles of each component have been adjusted.
- The slot names of each component have been adjusted.
- The class names of each component have been adjusted.
- The naming convention of all boolean properties (`isOpen`, `isDisabled`, etc.) in the props of each component has been changed. For example, `isOpen` has been changed to `open`.
:::note
The improvement points of each component are described in the documentation of each component.
:::
### Style Props
- `color-mix` has been supported. If the browser does not support `color-mix`, the fallback value will be applied.
- `blur` and `brightness` can now be applied without setting `filter="auto"`.
- `backdropBlur` and `backdropBrightness` can now be applied without setting `backdropFilter="auto"`.
- `translateX` and `skewX` can now be applied without setting `transform="auto"` or `transform="auto-3d"`.
### Theme
- [CSS Value Functions](https://yamada-ui.com/docs/styling/css-value-functions.md) can now be used for tokens.
- [Interpolation](https://yamada-ui.com/docs/styling/interpolation.md) can now be used for tokens.
- [Theme](https://yamada-ui.com/docs/theming.md) can now be defined using `defineTheme`.
- Tokens can now be defined using `defineTokens`.
- Semantic tokens can now be defined using `defineSemanticTokens`.
- Styles can now be defined using `defineStyles`.
- [Config](https://yamada-ui.com/docs/theming/config.md) can now be defined using `defineConfig`.
- The slot names of the components have been adjusted and changed.
- The global styles have been adjusted.
- The reset styles have been adjusted.
- The values of the tokens have been adjusted.
## Removed Features
### Packages
[Tree Shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) considerations have made it unnecessary to divide each package, and since there is a possibility that other choices than [React](https://react.dev) will become available in future Yamada UI projects, these packages have been deprecated.
- [@yamada-ui/input](https://www.npmjs.com/package/@yamada-ui/input) has been deprecated. Use [@yamada-ui/react](https://www.npmjs.com/package/@yamada-ui/react) instead.
- [@yamada-ui/use-disclosure](https://www.npmjs.com/package/@yamada-ui/use-disclosure) has been deprecated. Use [@yamada-ui/react](https://www.npmjs.com/package/@yamada-ui/react) instead.
- [@yamada-ui/providers](https://www.npmjs.com/package/@yamada-ui/providers) has been deprecated. Use [@yamada-ui/react](https://www.npmjs.com/package/@yamada-ui/react) instead.
- [@yamada-ui/theme](https://www.npmjs.com/package/@yamada-ui/theme) has been deprecated. Use [@yamada-ui/react](https://www.npmjs.com/package/@yamada-ui/react) instead.
- [@yamada-ui/theme-tools](https://www.npmjs.com/package/@yamada-ui/theme-tools) has been deprecated. Use [@yamada-ui/react](https://www.npmjs.com/package/@yamada-ui/react) instead.
- [@yamada-ui/next](https://www.npmjs.com/package/@yamada-ui/next) has been deprecated.
### Style Props
- `fallback` has been removed.
- `keyframes` has been removed. Use `_keyframes` instead.
- `isTruncated` has been removed. Use `truncated` instead.
### Theme
- `transitions` has been removed. Use [easings](https://yamada-ui.com/docs/theming/tokens/easings.md) and [durations](https://yamada-ui.com/docs/theming/tokens/durations.md) instead.
- `semantics` has been removed. Use `semanticTokens` instead.
- `components` has been removed. Use [CLI](https://yamada-ui.com/docs/components/cli.md) to style components.
- `extendBaseTheme` has been removed. Use `extendTheme` instead.
- `extendStyle` has been removed. Use `extendTheme` instead.
- `extendToken` has been removed. Use `extendTheme` instead.
- `extendComponent` has been removed.
- `extendComponentSize` has been removed.
- `extendComponentVariant` has been removed.
- `extendComponentDefaultProps` has been removed.
- `withDefaultSize` has been removed.
- `withDefaultVariant` has been removed.
- `withDefaultColorScheme` has been removed.
- `withDefaultProps` has been removed.
- `generate` has been removed.
### Other
- `forwardRef` has been removed. Use [forwardRef](https://react.dev/reference/react/forwardRef) instead.
- `memo` has been removed. Use [memo](https://react.dev/reference/react/memo) instead.
- `ui` has been removed. Use [styled](https://yamada-ui.com/docs/components/styled.md) instead.
- `sx` and `__css` have been removed. Use `css` instead.
## Added Components
### Mark
[Mark](https://yamada-ui.com/docs/components/mark.md) has been added.
### ClientOnly
[ClientOnly](https://yamada-ui.com/docs/components/client-only.md) has been added.
### Format.Datetime
[Format.Datetime](https://yamada-ui.com/docs/components/format.md#日付) has been added.
### Show
[Show](https://yamada-ui.com/docs/components/show.md) has been added.
### Slot
[Slot](https://yamada-ui.com/docs/components/slot.md) has been added.
### Steps
[Steps](https://yamada-ui.com/docs/components/steps.md) has been added.
### Group
[Group](https://yamada-ui.com/docs/components/group.md) has been added.
### Timeline
[Timeline](https://yamada-ui.com/docs/components/timeline.md) has been added.
## Removed Components
### FontAwesomeIcon
[FontAwesomeIcon](https://v1.yamada-ui.com/components/media-and-icons/fontawesome) has been removed.
### NativeImage
[NativeImage](https://v1.yamada-ui.com/components/media-and-icons/native-image) has been removed. Use [Image](https://yamada-ui.com/docs/components/image.md) instead.
### Dialog
[Dialog](https://v1.yamada-ui.com/components/overlay/dialog) has been removed. Use [Modal](https://yamada-ui.com/docs/components/modal.md#use-props) instead.
### ContextMenu
[ContextMenu](https://v1.yamada-ui.com/components/navigation/context-menu) has been removed. Use [Menu.ContextTrigger](https://yamada-ui.com/docs/components/menu.md#use-context-menu) instead.
### FormControl
[FormControl](https://v1.yamada-ui.com/components/forms/form-control) has been removed. Use [Field](https://yamada-ui.com/docs/components/field.md) instead.
### MultiAutocomplete
[MultiAutocomplete](https://v1.yamada-ui.com/components/forms/multi-autocomplete) has been removed. Use `multiple` of [Autocomplete](https://yamada-ui.com/docs/components/autocomplete.md#enable-multiple-selection) instead.
### MultiDatePicker
[MultiDatePicker](https://v1.yamada-ui.com/components/forms/multi-date-picker) has been removed. Use `multiple` of [DatePicker](https://yamada-ui.com/docs/components/date-picker.md#enable-multiple-selection) instead.
### RangeDatePicker
[RangeDatePicker](https://v1.yamada-ui.com/components/forms/range-date-picker) has been removed. Use `range` of [DatePicker](https://yamada-ui.com/docs/components/date-picker.md#enable-range-selection) instead.
### MultiSelect
[MultiSelect](https://v1.yamada-ui.com/components/forms/multi-select) has been removed. Use `multiple` of [Select](https://yamada-ui.com/docs/components/select.md#enable-multiple-selection) instead.
### YearPicker
[YearPicker](https://v1.yamada-ui.com/components/forms/year-picker) has been removed.
### MonthPicker
[MonthPicker](https://v1.yamada-ui.com/components/forms/month-picker) has been removed.
### RangeSlider
[RangeSlider](https://v1.yamada-ui.com/components/forms/range-slider) has been removed. Use `value` or `defaultValue` of [Slider](https://yamada-ui.com/docs/components/slider.md#enable-range-selection) with an array instead.
### Markdown
[Markdown](https://v1.yamada-ui.com/components/data-display/markdown) has been removed.
### Stepper
[Stepper](https://v1.yamada-ui.com/components/navigation/stepper) has been removed. Use [Steps](https://yamada-ui.com/docs/components/steps.md) instead.
### Divider
[Divider](https://v1.yamada-ui.com/components/layouts/divider) has been removed. Use [Separator](https://yamada-ui.com/docs/components/separator.md) instead.
### PagingTable
[PagingTable](https://v1.yamada-ui.com/components/data-display/paging-table) has been removed. Use `enablePagination` of [Table](https://yamada-ui.com/docs/components/table.md#enable-pagination) instead.
## Components that have not been migrated
v2.0 does not have all components migrated. These will be migrated in v2.0.x.
- [AreaChart](https://yamada-ui.com/docs/components/area-chart.md)
- [BarChart](https://yamada-ui.com/docs/components/bar-chart.md)
- [DonutChart](https://yamada-ui.com/docs/components/donut-chart.md)
- [LineChart](https://yamada-ui.com/docs/components/line-chart.md)
- [PieChart](https://yamada-ui.com/docs/components/pie-chart.md)
- [RadarChart](https://yamada-ui.com/docs/components/radar-chart.md)
- [RadialChart](https://yamada-ui.com/docs/components/radial-chart.md)
## Added Hooks
### useCounter
[useCounter](https://yamada-ui.com/docs/hooks/use-counter.md) has been added.
### useDescendants
[useDescendants](https://yamada-ui.com/docs/hooks/use-descendants.md) has been added.
### useEyeDropper
[useEyeDropper](https://yamada-ui.com/docs/hooks/use-eye-dropper.md) has been added.
### useFocusOnShow
[useFocusOnShow](https://yamada-ui.com/docs/hooks/use-focus-on-show.md) has been added.
### useFormatDateTime
[useFormatDateTime](https://yamada-ui.com/docs/hooks/use-format-date-time.md) has been added.
### useOnline
[useOnline](https://yamada-ui.com/docs/hooks/use-online.md) has been added.
## Removed Hooks
### useToken
[useToken](https://v1.yamada-ui.com/hooks/use-token) has been removed.
# Next.js (App)
## Installation
### Create application
Create Next.js application.
```bash
pnpm create next-app my-app --typescript
```
```bash
npx create-next-app my-app --typescript
```
```bash
yarn create next-app my-app --typescript
```
```bash
bun create next-app my-app --typescript
```
### Setup
Running the command will create the necessary files and folders in your project.
```bash
pnpm dlx @yamada-ui/cli init
```
```bash
npx @yamada-ui/cli init
```
```bash
yarn dlx @yamada-ui/cli init
```
```bash
bunx @yamada-ui/cli init
```
### Install the package
Install `@workspaces/ui` to your application.
```bash
pnpm add "@workspaces/ui@workspace:*"
```
```bash
npm install "@workspaces/ui@workspace:*"
```
```bash
yarn add "@workspaces/ui@workspace:*"
```
```bash
bun add "@workspaces/ui@workspace:*"
```
### Add provider
After installing, add `UIProvider` to the root of your application.
To suppress hydration errors, add `suppressHydrationWarning` to the `html` and `body` tags.
```tsx
import { UIProvider } from "@yamada-ui/react"
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
{children}
)
}
```
### Use components
After adding `UIProvider`, you can use the components in your application.
```tsx
import { Button } from "@workspaces/ui"
export default function Home() {
return
}
```
That's it! You've successfully set up Yamada UI.
## Scripts
### ColorModeScript
To use [Color Mode](https://yamada-ui.com/docs/theming/color-mode.md), you need to add `ColorModeScript` to the `body` to ensure it works correctly.
This is because color mode is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads.
```tsx
import { UIProvider, ColorModeScript } from "@workspaces/ui"
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
{children}
)
}
```
If you change the `defaultColorMode` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ColorModeScript`.
```tsx
import { UIProvider, ColorModeScript } from "@workspaces/ui"
import { config } from "@workspaces/theme"
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
{children}
)
}
```
### ThemeSchemeScript
To use [theme switching](https://yamada-ui.com/docs/theming/switching-themes.md), you need to add `ThemeSchemeScript` to the `body` to ensure it works correctly.
This is because theme switching is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads.
```tsx
import { UIProvider, ThemeSchemeScript } from "@workspaces/ui"
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
{children}
)
}
```
If you change the `defaultThemeScheme` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ThemeSchemeScript`.
```tsx
import { UIProvider, ThemeSchemeScript } from "@workspaces/ui"
import { config } from "@workspaces/theme"
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
{children}
)
}
```
### Use cookies
Using cookies allows you to ensure proper operation even on server-side rendering.
:::warning
Using [cookies](https://nextjs.org/docs/app/api-reference/functions/cookies) will opt into [dynamic rendering](https://nextjs.org/docs/app/getting-started/partial-prerendering#dynamic-rendering).
:::
```tsx
import { UIProvider, ColorModeScript, ThemeSchemeScript } from "@workspaces/ui"
import { cookies } from "next/headers"
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
const cookieStore = await cookies()
return (
{children}
)
}
```
# Next.js (Pages)
## Installation
### Create application
Create Next.js application.
```bash
pnpm create next-app my-app --typescript
```
```bash
npx create-next-app my-app --typescript
```
```bash
yarn create next-app my-app --typescript
```
```bash
bun create next-app my-app --typescript
```
### Setup
Running the command will create the necessary files and folders in your project.
```bash
pnpm dlx @yamada-ui/cli init
```
```bash
npx @yamada-ui/cli init
```
```bash
yarn dlx @yamada-ui/cli init
```
```bash
bunx @yamada-ui/cli init
```
### Install the package
Install `@workspaces/ui` to your application.
```bash
pnpm add "@workspaces/ui@workspace:*"
```
```bash
npm install "@workspaces/ui@workspace:*"
```
```bash
yarn add "@workspaces/ui@workspace:*"
```
```bash
bun add "@workspaces/ui@workspace:*"
```
### Add provider
After installing, add `UIProvider` to the root of your application.
```tsx
import { UIProvider } from "@workspaces/ui"
import type { AppProps } from "next/app"
export default function App({ Component, pageProps }: AppProps) {
return (
)
}
```
### Use components
After adding `UIProvider`, you can use the components in your application.
```tsx
import { Button } from "@workspaces/ui"
export default function Home() {
return
}
```
That's it! You've successfully set up Yamada UI.
## Scripts
### ColorModeScript
To use [Color Mode](https://yamada-ui.com/docs/theming/color-mode.md), you need to add `ColorModeScript` to the `body` to ensure it works correctly.
This is because color mode is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads.
#### Add Script
```tsx
import { Html, Head, Main, NextScript } from "next/document"
import { ColorModeScript } from "@workspaces/ui"
export default function Document() {
return (
)
}
```
If you change the `defaultColorMode` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ColorModeScript`.
```tsx
import { Html, Head, Main, NextScript } from "next/document"
import { ColorModeScript } from "@workspaces/ui"
import { config } from "@workspace/theme"
export default function Document() {
return (
)
}
```
#### Add getServerSideProps
To share `getServerSideProps` across multiple pages, define `getServerSideSharedProps`.
```tsx
import { GetServerSidePropsContext } from "next"
export const getServerSideSharedProps = ({
req,
}: GetServerSidePropsContext) => {
return {
props: {
cookies: req.headers.cookie ?? "",
},
}
}
```
```tsx
import { getServerSideSharedProps } from "@/get-server-side-props"
import { Button } from "@workspaces/ui"
export const getServerSideProps = getServerSideSharedProps
export default function Home() {
return
}
```
#### Update Provider
```tsx
import { UIProvider } from "@workspaces/ui"
import type { AppProps } from "next/app"
export default function App({ Component, pageProps }: AppProps) {
const { cookie } = pageProps
return (
)
}
```
### ThemeSchemeScript
To use [theme switching](https://yamada-ui.com/docs/theming/switching-themes.md), you need to add `ThemeSchemeScript` to the `body` to ensure it works correctly.
This is because theme switching is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads.
#### Add Script
```tsx
import { Html, Head, Main, NextScript } from "next/document"
import { ThemeSchemeScript } from "@workspaces/ui"
export default function Document() {
return (
)
}
```
If you change the `defaultThemeScheme` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ThemeSchemeScript`.
```tsx
import { Html, Head, Main, NextScript } from "next/document"
import { ThemeSchemeScript } from "@workspaces/ui"
import { config } from "@workspace/theme"
export default function Document() {
return (
)
}
```
#### Add getServerSideProps
To share `getServerSideProps` across multiple pages, define `getServerSideSharedProps`.
```tsx
import { GetServerSidePropsContext } from "next"
export const getServerSideSharedProps = ({
req,
}: GetServerSidePropsContext) => {
return {
props: {
cookies: req.headers.cookie ?? "",
},
}
}
```
```tsx
import { getServerSideSharedProps } from "@/get-server-side-props"
import { Button } from "@workspaces/ui"
export const getServerSideProps = getServerSideSharedProps
export default function Home() {
return
}
```
#### Update Provider
```tsx
import { UIProvider } from "@workspaces/ui"
import type { AppProps } from "next/app"
export default function App({ Component, pageProps }: AppProps) {
const { cookie } = pageProps
return (
)
}
```
# React Router
## Installation
### Create application
Create React Router application.
```bash
pnpm create react-router my-app
```
```bash
npx create-react-router my-app
```
```bash
yarn create react-router my-app
```
```bash
bun create react-router my-app
```
### Setup
Running the command will create the necessary files and folders in your project.
```bash
pnpm dlx @yamada-ui/cli init
```
```bash
npx @yamada-ui/cli init
```
```bash
yarn dlx @yamada-ui/cli init
```
```bash
bunx @yamada-ui/cli init
```
### Install the package
Install `@workspaces/ui` to your application.
```bash
pnpm add "@workspaces/ui@workspace:*"
```
```bash
npm install "@workspaces/ui@workspace:*"
```
```bash
yarn add "@workspaces/ui@workspace:*"
```
```bash
bun add "@workspaces/ui@workspace:*"
```
### Add provider
After installing, add `UIProvider` to the root of your application.
To suppress hydration errors, add `suppressHydrationWarning` to the `html` and `body` tags.
```tsx
import { Meta, Outlet, Scripts, ScrollRestoration } from "react-router"
import { UIProvider } from "@workspaces/ui"
export function Layout({ children }: { children: React.ReactNode }) {
return (
{children}
)
}
export default function App() {
return
}
```
### Use components
After adding `UIProvider`, you can use the components in your application.
```tsx
import { Button } from "@workspaces/ui"
export default function Home() {
return
}
```
That's it! You've successfully set up Yamada UI.
## スクリプト
### ColorModeScript
To use [Color Mode](https://yamada-ui.com/docs/theming/color-mode.md), you need to add `ColorModeScript` to the `body` to ensure it works correctly.
This is because color mode is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads.
```tsx
import {
data,
Meta,
Outlet,
Scripts,
ScrollRestoration,
useRouteLoaderData,
} from "react-router"
import { ColorModeScript, UIProvider } from "@workspaces/ui"
import type { Route } from "./+types/root"
export async function loader({ request }: Route.LoaderArgs) {
const cookie = request.headers.get("cookie") ?? ""
return data({ cookie })
}
export function Layout({ children }: { children: React.ReactNode }) {
const { cookie } = useRouteLoaderData("root")
return (
{children}
)
}
export default function App() {
return
}
```
If you change the `defaultColorMode` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ColorModeScript`.
```tsx
import {
data,
Meta,
Outlet,
Scripts,
ScrollRestoration,
useRouteLoaderData,
} from "react-router"
import { ColorModeScript, UIProvider } from "@workspaces/ui"
import type { Route } from "./+types/root"
import { config } from "@workspace/theme"
export async function loader({ request }: Route.LoaderArgs) {
const cookie = request.headers.get("cookie") ?? ""
return data({ cookie })
}
export function Layout({ children }: { children: React.ReactNode }) {
const { cookie } = useRouteLoaderData("root")
return (
{children}
)
}
export default function App() {
return
}
```
### ThemeSchemeScript
To use [theme switching](https://yamada-ui.com/docs/theming/switching-themes.md), you need to add `ThemeSchemeScript` to the `body` to ensure it works correctly.
This is because theme switching is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads.
```tsx
import {
data,
Meta,
Outlet,
Scripts,
ScrollRestoration,
useRouteLoaderData,
} from "react-router"
import { ThemeSchemeScript, UIProvider } from "@workspaces/ui"
import type { Route } from "./+types/root"
export async function loader({ request }: Route.LoaderArgs) {
const cookie = request.headers.get("cookie") ?? ""
return data({ cookie })
}
export function Layout({ children }: { children: React.ReactNode }) {
const { cookie } = useRouteLoaderData("root")
return (
{children}
)
}
export default function App() {
return
}
```
If you change the `defaultThemeScheme` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ThemeSchemeScript`.
```tsx
import {
data,
Meta,
Outlet,
Scripts,
ScrollRestoration,
useRouteLoaderData,
} from "react-router"
import { ThemeSchemeScript, UIProvider } from "@workspaces/ui"
import type { Route } from "./+types/root"
import { config } from "@workspace/theme"
export async function loader({ request }: Route.LoaderArgs) {
const cookie = request.headers.get("cookie") ?? ""
return data({ cookie })
}
export function Layout({ children }: { children: React.ReactNode }) {
const { cookie } = useRouteLoaderData("root")
return (
{children}
)
}
export default function App() {
return
}
```
# Vite
## Installation
### Create application
Create Vite application.
```bash
pnpm create vite my-app --template react-ts
```
```bash
npm create vite my-app -- --template react-ts
```
```bash
yarn create vite my-app --template react-ts
```
```bash
bun create vite my-app --template react-ts
```
### Setup
Running the command will create the necessary files and folders in your project.
```bash
pnpm dlx @yamada-ui/cli init
```
```bash
npx @yamada-ui/cli init
```
```bash
yarn dlx @yamada-ui/cli init
```
```bash
bunx @yamada-ui/cli init
```
### Install the package
Install `@workspaces/ui` to your application.
```bash
pnpm add "@workspaces/ui@workspace:*"
```
```bash
npm install "@workspaces/ui@workspace:*"
```
```bash
yarn add "@workspaces/ui@workspace:*"
```
```bash
bun add "@workspaces/ui@workspace:*"
```
### Add provider
After installing, add `UIProvider` to the root of your application.
```tsx
import { StrictMode } from "react"
import { createRoot } from "react-dom/client"
import App from "./App.tsx"
import { UIProvider } from "@workspaces/ui"
createRoot(document.getElementById("root")!).render(
,
)
```
### Use components
After adding `UIProvider`, you can use the components in your application.
```tsx
import { Button } from "@workspaces/ui"
function App() {
return
}
export default App
```
That's it! You've successfully set up Yamada UI.
## Scripts
### ColorModeScript
To use [Color Mode](https://yamada-ui.com/docs/theming/color-mode.md), you need to add `ColorModeScript` to the `body` to ensure it works correctly.
This is because color mode is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads.
```ts title="vite.config.ts" {1,4-18,22}
import type { Plugin } from "vite"
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import { COLOR_MODE_STORAGE_KEY, getStorageScript } from "@workspaces/ui"
function injectColorModeScript(): Plugin {
return {
name: "inject-color-mode-script",
transformIndexHtml(html) {
const content = getStorageScript(
"colorMode",
COLOR_MODE_STORAGE_KEY,
)({ defaultValue: "light" })
return html.replace("", ``)
},
}
}
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), injectColorModeScript()],
})
```
If you change the `defaultColorMode` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ColorModeScript`.
```ts title="vite.config.ts" {5,14}
import type { Plugin } from "vite"
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import { COLOR_MODE_STORAGE_KEY, getStorageScript } from "@workspaces/ui"
import { config } from "@workspace/theme"
function injectColorModeScript(): Plugin {
return {
name: "inject-color-mode-script",
transformIndexHtml(html) {
const content = getStorageScript(
"colorMode",
COLOR_MODE_STORAGE_KEY,
)({ defaultValue: config.defaultColorMode })
return html.replace("", ``)
},
}
}
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), injectColorModeScript()],
})
```
### ThemeSchemeScript
To use [theme switching](https://yamada-ui.com/docs/theming/switching-themes.md), you need to add `ThemeSchemeScript` to the `body` to ensure it works correctly.
This is because theme switching is implemented using `localStorage` or `cookies`, and adding the script ensures proper synchronization when the page loads.
```ts title="vite.config.ts" {1,4-18,22}
import type { Plugin } from "vite"
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import { getStorageScript, THEME_SCHEME_STORAGE_KEY } from "@workspaces/ui"
function injectThemeSchemeScript(): Plugin {
return {
name: "inject-theme-scheme-scripts",
transformIndexHtml(html) {
const content = getStorageScript(
"themeScheme",
THEME_SCHEME_STORAGE_KEY,
)({ defaultValue: "base" })
return html.replace("", ``)
},
}
}
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), injectThemeSchemeScript()],
})
```
If you change the `defaultThemeScheme` in your [config](https://yamada-ui.com/docs/theming/configuration/overview.md), set the `defaultValue` prop on `ThemeSchemeScript`.
```ts title="vite.config.ts" {5,14}
import type { Plugin } from "vite"
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import { getStorageScript, THEME_SCHEME_STORAGE_KEY } from "@workspaces/ui"
import { config } from "@workspace/theme"
function injectThemeSchemeScript(): Plugin {
return {
name: "inject-theme-scheme-scripts",
transformIndexHtml(html) {
const content = getStorageScript(
"themeScheme",
THEME_SCHEME_STORAGE_KEY,
)({ defaultValue: config.defaultThemeScheme })
return html.replace("", ``)
},
}
}
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), injectThemeSchemeScript()],
})
```