Documentation navigation

Published API · 0.1.0-rc.1

foldkit-ui · disclosure

Published foldkit-ui API declarations for disclosure.

./disclosure

@wsagency/wseffect-foldkit-ui · MIT · source · MIT license · WS-AGENCY-NOTICE · THIRD-PARTY-NOTICES

This entry point is published in @wsagency/wseffect-foldkit-ui@0.1.0-rc.1. Import it from the package subpath shown below; the signatures and documentation are read from the installed package declarations.

import * as Wseffect from '@wsagency/wseffect-foldkit-ui/disclosure'

Exported declarations

AnimatePanelOptions

Options for `DisclosureAttributes.animatePanel`. - `peek`: a CSS height the collapsed panel keeps, such as `'7.5em'` for five lines at a 1.5 leading. The visible content is an inert preview; content becomes accessible and interactive when the disclosure opens.

export type AnimatePanelOptions = Readonly<{
    peek?: string;
}>;

buttonId

Returns the bare DOM id of the disclosure toggle button, derived from the disclosure's base id. Use this to associate an external label with the button via a native `<label for={Disclosure.buttonId(id)}>` or an `aria-labelledby` reference.

buttonId: (id: string) => string

DisclosureAttributes

Attribute groups the disclosure provides to the consumer's `toView` callback. The consumer composes the button + panel layout themselves using these bundles. The `button` bundle carries the click and Enter/Space handlers that dispatch the configured `onToggle` Message. The `button` bundle sets `type="button"` so that rendering the trigger as a `button` element inside a `form` element toggles without also submitting the form. Setting it is harmless on the other elements a trigger might use, such as a `div` or a `span`, because the builder assigns a DOM property rather than an HTML attribute. Spread a later `h.Type` to override it.

export type DisclosureAttributes<Message> = Readonly<{
    button: ReadonlyArray<Attribute<Message>>;
    panel: ReadonlyArray<Attribute<Message>>;
    /** Wraps panel content in a CSS-grid container that smoothly animates
     *  height (`grid-template-rows: 0fr → 1fr` with `overflow: hidden`) as the
     *  disclosure opens and closes. The panel stays mounted while collapsed, so
     *  the transition has something to animate from and to. Spread the `panel`
     *  bundle onto the element you pass in, and render it unconditionally rather
     *  than gating on `isOpen`.
     *
     *  Without options the collapsed panel is fully hidden. With `peek`, it keeps
     *  that height as a visual preview of its content. In either case, the
     *  collapsed content is inert and hidden from assistive technology until the
     *  disclosure opens. */
    animatePanel: (content: Html, options?: AnimatePanelOptions) => Html;
}>;

view

Renders a headless disclosure as a stateless controlled component. The parent owns the open state (`isOpen`) and receives the new state via `onToggle` when the user toggles it. The consumer composes the layout through `toView`, spreading the `button` and `panel` bundles onto their own elements. ```ts // In view: Disclosure.view( { id: 'details', isOpen: model.isDetailsOpen, onToggle: isOpen => ToggledDetails({ isOpen }), toView: ({ button, panel, animatePanel }) => ..., }, h, ) // In update: ToggledDetails: ({ isOpen }) => ({ model: modifyFields(model, { isDetailsOpen: () => isOpen }), }), ```

view: <Message>(config: ViewConfig<Message>, h: HtmlBuilder<Message>) => Html

ViewConfig

export type ViewConfig<Message> = Readonly<{
    id: string;
    isOpen: boolean;
    onToggle: (isOpen: boolean) => Message;
    toView: (attributes: DisclosureAttributes<Message>) => Html;
    isDisabled?: boolean;
    ariaLabel?: string;
    ariaLabelledBy?: string;
}>;