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

[DashboardLayout] Add homeUrl to branding and appTitle slot #4477

Merged
merged 13 commits into from
Dec 8, 2024

Conversation

bharatkashyap
Copy link
Member

@bharatkashyap bharatkashyap commented Nov 26, 2024

https://deploy-preview-4477--mui-toolpad-docs.netlify.app/toolpad/core

@bharatkashyap bharatkashyap added new feature New feature or request component: layout This is the name of the generic UI component, not the React module! labels Nov 26, 2024
@Janpot
Copy link
Member

Janpot commented Nov 26, 2024

Passes the merged branding object as a prop to the branding slot component

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.

@apedroferreira
Copy link
Member

I think calling the slot branding is what can be confusing? We should give it a different name, as it shouldn't be directly related with the branding context and properties.

@bharatkashyap
Copy link
Member Author

I think calling the slot branding is what can be confusing? We should give it a different name, as it shouldn't be directly related with the branding context and properties.

Fair enough, does renaming it to appTitle as a slot make sense?

@apedroferreira
Copy link
Member

I think calling the slot branding is what can be confusing? We should give it a different name, as it shouldn't be directly related with the branding context and properties.

Fair enough, does renaming it to appTitle as a slot make sense?

I think that's fine, or headerTitle, maybe even headerBranding...

@bharatkashyap
Copy link
Member Author

bharatkashyap commented Nov 28, 2024

I think calling the slot branding is what can be confusing? We should give it a different name, as it shouldn't be directly related with the branding context and properties.

Fair enough, does renaming it to appTitle as a slot make sense?

I think that's fine, or headerTitle, maybe even headerBranding...

Now that we have the PageHeader component which refers to the section below the app bar, I feel using header in the slot name will still be confusing; How about appBarBranding?

Update: Discussed with @mnajdova that an appTitle slot makes the most sense for now, but we should quickly make progress on separating the DashboardLayout into constituent AppBar and Sidebar components which can then take these nested slots. Updated the description here to reflect that: #4071

@bharatkashyap bharatkashyap changed the title [DashboardLayout] Add homeUrl and branding slot [DashboardLayout] Add homeUrl and appTitle slot Dec 3, 2024
@bharatkashyap bharatkashyap changed the title [DashboardLayout] Add homeUrl and appTitle slot [DashboardLayout] Add homeUrl to branding and appTitle slot Dec 3, 2024
Copy link
Member

@apedroferreira apedroferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Screenshot 2024-12-05 at 18 04 22

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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this!

@@ -149,6 +153,8 @@ Some possibly useful slots:

- `sidebarFooter`: allows you to add footer content in the sidebar.

- `branding`: allows you to pass in your own component in the branding section.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' }}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why color: red? :D Was it there before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, good catch! Missed removing this after using it to test :)

</Typography>
</Stack>
</Link>
{slots?.appTitle ? <slots.appTitle /> : <AppTitleComponent {...appTitleProps} />}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@apedroferreira apedroferreira Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -73,6 +73,7 @@ function DashboardLayoutBranding(props) {
branding={{
logo: <img src="https://mui.com/static/logo.png" alt="MUI logo" />,
title: 'MUI',
homeUrl: 'https://mui.com/toolpad/core/introduction',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll switch to the relative URL since the navigation doesn't actually work in the iframe demo

@ashishjaswal2002
Copy link

So homeUrl is finally available?

@bharatkashyap
Copy link
Member Author

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.

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

</Typography>
</Stack>
</Link>
{slots?.appTitle ? <slots.appTitle /> : <AppTitleComponent {...appTitleProps} />}
Copy link
Member

@apedroferreira apedroferreira Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -359,7 +360,11 @@ function DashboardLayout(props: DashboardLayoutProps) {
</Box>
</React.Fragment>
) : null}
{slots?.appTitle ? <slots.appTitle /> : <AppTitleComponent {...appTitleProps} />}
{slots?.appTitle ? (
<slots.appTitle {...slotProps?.appTitle} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cool if the custom component also gets branding, but if that causes typing issues we can stay like this for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this originally but removed it after #4477 (comment)

Copy link
Member

@apedroferreira apedroferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 <10789765+apedroferreira@users.noreply.github.com>
Signed-off-by: Bharat Kashyap <bharatkashyap@outlook.com>
Copy link

@ashishjaswal2002 ashishjaswal2002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is homeUrl released or not?

@bharatkashyap bharatkashyap merged commit 655fea0 into mui:master Dec 8, 2024
14 checks passed
@ashishjaswal2002
Copy link

?

@bharatkashyap
Copy link
Member Author

?

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

apedroferreira added a commit that referenced this pull request Dec 9, 2024
)

Signed-off-by: Bharat Kashyap <bharatkashyap@outlook.com>
Co-authored-by: Pedro Ferreira <10789765+apedroferreira@users.noreply.github.com>
@ashishjaswal2002
Copy link

@bharatkashyap how to use the latest version in the latest project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: layout This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
4 participants