🔥 遇见我们的新项目 t0ggles - 你终极的项目管理工具! 🔥

弹窗 React 组件

弹窗是一个弹出窗口,包含任何 HTML 内容,它会弹出到应用程序的主内容之上。弹窗与所有其他叠加层一样,是所谓的“临时视图”的一部分。

以下组件包含在内

  • Popup - 弹出元素
名称类型默认值描述
backdrop布尔值true

启用弹窗背景(弹出后面半透明的暗层)

colors对象

带有 Tailwind CSS 颜色类的对象

colors.bg字符串'bg-white dark:bg-black'

弹窗背景颜色

component字符串'div'

组件的 HTML 元素

opened布尔值false

允许打开/关闭弹窗并设置其初始状态

size字符串'w-screen h-screen md:w-160 md:h-160'

Tailwind CSS 尺寸类

onBackdropClick函数(e)

背景元素上的点击处理程序

示例

Popup.jsx
import React, { useState } from 'react';
import {
Page,
Navbar,
NavbarBackLink,
Popup,
Block,
Link,
Button,
} from 'konsta/react';
export default function PopupPage() {
const [popupOpened, setPopupOpened] = useState(false);
return (
<Page>
<Navbar
title="Popup"
/>
<Block strong className="space-y-4">
<p>
Popup is a modal window with any HTML content that pops up over App's
main content. Popup as all other overlays is part of so called
"Temporary Views".
</p>
<p>
<Button onClick={() => setPopupOpened(true)}>Open Popup</Button>
</p>
</Block>
<Popup opened={popupOpened} onBackdropClick={() => setPopupOpened(false)}>
<Page>
<Navbar
title="Popup"
right={
<Link navbar onClick={() => setPopupOpened(false)}>
Close
</Link>
}
/>
<Block className="space-y-4">
<p>
Here comes popup. You can put here anything, even independent view
with its own navigation. Also not, that by default popup looks a
bit different on iPhone/iPod and iPad, on iPhone it is fullscreen.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse faucibus mauris leo, eu bibendum neque congue non. Ut
leo mauris, eleifend eu commodo a, egestas ac urna. Maecenas in
lacus faucibus, viverra ipsum pulvinar, molestie arcu. Etiam
lacinia venenatis dignissim. Suspendisse non nisl semper tellus
malesuada suscipit eu et eros. Nulla eu enim quis quam elementum
vulputate. Mauris ornare consequat nunc viverra pellentesque.
Aenean semper eu massa sit amet aliquam. Integer et neque sed
libero mollis elementum at vitae ligula. Vestibulum pharetra sed
libero sed porttitor. Suspendisse a faucibus lectus.
</p>
<p>
Duis ut mauris sollicitudin, venenatis nisi sed, luctus ligula.
Phasellus blandit nisl ut lorem semper pharetra. Nullam tortor
nibh, suscipit in consequat vel, feugiat sed quam. Nam risus
libero, auctor vel tristique ac, malesuada ut ante. Sed molestie,
est in eleifend sagittis, leo tortor ullamcorper erat, at
vulputate eros sapien nec libero. Mauris dapibus laoreet nibh quis
bibendum. Fusce dolor sem, suscipit in iaculis id, pharetra at
urna. Pellentesque tempor congue massa quis faucibus. Vestibulum
nunc eros, convallis blandit dui sit amet, gravida adipiscing
libero.
</p>
</Block>
</Page>
</Popup>
</Page>
);
}
代码许可证: MIT.
2022 © Konsta UI 由 nolimits4web.