npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@molecule/app-embed-snippet-react

v1.0.1

Published

Configurable iframe-snippet generator + copy button — pre-formatted HTML/script snippets for embeddable widgets

Readme

@molecule/app-embed-snippet-react

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

@molecule/app-embed-snippet-react<EmbedSnippet> component.

Renders a pre-formatted HTML / iframe / React snippet inside a <pre> element with a copy-to-clipboard button and optional inline controls (width / height / theme) bound to caller-provided state. Reusable across any embeddable widget — 3d-model-viewer, chat-widget, charts, status-page.

Quick Start

import { EmbedSnippet } from '@molecule/app-embed-snippet-react'

;<EmbedSnippet
  template={
    '<iframe src="https://example.com/embed" width="{{width}}" height="{{height}}" data-theme="{{theme}}" />'
  }
  controls={{ width: true, height: true, theme: true }}
  values={values}
  onChange={setValues}
  language="iframe"
/>

Type

feature

Installation

npm install @molecule/app-embed-snippet-react @molecule/app-i18n @molecule/app-react @molecule/app-ui @molecule/app-ui-react react
npm install -D @types/react

API

Interfaces

EmbedSnippetControls

Inline-control configuration: which knobs render alongside the snippet.

interface EmbedSnippetControls {
  /** Render a width input. */
  width?: boolean
  /** Render a height input. */
  height?: boolean
  /**
   * Render a theme selector. Either `true` (uses default theme options) or
   * an array of `{ value, label }` choices.
   */
  theme?: boolean | EmbedSnippetThemeOption[]
}

EmbedSnippetProps

Props for <EmbedSnippet> — the copy-embed-code panel used by 3d-model-viewer, status-page, embeddable-chat-widget, charts, etc.

interface EmbedSnippetProps {
  /**
   * Snippet template string with `{{width}}`, `{{height}}`, `{{theme}}`
   * placeholders that get substituted with the current `values`. Anything
   * not referenced is preserved verbatim.
   */
  template: string
  /** Optional inline controls (width / height / theme) bound to `values`. */
  controls?: EmbedSnippetControls
  /** Current control values. Required when `controls` is supplied. */
  values?: EmbedSnippetValues
  /** Called whenever the user changes a control value. */
  onChange?: (next: EmbedSnippetValues) => void
  /** Snippet language token, surfaced in the eyebrow + aria-label. Defaults to `'html'`. */
  language?: EmbedSnippetLanguage
  /** Optional heading override (defaults to a translated `Embed code`). */
  heading?: string
  /** Optional eyebrow override (defaults to a translated `Copy embed code`). */
  eyebrow?: string
  /** Called after a successful clipboard copy. */
  onCopy?: (rendered: string) => void
  /** How long the "Copied!" feedback lingers, in ms. Defaults to `1500`. */
  feedbackMs?: number
  /** Stable `data-mol-id` token for the panel root. Defaults to `'embed-snippet'`. */
  molId?: string
  /** Extra class string appended to the panel root. */
  className?: string
}

EmbedSnippetThemeOption

A single option for the theme <select> control.

interface EmbedSnippetThemeOption {
  /** Underlying value substituted into the snippet template. */
  value: string
  /** Human-readable label shown in the dropdown. Already translated by the caller. */
  label: string
}

EmbedSnippetValues

User-editable values that get substituted into a snippet template.

interface EmbedSnippetValues {
  /** Width of the embedded widget. May be a CSS length (`'600px'`) or a number (interpreted as px). */
  width?: string | number
  /** Height of the embedded widget. May be a CSS length (`'400px'`) or a number (interpreted as px). */
  height?: string | number
  /** Theme token forwarded into the snippet (e.g. `'light'`, `'dark'`). */
  theme?: string
}

Types

EmbedSnippetLanguage

Language used to format the rendered snippet.

type EmbedSnippetLanguage = 'html' | 'react' | 'iframe'

Functions

coerceDimension(value)

Coerce a width/height value into the string form embedded in the rendered snippet. Numbers become <n>px; strings pass through; nullish values become an empty string.

function coerceDimension(value: string | number | null | undefined): string
  • value — The raw value supplied by the caller.

Returns: A string ready for substitution.

EmbedSnippet(props)

<EmbedSnippet> — the "Copy embed code" panel.

Renders a substituted snippet inside a <pre> element, a copy-to-clipboard button with "Copied!" feedback, and (optionally) inline width / height / theme controls bound to values + onChange.

All styling resolves through getClassMap() and all user-facing text resolves through useTranslation() — no hardcoded UI strings or styling-library class names.

function EmbedSnippet(
  props: EmbedSnippetProps,
): ReactElement<unknown, string | JSXElementConstructor<any>>
  • props — {@link EmbedSnippetProps}.

Returns: The rendered embed-snippet panel.

substituteTemplate(template, values)

Substitute {{width}}, {{height}}, {{theme}} (case-sensitive, optional internal whitespace) in a template with the supplied values.

Unknown placeholders are left untouched so callers can freely mix this with their own templating.

function substituteTemplate(template: string, values?: EmbedSnippetValues): string
  • template — Raw snippet template.
  • values — Values to substitute.

Returns: The template with known placeholders replaced.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-i18n ^1.0.1
  • @molecule/app-react ^1.0.1
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-react ^1.0.1
  • react ^18.0.0 || ^19.0.0

Runtime Dependencies

  • @molecule/app-i18n
  • @molecule/app-react
  • @molecule/app-ui
  • @molecule/app-ui-react
  • react

All UI text resolves through useTranslation() from @molecule/app-react with English fallbacks. Companion locale bond: @molecule/app-locales-embed-snippet.

Copy-to-clipboard uses navigator.clipboard, which browsers only expose in secure contexts (HTTPS or localhost). On insecure origins the Copy button is a silent no-op — no error, no "Copied!" feedback. If your app must support insecure origins, wire onCopy and surface your own fallback (e.g. select-the-text instructions).

Substitution replaces only the {{width}}, {{height}} and {{theme}} placeholders (numbers become <n>px); unknown placeholders pass through untouched, so the template can mix in your own tokens.

Translations

Translation strings are provided by @molecule/app-locales-embed-snippet.