Ring UI

repository·master·Indexed 26 days ago

https://github.com/jetbrains/ring-ui

A collection of web UI components designed by JetBrains to provide building blocks for web-based products and third-party plugins within the JetBrains ecosystem. The library includes design tokens for Light and Dark themes, a Rollup CSS plugin for style integration, and a high-performance Table component supporting virtualization, row expansion, and custom focus models.

Tokens
7.9K
Snippets
8
Records
66
Agent score
86%

What's inside @jetbrains/ring-ui

  1. Overview of the new Table component

    master
    The new Table component is a replacement for all legacy table components in Ring UI. It is designed to provide a rich feature set and high customization for complex use cases like row selection, sorting, column reordering, row expansion, and row reordering. It is optimized for performance and supports virtualization for thousands of rows.
  2. Run the Ring UI test app

    master

    To run the test application used for verifying the built Ring UI components, follow these steps in order:

    1. Build the Ring UI library from the repository root: npm run build in the Ring UI root directory.
    2. Install dependencies for the test app: npm run install within the test-app subdirectory.
    3. Start the test application: npm run start within the test-app subdirectory.
  3. Access early access versions of the new Table component

    master
    The new Table component is being developed in the develop-8.0 branch. Clients can access early access versions (e.g., 8.0.0-beta.x) via the TeamCity Publish@next configuration. These versions are published periodically from the develop-8.0 branch or its child branches to allow for testing and feedback during the beta phase.
  4. Configure Column Controls and Discoverability

    master

    The Table component supports configurable column interactions:

    • Desktop: Drag-and-drop handles for column reordering are shown on hover.
    • Mobile: A gear button in the top-right corner can be configured to reveal drag-and-drop handles. Column reordering is also available without the gear button.
    • Configuration: The visibility of the gear button is configurable.
  5. Use the DatePicker component

    master

    The DatePicker component allows users to select a single date, a date and time, or a date range.

    Single Date Mode

    Use date to set the current value and onChange to handle selection.

    Date and Time Mode

    Enable time selection by setting the withTime prop to true. You can customize how time is applied using applyTimeInput.

    Range Selection Mode

    Enable range selection by setting the range prop to true. In this mode, use from and to props instead of date.

    Constraints and Customization

    • Limits: Use minDate and maxDate to restrict the selectable range.
    • Appearance: Use inline to render the trigger as a link instead of a button. Use size to adjust the horizontal size of the trigger.
    • Placeholders: Customize text using datePlaceholder, dateTimePlaceholder, or rangePlaceholder.
  6. Migrate from Legacy Tables

    master

    The existing table components are being moved to a legacy namespace. To continue using them, update your import paths:

    Old path: @jetbrains/ring-ui-built/components/table/...
    New path: @jetbrains/ring-ui-built/components/legacy-table/...

    Additionally, the table/selection.ts utility has been moved to global/table-selection.ts.

  7. Implement Row Selection with TableSelection utility

    master

    To implement row selection (via checkbox or row click), use the TableSelection utility to manage state. When handling row clicks, use isWithinInteractiveElement to ensure clicking a button or checkbox inside a row doesn't trigger the row's selection logic.

    const [data] = useState(['Amsterdam', 'Berlin', 'Limassol', 'Prague'])
    const [selection, setSelection] = useState(() => new TableSelection<string>({data}))
    
    return (
      <Table
        data={data}
        getKey={(_, i) => i}
        columns={[
          {
            key: 'Check',
            renderCell: item => (
              <input
                type="checkbox"
                checked={selection.isSelected(item)}
                onChange={e => setSelection(
                  e.target.checked
                    ? selection.select(item)
                    : selection.deselect(item)
                )}
              />
            )
          },
          {
            key: 'City',
            renderCell: item => item,
          }
        ]}
        renderItem={(item, index, items) => (
          <DefaultItemRenderer
            index={index}
            clickable
            selected={selection.isSelected(item)}
            onClick={e => {
              if (!isWithinInteractiveElement(e.target)) {
                setSelection(selection.toggleSelection(item))
              }
            }}
          />
        )}
      />
    )
  8. Configure TableProps for the Table component

    master

    The TableProps<T> interface defines the configuration for the Table component. Key props include:

    • data: readonly T[] - The array of items to render.
    • columns: readonly Column<T>[] - The column definitions.
    • getKey: (item: T, index: number, items: readonly T[]) => React.Key - Function to provide a unique key for each item.
    • renderItem: (item: T, index: number, items: readonly T[]) => React.ReactNode - Customizes how an item is rendered. Can return DefaultItemRenderer or custom rows using TableRow and TableCell.
    • onSort: (columnIndex: number, newOrder: SortOrder, columns: readonly Column<T>[]) => void - Callback for column sorting.
    • onColumnDelete: (column: Column<T>, columnIndex: number, columns: readonly Column<T>[]) => void - Callback for deleting a column.
    • onColumnReorder: (columnBeingReordered: Column<T>, fromIndex: number, insertionIndex: number, columns: readonly Column<T>[]) => void - Callback for reordering columns.
    • onItemReorder: (itemBeingReordered: T, fromIndex: number, insertionIndex: number, items: readonly T[]) => boolean - Callback for reordering items.
    • virtualizeRows: boolean - Enables row virtualization.
    • scrollerRef: RefObject<HTMLElement | null> - Required for virtualizeRows if the scroller is not the document.
    • columnEditing: boolean | undefined - Controls column editing mode (reorder/delete buttons visibility).
  9. Use the Table component (Controlled Component)

    master
    The Table component is a controlled component, meaning it does not manage its own data, selection, sorting, or column order. The client is responsible for providing this state and registering callbacks to handle user interactions. The component also accepts native <table> props via intersection types.
  10. Configure Column definitions

    master

    The Column<T> interface defines how individual columns behave and render:

    • key: React.Key - Unique identifier for the column.
    • name: string - Used for aria-labels. Defaults to String(key).
    • renderHeader: () => React.ReactNode - Custom header content.
    • renderCell: (item: T, index: number, items: readonly T[]) => React.ReactNode - Custom cell content. Defaults to stringifying the value.
    • indent: boolean - If true, applies indentation based on the row's level.
    • sortOrder: 'none' | 'ascending' | 'descending' - The current sort state.
    • deletable: boolean - Whether a delete button is shown in the header.
    • canReorder: boolean | ((columnBeingReordered: Column<T>, fromIndex: number, insertionIndex: number, columns: readonly Column<T>[]) => boolean) - Determines if the column can be moved.
    • thClassName: string - Class name for the header cell.
    • tdClassName: string | ((item: T, index: number, items: readonly T[]) => string | undefined) - Class name for the data cell.
  11. Use DefaultItemRenderer for custom row behavior

    master

    The DefaultItemRenderer<T> is a standard component for rendering a table row. It allows you to configure item-scoped behavior like selection, keyboard navigation, and event handlers while maintaining standard table row functionality. It accepts standard <tr> props.

    Key props:

    • index: number - Index of the data item.
    • keyboardFocusable: boolean - Enables roving tabindex for arrow key navigation.
    • clickable: boolean - Applies hover background and pointer cursor.
    • selected: boolean - Shows the row as selected.
    • level: number - The nesting level (used for indentation).
    • noItemVirtualization: boolean - Disables built-in virtualization control.