Skip to content

Commit

Permalink
chore: more example code
Browse files Browse the repository at this point in the history
  • Loading branch information
shlroland committed Sep 13, 2024
1 parent 373602f commit 93ebf10
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 75 deletions.
4 changes: 3 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"preview": "vite preview"
},
"dependencies": {
"clsx": "^2.1.1",
"next-themes": "^0.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"tailwind-merge": "^2.5.2"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
Expand Down
17 changes: 17 additions & 0 deletions example/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions example/src/App.css

This file was deleted.

37 changes: 7 additions & 30 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
import { useState } from 'react'

import reactLogo from './assets/react.svg'

import viteLogo from '/vite.svg'
import './App.css'
import { Sidebar, SidebarItem } from './sidebar'

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

return (
<>
<div>
<a href="https://vitejs.dev" target="_blank" rel="noreferrer">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank" rel="noreferrer">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
<main className="bg-muted/50 flex h-dvh flex-1 flex-col">
<Sidebar>
<SidebarItem selected>auto stay</SidebarItem>
<SidebarItem>manual stay</SidebarItem>
</Sidebar>
</main>
)
}

Expand Down
1 change: 0 additions & 1 deletion example/src/assets/react.svg

This file was deleted.

6 changes: 6 additions & 0 deletions example/src/cn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import clsx, { type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
2 changes: 1 addition & 1 deletion example/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'

import App from './App.tsx'
import '@unocss/reset/tailwind.css'
import 'virtual:uno.css'
import '@unocss/reset/tailwind-compat.css'

createRoot(document.getElementById('root')!).render(
<StrictMode>
Expand Down
39 changes: 39 additions & 0 deletions example/src/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { type PropsWithChildren } from 'react'
import { cn } from './cn'

export function Sidebar(props: PropsWithChildren) {
return (
<div className="relative flex h-full overflow-hidden">
<div className="peer absolute inset-y-0 z-30 hidden border-r bg-muted duration-300 ease-in-out data-[state=open]:translate-x-0 lg:flex lg:w-[250px] xl:w-[300px] h-full flex-col dark:bg-zinc-950">
<div className="flex h-full flex-col">
<div className="flex flex-1 flex-col overflow-hidden">
<div className="flex-1 overflow-auto py-8 space-y-2">
{props.children}
</div>
</div>
</div>
</div>
</div>
)
}

export function SidebarItem(props: PropsWithChildren<{ selected?: boolean }>) {
return (
<>
<div className="space-y-2 px-2">
<div>
<div className="relative h-8">
<div
className={cn(
'inline-flex items-center whitespace-nowrap rounded-md text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 hover:text-accent-foreground h-9 py-2 group w-full px-8 transition-colors hover:bg-zinc-200/40 dark:hover:bg-zinc-300/10 cursor-pointer',
props.selected ? 'bg-zinc-200/40 dark:bg-zinc-300/10' : '',
)}
>
{props.children}
</div>
</div>
</div>
</div>
</>
)
}

0 comments on commit 93ebf10

Please sign in to comment.