mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Usign material icons for general entities
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
2bd344c1c9
commit
2f92e80e08
@ -20,13 +20,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { navigate } from "../../renderer/navigation";
|
import { navigate } from "../../renderer/navigation";
|
||||||
import { CatalogCategory, CatalogEntity, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
|
import { CatalogCategory, CatalogEntity, CatalogEntityMetadata, CatalogEntitySpec, CatalogEntityStatus } from "../catalog";
|
||||||
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
||||||
|
|
||||||
export type GeneralEntitySpec = {
|
type GeneralEntitySpec = {
|
||||||
path: string;
|
path: string;
|
||||||
icon?: string;
|
materialIcon?: string;
|
||||||
};
|
} & CatalogEntitySpec;
|
||||||
|
|
||||||
export class GeneralEntity extends CatalogEntity<CatalogEntityMetadata, CatalogEntityStatus, GeneralEntitySpec> {
|
export class GeneralEntity extends CatalogEntity<CatalogEntityMetadata, CatalogEntityStatus, GeneralEntitySpec> {
|
||||||
public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
|
public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
|
||||||
|
|||||||
@ -34,7 +34,7 @@ const generalEntities = observable([
|
|||||||
},
|
},
|
||||||
spec: {
|
spec: {
|
||||||
path: catalogURL(),
|
path: catalogURL(),
|
||||||
icon: "view_list"
|
materialIcon: "view_list",
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
phase: "active",
|
phase: "active",
|
||||||
@ -49,7 +49,7 @@ const generalEntities = observable([
|
|||||||
},
|
},
|
||||||
spec: {
|
spec: {
|
||||||
path: preferencesURL(),
|
path: preferencesURL(),
|
||||||
icon: "settings"
|
materialIcon: "settings"
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
phase: "active",
|
phase: "active",
|
||||||
|
|||||||
@ -79,7 +79,8 @@ export class CatalogEntityDetails extends Component<Props> {
|
|||||||
uid={entity.metadata.uid}
|
uid={entity.metadata.uid}
|
||||||
title={entity.metadata.name}
|
title={entity.metadata.name}
|
||||||
source={entity.metadata.source}
|
source={entity.metadata.source}
|
||||||
icon={entity.spec.iconData}
|
src={entity.spec.iconData}
|
||||||
|
materialIcon={entity.spec.materialIcon}
|
||||||
onClick={() => this.openEntity()}
|
onClick={() => this.openEntity()}
|
||||||
size={128} />
|
size={128} />
|
||||||
<div className="IconHint">
|
<div className="IconHint">
|
||||||
|
|||||||
@ -173,7 +173,8 @@ export class Catalog extends React.Component<Props> {
|
|||||||
uid={item.getId()}
|
uid={item.getId()}
|
||||||
title={item.getName()}
|
title={item.getName()}
|
||||||
source={item.source}
|
source={item.source}
|
||||||
icon={item.entity.spec.iconData}
|
src={item.entity.spec.iconData}
|
||||||
|
materialIcon={item.entity.spec.materialIcon}
|
||||||
onClick={() => this.onDetails(item)}
|
onClick={() => this.onDetails(item)}
|
||||||
size={24} />
|
size={24} />
|
||||||
);
|
);
|
||||||
|
|||||||
@ -69,11 +69,11 @@ function getIconString(title: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Avatar(props: Props) {
|
export function Avatar(props: Props) {
|
||||||
const { title, src, width = 32, height = 32, colorHash, ...settings } = props;
|
const { title, width = 32, height = 32, colorHash, children, ...settings } = props;
|
||||||
|
|
||||||
const generateAvatarStyle = (): React.CSSProperties => {
|
const generateAvatarStyle = (): React.CSSProperties => {
|
||||||
return {
|
return {
|
||||||
backgroundColor: randomColor({ seed: colorHash, luminosity: "dark" }),
|
backgroundColor: settings.src ? "transparent" : randomColor({ seed: colorHash, luminosity: "dark" }),
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
textTransform: "uppercase"
|
textTransform: "uppercase"
|
||||||
@ -86,7 +86,7 @@ export function Avatar(props: Props) {
|
|||||||
style={generateAvatarStyle()}
|
style={generateAvatarStyle()}
|
||||||
{...settings}
|
{...settings}
|
||||||
>
|
>
|
||||||
{getIconString(title)}
|
{children || getIconString(title)}
|
||||||
</MaterialAvatar>
|
</MaterialAvatar>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,7 +86,7 @@ export class ClusterIconSetting extends React.Component<Props> {
|
|||||||
uid={entity.metadata.uid}
|
uid={entity.metadata.uid}
|
||||||
title={entity.metadata.name}
|
title={entity.metadata.name}
|
||||||
source={entity.metadata.source}
|
source={entity.metadata.source}
|
||||||
icon={entity.spec.iconData}
|
src={entity.spec.iconData}
|
||||||
/>
|
/>
|
||||||
<span style={{marginRight: "var(--unit)"}}>Browse for new icon...</span>
|
<span style={{marginRight: "var(--unit)"}}>Browse for new icon...</span>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -129,7 +129,8 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
|||||||
uid={entity.metadata.uid}
|
uid={entity.metadata.uid}
|
||||||
title={entity.metadata.name}
|
title={entity.metadata.name}
|
||||||
source={entity.metadata.source}
|
source={entity.metadata.source}
|
||||||
icon={entity.spec.iconData}
|
src={entity.spec.iconData}
|
||||||
|
materialIcon={entity.spec.materialIcon}
|
||||||
className={className}
|
className={className}
|
||||||
active={isActive}
|
active={isActive}
|
||||||
onMenuOpen={onOpen}
|
onMenuOpen={onOpen}
|
||||||
|
|||||||
@ -30,12 +30,14 @@ import { Menu, MenuItem } from "../menu";
|
|||||||
import { MaterialTooltip } from "../material-tooltip/material-tooltip";
|
import { MaterialTooltip } from "../material-tooltip/material-tooltip";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { Avatar } from "../avatar/avatar";
|
import { Avatar } from "../avatar/avatar";
|
||||||
|
import { Icon } from "../icon";
|
||||||
|
|
||||||
export interface HotbarIconProps extends DOMAttributes<HTMLElement> {
|
export interface HotbarIconProps extends DOMAttributes<HTMLElement> {
|
||||||
uid: string;
|
uid: string;
|
||||||
title: string;
|
title: string;
|
||||||
source: string;
|
source: string;
|
||||||
icon?: string;
|
src?: string;
|
||||||
|
materialIcon?: string;
|
||||||
onMenuOpen?: () => void;
|
onMenuOpen?: () => void;
|
||||||
className?: IClassName;
|
className?: IClassName;
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
@ -62,7 +64,7 @@ function onMenuItemClick(menuItem: CatalogEntityContextMenu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: HotbarIconProps) => {
|
export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: HotbarIconProps) => {
|
||||||
const { uid, title, icon, active, className, source, disabled, onMenuOpen, children, ...rest } = props;
|
const { uid, title, src, materialIcon, active, className, source, disabled, onMenuOpen, children, ...rest } = props;
|
||||||
const id = `hotbarIcon-${uid}`;
|
const id = `hotbarIcon-${uid}`;
|
||||||
const [menuOpen, setMenuOpen] = useState(false);
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
|
|
||||||
@ -71,27 +73,23 @@ export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: Hotba
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderIcon = () => {
|
const renderIcon = () => {
|
||||||
if (icon) {
|
return (
|
||||||
return <img
|
<Avatar
|
||||||
{...rest}
|
|
||||||
src={icon}
|
|
||||||
className={active ? "active" : "default"}
|
|
||||||
width={size}
|
|
||||||
height={size} />;
|
|
||||||
} else {
|
|
||||||
return <Avatar
|
|
||||||
{...rest}
|
{...rest}
|
||||||
title={title}
|
title={title}
|
||||||
colorHash={`${title}-${source}`}
|
colorHash={`${title}-${source}`}
|
||||||
className={active ? "active" : "default"}
|
className={active ? "active" : "default"}
|
||||||
width={size}
|
width={size}
|
||||||
height={size}
|
height={size}
|
||||||
/>;
|
src={src}
|
||||||
}
|
>
|
||||||
|
{materialIcon && <Icon material={materialIcon}/>}
|
||||||
|
</Avatar>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cssNames("HotbarIcon flex inline", className, { disabled })}>
|
<div className={cssNames("HotbarIcon flex", className, { disabled })}>
|
||||||
<MaterialTooltip title={`${title || "unknown"} (${source || "unknown"})`} placement="right">
|
<MaterialTooltip title={`${title || "unknown"} (${source || "unknown"})`} placement="right">
|
||||||
<div id={id}>
|
<div id={id}>
|
||||||
{renderIcon()}
|
{renderIcon()}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user