Mixins / foldkit-mixins-ui

ColorPicker

namespace · packages/mixins-ui/src/colorPicker.ts:1

export * as ColorPicker from './colorPicker.js'

In the guides

Members

ColorPicker.buildersOf

function · packages/mixins-ui/src/colorPicker.ts:575

function buildersOf<Message>(options: ColorPickerView<Message>, h: HtmlBuilder<Message>): SlotView.SlotBuilders<Slots.Contract<{ readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-labelledby">], readonly Slot.RequirementName[], boolean>; readonly label: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly area: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly areaThumb: Slot.UnnamedSlot<Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"keydown">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-label">, Attr.AttrToken<"aria-valuenow">], readonly Slot.RequirementName[], boolean>; readonly controls: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly S …;

For colorPicker/popover.ts, which draws the picker's Slots around it.

ColorPicker.canEyedrop

function · packages/mixins-ui/src/colorPicker.ts:407

function canEyedrop(): boolean

Whether this runtime has an eyedropper to open; false off a browser and where it is unsupported. The view never calls it, since a server and a browser would then draw different markup: the application reads it where it learns its environment and passes the answer as eyedropper.

ColorPicker.Color

const · packages/mixins-ui/src/colorPicker.ts:96

const Color: Schema.Struct<{
  readonly h: Schema.Number
  readonly s: Schema.Number
  readonly v: Schema.Number
  readonly alpha: Schema.Number
}>

A color in sRGB as the area draws it: hue 0–360 degrees, saturation and value (brightness) 0–1, and alpha 0–1. Hue is kept apart from the other channels, so dragging to grey and back does not lose it.

ColorPicker.color

function · packages/mixins-ui/src/colorPicker.ts:304

function color(text: string): Color

The color a CSS literal names, for presets and initial values written in code: ColorPicker.color('#3b82f6'). It throws on text that names none, so a typo fails where it is written rather than drawing black.

ColorPicker.ColorPickerDefaults

type · packages/mixins-ui/src/colorPicker.ts:601

type ColorPickerDefaults = Pick<
  ColorPickerView<never>,
  'presets' | 'alpha' | 'eyedropper' | 'words' | 'disabled' | 'style' | 'slider'
> & {
  readonly mixins?: MixinList<never>
}

What a ColorPicker is given once: its look and each option that holds no Message.

ColorPicker.ColorPickerPopover

interface · packages/mixins-ui/src/colorPicker/popover.ts:18

interface ColorPickerPopover<Message> extends ColorPickerView<Message> {
  readonly popover: UiPopover.Model
  readonly onPopover: (message: UiPopover.Message) => NoInfer<Message>
  readonly anchor?: AnchorConfig | undefined
  readonly popoverMixins?: MixinList<Message> | undefined
}

ColorPicker.ColorPickerPreset

interface · packages/mixins-ui/src/colorPicker.ts:512

interface ColorPickerPreset {
  readonly label: string
  readonly value: Color
}

ColorPicker.ColorPickerSlots

const · packages/mixins-ui/src/colorPicker.ts:48

const ColorPickerSlots: Slots.Contract<{ readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-labelledby">], readonly Slot.RequirementName[], boolean>; readonly label: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly area: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly areaThumb: Slot.UnnamedSlot<Capability.Capability<"Focusable", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly [Event.EventToken<"keydown">], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-label">, Attr.AttrToken<"aria-valuenow">], readonly Slot.RequirementName[], boolean>; readonly controls: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], …;

A color picker after ReUI's: a 2D area of saturation (across) and brightness (up) at the color's hue, hue and alpha sliders (two Sliders of this package), an eyedropper when the application asks for one, the color as text in a chosen format (hex, rgb, hsl or oklch) that the user can type into, and presets, a radio group of swatches. popover draws it in the package's Popover, opened by a swatch of the color.

The color, the format and the text being typed are a small Model of this module's, which the application keeps and folds with update. Every key, press and drag reaches update as a Message that says what was done (a key, a point of the area), not the color the last frame drew, so keys faster than a frame each move from the color before them.

