gradum-kit - v0.1.0
    Preparing search index...

    Class GradumContentSwitch<ValueType, SecondaryValueType, EntryType, ViewType, DataType, ModelType, EmitterType>

    GradumContentSwitch

    Shows one entry at a time and animates the swap when the selection changes. Registered as <gradum-content-switch>. Selection works as on any GradumSelectElement; this adds the transition between the outgoing and incoming entry, configured through GradumContentSwitch.mode.

    Type Parameters

    • ValueType = string

      The type of the value held by each entry.

    • SecondaryValueType = string

      The type of each entry's secondary value.

    • EntryType extends HTMLElement = HTMLElement

      The type of the entry elements.

    • ViewType extends GradumView = GradumView<any, any>

      The element's view type, if initializing MVC.

    • DataType extends object = object

      The element's data type, if initializing MVC.

    • ModelType extends GradumModel<DataType> = GradumModel

      The element's model type, if initializing MVC.

    • EmitterType extends GradumEmitter = GradumEmitter

      The element's emitter type, if initializing MVC.

    Hierarchy (View Summary)

    Index
    _sizeTransitionTimeout: Timeout

    The pending timer that clears the container's fixed size once the resize animation ends.

    The selection logic backing this element. It owns the entries and their selected state; this element renders them.

    entriesTag:
        | "symbol"
        | "animate"
        | "animateMotion"
        | "animateTransform"
        | "circle"
        | "clipPath"
        | "defs"
        | "desc"
        | "ellipse"
        | "feBlend"
        | "feColorMatrix"
        | "feComponentTransfer"
        | "feComposite"
        | "feConvolveMatrix"
        | "feDiffuseLighting"
        | "feDisplacementMap"
        | "feDistantLight"
        | "feDropShadow"
        | "feFlood"
        | "feFuncA"
        | "feFuncB"
        | "feFuncG"
        | "feFuncR"
        | "feGaussianBlur"
        | "feImage"
        | "feMerge"
        | "feMergeNode"
        | "feMorphology"
        | "feOffset"
        | "fePointLight"
        | "feSpecularLighting"
        | "feSpotLight"
        | "feTile"
        | "feTurbulence"
        | "filter"
        | "foreignObject"
        | "g"
        | "image"
        | "line"
        | "linearGradient"
        | "marker"
        | "mask"
        | "metadata"
        | "mpath"
        | "path"
        | "pattern"
        | "polygon"
        | "polyline"
        | "radialGradient"
        | "rect"
        | "set"
        | "stop"
        | "svg"
        | "switch"
        | "text"
        | "textPath"
        | "tspan"
        | "use"
        | "view"
        | (keyof HTMLElementTagNameMap)
        | (keyof MathMLElementTagNameMap)
        | (keyof GradumElementTagNameMap)

    The tag used to build entries from plain values.

    values: ValueType[]
    entriesClasses: string | string[]
    selectedEntriesClasses: string | string[]
    defaultProperties: { transitionDuration: number } = ...

    Default properties assigned to a new content switch. Entries cross over 0.3 seconds.

    properties: GradumContentSwitchProperties<
        ViewType,
        DataType,
        ModelType,
        EmitterType,
    >
    onAttach: Delegate<() => void> = ...

    Delegate fired when the element is attached to DOM.

    onDetach: Delegate<() => void> = ...

    Delegate fired when the element is detached from the DOM.

    onAdopt: Delegate<() => void> = ...

    Delegate fired when the element is adopted by a new parent in the DOM.

    tagName: string
    initialized: boolean

    Whether the element was initialized already or not.

    defaultFeedforwardProperties: GradumElementProperties

    The properties passed on to children created through feedforward, letting a parent seed its descendants with shared defaults.

    view: ViewType

    The view (if any) of the element.

    model: ModelType

    The model (if any) of the element.

    emitter: GradumEmitter

    The emitter (if any) of the element.

    data: DataType

    The main data block (if any) attached to the element, taken from its model (if any).

    dataId: string

    The ID of the main data block (if any) of the element, taken from its model (if any).

    dataIndex: number

    The numerical index of the main data block (if any) of the element, taken from its model (if any).

    dataSize: number

    The size (number) of the main data block (if any) of the element, taken from its model (if any).

    operators: GradumOperator<
        object,
        GradumView<
            any,
            any,
            GradumEmitter<GradumModel<any, any, any, any, any>, KeyType>,
        >,
        GradumModel<any, any, any, any, any>,
        GradumEmitter<GradumModel<any, any, any, any, any>, KeyType>,
    >[]

    The operators (if any) attached to the element's MVC structure.

    handlers: GradumHandler<GradumModel<any, any, any, any, any>>[]

    The handlers (if any) attached to the element's model. Returns an empty array if no model is set.

    interactors: GradumInteractor<
        object,
        GradumView<
            any,
            any,
            GradumEmitter<GradumModel<any, any, any, any, any>, KeyType>,
        >,
        GradumModel<any, any, any, any, any>,
        GradumEmitter<GradumModel<any, any, any, any, any>, KeyType>,
    >[]

    The interactors (if any) attached to the element's MVC structure.

    tools: GradumTool<
        object,
        GradumView<
            any,
            any,
            GradumEmitter<GradumModel<any, any, any, any, any>, KeyType>,
        >,
        GradumModel<any, any, any, any, any>,
        GradumEmitter<GradumModel<any, any, any, any, any>, KeyType>,
    >[]

    The tools (if any) attached to the element's MVC structure.

    constrainers: GradumConstrainer<
        object,
        GradumView<
            any,
            any,
            GradumEmitter<GradumModel<any, any, any, any, any>, KeyType>,
        >,
        GradumModel<any, any, any, any, any>,
        GradumEmitter<GradumModel<any, any, any, any, any>, KeyType>,
    >[]

    The constrainers (if any) attached to the element's MVC structure.

    unsetDefaultClasses: boolean

    Whether to set the default CSS classes defined in the static config on the element or not. Setting it will accordingly add/remove the CSS classes from the element.

    shadowDOM: boolean

    Whether the element renders its children into a shadow root. Assigning true attaches one if the element does not already have it.

    defaultClasses: string | string[]

    The CSS classes applied to every instance of this element class. Assigning a new value swaps the previous classes out for the new ones, unless unsetDefaultClasses is set.

    • get entries(): EntryType[]

      Returns EntryType[]

      The element's entries, in order. Assigning a new list replaces them all.

    • set entries(value: NodeList | HTMLCollection | EntryType[]): void

      Parameters

      Returns void

    selectedEntries: EntryType[]
    selectedEntry: EntryType
    selectedIndex: number
    selectedIndices: number[]
    inputName: string
    inputField: HTMLInputElement
    multiSelection: boolean
    forceSelection: boolean
    enabledEntries: EntryType[]
    enabledValues: ValueType[]
    enabledSecondaryValues: SecondaryValueType[]
    selectedValue: ValueType
    selectedValues: ValueType[]
    selectedSecondaryValues: SecondaryValueType[]
    selectedSecondaryValue: SecondaryValueType
    stringSelectedValue: string
    • get transitionReifect(): Reifect

      Returns Reifect

    • set transitionReifect(value: Reifect<Node> | StatelessReifectProperties): void

      Returns void

    • set mode(value: ContentSwitchMode): void

      Parameters

      Returns void

      The transition played when the selected entry changes. Assigning a new mode rebuilds the movement reifect, so the next switch uses it. Defaults to ContentSwitchMode.fadeRight.

    • get entryTransitionReifect(): Reifect

      Returns Reifect

    • set entryTransitionReifect(
          value: Reifect<Node> | StatelessReifectProperties,
      ): void

      Returns void

      The reifect controlling how each entry itself fades. Assigning a properties object builds a Reifect from it, and the result is attached to every current entry.

    • set transitionDuration(value: number): void

      Parameters

      • value: number

      Returns void

      How long the entry transition lasts, in seconds. Assigning a value rewrites the entry reifect's CSS transition, creating that reifect if it does not exist yet. Values of 0 or less are ignored. Defaults to 0.3.

    • Returns void

      Animates the container from its current size to the selected entry's natural size. Subclasses should call super.applyTransition() then add their own entry-level logic. The sequence:

      1. Freeze container at current px size (gives CSS transition a from value)
      2. Call beforeResize() — subclass hook to prepare entries before the frame
      3. Next frame: read selected entry's natural size, animate container to it
      4. After transitionDurationms: release explicit container size
    • Parameters

      • selectedEntry: EntryType

        The entry that is now selected.

      Returns void

      Called after the container size transition completes.

    • Function

      initialize

      Returns void

      Set the element up and select its initial entry.

    • Parameters

      Returns void

    • Parameters

      • selectedEntry: EntryType

        The newly selected entry.

      Returns void

      Called synchronously inside applyTransition, before the rAF that reads the selected entry's new size. Use this to reposition/reflow entries so the size read is correct.

    • Function

      create

      Type Parameters

      Parameters

      • this: This
      • Optionalproperties: This["prototype"]["properties"] & ElementTagDefinition<"div"> & Omit<
            HTMLElementMutableFields<"div">,
            "tag" | "namespace",
        > & {
            id?: string;
            classes?: string | string[];
            style?: string;
            stylesheet?: string;
            shadowDOM?: boolean;
            parent?: Element;
            children?: Element | Element[];
            text?: string;
            listeners?: Record<
                string,
                (e: Event, el: ValidElement<Tag>) => boolean | any,
            >;
            onClick?: (e: Event, el: HTMLDivElement) => any;
            onDrag?: (e: Event, el: HTMLDivElement) => any;
            out?: string | Node;
            [key: string]: any;
        } & MvcProperties<ViewType, ModelType, EmitterType> & {
            data?: DataType;
            initialize?: boolean;
        } & { out?: string
        | Node; [key: string]: any } & {
            unsetDefaultClasses?: boolean;
            shadowDOM?: boolean;
            defaultSelectedClasses?: string | string[];
            defaultClasses?: string | string[];
        }

        Properties to set on the new instance.

      Returns This["prototype"] & GradumElement<ViewType, DataType, ModelType, EmitterType>

      The created instance, typed as the class this was called on.

      Instantiate this class with the given properties. Defaults declared by every class in the inheritance chain are applied first, nearest ancestor last, so a subclass' defaultProperties win over its parent's. The return type follows the class it is called on, and the MVC type parameters are read back off the properties — passing model: MyModel types .model as MyModel without a cast.

      Note: the callee is read through this["prototype"] rather than InstanceType<this>, because the latter instantiates a generic class' parameters with their constraints instead of their defaults, which is what forced casts at call sites.

    • Protected Function

      Parameters

      • properties: object

        Properties to set on the new instance, defaults already merged in.

      Returns object

      The created instance.

      customCreate

      The construction step behind create. Override it to change how instances of a class are built — to route through a factory, or to wrap the instance — while keeping the default-merging that create performs.

    • Protected Function

      setupChangedCallbacks

      Returns void

      Setup method intended to initialize change listeners and callbacks. Called on initialize().

    • Protected Function

      setupUIElements

      Returns void

      Setup method intended to initialize all direct sub-elements attached to this element, and store them in fields. Called on initialize().

    • Protected Function

      setupUILayout

      Returns void

      Setup method to create the layout structure of the element by adding all created sub-elements to this element's child tree. Called on initialize().

    • Protected Function

      setupUIListeners

      Returns void

      Setup method to initialize and define all input/DOM event listeners of the element. Called on initialize().

    • Function

      connectedCallback

      Returns void

      function called when the element is attached to the DOM.

    • Function

      disconnectedCallback

      Returns void

      function called when the element is detached from the DOM.

    • Function

      adoptedCallback

      Returns void

      function called when the element is adopted by a new parent in the DOM.

    • Function

      destroy

      Returns this

      Itself, allowing for method chaining.

      Destroys the node by removing it from the document and removing all its bound listeners.

    • Function

      feedforward

      Parameters

      • Optionalproperties: FeedforwardProperties

        Properties to feed forward. Defaults to defaultFeedforwardProperties.

      Returns this

      Itself, allowing for method chaining.

      Push this element's feedforward properties down to its children, so newly added descendants pick up the same defaults.

    • Function

      clone

      Parameters

      Returns this

      The cloned element.

      Create a copy of this element. By default the copy carries the same properties and children but none of the bound listeners.