UNPKG

4.79 kBTypeScriptView Raw
1import * as React from "react";
2import { AbstractPureComponent2, ActionProps, Alignment, IElementRefProps, MaybeElement } from "../../common";
3import { IconName } from "../icon/icon";
4/** @deprecated use ButtonProps */
5export declare type IButtonProps<E extends HTMLButtonElement | HTMLAnchorElement = HTMLButtonElement> = ButtonProps<E>;
6/**
7 * Props interface for both the Button and AnchorButton components.
8 *
9 * Note that it is useful for the props for the two components to be assignable to each other, which we can allow
10 * by omitting the `elementRef` prop as `DialogStepButton` does. This is mostly for backwards compatibility, but it is
11 * a feature we like to preserve because the components are so similar and distinguishing between them in their event
12 * handlers is usually unnecessary. For this reason, we extend `ActionProps<HTMLElement>` rather than `ActionProps<E>`.
13 *
14 * @see {@link ActionProps}
15 */
16export interface ButtonProps<E extends HTMLButtonElement | HTMLAnchorElement = HTMLButtonElement> extends ActionProps<HTMLElement>, IElementRefProps<E> {
17 /**
18 * If set to `true`, the button will display in an active state.
19 * This is equivalent to setting `className={Classes.ACTIVE}`.
20 *
21 * @default false
22 */
23 active?: boolean;
24 /**
25 * Text alignment within button. By default, icons and text will be centered
26 * within the button. Passing `"left"` or `"right"` will align the button
27 * text to that side and push `icon` and `rightIcon` to either edge. Passing
28 * `"center"` will center the text and icons together.
29 *
30 * @default Alignment.CENTER
31 */
32 alignText?: Alignment;
33 /** Button contents. */
34 children?: React.ReactNode;
35 /** Whether this button should expand to fill its container. */
36 fill?: boolean;
37 /** Whether this button should use large styles. */
38 large?: boolean;
39 /**
40 * If set to `true`, the button will display a centered loading spinner instead of its contents
41 * and the button will be disabled (_even if_ `disabled={false}`). The width of the button is
42 * not affected by the value of this prop.
43 *
44 * @default false
45 */
46 loading?: boolean;
47 /** Whether this button should use minimal styles. */
48 minimal?: boolean;
49 /** Whether this button should use outlined styles. */
50 outlined?: boolean;
51 /** Name of a Blueprint UI icon (or an icon element) to render after the text. */
52 rightIcon?: IconName | MaybeElement;
53 /** Whether this button should use small styles. */
54 small?: boolean;
55 /**
56 * HTML `type` attribute of button. Accepted values are `"button"`, `"submit"`, and `"reset"`.
57 * Note that this prop has no effect on `AnchorButton`; it only affects `Button`.
58 *
59 * @default "button"
60 */
61 type?: "submit" | "reset" | "button";
62}
63/** @deprecated use AnchorButtonProps */
64export declare type IAnchorButtonProps = ButtonProps<HTMLAnchorElement>;
65export declare type AnchorButtonProps = IAnchorButtonProps;
66export interface IButtonState {
67 isActive: boolean;
68}
69export declare abstract class AbstractButton<E extends HTMLButtonElement | HTMLAnchorElement> extends AbstractPureComponent2<ButtonProps<E> & (E extends HTMLButtonElement ? React.ButtonHTMLAttributes<HTMLButtonElement> : React.AnchorHTMLAttributes<HTMLAnchorElement>), IButtonState> {
70 state: {
71 isActive: boolean;
72 };
73 protected abstract buttonRef: HTMLElement | null;
74 private currentKeyDown?;
75 abstract render(): JSX.Element;
76 protected getCommonButtonProps(): {
77 className: string;
78 disabled: boolean | NonNullable<(ButtonProps<E> & (E extends HTMLButtonElement ? React.ButtonHTMLAttributes<HTMLButtonElement> : React.AnchorHTMLAttributes<HTMLAnchorElement>))["disabled"]>;
79 onBlur: (e: React.FocusEvent<any, Element>) => void;
80 onClick: (ButtonProps<E> & (E extends HTMLButtonElement ? React.ButtonHTMLAttributes<HTMLButtonElement> : React.AnchorHTMLAttributes<HTMLAnchorElement>))["onClick"] | undefined;
81 onFocus: (ButtonProps<E> & (E extends HTMLButtonElement ? React.ButtonHTMLAttributes<HTMLButtonElement> : React.AnchorHTMLAttributes<HTMLAnchorElement>))["onFocus"] | undefined;
82 onKeyDown: (e: React.KeyboardEvent<any>) => void;
83 onKeyUp: (e: React.KeyboardEvent<any>) => void;
84 tabIndex: number | (ButtonProps<E> & (E extends HTMLButtonElement ? React.ButtonHTMLAttributes<HTMLButtonElement> : React.AnchorHTMLAttributes<HTMLAnchorElement>))["tabIndex"] | undefined;
85 };
86 protected handleKeyDown: (e: React.KeyboardEvent<any>) => void;
87 protected handleKeyUp: (e: React.KeyboardEvent<any>) => void;
88 protected handleBlur: (e: React.FocusEvent<any>) => void;
89 protected renderChildren(): React.ReactNode;
90}