ui5-webcomponents-react

repository·main·Indexed 19 days ago

https://github.com/ui5/webcomponents-react

A Fiori-compliant React implementation that wraps official UI5 Web Components, allowing developers to use SAP's design system natively within React applications. The ecosystem includes specialized packages such as @ui5/webcomponents-ai-react for AI components, @ui5/webcomponents-react-charts for charting, @ui5/webcomponents-react-cli for migrations and codemods, and @ui5/webcomponents-react-compat for backwards compatibility.

Tokens
303.9K
Snippets
647
Records
1.3K
Agent score
64%

What's inside ui5-webcomponents-react

  1. Overview of @ui5/webcomponents-react packages

    main

    The UI5 Web Components for React ecosystem consists of several specialized packages:

    • @ui5/webcomponents-react: The main package containing the React wrappers.
    • @ui5/webcomponents-react-base: The base package.
    • @ui5/webcomponents-react-charts: Charts package (deprecated).
    • @ui5/webcomponents-react-compat: Legacy components package for compatibility.
    • @ui5/webcomponents-react-cli: Package for wrapper generation and code-mods.
    • @ui5/webcomponents-ai-react: React wrapper for the @ui5/webcomponents-ai package.
    • @ui5/webcomponents-cypress-commands: Custom Cypress commands and queries.
  2. Use TimelineChart for visualizing time-based data

    main

    The TimelineChart component (available in @ui5/webcomponents-react-charts since version 1.10.0) is used to visualize sequences of events or tasks over a timeline. It supports custom item colors, labels, and various connection types between items:

    • Start-To-Start
    • Start-To-Finish
    • Finish-To-Start
    • Finish-To-Finish

    Note: This component is marked as experimental and is scheduled for removal without replacement in version 3.0 of @ui5/webcomponents-react-charts.

  3. Available Chart Components in @ui5/webcomponents-react-charts

    main

    The @ui5/webcomponents-react-charts package provides a variety of specialized chart components for data visualization. The following components are available:

    • BarChart
    • BulletChart
    • ColumnChart
    • ColumnChartWithTrend
    • ComposedChart
    • DonutChart
    • LineChart
    • PieChart
    • RadarChart
    • RadialChart
    • ScatterChart
  4. Deprecation notice for @ui5/webcomponents-react-charts

    main

    The @ui5/webcomponents-react-charts package is deprecated and will be discontinued with v3 of @ui5/webcomponents-react. It will not receive updates beyond v2 maintenance.

    Why: This package is not backed by SAP global design or accessibility specifications and does not meet the quality and governance standards of the UI5 Web Components ecosystem.

    Action required: New implementations should not depend on this package. Existing consumers should plan for migration before the v3 release.

  5. Use the ShellBar component

    main

    The ShellBar is a top-level navigation component used to provide branding, search, and global actions. It can include various subcomponents like ShellBarItem, ShellBarSpacer, and ShellBarSearch to structure the navigation bar.

    import { ShellBar, ShellBarItem } from '@ui5/webcomponents-react';
    
    const MyComponent = () => (
      <ShellBar>
        <ShellBarItem icon="add" text="add" />
      </ShellBar>
    );
  6. Understand the plugin execution order in `useTable()`

    main

    When using the useTable hook in AnalyticalTable, the order in which you pass plugins is critical because hooks accumulate properties and state through a pipeline. useTable automatically prepends useColumnVisibility to your plugin list.

    To ensure correct behavior, follow this effective execution order:

    1. Vendored react-table plugins: These should generally come first (e.g., useFilters, useGlobalFilter, useColumnOrder, useGroupBy, useSortBy, useExpanded).
    2. UI5WCR useRowSelect: This is a specialized fork that replaces the upstream react-table version.
    3. UI5WCR Internal Hooks: These provide core functionality like resizing, selection, and accessibility. They must follow the order specified in the documentation to avoid state conflicts.
    4. User-provided plugins: These should be passed LAST. Adding plugins at the beginning or middle can clobber the logic of prior hooks in the pipeline.
    useTable(
      config,
      // 1. Vendored react-table plugins
      useFilters,
      useGlobalFilter,
      useColumnOrder,
      useGroupBy,
      useSortBy,
      useExpanded,
    
      // 2. UI5WCR fork
      useRowSelect,
    
      // 3. UI5WCR internal hooks
      useColumnResizing,
      useColumnsDeps,
      useRowSelectionColumn,
      useAutoResize,
      useSingleRowStateSelection,
      useSelectionChangeCallback,
      useRowHighlight,
      useRowNavigationIndicators,
      useDynamicColumnWidths,
      useStyling,
      useToggleRowExpand,
      useA11y,
      usePopIn,
      useVisibleColumnsWidth,
      useKeyboardNavigation,
      useColumnDragAndDrop,
    
      // 4. User-provided plugins (LAST)
      ...tableHooks
    );
  7. Optimize Selection Performance in AnalyticalTable

    main

    Selection in large tables can be expensive. The AnalyticalTable uses several optimizations to maintain performance:

    Memoization and Fast Paths

    • selectedFlatRows: This is memoized using useMemo with dependencies on rows, selectSubRows, selectedRowIds, getSubRows, and isSelectionEnabled. This prevents O(n) iterations on every scroll or layout change.
    • Disabled Fast Path: When selectionMode === 'None', the table returns a stable empty array for selectedFlatRows, a noop function for toggleRowSelected, and skips isAllRowsSelected computations entirely.
    • Single-Select Optimization: For single-row selection, useSingleRowStateSelection calls toggleRowSelected directly from handlers, bypassing the state reducer.

    Selection Logic

    • Indeterminate State: The select-all indeterminate check is calculated based on visible/filtered rows only (selectedFlatRows?.length) rather than the total set of selected IDs. This prevents the checkbox from showing an indeterminate state due to rows that are selected but currently hidden by filters.
    • isAllRowsSelected: This is calculated as Object.keys(nonGroupedRowsById).every(...). While not memoized, it operates on the keys of grouped rows (O(keys)) rather than the full row set (O(n)).
  8. Understand the AnalyticalTable state reducer chain

    main

    The AnalyticalTable uses a layered reducer system to manage state. Reducers execute in a specific registration order. Understanding this order is critical when implementing custom hooks or managing state via the stateReducer option.

    Execution Order

    1. Internal Hooks (via useTable):

      • Vendored react-table reducers: useFilters, useGlobalFilter, useColumnOrder, useGroupBy, useSortBy, and useExpanded.
      • useRowSelect: Manages selection actions and selectedFlatRows (visible-only).
      • useColumnResizing: Manages column resize actions (columnStartResizing, columnResizing, columnDoneResizing, resetResize).
    2. Plugin Hooks (User-provided via tableHooks):

      • useOrderedMultiSort: Reorders sortBy by priority during toggleSortBy.
      • useIndeterminateRowSelection: Handles INDETERMINATE_ROW_IDS and auto-selects parents when all siblings are selected.
      • useF2CellEdit: Handles CELL_CONTENT_TAB_INDEX.
    3. Main Table Reducer (stateReducer):

      • This is the final layer passed as the stateReducer option in useTable. It handles UI5-specific actions like TABLE_RESIZE, SET_SELECTED_ROW_IDS, COLUMN_DND_START/END, IS_RTL, VISIBLE_ROWS, TABLE_SCROLLING_ENABLED, SET_POPIN_COLUMNS, INTERACTIVE_ROWS_HAVE_POPIN, SUB_COMPONENTS_HEIGHT, TRIGGER_PROG_SCROLL, AUTO_RESIZE, and TABLE_COL_RESIZED. It also intercepts toggleRowExpanded to dispatch rowCollapsed.
  9. MessageView subcomponents: MessageItem and MessageViewButton

    main

    The MessageView component relies on the following subcomponents:

    • MessageItem: Represents an individual message entry within the list.
    • MessageViewButton: A specialized button designed to act as an opener for a MessageView (typically within a Popover). The button's type should reflect the highest severity level of the messages contained within the view.
  10. Keyboard navigation and focus in AnalyticalTable

    main

    Focus management and keyboard interaction in the AnalyticalTable follow these rules:

    • Cell Focus: tabIndex on cells is managed imperatively via useKeyboardNavigation.setFocus and getFirstVisibleCell. It is not handled by the accessibility (useA11y) hook.
    • Popovers: Sort, filter, and group popovers use accessibleRole={ListAccessibleRole.Menu} on the inner List and accessibleRole={PopupAccessibleRole.None} on the wrapping Popover. The header cell uses aria-haspopup="menu", aria-expanded, and aria-controls.
    • Sorting Annotations: aria-sort is only applied when the column is actively sorted (e.g., "ascending" or "descending"). There is no "none" value for the unsorted state.
  11. Understand AnalyticalTable hook invocation patterns

    main

    The AnalyticalTable (via react-table) uses three distinct invocation patterns for its hooks. Understanding these is critical for correctly implementing or extending functionality:

    1. Pipeline Hooks (reduceHooks): Used for transforming data (e.g., columns, visibleColumns, stateReducers). The callback receives the previous result and MUST return the next value. Returning undefined will throw an error.
    2. Side-effect Hooks (loopHooks): Used for side effects (e.g., useInstance, useInstanceAfterData, prepareRow). The callback receives the instance and MUST NOT return a value. Returning anything will throw an error in development mode.
    3. Prop Getter Hooks: Used to generate props for UI elements (e.g., getRowProps, getCellProps). The callback receives (accumulatedProps, meta) and returns either a props object or a [props, extraProps] tuple. Props are accumulated via reduction: style is deep-merged and className is concatenated.