UNPKG

1.17 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps } from './common'
3interface RootPortalProps extends StandardProps {
4 /**
5 * 是否从页面中脱离出来
6 * @supported weapp
7 * @default true
8 */
9 enable?: boolean
10}
11
12/** root-portal
13 * 使整个子树从页面中脱离出来,类似于在 CSS 中使用 fixed position 的效果。主要用于制作弹窗、弹出层等。
14 * @see https://developers.weixin.qq.com/miniprogram/dev/component/root-portal.html
15 * @classification viewContainer
16 * @supported weapp
17 * @example_react
18 * ```tsx
19 * import { useState } from 'react'
20 * import { RootPortal, View, Button } from '@tarojs/components'
21 *
22 * export default function RootPortalExample {
23 * const [show, setShow] = useState(false)
24 * const toggle = () => {
25 * setShow(!show)
26 * }
27 * render () {
28 * return (
29 * <View>
30 * <Button onClick={toggle}>显示root-portal</Button>
31 * {
32 * show && (<RootPortal><View>content</View></RootPortal>)
33 * }
34 * </View>
35 * )
36 * }
37 * }
38 * ```
39 */
40declare const RootPortal: ComponentType<RootPortalProps>
41
42export { RootPortal, RootPortalProps }