Slot & Fill component for merging React subtrees together.
simple demo on glitch (view source)
Check out theInstallation
npm install react-slot-fill --save
Check out the examples locally
git clone https://github.com/camwest/react-slot-fill
cd react-slot-fill
npm start
Usage
Note These examples use React Fiber Alpha
Toolbar.js
import Slot Fill from 'react-slot-fill'; const Toolbar = props <div> <Slot ="Toolbar.Item" /> </div> ; Toolbar <Fill ="Toolbar.Item"> <button> propslabel </button> </Fill>
Feature.js
import Toolbar from './Toolbar'; const Feature = <Toolbar.Item ="My Feature!" /> ;
App.js
import Toolbar from './Toolbar';import Feature from './Feature'; import Provider from 'react-slot-fill'; const App = <Provider> <Toolbar /> <Feature /> </Provider> ReactDOMFiber;
Components
Creates a Slot/Fill context. All Slot/Fill components must be descendants of Provider. You may only pass a single descendant to Provider
.
getFillsByName
and getChildrenByName
are really useful for testing Fill components.
See src/lib/__tests/Provider.test.tsx for an example.
Expose a global extension point
;
Props
Render children into a Slot
;
Props
You can add additional props to the Fill which can be accessed in the parent node of the slot via fillChildProps.