ComPDFKit Web SDK
    Preparing search index...

    Class StatefulButton

    A button that cycles through named states; each state has its own icon, title and click handler.

    const countButton = new instance.UI.Components.StatefulButton({
    dataElement: 'countButton',
    initialState: 'Off',
    states: {
    Off: { getContent: () => 'Off', onClick: (update) => update('On') },
    On: { getContent: () => 'On', onClick: (update) => update('Off') },
    },
    });
    const header = instance.UI.getModularHeader('default-top-header');
    header.setItems([...header.getItems(), countButton]);

    Hierarchy (View Summary)

    • Item
      • StatefulButton
    Index
    • Creates a stateful button.

      Parameters

      • props: { [x: string]: unknown }

        initialState and states (required), mount, unmount, dataElement, title.

      Returns StatefulButton

    • Replaces the inline CSS styles of the item and updates it on screen when it is already in the UI.

      Parameters

      • style: Record<string, unknown>

        CSS property names (camelCase) mapped to their values.

      Returns void

    className?: string

    Extra CSS class names added to the item's element.

    dataElement: string

    Unique name of the item; used to find, show, hide or update it later.

    disabled?: boolean

    Whether the item is disabled (rendered but not clickable).

    hidden?: boolean | string[]

    Hides the item: true always hides it; an array of screen sizes ('desktop', 'tablet', 'mobile', 'small-mobile') hides it only on those screen sizes.

    initialState: string

    Name of the state the button starts in.

    mount?: unknown

    Called when the button is added to the UI with update(stateName), which switches the state (without an argument it refreshes the content).

    states: Record<string, Record<string, unknown>>

    The states of the button, keyed by state name. Each state may define img, title, getContent(state) and onClick(update, state).

    style?: Record<string, unknown>

    Inline CSS styles applied to the item's element.

    title?: string

    Tooltip text, or a translation key that is resolved in the current language.

    type?: string

    Item type (for example 'customButton', 'toolButton', 'divider'); set by each subclass.

    unmount?: unknown

    Called when the button is removed from the UI.