UI弹出呈现
alert
显示提示框。
alert(options) 显示系统提示框。点击任意按钮后,先执行该按钮的 action,再调用 onDismiss。
import { Button, Modifier, Text, TextField, useState } from "onescript/views"
function FileRow() {
const [deleting, setDeleting] = useState(false)
const [renaming, setRenaming] = useState(false)
const [name, setName] = useState("notes.txt")
return (
<Text modifier={Modifier
.alert({
title: "删除这个文件?",
message: "此操作无法撤销。",
isPresented: deleting,
onDismiss: () => setDeleting(false),
actions: [
<Button
role="destructive"
action={() => remove()}
>
删除
</Button>,
<Button
role="cancel"
action={() => {}}
>
取消
</Button>,
],
})
.alert({
title: "重命名",
isPresented: renaming,
onDismiss: () => setRenaming(false),
actions: [
<TextField
value={name}
onChange={setName}
prompt="文件名"
/>,
<Button action={() => rename(name)}>保存</Button>,
<Button
role="cancel"
action={() => {}}
>
取消
</Button>,
],
})}>
{name}
</Text>
)
}| 参数 | 类型 | 说明 |
|---|---|---|
title | string | 标题。 |
message | string | 可选。标题下方的说明文字。 |
isPresented | boolean | 是否显示。 |
onDismiss | () => void | 提示框关闭时调用,需在其中把 isPresented 设为 false。 |
actions | ViewChild | 按钮与输入框。不传按钮时系统显示一个"好"按钮。 |
How is this guide?
最后更新于