From 33764cd32888f62d48fa4d9182001a21a9016363 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 29 Aug 2019 11:05:22 +0800 Subject: [PATCH] docs(Popup): update demo (#1926) --- example/pages/popup/index.js | 56 +++++++++++++++---------- example/pages/popup/index.wxml | 74 +++++++++++++--------------------- example/pages/popup/index.wxss | 29 ------------- packages/popup/README.md | 26 +++++++----- 4 files changed, 80 insertions(+), 105 deletions(-) diff --git a/example/pages/popup/index.js b/example/pages/popup/index.js index eaf2549d..038ddf39 100644 --- a/example/pages/popup/index.js +++ b/example/pages/popup/index.js @@ -3,44 +3,58 @@ import Page from '../../common/page'; Page({ data: { show: { - middle: false, + basic: false, top: false, bottom: false, - right: false, - right2: false + left: false, + right: false } }, - onTransitionEnd() { - console.log(`You can't see me 🌚`); - }, - toggle(type) { + toggle(type, show) { this.setData({ - [`show.${type}`]: !this.data.show[type] + [`show.${type}`]: show }); }, - togglePopup() { - this.toggle('middle'); + showBasic() { + this.toggle('basic', true); }, - toggleRightPopup() { - this.toggle('right'); + hideBasic() { + this.toggle('basic', false); }, - toggleRightPopup2() { - this.toggle('right2'); + showTop() { + this.toggle('top', true); }, - toggleBottomPopup() { - this.toggle('bottom'); + hideTop() { + this.toggle('top', false); }, - toggleTopPopup() { - this.toggle('top'); - setTimeout(() => { - this.toggle('top'); - }, 2000); + showLeft() { + this.toggle('left', true); + }, + + hideLeft() { + this.toggle('left', false); + }, + + showRight() { + this.toggle('right', true); + }, + + hideRight() { + this.toggle('right', false); + }, + + showBottom() { + this.toggle('bottom', true); + }, + + hideBottom() { + this.toggle('bottom', false); }, onClickLeft() { diff --git a/example/pages/popup/index.wxml b/example/pages/popup/index.wxml index bca283ac..6b497c25 100644 --- a/example/pages/popup/index.wxml +++ b/example/pages/popup/index.wxml @@ -6,65 +6,47 @@ /> - 弹出 Popup + 展示弹出层 内容 - 底部弹出 + + 顶部弹出 + 底部弹出 + - - 内容 - + 左侧弹出 + 右侧弹出 - 顶部弹出 - 内容 - - - 右侧弹出 + custom-style="height: 20%" + bind:close="hideTop" + /> + + - 关闭弹层 - - 右侧弹出 - - 关闭弹层 - - + custom-style="width: 20%; height: 100%" + bind:close="hideRight" + /> diff --git a/example/pages/popup/index.wxss b/example/pages/popup/index.wxss index cb419fa3..4b87cdf4 100644 --- a/example/pages/popup/index.wxss +++ b/example/pages/popup/index.wxss @@ -1,32 +1,3 @@ :host { font-size: 16px; } - -.center { - width: 60%; - padding: 20px; - text-align: center; - box-sizing: border-box; -} - -.top { - color: #fff; - width: 100%; - padding: 20px; - border-radius: 0; - line-height: 20px; - background-color: rgba(0, 0, 0, 0.8)!important; -} - -.bottom { - width: 100%; - padding: 20px; - line-height: 100px; - background-color: #fff; -} - -.right { - width: 100%; - height: 100%; - padding: 20px; -} diff --git a/packages/popup/README.md b/packages/popup/README.md index 5aa928d4..01ce8367 100644 --- a/packages/popup/README.md +++ b/packages/popup/README.md @@ -12,9 +12,14 @@ ## 代码演示 ### 基础用法 -`popup`默认从中间弹出 + +通过`show`属性控制弹出层是否展示 ```html + + 展示弹出层 + + 内容 ``` @@ -24,6 +29,10 @@ Page({ show: false }, + showPopup() { + this.setData({ show: true }); + }, + onClose() { this.setData({ show: false }); } @@ -31,17 +40,16 @@ Page({ ``` ### 弹出位置 -通过`position`属性设置 Popup 弹出位置 + +通过`position`属性设置弹出位置,默认居中弹出,可以设置为`top`、`bottom`、`left`、`right` ```html - 内容 - +/> ``` ### Props @@ -50,12 +58,12 @@ Page({ |-----------|-----------|-----------|-------------| | show | 是否显示弹出层 | *boolean* | `false` | | z-index | z-index 层级 | *number* | `100` | -| overlay | 是否显示背景蒙层 | *boolean* | `true` | -| position | 可选值为 `top` `bottom` `right` `left` | *string* | - | +| overlay | 是否显示遮罩层 | *boolean* | `true` | +| position | 弹出位置,可选值为 `top` `bottom` `right` `left` | *string* | `center` | | duration | 动画时长,单位为毫秒 | *number \| object* | `300` | | custom-style | 自定义弹出层样式 | *string* | `` | | overlay-style | 自定义背景蒙层样式 | *string* | `` | -| close-on-click-overlay | 点击蒙层是否关闭 Popup | *boolean* | `true` | +| close-on-click-overlay | 是否在点击遮罩层后关闭 | *boolean* | `true` | | safe-area-inset-bottom | 是否为 iPhoneX 留出底部安全距离 | *boolean* | `true` | | safe-area-inset-top | 是否留出顶部安全距离(状态栏高度 + 导航栏高度) | *boolean* | `false` |