# PatternFly Usage Guidelines This document defines how PatternFly (PF) components, layout primitives, design tokens, and icons are used in konflux-ui. ## Core Principle **Always use PatternFly components instead of raw HTML.** Never write `
` when `` exists. Never use ` ``` ### Disabled Buttons **Never use `isDisabled` alone.** Always use `isAriaDisabled` wrapped in a `Tooltip`: ```tsx import { Tooltip } from '@patternfly/react-core'; Create ; ``` `isAriaDisabled` keeps the button focusable for accessibility (tooltips don't work on elements with `disabled`). The project has `ButtonWithAccessTooltip` for RBAC-gated buttons: ```tsx import ButtonWithAccessTooltip from '~/components/ButtonWithAccessTooltip'; Create ; ``` ## Alert Always use `isInline` inside forms and modals: ```tsx import { Alert, AlertVariant } from '@patternfly/react-core'; // Error alert in a form/modal { error && ( {error} ); } // Info alert for unsaved changes Click Save to save changes or Reload to cancel changes. ; ``` ## Modal ### Use the Modal Launcher System Never manage modal state with `useState(isOpen)` + raw ``. Use the centralized system: ```tsx import { createModalLauncher } from '~/components/modal/createModalLauncher'; import { useModalLauncher } from '~/components/modal/ModalProvider'; // 1. Create launcher const myModalLauncher = createModalLauncher(MyModalContent, { 'data-test': 'my-modal', variant: ModalVariant.small, title: 'My Modal Title', }); // 2. Use in component const showModal = useModalLauncher(); showModal(myModalLauncher({ prop1: value1 })); ``` ### When to Use Which | Scenario | Use | | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | | Simple modal where title, variant, and data-test are enough | `createModalLauncher` — modal chrome (title, variant, close) is handled for you | | Modal with custom header, description, footer, or composable API features | `createRawModalLauncher` — you control `ModalHeader`, `ModalBody`, `ModalFooter` directly | ### Composable Modal with `createRawModalLauncher` For modals that need full control over layout (custom headers, descriptions, footers), use `createRawModalLauncher` with PF v6's composable `Modal`: ```tsx import { Modal, ModalBody, ModalFooter, ModalHeader, ModalVariant } from '@patternfly/react-core'; import { createRawModalLauncher, RawComponentProps } from '~/components/modal/createModalLauncher'; const MyModal: React.FC = ({ onClose, modalProps }) => { const { isOpen, appendTo, ...rest } = modalProps || {}; return ( {/* modal content */} {/* action buttons */} ); }; export const myModalLauncher = createRawModalLauncher(MyModal, { 'data-test': 'my-modal' }); ``` > **Note:** Do not import `Modal` from `@patternfly/react-core/deprecated`. Use the composable `Modal` from `@patternfly/react-core`. ### Modal Variants | Variant | Width | Use For | | --------------------- | ----- | --------------------------- | | `ModalVariant.small` | 560px | Confirmations, simple forms | | `ModalVariant.medium` | 768px | Standard forms | | `ModalVariant.large` | 992px | Complex content, tables | ## Toolbar ```tsx import { Toolbar, ToolbarContent, ToolbarItem } from '@patternfly/react-core'; onTextInput(value)} value={text} /> {children} ; ``` Use `className="pf-v6-u-py-md"` for vertical spacing. Use `clearAllFilters` callback for filter reset. ## Empty States Use the three shared empty state wrappers. Never use raw PF `EmptyState` in feature components. | Component | Use For | | -------------------- | ------------------------------ | | `AppEmptyState` | Zero data (no resources exist) | | `FilteredEmptyState` | Filters yielded no results | | `ErrorEmptyState` | Error loading data | ```tsx import { AppEmptyState, FilteredEmptyState, ErrorEmptyState, } from '~/shared/components/empty-state'; // In table: EmptyMsg / NoDataEmptyMsg } />; // Direct usage if (error) return ; ``` ## Tabs All tabs are router-driven via `TabsLayout`. Never manage tab state with `useState`: ```tsx // Define tabs as data const tabs: DetailsPageTabProps[] = [ { key: '', label: 'Overview', isFilled: true }, // index route { key: 'pipelineruns', label: 'Pipeline runs' }, { key: 'activity', label: 'Activity', partial: true }, // matches /activity/* ]; // TabsLayout renders PF Tabs + ; ``` Always use `mountOnEnter` and `unmountOnExit` (set by default in `TabsLayout`). ## Labels ```tsx import { Label, LabelGroup, Truncate } from '@patternfly/react-core'; {items.map((item) => ( ))} ; ``` ## Tooltip / Popover ```tsx import { Tooltip, Popover } from '@patternfly/react-core'; // Simple tooltip // Popover with structured content {items.map(item => {item.name})} } > ``` ## DescriptionList Used on detail page overview tabs for key-value display: ```tsx import { DescriptionList, DescriptionListGroup, DescriptionListTerm, DescriptionListDescription, } from '@patternfly/react-core'; Name {resource.metadata.name} Created ; ``` ## Design Tokens ### Spacing Tokens (SCSS) Use PatternFly design tokens. Never hardcode pixel values. ```scss // Spacing scale gap: var(--pf-t--global--spacer--xs); // 4px gap: var(--pf-t--global--spacer--sm); // 8px gap: var(--pf-t--global--spacer--md); // 16px gap: var(--pf-t--global--spacer--lg); // 24px gap: var(--pf-t--global--spacer--xl); // 32px gap: var(--pf-t--global--spacer--2xl); // 48px gap: var(--pf-t--global--spacer--3xl); // 64px ``` ### Color Tokens ```scss // Semantic colors color: var(--pf-t--global--color--status--danger--default); // errors color: var(--pf-t--global--color--status--warning--default); // warnings color: var(--pf-t--global--color--status--success--default); // success color: var(--pf-t--global--color--status--info--default); // info color: var(--pf-t--global--text--color--disabled); // muted color: var(--pf-t--global--text--color--link--default); // links // Background background-color: var(--pf-t--global--background--color--secondary--default); // Border border: var(--pf-t--global--border--width--regular) solid var(--pf-t--global--border--color--default); ``` ### Typography Tokens ```scss font-size: var(--pf-t--global--font--size--sm); font-size: var(--pf-t--global--font--size--md); font-size: var(--pf-t--global--font--size--lg); font-weight: var(--pf-t--global--font--weight--heading--bold); font-family: var(--pf-t--global--font--family--mono); ``` ### Inline Style Tokens (TSX) Only acceptable inline styles are PF token references: ```tsx ``` ## Icon Imports Always use the deep ESM path. The barrel import is banned by ESLint: ```tsx // Correct import { CheckCircleIcon } from '@patternfly/react-icons/dist/esm/icons/check-circle-icon'; import { ExternalLinkAltIcon } from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon'; import { OutlinedQuestionCircleIcon } from '@patternfly/react-icons/dist/esm/icons/outlined-question-circle-icon'; // Wrong -- banned by ESLint import { CheckCircleIcon } from '@patternfly/react-icons'; ``` The icon name in the path is the kebab-case version of the component name. ## CSS Utility: `css()` from `@patternfly/react-styles` Use `css()` for conditional className merging alongside PF components: ```tsx import { css } from '@patternfly/react-styles'; ``` ## SCSS Conventions - Use BEM naming: `.my-component`, `.my-component__element`, `.my-component--modifier` - Always use PF design tokens for spacing, colors, typography - Co-locate SCSS files with their component: `MyComponent.scss` next to `MyComponent.tsx` - Never use `!important` -- fix specificity issues properly - Scope overrides to component classes: ```scss .my-component { // Custom styles using PF tokens padding: var(--pf-t--global--spacer--md); &__header { margin-bottom: var(--pf-t--global--spacer--sm); } &--compact { padding: var(--pf-t--global--spacer--sm); } // Override PF component token within this component scope .pf-v6-c-description-list { --pf-v6-c-description-list--GridTemplateColumns: repeat(3, 1fr); } } ``` ## Deprecated PF APIs to Avoid PF v6 removed `@patternfly/react-core/deprecated` entirely. All components that previously lived there (Dropdown, Select, Modal, Chip/ChipGroup) have already been migrated to their composable equivalents. Do not re-introduce imports from `@patternfly/react-core/deprecated`. ## Common Pitfalls — Composable Component DOM Semantics When migrating from deprecated PF APIs to the composable equivalents (`Select`, `Menu`, `Dropdown`), pay attention to DOM semantics. The composable API gives you full control over the markup, which means you are responsible for valid HTML nesting. ### Divider inside list containers `SelectList`, `MenuList`, and `DropdownList` render a `
    ` element. A `` renders `
    ` by default, which is not a valid child of `
      `. Always set `component="li"`: ```tsx // ✅ Correct — valid inside
        Option 1 Option 2 // ❌ Wrong —
        is invalid inside
          Option 1 Option 2 ``` The same rule applies to `MenuList` and `DropdownList`. ### MenuToggle ref forwarding The composable `Select`, `Menu`, and `Dropdown` require a `toggle` render function that receives a `ref`. You **must** forward this ref to `MenuToggle` — without it, Popper positioning and outside-click detection break silently: ```tsx ``` ### SelectOption and value types In the composable `Select`, `SelectOption` requires an explicit `value` prop. If you omit it, click handlers receive `undefined`. When using object values, provide a `toString()` method or use `itemId` for identification. ## Component Wrapping Decision Guide | Need | Use | | ------------------------------- | ------------------------------------------------------ | | Button in feature component | `AnalyticsButton` | | Button with RBAC tooltip | `ButtonWithAccessTooltip` | | External link | `ExternalLink` from `~/shared/components/links/` | | Action menu / kebab | `ActionMenu` from `~/shared/components/action-menu/` | | Loading/error wrapper | `StatusBox` from `~/shared/components/status-box/` | | Simple modal | `createModalLauncher` + `useModalLauncher` | | Modal with custom header/footer | `createRawModalLauncher` + `useModalLauncher` | | Timestamp display | `Timestamp` from `~/shared/components/timestamp/` | | Text truncation | `Truncate` from `~/shared/components/truncate-text/` | | Overflow list with popover | `TruncatedLinkListWithPopover` | | Skeleton placeholder | `LoadingSkeleton` from `~/shared/components/skeleton/` | | Countdown display | `Countdown` from `~/shared/components/countdown/` |