UNPKG

element-book

Version:

An [`element-vir`](https://npmjs.com/package/element-vir) drop-in element for building, testing, and demonstrating a collection of elements (or, in other words, a design system).

64 lines (63 loc) 3.08 kB
import { type Overwrite, type PartialWithUndefined, type SetOptionalAndNullable } from '@augment-vir/common'; import { type CSSResult, type HtmlInterpolation, type PropertyInitMapBase, type RenderParams, type TypedEvent } from 'element-vir'; import { type GlobalValues } from '../../../ui/elements/element-book-app/global-values.js'; import { type BaseBookEntry } from '../base-book-entry.js'; import { type BookEntryType } from '../book-entry-type.js'; import { type BookPageControlsInitBase, type ControlsToValues } from './book-page-controls.js'; /** * An individual element-book page. * * @category Type */ export type BookPage<GlobalValuesType extends GlobalValues = {}, ParentPage extends BookPage | undefined = any, ControlsInit extends BookPageControlsInitBase = BookPageControlsInitBase> = Overwrite<BaseBookEntry, { /** * The parent page of this page. If this page is meant to be at the top-level, set this to * `undefined`. */ parent: ParentPage; entryType: BookEntryType.Page; }> & { controls: ControlsInit; elementExamples: Record<string, BookElementExample>; useVerticalExamples: boolean; }; /** * All parameters required for rendering an element-book page. * * @category Internal */ export type BookPageExampleRenderParams<GlobalValuesType extends GlobalValues, ControlsInit extends BookPageControlsInitBase, State extends PropertyInitMapBase> = Pick<RenderParams<any, any, State, any, any, any, any, any>, 'state' | 'updateState'> & { controls: ControlsToValues<ControlsInit> & GlobalValuesType; }; /** * An individual element example for an element-book page. * * @category Internal */ export type BookElementExample<GlobalValuesType extends GlobalValues = {}, ControlsInit extends BookPageControlsInitBase = {}, State extends PropertyInitMapBase = {}> = Overwrite<BaseBookEntry, { parent: BookPage | undefined; entryType: BookEntryType.ElementExample; isVertical: boolean; /** Render the example. */ render: (renderParams: BookPageExampleRenderParams<GlobalValuesType, ControlsInit, State>) => HtmlInterpolation; } & PartialWithUndefined<{ /** * Initialize the state for this example. This is only called once, before the first render * of the example. */ state: () => State; /** Specify which events this example should intercept (so the user can see them). */ showEvents: ReadonlyArray<string | TypedEvent>; /** * Style the element example. You can even use the :host selector to style this specific * example's wrapper element! */ styles: CSSResult; }>>; /** * The properties that are necessary to initialize an element example. Missing properties will be * filled in by the parent. * * @category Internal */ export type BookElementExampleInit<GlobalValuesType extends GlobalValues, Controls extends BookPageControlsInitBase, State extends PropertyInitMapBase> = SetOptionalAndNullable<Omit<BookElementExample<GlobalValuesType, Controls, State>, 'entryType' | 'parent' | 'errors' | 'isVertical'>, 'descriptionParagraphs'>;