Skip to content

Commit

Permalink
📃 docs: 初步完成 MessageBox 组件文档
Browse files Browse the repository at this point in the history
  • Loading branch information
GuoJikun committed Jan 17, 2024
1 parent 7a89f70 commit a40dac1
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 62 deletions.
128 changes: 66 additions & 62 deletions packages/docs/src/.vitepress/config/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ const guide = [

const basic = [
{
text: "Icon 图标",
link: "/components/icon",
text: "AspectRatio 比例容器",
link: "/components/aspect-ratio",
},
{
text: "Button 按钮",
link: "/components/button",
},
{
text: "Divider 分割线",
link: "/components/divider",
},
{
text: "Icon 图标",
link: "/components/icon",
},
{
text: "Space 间距",
link: "/components/space",
Expand All @@ -46,14 +54,6 @@ const basic = [
text: "Split 分割面板",
link: "/components/split",
},
{
text: "Divider 分割线",
link: "/components/divider",
},
{
text: "AspectRatio 比例容器",
link: "/components/aspect-ratio",
},
{
text: "Scrollbar 滚动条",
link: "/components/scrollbar",
Expand All @@ -79,28 +79,28 @@ const components = [
collapsible: true,
items: [
{
text: "Input 输入框",
link: "/components/input",
text: "Checkbox 多选框",
link: "/components/checkbox",
},
{
text: "Select 选择框",
link: "/components/select",
text: "Input 输入框",
link: "/components/input",
},
{
text: "Radio 单选框",
link: "/components/radio",
},
{
text: "Checkbox 多选框",
link: "/components/checkbox",
text: "Rate 评分",
link: "/components/rate",
},
{
text: "Switch 开关",
link: "/components/switch",
text: "Select 选择框",
link: "/components/select",
},
{
text: "Rate 评分",
link: "/components/rate",
text: "Switch 开关",
link: "/components/switch",
},
],
},
Expand All @@ -116,53 +116,53 @@ const components = [
text: "Description 描述列表",
link: "/components/description",
},
{
text: "Table 表格",
link: "/components/table",
},
{
text: "Tag 标签",
link: "/components/tag",
},
{
text: "Badge 徽标",
link: "/components/badge",
},
{
text: "Empty 空状态",
link: "/components/empty",
},
{
text: "Timeline 时间线",
link: "/components/timeline",
},
{
text: "Card 卡片",
link: "/components/card",
},
{
text: "Progress 进度条",
link: "/components/progress",
text: "Carousel 轮播图",
link: "/components/carousel",
},
{
text: "Circle 环形进度条",
link: "/components/circle",
},
{
text: "Collapse 折叠面板",
link: "/components/collapse",
},
{
text: "Image 图片",
link: "/components/image",
text: "Empty 空状态",
link: "/components/empty",
},
{
text: "Circle 环形进度条",
link: "/components/circle",
text: "Image 图片",
link: "/components/image",
},
{
text: "Pagination 分页",
link: "/components/pagination",
},
{
text: "Carousel 轮播图",
link: "/components/carousel",
text: "Progress 进度条",
link: "/components/progress",
},
{
text: "Table 表格",
link: "/components/table",
},
{
text: "Tag 标签",
link: "/components/tag",
},
{
text: "Timeline 时间线",
link: "/components/timeline",
},
{
text: "Tree 树形控件",
Expand All @@ -175,36 +175,40 @@ const components = [
collapsible: true,
items: [
{
text: "Tip 提示信息",
link: "/components/tip",
text: "Dialog 对话框",
link: "/components/dialog",
},
{
text: "Message 消息提示",
link: "/components/message",
text: "Drawer 抽屉",
link: "/components/drawer",
},
{
text: "Tooltip 文字提示",
link: "/components/tooltip",
text: "Loading 加载",
link: "/components/loading",
},
{
text: "Dialog 对话框",
link: "/components/dialog",
text: "Message 消息提示",
link: "/components/message",
},
{
text: "Notification 通知框",
link: "/components/notification",
text: "MessageBox 消息弹出框",
link: "/components/message-box",
},
{
text: "Drawer 抽屉",
link: "/components/drawer",
text: "Notification 通知框",
link: "/components/notification",
},
{
text: "Result 结果",
link: "/components/result",
},
{
text: "Loading 加载",
link: "/components/loading",
text: "Tip 提示信息",
link: "/components/tip",
},
{
text: "Tooltip 文字提示",
link: "/components/tooltip",
},
],
},
Expand All @@ -220,14 +224,14 @@ const components = [
text: "Breadcrumb 面包屑",
link: "/components/breadcrumb",
},
{
text: "Steps 步骤条",
link: "/components/steps",
},
{
text: "Dropdown 下拉菜单",
link: "/components/dropdown",
},
{
text: "Steps 步骤条",
link: "/components/steps",
},
{
text: "Tabs 标签页",
link: "/components/tab",
Expand Down
95 changes: 95 additions & 0 deletions packages/docs/src/components/message-box.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# MessageBox 消息弹出框

模拟系统的消息提示框而实现的一套模态对话框组件,用于消息提示、确认消息和提交内容。

:::tip 提示
从设计上来说,MessageBox 的作用是美化系统自带的 alert、confirm 和 prompt,因此适合展示较为简单的内容。 如果需要弹出较为复杂的内容,请使用 Dialog。
:::

## 消息提示

当用户进行操作时会被触发,该对话框中断用户操作,直到用户确认知晓后才可关闭。

调用 MessageBox.alert 方法以打开 `alert` 框。 它模拟了系统的 `alert`

<ivy-button type="primary" @click="showMsgBox"> 打开一个 Alert 消息框 </ivy-button>

## 确认消息

提示用户确认其已经触发的动作,并询问是否进行此操作时会用到此对话框。

调用 ElMessageBox.confirm 方法以打开 confirm 框。它模拟了系统的 confirm。
Message Box 组件也拥有极高的定制性,我们可以传入 options 作为第三个参数,它是一个字面量对象。
type 字段表明消息类型,可以为success,error,info和 warning,无效的设置将会被忽略。
需要注意的是,第二个参数 title 必须定义为 String 类型,如果是 Object,会被当做为 options使用。 在这里我们返回了一个 Promise 来处理后续响应。

<ivy-button type="primary" @click="showConfirmBox"> 打开一个 Confirm 消息框 </ivy-button>

## 提交内容

当需要用户输入内容时,可以使用 Prompt 类型的消息框。

调用 ElMessageBox.prompt 方法以打开 prompt 框。它模拟了系统的 prompt。
可以用 inputPattern 字段自己规定匹配模式, 使用 inputValidator 来指定验证方法,它应该返回 Boolean 或 String。
返回 false 或 String 表示验证失败, 返回的字符串将用作 inputErrorMessage,用来提示用户错误原因。
此外,可以用 inputPlaceholder 字段来定义输入框的占位符。

<ivy-button type="primary" @click="showPromptBox"> 打开一个 Prompt 消息框 </ivy-button>

## API

### 属性

| 名称 | 说明 | 类型 | 可选值 | 默认值 |
| -------- | -------- | ------ | --------------- | ------ |
| offset | 偏移距离 | number | - | `0` |
| position | 固钉位置 | string | `top \| bottom` | `top` |
| z-index | z-index | number | - | `100` |

### 事件

| 名称 | 说明 | 类型 |
| ------ | ------------------------ | ---------------------------------------- |
| change | 固钉状态改变时触发的事件 | ({fixed:boolean})=>void |
| scroll | 滚动时触发的事件 | ({fixed:boolean,scrollTop:number})=>void |

<script setup>
import { $ivy } from '@ivy-design/ce'
const showMsgBox = () => {
console.log('click', $ivy)
$ivy.msgBox({
title: '提示',
message: '这是一条提示消息',
})
}

const showConfirmBox = () => {
$ivy.msgBox.confirm('你确定要删除这条信息吗?', "提示", {
type: 'warning',
showCancelButton: true,
confirmButtonText: '确定',
cancelButtonText: '取消',
}).then(() => {
console.log('confirm')
}).catch(() => {
console.log('cancel')
})
}

const showPromptBox = () => {
$ivy.msgBox.prompt('请输入内容', "提示", {
inputPattern: /^[a-zA-Z0-9]+$/,
inputErrorMessage: '只能输入数字',
inputPlaceholder: '请输入内容',
confirmButtonText: '确定',
cancelButtonText: '取消',
inputValidator: (val)=>{
return !/^[a-zA-Z0-9]+$/.test(val)
}
}).then((value) => {
console.log('confirm', value)
}).catch(() => {
console.log('cancel')
})
}
</script>

0 comments on commit a40dac1

Please sign in to comment.