2020-04-10 20:57:50 +02:00
|
|
|
import * as React from "react";
|
2021-05-05 16:28:10 +02:00
|
|
|
import {ClientIconRenderer} from "tc-shared/ui/react-elements/Icons";
|
|
|
|
import {ClientIcon} from "svg-sprites/client-icons";
|
2021-03-21 16:51:30 +01:00
|
|
|
import {getIconManager, RemoteIcon, RemoteIconInfo} from "tc-shared/file/Icons";
|
2021-05-05 16:28:10 +02:00
|
|
|
import {useState} from "react";
|
2020-04-10 20:57:50 +02:00
|
|
|
|
2020-09-29 15:02:36 +02:00
|
|
|
const cssStyle = require("./Icon.scss");
|
|
|
|
|
2021-05-05 16:28:10 +02:00
|
|
|
export const IconEmpty = React.memo((props: { className?: string, title?: string }) => (
|
|
|
|
<div className={cssStyle.container + " icon-container icon-empty " + props.className} title={props.title} />
|
|
|
|
));
|
|
|
|
|
|
|
|
export const IconLoading = React.memo((props: { className?: string, title?: string }) => (
|
|
|
|
<div className={cssStyle.container + " icon-container " + props.className} title={props.title}>
|
|
|
|
<div className={cssStyle.iconLoading} />
|
|
|
|
</div>
|
|
|
|
));
|
2021-03-21 16:51:30 +01:00
|
|
|
|
2021-05-05 16:28:10 +02:00
|
|
|
export const IconError = React.memo((props: { className?: string, title?: string }) => (
|
|
|
|
<ClientIconRenderer icon={ClientIcon.Warning} className={props.className} title={props.title} />
|
|
|
|
));
|
|
|
|
|
|
|
|
export const IconUrl = React.memo((props: { iconUrl: string, className?: string, title?: string }) => (
|
|
|
|
<div className={cssStyle.container + " icon-container " + props.className}>
|
|
|
|
<img style={{ maxWidth: "100%", maxHeight: "100%" }} src={props.iconUrl} alt={props.title} draggable={false} />
|
|
|
|
</div>
|
|
|
|
));
|
|
|
|
|
|
|
|
export const IconRenderer = React.memo((props: {
|
2020-09-26 01:22:21 +02:00
|
|
|
icon: string;
|
2020-04-18 19:37:30 +02:00
|
|
|
title?: string;
|
2020-09-24 15:51:22 +02:00
|
|
|
className?: string;
|
|
|
|
}) => {
|
|
|
|
if(!props.icon) {
|
2020-12-07 19:37:06 +01:00
|
|
|
return <div className={cssStyle.container + " icon-container icon-empty " + props.className} title={props.title} />;
|
2020-09-24 15:51:22 +02:00
|
|
|
} else if(typeof props.icon === "string") {
|
2020-12-12 00:16:17 +01:00
|
|
|
return <div className={cssStyle.container + " icon_em " + props.icon + " " + props.className} title={props.title} />;
|
2020-09-24 15:51:22 +02:00
|
|
|
} else {
|
|
|
|
throw "JQuery icons are not longer supported";
|
2020-04-18 19:37:30 +02:00
|
|
|
}
|
2021-05-05 16:28:10 +02:00
|
|
|
});
|
2020-04-18 19:37:30 +02:00
|
|
|
|
2021-05-05 16:28:10 +02:00
|
|
|
export const RemoteIconRenderer = React.memo((props: { icon: RemoteIcon | undefined, className?: string, title?: string }) => {
|
2020-09-26 01:22:21 +02:00
|
|
|
const [ revision, setRevision ] = useState(0);
|
2020-04-18 19:37:30 +02:00
|
|
|
|
2020-09-26 01:22:21 +02:00
|
|
|
props.icon.events.reactUse("notify_state_changed", () => setRevision(revision + 1));
|
2020-04-10 20:57:50 +02:00
|
|
|
|
2020-09-26 01:22:21 +02:00
|
|
|
switch (props.icon.getState()) {
|
|
|
|
case "empty":
|
|
|
|
case "destroyed":
|
2021-05-05 16:28:10 +02:00
|
|
|
return (
|
|
|
|
<IconEmpty key={"empty"} className={props.className} title={props.title} />
|
|
|
|
);
|
2020-04-10 20:57:50 +02:00
|
|
|
|
2020-09-26 01:22:21 +02:00
|
|
|
case "loaded":
|
|
|
|
if(props.icon.iconId >= 0 && props.icon.iconId <= 1000) {
|
|
|
|
if(props.icon.iconId === 0) {
|
2021-05-05 16:28:10 +02:00
|
|
|
return (
|
|
|
|
<IconEmpty key={"loaded-empty"} className={props.className} title={props.title} />
|
|
|
|
);
|
2020-09-26 01:22:21 +02:00
|
|
|
}
|
2020-04-10 20:57:50 +02:00
|
|
|
|
2020-12-07 19:37:06 +01:00
|
|
|
return <div key={"loaded"} className={cssStyle.container + " icon_em client-group_" + props.icon.iconId + " " + props.className} title={props.title} />;
|
2020-04-18 19:37:30 +02:00
|
|
|
}
|
2021-05-05 16:28:10 +02:00
|
|
|
|
2020-09-26 01:22:21 +02:00
|
|
|
return (
|
2021-06-11 11:43:53 +02:00
|
|
|
<IconUrl iconUrl={props.icon.getImageUrl()} title={props.title || ("icon " + props.icon.iconId)} key={"icon-" + props.icon.iconId} className={props.className} />
|
2020-09-26 01:22:21 +02:00
|
|
|
);
|
2020-04-10 20:57:50 +02:00
|
|
|
|
2020-09-26 01:22:21 +02:00
|
|
|
case "loading":
|
2021-05-05 16:28:10 +02:00
|
|
|
return (
|
|
|
|
<IconLoading className={props.className} title={props.title} key={"loading"} />
|
|
|
|
);
|
2020-04-18 19:37:30 +02:00
|
|
|
|
2020-09-26 01:22:21 +02:00
|
|
|
case "error":
|
2021-05-05 16:28:10 +02:00
|
|
|
return (
|
|
|
|
<IconError key={"error"} className={props.className} title={props.icon.getErrorMessage()} />
|
|
|
|
);
|
2020-06-15 16:56:05 +02:00
|
|
|
|
2020-09-26 01:22:21 +02:00
|
|
|
default:
|
|
|
|
throw "invalid icon state";
|
2020-06-15 16:56:05 +02:00
|
|
|
}
|
2021-05-05 16:28:10 +02:00
|
|
|
});
|
2021-03-21 16:51:30 +01:00
|
|
|
|
|
|
|
export const RemoteIconInfoRenderer = React.memo((props: { icon: RemoteIconInfo | undefined, className?: string, title?: string }) => {
|
|
|
|
if(!props.icon || props.icon.iconId === 0) {
|
2021-05-05 16:28:10 +02:00
|
|
|
return <IconEmpty title={props.title} className={props.className} key={"empty-icon"} />;
|
2021-03-21 16:51:30 +01:00
|
|
|
} else {
|
|
|
|
return <RemoteIconRenderer icon={getIconManager().resolveIconInfo(props.icon)} className={props.className} title={props.title} key={"icon"} />;
|
|
|
|
}
|
|
|
|
});
|