|
1 | 1 | 'use client'
|
2 | 2 |
|
| 3 | +import { CodeBlock } from '@/src/components/code-block.client' |
3 | 4 | import { QuerySpy } from '@/src/components/query-spy'
|
4 | 5 | import { ContainerQueryHelper } from '@/src/components/responsive-helpers'
|
5 | 6 | import { Button } from '@/src/components/ui/button'
|
6 | 7 | import { Checkbox } from '@/src/components/ui/checkbox'
|
| 8 | +import { |
| 9 | + Pagination, |
| 10 | + PaginationButton, |
| 11 | + PaginationContent, |
| 12 | + PaginationItem, |
| 13 | + PaginationNext, |
| 14 | + PaginationPrevious |
| 15 | +} from '@/src/components/ui/pagination' |
7 | 16 | import { Slider } from '@/src/components/ui/slider'
|
8 | 17 | import { cn } from '@/src/lib/utils'
|
9 | 18 | import { ChevronDown, ChevronUp, Minus, Star } from 'lucide-react'
|
@@ -173,25 +182,46 @@ export function HexParserDemo() {
|
173 | 182 | }
|
174 | 183 |
|
175 | 184 | export function IndexParserDemo() {
|
176 |
| - const [value, setValue] = useQueryState('page', parseAsIndex) |
| 185 | + const numPages = 5 |
| 186 | + const [pageIndex, setPageIndex] = useQueryState( |
| 187 | + 'page', |
| 188 | + parseAsIndex.withDefault(0).withOptions({ clearOnDefault: false }) |
| 189 | + ) |
177 | 190 | return (
|
178 | 191 | <DemoContainer demoKey="page">
|
179 |
| - <input |
180 |
| - type="number" |
181 |
| - className="flex h-10 flex-1 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50" |
182 |
| - value={value ?? ''} // Handle empty input |
183 |
| - onChange={e => { |
184 |
| - if (e.target.value === '') { |
185 |
| - setValue(null) |
186 |
| - } else { |
187 |
| - setValue(e.target.valueAsNumber) |
188 |
| - } |
189 |
| - }} |
190 |
| - placeholder="What page are you on?" |
| 192 | + <Pagination className="not-prose items-center gap-2"> |
| 193 | + <PaginationContent> |
| 194 | + <PaginationItem> |
| 195 | + <PaginationPrevious |
| 196 | + disabled={pageIndex === 0} |
| 197 | + onClick={() => setPageIndex(p => Math.max(0, p - 1))} |
| 198 | + /> |
| 199 | + </PaginationItem> |
| 200 | + {Array.from({ length: numPages }, (_, i) => ( |
| 201 | + <PaginationItem key={i}> |
| 202 | + <PaginationButton |
| 203 | + isActive={pageIndex === i} |
| 204 | + onClick={() => setPageIndex(i)} |
| 205 | + > |
| 206 | + {i + 1} |
| 207 | + </PaginationButton> |
| 208 | + </PaginationItem> |
| 209 | + ))} |
| 210 | + <PaginationItem> |
| 211 | + <PaginationNext |
| 212 | + disabled={pageIndex === numPages - 1} |
| 213 | + onClick={() => setPageIndex(p => Math.min(numPages - 1, p + 1))} |
| 214 | + /> |
| 215 | + </PaginationItem> |
| 216 | + </PaginationContent> |
| 217 | + </Pagination> |
| 218 | + <CodeBlock |
| 219 | + className="my-0 flex-1 [&_pre]:py-1" |
| 220 | + code={`pageIndex: ${pageIndex} // internal state is zero-indexed`} |
191 | 221 | />
|
192 | 222 | <Button
|
193 | 223 | variant="secondary"
|
194 |
| - onClick={() => setValue(null)} |
| 224 | + onClick={() => setPageIndex(null)} |
195 | 225 | className="ml-auto"
|
196 | 226 | >
|
197 | 227 | Clear
|
|
0 commit comments