1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/ui-components/button/src/button.tsx
Sebastian Malton d8823085a8 chore: Change name from SafeReactNode to StrictReactNode
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2023-05-15 11:56:30 -04:00

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>
);
});