UNPKG

3.42 kBTypeScriptView Raw
1/// <reference types="react" />
2
3import * as React from 'react';
4import CommonProps from '../util';
5
6interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
7 defaultValue?: any;
8 onChange?: any;
9}
10
11type data = {
12 value?: string | number;
13 label?: React.ReactNode;
14 disabled?: boolean;
15 [propName: string]: any;
16}
17
18export interface GroupProps extends HTMLAttributesWeak, CommonProps {
19 /**
20 * 自定义类名
21 */
22 className?: string;
23
24 /**
25 * 自定义内敛样式
26 */
27 style?: React.CSSProperties;
28
29 /**
30 * 整体禁用
31 */
32 disabled?: boolean;
33
34 /**
35 * 是否为预览态
36 */
37 isPreview?: boolean;
38
39 renderPreview?: (checked: boolean, props: object) => React.ReactNode;
40
41 /**
42 * 可选项列表, 数据项可为 String 或者 Object, 如 `['apple', 'pear', 'orange']` 或者 `[{value: 'apple', label: '苹果',}, {value: 'pear', label: '梨'}, {value: 'orange', label: '橙子'}]`
43 */
44 dataSource?: Array<string> | Array<data> | Array<number>;
45
46 /**
47 * 被选中的值列表
48 */
49 value?: Array<string> | Array<number> | string | number;
50
51 /**
52 * 默认被选中的值列表
53 */
54 defaultValue?: Array<string> | Array<number> | string | number;
55
56 /**
57 * name
58 */
59 name?: string;
60
61 /**
62 * 通过子元素方式设置内部 checkbox
63 */
64 children?: Array<any>;
65
66 /**
67 * 选中值改变时的事件
68 */
69 onChange?: (value: Array<string>, e: any) => void;
70
71 /**
72 * 子项目的排列方式
73 * - hoz: 水平排列 (default)
74 * - ver: 垂直排列
75 */
76 direction?: 'hoz' | 'ver';
77 itemDirection?: 'hoz' | 'ver';
78}
79
80export class Group extends React.Component<GroupProps, any> {}
81interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
82 onChange?: any;
83 onMouseEnter?: any;
84 onMouseLeave?: any;
85}
86
87export interface CheckboxProps extends HTMLAttributesWeak, CommonProps {
88 /**
89 * 自定义类名
90 */
91 className?: string;
92
93 /**
94 * checkbox id, 挂载在input上
95 */
96 id?: string;
97
98 /**
99 * 自定义内敛样式
100 */
101 style?: React.CSSProperties;
102
103 /**
104 * 选中状态
105 */
106 checked?: boolean;
107
108 /**
109 * checkbox 的value
110 */
111 value?: string | number;
112
113 /**
114 * name
115 */
116 name?: string;
117
118 /**
119 * 默认选中状态
120 */
121 defaultChecked?: boolean;
122
123 /**
124 * 禁用
125 */
126 disabled?: boolean;
127
128 /**
129 * 通过属性配置label,
130 */
131 label?: React.ReactNode;
132
133 /**
134 * Checkbox 的中间状态,只会影响到 Checkbox 的样式,并不影响其 checked 属性
135 */
136 indeterminate?: boolean;
137
138 /**
139 * Checkbox 的默认中间态,只会影响到 Checkbox 的样式,并不影响其 checked 属性
140 */
141 defaultIndeterminate?: boolean;
142
143 /**
144 * 是否为预览态
145 */
146 isPreview?: boolean;
147
148 /**
149 * 状态变化时触发的事件
150 */
151 onChange?: (checked: boolean, e: any) => void;
152
153 /**
154 * 鼠标进入enter事件
155 */
156 onMouseEnter?: (e: React.MouseEvent<HTMLInputElement>) => void;
157
158 /**
159 * 鼠标离开Leave事件
160 */
161 onMouseLeave?: (e: React.MouseEvent<HTMLInputElement>) => void;
162}
163
164export default class Checkbox extends React.Component<CheckboxProps, any> {
165 static Group: typeof Group;
166}