[DashboardLayout] Add homeUrl to branding and appTitle slot#4477
[DashboardLayout] Add homeUrl to branding and appTitle slot#4477bharatkashyap merged 13 commits intomui:masterfrom
homeUrl to branding and appTitle slot#4477Conversation
This one feels out of spirit for slot components to me. I don't think we should stretch the definition of slots beyond React components. |
|
I think calling the slot |
Fair enough, does renaming it to |
I think that's fine, or |
Now that we have the Update: Discussed with @mnajdova that an |
homeUrl and branding slothomeUrl and appTitle slot
homeUrl and appTitle slothomeUrl to branding and appTitle slot
There was a problem hiding this comment.
Mostly looks good, thanks for adding these!
But noticed a few improvements that would probably make sense.
Also I was a bit surprised by this logo at first, something about it seemed weird, but maybe I'm just used to the old one...
Would it maybe look better if the title was blue and bold? Not sure about it though, feel free to keep it if there's nothing obvious to do.
| {{"demo": "DashboardLayoutBranding.js", "height": 400, "iframe": true}} | ||
|
|
||
| :::info | ||
| You may also override the default branding components by passing in your own component to the `branding` slot, as described in the [Slots section](#slots). |
There was a problem hiding this comment.
| You may also override the default branding components by passing in your own component to the `branding` slot, as described in the [Slots section](#slots). | |
| You may also override the default branding components by passing in your own component to the `appTitle` slot, as shown in the [Slots section](#slots). |
It's called appTitle after all, right?
|
|
||
| - `sidebarFooter`: allows you to add footer content in the sidebar. | ||
|
|
||
| - `branding`: allows you to pass in your own component in the branding section. |
There was a problem hiding this comment.
| - `branding`: allows you to pass in your own component in the branding section. | |
| - `appTitle`: allows you to customize the branding in the layout header. |
Rename to appTitle and suggested an alternative for the description but doesn't need to be exactly like I suggested.
Also I'd list this slot first as visually it's present before the others in the layout.
There was a problem hiding this comment.
Maybe call it "app title" instead of "branding" in my first suggestion to match the description here more https://github.com/mui/toolpad/pull/4477/files#diff-87af69cfab4c32bae2f8f22cd3d491883936a394263a91aea7824875db51e2a7
| const defaultTitle = useApplicationTitle(); | ||
| const title = props?.title ?? defaultTitle; | ||
| return ( | ||
| <Link href={props?.homeUrl ?? '/'} style={{ color: 'red', textDecoration: 'none' }}> |
There was a problem hiding this comment.
Why color: red? :D Was it there before?
There was a problem hiding this comment.
Nope, good catch! Missed removing this after using it to test :)
| </Typography> | ||
| </Stack> | ||
| </Link> | ||
| {slots?.appTitle ? <slots.appTitle /> : <AppTitleComponent {...appTitleProps} />} |
There was a problem hiding this comment.
Should people be able to pass in slotProps of the type Branding to the custom slot if they set it? Then it would match the props of AppTitleComponent, right?
Also I'd just have a single branding prop for these slot components instead of all the props inside Branding, then maybe we could add other stuff later.
There was a problem hiding this comment.
Should people be able to pass in
slotPropsof the typeBrandingto the custom slot if they set it? Then it would match the props ofAppTitleComponent, right?
Agreed, missed this
Also I'd just have a single branding prop for these slot components instead of all the props inside Branding, then maybe we could add other stuff later.
Makes sense, so merge all the Branding properties inside a single branding prop for the AppTitle
For the slot type definition, if I used
appTitle?: React.JSXElementConstructor<AppTitleProps>;that would cause type errors if someone wanted to create a custom element with their own props for this component, right? Would it be better to use React.ElementType instead here?
There was a problem hiding this comment.
that would cause type errors if someone wanted to create a custom element with their own props for this component, right? Would it be better to use React.ElementType instead here?
Could we make it so that the custom component automatically has these default props but can be expanded with whatever other properties people want to add?
But if not and that causes errors, we haven't really decided on a pattern for the slots yet so if using React.ElementType fixes that we can go with that pattern.
In this particular case you don't even need to pass branding as a prop to the slot if that ends up solving this problem, those branding values can just be read from the context if that's the best solution.
There was a problem hiding this comment.
I guess going with React.ElementType like you did should work if it shows no errors. But it would be nice if it could be typed somehow.
| branding={{ | ||
| logo: <img src="https://mui.com/static/logo.png" alt="MUI logo" />, | ||
| title: 'MUI', | ||
| homeUrl: 'https://mui.com/toolpad/core/introduction', |
There was a problem hiding this comment.
If you click this in the demo it just changes the page content to "Dashboard content for /toolpad/core/introduction".
So not sure if we should use a relative link?
Anyway this comment is just a thought - not sure what the best option would be...
There was a problem hiding this comment.
Yes, I'll switch to the relative URL since the navigation doesn't actually work in the iframe demo
|
So homeUrl is finally available? |
You're right, in hindsight this demo wasn't really demonstrative at all, I've changed it to better reflect the utility of the slot |
…lpad into core/branding-slot
docs/data/toolpad/core/components/dashboard-layout/dashboard-layout.md
Outdated
Show resolved
Hide resolved
| </Typography> | ||
| </Stack> | ||
| </Link> | ||
| {slots?.appTitle ? <slots.appTitle /> : <AppTitleComponent {...appTitleProps} />} |
There was a problem hiding this comment.
I guess going with React.ElementType like you did should work if it shows no errors. But it would be nice if it could be typed somehow.
| ) : null} | ||
| {slots?.appTitle ? <slots.appTitle /> : <AppTitleComponent {...appTitleProps} />} | ||
| {slots?.appTitle ? ( | ||
| <slots.appTitle {...slotProps?.appTitle} /> |
There was a problem hiding this comment.
Would be cool if the custom component also gets branding, but if that causes typing issues we can stay like this for now.
There was a problem hiding this comment.
I added this originally but removed it after #4477 (comment)
apedroferreira
left a comment
There was a problem hiding this comment.
Looks good, thanks for the changes!
Also the new slots title uses the same icon as the dashboard navigation item, maybe we could use a different one? Not too important.
Co-authored-by: Pedro Ferreira <[email protected]> Signed-off-by: Bharat Kashyap <[email protected]>
ashishjaswal2002
left a comment
There was a problem hiding this comment.
Is homeUrl released or not?
|
? |
Hi @ashishjaswal2002, the next release (v0.11.0) will have this feature. You can track when it comes out here: https://github.com/mui/toolpad/releases - it'll be sometime today or in the next few days |
) Signed-off-by: Bharat Kashyap <[email protected]> Co-authored-by: Pedro Ferreira <[email protected]>
|
@bharatkashyap how to use the latest version in the latest project |
homeUrlattribute to thebrandingobjectbrandingslot toDashboardLayoutto customize the branding section entirelybrandingoverride inDashboardLayoutto override individual properties of thebrandingprop passed inAppProvider, instead of replacing the entire objectbrandingobject as a prop to thebrandingslot componenthttps://deploy-preview-4477--mui-toolpad-docs.netlify.app/toolpad/core