UNPKG

4.34 kBTypeScriptView Raw
1import * as React from "react";
2import { AbstractPureComponent2, Alignment, IRef } from "../../common";
3import { HTMLInputProps, Props } from "../../common/props";
4export declare type ControlProps = IControlProps;
5/** @deprecated use ControlProps */
6export interface IControlProps extends Props, HTMLInputProps {
7 /**
8 * Alignment of the indicator within container.
9 *
10 * @default Alignment.LEFT
11 */
12 alignIndicator?: Alignment;
13 /** Whether the control is checked. */
14 checked?: boolean;
15 /** JSX label for the control. */
16 children?: React.ReactNode;
17 /** Whether the control is initially checked (uncontrolled mode). */
18 defaultChecked?: boolean;
19 /** Whether the control is non-interactive. */
20 disabled?: boolean;
21 /** Ref handler that receives HTML `<input>` element backing this component. */
22 inputRef?: IRef<HTMLInputElement>;
23 /** Whether the control should appear as an inline element. */
24 inline?: boolean;
25 /**
26 * Text label for the control.
27 *
28 * Use `children` or `labelElement` to supply JSX content. This prop actually supports JSX elements,
29 * but TypeScript will throw an error because `HTMLAttributes` only allows strings.
30 */
31 label?: string;
32 /**
33 * JSX Element label for the control.
34 *
35 * This prop is a workaround for TypeScript consumers as the type definition for `label` only
36 * accepts strings. JavaScript consumers can provide a JSX element directly to `label`.
37 */
38 labelElement?: React.ReactNode;
39 /** Whether this control should use large styles. */
40 large?: boolean;
41 /** Event handler invoked when input value is changed. */
42 onChange?: React.FormEventHandler<HTMLInputElement>;
43 /**
44 * Name of the HTML tag that wraps the checkbox.
45 *
46 * By default a `<label>` is used, which effectively enlarges the click
47 * target to include all of its children. Supply a different tag name if
48 * this behavior is undesirable or you're listening to click events from a
49 * parent element (as the label can register duplicate clicks).
50 *
51 * @default "label"
52 */
53 tagName?: keyof JSX.IntrinsicElements;
54}
55export declare type SwitchProps = ISwitchProps;
56/** @deprecated use SwitchProps */
57export interface ISwitchProps extends ControlProps {
58 /**
59 * Text to display inside the switch indicator when checked.
60 * If `innerLabel` is provided and this prop is omitted, then `innerLabel`
61 * will be used for both states.
62 *
63 * @default innerLabel
64 */
65 innerLabelChecked?: string;
66 /**
67 * Text to display inside the switch indicator when unchecked.
68 */
69 innerLabel?: string;
70}
71export declare class Switch extends AbstractPureComponent2<SwitchProps> {
72 static displayName: string;
73 render(): JSX.Element;
74}
75/** @deprecated use RadioProps */
76export declare type IRadioProps = ControlProps;
77export declare type RadioProps = IRadioProps;
78export declare class Radio extends AbstractPureComponent2<RadioProps> {
79 static displayName: string;
80 render(): JSX.Element;
81}
82export declare type CheckboxProps = ICheckboxProps;
83/** @deprecated use CheckboxProps */
84export interface ICheckboxProps extends ControlProps {
85 /** Whether this checkbox is initially indeterminate (uncontrolled mode). */
86 defaultIndeterminate?: boolean;
87 /**
88 * Whether this checkbox is indeterminate, or "partially checked."
89 * The checkbox will appear with a small dash instead of a tick to indicate that the value
90 * is not exactly true or false.
91 *
92 * Note that this prop takes precendence over `checked`: if a checkbox is marked both
93 * `checked` and `indeterminate` via props, it will appear as indeterminate in the DOM.
94 */
95 indeterminate?: boolean;
96}
97export interface ICheckboxState {
98 indeterminate: boolean;
99}
100export declare class Checkbox extends AbstractPureComponent2<CheckboxProps, ICheckboxState> {
101 static displayName: string;
102 static getDerivedStateFromProps({ indeterminate }: CheckboxProps): ICheckboxState | null;
103 state: ICheckboxState;
104 input: HTMLInputElement | null;
105 private handleInputRef;
106 render(): JSX.Element;
107 componentDidMount(): void;
108 componentDidUpdate(prevProps: CheckboxProps): void;
109 private updateIndeterminate;
110 private handleChange;
111}