Skip to content

Conversation

@dmytrokirpa
Copy link
Contributor

@dmytrokirpa dmytrokirpa commented Dec 7, 2025

Previous Behavior

Previously, we generated classes from the component state using the pattern .fui${Component}--${stateValue}. For example, .fuiButton--primary for a button with the state { appearance: "primary" }, or .fuiButton--small for { 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 names fuiButton--appearance-primary fuiButton--size-small.

Related Issue(s)

  • Fixes #

@dmytrokirpa dmytrokirpa self-assigned this Dec 7, 2025
@github-actions
Copy link

github-actions bot commented Dec 7, 2025

📊 Bundle size report

✅ No changes found

@github-actions
Copy link

github-actions bot commented Dec 7, 2025

Pull request demo site: URL

@dmytrokirpa dmytrokirpa changed the title feat: implement getComponentSlotClassName utility for dynamic class n… …ame generation feat: implement getComponentSlotClassName utility for dynamic class name generation Dec 7, 2025
@dmytrokirpa dmytrokirpa marked this pull request as ready for review December 9, 2025 08:18
@dmytrokirpa dmytrokirpa requested review from a team and marcosmoura as code owners December 9, 2025 08:18
Copy link
Member

@layershifter layershifter left a 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.

@dmytrokirpa
Copy link
Contributor Author

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 getComponentSlotClassName__experimental/getComponentSlotClassName__unstable if you think that would be helpful.

@layershifter
Copy link
Member

layershifter commented Dec 10, 2025

@dmytrokirpa is there a reason why these utils cannot be shipped in a preview package?

@dmytrokirpa
Copy link
Contributor Author

dmytrokirpa commented Dec 11, 2025

@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 .headless.js resolution trick won’t work. As for the getComponentSlotClassName util, we could totally ship it as a preview package, but I’m not sure there’s much upside since we’d still have to add it as a dependency for the component packages. Unless I’m missing something here!

@layershifter If you have any ideas or suggestions on how we can improve this, I’m all ears.

@dmytrokirpa dmytrokirpa changed the base branch from master to headless-components December 12, 2025 10:15
@dmytrokirpa dmytrokirpa merged commit 7829837 into microsoft:headless-components Dec 12, 2025
12 checks passed
@dmytrokirpa
Copy link
Contributor Author

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.

dmytrokirpa added a commit that referenced this pull request Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants