Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md on SlotFills to add info + example about the prop fillProps #51013

Merged
merged 3 commits into from
Jun 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion packages/components/src/slot-fill/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Both `Slot` and `Fill` accept a `name` string prop, where a `Slot` with a given

`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.
`Slot` accepts optional `children` function prop, which takes `fills` as a param. It allows to perform additional processing and wrap `fills` conditionally.
rmorse marked this conversation as resolved.
Show resolved Hide resolved

_Example_:

Expand All @@ -89,3 +89,27 @@ const Toolbar = ( { isMobile } ) => (
</div>
);
```

Props can also be passed from a `Slot` to a `Fill` by using the prop `fillProps` on the `Slot`:
```jsx
rmorse marked this conversation as resolved.
Show resolved Hide resolved
const { Fill, Slot } = createSlotFill( 'Toolbar' );

const ToolbarItem = () => (
<Fill>
{ ( { hideToolbar } ) => {
<Button onClick={ hideToolbar }>Hide</Button>;
} }
</Fill>
);

const Toolbar = () =>
const hideToolbar() => {
console.log( 'Hide toolbar' );
}
return (
<div className="toolbar">
<Slot fillProps={ { hideToolbar } } />
</div>
);
);
```