import * as React from "react"; import { FCReturn, ForwardRefProps, JSXIntrinsicElementProps, ReactAnchorAttr, ReactButtonAttr, ReactComponentConstructor, TooltipAlignment, TooltipPosition, } from "../../../typings/shared"; export type ButtonKind = | "danger" | "danger--ghost" | "danger--primary" | "danger--tertiary" | "ghost" | "primary" | "secondary" | "tertiary"; export type ButtonSize = "default" | "field" | "lg" | "md" | "sm" | "small" | "xl" | "2xl"; export interface ButtonRenderIconRenderProps { "aria-hidden"?: boolean | undefined; "aria-label"?: string | undefined; className?: string | undefined; } // this is split due to a typing issue with the specialized buttons (SecondaryButton, etc) export interface ButtonKindProps { kind?: ButtonKind | undefined; // required by has default value } // these props are not passed to the general createElement call interface ButtonBaseIsolatedProps { dangerDescription?: string | undefined; hasIconOnly?: boolean | undefined; iconDescription?: string | undefined; isExpressive?: boolean | undefined; isSelected?: boolean | undefined; // trying to type this just causes problems around inference, overload selection, and anon fn vs typed component references. // if anon render props type is desired, import ButtonRenderIconRenderProps. renderIcon?: any; size?: ButtonSize | undefined; /** * @deprecated */ small?: boolean | undefined; tooltipAlignment?: TooltipAlignment | undefined; tooltipPosition?: TooltipPosition | undefined; } type SafeProps
= Omit
;
interface ButtonBaseProps extends ButtonBaseIsolatedProps {
children?: React.ReactNode | undefined;
className?: string | undefined;
disabled?: boolean | undefined;
}
export interface ButtonDefaultProps extends ButtonBaseProps, ReactButtonAttr {
as?: undefined;
href?: undefined;
}
// alias for old type that used to be exported
export type ButtonProps = ButtonDefaultProps;
export interface ButtonAnchorProps extends ButtonBaseProps, Omit
& {
as: C;
}
: never;
//
// Note: TypeScript will try to select the best overload but this is not always easily predictable the more freedom the
// generic types have or the more they overlap. If you're having difficulty with these types you can try reexporting the
// component casted to your desired type.
// ex:
// import { Button } from "carbon-components-react"
// export const DefaultButton = Button as React.FC