mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
* feat: Add icon and color to user groups * refactor: useContrastColor hook * refactor: Share icon contrast check via useContrastColor hook, named GroupIcon export
22 lines
677 B
TypeScript
22 lines
677 B
TypeScript
import { useCallback } from "react";
|
|
import { ensureContrast } from "../utils/color";
|
|
import useStores from "./useStores";
|
|
|
|
/**
|
|
* Returns a function that swaps a color for a fallback when the color is not
|
|
* visible against the background of the current theme.
|
|
*
|
|
* @returns a function that takes a color and an optional fallback, which
|
|
* defaults to currentColor, and returns the color to render.
|
|
*/
|
|
export default function useContrastColor() {
|
|
const { ui } = useStores();
|
|
const isDark = ui.resolvedTheme === "dark";
|
|
|
|
return useCallback(
|
|
(color: string | null | undefined, fallback?: string) =>
|
|
ensureContrast(color, isDark, fallback),
|
|
[isDark]
|
|
);
|
|
}
|