-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: implement getComponentSlotClassName utility for dynamic class name generation #35548
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
feat: implement getComponentSlotClassName utility for dynamic class name generation #35548
Conversation
📊 Bundle size report✅ No changes found |
|
Pull request demo site: URL |
packages/react-components/react-utilities/src/utils/getComponentSlotClassName.test.ts
Show resolved
Hide resolved
packages/react-components/react-utilities/src/utils/getComponentSlotClassName.test.ts
Outdated
Show resolved
Hide resolved
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.
Considering that the RFC (#35464) was not merged, please don't put any related utils into stable packages.
That's true, and the RFC hasn't been merged yet. However, since it isn't impacting anyone and there's no alternative way to validate the approach and gather real data from partner codebases, I believe we can proceed with checking this in. I can add a note indicating the utils is not meant for public use, or rename it to be |
|
@dmytrokirpa is there a reason why these utils cannot be shipped in a preview package? |
For the headless style hooks, they really need to stay in the component packages - otherwise, the bundler's @layershifter If you have any ideas or suggestions on how we can improve this, I’m all ears. |
ed8a5dc to
da12530
Compare
|
Merged this PR to the headless-components branch instead of master to not block progress, and once the RFC is approved/merged we'll merge it back to master. |
Previous Behavior
Previously, we generated classes from the component state using the pattern
.fui${Component}--${stateValue}. For example,.fuiButton--primaryfor a button with the state{ appearance: "primary" }, or.fuiButton--smallfor{ size: 'small' }. These classes were mapped manually.New Behavior
This PR introduces the utility
getComponentSlotClassName, which maps component state to CSS classes using a new structure:.fui${Component}--${stateName}-${stateValue}or.fui${Component}--${stateName}if the value is a truthy boolean. For instance, a state of{ appearance: "primary", size: 'small' }will result in the class namesfuiButton--appearance-primary fuiButton--size-small.Related Issue(s)