UNPKG

20.5 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3import { StyleProp, ViewStyle } from 'react-native'
4interface ButtonProps extends StandardProps {
5 /** 按钮的大小
6 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn
7 * @default default
8 */
9 size?: keyof ButtonProps.Size
10 /** 按钮的样式类型
11 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn
12 * @default default
13 */
14 type?: keyof ButtonProps.Type
15 /** 按钮是否镂空,背景色透明
16 * @supported weapp, alipay, swan, qq, jd, h5, rn
17 * @default false
18 */
19 plain?: boolean
20 /** 是否禁用
21 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn
22 * @default false
23 */
24 disabled?: boolean
25 /** 名称前是否带 loading 图标
26 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn
27 * @default false
28 */
29 loading?: boolean
30 /** 用于 `<form/>` 组件,点击分别会触发 `<form/>` 组件的 submit/reset 事件
31 * @supported weapp, alipay, swan, tt, qq, jd
32 */
33 formType?: keyof ButtonProps.FormType
34 /** 微信开放能力
35 * @supported weapp, alipay, swan, tt, qq, jd
36 */
37 openType?: ButtonProps.OpenType
38 /** 指定按下去的样式类。当 `hover-class="none"` 时,没有点击态效果
39 * @default button-hover
40 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn
41 * @rn 支持 hoverStyle 属性,但框架未支持 hoverClass
42 */
43 hoverClass?: string
44 /** 由于 RN 不支持 hoverClass,故 RN 端的 Button 组件实现了 `hoverStyle`属性,写法和 style 类似,只不过 `hoverStyle` 的样式是指定按下去的样式。
45 * @default none
46 * @supported rn
47 */
48 hoverStyle?: StyleProp<ViewStyle>
49 /** 指定是否阻止本节点的祖先节点出现点击态
50 * @default false
51 * @supported weapp, alipay, swan, tt, qq, jd
52 */
53 hoverStopPropagation?: boolean
54 /** 按住后多久出现点击态,单位毫秒
55 * @default 20
56 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn
57 */
58 hoverStartTime?: number
59 /** 手指松开后点击态保留时间,单位毫秒
60 * @default 70
61 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn
62 */
63 hoverStayTime?: number
64 /** 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。
65 *
66 * 生效时机: `open-type="getUserInfo"`
67 * @supported weapp, qq, jd
68 */
69 lang?: keyof ButtonProps.Lang
70 /** 会话来源
71 *
72 * 生效时机:`open-type="contact"`
73 * @supported weapp
74 */
75 sessionFrom?: string
76 /** 会话内消息卡片标题
77 *
78 * 生效时机:`open-type="contact"`
79 * @default 当前标题
80 * @supported weapp
81 */
82 sendMessageTitle?: string
83 /** 会话内消息卡片点击跳转小程序路径
84 *
85 * 生效时机:`open-type="contact"`
86 * @default 当前标题
87 * @supported weapp
88 */
89 sendMessagePath?: string
90 /** 会话内消息卡片图片
91 *
92 * 生效时机:`open-type="contact"`
93 * @default 截图
94 * @supported weapp
95 */
96 sendMessageImg?: string
97 /** 打开 APP 时,向 APP 传递的参数
98 *
99 * 生效时机:`open-type="launchApp"`
100 * @supported weapp, qq, jd
101 */
102 appParameter?: string
103 /** 支付宝小程序 scope
104 *
105 * 生效时机:`open-type="getAuthorize"`
106 * @supported alipay
107 */
108 scope?: 'userInfo' | 'phoneNumber'
109 /** 显示会话内消息卡片
110 *
111 * 生效时机:`open-type="contact"`
112 * @supported weapp
113 * @default false
114 */
115 showMessageCard?: boolean
116 /** 生活号 id,必须是当前小程序同主体且已关联的生活号,open-type="lifestyle" 时有效。
117 * @supported alipay, qq
118 */
119 publicId?: string
120 /** 发送订阅类模板消息所用的模板库标题 ID ,可通过 getTemplateLibraryList 获取
121 * 当参数类型为 Array 时,可传递 1~3 个模板库标题 ID
122 * @supported swan
123 */
124 templateId?: string | Array<string>
125 /** 发送订阅类模板消息时所使用的唯一标识符,内容由开发者自定义,用来标识订阅场景
126 * 注意:同一用户在同一 subscribe-id 下的多次授权不累积下发权限,只能下发一条。若要订阅多条,需要不同 subscribe-id
127 * @supported swan
128 */
129 subscribeId?: string
130 /** 打开群资料卡时,传递的群号
131 * @supported qq
132 */
133 groupId?: string
134 /** 打开频道页面时,传递的频道号
135 * @supported qq
136 */
137 guildId?: string
138 /** 分享类型集合,请参考下面share-type有效值说明。share-type后续将不再维护,请更新为share-mode
139 * @supported qq
140 * @default 27
141 */
142 shareType?: string
143 /** 分享类型集合,请参考下面share-mode有效值说明
144 * @supported qq
145 * @default ['qq', 'qzone']
146 */
147 shareMode?: string
148 /** 无障碍访问,(属性)元素的额外描述
149 * @supported qq
150 */
151 ariaLabel?: string
152 /** 添加好友时,对方的 openid
153 * @supported qq
154 */
155 openId?: string
156 /** 发送对象的 FriendInfo
157 * @supported qq
158 */
159 shareMessageFriendInfo?: string
160 /** 转发标题,不传则默认使用当前小程序的昵称。 FriendInfo
161 * @supported qq
162 */
163 shareMessageTitle?: string
164 /** 转发显示图片的链接,可以是网络图片路径(仅 QQ CDN 域名路径)或本地图片文件路径或相对代码包根目录的图片文件路径。显示图片长宽比是 5:4FriendInfo
165 * @supported qq
166 */
167 shareMessageImg?: string
168 /** 用户点击该按钮时,会返回获取到的用户信息,回调的detail数据与 Taro.getUserInfo 返回的一致
169 *
170 * 生效时机: `open-type="getUserInfo"`
171 * @supported weapp, alipay, swan, qq, jd
172 */
173 onGetUserInfo?: CommonEventFunction<ButtonProps.onGetUserInfoEventDetail>
174 /** 支付宝获取会员基础信息授权回调
175 *
176 * 生效时机:`open-type="getAuthorize"`
177 * @supported alipay
178 */
179 onGetAuthorize?: CommonEventFunction
180 /** 客服消息回调
181 *
182 * 生效时机:`open-type="contact"`
183 * @supported weapp, swan, qq
184 */
185 onContact?: CommonEventFunction<ButtonProps.onContactEventDetail>
186 /** 获取用户手机号回调
187 *
188 * 生效时机:`open-type="getphonenumber"`
189 * @supported weapp, alipay, swan, tt, jd
190 */
191 onGetPhoneNumber?: CommonEventFunction<ButtonProps.onGetPhoneNumberEventDetail>
192 /** 当使用开放能力时,发生错误的回调
193 *
194 * 生效时机:`open-type="launchApp"`
195 * @supported weapp, alipay, qq, jd
196 */
197 onError?: CommonEventFunction
198 /** 在打开授权设置页后回调
199 *
200 * 生效时机:`open-type="openSetting"`
201 * @supported weapp, swan, qq, jd
202 */
203 onOpenSetting?: CommonEventFunction<ButtonProps.onOpenSettingEventDetail>
204 /** 打开 APP 成功的回调
205 *
206 * 生效时机:`open-type="launchApp"`
207 * @supported weapp, qq
208 */
209 onLaunchApp?: CommonEventFunction
210 /** 获取用户头像回调
211 *
212 * 生效时机:`open-type="chooseAvatar"`
213 * @supported weapp
214 */
215 onChooseAvatar?: CommonEventFunction
216 /** 点击。
217 * 说明: 每点击一次会触发一次事件,建议自行使用代码防止重复点击,可以使用 js 防抖和节流实现。
218 * @supported alipay
219 */
220 onTap?: CommonEventFunction
221 /** 当 open-type 为 lifestyle 时有效。
222 * 当点击按钮时触发。
223 * event.detail = { followStatus },followStatus 合法值有 1、2、3,其中 1 表示已关注。2 表示用户不允许关注。3 表示发生未知错误;
224 * 已知问题:基础库 1.0,当用户在点击按钮前已关注生活号,event.detail.followStatus 的值为 true。
225 * @supported alipay
226 */
227 onFollowLifestyle?: CommonEventFunction<{
228 followStatus: 1 | 2 | 3 | true
229 }>
230 /** 用户点击该按钮时,调起用户编辑收货地址原生界面,并在编辑完成后返回用户选择的地址,从返回参数的 detail 中获取,和 swan.chooseAddress 一样的。和 open-type 搭配使用,使用时机:open-type="chooseAddress"
231 * @supported swan
232 */
233 onChooseAddress?: CommonEventFunction
234 /** 用户点击该按钮时,选择用户的发票抬头,和 swan.chooseInvoiceTitle 一样的。和 open-type 搭配使用,使用时机:open-type="chooseInvoiceTitle"
235 * @supported swan
236 */
237 onChooseInvoiceTitle?: CommonEventFunction
238 /** 登录回调,和 open-type 搭配使用,使用时机:open-type="login"。可以通过返回参数的 detail 判断是否登录成功,当 errMsg 为'login:ok'时即为成功。如想获取登录凭证请使用 swan.getLoginCode
239 * @supported swan
240 */
241 onLogin?: CommonEventFunction
242 /** 订阅消息授权回调,和 open-type 搭配使用,使用时机:open-type="subscribe"
243 * @supported swan
244 */
245 onSubscribe?: CommonEventFunction
246 /** 添加好友的回调
247 * @supported qq
248 */
249 onAddFriend?: CommonEventFunction
250 /** 添加群应用的回调。errCode 错误码:41004(当前用户非管理员或群主,无权操作),41005(超过可添加群应用的群数量)
251 * @supported qq
252 */
253 onAddGroupApp?: CommonEventFunction
254}
255declare namespace ButtonProps {
256 /** size 的合法值 */
257 interface Size {
258 /** 默认大小 */
259 default
260 /** 小尺寸 */
261 mini
262 }
263 /** type 的合法值 */
264 interface Type {
265 /** 绿色 */
266 primary
267 /** 白色 */
268 default
269 /** 红色 */
270 warn
271 }
272 /** form-type 的合法值 */
273 interface FormType {
274 /** 提交表单 */
275 submit
276 /** 重置表单 */
277 reset
278 }
279 /** open-type 的合法值 */
280 type OpenType = keyof openTypeKeys['weapp'] | keyof openTypeKeys['alipay'] | keyof openTypeKeys['qq']
281 /** open-type 的合法值 */
282 interface openTypeKeys {
283 weapp: {
284 /** 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从回调中获得具体信息
285 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/customer-message.html
286 */
287 contact
288 /** 触发用户转发,使用前建议先阅读使用指引
289 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%BC%95
290 */
291 share
292 /** 获取用户手机号,可以从回调中获取到用户信息
293 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
294 */
295 getPhoneNumber
296 /** 获取用户信息,可以从回调中获取到用户信息 */
297 getUserInfo
298 /** 打开APP,可以通过 app-parameter 属性设定向APP传的参数
299 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/launchApp.html
300 */
301 launchApp
302 /** 打开授权设置页 */
303 openSetting
304 /** 打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容 */
305 feedback
306 /** 获取用户头像,可以从回调中获得具体信息 */
307 chooseAvatar
308 }
309 /** 支付宝小程序专属的 open-type 合法值
310 * @see https://opendocs.alipay.com/mini/component/button
311 */
312 alipay: {
313 /** 触发 自定义分享 */
314 share
315 /** 支持小程序授权 */
316 getAuthorize
317 /** 分享到通讯录好友 */
318 contactShare
319 /** 关注生活号 */
320 lifestyle
321 }
322 /** QQ 小程序专属的 open-type 合法值
323 * @see https://q.qq.com/wiki/develop/miniprogram/component/form/button.html
324 */
325 qq: {
326 /** 触发用户转发,使用前建议先阅读使用指引
327 * @see https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_share.html#%E8%BD%AC%E5%8F%91-2
328 */
329 share
330 /** 获取用户信息,可以从 onGetUserInfo 回调中获取到用户信息 */
331 getUserInfo
332 /** 打开APP,可以通过 app-parameter 属性设定向APP传的参数
333 * @see https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_app.html
334 */
335 launchApp
336 /** 打开授权设置页 */
337 openSetting
338 /** 呼起吐个槽反馈页面,开发者可以到官网查看反馈 */
339 feedback
340 /** 呼起群资料卡页面,可以通过 group-id 属性设定需要打开的群资料卡的群号,同时 app.json 中必须配置 groupIdList(数量不超过 10 个),表明可以打开群资料卡的群号 */
341 openGroupProfile
342 /** 添加好友,对方需要通过该小程序进行授权,允许被加好友后才能调用成功[用户授权](https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_userinfo.html#%E6%8E%88%E6%9D%83) */
343 addFriend
344 /** 添加彩签,点击后添加状态有用户提示,无回调 */
345 addColorSign
346 /** 打开公众号资料卡,可以通过 public-id 属性设定需要打开的公众号资料卡的号码,同时 app.json 中必须配置 publicIdList(目前只能配置 1 个),表明可以打开的公众号资料卡的号码 */
347 openPublicProfile
348 /** 添加群应用(只有管理员或群主有权操作,建议先调用 qq.getGroupInfo 获取当前用户是否为管理员,如果是管理员才显示该按钮),添加后给button绑定 onAddGroupApp 事件接收回调数据。 */
349 addGroupApp
350 /** 在自定义开放数据域组件中,向指定好友发起分享据 */
351 shareMessageToFriend
352 }
353 }
354 /** lang 的合法值 */
355 interface Lang {
356 /** 英文 */
357 en
358 /** 简体中文 */
359 zh_CN
360 /** 繁体中文 */
361 zh_TW
362 }
363 interface onGetUserInfoEventDetail {
364 userInfo: {
365 /** 昵称 */
366 nickName: string
367 /** 头像链接 */
368 avatarUrl: string
369 /** 头像
370 * @supported alipay
371 */
372 avatar: string
373 /** 性别 */
374 gender: keyof Gender
375 /** 省份,如:`Yunnan` */
376 province: string
377 /** 城市,如:`Dalian` */
378 city: string
379 /** 国家,如:`China` */
380 country: string
381 }
382 /** 不包括敏感信息的原始数据 `JSON` 字符串,用于计算签名 */
383 rawData: string
384 /** 使用 `sha1(rawData + sessionkey)` 得到字符串,用于校验用户信息 */
385 signature: string
386 /** 包括敏感数据在内的完整用户信息的加密数据 */
387 encryptedData: string
388 /** 加密算法的初始向量 */
389 iv: string
390 /* 用户信息的调用状态 */
391 errMsg: string
392 /** 敏感数据对应的云 ID,开通[云开发](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)的小程序才会返回,可通过云调用直接获取开放数据,详细见[云调用直接获取开放数据](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html#method-cloud) */
393 cloudID?: string
394 }
395 /** 性别的合法值 */
396 interface Gender {
397 /** 未知 */
398 0
399 /** 男 */
400 1
401 /** 女 */
402 2
403 }
404 interface onContactEventDetail {
405 /* 小程序消息的调用状态 */
406 errMsg: string
407 /** 小程序消息指定的路径 */
408 path: string
409 /** 小程序消息指定的查询参数 */
410 query: Record<string, any>
411 }
412 interface onGetPhoneNumberEventDetail {
413 /* 获取用户手机号的调用状态 */
414 errMsg: string
415 /** 包括敏感数据在内的完整用户信息的加密数据 */
416 encryptedData: string
417 /** 加密算法的初始向量 */
418 iv: string
419 /** 动态令牌。可通过动态令牌换取用户手机号。
420 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%BC%95
421 */
422 code?: string
423 /**
424 * 签名信息,如果在开放平台后台配置了加签方式后有此字段
425 * @supported alipay
426 */
427 sign: string
428 }
429 interface onOpenSettingEventDetail {
430 /* 打开授权设置页的调用状态 */
431 errMsg: string
432 /* 用户授权结果 */
433 authSetting: Record<string, boolean>
434 }
435}
436/** 按钮
437 * @classification forms
438 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony
439 * @example_react
440 * ```tsx
441 * export default class PageButton extends Component {
442 * state = {
443 * btn: [
444 * {
445 * text: '页面主操作 Normal',
446 * size: 'default',
447 * type: 'primary'
448 * },
449 * {
450 * text: '页面主操作 Loading',
451 * size: 'default',
452 * type: 'primary',
453 * loading: true,
454 * },
455 * {
456 * text: '页面主操作 Disabled',
457 * size: 'default',
458 * type: 'primary',
459 * disabled: true,
460 * },
461 * {
462 * text: '页面次要操作 Normal',
463 * size: 'default',
464 * type: 'default'
465 * },
466 * {
467 * text: '页面次要操作 Disabled',
468 * size: 'default',
469 * type: 'default',
470 * disabled: true,
471 * },
472 * {
473 * text: '警告类操作 Normal',
474 * size: 'default',
475 * type: 'warn'
476 * },
477 * {
478 * text: '警告类操作 Disabled',
479 * size: 'default',
480 * type: 'warn',
481 * disabled: true,
482 * }
483 * ]
484 * }
485 * render () {
486 * return (
487 * <View className='container'>
488 * {this.state.btn.map(item => {
489 * return (
490 * <Button
491 * size={item.size ? item.size : ''}
492 * type={item.type ? item.type : ''}
493 * loading={item.loading ? item.loading : false}
494 * disabled={item.disabled ? item.disabled : false}
495 * >
496 * {item.text}
497 * </Button>
498 * )
499 * })}
500 * <Button className='btn-max-w' plain type='primary'>按钮</Button>
501 * <Button className='btn-max-w' plain type='primary' disabled>不可点击的按钮</Button>
502 * <Button className='btn-max-w' plain >按钮</Button>
503 * <Button className='btn-max-w' plain disabled >按钮</Button>
504 * <Button size='mini' type='primary'>按钮</Button>
505 * <Button size='mini' >按钮</Button>
506 * <Button size='mini' type='warn'>按钮</Button>
507 * </View>
508 * )
509 * }
510 * }
511 * ```
512 * @example_vue
513 * ```html
514 * <template>
515 * <view class="container">
516 * <button
517 * v-for="item in btn"
518 * :size="item.size ? item.size : ''"
519 * :type="item.type ? item.type : ''"
520 * :loading="item.loading ? item.loading : false"
521 * :disabled="item.disabled ? item.disabled : false"
522 * >
523 * {{ item.text }}
524 * </button>
525 * <button class="btn-max-w" :plain="true" type="primary">按钮</button>
526 * <button class="btn-max-w" :plain="true" type="primary" :disabled="true">不可点击的按钮</button>
527 * <button class="btn-max-w" :plain="true">按钮</button>
528 * <button class="btn-max-w" :plain="true" :disabled="true">按钮</button>
529 * <button size="mini" type="primary">按钮</button>
530 * <button size="mini" >按钮</button>
531 * <button size="mini" type="warn">按钮</button>
532 * </view>
533 * </template>
534 *
535 * <script>
536 * export default {
537 * data() {
538 * return {
539 * btn: [
540 * {
541 * text: '页面主操作 Normal',
542 * size: 'default',
543 * type: 'primary'
544 * },
545 * {
546 * text: '页面主操作 Loading',
547 * size: 'default',
548 * type: 'primary',
549 * loading: true,
550 * },
551 * {
552 * text: '页面主操作 Disabled',
553 * size: 'default',
554 * type: 'primary',
555 * disabled: true,
556 * },
557 * {
558 * text: '页面次要操作 Normal',
559 * size: 'default',
560 * type: 'default'
561 * },
562 * {
563 * text: '页面次要操作 Disabled',
564 * size: 'default',
565 * type: 'default',
566 * disabled: true,
567 * },
568 * {
569 * text: '警告类操作 Normal',
570 * size: 'default',
571 * type: 'warn'
572 * },
573 * {
574 * text: '警告类操作 Disabled',
575 * size: 'default',
576 * type: 'warn',
577 * disabled: true,
578 * }
579 * ]
580 * }
581 * }
582 * }
583 * </script>
584 * ```
585 * @see https://developers.weixin.qq.com/miniprogram/dev/component/button.html
586 */
587declare const Button: ComponentType<ButtonProps>
588export { Button, ButtonProps }