import { Attachment } from "@replicas/ui";

const photo =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 96 96'%3E%3Cdefs%3E%3ClinearGradient id='s' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23f6c9a8'/%3E%3Cstop offset='1' stop-color='%23f2e4d3'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='96' height='96' fill='url(%23s)'/%3E%3Ccircle cx='66' cy='30' r='10' fill='%23fff3e6'/%3E%3Cpath d='M0 70l26-22 18 14 16-12 36 28v18H0z' fill='%238aa58c'/%3E%3Cpath d='M0 80l30-16 24 12 18-8 24 12v16H0z' fill='%235f7f63'/%3E%3C/svg%3E";

export default function AttachmentDemo() {
  return (
    <div style={{ display: "flex", flexWrap: "wrap", alignItems: "center", gap: 8 }}>
      <Attachment.Root type="image" kind="image">
        <Attachment.Preview src={photo} alt="Hillside at sunset" />
        <Attachment.Remove label="Remove hillside.png" />
      </Attachment.Root>
      <Attachment.Root kind="pdf">
        <Attachment.Preview extension="PDF" />
        <Attachment.Info>
          <Attachment.Name>quarterly-report.pdf</Attachment.Name>
          <Attachment.Meta>PDF · 2.4 MB</Attachment.Meta>
        </Attachment.Info>
        <Attachment.Remove label="Remove quarterly-report.pdf" />
      </Attachment.Root>
      <Attachment.Root kind="code">
        <Attachment.Preview extension="SQL" />
        <Attachment.Name>schema.sql</Attachment.Name>
        <Attachment.Remove label="Remove schema.sql" />
      </Attachment.Root>
    </div>
  );
}

Prompt

Copy Prompt hands your agent everything it needs to build the Attachment in the Geist style: the measured tokens, the CSS and the structure.

Show Prompt
# Geist Attachment

A file or image attached to a message, with a button to remove it.

Build a Attachment in this project that looks and behaves like Geist's. Measured from the running Geist app (vercel.com/geist). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or Base UI primitives if it has none.

Fidelity: Partly measured from the AI Elements Attachments demos (grid, inline and list). The 10px file card and 56px image tile are measured. Colours are mapped to Geist's gray scale.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--ds-background-100` | `hsl(0 0% 100%)` | `hsl(0 0% 4%)` |
| `--ds-gray-100` | `hsl(0 0% 95%)` | `hsl(0 0% 10%)` |
| `--ds-gray-900` | `hsl(0 0% 30%)` | `hsl(0 0% 63%)` |
| `--ds-gray-1000` | `hsl(0 0% 9%)` | `hsl(0 0% 93%)` |
| `--ds-gray-alpha-200` | `#00000014` | `#ffffff17` |
| `--ds-gray-alpha-400` | `#00000014` | `#ffffff24` |
| `--ds-focus-color` | `oklch(57.61% 0.2508 258.23)` | `oklch(71.78% 0.1521 250.77)` |
| `--ds-focus-ring` | `0 0 0 2px var(--ds-background-100), 0 0 0 4px var(--ds-focus-color)` | `0 0 0 2px var(--ds-background-100), 0 0 0 4px var(--ds-focus-color)` |
| `--ds-shadow-border-small` | `0 0 0 1px #00000014, 0 2px 2px #0000000a, 0 0 0 1px var(--ds-background-200)` | `0 0 0 1px #ffffff25, 0 1px 2px #00000029, 0 0 0 1px #000` |
| `--ease-in-out` | `cubic-bezier(0.4, 0, 0.2, 1)` | `cubic-bezier(0.4, 0, 0.2, 1)` |
| `--default-transition-duration` | `0.15s` | `0.15s` |
| `--font-monospace` | `"Geist Mono Variable", "Geist Mono", Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace` | `"Geist Mono Variable", "Geist Mono", Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace` |
| `--font-size-micro` | `0.75rem` | `0.75rem` |
| `--font-size-small` | `0.875rem` | `0.875rem` |
| `--font-weight-normal` | `400` | `400` |
| `--font-weight-medium` | `500` | `500` |
| `--font-weight-semibold` | `600` | `600` |
| `--radius-control` | `6px` | `6px` |
| `--radius-kbd` | `4px` | `4px` |
| `--radius-rounded` | `9999px` | `9999px` |

## CSS

Scoped under `[data-style="geist"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.

```css
[data-style="geist"] {
  .ui-attachment {
    position: relative;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    max-width: 280px;
    height: 56px;
    padding: 8px;
    border-radius: 10px;
    background-color: var(--ds-background-100);
    box-shadow: inset 0 0 0 1px var(--ds-gray-alpha-400);
    color: var(--ds-gray-1000);
    font-family: inherit;
    font-size: var(--font-size-small);
    line-height: 20px;
  }

  .ui-attachment-preview {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: 1px;
    width: 40px;
    height: 40px;
    overflow: hidden;
    border-radius: var(--radius-control);
    background-color: var(--ds-gray-100);
    color: var(--ds-gray-900);

    & svg {
      width: 16px;
      height: 16px;
    }

    & img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  .ui-attachment-extension {
    font-family: var(--font-monospace);
    font-size: 9px;
    font-weight: var(--font-weight-semibold);
    line-height: 10px;
    letter-spacing: 0.02em;
  }

  .ui-attachment-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .ui-attachment-name {
    min-width: 0;
    overflow: hidden;
    color: var(--ds-gray-1000);
    font-weight: var(--font-weight-medium);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ui-attachment-meta {
    overflow: hidden;
    color: var(--ds-gray-900);
    font-size: var(--font-size-micro);
    line-height: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ui-attachment-remove {
    box-sizing: border-box;
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin: 0 0 0 auto;
    padding: 0;
    border: none;
    border-radius: var(--radius-control);
    background-color: transparent;
    color: var(--ds-gray-900);
    cursor: pointer;
    transition:
      background-color var(--default-transition-duration) var(--ease-in-out),
      color var(--default-transition-duration) var(--ease-in-out),
      opacity var(--default-transition-duration) var(--ease-in-out);

    & svg {
      width: 16px;
      height: 16px;
    }

    &:focus-visible {
      outline: none;
      box-shadow: var(--ds-focus-ring);
    }

    @media (hover: hover) {
      &:hover {
        background-color: var(--ds-gray-alpha-200);
        color: var(--ds-gray-1000);
      }
    }
  }

  .ui-attachment[data-type="image"] {
    width: 56px;
    padding: 0;
    overflow: hidden;
    background-color: var(--ds-gray-100);
    box-shadow: none;

    &::after {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: inherit;
      box-shadow: inset 0 0 0 1px var(--ds-gray-alpha-400);
      pointer-events: none;
    }

    & .ui-attachment-preview {
      width: 100%;
      height: 100%;
      border-radius: 0;
    }

    & .ui-attachment-remove {
      position: absolute;
      top: 4px;
      right: 4px;
      z-index: 1;
      width: 20px;
      height: 20px;
      margin: 0;
      border-radius: var(--radius-rounded);
      background-color: var(--ds-background-100);
      box-shadow: var(--ds-shadow-border-small);
      color: var(--ds-gray-1000);

      & svg {
        width: 12px;
        height: 12px;
      }

      &:focus-visible {
        box-shadow:
          var(--ds-shadow-border-small),
          var(--ds-focus-ring);
      }

      @media (hover: hover) {
        &:hover {
          background-color: var(--ds-gray-100);
        }
      }
    }
  }

  @media (hover: hover) {
    .ui-attachment[data-type="image"]:not(:hover, :focus-within) .ui-attachment-remove {
      opacity: 0;
    }
  }

  .ui-prompt-input-attachments .ui-attachment {
    gap: 6px;
    height: 32px;
    padding: 0 4px 0 6px;
    border-radius: 8px;
    background-color: transparent;

    & .ui-attachment-preview {
      width: 20px;
      height: 20px;
      border-radius: var(--radius-kbd);
      background-color: transparent;
    }

    & .ui-attachment-extension {
      display: none;
    }

    & .ui-attachment-info {
      flex-direction: row;
      align-items: baseline;
      gap: 6px;
    }

    & .ui-attachment-name {
      font-weight: var(--font-weight-normal);
    }

    & .ui-attachment-remove {
      width: 20px;
      height: 20px;
      border-radius: var(--radius-kbd);

      & svg {
        width: 14px;
        height: 14px;
      }
    }
  }

  .ui-prompt-input-attachments .ui-attachment[data-type="image"] {
    width: 32px;
    padding: 0;

    & .ui-attachment-preview {
      width: 100%;
      height: 100%;
      border-radius: 0;
    }

    & .ui-attachment-remove {
      inset: 0;
      width: auto;
      height: auto;
      border-radius: 0;
      background-color: hsl(0 0% 0% / 0.5);
      box-shadow: none;
      color: #fff;

      &:focus-visible {
        box-shadow: inset 0 0 0 2px var(--ds-focus-color);
      }

      @media (hover: hover) {
        &:hover {
          background-color: hsl(0 0% 0% / 0.6);
        }
      }
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .ui-attachment-remove {
      transition: none;
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { Button as BaseButton } from "@base-ui/react/button";
import type { ComponentProps } from "react";
import { join } from "./utils";

type RootProps = ComponentProps<"div"> & { type?: "file" | "image"; kind?: string };

function Root({ className, type = "file", kind, ...props }: RootProps) {
  return <div className={join("ui-attachment", className)} data-type={type} data-kind={kind} {...props} />;
}

type PreviewProps = ComponentProps<"span"> & { src?: string; alt?: string; extension?: string };

function Preview({ className, src, alt = "", extension, children, ...props }: PreviewProps) {
  return (
    <span className={join("ui-attachment-preview", className)} {...props}>
      {src ? (
        <img src={src} alt={alt} />
      ) : (
        (children ?? (
          <>
            <svg viewBox="0 0 16 16" fill="none" aria-hidden>
              <path
                d="M4 2.5h5l3 3v8a.5.5 0 0 1-.5.5h-7.5a.5.5 0 0 1-.5-.5v-10.5a.5.5 0 0 1 .5-.5zM9 2.5v3h3"
                stroke="currentColor"
                strokeWidth="1.25"
                strokeLinejoin="round"
              />
            </svg>
            {extension ? <span className="ui-attachment-extension">{extension}</span> : null}
          </>
        ))
      )}
    </span>
  );
}

function Info({ className, ...props }: ComponentProps<"span">) {
  return <span className={join("ui-attachment-info", className)} {...props} />;
}

function Name({ className, ...props }: ComponentProps<"span">) {
  return <span className={join("ui-attachment-name", className)} {...props} />;
}

function Meta({ className, ...props }: ComponentProps<"span">) {
  return <span className={join("ui-attachment-meta", className)} {...props} />;
}

function Remove({
  className,
  label = "Remove attachment",
  ...props
}: Omit<BaseButton.Props, "className"> & { className?: string; label?: string }) {
  return (
    <BaseButton className={join("ui-attachment-remove", className)} aria-label={label} {...props}>
      <svg viewBox="0 0 16 16" fill="none" aria-hidden>
        <path d="M5 5l6 6M11 5l-6 6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
      </svg>
    </BaseButton>
  );
}

export const Attachment = {
  Root,
  Preview,
  Info,
  Name,
  Meta,
  Remove,
};
```

## Example

```tsx
import { Attachment } from "@replicas/ui";

const photo =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 96 96'%3E%3Cdefs%3E%3ClinearGradient id='s' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23f6c9a8'/%3E%3Cstop offset='1' stop-color='%23f2e4d3'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='96' height='96' fill='url(%23s)'/%3E%3Ccircle cx='66' cy='30' r='10' fill='%23fff3e6'/%3E%3Cpath d='M0 70l26-22 18 14 16-12 36 28v18H0z' fill='%238aa58c'/%3E%3Cpath d='M0 80l30-16 24 12 18-8 24 12v16H0z' fill='%235f7f63'/%3E%3C/svg%3E";

export default function AttachmentDemo() {
  return (
    <div style={{ display: "flex", flexWrap: "wrap", alignItems: "center", gap: 8 }}>
      <Attachment.Root type="image" kind="image">
        <Attachment.Preview src={photo} alt="Hillside at sunset" />
        <Attachment.Remove label="Remove hillside.png" />
      </Attachment.Root>
      <Attachment.Root kind="pdf">
        <Attachment.Preview extension="PDF" />
        <Attachment.Info>
          <Attachment.Name>quarterly-report.pdf</Attachment.Name>
          <Attachment.Meta>PDF · 2.4 MB</Attachment.Meta>
        </Attachment.Info>
        <Attachment.Remove label="Remove quarterly-report.pdf" />
      </Attachment.Root>
      <Attachment.Root kind="code">
        <Attachment.Preview extension="SQL" />
        <Attachment.Name>schema.sql</Attachment.Name>
        <Attachment.Remove label="Remove schema.sql" />
      </Attachment.Root>
    </div>
  );
}
```

## Foundations

The rest of the Geist style, as a skill: https://replicas.raphaelsalaja.com/skills/geist/SKILL.md