Bitcoin search
bitcoin-ui/bitcoin-searchFreeComponent
Validated search for Bitcoin heights, hashes, and addresses.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/dennisonbertram/bitcoin-ui/main/public/r/bitcoin-search.jsonSource
1"use client";23import { Search } from "lucide-react";4import {5 type ComponentProps,6 type FormEvent,7 useId,8 useState,9} from "react";1011import {12 classifyBitcoinQuery,13 type BitcoinSearchKind,14} from "@/lib/bitcoin";15import { componentClasses } from "@/lib/utils";1617import {18 interactiveStyles,19 type BitcoinVisualProps,20} from "./shared";2122export type BitcoinSearchSubmit = {23 query: string;24 kind: BitcoinSearchKind;25};2627export type BitcoinSearchProps = Omit<28 ComponentProps<"form">,29 "children" | "onSubmit"30> &31 BitcoinVisualProps & {32 value?: string;33 defaultValue?: string;34 onValueChange?: (value: string) => void;35 onSearch: (search: BitcoinSearchSubmit) => void | Promise<void>;36 label?: string;37 placeholder?: string;38 loading?: boolean;39 error?: string;40 };4142export function BitcoinSearch({43 value,44 defaultValue = "",45 onValueChange,46 onSearch,47 label = "Search the Bitcoin chain",48 placeholder = "Block, transaction, or address",49 loading,50 error,51 unstyled,52 className,53 ...props54}: BitcoinSearchProps) {55 const inputId = useId();56 const helpId = useId();57 const [internalValue, setInternalValue] = useState(defaultValue);58 const [internalError, setInternalError] = useState<string>();59 const query = value ?? internalValue;60 const visibleError = error ?? internalError;6162 async function handleSubmit(event: FormEvent<HTMLFormElement>) {63 event.preventDefault();64 const normalized = query.trim();65 const kind = classifyBitcoinQuery(normalized);6667 if (!normalized) {68 setInternalError("Enter a block height, transaction ID, block hash, or address.");69 return;70 }7172 if (kind === "unknown") {73 setInternalError("That does not look like a Bitcoin identifier.");74 return;75 }7677 setInternalError(undefined);78 await onSearch({ query: normalized, kind });79 }8081 function updateValue(nextValue: string) {82 if (value === undefined) setInternalValue(nextValue);83 setInternalError(undefined);84 onValueChange?.(nextValue);85 }8687 return (88 <form89 data-slot="bitcoin-search"90 data-state={visibleError ? "error" : loading ? "loading" : "idle"}91 data-unstyled={unstyled || undefined}92 className={componentClasses(93 unstyled,94 "grid gap-2",95 className,96 )}97 onSubmit={handleSubmit}98 aria-busy={loading}99 {...props}100 >101 <label102 htmlFor={inputId}103// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from bitcoin-ui
All 23 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Address displayaddress-display | bitcoin-ui | Components | Free | no deps | |
| Bitcoin amountbitcoin-amount | bitcoin-ui | Components | Free | no deps | |
| Bitcoin motionbitcoin-motion | bitcoin-ui | Components | Free | no deps · 2 files | |
| Block cardblock-card | bitcoin-ui | Components | Free | 1 dep | |
| Block listblock-list | bitcoin-ui | Components | Free | no deps | |
| Confirmation progressconfirmation-progress | bitcoin-ui | Components | Free | no deps | |
| Difficulty adjustmentdifficulty-adjustment | bitcoin-ui | Components | Free | no deps | |
| Fee estimatesfee-estimates | bitcoin-ui | Components | Free | 1 dep |
