npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@humanmade/react-slot-fill

v0.0.4

Published

This package is the [SlotFill component](https://developer.wordpress.org/block-editor/components/slot-fill/) from the [WordPress Gutenberg project](https://github.com/WordPress/gutenberg), broken out for standalone usage.

Downloads

6

Readme

@humanmade/react-slot-fill

This package is the SlotFill component from the WordPress Gutenberg project, broken out for standalone usage.

Licensed under the GPL. Copyright 2011-2020 by the contributors.

The original package's readme follows.


Slot Fill

Slot and Fill are a pair of components which enable developers to render elsewhere in a React element tree, a pattern often referred to as "portal" rendering. It is a pattern for component extensibility, where a single Slot may be occupied by an indeterminate number of Fills elsewhere in the application.

Slot Fill is heavily inspired by the react-slot-fill library, but uses React's own portal rendering API, exposed as an unstable API in React 16 and slated to be promoted to a stable API in React 17.

Usage

At the root of your application, you must render a SlotFillProvider which coordinates Slot and Fill rendering.

Then, render a Slot component anywhere in your application, giving it a name.

Any Fill will automatically occupy this Slot space, even if rendered elsewhere in the application.

You can either use the Fill component directly, or a wrapper component type as in the below example to abstract the slot name from consumer awareness.

import { SlotFillProvider, Slot, Fill, Panel, PanelBody } from '@wordpress/components';

const MySlotFillProvider = () => {
	const MyPanelSlot = () => (
		<Panel header="Panel with slot">
			<PanelBody>
				<Slot name="MyPanelSlot"/>
			</PanelBody>
		</Panel>
	);

	MyPanelSlot.Content = () => (
		<Fill name="MyPanelSlot">
			Panel body
		</Fill>
	);

	return (
		<SlotFillProvider>
			<MyPanelSlot />
			<MyPanelSlot.Content />
		</SlotFillProvider>
	);
};

There is also createSlotFill helper method which was created to simplify the process of matching the corresponding Slot and Fill components:

const { Fill, Slot } = createSlotFill( 'Toolbar' );

const ToolbarItem = () => (
	<Fill>
		My item
	</Fill>
);

const Toolbar = () => (
	<div className="toolbar">
		<Slot />
	</div>
); 

Props

The SlotFillProvider component does not accept any props.

Both Slot and Fill accept a name string prop, where a Slot with a given name will render the children of any associated Fills.

Slot accepts a bubblesVirtually prop which changes the event bubbling behaviour:

  • By default, events will bubble to their parents on the DOM hierarchy (native event bubbling)
  • If bubblesVirtually is set to true, events will bubble to their virtual parent in the React elements hierarchy instead.

Slot with bubblesVirtually set to true also accept an optional className to add to the slot container.

Slot also accepts optional children function prop, which takes fills as a param. It allows to perform additional processing and wrap fills conditionally.

Example:

const Toolbar = ( { isMobile } ) => (
	<div className="toolbar">
		<Slot name="Toolbar">
			{ ( fills ) => {
				return isMobile && fills.length > 3 ?
					<div className="toolbar__mobile-long">{ fills }</div> :
					fills;
			} }	
		</Slot>
	</div>
);