master @ 28 LINES
[ HISTORY ] [ UP ]
┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ // Page-level notice in callout chrome - the component sibling of the │
│ // markdown [!NOTE] transform, for use outside prose. │
│ import { G, checkGrid, len, pad, wrap } from "../../lib/ascii"; │
│ │
│ export type BannerVariant = "notice" | "warning" | "error"; │
│ │
│ export interface Props { │
│ variant?: BannerVariant; │
│ message: string; │
│ } │
│ │
│ export const BANNER_LABEL: Record<BannerVariant, string> = { │
│ notice: "NOTICE", │
│ warning: "WARNING", │
│ error: "ERROR", │
│ }; │
│ │
│ export function buildBanner(variant: BannerVariant, message: string, width: number │
│ ): string { │
│ const label = BANNER_LABEL[variant]; │
│ const inner = width - 4; │
│ const lines = [ │
│ `${G.TL}${G.H} ${label} ${G.H.repeat(Math.max(0, width - 5 - len(label)))}${G. │
│ TR}`, │
│ ...wrap(message, inner).split("\n").map((ln) => `${G.V} ${pad(ln, inner)} ${G. │
│ V}`), │
│ `${G.BL}${G.H.repeat(width - 2)}${G.BR}`, │
│ ]; │
│ return checkGrid(lines.join("\n"), width, `banner(${label})`); │
│ } │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ // Page-level notice in callout chrome - the │
│ component sibling of the │
│ // markdown [!NOTE] transform, for use outsi │
│ de prose. │
│ import { G, checkGrid, len, pad, wrap } from │
│ "../../lib/ascii"; │
│ │
│ export type BannerVariant = "notice" | "warn │
│ ing" | "error"; │
│ │
│ export interface Props { │
│ variant?: BannerVariant; │
│ message: string; │
│ } │
│ │
│ export const BANNER_LABEL: Record<BannerVari │
│ ant, string> = { │
│ notice: "NOTICE", │
│ warning: "WARNING", │
│ error: "ERROR", │
│ }; │
│ │
│ export function buildBanner(variant: BannerV │
│ ariant, message: string, width: number): str │
│ ing { │
│ const label = BANNER_LABEL[variant]; │
│ const inner = width - 4; │
│ const lines = [ │
│ `${G.TL}${G.H} ${label} ${G.H.repeat(Mat │
│ h.max(0, width - 5 - len(label)))}${G.TR}`, │
│ ...wrap(message, inner).split("\n").map( │
│ (ln) => `${G.V} ${pad(ln, inner)} ${G.V}`), │
│ `${G.BL}${G.H.repeat(width - 2)}${G.BR}` │
│ , │
│ ]; │
│ return checkGrid(lines.join("\n"), width, │
│ `banner(${label})`); │
│ } │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET