# patchkit-modal

> Modal (popup) components

Latest version **1.3.1** (published 2016-07-10) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install patchkit-modal
pnpm add patchkit-modal
yarn add patchkit-modal
bun add patchkit-modal
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2016-07-10 |
| First published | 2016-04-01 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Paul Frazee |
| Maintainers | pfraze |
| Keywords | react |

## Links

- npm: https://www.npmjs.com/package/patchkit-modal
- Repository: https://github.com/patchkit/patchkit-modal
- Homepage: https://github.com/patchkit/patchkit-modal#readme
- Issues: https://github.com/patchkit/patchkit-modal/issues
- npm.io page: https://npm.io/package/patchkit-modal

## Dependencies (3)

- [react](https://npm.io/package/react.md) ^0.14.6
- [patchwork-translations](https://npm.io/package/patchwork-translations.md) ^1.0.0
- [patchkit-stepped-progress-bar](https://npm.io/package/patchkit-stepped-progress-bar.md) ^1.0.4

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.3.1 (latest) — 2016-07-10
- 1.3.0 — 2016-07-07
- 1.2.1 — 2016-04-08
- 1.2.0 — 2016-04-08
- 1.1.0 — 2016-04-03
- 1.0.3 — 2016-04-02
- 1.0.2 — 2016-04-02
- 1.0.1 — 2016-04-02
- 1.0.0 — 2016-04-01

## README

# Modal

Modal (popup) component, in fullscreen and centered-block.
Includes a Btn component for triggering the modal, and a Flow component for when there are multiple modals that follow a wizard-style of flow.

![screenshot.png](screenshot.png)

## Usage

The simplest way to use the modals is with a the `<Btn>` component, which will handle the logic for showing and hiding them.
The `<Btn>` will pass through all properties to the modal.

```jsx
import ModalBtn from 'patchkit-modal/btn'

// define the "forms" to go inside the modal:
class ModalContent1 extends React.Component {
  // ...
}
class ModalContent2 extends React.Component {
  // ...
}

// single modal
<ModalBtn Form={ModalContent1} className="fullheight" onClose={onClose}>Click to open</ModalBtn>

// modal flow
<ModalBtn Forms={[ModalContent1, ModalContent2]} className="fullheight" onClose={onClose}>Click to open</ModalBtn>
```

The `<Btn>` wraps its children in a clickable region, but adds no visual elements, so you can put custom elements inside to control its appearance:

```jsx
<ModalBtn Form={ModalContent1} className="fullheight" onClose={onClose}>
  <a className="btn highlighted">Click to open</a>
</ModalBtn>
```

However, you can use the modals directly, if you want to show/hide the modal using different logic.

```jsx
import ModalSingle from 'patchkit-modal/single'
import ModalFlow from 'patchkit-modal/flow'

<ModalSingle Form={ModalContent1} className="fullheight" onClose={onClose} isOpen={true|false} />
<ModalFlow Forms={[ModalContent1, ModalContent2]} className="fullheight" onClose={onClose} isOpen={true|false} />
```

The 'Form' should implement a `submit(cb)` function, to be called when the Modal's next/finish button is pressed.
It should also call...

 - `this.props.isValid(true|false)` to indicate whether next/finish should be clickable.
 - `this.props.isHighlighted(true|false)` to indicate whether next/finish should be highlighted blue or not.
 - `this.props.setHelpText(str)` to set some help-text at the bottom of the modal.

Example:

```jsx
class ModalForm extends React.Component {
  constructor(props) {
    super(props)
    this.state = { inputValue: '' }
  }
  componentDidMount() {
    this.props.setIsHighlighted(true)
    this.validate()
  }
  validate() {
    this.props.setIsValid(!!this.state.inputValue)
    this.props.setHelpText(!this.state.inputValue ? 'Help Text: Type some text to make the form valid' : 'Help Text: You can now press Finish!')
  }
  submit(cb) {
    console.log('doing submit logic')
    cb()
  }
  render() {
    const onInputChange = e => {
      this.setState({ inputValue: e.target.value }, this.validate.bind(this))
    }
    return <div style={{marginBottom: '4em'}}>
      <form>
        <h1>Modal Form</h1>
        <p><label>What is your name?<br/><input type="text" onChange={onInputChange} value={this.state.inputValue} /></label></p>
      </form>
    </div>
  }
}

<Btn Form={ModalForm} className="center-block" onClose={onClose}>Click to open</Btn>
```

Other properties:

 - On `<Single>`, you can set `nextLabel` and `cancelLabel` to control the button text at the bottom of the modal.
 - On `<Flow>`, you can set `labels` to an array of text labels to be put on the stepped progress-bar.
 - On single modals (or a `<Btn>` to one), you can set `formProps` to an object of properties to pass to the Form on render.
 - On flow modals (or a `<Btn>` to one), you can set `formsProps` to an object of properties to pass to the Forms on render.

## Styles

There are two classes that are included with the styles, "fullheight" and "center-block".

Use the .less file:

```less
@import "node_modules/patchkit-modal/styles.less"
```

---
_Source: https://npm.io/package/patchkit-modal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
