# Bubble

A message's frame: a rounded box drawn round what is said, shaded solid, hatched, washed or just pencilled, in the ink or the red pen.

Docs: https://ballpoint.st9wd.com/docs/bubble

```bash
npx shadcn@latest add @ballpoint/bubble
```

```tsx
import { Bubble, BubbleContent } from "@/components/ui/bubble"

<Bubble variant="secondary">
  <BubbleContent>How can I help you today?</BubbleContent>
</Bubble>
```

Props:

- `Bubble variant`: `"default" | "secondary" | "muted" | "tinted" | "outline" | "ghost" | "destructive"` (default `"default"`). Solid ink, hatched, lightly hatched, washed, pencilled, unframed, or red pen.
- `Bubble align`: `"start" | "end"` (default `"start"`). Which edge of the conversation it sits against.
- `BubbleContent render`: `ReactElement`. Render the surface as a link or a button.
- `BubbleReactions side / align`: `"top" | "bottom" / "start" | "end"` (default `"bottom" / "end"`). Where on the edge the reactions sit.
- `BubbleGroup`: `div`. Groups consecutive bubbles from one sender.
- `seed`: `string | number`. Pins the drawing.

Pen settings: `draw`, `roughness`, `passes`, `radius`, `corners`, `weight`, `speed` (see Pen settings).

Every other prop goes to Base UI's Use Render: https://base-ui.com/react/utils/use-render

## Example

```tsx
import { Bubble, BubbleContent, BubbleGroup } from "@/components/ui/bubble";

export default function BubbleDemo() {
  return (
    <div className="flex w-full max-w-md flex-col gap-3">
      <Bubble variant="secondary">
        <BubbleContent seed="bubble-a">How can I help you today?</BubbleContent>
      </Bubble>
      <Bubble align="end">
        <BubbleContent seed="bubble-b">Draw me a ballpoint pen.</BubbleContent>
      </Bubble>
      <BubbleGroup>
        <Bubble variant="secondary">
          <BubbleContent seed="bubble-c">Here is one.</BubbleContent>
        </Bubble>
        <Bubble variant="secondary">
          <BubbleContent seed="bubble-d">I hatched the shadow lightly.</BubbleContent>
        </Bubble>
      </BubbleGroup>
    </div>
  );
}
```

## Variants

Seven ways to colour it in, from the solid bubble for the current user to unframed text.

```tsx
import { Bubble, BubbleContent } from "@/components/ui/bubble";

const variants = ["default", "secondary", "muted", "tinted", "outline", "ghost", "destructive"] as const;

export default function BubbleVariants() {
  return (
    <div className="flex w-full max-w-md flex-col gap-3">
      {variants.map((variant) => (
        <Bubble key={variant} variant={variant} align={variant === "default" ? "end" : "start"}>
          <BubbleContent seed={`bv-${variant}`}>{variant === "destructive" ? "That page didn't save." : `A ${variant} bubble.`}</BubbleContent>
        </Bubble>
      ))}
    </div>
  );
}
```

## Reactions

Small pencilled chips pinned to the edge, on the bottom or the top.

```tsx
import { Bubble, BubbleContent, BubbleReactions } from "@/components/ui/bubble";

export default function BubbleReactionsExample() {
  return (
    <div className="flex w-full max-w-md flex-col gap-6 pb-3">
      <Bubble variant="secondary">
        <BubbleContent seed="br-a">I checked the registry output and removed the stale route.</BubbleContent>
        <BubbleReactions>
          <span>👍</span>
          <span>2</span>
        </BubbleReactions>
      </Bubble>
      <Bubble align="end">
        <BubbleContent seed="br-b">Lovely, thank you.</BubbleContent>
        <BubbleReactions side="top" align="start">
          <span>❤️</span>
        </BubbleReactions>
      </Bubble>
    </div>
  );
}
```

## As a link or a button

Render the surface as another element with `render`.

```tsx
import { Bubble, BubbleContent } from "@/components/ui/bubble";

export default function BubbleLink() {
  return (
    <div className="flex w-full max-w-md flex-col gap-3">
      <Bubble variant="outline">
        <BubbleContent render={<a href="#" />} seed="bl-a" className="underline decoration-ink-4 underline-offset-4 hover:decoration-ink">
          Read the full registry notes
        </BubbleContent>
      </Bubble>
      <Bubble variant="tinted">
        <BubbleContent render={<button type="button" />} seed="bl-b" className="cursor-pointer">
          Try a different pen
        </BubbleContent>
      </Bubble>
    </div>
  );
}
```

## Pen settings

- `draw`: `"auto" | "mount" | "none"` (default `"auto"`). When the strokes draw themselves in: the first time they scroll into view, as soon as they render, or never (already drawn).
- `roughness`: `number` (default `1`). 0 is ruler-neat, 1 a quick confident hand, 2 a scrawl.
- `passes`: `1 | 2 | 3`. How many times an outline is gone over. Each component picks its own default.
- `radius`: `number | "full"` (default `0`). Corner radius in px; "full" draws a pill.
- `corners`: `"crossed" | "joined"` (default `"crossed"`). Square corners: sides pulled separately past each other, or the box drawn in one motion.
- `weight`: `number` (default `1`). Line weight multiplier. Also settable in CSS as --ink-weight.
- `speed`: `number` (default `1`). Drawing speed multiplier. Also settable in CSS as --ink-speed.
