Trade Buttons
solanaui/trade-buttonsFreeComponent
A long/short toggle button group for selecting trade direction.
Live preview
live · rendered by the registry
Rendered by solanaui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.solanaui.dev/r/trade-buttons.jsonSource
1"use client";23import React from "react";4import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";5import { cn } from "@/lib/utils";67interface TradeButtonsProps {8 defaultValue?: string;9 value?: string;10 onValueChange?: (value: string) => void;11 labels?: [string, string];12 className?: string;13}1415const TradeButtons = ({16 defaultValue = "long",17 value,18 onValueChange,19 labels = ["Long", "Short"],20 className,21}: TradeButtonsProps) => {22 const [internalValue, setInternalValue] = React.useState(defaultValue);23 const currentValue = value ?? internalValue;2425 const handleValueChange = (newValue: string) => {26 if (!newValue) return;27 setInternalValue(newValue);28 onValueChange?.(newValue);29 };3031 return (32 <ToggleGroup33 type="single"34 variant="outline"35 spacing={2}36 value={currentValue}37 onValueChange={handleValueChange}38 className={cn("w-full", className)}39 >40 <ToggleGroupItem41 value="long"42 aria-label={`Toggle ${labels[0]}`}43 className={cn(44 "flex-1 shrink transition-colors",45 currentValue === "long"46 ? "bg-emerald-500/15 text-emerald-500 border-emerald-500/25 hover:bg-emerald-500/25 hover:text-emerald-500 data-[state=on]:bg-emerald-500/15 data-[state=on]:text-emerald-500"47 : "hover:bg-muted/80",48 )}49 >50 {labels[0]}51 </ToggleGroupItem>52 <ToggleGroupItem53 value="short"54 aria-label={`Toggle ${labels[1]}`}55 className={cn(56 "flex-1 shrink transition-colors",57 currentValue === "short"58 ? "bg-red-400/15 text-red-400 border-red-400/25 hover:bg-red-400/25 hover:text-red-400 data-[state=on]:bg-red-400/15 data-[state=on]:text-red-400"59 : "hover:bg-muted/80",60 )}61 >62 {labels[1]}63 </ToggleGroupItem>64 </ToggleGroup>65 );66};6768export type { TradeButtonsProps };69export { TradeButtons };
What it pulls in
Other registry items
Files it writes
More from solanaui
All 31 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Action Boxaction-box | solanaui | Components | Free | no deps | |
| Activity Feedactivity-feed | solanaui | Components | Free | 1 dep | |
| Address Displayaddress-display | solanaui | Components | Free | 1 dep | |
| Auth Cardauth-card | solanaui | Components | Free | no deps | |
| Health Barhealth-bar | solanaui | Components | Free | no deps | |
| Leverage Sliderleverage-slider | solanaui | Components | Free | no deps | |
| NFT Cardnft-card | solanaui | Components | Free | no deps | |
| Order Bookorder-book | solanaui | Components | Free | no deps |
