mirror of
https://github.com/outline/outline.git
synced 2026-11-29 08:39:20 +03:00
* feat: Add icon and color to user groups * refactor: useContrastColor hook * refactor: Share icon contrast check via useContrastColor hook, named GroupIcon export
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import { CollectionIcon, PrivateCollectionIcon } from "outline-icons";
|
|
import Icon from "@shared/components/Icon";
|
|
import { colorPalette } from "@shared/constants";
|
|
import useContrastColor from "@shared/hooks/useContrastColor";
|
|
import type Collection from "~/models/Collection";
|
|
|
|
type Props = {
|
|
/** The collection to show an icon for */
|
|
collection: Collection;
|
|
/** Whether the icon should be the "expanded" graphic when displaying the default collection icon */
|
|
expanded?: boolean;
|
|
/** The size of the icon, 24px is default to match standard icons */
|
|
size?: number;
|
|
/** The color of the icon, defaults to the collection color */
|
|
color?: string;
|
|
className?: string;
|
|
};
|
|
|
|
function ResolvedCollectionIcon({
|
|
collection,
|
|
color: inputColor,
|
|
expanded,
|
|
size,
|
|
className,
|
|
}: Props) {
|
|
const contrastColor = useContrastColor();
|
|
|
|
if (!collection.icon || collection.icon === "collection") {
|
|
const color =
|
|
inputColor || contrastColor(collection.color ?? colorPalette[0]);
|
|
|
|
const Component = collection.isPrivate
|
|
? PrivateCollectionIcon
|
|
: CollectionIcon;
|
|
return (
|
|
<Component
|
|
color={color}
|
|
expanded={expanded}
|
|
size={size}
|
|
className={className}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Icon
|
|
value={collection.icon}
|
|
color={inputColor ?? collection.color ?? undefined}
|
|
size={size}
|
|
initial={collection.initial}
|
|
className={className}
|
|
forceColor={inputColor ? true : false}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default observer(ResolvedCollectionIcon);
|