choice-poll
cult-ui/choice-pollUnverifiedComponent
Poll component with single or multiple selection, optional results, and keyboard navigation
Install it
npx shadcn@latest add https://raw.githubusercontent.com/nolly-studio/cult-ui/HEAD/apps/www/choice-poll.jsonSource
1"use client"23import {4 createContext,5 useCallback,6 useContext,7 useEffect,8 useMemo,9 useRef,10 useState,11 type ComponentProps,12 type KeyboardEvent,13 type MouseEvent,14} from "react"15import { useControllableState } from "@radix-ui/react-use-controllable-state"16import { cva } from "class-variance-authority"17import { Check } from "lucide-react"1819import { cn } from "@/lib/utils"2021/* -----------------------------------------------------------------------------22 * Types23 * -------------------------------------------------------------------------- */2425export interface ChoicePollRootProps26 extends Omit<ComponentProps<"div">, "defaultValue"> {27 /** Currently selected option(s) - controlled */28 value?: string | string[]29 /** Default selected option(s) - uncontrolled */30 defaultValue?: string | string[]31 /** Callback when selection changes */32 onValueChange?: (value: string | string[]) => void33 /** Whether multiple selections are allowed */34 multiple?: boolean35 /** Whether the poll is disabled */36 disabled?: boolean37 /** Whether poll results should be visible after voting */38 showResults?: boolean39 /** Vote counts per option (for showing results) */40 votes?: Record<string, number>41 /** Whether user has submitted their vote */42 hasVoted?: boolean43}4445export interface ChoicePollOptionProps extends ComponentProps<"button"> {46 /** Unique identifier for this option */47 value: string48 /** Whether this specific option is disabled */49 disabled?: boolean50}5152export type ChoicePollHeaderProps = ComponentProps<"div">5354export type ChoicePollTitleProps = ComponentProps<"h3">5556export type ChoicePollDescriptionProps = ComponentProps<"p">5758export type ChoicePollOptionsProps = ComponentProps<"div">5960export type ChoicePollLabelProps = ComponentProps<"span">6162export type ChoicePollIndicatorProps = ComponentProps<"span">6364export type ChoicePollProgressProps = ComponentProps<"div">6566export type ChoicePollPercentageProps = ComponentProps<"span">6768export interface ChoicePollFooterProps extends ComponentProps<"div"> {69 /** Total number of votes */70 totalVotes?: number71}7273/* -----------------------------------------------------------------------------74 * Context75 * -------------------------------------------------------------------------- */7677interface ChoicePollContextValue {78 selected: string[]79 multiple: boolean80 disabled: boolean81 showResults: boolean82 votes: Record<string, number>83 totalVotes: number84 hasVoted: boolean85// … truncated
What it pulls in
npm packages
Files it writes
More from cult/ui
All 157 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-instructionsai-instructions | cult/ui | Components | Unverified | 2 deps | |
| ai-instructions-demoai-instructions-demo | cult/ui | Components | Unverified | no deps | |
| animated-numberanimated-number | cult/ui | Components | Unverified | 1 dep | |
| animated-number-demoanimated-number-demo | cult/ui | Components | Unverified | no deps | |
| bg-animate-buttonbg-animate-button | cult/ui | Components | Unverified | no deps | |
| bg-animate-button-demobg-animate-button-demo | cult/ui | Components | Unverified | no deps | |
| bg-animated-fractal-dot-gridbg-animated-fractal-dot-grid | cult/ui | Components | Unverified | 1 dep | |
| bg-animated-fractal-dot-grid-demobg-animated-fractal-dot-grid-demo | cult/ui | Components | Unverified | no deps |
