UNPKG

3.99 kBTypeScriptView Raw
1import * as React from 'react';
2import { UIAnalyticsEvent, WithAnalyticsEventsProps } from '@kalamazoo/analytics-next';
3import { InterpolationWithTheme } from '@emotion/core';
4export declare type ButtonAppearances = 'default' | 'danger' | 'link' | 'primary' | 'subtle' | 'subtle-link' | 'warning';
5declare type HtmlAttributes = Pick<React.AllHTMLAttributes<HTMLElement>, Exclude<keyof React.AllHTMLAttributes<HTMLElement>, keyof OnlyButtonProps | 'css'>> & {
6 css?: InterpolationWithTheme<any>;
7};
8export declare type OnlyButtonProps = {
9 /** The base styling to apply to the button */
10 appearance?: ButtonAppearances;
11 /** Set the button to autofocus on mount */
12 autoFocus?: boolean;
13 /** Add a classname to the button */
14 className?: string;
15 /** A custom component to use instead of the default button */
16 component?: React.ElementType<any>;
17 /** Internal use only. Please use `ref` to forward refs */
18 consumerRef?: React.Ref<HTMLElement>;
19 /** Provides a url for buttons being used as a link */
20 href?: string;
21 /** Places an icon within the button, after the button's text */
22 iconAfter?: React.ReactChild;
23 /** Places an icon within the button, before the button's text */
24 iconBefore?: React.ReactChild;
25 /** Set if the button is disabled */
26 isDisabled?: boolean;
27 /**
28 * Set if the button is loading. When isLoading is true, text is hidden, and
29 * a spinner is shown in its place. The button maintains the width that it
30 * would have if the text were visible.
31 */
32 isLoading?: boolean;
33 /** Change the style to indicate the button is selected */
34 isSelected?: boolean;
35 /** Handler to be called on blur */
36 onBlur?: React.FocusEventHandler<HTMLElement>;
37 /** Handler to be called on click. The second argument can be used to track analytics data. See the tutorial in the analytics-next package for details */
38 onClick?: (e: React.MouseEvent<HTMLElement>, analyticsEvent: UIAnalyticsEvent) => void;
39 onMouseDown?: React.MouseEventHandler<HTMLElement>;
40 onMouseEnter?: React.MouseEventHandler<HTMLElement>;
41 onMouseLeave?: React.MouseEventHandler<HTMLElement>;
42 onMouseUp?: React.MouseEventHandler<HTMLElement>;
43 /** Handler to be called on focus */
44 onFocus?: React.FocusEventHandler<HTMLElement>;
45 /** Set the amount of padding in the button */
46 spacing?: Spacing;
47 /** Pass target down to a link within the button component, if a href is provided */
48 target?: string;
49 /** Option to fit button width to its parent width */
50 shouldFitContainer?: boolean;
51 /** Pass in a custom theme */
52 theme?: (current: (props: ThemeProps) => ThemeTokens, props: ThemeProps) => ThemeTokens;
53 children?: React.ReactNode;
54 /** A `testId` prop is provided for specified elements, which is a unique string that appears as a data attribute `data-testid` in the rendered code, serving as a hook for automated tests */
55 testId?: string;
56};
57export interface ButtonProps extends HtmlAttributes, OnlyButtonProps, WithAnalyticsEventsProps {
58}
59export declare type Spacing = 'compact' | 'default' | 'none';
60export declare type ThemeMode = 'dark' | 'light';
61export declare type ThemeTokens = {
62 buttonStyles: Object;
63 spinnerStyles: Object;
64};
65export interface ThemeProps extends Partial<ButtonProps> {
66 state: string;
67 iconIsOnlyChild?: boolean;
68 mode?: ThemeMode;
69}
70export declare type ThemeFallbacks = {
71 [index: string]: {
72 [index: string]: string;
73 };
74};
75export declare type AppearanceStates = {
76 default: {
77 light: string;
78 dark?: string;
79 };
80 hover?: {
81 light: string;
82 dark?: string;
83 };
84 active?: {
85 light: string;
86 dark?: string;
87 };
88 disabled?: {
89 light: string;
90 dark?: string;
91 };
92 selected?: {
93 light: string;
94 dark?: string;
95 };
96 focusSelected?: {
97 light: string;
98 dark?: string;
99 };
100};
101export {};