Skip to content

Commit

Permalink
Rename slot name, and slot component's name and component
Browse files Browse the repository at this point in the history
  • Loading branch information
stevepiercy committed Feb 28, 2024
1 parent 18333ee commit 40c1dfd
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions docs/source/configuration/slots.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Volto renders slots using the `SlotRenderer` component.
You can add slot insertion points in your code, as shown in the following example.

```ts
<SlotRenderer name="toolbar" content={content} />
<SlotRenderer name="aboveContent" content={content} />
```

Slot components consist of a data structure with key/value pairs, where the keys are the parent's slot name, the slot component's name, the component to render in the slot, and optional predicates.
Expand All @@ -34,82 +34,82 @@ The renderer of a slot component is controlled by the presence or absence of a l

You can register multiple slot components with the same name under the same slot, as long as they have different predicates or components.

To illustrate how slots are structured and work, let's register a slot component, where the component is `@sneridagh what goes here?`, and the predicate matches a route that begins with `/de/about`.
To illustrate how slots are structured and work, let's register a slot component, where the component is `PageHeader`, and the predicate matches a route that begins with `/de/about`.

```ts
config.registerSlotComponent({
slot: 'toolbar',
name: 'save',
component: '@sneridagh what goes here?',
slot: 'aboveContent',
name: 'header',
component: PageHeader,
predicates: [RouteCondition('/de/about')],
});
```

The following tree structure diagram illustrates the resultant registration.

```text
Slot (`name`=`toolbar`)
Slot (`name`=`aboveContent`)
└── SlotComponent
├── `slot`=`toolbar`
├── `name`=`save`
├── `component`=`@sneridagh what goes here?`
├── `slot`=`aboveContent`
├── `name`=`header`
├── `component`=PageHeader
└── predicate of "only appear under `/de/about`"
```

Next, let's register another slot component in the same slot, with the same name and component, but with a different predicate where the content type matches either `Document` or `News Item`.

```ts
config.registerSlotComponent({
slot: 'toolbar',
name: 'save',
component: '@sneridagh what goes here?',
slot: 'aboveContent',
name: 'header',
component: PageHeader,
predicates: [ContentTypeCondition(['Document', 'News Item'])],
});
```

The following tree structure diagram illustrates the result of the second registration.

```text
Slot (`name`=`toolbar`)
Slot (`name`=`aboveContent`)
├── SlotComponent
│ ├── `slot`=`toolbar`
│ ├── `name`=`save`
│ ├── `component`=`@sneridagh what goes here?`
│ ├── `slot`=`aboveContent`
│ ├── `name`=`header`
│ ├── `component`=PageHeader
│ └── predicate of "only appear under `/de/about`"
└── SlotComponent
├── `slot`=`toolbar`
├── `name`=`save`
├── `component`=`@sneridagh what goes here?`
├── `slot`=`aboveContent`
├── `name`=`header`
├── `component`=PageHeader
└── predicate of "only appear when the content type is either a Document or News Item"
```

Finally, let's register another slot component in the same slot, with the same name, but with a different component and without a predicate.

```ts
config.registerSlotComponent({
slot: 'toolbar',
name: 'save',
slot: 'aboveContent',
name: 'header',
component: '@sneridagh what goes here as a different component?',
});
```

The following tree structure diagram illustrates the result of the third registration.

```text
Slot (`name`=`toolbar`)
Slot (`name`=`aboveContent`)
├── SlotComponent
│ ├── `slot`=`toolbar`
│ ├── `name`=`save`
│ ├── `component`=`@sneridagh what goes here?`
│ ├── `slot`=`aboveContent`
│ ├── `name`=`header`
│ ├── `component`=PageHeader
│ └── predicate of "only appear under `/de/about`"
├── SlotComponent
│ ├── `slot`=`toolbar`
│ ├── `name`=`save`
│ ├── `component`=`@sneridagh what goes here?`
│ ├── `slot`=`aboveContent`
│ ├── `name`=`header`
│ ├── `component`=PageHeader
│ └── predicate of "only appear when the content type is either a Document or News Item"
└── SlotComponent
├── `slot`=`toolbar`
├── `name`=`save`
├── `slot`=`aboveContent`
├── `name`=`header`
└── `component`=`@sneridagh what goes here as a different component?`
```

Expand All @@ -118,8 +118,8 @@ Else, if there are slot components with the same name, but with a different comp

Thus the example slot renderer will have the following behavior.

- When both a user visits the route beginning with `/de/about`, and the content type is either a Document or News Item, then the component `@sneridagh what goes here?` will render in the `toolbar` slot.
- When one or both of the predicates are false, then the component `@sneridagh what goes here as a different component?` will render in the `toolbar` slot.
- When both a user visits the route beginning with `/de/about`, and the content type is either a Document or News Item, then the component `PageHeader` will render in the `aboveContent` slot.
- When one or both of the predicates are false, then the component `@sneridagh what goes here as a different component?` will render in the `aboveContent` slot.

```{tip}
In our example, if we had not registered the third slot component—the one without predicates—and when either of the first two slot components' predicates return `false`, then no component would render.
Expand Down Expand Up @@ -154,8 +154,8 @@ You register a slot component using the configuration registry, as shown.

```ts
config.registerSlotComponent({
slot: 'toolbar',
name: 'save',
slot: 'aboveContent',
name: 'header',
component: '@sneridagh this needs a component',
predicates: [
RouteCondition('/de/about'),
Expand Down

0 comments on commit 40c1dfd

Please sign in to comment.