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

The web component doesn't support the config attribute? #394

Closed
jonsage opened this issue Jul 15, 2021 · 12 comments
Closed

The web component doesn't support the config attribute? #394

jonsage opened this issue Jul 15, 2021 · 12 comments

Comments

@jonsage
Copy link

jonsage commented Jul 15, 2021

The web component doesn't appear to support the config attribute in any way.

@github-actions
Copy link

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.

Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@magicmatatjahu
Copy link
Member

@jonsage Hi! Did you use the webcomponent from master or from next branch (installed as @asyncapi/web-component@next)?

Please also add more information in which environment - framework are you using the component.

@jonsage
Copy link
Author

jonsage commented Jul 15, 2021

Hi, I've tried both master and next, I'm not using the component in any framework, just HTML.

The scripts load from unpkg as in the examples.

I've tried config as an attribute, and also as a property (accessing the webcomponent node through JS).

I've taken a look in the webcomponent tsx file, and the config property isn't exported but it is registered when defining the custom element.

I can find no usage example of using config with the web component so this might just be something I'm doing wrong - right now I've tried passing in a JSON object as the value:

config='{ "show": { "sidebar": true } }'

@magicmatatjahu
Copy link
Member

For me this html works:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/@asyncapi/[email protected]/lib/asyncapi-web-component.js" defer></script>
  </head>
  <body>

    <asyncapi-component
      schemaUrl="https://raw.githubusercontent.com/asyncapi/spec/v2.0.0/examples/2.0.0/streetlights.yml"
      schemaFetchOptions='{"method":"GET","mode":"cors"}'
      config='{"show": {"info": false}}'
      cssImportPath="https://unpkg.com/@asyncapi/[email protected]/lib/styles/fiori.css">
    </asyncapi-component>

  </body>
</html>

So I pass config as stringified JSON as in your example.

@jonsage
Copy link
Author

jonsage commented Jul 15, 2021

I have this, but it wont show the sidebar :/

<asyncapi-component
  schemaUrl="https://raw.githubusercontent.com/asyncapi/spec/v2.0.0/examples/2.0.0/streetlights.yml"
  schemaFetchOptions='{"method":"GET","mode":"cors"}'
  cssImportPath="https://unpkg.com/@asyncapi/[email protected]/lib/styles/fiori.css"
  config='{"show": {"sidebar": true}}'>
</asyncapi-component>

@magicmatatjahu
Copy link
Member

magicmatatjahu commented Jul 15, 2021

Sidebar is added in the next version of component :)

Try this:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/@asyncapi/[email protected]/lib/asyncapi-web-component.js" defer></script>
  </head>
  <body>

    <asyncapi-component
      schemaUrl="https://raw.githubusercontent.com/asyncapi/spec/v2.0.0/examples/2.0.0/streetlights.yml"
      schemaFetchOptions='{"method":"GET","mode":"cors"}'
      config='{"show": {"sidebar": true }}'
      cssImportPath="https://unpkg.com/@asyncapi/[email protected]/styles/default.min.css">
    </asyncapi-component>

  </body>
</html>

@magicmatatjahu
Copy link
Member

magicmatatjahu commented Jul 16, 2021

You can also use the standalone bundle - preferrer way, because web-component has shadow dom, which breaks the hashchange event and style must be imported as cssImportPath prop - due to shadow CSS...

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="https://unpkg.com/@asyncapi/[email protected]/styles/default.min.css">
  </head>
  <body>
    
    <div id="asyncapi"></div>

    <script src="https://unpkg.com/@asyncapi/[email protected]/browser/standalone/index.js"></script>
    <script>
      AsyncApiStandalone.render({
        schema: {
          url: 'https://raw.githubusercontent.com/asyncapi/spec/v2.0.0/examples/2.0.0/streetlights.yml',
          options: { method: "GET", mode: "cors" },
        },
        config: {
          show: {
            sidebar: true,
          }
        },
      }, document.getElementById('asyncapi'));
    </script>

  </body>
</html>

I will update the docs and sorry for the problems with unclear docs :)

@jonsage
Copy link
Author

jonsage commented Jul 16, 2021

One problem with the approach above is the default.css (without shadow DOM) leaks Tailwind global CSS affecting typography amongst other things - it would be good if all the styles included were scoped to just the component and not the rest of the site hosting it.

I'm not knowledgeable on React and Tailwind so I'm not sure the best way to do this, but I thought I'd just bring it to your attention in case you felt it was worth looking into :)

Thank you so much for your time and effort btw - it's extremely appreciated.

@magicmatatjahu
Copy link
Member

If you have in mind normalizer/reset CSS from TailwindCSS, we know about that and we have issue for that #368 and PR is on the way :)

@magicmatatjahu
Copy link
Member

Docs will be merged with PR #395

@jonsage
Copy link
Author

jonsage commented Jul 16, 2021

@magicmatatjahu

… because web-component has shadow dom, which breaks the hashchange event

Is there a plan to capture the click and scroll to the target element instead of relying on the hashchange? It seems like a big caveat to have the sidebar not work to navigate. That way the shadow dom issue wouldn't matter.

@magicmatatjahu
Copy link
Member

It's a solution, but we don't want to add "extra" logic inside component. It should only render the html. We have something similar in the master branch:

image

and it's a buggy, really buggy. Probably in the future we will remove the web-component and only support the standalone bundle, due to fact that we want to add plugins feature #305 and the web-component doesn't support passing functions (as ref) as prop to itself.

BTW. I merged the #395 PR with docs how to pass the config to web-component.

If you will have another problems, please open another issue, or reopen it. I will close it, thanks for informing us about this issue :)

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

2 participants