1
0
Fork 0

feat(chips): sm size variant for chip piles on dense felt surfaces

Co-authored-by: Sisyphus <sisyphus@ohmyopencode.dev>
This commit is contained in:
Jason Fraley 2026-09-14 23:00:54 -04:00
parent 169f938b05
commit f81d978f88
2 changed files with 31 additions and 11 deletions

View file

@ -2918,22 +2918,34 @@
exact number always rides alongside in a text label. Pile heights are set exact number always rides alongside in a text label. Pile heights are set
inline from the chip count so nothing clips or overlaps. */ inline from the chip count so nothing clips or overlaps. */
.bj-chip-stack { .bj-chip-stack {
--bj-chip-w: 1.6rem;
--bj-chip-h: 0.95rem;
--bj-chip-step: 0.3rem;
display: inline-flex; display: inline-flex;
align-items: flex-end; align-items: flex-end;
gap: 0.3rem; gap: 0.3rem;
} }
/* Compact piles (sm) share the same markup with smaller discs so dense
surfaces like poker's bet pills and console readouts keep their height. */
.bj-chip-stack-sm {
--bj-chip-w: 1.15rem;
--bj-chip-h: 0.68rem;
--bj-chip-step: 0.2rem;
gap: 0.22rem;
}
.bj-chip-pile { .bj-chip-pile {
position: relative; position: relative;
display: inline-block; display: inline-block;
width: 1.6rem; width: var(--bj-chip-w, 1.6rem);
} }
.bj-chip { .bj-chip {
position: absolute; position: absolute;
left: 0; left: 0;
width: 1.6rem; width: var(--bj-chip-w, 1.6rem);
height: 0.95rem; height: var(--bj-chip-h, 0.95rem);
border: 2px dashed rgb(255 255 255 / 72%); border: 2px dashed rgb(255 255 255 / 72%);
border-radius: 50%; border-radius: 50%;
box-shadow: box-shadow:

View file

@ -6,7 +6,9 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/comp
/** /**
* Renders an amount as a pile of casino chips: denomination-colored CSS * Renders an amount as a pile of casino chips: denomination-colored CSS
* discs stacked into piles, popping in as the amount grows. Purely visual; * discs stacked into piles, popping in as the amount grows. Purely visual;
* the exact number always rides alongside in a text label. * the exact number always rides alongside in a text label. `size="sm"`
* renders smaller discs for dense surfaces (poker bet pills, console
* readouts) without forking the markup.
*/ */
interface ChipDenomination { interface ChipDenomination {
@ -55,10 +57,6 @@ export function chipFlightChips(amount: number, maxChips = 8): FlightChip[] {
return chips; return chips;
} }
/** Must match the .bj-chip height + vertical step in styles.css. */
const CHIP_HEIGHT_REM = 0.95;
const CHIP_STEP_REM = 0.3;
interface ChipPile { interface ChipPile {
readonly key: string; readonly key: string;
readonly tone: string; readonly tone: string;
@ -96,27 +94,37 @@ function pileUp(amount: number): ChipPile[] {
export function BlackjackChipStack({ export function BlackjackChipStack({
amount, amount,
className, className,
size = "md",
}: { }: {
readonly amount: number; readonly amount: number;
readonly className?: string; readonly className?: string;
readonly size?: "md" | "sm";
}) { }) {
if (amount <= 0) return null; if (amount <= 0) return null;
const piles = pileUp(amount); const piles = pileUp(amount);
return ( return (
<TooltipProvider delayDuration={150}> <TooltipProvider delayDuration={150}>
<span className={cn("bj-chip-stack", className)} aria-hidden="true"> <span
className={cn("bj-chip-stack", size === "sm" && "bj-chip-stack-sm", className)}
aria-hidden="true"
>
{piles.map((pile) => ( {piles.map((pile) => (
<Tooltip key={pile.key}> <Tooltip key={pile.key}>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<span <span
className="bj-chip-pile" className="bj-chip-pile"
style={{ height: `${CHIP_HEIGHT_REM + (pile.count - 1) * CHIP_STEP_REM}rem` }} style={{
height: `calc(var(--bj-chip-h) + ${pile.count - 1} * var(--bj-chip-step))`,
}}
> >
{Array.from({ length: pile.count }, (_, chipIndex) => ( {Array.from({ length: pile.count }, (_, chipIndex) => (
<span <span
key={`${pile.key}-${chipIndex}`} key={`${pile.key}-${chipIndex}`}
className={cn("bj-chip", pile.tone)} className={cn("bj-chip", pile.tone)}
style={{ bottom: `${chipIndex * CHIP_STEP_REM}rem`, zIndex: chipIndex + 1 }} style={{
bottom: `calc(${chipIndex} * var(--bj-chip-step))`,
zIndex: chipIndex + 1,
}}
/> />
))} ))}
</span> </span>