Getting Started
IntroductionHow to Use
Components
FrameMenuAlertAccordionDialogTabsToastNewButtonInputSwitchTextareaRadio GroupCheckboxChartComboboxSelectNewAlert DialogSoonAvatarSoonBreadcrumbSoonButton GroupSoonCalendarSoonDatepickerSoonDaterangepickerSoonSheetSoonNumber InputSoonPaginationSoonTableSoon

How to Use

Install and configure Cosmic UI for Vite.
Create project

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

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

Replace everything insrc/index.csswith 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 thebaseUrlandpathsproperties to thecompilerOptionssection of thetsconfig.jsonandtsconfig.app.jsonfiles:

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 thetsconfig.app.jsonfile 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 vue from "@vitejs/plugin-vue"
import { defineConfig } from "vite"

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), 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.vue
Expand

<script setup lang="ts">
import Button from "@/components/ui/button.vue";
</script>

<template>
  <div class="flex min-h-svh flex-col items-center justify-center">
    <Button variant="success">Button</Button>
  </div>
</template>
 
Expand
Powered by synthetic caffeine · Deployed by Left4code · Signal traceable on GitHub.