# Popup 弹出层

### 介绍

弹出层容器，用于展示弹窗、信息提示等内容，支持多个弹出层叠加展示

### 引入

在`index.config.js中引入组件

```json
"usingComponents": {
  "van-popup": "@vant/weapp/popup/index"
}
```

## 代码演示

### 基础用法

通过`show`属性控制弹出层是否展示

```html
<van-cell title="展示弹出层" isLink onClick={() => this.showPopup()} />

<van-popup show="{{ show }}" onClose="() => this.onClose()">内容</van-popup>
```

```javascript
class PopupComponents extends Component {
  state = {
    show: false,
  }

  showPopup() {
    this.setState({ show: true });
  }
  onClose() {
    this.setState({ show: false });
  }
}
```

### 弹出位置

通过`position`属性设置弹出位置，默认居中弹出，可以设置为`top`、`bottom`、`left`、`right`

```html
<van-popup
  show={ this.state.show }
  position="top"
  customStyle="height: 20%;"
  onClose="() => this.onClose()"
/>
```

### 关闭图标

设置`closeable`属性后，会在弹出层的右上角显示关闭图标，并且可以通过`close-icon`属性自定义图标，使用`close-icon-position`属性可以自定义图标位置

```html
<van-popup
  show={ this.state.show }
  closeable
  position="bottom"
  customStyle="height: 20%"
  onClose="() => this.onClose()"
/>

<!-- 自定义图标 -->
<van-popup
  show={ this.state.show }
  closeable
  closeIcon="close"
  position="bottom"
  customStyle="height: 20%"
  onClose="() => this.onClose()"
/>

<!-- 图标位置 -->
<van-popup
  show={ this.state.show }
  closeable
  closeIconPosition="top-left"
  position="bottom"
  customStyle="height: 20%"
  onClose="() => this.onClose()"
/>
```

### 圆角弹窗

设置`round`属性后，弹窗会根据弹出位置添加不同的圆角样式

```html
<van-popup
  show={ this.state.show }
  round
  position="bottom"
  customStyle="height: 20%"
  onClose="() => this.onClose()"
/>
```


## API
### 注:属性应用在组件上需要统一使用驼峰式命名，如custom-class应变为
```html
<van-button type="primary" customClass='myClass' size="large">大号按钮</van-button>
```
### 注:事件应用在组件上需要统一使用驼峰式命名，如bind:click/bind:search/bind:before-enter应变为
```html
<van-button type="primary" onClick={()=>this.onClick()}>大号按钮</van-button>
<van-search type="primary" onSearch={()=>this.onSearch()}>大号按钮</van-search>
<van-transition type="primary" onBeforeEnter={()=>this.onBeforeEnter()}>大号按钮</van-transition>
```
### Props

| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| show | 是否显示弹出层 | _boolean_ | `false` | - |
| z-index | z-index 层级 | _number_ | `100` | - |
| overlay | 是否显示遮罩层 | _boolean_ | `true` | - |
| position | 弹出位置，可选值为 `top` `bottom` `right` `left` | _string_ | `center` | - |
| duration | 动画时长，单位为毫秒 | _number \| object_ | `300` | - |
| round | 是否显示圆角 | _boolean_ | `false` | - |
| custom-style | 自定义弹出层样式 | _string_ | `` | - |
| overlay-style | 自定义遮罩层样式 | _string_ | `` | - |
| close-on-click-overlay | 是否在点击遮罩层后关闭 | _boolean_ | `true` | - |
| closeable | 是否显示关闭图标 | _boolean_ | `false` | - |
| close-icon | 关闭图标名称或图片链接 | _string_ | `cross` | - |
| safe-area-inset-bottom | 是否为 iPhoneX 留出底部安全距离 | _boolean_ | `true` | - |
| safe-area-inset-top | 是否留出顶部安全距离（状态栏高度） | _boolean_ | `false` | - |

### Events

| 事件名             | 说明             | 参数 |
| ------------------ | ---------------- | ---- |
| bind:close         | 关闭弹出层时触发 | -    |
| bind:click-overlay | 点击遮罩层时触发 | -    |
| bind:before-enter  | 进入前触发       | -    |
| bind:enter         | 进入中触发       | -    |
| bind:after-enter   | 进入后触发       | -    |
| bind:before-leave  | 离开前触发       | -    |
| bind:leave         | 离开中触发       | -    |
| bind:after-leave   | 离开后触发       | -    |

### 外部样式类

| 类名         | 说明         |
| ------------ | ------------ |
| custom-class | 根节点样式类 |
