setOklch
setOklch sets one or more OKLCH channels to the values you choose. The channels you omit keep their current values, and opacity is preserved.
Example
import { colore } from 'colore-js';
import { setOklch } from 'colore-js/fn';
colore('#2563eb').setOklch({ l: 0.62 }).oklch(); // 'oklch(0.62000 0.21521 262.88)'
setOklch('#2563eb', { l: 0.62 }); // 'color(display-p3 0.29547 0.47723 0.98934)'
Syntax
colore(color).setOklch(channels: OklchChannels): Color
setOklch(color: ColorInput, channels: OklchChannels): string
Parameters
Returns
The method returns a new Color. The function returns a CSS string in hex, Display P3 or OKLCH. Colore keeps the requested channels before output and leaves gamut mapping to you.
Throws
A ColorError if the color is invalid, the channel object is empty or contains an unknown key, a channel is out of range, or chroma is added to a gray without supplying its hue.
Tint a neutral gray with a specific hue
Set both hue and chroma on a gray. Start low on chroma when you want the new color to read as a neutral.
import { colore } from 'colore-js';
colore('#ddd').setOklch({ c: 0.03, h: 75 }).oklch(); // 'oklch(0.89755 0.03000 75.00)'
colore('#ddd').setOklch({ c: 0.03, h: 75 }).css(); // '#e9dbc8'
Use the method with .oklch() when you want to read the new coordinates. Use toGamut('srgb') when a color must fit in sRGB before you export it.
Related
- lighten to shift lightness by a percentage
- adjustHue to rotate an existing hue
- OKLCH in JavaScript for a worked example