import { createSignal, For, Show } from "solid-js"; import preview from "../../../.storybook/preview.js"; import { createSocialShare, createWebShare, BLUESKY, EMAIL, FACEBOOK, LINKEDIN, REDDIT, TELEGRAM, WHATSAPP, X, } from "@solid-primitives/share"; import type { Network } from "@solid-primitives/share"; import readme from "../README.md?raw"; import { Alert, Badge, BoolRow, Button, ButtonRow, Card, Container, Section, StatRow, TextField, } from "../../../.storybook/ui/index.js"; const meta = preview.meta({ title: "Utilities/Share", tags: ["autodocs"], parameters: { layout: "centered", docs: { description: { component: readme, }, }, }, }); export default meta; const POPULAR_NETWORKS: { label: string; network: Network }[] = [ { label: "X", network: X }, { label: "Bluesky", network: BLUESKY }, { label: "Facebook", network: FACEBOOK }, { label: "LinkedIn", network: LINKEDIN }, { label: "Reddit", network: REDDIT }, { label: "WhatsApp", network: WHATSAPP }, { label: "Telegram", network: TELEGRAM }, { label: "Email", network: EMAIL }, ]; export const SocialShareStory = meta.story({ name: "Social network picker", parameters: { docs: { description: { story: "`createSocialShare` opens a share popup for the chosen network. `isSharing` goes `true` while the popup window is open and resets to `false` when the user closes it.", }, }, }, render: () => { const { share, isSharing } = createSocialShare(() => ({ url: "https://primitives.solidjs.community", title: "Solid Primitives", description: "A library of high-quality primitives for Solid.js", })); return (

createSocialShare

{({ label, network }) => ( )}
Popup is open — close it to reset
); }, }); export const WebShareStory = meta.story({ name: "Native share dialog", parameters: { docs: { description: { story: "`createWebShare` wraps the browser's native Web Share API with reactive state. `pending` is `true` while the dialog is open; `status` is `true` on success or `false` on failure. Requires a secure context and browser support.", }, }, }, render: () => { const { share, pending, status, message } = createWebShare(); return (

createWebShare

Shared successfully! {message()}

Requires HTTPS and browser support. The error message appears above when the API is unavailable or the user cancels.

); }, }); export const CustomNetworkStory = meta.story({ name: "Custom URL template", parameters: { docs: { description: { story: "Any URL string can be passed as the `network`. Markers `@u`, `@t`, `@d`, `@q`, `@h`, `@m`, and `@tu` are substituted at share time — useful for networks not included in the built-in list.", }, }, }, render: () => { const [template, setTemplate] = createSignal("https://www.x.com/intent/tweet?text=@t&url=@u"); const previewUrl = () => template() .replace(/@tu/g, "") .replace(/@u/g, encodeURIComponent("https://primitives.solidjs.community")) .replace(/@t/g, encodeURIComponent("Solid Primitives")) .replace(/@d/g, encodeURIComponent("High-quality primitives for Solid.js")) .replace(/@q/g, "") .replace(/@h/g, "") .replace(/@m/g, ""); const { share } = createSocialShare(() => ({ url: "https://primitives.solidjs.community", title: "Solid Primitives", description: "High-quality primitives for Solid.js", })); return (

Custom network URL

@u url  ·  @t title  ·  @d{" "} description  ·  @q quote  ·  @h hashtags  ·  @m media

{previewUrl()}
); }, });