feat(theme): allow replacing slot classes with a function#6562
Draft
benjamincanac wants to merge 1 commit into
Draft
feat(theme): allow replacing slot classes with a function#6562benjamincanac wants to merge 1 commit into
benjamincanac wants to merge 1 commit into
Conversation
Slot classes set through `:ui`, the `class` prop and `app.config.ui` can now be a `(defaults) => classes` function that replaces the slot's default classes instead of merging onto them. Strings keep their current merge behavior. Implemented centrally in the `tv` wrapper (apply-trap Proxy + slot wrapping + construction-time directive extraction), so no component changes are needed. Resolves #4953
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
Resolves #4953
Related to #6551
❓ Type of change
📚 Description
Adds a function form for slot classes so you can fully replace a slot's defaults instead of merging onto them, which is the recurring ask in #4953. Today
app.config.ui, the:uiprop and theclassprop only ever merge onto the component defaults (tailwind-variantsextendconcatenates andtwMergeonly drops conflicting utilities), so non conflicting defaults always survive and you end up fighting the cascade.Now any slot value can be a
(defaults) => classesfunction. It receives the slot's resolved default classes and returns what to use in their place, while plain strings keep merging exactly as before so nothing changes for existing code.It works in the
:uiprop, theclassprop,app.config.uiand<UTheme :ui>. The whole thing lives in the sharedtvwrapper (an apply-trap Proxy that preservesextend, plus slot wrapping and construction-time directive extraction), so there are zero component changes. The function is also the safest possible encoding here since it survivesdefu, is never bound to:classand is never serialized.Performance is a non issue: the wrapper adds about 0.24µs per build plus four slot calls on the no replace path (a couple of
typeofchecks then a delegate to the original slot fn), and the build is already memoized inside each component'scomputed. The full suite passes with byte identical snapshots.This pairs with the build-time
theme.unstyledoption from #6551 (global strip) to give a full three tier story: global, per instance and per slot. Note the docs cross link totheme.unstyledonly resolves once #6551 lands.📝 Checklist