# Pixel glyphs

Crisp pixel glyphs shared by the primitives: check, minus, close, chevron, arrow, dot, radio, error and 16x16 folder, document and terminal icons.

Source: https://www.ui95.dev/ui/pixel-glyphs

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/pixel-glyphs.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn
```

`components/ui/pixel-glyphs.tsx`

```tsx
import { cn } from "cn"
import type * as React from "react"

type GlyphProps = React.ComponentProps<"svg">

type GlyphDirection = "down" | "left" | "up" | "right"

type DirectionalGlyphProps = GlyphProps & {
  direction?: GlyphDirection
}

const GLYPH_PATHS = {
  check:
    "M6 1h1v1H6zM5 2h2v1H5zM0 3h1v1H0zM4 3h2v1H4zM0 4h2v1H0zM3 4h2v1H3zM1 5h3v1H1zM2 6h1v1H2z",
  minus: "M1 3h5v1H1z",
  minimize: "M1 5h5v2H1z",
  maximize: "M0 0h7v2H0zM0 2h1v5H0zM6 2h1v5H6zM1 6h5v1H1z",
  close:
    "M0 0h2v1H0zM5 0h2v1H5zM1 1h2v1H1zM4 1h2v1H4zM2 2h3v1H2zM3 3h1v1H3zM2 4h3v1H2zM1 5h2v1H1zM4 5h2v1H4zM0 6h2v1H0zM5 6h2v1H5z",
  chevron:
    "M0 2h2v1H0zM5 2h2v1H5zM1 3h2v1H1zM4 3h2v1H4zM2 4h3v1H2zM3 5h1v1H3z",
  arrow: "M0 2h7v1H0zM1 3h5v1H1zM2 4h3v1H2zM3 5h1v1H3z",
  dot: "M2 1h3v1H2zM1 2h5v3H1zM2 5h3v1H2z",
  search: "M1 0h3v1H1zM0 1h1v3H0zM4 1h1v3H4zM1 4h3v1H1zM4 4h1v1H4zM5 5h1v1H5zM6 6h1v1H6z",
  info: "M3 0h1v1H3zM2 2h2v1H2zM3 3h1v3H3zM2 6h3v1H2z",
  alert: "M3 0h1v5H3zM3 6h1v1H3z",
  slash: "M5 0h1v1H5zM4 1h1v2H4zM3 3h1v1H3zM2 4h1v2H2zM1 6h1v1H1z",
  panel: "M0 0h7v1H0zM0 1h1v5H0zM2 1h1v5H2zM6 1h1v5H6zM0 6h7v1H0z",
} as const

const RADIO_PATHS = {
  ring: "M3 0h4v1H3zM1 1h2v1H1zM7 1h2v1H7zM1 2h1v1H1zM8 2h1v1H8zM0 3h1v4H0zM9 3h1v4H9zM1 7h1v1H1zM8 7h1v1H8zM1 8h2v1H1zM7 8h2v1H7zM3 9h4v1H3z",
  well: "M3 1h4v1H3zM2 2h6v1H2zM1 3h8v4H1zM2 7h6v1H2zM3 8h4v1H3z",
  dot: "M4 3h2v1H4zM3 4h4v2H3zM4 6h2v1H4z",
} as const

const ICON_PATHS = {
  folderInk: "M1 2h6v2H1zM0 4h16v11H0z",
  folderPaper: "M2 3h4v1H2zM1 5h14v9H1z",
  folderFlap: "M1 7h14v1H1z",
  documentPaper: "M3 1h7v3H3zM3 4h10v11H3z",
  documentInk:
    "M2 0h9v1H2zM2 1h1v15H2zM13 3h1v13h-1zM3 15h10v1H3zM10 1h1v3h-1zM11 3h2v1h-2zM11 1h1v1h-1zM12 2h1v1h-1zM5 6h6v1H5zM5 8h6v1H5zM5 10h6v1H5zM5 12h4v1H5z",
  terminalInk: "M0 1h16v11H0zM5 12h6v2H5zM3 14h10v1H3z",
  terminalPaper: "M2 3h1v1H2zM3 4h1v1H3zM2 5h1v1H2zM5 5h3v1H5z",
} as const

const DIRECTION_ROTATIONS: Record<GlyphDirection, number> = {
  down: 0,
  left: 90,
  up: 180,
  right: 270,
}

function renderGlyph(path: string, { className, ...props }: GlyphProps, rotation = 0) {
  return (
    <svg
      viewBox="0 0 7 7"
      shapeRendering="crispEdges"
      aria-hidden="true"
      className={cn("size-3.5 fill-current", className)}
      {...props}
    >
      <path d={path} transform={rotation === 0 ? undefined : `rotate(${rotation} 3.5 3.5)`} />
    </svg>
  )
}

function CheckGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.check, props)
}

function MinusGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.minus, props)
}

function MinimizeGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.minimize, props)
}

function MaximizeGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.maximize, props)
}

function CloseGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.close, props)
}

function ChevronGlyph({ direction = "down", ...props }: DirectionalGlyphProps) {
  return renderGlyph(GLYPH_PATHS.chevron, props, DIRECTION_ROTATIONS[direction])
}

function ArrowGlyph({ direction = "down", ...props }: DirectionalGlyphProps) {
  return renderGlyph(GLYPH_PATHS.arrow, props, DIRECTION_ROTATIONS[direction])
}

function DotGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.dot, props)
}

function SearchGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.search, props)
}

function InfoGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.info, props)
}

function AlertGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.alert, props)
}

function SlashGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.slash, props)
}

function PanelGlyph(props: GlyphProps) {
  return renderGlyph(GLYPH_PATHS.panel, props)
}

function RadioRingGlyph({ className, ...props }: GlyphProps) {
  return (
    <svg
      viewBox="0 0 10 10"
      shapeRendering="crispEdges"
      aria-hidden="true"
      className={cn("size-5 shrink-0", className)}
      {...props}
    >
      <path className="fill-card" d={RADIO_PATHS.well} />
      <path className="fill-current" d={RADIO_PATHS.ring} />
    </svg>
  )
}

function RadioDotGlyph({ className, ...props }: GlyphProps) {
  return (
    <svg
      viewBox="0 0 10 10"
      shapeRendering="crispEdges"
      aria-hidden="true"
      className={cn("size-5 shrink-0 fill-current", className)}
      {...props}
    >
      <path d={RADIO_PATHS.dot} />
    </svg>
  )
}

function renderIcon(paths: readonly { className: string; d: string }[], { className, ...props }: GlyphProps) {
  return (
    <svg
      viewBox="0 0 16 16"
      shapeRendering="crispEdges"
      aria-hidden="true"
      className={cn("size-8 shrink-0", className)}
      {...props}
    >
      {paths.map(({ className: pathClassName, d }) => (
        <path key={d} className={pathClassName} d={d} />
      ))}
    </svg>
  )
}

function FolderGlyph(props: GlyphProps) {
  return renderIcon(
    [
      { className: "fill-foreground", d: ICON_PATHS.folderInk },
      { className: "fill-card", d: ICON_PATHS.folderPaper },
      { className: "fill-foreground", d: ICON_PATHS.folderFlap },
    ],
    props
  )
}

function DocumentGlyph(props: GlyphProps) {
  return renderIcon(
    [
      { className: "fill-card", d: ICON_PATHS.documentPaper },
      { className: "fill-foreground", d: ICON_PATHS.documentInk },
    ],
    props
  )
}

function TerminalGlyph(props: GlyphProps) {
  return renderIcon(
    [
      { className: "fill-foreground", d: ICON_PATHS.terminalInk },
      { className: "fill-card", d: ICON_PATHS.terminalPaper },
    ],
    props
  )
}

function ErrorGlyph({ className, ...props }: GlyphProps) {
  return (
    <svg
      viewBox="0 0 13 13"
      shapeRendering="crispEdges"
      aria-hidden="true"
      className={cn("size-10 shrink-0", className)}
      {...props}
    >
      <path
        className="fill-foreground"
        d="M4 0h5v1h2v2h1v2h1v3h-1v2h-1v2H9v1H4v-1H2v-2H1V8H0V5h1V3h1V1h2z"
      />
      <path
        className="fill-card"
        transform="translate(3 3)"
        d={GLYPH_PATHS.close}
      />
    </svg>
  )
}

export {
  AlertGlyph,
  ArrowGlyph,
  CheckGlyph,
  ChevronGlyph,
  CloseGlyph,
  DocumentGlyph,
  DotGlyph,
  ErrorGlyph,
  FolderGlyph,
  type GlyphDirection,
  InfoGlyph,
  MaximizeGlyph,
  MinimizeGlyph,
  MinusGlyph,
  PanelGlyph,
  RadioDotGlyph,
  RadioRingGlyph,
  SearchGlyph,
  SlashGlyph,
  TerminalGlyph,
}
```

## API reference

### AlertGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### ArrowGlyph

| Prop | Type | Default |
| --- | --- | --- |
| `direction` | `"down" \| "left" \| "up" \| "right"` | `"down"` |

### CheckGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### ChevronGlyph

| Prop | Type | Default |
| --- | --- | --- |
| `direction` | `"down" \| "left" \| "up" \| "right"` | `"down"` |

### CloseGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### DocumentGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### DotGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### ErrorGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### FolderGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### InfoGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### MaximizeGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### MinimizeGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### MinusGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### PanelGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### RadioDotGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### RadioRingGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### SearchGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### SlashGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

### TerminalGlyph

No props of its own. It forwards the props of the element or primitive it wraps.

## Used by

- [checkbox](https://www.ui95.dev/ui/checkbox)
- [dialog](https://www.ui95.dev/ui/dialog)
- [radio-group](https://www.ui95.dev/ui/radio-group)
- [select](https://www.ui95.dev/ui/select)
- [dropdown-menu](https://www.ui95.dev/ui/dropdown-menu)
- [menubar](https://www.ui95.dev/ui/menubar)
- [accordion](https://www.ui95.dev/ui/accordion)
- [sheet](https://www.ui95.dev/ui/sheet)
- [context-menu](https://www.ui95.dev/ui/context-menu)
- [breadcrumb](https://www.ui95.dev/ui/breadcrumb)
- [pagination](https://www.ui95.dev/ui/pagination)
- [native-select](https://www.ui95.dev/ui/native-select)
- [navigation-menu](https://www.ui95.dev/ui/navigation-menu)
- [input-otp](https://www.ui95.dev/ui/input-otp)
- [command](https://www.ui95.dev/ui/command)
- [sidebar](https://www.ui95.dev/ui/sidebar)
- [calendar](https://www.ui95.dev/ui/calendar)
- [sonner](https://www.ui95.dev/ui/sonner)
- [carousel](https://www.ui95.dev/ui/carousel)
- [window](https://www.ui95.dev/ui/window)
- [error-dialog](https://www.ui95.dev/ui/error-dialog)
