-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[experimentalStyled] Add name and slot options #23964
Conversation
@material-ui/core: parsed: +0.06% , gzip: +0.10% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an improvement for the DX of customizations :). I wonder if we can't abstract the API, like:
- name: string
Slider
- slot: string
Rail
to avoid naming mistakes & enforce more consistency. For instance, if slot is Root
, apply muiName automatically.
Definitely looks better, implemented with 3845a64 |
@@ -56,7 +56,7 @@ const overridesResolver = (props, styles) => { | |||
const BadgeRoot = styled( | |||
'span', | |||
{}, | |||
{ muiName: 'MuiBadge', overridesResolver }, | |||
{ name: 'Badge', slot: 'Root', overridesResolver }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been meaning to ask – is "slot" a recognised term? I hadn't come across it before your use, and a quick web search doesn't bring up anything relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s not something standardized, I’ve just got used to use it for describing different parts of the component. In Vue, slots are used as templates part for creating a layout https://vuejs.org/v2/guide/components-slots.html Here is an example:
<div class="container">
<header>
<!-- We want header content here -->
<slot name="header"></slot>
</header>
<main>
<!-- We want main content here -->
<slot name="body"></slot>
</main>
<footer>
<!-- We want footer content here -->
<slot name="footer"></slot>
</footer>
</div>
I don’t think react has a similar notion for it, but I think we can just use the same term. Open for other options around naming here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was influenced by the usage of the slot terminology by Vue and Web Components when making the initial proposal. The first idea that came to mind was component but it seemed to be overloaded. Hence slot as the second option.
Any other idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
part
is the other term I had in mind too, but slot
sound better to me 🤷♀️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
svelte has slots as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm struggling to see how "slot" as used here relates to slots in Vue and Svelte, where it appears to be a placeholder for children equivalent to {props.children}
in React. A slot is something that you put things into. That doesn't seem to be the case here, unless I'm misunderstanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbrookes each components
' prop key is a slot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks.
This PR aims to resolve #23745 (comment) by providing
name
andslot
as options in theexperimentalStyled
utility.Here is the output of both the generated HTML and the React tree.
HTML
Previously:
![classes old](https://user-images.githubusercontent.com/4512430/101926557-9e9a9080-3bd3-11eb-92a7-bf3ca175c8f6.png)
Now:
![Classes new](https://user-images.githubusercontent.com/4512430/101926580-a5c19e80-3bd3-11eb-9087-9765c2f13037.png)
React tree
Previously:
![component names old dev](https://user-images.githubusercontent.com/4512430/101926918-21235000-3bd4-11eb-9e11-397d4fded09a.png)
Now:
![components new name](https://user-images.githubusercontent.com/4512430/101926622-b70aab00-3bd3-11eb-8afd-28e108e1339c.png)