Skip to content

@askable-ui/svelte

Svelte 4 bindings for askable-ui.

Install

bash
npm install @askable-ui/svelte @askable-ui/core

<Askable>

Renders a wrapper element with data-askable managed reactively.

svelte
<script>
  import Askable from '@askable-ui/svelte/Askable.svelte';
</script>

<Askable meta={{ metric: 'revenue', delta: '-12%' }}>
  <RevenueChart />
</Askable>

<Askable meta={{ metric: 'revenue' }} scope="analytics">
  <RevenueChart />
</Askable>

<Askable meta="main navigation" as="nav">
  <NavLinks />
</Askable>

Props:

PropTypeDefaultDescription
metaRecord<string, unknown> | stringValue for data-askable attribute
scopestringOptional category written to data-askable-scope for scoped prompt/history queries
asstring"div"HTML element to render

createAskableStore(options?)

Factory that returns Svelte stores backed by an AskableContext. SSR-safe — observe() is guarded and only runs in the browser.

ts
import { createAskableStore } from '@askable-ui/svelte';

const { focus, promptContext, ctx, destroy } = createAskableStore();

Always call destroy() in onDestroy:

ts
import { onDestroy } from 'svelte';
const { destroy } = createAskableStore();
onDestroy(destroy);

Options:

OptionTypeDescription
eventsAskableEvent[]Trigger events. Default: ['click', 'hover', 'focus']

Returns:

ValueTypeDescription
focusReadable<AskableFocus | null>Reactive focus store
promptContextReadable<string>Reactive prompt-ready context store
ctxAskableContextFull context instance
destroy() => voidTears down the context

Examples:

ts
// Subscribe with $ auto-subscription in Svelte
$: console.log($focus?.meta);
$: console.log($promptContext);

// Click-only
const store = createAskableStore({ events: ['click'] });

Released under the MIT License.