A whiteboard's quick styles: color, fill, line, size, connector route and note color.
Note
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import { Schema } from "effect"import { defaultDrawStyle, StylePanel, withStyle } from "./ui/uicontext/components/canvas/StylePanel.ts"import { DrawStyle } from "./ui/uicontext/components/canvas/Viewport.ts"const Message = UiSchema.TaggedEnum({ PickedStyle: { pick: Schema.Any } })// The style new shapes take; with something selected, `styleChanges` applies the same pick to it.export const BoardStyle = Html.component({ name: "BoardStyle", model: Schema.Struct({ style: DrawStyle }), message: Message,}).make({ init: () => ({ style: defaultDrawStyle }), update: { PickedStyle: ($, { pick }) => $.evolve({ style: (s) => withStyle(s, pick) }) }, view: (h, { style }) => StylePanel(h, { value: style, onPick: (pick) => Message.PickedStyle({ pick }), show: { route: true, sticky: true } }),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/style-panelUsage
import { StylePanel } from "./ui/uicontext/components/canvas/StylePanel.ts"import type { DrawStyle } from "./ui/uicontext/components/canvas/Viewport.ts"const Message = UiSchema.TaggedEnum({ PickedStyle: { pick: Schema.Any } })export const Style = (h: Html.H<typeof Message.Type>, style: DrawStyle) => StylePanel(h, { value: style, onPick: (pick) => Message.PickedStyle({ pick }) })API reference
Options
| Name | Type | Description |
|---|---|---|
valuerequired | DrawStyle | — |
onPickrequired | (pick: StylePick) => Message | — |
show | { readonly route?: boolean; readonly sticky?: boolean } | Show what applies: connectors add the route, notes their color |
style | Style | StyleX styles applied after the panel's own: a docked panel drops its float |