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

Define variants inside a component #3681

Closed
memic84 opened this issue Mar 25, 2025 · 7 comments
Closed

Define variants inside a component #3681

memic84 opened this issue Mar 25, 2025 · 7 comments
Labels
question Further information is requested v3 #1289

Comments

@memic84
Copy link

memic84 commented Mar 25, 2025

Description

Is it possible to define the same configuration that is defined in app.config, inside a component.

Now it seems that you can only define the slots, or class when there are no slots.

@memic84 memic84 added question Further information is requested v3 #1289 labels Mar 25, 2025
@HugoRCD
Copy link
Member

HugoRCD commented Mar 25, 2025

Yes, using the :ui props. I didn't really understand what you meant exactly 🤔

Copy link
Member

No it's not possible, the ui prop only targets slots after variants have been calculated.

@memic84
Copy link
Author

memic84 commented Mar 25, 2025

It would be great if that also could be done from the component.

We are creating our own abstractions in between nuxt ui and pass the props with v-bind=props

That means when we create components which are custom and not from nuxt ui l, the tailwind variants aren't under app config ui but in the component itself.

However i think it would be also more readable if the component variant was an option.

As a solution we now have like Button.vue and button.theme.ts which is imported in app config.

Any thoughts on this? @benjamincanac

Copy link
Member

Unfortunately this is not how the library has been designed. The goal is to define all possible variants in the app.config.ts so they are available to all instances of components. When instantiated the component computes each slots class based on the props and let the user override the result of this using the ui and class props.

@benjamincanac benjamincanac closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2025
@memic84
Copy link
Author

memic84 commented Mar 26, 2025

One last question about the variants. When defined inside app.config, is it possible to add new variants, or just completely override the existing one?

Copy link
Member

You can't directly add new keys under variants as it requires a prop on the component but you can add new keys under each variants object if it makes sense. For example, you can add a new variant for the Button: https://github.com/nuxt/ui/blob/v3/src/theme/button.ts#L19

@memic84
Copy link
Author

memic84 commented Mar 26, 2025

Yes. Maybe variants and variant make ot confusing, but for example adding '2xl' key to sizes works as i have seen.

I just wonder if it is possible to define variant, as primary and secondary and remove the solid, outline keys and all the others. The object merge probably kicks in here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested v3 #1289
Projects
None yet
Development

No branches or pull requests

3 participants