CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-patternfly--react-table

React table components for PatternFly design system with sorting, selection, expansion, and editing capabilities

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

utilities.mddocs/

Table Utilities

Utility functions, decorators, and transformers for customizing table behavior and appearance. These utilities enable advanced table functionality through composable transforms and formatters.

Capabilities

Decorators

Functions that add interactive behaviors and styling to table cells and headers.

/**
 * Makes table rows selectable with checkboxes
 * @param onSelect - Selection change handler
 * @param selectableRowCaptionText - Screen reader text for row selection
 * @param hideCheckbox - Whether to hide checkbox column
 * @param isHeaderSelectDisabled - Whether header select is disabled
 * @param canSelectAll - Whether "select all" functionality is enabled
 * @returns Cell decorator for selection functionality
 */
function selectable(
  onSelect: OnSelect,
  selectableRowCaptionText?: string,
  hideCheckbox?: boolean,
  isHeaderSelectDisabled?: boolean,
  canSelectAll?: boolean
): ITransform;

/**
 * Makes table headers sortable with click handlers and sort indicators
 * @param onSort - Sort change handler
 * @param options - Sort configuration options
 * @returns Header decorator for sorting functionality
 */
function sortable(onSort: OnSort, options?: ISortBy): ITransform;

/**
 * Adds action buttons/dropdown to table cells
 * @param actions - Array of actions or action resolver function
 * @param areActionsDisabled - Function to determine if actions are disabled
 * @param actionsToggle - Custom toggle component for actions dropdown
 * @returns Cell decorator for action functionality
 */
function cellActions(
  actions: IActions | IActionsResolver,
  areActionsDisabled?: IAreActionsDisabled,
  actionsToggle?: React.ComponentType<CustomActionsToggleProps>
): ITransform;

/**
 * Makes table rows collapsible/expandable
 * @param onCollapse - Collapse toggle handler
 * @returns Row decorator for collapse functionality
 */
function collapsible(onCollapse: OnCollapse): ITransform;

/**
 * Adds expanded row content below collapsed rows
 * @param expandedRowContent - Content to display when row is expanded
 * @returns Row decorator for expanded content
 */
function expandedRow(expandedRowContent: React.ReactNode): ITransform;

/**
 * Makes table cells editable inline
 * @param onRowEdit - Edit action handler
 * @param validationErrors - Validation error configuration
 * @returns Cell decorator for inline editing
 */
function editable(onRowEdit?: OnRowEdit, validationErrors?: any): ITransform;

/**
 * Adds favorite/unfavorite functionality to table rows
 * @param onFavorite - Favorite toggle handler
 * @returns Row decorator for favorites functionality
 */
function favoritable(onFavorite: OnFavorite): ITransform;

/**
 * Makes favorites column sortable with custom favorite sort logic
 * @param onSort - Sort change handler
 * @param options - Sort configuration options
 * @returns Header decorator for sortable favorites
 */
function sortableFavorites(onSort: OnSort, options?: ISortBy): ITransform;

/**
 * Enables tree table row functionality with indentation and expand/collapse
 * @param onCollapse - Tree row collapse handler
 * @param leftOffset - Left indentation offset
 * @param icon - Custom expand/collapse icon
 * @returns Row decorator for tree functionality
 */
function treeRow(
  onCollapse?: OnTreeRowCollapse,
  leftOffset?: number,
  icon?: React.ReactNode
): ITransform;

/**
 * Enables compound expand functionality for nested table content
 * @param onExpand - Compound expand handler
 * @returns Cell decorator for compound expansion
 */
function compoundExpand(onExpand: OnExpand): ITransform;

/**
 * Adds info popover/tooltip functionality to header cells
 * @param infoContent - Content to display in info popover
 * @param ariaLabel - Accessibility label for info trigger
 * @param popoverProps - Additional popover configuration
 * @returns Header decorator for info functionality
 */
function info(
  infoContent: React.ReactNode,
  ariaLabel?: string,
  popoverProps?: any
): ITransform;

