├── .editorconfig ├── .gitignore ├── .travis.yml ├── README.md ├── package.json ├── src ├── index.js ├── slot-content.js ├── slot-provider.js ├── slot.js └── with-slot.js └── test ├── index.test.js ├── slot-content.test.js ├── slot-provider.test.js ├── slot.test.js └── with-slot.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,.*rc,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | *.log 4 | dist 5 | package-lock.json 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - stable 4 | dist: trusty 5 | sudo: false 6 | addons: 7 | chrome: stable 8 | cache: 9 | npm: true 10 | directories: 11 | - node_modules 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 | # preact-slots [![npm](https://img.shields.io/npm/v/preact-slots.svg?style=flat)](https://www.npmjs.org/package/preact-slots) [![travis](https://travis-ci.org/developit/preact-slots.svg?branch=master)](https://travis-ci.org/developit/preact-slots) 6 | 7 | Render Preact trees into other Preact trees, like portals. 8 | 9 | 10 | ## Install 11 | 12 | **preact-slots** is available on npm: 13 | 14 | `npm install --save preact-slots` 15 | 16 | 17 | ### Usage 18 | 19 | Define "holes" in your appliation using ``, 20 | then fill them using `some content`: 21 | 22 | ```js 23 | import { SlotProvider, Slot, SlotContent } from 'preact-slots' 24 | 25 | render( 26 | 27 |
28 | 29 | Some Fallback Content 30 | 31 | 32 | Replacement Content 33 | 34 |
35 |
36 | ) 37 | ``` 38 | 39 | The above renders `
Replacement Content
`. 40 | 41 | An extended example follows: 42 | 43 | ```js 44 | import { Slot, SlotContent, SlotProvider } from 'preact-slots' 45 | 46 | const Header = () => ( 47 |
48 | Slots Demo 49 | 50 | { items => items && } 51 | 52 |
53 | ) 54 | 55 | const EditPage = ({ page, content, onSave, onCancel }) => ( 56 |
57 | Editing {page} 58 | 59 | 60 | 61 | 62 |