UseColorReturn
Color state, conversions and setters returned by useColor and useColorContext.
import type { UseColorReturn } from '@pbroom/color-kit/react';use-color.ts:110interface UseColorReturn {
store: ColorStore;
state: ColorState;
requested: Color;
displayed: Color;
displayedSrgb: Color;
displayedP3: Color;
activeGamut: GamutTarget;
activeView: ViewModel;
setRequested: (requested: Color, options?: SetRequestedOptions) => void;
setChannel: (channel: ColorChannel, value: number, options?: Omit<SetRequestedOptions, 'changedChannel'>) => void;
setFromString: (css: string, options?: SetRequestedOptions) => void;
setFromRgb: (rgb: Rgb, options?: SetRequestedOptions) => void;
setFromHsl: (hsl: Hsl, options?: SetRequestedOptions) => void;
setFromHsv: (hsv: Hsv, options?: SetRequestedOptions) => void;
setActiveGamut: (gamut: GamutTarget, source?: ColorSource) => void;
setActiveView: (view: ViewModel, source?: ColorSource) => void;
hex: string;
rgb: Rgb;
hsl: Hsl;
hsv: Hsv;
oklch: Oklch;
requestedCss: (format?: CssColorFormat) => string;
displayedCss: (format?: CssColorFormat) => string;
}Properties
- store
ColorStore - Subscribable store backing this hook; child components subscribe to slices.
- state
ColorState - The full current state.
- displayedSrgb
Color - The requested color gamut-mapped into sRGB.
- displayedP3
Color - The requested color gamut-mapped into Display P3.
- activeGamut
GamutTarget - Gamut that
displayedanddisplayedCss()target. - activeView
ViewModel - View model the UI is presenting (
oklch,rgb,hex, ...). - setRequested
(requested: Color, options?: SetRequestedOptions) => void - Sets the requested OKLCH color.
- setChannel
(channel: ColorChannel, value: number, options?: Omit<SetRequestedOptions, 'changedChannel'>) => void - Sets one OKLCH channel (
l,c,horalpha) of the requested color; reportschannelas the event'schangedChannel. - setFromString
(css: string, options?: SetRequestedOptions) => void - Parses a CSS color and sets it as requested. Except for an
oklch()string with a hue, an achromatic color keeps the latest requested hue (seeSetRequestedOptions.explicitHue); the same applies tosetFromRgb,setFromHslandsetFromHsv. - setFromRgb
(rgb: Rgb, options?: SetRequestedOptions) => void - Sets the requested color from sRGB channels (0-255, alpha 0-1).
- setFromHsl
(hsl: Hsl, options?: SetRequestedOptions) => void - Sets the requested color from HSL.
- setFromHsv
(hsv: Hsv, options?: SetRequestedOptions) => void - Sets the requested color from HSV.
- setActiveGamut
(gamut: GamutTarget, source?: ColorSource) => void - Sets the active display gamut;
sourcedefaults to'user'. - setActiveView
(view: ViewModel, source?: ColorSource) => void - Sets the active view model;
sourcedefaults to'user'. - hex
string - Requested color as hex. This and the other requested-color conversions (
rgb,hsl,hsv,oklch) are computed lazily on first access and cached per requested color. - requestedCss
(format?: CssColorFormat) => string - Formats the requested color as CSS;
formatdefaults to'hex'. - displayedCss
(format?: CssColorFormat) => string - Formats the displayed color as CSS. Defaults to
'display-p3'when the active gamut is Display P3 and'hex'otherwise.