The area is one focusable thumb, role="slider" with both values in its aria-valuetext, as the APG has no two-dimensional slider: its value is the saturation and Up and Down move the brightness. Arrows step by 1% (with Shift by 10%), Page Up and Page Down move the brightness by 10% (with Shift the saturation), Home and End take the saturation to its ends. The plane is drawn the same way in either direction, so its keys are physical too. A press or drag on it, a Mount, says where in it the pointer is, from 0 to 1 each way.

The root carries the color for the recipe as custom properties computed from it: --fk-color (with alpha), --fk-color-opaque, --fk-color-hue (the pure hue the area runs to), --fk-color-area (the area's paint), --fk-color-hues (the hue track's stops), and --fk-color-x, --fk-color-y (the thumb's place, 0 to 1). A preset carries its own --fk-color. The sliders take a style of their own (slider), since they are Sliders; Recipes.Slider({ track: 'paint', label: 'hidden' }) paints them from what each channel (data-channel) sets.

ColorPicker.ColorPickerView

interface · packages/mixins-ui/src/colorPicker.ts:547

interface ColorPickerView<Message> {
  readonly model: Model
  readonly onMessage: (message: typeof Message.Type) => NoInfer<Message>
  readonly label: string
  readonly presets?: ReadonlyArray<ColorPickerPreset> | undefined
  readonly alpha?: boolean | undefined
  readonly eyedropper?: boolean | undefined
  readonly words?: Partial<ColorPickerWords> | undefined
  readonly disabled?: boolean | undefined
  readonly style?: NamedStyle<typeof ColorPickerSlots> | undefined
  readonly slider?: NamedStyle<typeof SliderSlots> | undefined
  readonly mixins?: MixinList<Message> | undefined
}

ColorPicker.ColorPickerWords

interface · packages/mixins-ui/src/colorPicker.ts:519

interface ColorPickerWords {
  readonly area: string
  readonly saturation: string
  readonly brightness: string
  readonly hue: string
  readonly alpha: string
  readonly format: string
  readonly input: string
  readonly eyedropper: string
  readonly presets: string
}

The words a picker says.

ColorPicker.configure

function · packages/mixins-ui/src/colorPicker.ts:613

function configure<const Names extends string = never>(
  config: Presets<ColorPickerDefaults, Names>,
): {
  readonly view: <Outer>(
    options: ColorPickerView<Outer> & PresetOption<Names>,
    h: HtmlBuilder<Outer>,
  ) => Html
}

The application's own ColorPicker: base for every use, presets chosen at a use with preset, and the call over both. mixins concatenate in that order and words merge word by word; any other option given at the call replaces the preset's. The inline view only: a picker in a popover is ColorPicker.popover, which takes the same options.

ColorPicker.drawn

function · packages/mixins-ui/src/colorPicker.ts:625

function drawn<Outer>(
  options: ColorPickerView<Outer>,
  h: HtmlBuilder<Outer>,
  rootAttributes: ReadonlyArray<ReturnType<HtmlBuilder<Outer>['OnMount']>>,
): Html

For colorPicker/popover.ts, which draws the picker inside its panel.

ColorPicker.Eyedrop

const · packages/mixins-ui/src/colorPicker.ts:418

const Eyedrop: Command.CommandDefinitionNoArgs<
  'ColorPicker.Eyedrop',
  Effect.Effect<
    | { readonly _tag: 'CancelledEyedropper' }
    | { readonly _tag: 'GotEyedropperColor'; readonly hex: string },
    never,
    never
  >
>

Opens the browser's eyedropper; its color, or CancelledEyedropper when there is none to read.

ColorPicker.Format

const · packages/mixins-ui/src/colorPicker.ts:105

const Format: Schema.Literals<readonly ['hex', 'rgb', 'hsl', 'oklch']>

How the color is written in the text field.

ColorPicker.format

function · packages/mixins-ui/src/colorPicker.ts:192

function format(color: Color, as: Format): string

The color as CSS text in format; alpha is written only when the color is not opaque.

ColorPicker.init

function · packages/mixins-ui/src/colorPicker.ts:330

function init(options: {
  readonly id: string
  readonly color?: Color | undefined
  readonly format?: Format | undefined
}): Model

A picker of color (default an opaque blue), written in format (default hex).

ColorPicker.Message

const · packages/mixins-ui/src/colorPicker.ts:341

const Message: MessageUnion<{
  readonly PointedArea: { readonly x: Schema.Number; readonly y: Schema.Number }
  readonly PressedAreaKey: {
    readonly key: Schema.String
    readonly shift: Schema.Boolean
  }
  readonly ChangedHue: { readonly hue: Schema.Number }
  readonly ChangedAlpha: { readonly alpha: Schema.Number }
  readonly PickedPreset: {
    readonly color: Schema.Struct<{
      readonly h: Schema.Number
      readonly s: Schema.Number
      readonly v: Schema.Number
      readonly alpha: Schema.Number
    }>
  }
  readonly ChangedFormat: {
    readonly format: Schema.Literals<readonly ['hex', 'rgb', 'hsl', 'oklch']>
  }
  readonly TypedText: { readonly text: Schema.String }
  readonly CommittedText: {}
  readonly RevertedText: {}
  readonly PressedEyedropper: {}
  readonly GotEyedropperColor: { readonly hex: Schema.String }
  readonly CancelledEyedropper: {}
}>

ColorPicker.Model

const · packages/mixins-ui/src/colorPicker.ts:319

const Model: Schema.Struct<{
  readonly id: Schema.String
  readonly color: Schema.Struct<{
    readonly h: Schema.Number
    readonly s: Schema.Number
    readonly v: Schema.Number
    readonly alpha: Schema.Number
  }>
  readonly format: Schema.Literals<readonly ['hex', 'rgb', 'hsl', 'oklch']>
  readonly draft: Schema.OptionFromNullOr<Schema.String>
}>

ColorPicker.paintOf

function · packages/mixins-ui/src/colorPicker.ts:583

function paintOf(value: Color): Record<string, string>

The custom properties a recipe paints from: the color, as data.

ColorPicker.parse

function · packages/mixins-ui/src/colorPicker.ts:258

function parse(text: string, hue?: number): Option.Option<Color>

The color CSS text names, or none: hex (#rgb, #rgba, #rrggbb, #rrggbbaa, the # optional), rgb(), hsl() and oklch(), with commas or spaces and an optional alpha. A channel out of its range is none; an oklch color outside sRGB is clipped into it. hue is kept for a grey, which has none of its own.

ColorPicker.popover

function · packages/mixins-ui/src/colorPicker/popover.ts:73

function popover<Outer>(
  options: ColorPickerPopover<Outer>,
  h: HtmlBuilder<Outer>,
): Html

The picker behind a swatch of its color and its text, in the package's Popover. The panel opens on the area's thumb, and closes on Escape, a press outside, or focus leaving it (unless a mouse opened it); a press or a drag anywhere inside keeps it open, whatever opened it. The open state is the Popover's Model.

ColorPicker.toOklch

function · packages/mixins-ui/src/colorPicker.ts:308

function toOklch(value: Color): {
  readonly l: number
  readonly c: number
  readonly h: number
}

OKLCH, lightness in percent as the theme's knobs take it, for an application feeding a palette.

ColorPicker.update

function · packages/mixins-ui/src/colorPicker.ts:443

function update(model: Model, message: Message): Return<Model, Message>

The picker after message; the same Model when nothing changes.

ColorPicker.view

function · packages/mixins-ui/src/colorPicker.ts:597

function view<Outer>(
  options: ColorPickerView<Outer>,
  h: HtmlBuilder<Outer>,
): Html

ColorPicker.widestText

function · packages/mixins-ui/src/colorPicker.ts:217

function widestText(as: Format, alpha: number): string

For colorPicker/popover.ts, which draws it beneath the trigger's value.

ColorPicker.words

const · packages/mixins-ui/src/colorPicker.ts:535

const words = {
  area,
  saturation,
  brightness,
  hue,
  alpha,
  format,
  input,
  eyedropper,
  presets,
}

The defaults, in English.