mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
67 lines
1.5 KiB
TypeScript
67 lines
1.5 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import "./button.scss";
|
|
import type { ButtonHTMLAttributes } from "react";
|
|
import React from "react";
|
|
import { cssNames, StrictReactNode } from "@k8slens/utilities";
|
|
import { withTooltip } from "@k8slens/tooltip";
|
|
|
|
export interface ButtonProps extends ButtonHTMLAttributes<any> {
|
|
label?: StrictReactNode;
|
|
waiting?: boolean;
|
|
primary?: boolean;
|
|
accent?: boolean;
|
|
light?: boolean;
|
|
plain?: boolean;
|
|
outlined?: boolean;
|
|
hidden?: boolean;
|
|
active?: boolean;
|
|
big?: boolean;
|
|
round?: boolean;
|
|
href?: string; // render as hyperlink
|
|
target?: "_blank"; // in case of using @href
|
|
children?: StrictReactNode;
|
|
}
|
|
|
|
export const Button = withTooltip((props: ButtonProps) => {
|
|
const { waiting, label, primary, accent, plain, hidden, active, big, round, outlined, light, children, ...btnProps } =
|
|
props;
|
|
|
|
if (hidden) {
|
|
return null;
|
|
}
|
|
|
|
btnProps.className = cssNames("Button", btnProps.className, {
|
|
waiting,
|
|
primary,
|
|
accent,
|
|
plain,
|
|
active,
|
|
big,
|
|
round,
|
|
outlined,
|
|
light,
|
|
});
|
|
|
|
// render as link
|
|
if (props.href) {
|
|
return (
|
|
<a {...btnProps}>
|
|
{label}
|
|
{children}
|
|
</a>
|
|
);
|
|
}
|
|
|
|
// render as button
|
|
return (
|
|
<button type="button" {...btnProps} data-waiting={typeof waiting === "boolean" ? String(waiting) : undefined}>
|
|
{label}
|
|
{children}
|
|
</button>
|
|
);
|
|
});
|