Installation
yarcl needs React 18 or newer and Vite 5 or newer.
-
Install the package.
Terminal window pnpm add yarclTerminal window npm install yarclTerminal window yarn add yarcl -
Add the Vite plugin. It points the library at your config and generates the CSS.
vite.config.ts import react from '@vitejs/plugin-react';import { defineConfig } from 'vite';import { yarcl } from 'yarcl/plugin';export default defineConfig({plugins: [react(), yarcl({ config: 'src/yarcl.config.ts' })],}); -
Point TypeScript at the same file, so the prop types come from your config.
tsconfig.json {"compilerOptions": {"moduleResolution": "bundler","paths": {"@yarcl/config": ["./src/yarcl.config.ts","./node_modules/yarcl/src/yarcl.config.ts"]}}}The second entry is a fallback: if your config file doesn’t exist, the types come from the library defaults. The plugin falls back the same way at runtime.
-
Create your config. Start from the library defaults and change what you need.
src/yarcl.config.ts import { defineConfig } from 'yarcl/define';import defaults from 'yarcl/defaults';export default defineConfig({...defaults,colors: {...defaults.colors,brand: { light: '#2d4bb8', dark: '#8aa2ff' },},defaults: { ...defaults.defaults, color: 'brand' },}); -
Use the components. Importing from
yarclalso loads the generated CSS.src/App.tsx import { Button } from 'yarcl';export function App() {return <Button color="brand">It works</Button>;}
Page styles
Section titled “Page styles”yarcl doesn’t style body. Use the generated CSS variables to match the page to your config:
body { margin: 0; font-family: var(--yarcl-font-sans); color: var(--yarcl-neutral-text); background: var(--yarcl-neutral-bg);}Keep both mappings in sync
Section titled “Keep both mappings in sync”The Vite plugin and the tsconfig.json paths entry must point at the same file. If they don’t, the types and the rendered styles come from different configs. See the Vite plugin for details.