import type { Meta, StoryObj } from 'storybook-solidjs-vite'; import { onMount } from 'solid-js'; import './register'; // side effect: registers the custom elements import { argTypesFor, specDescription } from '../stories/docs/element-controls'; // The web components are custom DOM elements, so declare the tags for JSX. declare module 'solid-js' { // eslint-disable-next-line @typescript-eslint/no-namespace namespace JSX { interface IntrinsicElements { 'kc-source': JSX.HTMLAttributes & { href?: string; label?: string; headline?: string; description?: string; 'show-favicon'?: boolean | '' }; } } } /** Render the actual `` custom element configured by attributes. */ function SourceElement(props: { href: string; label?: string; headline?: string; description?: string; showFavicon?: boolean; }) { let el: HTMLElement | undefined; onMount(() => { if (!el) return; el.setAttribute('href', props.href); if (props.label) el.setAttribute('label', props.label); if (props.headline) el.setAttribute('headline', props.headline); if (props.description) el.setAttribute('description', props.description); if (props.showFavicon) el.setAttribute('show-favicon', ''); }); return (el = e as HTMLElement)} style={{ display: 'inline-block', padding: '16px' }} />; } const HTML_SNIPPET = ` `; const meta = { title: 'Components/Source', tags: ['autodocs'], argTypes: argTypesFor('kc-source'), parameters: { layout: 'fullscreen', docs: { description: specDescription('kc-source', [ '`` is the framework-agnostic **web component** for a single citation link with a hover-card preview, isolated in **Shadow DOM**.', '**When to use:** inlining a single source citation in a non-Solid app. For multiple sources, use ``; in SolidJS, compose the `Source` primitives.', '**Placement:** inline within message text (beside a sentence or at the end of a paragraph) or as a standalone citation chip below a message; it is an `inline-block` element that fits naturally within flow content.', "**How to use:** register once with `import '@kitn.ai/chat/elements'`, then set `href` (the link, also the default label/favicon source), `label`, `headline` (the hover headline — note `headline`, not `title`), `description`, and the `show-favicon` flag via attributes.", 'See the **Code** tab for HTML usage.', ]), }, }, } satisfies Meta; export default meta; type Story = StoryObj; /** A citation with a custom label, hover headline/description, and favicon. */ export const Default: Story = { render: () => ( ), parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } }, }; /** With no `label`, the trigger falls back to the domain. */ export const DomainLabel: Story = { name: 'Domain Label', render: () => , };