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

feat: support custom global ui component injection #118

Open
3 tasks done
sanyuan0704 opened this issue Oct 28, 2022 · 1 comment
Open
3 tasks done

feat: support custom global ui component injection #118

sanyuan0704 opened this issue Oct 28, 2022 · 1 comment

Comments

@sanyuan0704
Copy link
Owner

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

For example, i want to inject a back to top component, then i can register it by following config:

// config.ts
export default {
  globalUIComponents: ['/User/project/src/components/BackToTop/index.tsx']
}

Then the component will be injected to page automatically.

Describe the solution you'd like

  1. declare virtual module in Layout component in default theme.
// Layout/index.tsx
import globalComponents from 'virtual:components'
  1. Generate component exports in vite plugin:
load(id) {
  if (id === 'virtual:components') {
    return `
      import BackToTop from '/User/project/src/components/BackToTop/index.tsx';
      export default [BackToTop]
   `
  }
}
  1. Render global component:
// Layout/index.tsx
function Layout() {
  return (
     // 省略
     globalComponents.map(globalComponent => React.createElement(globalComponent))
  )
}

Describe alternatives you've considered

No response

Additional context

No response

Validations

  • Read the docs.
  • Read the Contributing Guidelines.
  • Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate.
@sanyuan0704
Copy link
Owner Author

I am not clear how to implement it

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

No branches or pull requests

1 participant