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

Allow Wrapping the Root Component with a Global Context Provider in Addons #2041

Open
sghuang19 opened this issue Feb 1, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@sghuang19
Copy link

sghuang19 commented Feb 1, 2025

Is your feature request related to a problem? Please describe.

When creating addons that introduces other component libraries, some will require a context provider to enable the full capability of the libraries. e.g. to provide themes. Currently, seems like we only have control on the app object, (can do app.use(), etc), but we don't have access to the definition of the app itself.

Describe the solution you'd like

Give a config function for wrapping global context provider:

import { h, type Component } from "vue";

export function defineGlobalProvider(
  wrapper: (appRoot: Component) => Component
) {
  return (appRoot: Component) => wrapper(appRoot);
}

This should be put in createApp()

And the configuration will look like:

// main.ts
defineGlobalProvider((rootComponent) => ({
  render() {
    return h(MyGlobalProvider, null, () => h(rootComponent));
  },
}));

See also in:

#2039

tusen-ai/naive-ui#6733

@sghuang19 sghuang19 added the enhancement New feature or request label Feb 1, 2025
@sghuang19
Copy link
Author

Inspired by https://sli.dev/features/global-layers, maybe we can have a global-context.vue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant