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-checkpoint': JSX.HTMLAttributes; } } } /** Render the actual `` custom element configured by attributes. */ function CheckpointElement(props: { label?: string; tooltip?: string; variant?: string; size?: string }) { let el: HTMLElement | undefined; onMount(() => { if (!el) return; if (props.label) el.setAttribute('label', props.label); if (props.tooltip) el.setAttribute('tooltip', props.tooltip); if (props.variant) el.setAttribute('variant', props.variant); if (props.size) el.setAttribute('size', props.size); el.addEventListener('kc-select', () => console.log('checkpoint selected')); }); return (el = e as HTMLElement)} style={{ display: 'inline-block', padding: '16px' }} />; } const HTML_SNIPPET = ` `; const meta = { title: 'Components/Checkpoint', tags: ['autodocs'], argTypes: argTypesFor('kc-checkpoint'), parameters: { layout: 'fullscreen', docs: { description: specDescription('kc-checkpoint', [ '`` is the framework-agnostic **web component** for a bookmark/checkpoint button (with an optional tooltip and label), isolated in **Shadow DOM**.', '**When to use:** marking a restore point in a conversation in a non-Solid app. In SolidJS, compose the `Checkpoint` primitives.', '**Placement:** inline inside a message row (e.g. in the action bar) or in a chat toolbar; it is a compact `inline-block` button and does not need a dedicated row.', "**How to use:** register once with `import '@kitn.ai/chat/elements'`, set `label`, `tooltip`, `variant` (`ghost` | `default` | `outline`), and `size` via attributes, and listen for the `kc-select` **CustomEvent** on click.", 'See the **Code** tab for HTML usage.', ]), }, }, } satisfies Meta; export default meta; type Story = StoryObj; /** A labeled checkpoint button. (Add a `tooltip` attribute for a hover hint — see the Code tab.) */ export const Labeled: Story = { render: () => , parameters: { docs: { source: { code: HTML_SNIPPET, language: 'html' } } }, }; /** Icon-only (no label), using an `icon` size. */ export const IconOnly: Story = { name: 'Icon Only', render: () => , };