Skip to content

Commit

Permalink
doc: Add RGB demo
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Jan 26, 2024
1 parent 3e36891 commit b60ef54
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ export default function BasicCounterDemoPage() {
)
return (
<>
<nav className="my-8 flex flex-wrap gap-4">
<Button size="sm" onClick={() => setCounter(x => x - 1)}>
<nav className="my-8 flex flex-wrap items-center gap-4">
<Button onClick={() => setCounter(x => x - 1)}>
<Minus />
</Button>
<Button size="sm" onClick={() => setCounter(x => x + 1)}>
<Button onClick={() => setCounter(x => x + 1)}>
<Plus />
</Button>
<Button size="sm" onClick={() => setCounter(null)}>
Reset
</Button>
<Button onClick={() => setCounter(null)}>Reset</Button>
<span className="text-2xl font-semibold tabular-nums">
Counter: {counter}
</span>
Expand Down
4 changes: 4 additions & 0 deletions packages/docs/src/app/playground/(demos)/demos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const demos = {
title: 'Batching',
description:
'State updates are collected and batched into one update on the next tick.'
},
'hex-colors': {
title: 'Hex colors',
description: 'Parsing RGB values from a hex color'
}
} as const satisfies Record<string, DemoMetadata>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ export default function HexColorsDemo() {
)
const asHex = '#' + hexColorSchema.serialize(color)
return (
<>
<h1>Hex colors</h1>
<section>
<div>
<div className="flex flex-wrap-reverse items-center gap-4">
<div
className="h-64 w-64 rounded border"
style={{
backgroundColor: `rgb(${color.r} ${color.g} ${color.b})`
}}
/>
<section className="space-y-2">
<div className="flex items-center">
<label>Color</label>
<input
type="color"
Expand Down Expand Up @@ -82,19 +87,7 @@ export default function HexColorsDemo() {
}
/>
</section>
<div
style={{
height: '200px',
width: '200px',
backgroundColor: `rgb(${color.r} ${color.g} ${color.b})`
}}
></div>
<p>
<a href="https://github.com/47ng/nuqs/tree/next/packages/docs/src/app/(pages)/playground/hex-colors/page.tsx">
Source on GitHub
</a>
</p>
</>
</div>
)
}

Expand All @@ -112,15 +105,7 @@ const ColorSlider = ({
accentColor
}: ColorSliderProps) => {
return (
<div
style={{
display: 'flex',
alignItems: 'center',
gap: '4px',
// @ts-ignore
accentColor
}}
>
<div className="flex items-center gap-4" style={{ accentColor }}>
<label>{label}</label>
<input
type="range"
Expand Down
20 changes: 20 additions & 0 deletions packages/docs/src/app/playground/(demos)/hex-colors/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Description } from '@/src/components/typography'
import { Suspense } from 'react'
import { SourceOnGitHub } from '../_components/source-on-github'
import { getMetadata } from '../demos'
import Client from './client'

export const metadata = getMetadata('hex-colors')

export default function HexColorsDemoPage() {
return (
<>
<h1>{metadata.title}</h1>
<Description>{metadata.description}</Description>
<Suspense>
<Client />
</Suspense>
<SourceOnGitHub path="hex-colors/client.tsx" />
</>
)
}
2 changes: 1 addition & 1 deletion packages/docs/src/app/playground/(demos)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function PlaygroundDemoLayout({
<Suspense fallback={<QuerySpySkeleton>&nbsp;</QuerySpySkeleton>}>
<QuerySpy />
</Suspense>
<main className="py-2 md:py-10">{children}</main>
<main className="py-2 md:py-4">{children}</main>
</>
)
}

0 comments on commit b60ef54

Please sign in to comment.