BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/ns-ui/container-box-drawing

Container Box Drawing

ns-ui/container-box-drawing
FreeComponent

A container with real box-drawing chrome — an inline title breaking the top rule, upgrading to a double-line border character by character on hover or focus.

Live preview

live · rendered by the registry
Rendered by ns-ui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://design.helpmarq.com/r/container-box-drawing.json

Source

registry/core/container-box-drawing/component.tsxdesign.helpmarq.com/r/container-box-drawing.json · first 6 KB
1"use client";
2
3import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
4
5type Role = "corner-tl" | "corner-tr" | "corner-bl" | "corner-br" | "h" | "v";
6type Cell = { char: string } | { refIndex: number; role: Role };
7
8const SINGLE: Record<Role, string> = {
9 "corner-tl": "┌",
10 "corner-tr": "┐",
11 "corner-bl": "└",
12 "corner-br": "┘",
13 h: "─",
14 v: "│",
15};
16const DOUBLE: Record<Role, string> = {
17 "corner-tl": "╔",
18 "corner-tr": "╗",
19 "corner-bl": "╚",
20 "corner-br": "╝",
21 h: "═",
22 v: "║",
23};
24
25const LINE_HEIGHT = 1.4;
26
27export interface RuleFrameProps {
28 /** sits inline in the top rule, like a fieldset legend */
29 title?: string;
30 children?: React.ReactNode;
31 className?: string;
32}
33
34// Builds every border position once, as plain data, in true clockwise order
35// starting at the top-left corner: each rule-character position gets a
36// stable `refIndex` (0..N-1) assigned by pure traversal order, never by a
37// ref-callback side effect. That matters because React tears down and sets
38// up a ref callback on every render whose identity changed (ours always
39// does, since it closes over per-render data) — if the index came from an
40// incrementing counter read inside the callback itself, an old callback's
41// teardown firing after a new callback's setup would scramble the count.
42// Indexing from precomputed data sidesteps that: every callback, old or
43// new, only ever writes to the one slot it was built for.
44function buildPerimeter(cols: number, rows: number, title?: string) {
45 const role: Role[] = [];
46 let n = 0;
47 const alloc = (r: Role) => {
48 role[n] = r;
49 return n++;
50 };
51
52 // `cols`/`rows` are the FULL measured box in character units, corners
53 // included. Each straight edge holds two of those cells for its own
54 // corners, so the run of dash/bar glyphs between them is cols-2 / rows-2
55 // long, not cols / rows — using the full count here was the bug: it made
56 // every straight edge two characters longer than the box it was supposed
57 // to tile, so the perimeter never closed.
58 const innerCols = Math.max(0, cols - 2);
59 const innerRows = Math.max(0, rows - 2);
60
61 const titleText = title ? ` ${title} ` : "";
62 const titleCols = Math.min(titleText.length, innerCols);
63 const leftDashes = Math.max(0, Math.floor((innerCols - titleCols) / 2));
64
65 const tl: Cell = { refIndex: alloc("corner-tl"), role: "corner-tl" };
66 const top: Cell[] = [];
67 for (let i = 0; i < innerCols; i++) {
68// … truncated

Files it writes

  • registry/core/container-box-drawing/component.tsx

Facts

Registry
ns-ui
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-02
Last confirmed
yesterday

Go to the source

Docs on ns-ui design.helpmarq.com nikolas-sapa/ns-ui on GitHub Raw registry item This item as JSON

More from ns-ui

All 228 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Accordion Latchaccordion-latchns-uiComponentsFreeno deps
Approval Inline Diffapproval-inline-diffns-uiComponentsFreeno deps
ASCII Engraving Contourascii-engraving-contourns-uiComponentsFreeno deps
ASCII Globe Spinascii-globe-spinns-uiComponentsFreeno deps
ASCII Torus Donutascii-torus-donutns-uiComponentsFreeno deps
Autosave Ratchetautosave-ratchetns-uiComponentsFreeno deps
Avatar Stack Flockavatar-stack-flockns-uiComponentsFreeno deps
Background ASCII Ditherbackground-ascii-ditherns-uiComponentsFreeno deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex