Skip to content

Extend component meta #5168

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

Closed
romhml opened this issue Feb 10, 2025 · 3 comments
Closed

Extend component meta #5168

romhml opened this issue Feb 10, 2025 · 3 comments

Comments

@romhml
Copy link

romhml commented Feb 10, 2025

What problem does this feature solve?

It would be usefull for library authors to be able to extend component metas. In @nuxt/ui for example we're using something similar for our devtools, allowing us to pass default property values and examples to preview components (Here's an example).

What does the proposed solution look like?

We could define a new macro defineComponentMeta(meta: Record<string, any>) that can be used within a component. Its content would be parsed and injected into the component's meta by the meta checker.

<script setup lang="ts">
const props = defineProps<{ foo: string }>()

extendComponentMeta({
    bar: 'baz'
})
</script>

<template>
    <span />
</template>

Which would result in the following meta:

{
    bar: 'baz',
    props: [ /* ... */ ],
    // ...
}

I can look into the implementation if needed.

@KazariEX
Copy link
Member

This requires runtime support (just drops it), you can try implementing this feature.

@romhml
Copy link
Author

romhml commented Feb 10, 2025

@KazariEX I submitted a draft implementation with some questions. I'll continue working on it and look into the runtime support too.

@romhml
Copy link
Author

romhml commented Feb 27, 2025

Hey! I managed to implement something on my own to achieve similar result (at runtime though). I'll continue working on implementing a macro by extending the meta checker on my own, since I don't think it makes a lot of sense to introduce it here (and in the vue runtime).

Thanks for your help @KazariEX :)

@romhml romhml closed this as completed Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants