创建主题
你可以基于默认主题创建一个新主题。假设你需要一个 purple-dark
主题。你可以通过将以下代码添加到你的 tailwind.config.js
文件中来创建它。
We recommend adding a palette that ranges from 50
to 900
. You can use tools like Eva Design System,
Smart Watch, Palette or Color Box to generate your palette.
将新主题添加到插件
// tailwind.config.jsconst {nextui} = require("@nextui-org/react");/** @type {import('tailwindcss').Config} */module.exports = {plugins: [nextui({themes: {"purple-dark": {extend: "dark", // <- inherit default values from dark themecolors: {background: "#0D001A",foreground: "#ffffff",primary: {50: "#3B096C",100: "#520F83",200: "#7318A2",300: "#9823C2",400: "#c031e2",500: "#DD62ED",600: "#F182F6",700: "#FCADF9",800: "#FDD5F9",900: "#FEECFE",DEFAULT: "#DD62ED",foreground: "#ffffff",},focus: "#F182F6",},layout: {disabledOpacity: "0.3",radius: {small: "4px",medium: "6px",large: "8px",},borderWidth: {small: "1px",medium: "2px",large: "3px",},},},},}),],};
应用新主题
现在,应用新主题就像将主题名称 purple-dark
添加到 className
的 html
/ body
或 main
元素一样简单。
// main.tsx or main.jsximport React from "react";import ReactDOM from "react-dom/client";import {NextUIProvider} from "@nextui-org/react";import App from "./App";import "./index.css";ReactDOM.createRoot(document.getElementById("root")).render(<React.StrictMode><NextUIProvider><main className="purple-dark text-foreground bg-background"><App /></main></NextUIProvider></React.StrictMode>,);
使用新主题
使用 primary
颜色的所有组件都将受到此更改的影响。
import {Button} from "@nextui-org/react";export default function App() {return (<div className="flex flex-wrap gap-4 items-center"><Button color="primary" variant="solid">Solid</Button><Button color="primary" variant="faded">Faded</Button><Button color="primary" variant="bordered">Bordered</Button><Button color="primary" variant="light">Light</Button><Button color="primary" variant="flat">Flat</Button><Button color="primary" variant="ghost">Ghost</Button><Button color="primary" variant="shadow">Shadow</Button></div>);}