File size: 6,856 Bytes
a93637f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// 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>
  );
}