Jigsaw Web Components Library

repository·master·Indexed 19 days ago

https://github.com/rdkmaster/jigsaw

A comprehensive Web components library for desktop (@rdkmaster/jigsaw) and mobile (@rdkmaster/jigsaw-mobile) applications. It provides a wide array of UI components, containers, services, and directives, featuring the ability to support multiple UX specifications simultaneously within a single project. The library utilizes a two-level combination system for both standard arrangement and advanced customization of UI elements.

Tokens
71.2K
Snippets
163
Records
456
Agent score
66%

What's inside Jigsaw

  1. Overview of Jigsaw packages

    master

    Jigsaw is a comprehensive Web component suite designed to cover most aspects of Web application development. It is available in different versions depending on your target platform:

    • Desktop version: @rdkmaster/jigsaw
    • Mobile version: @rdkmaster/jigsaw-mobile
    • Icon library: @rdkmaster/icon-font

    The suite includes a wide array of building blocks: 56 components, 7 containers, 7 services, and 9 directives.

  2. Introduction to Jigsaw

    master

    Jigsaw is a component set implemented based on Angular (version 4+). It is the next-generation component suite for RDK (ZTE Big Data Application Support Component). The primary design goal of Jigsaw is to facilitate the construction of complex, interaction-intensive web pages.

    Before using Jigsaw, it is highly recommended to have a foundational understanding of Angular by reviewing the Angular Hero Guide.

  3. Identify the correct Jigsaw package for your platform

    master

    Jigsaw provides specialized packages depending on whether you are developing for desktop or mobile environments:

    • Desktop applications: Use @rdkmaster/jigsaw.
    • Mobile applications: Use @rdkmaster/jigsaw-mobile.
    • Icons: Use @rdkmaster/icon-font for font-based icons.

    Jigsaw is a comprehensive Web components set designed to cover most aspects of Web application development, including components, containers, services, and directives.

    npm install @rdkmaster/jigsaw # For desktop
    npm install @rdkmaster/jigsaw-mobile # For mobile
  4. Customize component content using slots and directives

    master

    Jigsaw components support customization by allowing you to inject custom content into specific parts of a component using specialized directives. For example, a jigsaw-dialog can be customized by providing content for the header, body, and footer using the following directives:

    • jigsaw-title: For the dialog header.
    • jigsaw-body: For the main content area.
    • jigsaw-button-bar: For the footer/action area.

    This pattern is also used in components like collapse and tab to configure their internal content.

    <jigsaw-dialog width="800px" (close)="onAnswer()">
        <!-- header -->
        <div jigsaw-title>
            <span class="fa fa-thumbs-up"></span>Title of the dialog
        </div>
        <!-- content -->
        <div jigsaw-body>
            <ul class="dialog-content">
                <li>Dialog content...</li>
            </ul>
         </div>
        <!-- footer -->
        <div jigsaw-button-bar>
            <jigsaw-button colorType="primary" (click)="onAnswer('OK')">OK</jigsaw-button>
            <jigsaw-button (click)="onAnswer('Cancel')">Cancel</jigsaw-button>
        </div>
    </jigsaw-dialog>
  5. Improve Angular performance using NgZone

    master

    You can significantly improve Angular application performance by running high-frequency or non-essential code outside of the Angular Zone. This prevents Angular from triggering unnecessary change detection cycles every time an asynchronous task (like mousemove, scroll, or setTimeout) completes.

    Core Concept: NgZone

    Angular uses NgZone to wrap asynchronous APIs (XHR, setTimeout, user events). When an asynchronous task finishes, NgZone notifies Angular to run change detection. For high-frequency events like mousemove, this can lead to excessive CPU usage and dropped frames if the application has many components or complex templates.

    Key Methods

    • NgZone.runOutsideAngular(callback): Executes the provided callback function outside of Angular's zone. Change detection will not be triggered when tasks inside this callback complete.
    • NgZone.run(callback): Executes the provided callback function inside the Angular zone, ensuring that change detection is triggered once the callback finishes. This is useful for synchronizing the application state with the UI after a period of running outside the zone.
    // Concept overview
    // 1. Use runOutsideAngular for high-frequency events to avoid change detection.
    // 2. Use run to bring execution back into the zone to sync state and trigger change detection.
  6. Why Angular uses compilation for performance

    master

    Angular uses compilation to transform component templates into highly optimized JavaScript classes. This approach provides several benefits over the dynamic rendering used in older frameworks like AngularJS 1.x:

    1. JS VM Optimization: By generating specific code for change detection and rendering, Angular allows the JavaScript Virtual Machine to use efficient property access and inline caches. This is significantly faster than the generic, dynamic 'dirty checking' used in AngularJS 1.x.
    2. Decoupling from Renderers: Compiling templates into JS classes decouples the component logic from the rendering engine. This allows the same compiled component to be rendered on different platforms (e.g., a web browser or NativeScript) by simply using a different renderer.
    3. Reduced Payload/Execution: With AoT, the browser does not need to download the Angular compiler or spend CPU cycles compiling templates, leading to faster startup times and better battery/data efficiency.
  7. Understand Drag and Drop concepts in Jigsaw

    master

    Jigsaw implements HTML5 drag and drop functionality using two primary roles:

    1. Drag Target (draggable element): The element being moved.
    2. Drop Target (droppable element): The element where the dragged item is placed.

    To make an element draggable in a standard HTML context, the attribute draggable="true" must be present.

  8. Optimize Fish Bone rendering with ChartIcon

    master
    If you are using ChartIcon within the Fish Bone component, note that the graphical rendering is independent of the Fish Bone logic. If only the icon/graph data has changed (and not the underlying tree structure), you do not need to refresh the entire Fish Bone component. Instead, follow the standard ChartIcon refresh method to update only the graphics.
  9. Use j-box for complex horizontal and vertical layouts

    master

    The j-box layout component is designed for both horizontal and vertical element alignment. While horizontal layout functions similarly to the Bootstrap grid system, j-box uniquely supports vertical layouts and nested combinations of both directions.

    When to use j-box:

    • Use j-box for complex views that require simultaneous horizontal and vertical layouts.
    • Use standard CSS or grid systems for simple, horizontal-only layouts to keep the application lightweight.
    • j-box and grid systems can be nested together seamlessly.
  10. Key advantage: Support for multiple UX specifications

    master
    A unique capability of Jigsaw is that an application can be developed once and simultaneously support multiple UX (User Experience) specifications. This allows developers to target different design standards or platform-specific looks without rewriting the core application logic.
  11. How to use j-box for complex layouts

    master

    The j-box layout engine is designed for complex layouts that require both horizontal and vertical alignment. While horizontal layout functions similarly to the Bootstrap grid system (supporting various arrangements and alignments), j-box extends this capability by supporting vertical layouts and nested layouts (e.g., a vertical layout containing horizontal layouts, or vice versa).

    Key Properties

    • direction: Determines if child j-box elements are arranged horizontally or vertically.
      • Default: Horizontal.
      • Vertical: Set direction="vertical" or use the shorthand direction="v".
    • grow: Controls the width or height ratio of child j-box elements based on the direction.
      • Default: 1 (elements are distributed equally, e.g., 1:1).
      • Custom Ratios: To achieve a 1:2 ratio, set the first child's grow to 1 and the second child's grow to 2.
      • Precision: Supports decimal values for more precise proportional control.

    Handling Content Overflow

    j-box automatically generates scrollbars when content overflows. To avoid layout issues, it is recommended to use relative global positioning for elements inside a j-box or ensure the j-box dimensions are sufficiently large.