Blocks / Stroke picker

Stroke picker

Colour, width, dash, ends and opacity of a line, with a live preview.

import { StrokePicker, editorDashArray, editorOpacityText } from "@forgeron/ui";
/01 → Default
Stroke
Stroke width4 px
Stroke opacity90%
import { StrokePicker, type EditorStroke } from "@forgeron/ui";
import { useState } from "react";

export default function Default() {
  const [stroke, setStroke] = useState<EditorStroke>({
    color: "#ff4f1f",
    width: 4,
    dash: "dashed",
    cap: "round",
    opacity: 0.9,
  });
  return (
    <div style={{ width: "100%", maxWidth: 320 }}>
      <StrokePicker label="Stroke" value={stroke} onChange={setStroke} />
    </div>
  );
}
/02 → Fields
Outline
Outline width2 px
import { StrokePicker } from "@forgeron/ui";

export default function Fields() {
  return (
    <div style={{ width: "100%", maxWidth: 320 }}>
      <StrokePicker label="Outline" fields={["color", "width"]} preview={false} />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
labelstring—Names the panel: “Stroke”.
value / defaultValue / onChange{ color: string | null, width, dash, cap, opacity }—dash: solid, dashed, dotted. cap: butt, round, square. opacity 0 to 1. A null colour is no line.
fields(“color” | “width” | “dash” | “cap” | “opacity”)[]—Which settings, in order. Default all five.
maxWidth / previewnumber; boolean32 / trueThe widest line; the preview strip.
disabledboolean—Greys out the whole panel.
classNamestring—Extra classes.