8000 Different wrappers for different components · Issue #2107 · fwouts/previewjs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Different wrappers for different components #2107
Open
@rudolfbyker

Description

@rudolfbyker

I'm curious to hear more about your use case for different wrappers for different components though. What do you envision that looking like?

Originally posted by @fwouts in #2086 (comment)

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

Let's say I have ComponentA and ComponentB. ComponentA requires some things to be provided by the wrapper, and some globals to be mocked. ComponentB requires something totally different, but maybe with the same name. It's not possible to use the same wrapper for previewing both.

Describe the solution you'd like

I don't have strong opinions about how to implement this, but here are some ideas:

  • Specify in nuxt.config.ts which components will use which wrapper. Something like
    {
      ...,
      previewjs: {
        wrappers: [
          {
            wrapper: {
              path: "__previewjs__/WrapperA.tsx",
              componentName: "WrapperA",
            },
            componentsToWrap: [
              {
                path: "components/ComponentA.vue",
                componentName: "ComponentA",
              },
              ...
            ],
          },
          ...
        ],
      },
      ...
    }
  • A special comment like /// <wrapper = foo> in the component file.
  • Special blocks inside the single-file .vue component:
    <template preview-js-wrapper>
      <div class="wrapped">
        <slot />
      </div>
    </template>
    
    <script setup preview-js-wrapper>
      import { provide } from 'vue';
      provide('foo', 'bar');
    </script>
  • Allow a file name pattern like ComponentA.wrapper.vue and ComponentB.wrapper.vue.

Some of these suggestions only allow a 1:1 relationship between wrapper and component. Others allow 1:N relationship between wrapper and components. Currently, we have a 1:all relationship (just one wrapper for all components in the project)

Describe alternatives you've considered

  • Create a folder called componentExamples or componentPreviews that contain components that are not used in production, but only as examples for preview. This can get a bit tedious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0