@kitn.ai/ui
Version:
Framework-agnostic, Shadow-DOM web components for building AI chat interfaces — works in React, Vue, Angular, Svelte, or plain HTML. Authored in SolidJS.
38 lines (37 loc) • 2 kB
TypeScript
import { Accessor } from 'solid-js';
import { WebComponentContext } from './define';
/** The open controller a primitive hands up via `controllerRef` so a facade can
* drive + observe its open/closed state. */
export interface OpenController {
open: Accessor<boolean>;
setOpen: (v: boolean) => void;
}
/**
* Wire the standard Shoelace/WebAwesome-style overlay surface onto an internal
* open controller — the kit's convention for every open/close element (hover-card,
* tooltip, popover, menu, model-switcher, scope-picker, collapsibles, …). NOT
* React-controlled: the element keeps self-managing; this layers the host-facing
* conveniences on top.
*
* Given the primitive's `{ open, setOpen }` controller, it provides:
* - **`open` reflects** to the host `[open]` attribute (for `:host([open])` CSS),
* and is **settable** — `el.open = true` / `<el open>` drives it;
* - **`kai-open-change` `{ open }`** fires once per change (a guarded reflect
* avoids the attribute⇄prop feedback loop);
* - **`show()` / `hide()` / `toggle()`** instance methods, gated by `disabled`.
*
* The facade still:
* - declares the `open` / `defaultOpen` / `disabled` props (defaults `undefined`),
* - seeds the primitive from `defaultOpen` (e.g. via the primitive's own prop),
* - includes `'kai-open-change': { open: boolean }` in its `Events` map.
*
* @param ctx the facade's WebComponentContext (its Events must include kai-open-change).
* @param getApi returns the open controller once the primitive has handed it up (may be undefined early).
* @param openProp reads the raw reactive `open` prop (e.g. `() => props.open`) — used to tell
* "consumer explicitly set open" from "unset" so a `defaultOpen` seed isn't clobbered.
*/
export declare function wireDisclosure<E extends {
'kai-open-change': {
open: boolean;
};
}>(ctx: WebComponentContext<E>, getApi: () => OpenController | undefined, openProp: () => unknown): void;