├── .babelrc ├── .eslintrc.js ├── .github ├── ISSUE_TEMPLATE │ ├── 1.Bug_report.md │ ├── 2.Feature_request.md │ └── 3.Storybook_Bug_report.md ├── lock.yml ├── no-response.yml └── stale.yml ├── .gitignore ├── .prettierrc.js ├── .storybook ├── addons.js ├── config.js ├── preview-head.html └── webpack.config.js ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── commitlint.config.js ├── package-lock.json ├── package.json ├── src ├── components │ ├── Fill │ │ └── index.tsx │ ├── Provider │ │ └── index.tsx │ └── Slot │ │ └── index.tsx └── index.tsx ├── stories └── index.stories.tsx └── tsconfig.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-typescript", "@babel/preset-react"], 3 | "plugins": [ 4 | "@babel/plugin-proposal-object-rest-spread", 5 | "@babel/plugin-proposal-class-properties" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | // ... 4 | 'react-hooks', 5 | ], 6 | extends: 'react-app', 7 | rules: { 8 | 'no-console': ['error', { allow: ['warn', 'error'] }], 9 | 'no-debugger': 'error', 10 | 'no-var': 'error', 11 | 'react-hooks/rules-of-hooks': 'error', 12 | 'react-hooks/exhaustive-deps': 'warn', 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/1.Bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a bug report for the React-Slot-Fill 4 | --- 5 | 6 | # Bug report 7 | 8 | ## Describe the bug 9 | 10 | A clear and concise description of what the bug is. 11 | 12 | ## To Reproduce 13 | 14 | Steps to reproduce the behavior, please provide code snippets or a repository: 15 | 16 | 1. Go to '...' 17 | 2. Click on '....' 18 | 3. Scroll down to '....' 19 | 4. See error 20 | 21 | ## Expected behavior 22 | 23 | A clear and concise description of what you expected to happen. 24 | 25 | ## Screenshots 26 | 27 | If applicable, add screenshots to help explain your problem. 28 | 29 | ## System information 30 | 31 | - OS: [e.g. macOS, Windows] 32 | - Browser (if applies) [e.g. chrome, safari] 33 | - Version of React-Slot-Fill: [e.g. 1.4.0] 34 | 35 | ## Additional context 36 | 37 | Add any other context about the problem here. 38 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/2.Feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Create a feature request for the React-Slot-Fill 4 | --- 5 | 6 | # Feature request 7 | 8 | ## Is your feature request related to a problem? Please describe. 9 | 10 | A clear and concise description of what you want and what your use case is. 11 | 12 | ## Describe the solution you'd like 13 | 14 | A clear and concise description of what you want to happen. 15 | 16 | ## Describe alternatives you've considered 17 | 18 | A clear and concise description of any alternative solutions or features you've considered. 19 | 20 | ## Additional context 21 | 22 | Add any other context or screenshots about the feature request here. 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/3.Storybook_Bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report for Storybook 3 | about: Create a bug report for Storybook in React-Slot-Fill 4 | --- 5 | 6 | # Examples bug report 7 | 8 | ## Example name 9 | 10 | Provide the example name 11 | 12 | ## Describe the bug 13 | 14 | A clear and concise description of what the bug is. 15 | 16 | ## To Reproduce 17 | 18 | Steps to reproduce the behavior, please provide code snippets or a repository: 19 | 20 | 1. Go to '...' 21 | 2. Click on '....' 22 | 23 | 3. Scroll down to '....' 24 | 4. See error 25 | 26 | ## Expected behavior 27 | 28 | A clear and concise description of what you expected to happen. 29 | 30 | ## Screenshots 31 | 32 | If applicable, add screenshots to help explain your problem. 33 | 34 | ## System information 35 | 36 | - OS: [e.g. macOS, Windows] 37 | - Browser (if applies) [e.g. chrome, safari] 38 | - Version of React-Slot-Fill: [e.g. 1.4.0] 39 | 40 | ## Additional context 41 | 42 | Add any other context about the problem here. 43 | -------------------------------------------------------------------------------- /.github/lock.yml: -------------------------------------------------------------------------------- 1 | # Configuration for lock-threads - https://github.com/dessant/lock-threads 2 | 3 | # Number of days of inactivity before a closed issue or pull request is locked 4 | daysUntilLock: 180 5 | # Comment to post before locking. Set to `false` to disable 6 | lockComment: > 7 | This issue has been automatically locked since there has not been 8 | any recent activity after it was closed. 9 | If you can still reproduce this issue then please open a new issue and fill out 10 | [the entire issue template](https://github.com/blackboxvision/react-slot-fill/blob/master/ISSUE_TEMPLATE.md) 11 | to ensure that we have enough information to address your issue. Thanks! 12 | # Issues or pull requests with these labels will not be locked 13 | exemptLabels: 14 | - help-wanted 15 | # Limit to only `issues` or `pulls` 16 | only: issues 17 | -------------------------------------------------------------------------------- /.github/no-response.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-no-response - https://github.com/probot/no-response 2 | 3 | # Number of days of inactivity before an issue is closed for lack of response 4 | daysUntilClose: 28 5 | 6 | # Label requiring a response 7 | responseRequiredLabel: more-information-needed 8 | 9 | # Comment to post when closing an issue for lack of response. Set to `false` to disable. 10 | closeComment: > 11 | This issue has been automatically closed because there has been no response 12 | to our request for more information from the original author. With only the 13 | information that is currently in the issue, we don't have enough information 14 | to take action. Please reach out if you have or find the answers we need so 15 | that we can investigate further. 16 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | # Number of days of inactivity before an Issue or Pull Request becomes stale 4 | daysUntilStale: 365 5 | # Number of days of inactivity before a stale Issue or Pull Request is closed 6 | daysUntilClose: 14 7 | # Issues or Pull Requests with these labels will never be considered stale 8 | exemptLabels: 9 | - regression 10 | - security 11 | - triaged 12 | # Label to use when marking as stale 13 | staleLabel: stale 14 | # Comment to post when marking as stale. Set to `false` to disable 15 | markComment: > 16 | Thanks for your contribution! 17 | 18 | This issue has been automatically marked as stale because it has not had 19 | recent activity. 20 | 21 | If you would like this issue to remain open: 22 | 23 | 1. Verify that you can still reproduce the issue in the latest version of react-slot-fill 24 | 1. Comment that the issue is still reproducible and include: 25 | * What version of react-slot-fill you reproduced the issue on 26 | * What OS and version you reproduced the issue on 27 | * What steps you followed to reproduce the issue 28 | 29 | Issues that are labeled as triaged will not be automatically marked as stale. 30 | # Comment to post when removing the stale label. Set to `false` to disable 31 | unmarkComment: false 32 | # Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable 33 | closeComment: false 34 | # Limit to only `issues` or `pulls` 35 | only: issues 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | pkg 2 | build 3 | coverage 4 | node_modules 5 | storybook-static -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | trailingComma: 'es5', 3 | singleQuote: true, 4 | }; 5 | -------------------------------------------------------------------------------- /.storybook/addons.js: -------------------------------------------------------------------------------- 1 | import '@storybook/addon-actions/register'; 2 | import '@storybook/addon-links/register'; 3 | -------------------------------------------------------------------------------- /.storybook/config.js: -------------------------------------------------------------------------------- 1 | import { withInfo } from '@storybook/addon-info'; 2 | import { addDecorator, addParameters, configure } from '@storybook/react'; 3 | import { themes } from '@storybook/theming'; 4 | 5 | addParameters({ 6 | options: { 7 | name: 'React Slot/Fill', 8 | theme: themes.light, 9 | showAddonPanel: false, 10 | addonPanelInRight: true, 11 | }, 12 | }); 13 | 14 | addDecorator(withInfo({ inline: true, header: false })); 15 | 16 | const req = require.context('../stories', true, /.stories.tsx$/); 17 | function loadStories() { 18 | req.keys().forEach(filename => req(filename)); 19 | } 20 | 21 | configure(loadStories, module); 22 | -------------------------------------------------------------------------------- /.storybook/preview-head.html: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /.storybook/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = async ({ config }) => { 2 | config.module.rules.push({ 3 | test: /\.(ts|tsx)$/, 4 | use: [ 5 | { 6 | loader: require.resolve('awesome-typescript-loader'), 7 | }, 8 | { 9 | loader: require.resolve('react-docgen-typescript-loader'), 10 | }, 11 | ], 12 | }); 13 | 14 | config.resolve.extensions.push('.ts', '.tsx'); 15 | 16 | return config; 17 | }; 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | All notable changes to this project will be documented in this file. 4 | This project adheres to [Semantic Versioning](http://semver.org/). -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to React-Slot-Fill 2 | 3 | 1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device. 4 | 1. Install the dependencies: `npm i`. 5 | 1. Run `npm run storybook` to run the stories behing `/stories` folder. 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 BlackBox Vision 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Slot and Fill [](https://badge.fury.io/js/%40blackbox-vision%2Freact-slot-fill) [](https://opensource.org/licenses/MIT) [](https://snyk.io/test/github/blackboxvision/react-slot-fill) 2 | 3 | :rocket: React Slot and Fill pattern implementation made with React.createContext API. Check out the [demo](https://blackboxvision.github.io/react-slot-fill/). 4 | 5 | ## Install 6 | 7 | You can install this library via NPM or YARN. 8 | 9 | ### NPM 10 | 11 | ```bash 12 | npm i @blackbox-vision/react-slot-fill 13 | ``` 14 | 15 | ### YARN 16 | 17 | ```bash 18 | yarn add @blackbox-vision/react-slot-fill 19 | ``` 20 | 21 | ## Use case 22 | 23 | If you need to render a component from somepart of the DOM tree, but it needs to be visible in another part of the tree, this library solves it. 24 | 25 | This library is very similar to [`react-slot-fill`](https://github.com/camwest/react-slot-fill), but we solve two particular issues: 26 | 27 | - Support for `React.createContext`, this library is intended to use with React >= 16.3.1. 28 | - If a `Fill` is declared after a `Slot`, it can render properly, which [`react-slot-fill`](https://github.com/camwest/react-slot-fill) doesn't support. 29 | 30 | ## Usage 31 | 32 | The usage is really simple: 33 | 34 | ```javascript 35 | // Toolbar.js 36 | import React from 'react'; 37 | import { Slot, Fill } from '@blackbox-vision/react-slot-fill'; 38 | 39 | const Toolbar = (props) => ( 40 |