1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/update-button/update-button.tsx
Alex Andreev 3b4f8779b7 Default button styles
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
2022-05-12 13:48:37 +03:00

72 lines
1.8 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import styles from "./styles.module.scss";
import React, { useState } from "react";
import { Menu, MenuItem } from "../menu";
import uniqueId from "lodash/uniqueId";
import { noop } from "lodash";
import { cssNames } from "../../utils";
interface UpdateButtonProps {
warningLevel?: "light" | "medium" | "high";
update: () => void;
}
export function UpdateButton({ warningLevel, update }: UpdateButtonProps) {
const id = uniqueId("update_button_");
const [opened, setOpened] = useState(false);
const onKeyDown = (evt: React.KeyboardEvent<HTMLButtonElement>) => {
if (evt.code == "Space" || evt.code == "Enter") {
toggle();
}
};
const toggle = () => {
setOpened(!opened);
};
if (!warningLevel) {
return null;
}
return (
<>
<button
data-testid="update-button"
id={id}
className={cssNames(styles.updateButton, {
[styles.warningHigh]: warningLevel === "high",
[styles.warningMedium]: warningLevel === "medium",
})}
onClick={toggle}
onKeyDown={onKeyDown}
>
Update
<svg width="12" height="12" viewBox="0 0 12 12" shapeRendering="crispEdges">
<path fill="currentColor" d="M0,8.5h12v1H0V8.5z"/>
<path fill="currentColor" d="M0,5.5h12v1H0V5.5z"/>
<path fill="currentColor" d="M0,2.5h12v1H0V2.5z"/>
</svg>
</button>
<Menu
usePortal
htmlFor={id}
isOpen={opened}
closeOnClickItem
closeOnClickOutside
close={toggle}
open={noop}
>
<MenuItem onClick={update} data-testid="update-lens-menu-item">
Relaunch to Update Lens
</MenuItem>
</Menu>
</>
);
}