import * as React from "react"; import { Button as AntButton } from "antd"; import { ButtonType as AntButtonType } from "antd/lib/button"; import { logger } from '@strata/logging/lib'; import IIconProps from "../icon/IIconProps"; import reactNodeToString from "../utils/ReactNodeToString"; export const ButtonClassName = 'tempo-btn'; export type ButtonType = "primary" | "secondary" | "tertiary" | "link"; export interface IButtonProps { /** Use with caution */ className?: string; /** Button type */ type?: ButtonType; /** Button icon */ icon?: React.ReactElement; /** HTML button type. Default is "button" */ htmlType?: "submit" | "button"; /** Called on button click */ onClick?: React.MouseEventHandler; /** Expand to container width */ block?: boolean; /** Disable item */ disabled?: boolean; /** Danger style (red) */ danger?: boolean; /** Additional log data */ logData?: object; /** Turn off logging. Default to false */ disableLogging?: boolean; /** Additional styles. Use sparingly*/ style?: React.CSSProperties; } const buttonTypeMappings: { [key: string]: AntButtonType; } = { primary: "primary", secondary: "default", tertiary: "dashed", link: "link" }; /** Buttons perform actions in a single click, tap, or keypress. */ const Button: React.FC = (props) => { let { type = "secondary", logData, disableLogging = false, onClick, className = "", ...validProps } = props; className = className == "" ? ButtonClassName : ButtonClassName + " " + className; const children = props.children; const buttonText = reactNodeToString(children ?? ""); const onClickInternal = (e: React.MouseEvent) => { !disableLogging && logger.log("button click", buttonText, logData); onClick && onClick(e); } return ( {props.children} ); }; Button.displayName = "Button"; export default Button;