fix: more random fixes related to incorrect parsing svg-icon content, added static Icon.isSvg(content: string)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2022-02-08 11:53:22 +02:00
1 parent 5b88f23a5f
commit 81560d5357
6 files changed
+10 -6

No files matched your search

@@ -25,7 +25,7 @@ interface Props<T extends CatalogEntity> {
@observer
export class CatalogEntityDetails<T extends CatalogEntity> extends Component<Props<T>> {
categoryIcon(category: CatalogCategory) {
if (category.metadata.icon.includes("<svg")) {
if (Icon.isSvg(category.metadata.icon)) {
return <Icon svg={category.metadata.icon} smallest />;
} else {
return <Icon material={category.metadata.icon} smallest />;
@@ -65,7 +65,7 @@ export class CatalogEntityDrawerMenu<T extends CatalogEntity> extends React.Comp
continue;
}
const key = menuItem.icon.includes("<svg") ? "svg" : "material";
const key = Icon.isSvg(menuItem.icon) ? "svg" : "material";
items.push(
<MenuItem key={menuItem.title} onClick={() => this.onMenuItemClick(menuItem)}>
@@ -28,7 +28,7 @@ function getCategoryIcon(category: CatalogCategory) {
const { icon } = category.metadata ?? {};
if (typeof icon === "string") {
return icon.includes("<svg")
return Icon.isSvg(icon)
? <Icon small svg={icon}/>
: <Icon small material={icon}/>;
}
@@ -47,7 +47,7 @@ export class HotbarEntityIcon extends React.Component<Props> {
return <Icon material="bug_report" className={className} />;
}
if (category.metadata.icon.includes("svg+xml")) {
if (Icon.isSvg(category.metadata.icon)) {
return <Icon svg={category.metadata.icon} className={className} />;
} else {
return <Icon material={category.metadata.icon} className={className} />;
+4
View File
@@ -37,6 +37,10 @@ export class Icon extends React.PureComponent<IconProps> {
focusable: true,
};
static isSvg(content: string){
return String(content).includes("svg+xml"); // data-url for raw svg-icon
}
get isInteractive() {
const { interactive, onClick, href, link } = this.props;