/**
 * Sets column as header column with proper scope attributes
 * @returns Header decorator for column headers
 */
function headerCol(): ITransform;

Text Formatting Decorators

Functions that control text wrapping and layout behavior in table cells.

/**
 * Allows text to wrap normally within table cells
 * @returns Cell decorator for text wrapping
 */
function wrappable(): ITransform;

/**
 * Forces text to break at word boundaries when needed
 * @returns Cell decorator for word breaking
 */
function breakWord(): ITransform;

/**
 * Sizes cell content to fit available space
 * @returns Cell decorator for fit content sizing  
 */
function fitContent(): ITransform;

/**
 * Prevents text from wrapping in table cells
 * @returns Cell decorator for no-wrap text
 */
function nowrap(): ITransform;

/**
 * Truncates overflowing text with ellipsis
 * @returns Cell decorator for text truncation
 */
function truncate(): ITransform;

/**
 * Centers text horizontally within table cells
 * @returns Cell decorator for center text alignment
 */
function textCenter(): ITransform;

Cell Width Decorators

Functions for controlling column width behavior.

/**
 * Sets specific width percentage for table columns
 * @param width - Width percentage (10-100)
 * @returns Cell decorator for width control
 */
function cellWidth(width: 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 60 | 70 | 80 | 90 | 100): ITransform;

Visibility Decorators

Functions for responsive visibility control.

/**
 * Controls cell visibility at different responsive breakpoints
 * @param visibility - Array of breakpoint visibility settings
 * @returns Cell decorator for responsive visibility
 */
function classNames(visibility: (keyof IVisibility)[]): ITransform;

/**
 * Visibility breakpoint enumeration for responsive table behavior
 */
enum Visibility {
  hidden = 'hidden',
  hiddenOnSm = 'hiddenOnSm',
  hiddenOnMd = 'hiddenOnMd',
  hiddenOnLg = 'hiddenOnLg',
  hiddenOnXl = 'hiddenOnXl',
  hiddenOn2Xl = 'hiddenOn2Xl',
  visibleOnSm = 'visibleOnSm',
  visibleOnMd = 'visibleOnMd',
  visibleOnLg = 'visibleOnLg',
  visibleOnXl = 'visibleOnXl',
  visibleOn2Xl = 'visibleOn2Xl'
}

Transformers

Low-level functions for manipulating table cell and row properties.

/**
 * Creates empty table data cell
 * @returns Transform for empty TD element
 */
function emptyTD(): ITransform;

/**
 * Adds column scope to table headers
 * @returns Transform for column scope attribute
 */
function scopeColTransformer(): ITransform;

/**
 * Creates empty column header with conditional scope
 * @param label - Column label for scope determination
 * @returns Transform for empty column configuration
 */
function emptyCol(label?: IFormatterValueType): ITransform;

/**
 * Maps parent row ID for hierarchical table structures
 * @param value - Cell value
 * @param extra - Extra data containing row information
 * @returns Transform with parent ID property
 */
function parentId(value?: IFormatterValueType, extra?: IExtra): ITransform;

/**
 * Maps row data properties to cell props
 * @param label - Cell label
 * @param extra - Extra data containing property and row data
 * @returns Transform with mapped properties
 */
function mapProps(label?: IFormatterValueType, extra?: IExtra): ITransform;

Formatters

Functions for formatting and displaying table cell content.

/**
 * Default formatter that extracts title property or returns data as-is
 * @param data - Cell data to format
 * @returns Formatted cell content
 */
function defaultTitle(data?: IFormatterValueType): any;

Header Utilities

Functions for generating and configuring table headers with transforms and formatters.

/**
 * Generate header configuration with transforms and formatters
 * @param header - Header object with transforms, formatters, and column transforms
 * @param title - Header title/label
 * @param transforms - Array of transform functions to apply
 * @param formatters - Array of formatter functions to apply
 * @param cellTransforms - Cell-specific transform functions
 * @returns Complete header configuration object
 */
