v9: Custom Components with Slots & Composition API Part 1 (AppBarTitle) #26890
Replies: 3 comments 4 replies
-
Where did you learn this Slot API? |
Beta Was this translation helpful? Give feedback.
-
That AppBar component looks cool. It could be useful for a lot of sites, are you allowed to share the full code? |
Beta Was this translation helpful? Give feedback.
-
Hey there @blendsdk. About the slot API you're presenting here: // file: AppBarTitle.types.ts
export type AppBarTitleSlots = {
root: NonNullable<Slot<"div"> | Slot<"a">>; // THIS WORKED!
root: NonNullable<Slot<"div", "a">>; // THIS DID NOT WORK!
....
}; The type The type If you are using |
Beta Was this translation helpful? Give feedback.
-
What is this about?
I am using the new v9 API to create (migrate) my v8 components to v9. Here are some code snippets and ideas that might help if you are in the same boat as I am. Please note that you do not have to use this style of component authoring. To keep a certain standard, I just want my components to be created the same way as FUI component did.
Take a look at this link for component templates.
At the time of writing this post, the
Slots
and the composition API in v9 is not marked as stable by the FUI team. After several experiments and spending some time studying thereact-components
package, I find this approach to be very flexible and fine to work with.The component
The
AppBarTitle
is a simple component that either shows a text or a link given the existance of thehref
property.Describing the Slot
The Slot is either a
DIV
or anAnchor
element.Conditional tag in State
Rendering
Nothing special here! Most of the work is done in the
hook
above.Styling
Here we make the
Anchor
element look like a text.Usage
Beta Was this translation helpful? Give feedback.
All reactions