8-bit Difficulty Select
8bitcn/difficulty-selectFreeBlock
A reusable 8-bit difficulty selector with Easy, Normal, Hard.
Install it
npx shadcn@latest add https://www.8bitcn.com/r/difficulty-select.jsonSource
1"use client";23import * as React from "react";45import { cn } from "@/lib/utils";67import { Button } from "@/components/ui/8bit/button";8import {9 Card,10 CardContent,11 CardDescription,12 CardHeader,13 CardTitle,14} from "@/components/ui/8bit/card";1516export type Difficulty = "easy" | "normal" | "hard";1718export interface DifficultySelectProps19 extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {20 value?: Difficulty;21 defaultValue?: Difficulty;22 onChange?: (value: Difficulty) => void;23 title?: string;24 description?: string;25 vertical?: boolean;26}2728export default function DifficultySelect({29 className,30 value,31 defaultValue = "normal",32 onChange,33 title = "Select Difficulty",34 description,35 vertical = true,36 ...props37}: DifficultySelectProps) {38 const isControlled = value !== undefined;39 const [internalValue, setInternalValue] =40 React.useState<Difficulty>(defaultValue);4142 const selected = isControlled ? (value as Difficulty) : internalValue;4344 const setSelected = React.useCallback(45 (next: Difficulty) => {46 if (!isControlled) setInternalValue(next);47 onChange?.(next);48 },49 [isControlled, onChange]50 );5152 return (53 <Card className={cn(className)} {...props}>54 <CardHeader className="flex flex-col items-center justify-center gap-4">55 <CardTitle>{title}</CardTitle>56 {description ? <CardDescription>{description}</CardDescription> : null}57 </CardHeader>58 <CardContent>59 <div60 className={cn("gap-4", vertical ? "flex flex-col" : "flex flex-row")}61 >62 <Button63 className="flex items-center justify-center"64 variant={selected === "easy" ? "default" : "secondary"}65 onClick={() => setSelected("easy")}66 >67 EASY68 </Button>69 <Button70 className="flex items-center justify-center"71 variant={selected === "normal" ? "default" : "secondary"}72 onClick={() => setSelected("normal")}73 >74 NORMAL75 </Button>76 <Button77 className="flex items-center justify-center"78 variant={selected === "hard" ? "default" : "secondary"}79 onClick={() => setSelected("hard")}80 >81 HARD82 </Button>83 </div>84 </CardContent>85 </Card>86 );87}
What it pulls in
Other registry items
Files it writes
More from 8bitcn
All 121 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| 8-bit Advanced 1advanced1 | 8bitcn | Blocks | Free | no deps · 3 files | |
| 8-bit Advanced 2advanced2 | 8bitcn | Blocks | Free | no deps · 5 files | |
| 8-bit Advanced 3advanced3 | 8bitcn | Blocks | Free | no deps · 6 files | |
| 8-bit Audio Settingsaudio-settings | 8bitcn | Blocks | Free | 2 deps · 7 files | |
| 8-bit Chapter Introchapter-intro | 8bitcn | Blocks | Free | no deps · 3 files | |
| 8-bit Character Sheetcharacter-sheet | 8bitcn | Blocks | Free | no deps · 9 files | |
| 8-bit Chartchart | 8bitcn | Blocks | Free | no deps · 3 files | |
| 8-bit Chart Area Stepchart-area-step | 8bitcn | Blocks | Free | no deps · 3 files |
