fleet/frontend/components/buttons/Button/Button.tsx
Roberto Dip 33d788caed
add support for displaying EULA during ADE/DEP (#11532)
Related to #11350 and the sub-tasks for stuff that happens in setup
assistant: #11477 and #11479

This adds back-end and UI logic to show an EULA during DEP enrollment if
one was uploaded via the UI, if an EULA wasn't uploaded, we just proceed
to enroll the device right after authentication.


https://user-images.githubusercontent.com/4419992/236316655-282ee74a-5f79-4095-a950-82b77b80a5c0.mov
2023-05-05 14:36:13 -03:00

137 lines
2.7 KiB
TypeScript

import React from "react";
import classnames from "classnames";
import Spinner from "components/Spinner";
const baseClass = "button";
export type ButtonVariant =
| "brand"
| "success"
| "alert"
| "blue-green"
| "grey"
| "warning"
| "link"
| "label"
| "text-link"
| "text-icon"
| "inverse"
| "inverse-alert"
| "block"
| "unstyled"
| "unstyled-modal-query"
| "contextual-nav-item"
| "small-text-icon"
| "oversized";
export interface IButtonProps {
autofocus?: boolean;
children: React.ReactNode;
className?: string;
disabled?: boolean;
size?: string;
tabIndex?: number;
type?: "button" | "submit" | "reset";
title?: string;
variant?: ButtonVariant;
onClick?:
| ((value?: any) => void)
| ((evt: React.MouseEvent<HTMLButtonElement>) => void);
isLoading?: boolean;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface IButtonState {}
interface Inputs {
button?: HTMLButtonElement;
}
class Button extends React.Component<IButtonProps, IButtonState> {
static defaultProps = {
size: "",
type: "button",
variant: "default",
};
componentDidMount(): void {
const { autofocus } = this.props;
const {
inputs: { button },
} = this;
if (autofocus && button) {
button.focus();
}
}
setRef = (button: HTMLButtonElement): boolean => {
this.inputs.button = button;
return false;
};
inputs: Inputs = {};
handleClick = (evt: React.MouseEvent<HTMLButtonElement>): boolean => {
const { disabled, onClick } = this.props;
if (disabled) {
return false;
}
if (onClick) {
onClick(evt);
}
return false;
};
render(): JSX.Element {
const { handleClick, setRef } = this;
const {
children,
className,
disabled,
size,
tabIndex,
type,
title,
variant,
isLoading,
} = this.props;
const fullClassName = classnames(
baseClass,
`${baseClass}--${variant}`,
className,
{
[`${baseClass}--disabled`]: disabled,
[`${baseClass}--${size}`]: size !== undefined,
}
);
const onWhite =
variant === "text-link" ||
variant === "inverse" ||
variant === "text-icon" ||
variant === "label";
return (
<button
className={fullClassName}
disabled={disabled}
onClick={handleClick}
tabIndex={tabIndex}
type={type}
title={title}
ref={setRef}
>
<div className={isLoading ? "transparent-text" : "children-wrapper"}>
{children}
</div>
{isLoading && <Spinner small button white={!onWhite} />}
</button>
);
}
}
export default Button;