@molecule/app-share-link-card-svelte

Feature · share-link-card · App (browser) · v1.2.3 · Apache-2.0

Card with share URL, copy button, optional QR code placeholder, password toggle

npm install @molecule/app-share-link-card-svelte

npm · Source on GitHub

How it works

@molecule/app-share-link-card-svelte is a ready-made share-link-card feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

<script lang="ts">
  import { setMoleculeContext } from '@molecule/app-svelte'
  import { ShareLinkCard } from '@molecule/app-share-link-card-svelte'

  setMoleculeContext({ i18n: i18nProvider })

  let passwordEnabled = $state(false)
</script>

<ShareLinkCard
  url="https://app.example.com/p/abc123"
  passwordProtect={{
    enabled: passwordEnabled,
    onChange: (enabled) => (passwordEnabled = enabled),
  }}
>
  {#snippet title()}Share this project{/snippet}
  {#snippet description()}Anyone with the link can view.{/snippet}
</ShareLinkCard>

Works with: @molecule/app-clipboard, @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte

Reference

Svelte share-link card.

Exports <ShareLinkCard> — a read-only URL field with a copy button, an optional title/description header, a QR slot, and an optional password-protect toggle. It is the Svelte counterpart of @molecule/app-share-link-card-react: the same props (React names), the same DOM for the same input, the same ClassMap tokens and i18n keys.

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.

Quick Start

<script lang="ts">
  import { setMoleculeContext } from '@molecule/app-svelte'
  import { ShareLinkCard } from '@molecule/app-share-link-card-svelte'

  setMoleculeContext({ i18n: i18nProvider })

  let passwordEnabled = $state(false)
</script>

<ShareLinkCard
  url="https://app.example.com/p/abc123"
  passwordProtect={{
    enabled: passwordEnabled,
    onChange: (enabled) => (passwordEnabled = enabled),
  }}
>
  {#snippet title()}Share this project{/snippet}
  {#snippet description()}Anyone with the link can view.{/snippet}
</ShareLinkCard>

Type

feature

Installation

npm install @molecule/app-share-link-card-svelte @molecule/app-clipboard @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte

API

Interfaces

ShareLinkCardProps

Props accepted by the ShareLinkCard component.

interface ShareLinkCardProps {
  /** Card title (a snippet slot). */
  title?: Snippet
  /** Supporting copy under the title (a snippet slot). */
  description?: Snippet
  /** The URL users can copy/share. */
  url: string
  /** Optional QR rendering slot — pass your own QR component from the app side. */
  qr?: Snippet
  /** Whether the QR is visible. Defaults to false. */
  showQR?: boolean
  /** Password-protect toggle — pass to render the toggle row. */
  passwordProtect?: {
    /** Whether the toggle is on. */
    enabled: boolean
    /** Called with the toggle's new boolean state. */
    onChange: (enabled: boolean) => void
    /** Row label (a string or a snippet); defaults to a translated "Password protect". */
    label?: string | Snippet
  }
  /** Extra classes. */
  className?: string
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string
}

Constants

ShareLinkCard

const ShareLinkCard: LegacyComponentType

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-clipboard ^1.0.1
  • @molecule/app-svelte ^3.13.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-svelte ^1.1.0
  • svelte ^5.0.0

Runtime Dependencies

  • @molecule/app-clipboard

  • @molecule/app-svelte

  • @molecule/app-ui

  • @molecule/app-ui-svelte

  • svelte

  • QR rendering is slot-based: pass BOTH qr (a snippet) and showQR — qr alone renders nothing.

  • The title, description and password label are snippet slots (the password label also accepts a plain string).

  • Copy goes through copyTextWithFallback() from @molecule/app-clipboard: the bonded clipboard provider first, then the legacy copy command. The "Copied!" feedback appears only when a copy actually happened — copy never throws, so a blocked clipboard leaves the label unchanged.

  • The password toggle is UI-only: persisting and enforcing the password is the app/server's job.

  • Requires a bonded ClassMap (e.g. @molecule/app-ui-tailwind) and the bonded i18n provider. Translations: @molecule/app-locales-share-link-card.

Translations

Translation strings are provided by @molecule/app-locales-share-link-card.