generateStates
generateStates creates hover, active, disabled and focus colors from a base color. Set the background to let Colore check the disabled and focus colors as they appear after opacity is applied.
Example
import { generateStates } from 'colore-js';
const button = generateStates('#2563eb', { background: '#fff' });
button.hover.css(); // '#0b48cf'
button.active.css(); // 'color(display-p3 0.04512 0.18278 0.68986)'
button.disabled.css(); // '#526c9f'
button.focusRing.css(); // '#00298f80'
Syntax
generateStates(base: ColorInput | Color, options?: StateOptions): ColorStates
Parameters
Returns
ColorStates includes base, hover, active, disabled and focusRing as Color values. Active and hover move away from the background in lightness.
Throws
A ColorError for invalid colors or options, or when the requested opacity prevents disabled or focus contrast from reaching the target.
Create a focus ring for dark mode
import { generateStates } from 'colore-js';
const darkButton = generateStates('#2563eb', {
background: '#0a0a0a',
focusOpacity: 1,
});
darkButton.focusRing.css(); // '#2563eb'
darkButton.focusRing.contrastRatio('#0a0a0a').toFixed(2); // '3.83'
Related
- Dark mode colors to check states against the actual background
- generateSystem for interaction states across theme roles
- ensureContrast to repair a single color pair