# Popup

### [Demo](https://vant.bctc.io/?path=/story/popup--default-popup)

#### Install

```
import React from 'react';
import { Popup } from 'vant-react';
```

## Usage

{% hint style="info" %}
Every popup should have its own state.
{% endhint %}

```
const [centerPopup, setCenterPopup] = useState(false);

<Button click={() => {setCenterPopup(true)}}/>
<Popup isActive={centerPopup} setActive={setCenterPopup} />
```

#### Type

```
<Popup type='top'/>
<Popup type='bottom'/>
<Popup type='left'/>
<Popup type='right'/>
```

#### Size

```
<Popup size={{width:'200px', height:'200px'}} />
<Popup size={{width:'50vwx', height:'60vh'}} />
```

#### Content

```
<Popup text={{
          text: 'It`s a popup',
          color: '#666',
          fontSize: '30px',
          textAlign: 'center'
        }} />
<Popup content={<Component />} />
```

#### CloseIcon

```
<Popup closeable />
<Popup closeable closeIcon={{ name: 'close', size: '20px' }} />
<Popup closeable closeIconPosition={{ top: '40px', left: '40px' }} />
```

#### Round Corner

```
<Popup borderRadius='50px' />
```

#### Custom Color

```
<Popup color='#b90000' />
<Popup color='rgba(234, 123, 232,0.4)' />
```

#### Action

```
<Popup text={{
          text: 'Click me',
          color: '#000',
          fontSize: '30px',
          textAlign: 'center'
        }}
       size={{width:'300px', height:'60vh'}}
       click={(e) => { alert(e) }} />
```

## API

#### Props

| Attribute           | Description                                                                                        | Type                                                                           | Default  | Required   |
| ------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | -------- | ---------- |
| `type`              | Can be set to `left` `right` `top` `bottom`                                                        | _**string**_                                                                   | `center` | _optional_ |
| `text`              | <p>Text to be displayed in popup ,<code>{text,color,size,</code></p><p><code>textAlign}</code></p> | _**object**_                                                                   | -        | _optional_ |
| `color`             | Popup background-color, in hex value:`#b90000`, in gradient value in rgba:`rgb(210,210,210,0.4)`   | _**string**_                                                                   | -        | _optional_ |
| `borderRadius`      | round corner                                                                                       | _**string**_                                                                   | -        | _optional_ |
| `size`              | popup size , { width: '10px', height: '100vh' }                                                    | _**object**_                                                                   | -        | _optional_ |
| `padding`           | <p>content padding ,  </p><p><code>10px</code> <code>0 20px</code> </p>                            | _**string**_                                                                   | -        | _optional_ |
| `content`           | Component to be displayed in popup                                                                 | <p><em><strong>React</strong></em></p><p><em><strong>Element</strong></em></p> | -        | _optional_ |
| `closeable`         | show close icon in popup                                                                           | _**boolean**_                                                                  | `false`  | _optional_ |
| `closeIcon`         | custom your close icon ,`{iconName, iconSize}`                                                     | _**object**_                                                                   | -        | _optional_ |
| `closeIconPosition` | `Ex: { top: '40px', left: '40px' }`                                                                | _**object**_                                                                   | -        | _optional_ |

#### Event

| Event   | Description                                                                  | Arguments      |
| ------- | ---------------------------------------------------------------------------- | -------------- |
| `click` | <p>Triggered when click text in popup </p><p>and not disabled or loading</p> | _event: Event_ |

