Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/vite-css/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
46 changes: 46 additions & 0 deletions examples/vite-css/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React + Base UI (styled with plain CSS) working in Vite with HMR and some ESLint rules.

## Getting Started

### Prerequisites

- [Node.js](https://nodejs.org/) (version 20.19+ or 22.12+ is required)
- [pnpm](https://pnpm.io/) (or use npm/yarn if preferred)

### Install dependencies

```bash
pnpm install
```

### Run the development server

```bash
pnpm dev
```

This will start the Vite development server. Open [http://localhost:5173](http://localhost:5173) to view the app in your browser.

Check warning on line 24 in examples/vite-css/README.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.Will] Avoid using 'will'. Raw Output: {"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "examples/vite-css/README.md", "range": {"start": {"line": 24, "column": 6}}}, "severity": "WARNING"}

### Build for production

```bash
pnpm build
```

### Preview the production build

```bash
pnpm preview
```

Make sure to build the project for production with `pnpm build` first.

## Linting

To run ESLint:

```bash
pnpm lint
```
25 changes: 25 additions & 0 deletions examples/vite-css/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
},
},
);
14 changes: 14 additions & 0 deletions examples/vite-css/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + Base UI + TS</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions examples/vite-css/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "vite-css-base-ui-example",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@base-ui-components/react": "latest",
"clsx": "^2.1.1",
"react": "^19.1.1",
"react-dom": "^19.1.1"
},
"devDependencies": {
"@eslint/js": "^9.32.0",
"@types/react": "^19.1.9",
"@types/react-dom": "^19.1.7",
"@vitejs/plugin-react": "^5.0.0",
"eslint": "^9.32.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.20",
"globals": "^16.3.0",
"typescript": "^5.9.2",
"typescript-eslint": "^8.39.0",
"vite": "^7.1.1"
}
}
52 changes: 52 additions & 0 deletions examples/vite-css/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}

.logo.vite:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}

.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

.logo.base-ui:hover {
filter: drop-shadow(0 0 2em #626262aa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}

to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
.logo.react {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
display: flex;
flex-direction: column;
align-items: center;
}

.read-the-docs {
color: #888;
}
39 changes: 39 additions & 0 deletions examples/vite-css/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as React from 'react';
import reactLogo from './assets/react.svg';
import viteLogo from './assets/vite.svg';
import baseUILogo from './assets/base-ui.svg';
import { Switch } from './widgets/Switch';
import './App.css';

function App() {
const [count, setCount] = React.useState(0);

return (
<React.Fragment>
<div>
<a href="https://vite.dev" target="_blank" rel="noopener noreferrer">
<img src={viteLogo} className="logo vite" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank" rel="noopener noreferrer">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
<a href="https://base-ui.com" target="_blank" rel="noopener noreferrer">
<img src={baseUILogo} className="logo base-ui" alt="Base UI logo" />
</a>
</div>
<h1>Vite + React + Base UI</h1>
<div className="card">
<Switch onCheckedChange={() => setCount((c) => c + 1)} />
<p>
Flicked the Switch {count} time{count !== 1 ? 's' : ''}.
</p>
<p>
Edit <code>src/App.tsx</code> and save to test HMR.
</p>
</div>
<p className="read-the-docs">Click on the Vite, React, and Base UI logos to learn more.</p>
</React.Fragment>
);
}

export default App;
5 changes: 5 additions & 0 deletions examples/vite-css/src/assets/base-ui.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/vite-css/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/vite-css/src/assets/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions examples/vite-css/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
:root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgb(255 255 255 / 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;

--color-blue: oklch(45% 50% 264deg);
--color-red: oklch(50% 55% 31deg);

--color-gray-50: oklch(98.42% 0.0034 247.86deg);
--color-gray-100: oklch(12% 9.5% 264deg / 5%);
--color-gray-200: oklch(12% 9% 264deg / 8%);
--color-gray-300: oklch(12% 8.5% 264deg / 17%);
--color-gray-400: oklch(12% 8% 264deg / 38%);
--color-gray-500: oklch(12% 7.5% 264deg / 50%);
--color-gray-600: oklch(12% 7% 264deg / 67%);
--color-gray-700: oklch(12% 6% 264deg / 77%);
--color-gray-800: oklch(12% 5% 264deg / 85%);
--color-gray-900: oklch(12% 5% 264deg / 90%);
--color-gray-950: oklch(12% 5% 264deg / 95%);

@media (prefers-color-scheme: dark) {
--color-blue: oklch(69% 50% 264deg);
--color-red: oklch(80% 55% 31deg);

--color-gray-50: oklch(17% 1% 264deg);
--color-gray-100: oklch(28% 3% 264deg / 65%);
--color-gray-200: oklch(31% 3% 264deg / 80%);
--color-gray-300: oklch(35% 3% 264deg / 80%);
--color-gray-400: oklch(47% 3.5% 264deg / 80%);
--color-gray-500: oklch(64% 4% 264deg / 80%);
--color-gray-600: oklch(82% 4% 264deg / 80%);
--color-gray-700: oklch(92% 4.5% 264deg / 80%);
--color-gray-800: oklch(93% 3.5% 264deg / 85%);
--color-gray-900: oklch(95% 2% 264deg / 90%);
--color-gray-950: oklch(94% 1.5% 264deg / 95%);
}
}

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;
}
}
10 changes: 10 additions & 0 deletions examples/vite-css/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom/client';
import App from './App.tsx';
import './index.css';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
1 change: 1 addition & 0 deletions examples/vite-css/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Loading
Loading