UNPKG

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