2020-06-20 00:18:03 +00:00
|
|
|
// @flow
|
2020-06-20 20:59:15 +00:00
|
|
|
import { inject, observer } from "mobx-react";
|
|
|
|
import { PrivateCollectionIcon, CollectionIcon } from "outline-icons";
|
2020-08-09 05:53:59 +00:00
|
|
|
import { getLuminance } from "polished";
|
|
|
|
import * as React from "react";
|
|
|
|
import UiStore from "stores/UiStore";
|
2020-06-20 20:59:15 +00:00
|
|
|
import Collection from "models/Collection";
|
|
|
|
import { icons } from "components/IconPicker";
|
2020-06-20 00:18:03 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
collection: Collection,
|
|
|
|
expanded?: boolean,
|
|
|
|
size?: number,
|
|
|
|
ui: UiStore,
|
|
|
|
};
|
|
|
|
|
|
|
|
function ResolvedCollectionIcon({ collection, expanded, size, ui }: Props) {
|
|
|
|
// If the chosen icon color is very dark then we invert it in dark mode
|
|
|
|
// otherwise it will be impossible to see against the dark background.
|
|
|
|
const color =
|
2020-09-07 18:51:09 +00:00
|
|
|
ui.resolvedTheme === "dark" && collection.color !== "currentColor"
|
2020-06-20 00:18:03 +00:00
|
|
|
? getLuminance(collection.color) > 0.12
|
|
|
|
? collection.color
|
2020-06-20 20:59:15 +00:00
|
|
|
: "currentColor"
|
2020-06-20 00:18:03 +00:00
|
|
|
: collection.color;
|
|
|
|
|
2020-06-20 20:59:15 +00:00
|
|
|
if (collection.icon && collection.icon !== "collection") {
|
2020-06-20 00:18:03 +00:00
|
|
|
try {
|
|
|
|
const Component = icons[collection.icon].component;
|
|
|
|
return <Component color={color} size={size} />;
|
|
|
|
} catch (error) {
|
2020-06-20 20:59:15 +00:00
|
|
|
console.warn("Failed to render custom icon " + collection.icon);
|
2020-06-20 00:18:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collection.private) {
|
|
|
|
return (
|
|
|
|
<PrivateCollectionIcon color={color} expanded={expanded} size={size} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <CollectionIcon color={color} expanded={expanded} size={size} />;
|
|
|
|
}
|
|
|
|
|
2020-06-20 20:59:15 +00:00
|
|
|
export default inject("ui")(observer(ResolvedCollectionIcon));
|