runloopable / web /src /sheet /borderIcons.tsx
fsanyoto's picture
Deploy AIOS web (React glide grid + FastAPI slice)
2eae9f0 verified
Raw History Blame Contribute Delete
6.86 kB
// sheet/borderIcons.tsx — the icons of the Borders gallery (S67-T15, instruction 16, J16).
//
// ⭐ ONE COMPONENT PER ENTRY, IN EXCEL'S OWN READING OF IT. Every preset icon is the same 16 by 16
// cell of four quarters: the edges the preset WRITES are drawn solid (thick or double where the
// preset's name says so), and every other line of the cell is a faint dotted grid, so the eye
// reads which sides change at a glance, exactly as Excel's menu does.
//
// ⚠ DESIGN CONTRACT (DESIGN.md 2 and 4): inline SVG on `currentColor`, the house `sheet-ribbon-icon`
// class, no icon pack, no emoji, no `<text>`, and no colour literal. The one colour an icon here
// may paint is the person's chosen LINE colour, which is data (DESIGN.md 3) and arrives as a prop.
import type { ReactNode } from "react";
import type { CellBorderStyle } from "./types";
/** The cell the icons draw on: an 11 by 11 box split into four quarters. */
const LO = 2.5;
const MID = 8;
const HI = 13.5;
type Edge = "top" | "bottom" | "left" | "right" | "insideH" | "insideV";
const EDGE_PATH: Record<Edge, string> = {
top: `M${LO} ${LO}H${HI}`,
bottom: `M${LO} ${HI}H${HI}`,
left: `M${LO} ${LO}V${HI}`,
right: `M${HI} ${LO}V${HI}`,
insideH: `M${LO} ${MID}H${HI}`,
insideV: `M${MID} ${LO}V${HI}`,
};
/** Every line of the cell, faint and dotted: what a preset leaves alone. */
const GRID = Object.values(EDGE_PATH).join("");
function Cell({ children, faint = true }: { children?: ReactNode; faint?: boolean }) {
return (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon sheet-border-icon">
{faint && <path d={GRID} strokeWidth="1" strokeDasharray="0.6 1.6" opacity="0.5" />}
{children}
</svg>
);
}
/** Solid edges at the house weight. */
const solid = (...edges: Edge[]) => <path d={edges.map((e) => EDGE_PATH[e]).join("")} />;
/** A thick edge, drawn at nearly twice the house weight. */
const thick = (...edges: Edge[]) => (
<path d={edges.map((e) => EDGE_PATH[e]).join("")} strokeWidth="2.6" strokeLinecap="square" />
);
/** The bottom edge as two thin rules, which is what Excel's double line is. */
const doubleBottom = () => (
<path d={`M${LO} ${HI - 1.6}H${HI}M${LO} ${HI}H${HI}`} strokeWidth="1" />
);
export const IconBorderBottom = () => <Cell>{solid("bottom")}</Cell>;
export const IconBorderTop = () => <Cell>{solid("top")}</Cell>;
export const IconBorderLeft = () => <Cell>{solid("left")}</Cell>;
export const IconBorderRight = () => <Cell>{solid("right")}</Cell>;
export const IconBorderNone = () => <Cell />;
export const IconBorderAll = () => (
<Cell faint={false}>{solid("top", "bottom", "left", "right", "insideH", "insideV")}</Cell>
);
export const IconBorderOutside = () => <Cell>{solid("top", "bottom", "left", "right")}</Cell>;
export const IconBorderThickOutside = () => (
<Cell>{thick("top", "bottom", "left", "right")}</Cell>
);
export const IconBorderBottomDouble = () => <Cell>{doubleBottom()}</Cell>;
export const IconBorderThickBottom = () => <Cell>{thick("bottom")}</Cell>;
export const IconBorderTopBottom = () => <Cell>{solid("top", "bottom")}</Cell>;
export const IconBorderTopThickBottom = () => <Cell>{solid("top")}{thick("bottom")}</Cell>;
export const IconBorderTopDoubleBottom = () => <Cell>{solid("top")}{doubleBottom()}</Cell>;
/** A pencil laid across the cell's corner: the shared mark of the three draw tools. */
const PENCIL = "M9.2 10.8l4.6-4.6 1.4 1.4-4.6 4.6-2 .6.6-2Z";
export const IconDrawBorder = () => (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon sheet-border-icon">
<path d={`M${LO} ${HI}H8M${LO} ${LO}V${HI}`} />
<path d={PENCIL} />
</svg>
);
export const IconDrawBorderGrid = () => (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon sheet-border-icon">
<path d={`M${LO} ${LO}H11M${LO} ${LO}V${HI}H8M${LO} ${MID}H8M${MID} ${LO}V8`} />
<path d={PENCIL} />
</svg>
);
export const IconEraseBorder = () => (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon sheet-border-icon">
<path d={`M${LO} ${HI}H${HI}`} strokeDasharray="0.6 1.6" opacity="0.5" />
<path d="M3.6 9.6l5.6-5.6 3.4 3.4-5.6 5.6H5.6Z" />
<path d="M6.4 6.8l3.4 3.4" />
</svg>
);
/** A pencil over a bar in the chosen line colour, which is data and so arrives as a prop. */
export function IconLineColor({ colour }: { colour: string }) {
return (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon sheet-border-icon">
<path d="M4.2 9.4l5.6-5.6 1.8 1.8-5.6 5.6-2.4.6.6-2.4Z" />
<rect x="1.5" y="13" width="13" height="2.5" fill={colour} stroke="currentColor" strokeWidth="0.8" />
</svg>
);
}
/** Three rules of three weights and patterns: the choice the flyout offers. */
export const IconLineStyle = () => (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon sheet-border-icon">
<path d="M2 4h12" strokeWidth="1" />
<path d="M2 8h12" strokeWidth="2.2" strokeLinecap="butt" />
<path d="M2 12.2h12" strokeWidth="1" strokeDasharray="2.4 1.6" strokeLinecap="butt" />
</svg>
);
/** The whole grid drawn, with a small ellipsis mark: the dialog that holds every option. */
export const IconMoreBorders = () => (
<svg viewBox="0 0 16 16" aria-hidden="true" className="sheet-ribbon-icon sheet-border-icon">
<path d={`M${LO} ${LO}H${HI}V${MID}M${LO} ${LO}V${HI}H${MID}M${LO} ${MID}H${MID}M${MID} ${LO}V${HI}`} />
<path d="M10.4 12.4h.01M12.2 12.4h.01M14 12.4h.01" strokeWidth="1.6" />
</svg>
);
/**
* ⭐ ONE SAMPLE PER LINE STYLE, DRAWN AS THE PAINTER DRAWS IT (`cellBorders.ts::paintCellBorders`):
* thin 1px, medium 2px, thick 3px, dashed, dotted, double, hair. The Line Style flyout shows the
* line itself rather than a word, because the word is what a person has to translate.
*/
export function LineStyleSample({ style }: { style: CellBorderStyle }) {
const common = { fill: "none", stroke: "currentColor", strokeLinecap: "butt" as const };
let body: ReactNode;
switch (style) {
case "medium": body = <path d="M1 5h54" strokeWidth="2" {...common} />; break;
case "thick": body = <path d="M1 5h54" strokeWidth="3" {...common} />; break;
case "dashed": body = <path d="M1 5h54" strokeWidth="1" strokeDasharray="4 2" {...common} />; break;
case "dotted": body = <path d="M1 5h54" strokeWidth="1" strokeDasharray="1 2" {...common} />; break;
case "double": body = <path d="M1 3.5h54M1 6.5h54" strokeWidth="1" {...common} />; break;
case "hair": body = <path d="M1 5h54" strokeWidth="1" strokeDasharray="1 1" opacity="0.7" {...common} />; break;
default: body = <path d="M1 5h54" strokeWidth="1" {...common} />;
}
return (
<svg viewBox="0 0 56 10" aria-hidden="true" className="sheet-border-sample">
{body}
</svg>
);
}