Function each

  • Render a CTag for each item in the provided list.

    each can work with a goold old array, or with a IConsumable. If you provide a Consumable, the list will update whenever the Consumable changes.

    Type Parameters

    • T

    Parameters

    • consumable: IConsumableOr<T[]>
    • consumer: ((val) => CTag)
        • (val): CTag
        • Parameters

          • val: T

          Returns CTag

    • Optional key: ((val) => any)
        • (val): any
        • Parameters

          • val: T

          Returns any

    Returns Node

    See

    https://github.com/nombrekeff/cardboard-js/wiki/Logic

    Example

    Static list

    const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
    div(
    each(colors, (color) =>
    button(color).addStyle('color', color)
    )
    );

    Example

    Dynamic list

     const colors = state(['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']);
    const selectedColor = state('red');
    div(
    each(colors, (color) =>
    button(color)
    .addStyle('color', color)
    .stylesIf(equalTo(selectedColor, color), { fontWeight: 'bold' });
    )
    );

Generated using TypeDoc