If you are not using React you may want to use the @asyncapi/web-component component as a plain web component in any other web framework of your choice or as an element of a static HTML webpage. This is achieved by making use of web-react-components.
Run this command to install the component in your project:
npm install --save @asyncapi/web-componentCheck out this simple sandbox application that uses the Web Component in Angular project:
Check how to use the Web Component in:
<!-- Remove 'webcomponentsjs' if no support for older browsers is required -->
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@2.5.0/webcomponents-bundle.js"></script>
<script src="https://unpkg.com/@asyncapi/web-component@0.24.0/lib/asyncapi-web-component.js" defer></script>
<asyncapi-component
schemaUrl="https://raw.githubusercontent.com/asyncapi/asyncapi/master/examples/2.0.0/streetlights.yml"
config='{"show": {"info": false}}'
schemaFetchOptions='{"method":"GET","mode":"cors"}' <!-- Remove if it is only a plain browser request -->
cssImportPath="https://unpkg.com/@asyncapi/react-component@0.24.0/styles/default.min.css">
</asyncapi-component>NOTE: webcomponentsjs is a series of polyfills to make code runnable in old browsers. It is optional if you do not intend to support any.
NOTE: If a Web Component is called with no properties at all, the error will be shown on the page.
NOTE: If there are several Web Components on one page, each one will be rendered using its own properties.
When invoked as an independent entity, Web Component takes the following props (as it is still a React component):
schemais aschemaproperty from the React component,NOTE: Since version 0.19.0 specifying a
schemaobject can be omitted.schema.urlandschema.requestOptionscan be replaced withschemaUrlandschemaFetchOptionsproperties accordingly.configis an optionalconfigproperty from the React component in the stringified JSON format,schemaUrlproperty is astring, specific to Web Component, containing a URL to fetch an AsyncAPI Schema from. It is a wrapper forschema.urlproperty inschemaobject under the hood,NOTE: If
schemaUrlproperty is specified, theschema.urlproperty of the React component will be ignored.schemaFetchOptionsproperty is an optionalobjectof RequestInit type in JSON format, specific to Web Component, containing additional fetching options. It is a wrapper forschema.requestOptionsproperty inschemaobject, which are both needed only in case process of fetching from a URL is any different from a usual browser request,NOTE: If
schemaFetchOptionsproperty is specified,schema.requestOptionsproperty of the React component will be ignored. IfschemaUrlproperty is NOT specified,schemaFetchOptionswill be ignored itself andschema.url/schema.requestOptionsproperties of the React component must be used in this case.cssImportPathproperty is the path to styles. Default version fromunpkg.comcontains guaranteed minimum styling for the Web Component,