mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
30 lines
959 B
TypeScript
30 lines
959 B
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import React, { ReactNode, useState } from "react";
|
|
|
|
import { HotbarStore } from "../../../common/hotbar-store";
|
|
import { MenuItem } from "../menu";
|
|
|
|
import type { CatalogEntity } from "../../api/catalog-entity";
|
|
|
|
export function HotbarToggleMenuItem(props: { entity: CatalogEntity, addContent: ReactNode, removeContent: ReactNode }) {
|
|
const store = HotbarStore.getInstance();
|
|
const [itemInHotbar, setItemInHotbar] = useState(store.isAddedToActive(props.entity));
|
|
|
|
return (
|
|
<MenuItem onClick={() => {
|
|
if (itemInHotbar) {
|
|
store.removeFromHotbar(props.entity.getId());
|
|
setItemInHotbar(false);
|
|
} else {
|
|
store.addToHotbar(props.entity);
|
|
setItemInHotbar(true);
|
|
}
|
|
}}>
|
|
{itemInHotbar ? props.removeContent : props.addContent }
|
|
</MenuItem>
|
|
);
|
|
}
|