ctrl+k
Enter a search term above to see results...
Enter a search term above to see results...
The Color utilities provide functions for working with different color formats and performing conversions.
function oklchToRgb(oklchString)Converts an OKLCH color string to an RGB object. Handles potential out-of-gamut colors by clamping the final RGB values. Based on https://bottosson.github.io/posts/oklab/.
| Name | Type | Description |
|---|---|---|
| oklchString | string | The color string in the format “oklch(L C H)” or “oklch(L, C, H)”. L: Lightness (0-1), C: Chroma (0-~0.4), H: Hue (0-360). |
An object with r, g, b properties (0-255), or null if the input string is invalid.
import { oklchToRgb } from '@semantic-ui/utils';
// Convert a specific OKLCH color (approx. red)const rgbRed = oklchToRgb('oklch(0.628 0.257 29.23)');console.log(rgbRed); // { r: 255, g: 0, b: 0 }
// Convert grayconst rgbGray = oklchToRgb('oklch(0.5, 0, 0)');console.log(rgbGray); // { r: 119, g: 119, b: 119 }
// Handle invalid inputconst invalid = oklchToRgb('not a color');console.log(invalid); // nullfunction oklchToHex(oklchString)Converts an OKLCH color string to a hex color string (e.g., “#RRGGBB”). This function internally uses oklchToRgb.
| Name | Type | Description |
|---|---|---|
| oklchString | string | The color string in the format “oklch(L C H)” or “oklch(L, C, H)”. |
The hex color string (e.g., “#FF0000”) or null if the input string is invalid.
import { oklchToHex } from '@semantic-ui/utils';
// Convert a specific OKLCH color (approx. red)const hexRed = oklchToHex('oklch(0.628 0.257 29.23)');console.log(hexRed); // "#ff0000"
// Convert grayconst hexGray = oklchToHex('oklch(0.5, 0, 0)');console.log(hexGray); // "#777777"
// Handle invalid inputconst invalidHex = oklchToHex('not a color');console.log(invalidHex); // null