function generateHeader(
  header: any,
  title: React.ReactNode,
  transforms?: ITransform[],
  formatters?: IFormatter[],
  cellTransforms?: ITransform[]
): ICell;

/**
 * Build table headers from column definitions
 * @param columns - Array of column definitions
 * @param sortBy - Current sort configuration
 * @param onSort - Sort change handler
 * @param onSelect - Selection change handler
 * @param canSelectAll - Whether select all is enabled
 * @param selectableRowCaptionText - Screen reader text for selection
 * @returns Array of configured header objects
 */
function buildHeaders(
  columns: IColumn[],
  sortBy?: ISortBy,
  onSort?: OnSort,
  onSelect?: OnSelect,
  canSelectAll?: boolean,
  selectableRowCaptionText?: string
): ICell[];

/**
 * Build table rows from data with applied transforms and formatters
 * @param data - Array of row data
 * @param columns - Column configuration
 * @param actions - Row actions configuration
 * @param areActionsDisabled - Function to check if actions are disabled
 * @param onSelect - Selection handler
 * @param onCollapse - Collapse handler
 * @param onRowEdit - Edit handler
 * @param onFavorite - Favorite handler
 * @returns Array of configured row objects
 */
function buildRows(
  data: any[],
  columns: IColumn[],
  actions?: IActions | IActionsResolver,
  areActionsDisabled?: IAreActionsDisabled,
  onSelect?: OnSelect,
  onCollapse?: OnCollapse,
  onRowEdit?: OnRowEdit,
  onFavorite?: OnFavorite
): IRow[];

Types

// Transform function signature
interface ITransform {
  (label?: IFormatterValueType, extra?: IExtra): decoratorReturnType;
}

// Formatter function signature
interface IFormatter {
  (data?: IFormatterValueType, extra?: IExtra): formatterValueType & decoratorReturnType;
}

// Decorator return type with additional properties
interface decoratorReturnType {
  component?: React.ComponentType<any>;
  className?: string;
  isVisible?: boolean;
  scope?: string;
  parentId?: string | number;
  [key: string]: any;
}

// Visibility configuration interface
interface IVisibility {
  hidden: string;
  hiddenOnSm: string;
  hiddenOnMd: string;
  hiddenOnLg: string;
  hiddenOnXl: string;
  hiddenOn2Xl: string;
  visibleOnSm: string;
  visibleOnMd: string;
  visibleOnLg: string;
  visibleOnXl: string;
  visibleOn2Xl: string;
}

// Column configuration interface
interface IColumn {
  title: React.ReactNode;
  transforms?: ITransform[];
  formatters?: IFormatter[];
  cellTransforms?: ITransform[];
  cellFormatters?: IFormatter[];
  props?: any;
}

// Extra data passed to transforms and formatters
interface IExtra extends IExtraColumnData, IExtraRowData {
  rowIndex?: number;
  columnIndex?: number;
  property?: string;
}

interface IExtraColumnData {
  column?: IColumn;
  columnIndex?: number;
}

interface IExtraRowData {
  rowIndex?: number;
  rowData?: IRowData;
}

Usage Examples:

import { 
  selectable,
  sortable,
  cellActions,
  collapsible,
  wrappable,
  cellWidth,
  textCenter,
  defaultTitle
} from "@patternfly/react-table";

// Create sortable, selectable table with actions
const columns = [
  {
    title: 'Name',
    transforms: [sortable(onSort), cellWidth(30)],
    formatters: [defaultTitle]
  },
  {
    title: 'Status', 
    transforms: [textCenter, cellWidth(20)]
  },
  {
    title: 'Actions',
    transforms: [cellActions(actions), cellWidth(20)]
  }
];

// Apply row-level transforms
const rows = data.map(rowData => ({
  cells: [rowData.name, rowData.status, ''],
  transforms: [
    selectable(onSelect),
    collapsible(onCollapse)
  ]
}));

Install with Tessl CLI

npx tessl i tessl/npm-patternfly--react-table

docs

content-display.md

core-components.md

editing.md

index.md

interactive-features.md

layout-scrolling.md

utilities.md

tile.json