PatternFly React

repository·main·Indexed 21 days ago

https://github.com/patternfly/patternfly-react

A comprehensive set of React components designed to implement the PatternFly design system. The library includes core UI components, specialized extensions such as @patternfly/react-charts and @patternfly/react-code-editor, as well as supporting packages for icons (@patternfly/react-icons), CSS-in-JS capabilities (@patternfly/react-styles), and an ESLint plugin for bundled rules.

Tokens
121.3K
Snippets
476
Records
642
Agent score
73%

What's inside patternfly-react

  1. Overview of PatternFly React packages

    main

    PatternFly React is organized into several packages categorized by their purpose:

    Core packages

    These provide the fundamental building blocks of the design system:

    • @patternfly/react-core: Core set of components.
    • @patternfly/react-table: Table components.
    • @patternfly/react-charts: Chart components.
    • @patternfly/react-icons: Icon components.
    • @patternfly/react-styles: PatternFly CSS styles.
    • @patternfly/react-tokens: PatternFly CSS variable tokens.

    Extension packages

    Additional specialized components:

    • @patternfly/react-log-viewer: Virtualized log viewer component.
    • @patternfly/react-catalog-view-extension: Catalog view extension.
    • @patternfly/react-topology: Topology components.

    Supporting packages

    • @patternfly/react-docs: Gatsby documentation site for components.
    • @patternfly/react-integration: Cypress integration tests.

    Deprecated packages

    • @patternfly/react-virtualized-extension: Table and list row virtualization extension.
  2. Navigation Demo Variations

    main

    PatternFly React provides several navigation patterns to suit different UI requirements. The following variations are available as demos:

    • Default nav: Standard navigation structure.
    • Grouped nav: Navigation items organized into logical groups.
    • Expandable nav: Navigation that can be expanded or collapsed.
    • Horizontal nav: Navigation items arranged horizontally.
    • Horizontal subnav: Horizontal navigation with a secondary sub-navigation layer.
    • Horizontal nav with horizontal subnav: Complex horizontal navigation with nested horizontal sub-navigation.
    • Manual nav: Custom navigation implementation.
    • Flyout nav: Navigation that appears as a flyout menu.
    • Drilldown nav: Navigation that uses a drilldown pattern to move through hierarchical levels.
    • Docked nav: Space-saving sidebar navigation (see detailed guide).
  3. What is Open UI Automation (OUIA)?

    main

    Open UI Automation (OUIA) is a specification designed to ease the creation and maintenance of automated testing environments. It standardizes specific HTML attributes and web page behaviors to provide trivial and unambiguous locators for elements in the DOM.

    Unlike ARIA (which focuses on accessibility) or id (which may be reserved by framework logic), OUIA attributes provide a framework-independent contract between developers and testers specifically for UI automation.

  4. Use the ActionList component

    main

    The ActionList component is used to display a list of actions. It is composed of three main parts:

    • ActionList: The main container.
    • ActionListGroup: A grouping mechanism for related actions.
    • ActionListItem: An individual action within the list.

    The CSS prefix for this component is pf-v6-c-action-list.

    import { ActionList, ActionListGroup, ActionListItem } from '@patternfly/react-core';
  5. Use ChartTooltip in PatternFly React charts

    main

    The ChartTooltip component is part of the @patternfly/react-charts/victory package. It is built on top of the Victory chart library and provides PatternFly-consistent styling and behavior for displaying data information on hover or interaction.

    Because ChartTooltip is a pass-through for Victory components, you should refer to the VictoryTooltip documentation for the full list of available props. Common usage patterns include:

    • Voronoi Containers: Using ChartVoronoiContainer to detect mouse proximity for displaying tooltips.
    • Combined Containers: Combining ChartCursor and ChartVoronoiContainer to show both a vertical cursor line and a tooltip simultaneously.
    • Custom Content: Embedding HTML, legends, or custom font sizes within the tooltip.
    • Data Labels: Using data labels as an alternative to hover-based tooltips.
    • Fixed Positioning: Adjusting tooltip position and label radius.
    import {
      ChartTooltip,
      ChartVoronoiContainer,
      // ... other components
    } from '@patternfly/react-charts/victory';
  6. Use the ProgressStepper component

    main

    The ProgressStepper component is used to display a sequence of steps in a process. It is composed of ProgressStepper and ProgressStep components. Steps can have different visual states via the variant property, which uses default icons, or you can provide custom icons using the icon property.

    Common variants include:

    • Basic: Standard step progression.
    • Issue/Failure: Visual indicators for steps that encounter problems.
    • Compact: A mode that only displays the current step's title and hides all description texts.
    import { ProgressStepper, ProgressStep } from '@patternfly/react-core';
    
    // Example structure
    <ProgressStepper>
      <ProgressStep title="Step 1" />
      <ProgressStep title="Step 2" />
    </ProgressStepper>
  7. Use the Form component and its sub-components

    main

    The Form component is used to layout form elements. It works in conjunction with several sub-components to manage structure, labels, and validation states.

    Key components used within a Form include:

    • FormGroup: Wraps a label and a form field.
    • FormGroupLabelHelp: Provides help text for a label.
    • FormHelperText: Used to wrap helper text inside a FormGroup to ensure correct spacing.
    • FormSection: Used to group related form fields into logical sections.
    • FormFieldGroup: Provides specialized grouping for form fields.
    • ActionGroup, ActionList, ActionListGroup, ActionListItem: Used for grouping actions within a form.

    Important Note on Helper Text: When using helper text inside a FormGroup, you must wrap the HelperText component with the FormHelperText component to provide the correct additional spacing.

    import { Form, FormGroup, FormHelperText } from '@patternfly/react-core';
    
    // Example pattern for helper text spacing
    <FormGroup>
      <FormGroupLabel>Label</FormGroupLabel>
      <input />
      <FormHelperText>
        <HelperText>
          Helper text content
        </HelperText>
      </FormHelperText>
    </FormGroup>
  8. Use the Compass component for page layouts

    main

    The Compass component provides a high-level layout structure for complex applications. You can populate different areas of the page using the following props:

    • header: Content rendered at the top. Typically includes a <CompassHeader> which divides the area into three parts: brand/logo, middle navigation, and profile.
    • sidebarStart: Content rendered at the horizontal start (left side by default).
    • main: Central content area. Typically contains a <CompassMainHeader> or <CompassHero>, and <CompassContent> containing one or more <Panel> components.
    • sidebarEnd: Content rendered at the horizontal end (right side by default).
    • footer: Content rendered at the bottom of the page. Note that content in this prop fills the entire width of the screen.

    For the <CompassHero> component inside the main section, you can customize the background using:

    • backgroundSrcLight / backgroundSrcDark: For background images.
    • gradientLight / gradientDark: For background gradients.
    /* See Basic example for implementation pattern */
  9. Use the Gallery layout component

    main

    The Gallery component is a layout tool used to arrange items in a responsive grid. It is typically used in conjunction with GalleryItem components. You can control the spacing between items using gutters and manage the sizing of items by adjusting their minimum and maximum widths.

    import { Gallery, GalleryItem } from '@patternfly/react-core';
    
    // Basic usage pattern
    <Gallery>
      <GalleryItem>
        {/* Content */}
      </GalleryItem>
    </Gallery>
  10. Configure Line chart themes and groups

    main

    When working with PatternFly charts, follow these best practices for theming and grouping:

    • Top-level Theming: Apply the theme and themeColor props at the highest level component in your chart hierarchy.
    • Theming Groups: Use ChartGroup to apply theme color scales and other shared properties to multiple child components simultaneously.
    • Standalone Legends: Instead of using the legendData prop, you can use ChartLegend as a standalone component for more control.
    • Handling Data Extremes: For charts containing only single data points or zero values, manually set the domain prop to ensure the axes render correctly.