Socket
Socket
Sign inDemoInstall

@behold/widget

Package Overview
Dependencies
1
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @behold/widget

[![Behold](https://img.shields.io/badge/Behold-e8ebd7.svg?style=for-the-badge&logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI2LjMuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcn


Version published
Weekly downloads
641
increased by2464%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Official Behold Widget Web Component

Behold React

This is the official Behold widget JS package. It is built using web components, which delivers a few benefits:

  1. It can be used with any JS framework (React, Svelte, Vue, Angular, Solid... you name it), or just dropped into an HTML document.
  2. It uses no framework and requires no external packages, so it's very lightweight, and won't cause dependency bloat.
  3. 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:

React Preact Svelte Vue.js Angular

Want us to add a framework to this list? Let us know what we should build next: support@behold.so

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>

Keywords

FAQs

Last updated on 30 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc