Skip to content

Commit

Permalink
Documentations: Add createSlotFill to the Slot & Fill Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 4, 2018
1 parent c77d161 commit 39c4715
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion components/slot-fill/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,48 @@ Any Fill will automatically occupy this Slot space, even if rendered elsewhere i

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

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

```jsx
const Toolbar = createSlotFill( 'Toolbar' );

const MyToolbarItem = () => (
<Toolbar>
My item
</Toolbar>
);

const MyToolbar = () => (
<div className="toolbar">
<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 `Fill`s.

`Slot` also accepts a `bubblesVirtually` prop which changes the event bubbling behaviour:
`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` also accepts optional `children` function prop, which takes `fills` as a param. It allows to perform additional processing and wrap `fills` conditionally.

_Example_:
```jsx
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>
);
```

0 comments on commit 39c4715

Please sign in to comment.