Popup
Popup 弹出层
代码示例
import { BfPopup } from '@bud-fe/react-taro-ui';import { Button, View } from '@tarojs/components';import React, { useState } from 'react';export default () => {const [visible, setVisible] = useState(false);const [showTop, setShowTop] = useState(false);const [showBottom, setShowBottom] = useState(false);const [showLeft, setShowLeft] = useState(false);const [showRight, setShowRight] = useState(false);return (<><View className="group-title">基础用法</View><Button onClick={() => setVisible(true)}>显示</Button><View className="group-title">弹出位置</View><Button onClick={() => setShowTop(true)}>顶部弹出</Button><Button onClick={() => setShowBottom(true)}>底部弹出</Button><Button onClick={() => setShowLeft(true)}>左侧弹出</Button><Button onClick={() => setShowRight(true)}>右侧弹出</Button><BfPopup visible={visible} style={{ padding: 30 }} onClose={() => setVisible(false)}>正文</BfPopup><BfPopup visible={showTop} style={{ height: '20%' }} position="top" onClose={() => setShowTop(false)} /><BfPopup visible={showBottom} style={{ height: '20%' }} position="bottom" onClose={() => setShowBottom(false)} /><BfPopupvisible={showLeft}style={{ width: '50%', height: '100%' }}position="left"onClose={() => setShowLeft(false)}/><BfPopupvisible={showRight}style={{ width: '50%', height: '100%' }}position="right"onClose={() => setShowRight(false)}/></>);};
API
属性名 | 描述 | 类型 | 默认值 |
---|---|---|---|
position | 弹出位置 top | bottom | left | right | center | string | center |
overlayStyle | 自定义遮罩样式 | CSSProperties | -- |
overlayClassName | 自定义遮罩类名 | string | -- |
closeIcon | 关闭 Icon | any | -- |
closeIconPosition | 关闭按钮位置 top-left | top-right | bottom-left | bottom-right | string | top-right |
left | 标题左侧部分 | any | -- |
title | 标题中间部分 | any | -- |
description | 子标题/描述部分 | any | -- |
mountOnEnter | 内容区元素是否只在动画开始时挂载 | boolean | true |
destroyOnClose | 组件不可见时,卸载内容 | boolean | false |
portal | 指定节点挂载 | Teleport | -- |
overlay | 是否显示遮罩 | boolean | true |
round | 是否显示圆角 | boolean | false |
onOpen | 打开弹框时触发 | () => void | -- |
onClose | 关闭弹框时触发 | () => void | -- |
onOverlayClick | 点击遮罩触发 | (e: ITouchEvent) => boolean | void | `() => true` |
onCloseIconClick | 点击关闭图标时触发 | (e: ITouchEvent) => boolean | void | `() => true`` |
onGetContentRef | 获取内容区的元素实例 | (ref: HTMLDivElement) => void | -- |