@byelabel/react
Advanced tools
+5
-1
| { | ||
| "name": "@byelabel/react", | ||
| "version": "0.0.3", | ||
| "version": "0.0.4", | ||
| "description": "ByeLabel React utilities (hooks, contexts)", | ||
@@ -25,2 +25,6 @@ "type": "module", | ||
| }, | ||
| "./color": { | ||
| "types": "./build/utils/color.d.ts", | ||
| "default": "./build/utils/color.js" | ||
| }, | ||
| "./package.json": "./package.json" | ||
@@ -27,0 +31,0 @@ }, |
+37
-1
@@ -18,4 +18,5 @@ # @byelabel/react | ||
| import { AppProvider, useAppContext } from '@byelabel/react/contexts'; | ||
| import { stringToColor, hexToRGBA, shader } from '@byelabel/react/color'; | ||
| // or flat barrel: | ||
| import { useDebouncedValue, AppProvider } from '@byelabel/react'; | ||
| import { useDebouncedValue, AppProvider, stringToColor } from '@byelabel/react'; | ||
| ``` | ||
@@ -161,2 +162,37 @@ | ||
| ## Color utilities | ||
| Pure functions for working with hex colors. Framework-agnostic — usable outside React. | ||
| ### `stringToColor(str): string` | ||
| Deterministic hex color derived from any string. Useful for avatar backgrounds, tag chips, or any "stable color per identifier" UI. | ||
| ```ts | ||
| const bg = stringToColor(user.email); // e.g. '#3F8AC2' | ||
| <Avatar style={{ backgroundColor: bg }}>{user.initials}</Avatar> | ||
| ``` | ||
| ### `hexToRGBA(hex, opacity): string` | ||
| Converts a 3- or 6-digit hex (with or without `#`) to a CSS `rgba()` string. | ||
| ```ts | ||
| hexToRGBA('#FF8800', 0.5); // 'rgba(255, 136, 0, 0.5)' | ||
| hexToRGBA('0F0', 0.25); // 'rgba(0, 255, 0, 0.25)' | ||
| <div style={{ boxShadow: `0 4px 12px ${hexToRGBA(theme.primary, 0.25)}` }} /> | ||
| ``` | ||
| ### `shader(hex, percent?): string` | ||
| Lightens (`percent > 0`) or darkens (`percent < 0`) a 6-digit hex color. Channels are clamped to 255. Defaults to `0` (no-op). | ||
| ```ts | ||
| shader('#336699', 50); // '#4c99e5' — 50% lighter | ||
| shader('#336699', -50); // '#19334c' — 50% darker | ||
| shader('#FFFFFF', 50); // '#ffffff' — clamped | ||
| ``` | ||
| ## Repository | ||
@@ -163,0 +199,0 @@ |
29236
4.48%203
21.56%