How to Use

Install and configure Cosmic UI for Vite.
Create project

Start by creating a new React project using vite. Select the React + TypeScript template:

pnpm
npm
yarn
bun
yarn create vite@latest
Add Tailwind CSS
pnpm
npm
yarn
bun
yarn add tailwindcss @tailwindcss/vite

Replace everything in src/index.css with the following:

src/index.css
Expand

@import "tailwindcss";
 
Expand
Edit tsconfig.json file

The current version of Vite splits TypeScript configuration into three files, two of which need to be edited. Add the baseUrl and paths properties to the compilerOptions section of the tsconfig.json and tsconfig.app.json files:

tsconfig.json
Expand

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.node.json"
    }
  ],
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}
 
Expand
Edit tsconfig.app.json file

Add the following code to the tsconfig.app.json file to resolve paths, for your IDE:

tsconfig.app.json
Expand

{
  "compilerOptions": {
    // ...
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
    // ...
  }
}
 
Expand
Update vite.config.ts

Add the following code to the vite.config.ts so your app can resolve paths without error:

pnpm
npm
yarn
bun
yarn add -D @types/node
vite.config.ts
Expand

import path from "path"
import tailwindcss from "@tailwindcss/vite"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"

// https://vite.dev/config/
export default defineConfig({
  plugins: [react(), tailwindcss()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
})
 
Expand
Install with the CLI

The fastest way. It writes each component plus everything that component imports, then installs the packages they need.

Expand

npx @left4code/cosmic-ui-cli@latest init
 
Expand

Then add components. Dependencies between components are resolved for you, so this also writes button, frame, portal and presence.

Expand

npx @left4code/cosmic-ui-cli@latest add dialog
 
Expand

Run npx @left4code/cosmic-ui-cli@latest list to see everything available. The steps below are the manual alternative.

Add Components

You can now start adding components to your project.

src/App.tsx
Expand

import { Button } from "@/components/ui/button";

function App() {
  return (
    <div className="flex min-h-svh flex-col items-center justify-center">
      <Button variant="success">Button</Button>
    </div>
  )
}

export default App
 
Expand
Powered by synthetic caffeine · Deployed by Left4code · Signal traceable on GitHub.