Installation

KARAKURI UIコンポーネントをプロジェクトにインストールして使う方法

Install

@karakuri-ui/reactv0.3.3
Terminal
# npm
npm install @karakuri-ui/react @karakuri-ui/tokens

# yarn
yarn add @karakuri-ui/react @karakuri-ui/tokens

# pnpm
pnpm add @karakuri-ui/react @karakuri-ui/tokens
Tailwind 必須: このパッケージは Tailwind CSS が必要です。下記の Setup セクションで設定してください。 tailwindcss.com

Setup

Step 1. Tailwind をインストール

Terminal
npm install tailwindcss @tailwindcss/postcss postcss

Step 2. PostCSS 設定ファイルを作成

postcss.config.mjs
const config = {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};

export default config;

Step 3. グローバル CSS を編集

app/globals.css
@import "tailwindcss";
@import '@karakuri-ui/tokens/tailwind/v4.css';

@source "../node_modules/@karakuri-ui/react/dist";
個別インポート
@import "tailwindcss";

@import '@karakuri-ui/tokens/css/variables.css';
@import '@karakuri-ui/tokens/css/themes/light.css';
@import '@karakuri-ui/tokens/css/themes/dark.css';
@import '@karakuri-ui/tokens/tailwind/v4-theme.css';

@source "../node_modules/@karakuri-ui/react/dist";

Tips

Next.js

スタイルが崩れる場合

globals.css* や要素セレクタのルールがある場合、@layer base で囲むことで Tailwind ユーティリティとの競合を防げます。

app/globals.css— 例を表示
app/globals.css
@layer base {
  * {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
  }
}
Vite

コンポーネントのスタイルが崩れる場合

Vite テンプレートの src/index.css には :root · button · body 等のデフォルトブロックが含まれており、コンポーネントスタイルを上書きします。以下をすべて削除してください。

src/index.css— 削除するブロック
src/index.css
:root {
  font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  font-weight: 400;
  color-scheme: light dark;
  color: rgba(255, 255, 255, 0.87);
  background-color: #242424;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  font-weight: 500;
  color: #646cff;
  text-decoration: inherit;
}
a:hover {
  color: #535bf2;
}

body {
  margin: 0;
  display: flex;
  place-items: center;
  min-width: 320px;
  min-height: 100vh;
}

h1 {
  font-size: 3.2em;
  line-height: 1.1;
}

button {
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.6em 1.2em;
  font-size: 1em;
  font-weight: 500;
  font-family: inherit;
  background-color: #1a1a1a;
  cursor: pointer;
  transition: border-color 0.25s;
}
button:hover {
  border-color: #646cff;
}
button:focus,
button:focus-visible {
  outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
  :root {
    color: #213547;
    background-color: #ffffff;
  }
  a:hover {
    color: #747bff;
  }
  button {
    background-color: #f9f9f9;
  }
}

Usage

Import & Usage

example.tsx
import {
  Card, CardHeader, CardTitle, CardDescription,
  CardContent, CardFooter, Button,
} from '@karakuri-ui/react'

<Card>
  <CardHeader>
    <CardTitle>Project Settings</CardTitle>
    <CardDescription>Manage your project configuration.</CardDescription>
  </CardHeader>
  <CardContent>
    <p>Content here</p>
  </CardContent>
  <CardFooter>
    <Button variant="outline">Cancel</Button>
    <Button>Save</Button>
  </CardFooter>
</Card>

Requirements

パッケージバージョン
react≥ 18.0.0
react-dom≥ 18.0.0
tailwindcssv4
@karakuri-ui/tokens必須(同時インストール)

Package Contents

2つのパッケージで構成されています。コンポーネントとトークンを別々に管理できます。

@karakuri-ui/react

UIコンポーネントライブラリ — dist/ 配布

index.js / .mjs / .d.ts
Main
chart.js / .mjs / .d.ts
Chart
import { Button, Card, Modal } from '@karakuri-ui/react'import { Chart } from '@karakuri-ui/react/chart'
@karakuri-ui/tokens

デザイントークン — CSS変数・Tailwindプリセット・JS

CSS

4

variables, light, dark, all

Tailwind

3

v3-preset, v4-theme, v4

JS / Types

4

CJS, ESM, .d.ts, JSON

figma-tokens.jsonnpx sync-tokens で全ファイル自動生成

Package Contents

Token Sync

デザインをカスタマイズ

トークンを変更するとコンポーネントのスタイルに自動反映

FigmaJSONsync-tokensCSS + Components
$ npx sync-tokensToken Sync