-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function-based slot support to
Astro.slots.render()
(#2954)
* feat(slots): add function-based slot support to Astro.slots.render() * test(slots): add render tests
- Loading branch information
1 parent
50af480
commit d81b6d9
Showing
8 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Improve `Astro.slots` API to support passing arguments to function-based slots. | ||
|
||
This allows for more ergonomic utility components that accept a callback function as a child. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/astro-slots/src/components/Render.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
const { id } = Astro.props; | ||
const content = await Astro.slots.render('default'); | ||
--- | ||
|
||
<div id={id} set:html={content} /> |
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/astro-slots/src/components/RenderArgs.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
const { id, text } = Astro.props; | ||
const content = await Astro.slots.render('default', [text]); | ||
--- | ||
|
||
<div id={id} set:html={content} /> |
6 changes: 6 additions & 0 deletions
6
packages/astro/test/fixtures/astro-slots/src/components/RenderFn.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
const { id } = Astro.props; | ||
const content = await Astro.slots.render('default'); | ||
--- | ||
|
||
<div id={id} set:html={content} /> |
20 changes: 20 additions & 0 deletions
20
packages/astro/test/fixtures/astro-slots/src/pages/slottedapi-render.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
import Render from '../components/Render.astro'; | ||
import RenderFn from '../components/RenderFn.astro'; | ||
import RenderArgs from '../components/RenderArgs.astro'; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<!-- | ||
Test Astro.slots.render behavior. | ||
- `Render` is basic imperative `render` call | ||
- `RenderFn` is `render` that calls child function with arguments | ||
--> | ||
</head> | ||
<body> | ||
<Render id="render">render</Render> | ||
<RenderFn id="render-fn">{() => "render-fn"}</RenderFn> | ||
<RenderArgs id="render-args" text="render-args">{(text: string) => text}</RenderArgs> | ||
</body> | ||
</html> |