@behold/widget
v0.5.64
Published
[![Behold](https://img.shields.io/badge/Behold-e8ebd7.svg?style=for-the-badge&logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI2LjMuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcn
Downloads
40
Maintainers
Readme
Official Behold Widget Web Component
This is the official Behold widget JS package. It is built using web components, which delivers a few benefits:
- It can be used with any JS framework (React, Svelte, Vue, Angular, Solid... you name it), or just dropped into an HTML document.
- It uses no framework and requires no external packages, so it's very lightweight, and won't cause dependency bloat.
- It uses the Shadow DOM, which provides style encapsulation.
Documentation
https://behold.so/docs/widget/
Installation
We have official wrapper components for a number of frameworks. Links below:
Want us to add a framework to this list? Let us know what we should build next: [email protected]
For other environments, or if you just want to use the web component directly, the recommended method is including the embed script directly in your HTML, loaded from our CDN: <script src="https://w.behold.so/widget.js" type="module"></script>
. In a traditional single page application, for example, you would add this script tag to your index.html
file.
The reason we suggest this method over installing the NPM package is that it means your widget will always be up to date. Whenever we publish a bugfix or improvement your users will automatically benefit without any action on your part, and you have one less dependency to worry about.
There may be some cases where you will want to import this package directly. To do this, you will begin by installing the package with your favorite package manager:
NPM
npm install @behold/widget
// or
pnpm add @behold/widget
// or
yarn add @behold/widget
Usage
If you've decided to use the NPM package directly, you will need to import and register the widget before it can be used. Like so:
import { widget } from '@behold/widget'
widget.register()
Once you've either included the embed script or imported and registered your widget you can use the widget web component just like you would any HTML element:
<behold-widget feed-id="YOUR_FEED_ID"></behold-widget>
Because of how web components work, the <behold-widget>
element will just be an empty HTML tag until the embed script loads or you call widget.register()
, at which point your widget will render. So you don't need to worry about running the JS before including the HTML tag, and the widget simply won't load in an environment without JavaScript support.
Configuration
The Behold widget component only accepts a single attribute, feed-id
, which can be found by opening your feed in the Behold dashboard and clicking on "Embed Code".
All configuration and customization is done on the Behold dashboard. When you make changes there, it will automatically update your widget, no code changes required.
Load event
This component emits a load event after its initial render.
<behold-widget
feed-id="YOUR_FEED_ID"
onload="console.log('loaded!')"
></behold-widget>