preact-portal

WebJar for preact-portal

Лицензия

Лицензия

MIT
Категории

Категории

React Взаимодействие с пользователем Веб-фреймворки
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

preact-portal
Последняя версия

Последняя версия

1.1.3
Дата

Дата

Тип

Тип

jar
Описание

Описание

preact-portal
WebJar for preact-portal
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/developit/preact-portal

Скачать preact-portal

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/preact-portal/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>preact-portal</artifactId>
    <version>1.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/preact-portal/
implementation 'org.webjars.npm:preact-portal:1.1.3'
// https://jarcasting.com/artifacts/org.webjars.npm/preact-portal/
implementation ("org.webjars.npm:preact-portal:1.1.3")
'org.webjars.npm:preact-portal:jar:1.1.3'
<dependency org="org.webjars.npm" name="preact-portal" rev="1.1.3">
  <artifact name="preact-portal" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='preact-portal', version='1.1.3')
)
libraryDependencies += "org.webjars.npm" % "preact-portal" % "1.1.3"
[org.webjars.npm/preact-portal "1.1.3"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

🌌 preact-portal 🌠

NPM travis-ci

Render Preact components into SPACE*

* a space in the DOM. Sorry.

Use this if you have a component that needs to render children into some other place in the DOM.

An example of this would be modal dialogs, where you may need to render <Dialog /> into <body>.

Demo #1 Demo #2
Moving around the DOM by changing into. Open a full-page modal from within a thumbnail.

Installation

Via npm:

npm install --save preact-portal

Usage

import { h, Component, render } from 'preact';
import Portal from 'preact-portal';

class Thumbnail extends Component {
  open = () => this.setState({ open:true });
  close = () => this.setState({ open:false });

  render({ url }, { open }) {
    return (
      <div class="thumb" onClick={this.open}>
        <img src={url} />

        { open ? (
          <Portal into="body">
            <div class="popup" onClick={this.close}>
              <img src={url} />
            </div>
          </Portal>
        ) : null }
      </div>
    );
  }
}

render(<Thumbnail url="//i.imgur.com/6Rp4hbs.gif" />, document.body);

Or, wrap up a very common case into a simple high order function:

const Popup = ({ open, into="body", children }) => (
  open ? <Portal into={into}>{ children }</Portal> : null
);

// Example: show popup on error.
class Form extends Component {
  render({}, { error }) {
    return (
      <form>
        <Popup open={error}>
          <p>Error: {error}</p>
        </Popup>
        ...etc
      </form>
    );
  }
}

Версии библиотеки

Версия
1.1.3