Package org.patternfly.style
This package provides programmatic access to PatternFly's CSS styling system. It includes utilities for applying modifier classes, working with responsive breakpoints, managing CSS variables, and using typed modifier interfaces for component styling.
Key Classes
Breakpoint- Responsive breakpoint definitions (sm, md, lg, xl, 2xl)BreakpointCollector- Stream collector for building breakpoint mapsBreakpoints- Container for breakpoint-specific valuesClasses- Constants for PatternFly CSS class namesColor- PatternFly color enumerationModifiers- Reusable modifier interfaces for common styling flagsSize- Size enumeration (default, sm, md, lg, xl, 2xl, 3xl, 4xl)TypedModifier- Interface for type-safe modifier applicationVariable- Type-safe CSS variable definitionsVariableAssignments- Utilities for applying CSS variable assignments to elementsVariables- CSS variable assignments for components
CSS Classes
The Classes class provides constants for PatternFly CSS classes:
import static org.patternfly.style.Classes.*;
// Base classes
div().css(component("alert"))
.add(div().css(component("alert", "title")));
// Modifier classes
div().css(modifier("bordered"), modifier("compact"));
Modifiers
The Modifiers interface defines sub-interfaces for common styling flags.
Components implement these interfaces to provide type-safe modifier methods:
// Components implement modifier interfaces
Card card = card()
.bordered() // from Modifiers.Bordered
.compact() // from Modifiers.Compact
.fullHeight(); // from Modifiers.FullHeight
// Toggle modifiers conditionally
Alert alert = alert("Warning")
.inline(isInlineMode)
.plain(!hasIcon);
Available modifier interfaces include:
Bordered, Box, Center, Compact, DisabledFill, FullHeight, FullWidth, GutterHorizontal, Inline, InvalidNoFill, NoPadding, NoOffsetPadding, PageInsets, Plain, PrimaryReadonly, Required, Secondary, Static, Sticky, Vertical
Responsive Breakpoints
Use Breakpoint for responsive design:
// Determine current breakpoint
Breakpoint current = Breakpoint.breakpoint(window.innerWidth);
// Apply breakpoint-specific styles
if (current == Breakpoint.lg || current == Breakpoint.xl) {
showDesktopLayout();
}
// Use Breakpoints container for responsive values
Breakpoints<Integer> columns = new Breakpoints<Integer>()
.default_(1)
.sm(2)
.md(3)
.lg(4);
int cols = columns.get(current);
CSS Variables
PatternFly uses CSS custom properties (variables) for theming. The Variable
class provides type-safe access:
// Create a typed variable
Variable<String> colorVar = new Variable<>("--pf-v6-global--primary-color--100");
// Apply variables to elements
Variables variables = new Variables();
variables.set(colorVar, "#0066cc");
element.style.cssText = variables.toCss();
Colors and Sizes
Use enum constants for consistent colors and sizes:
// Colors
Badge badge = badge("New")
.color(Color.blue);
Label label = label("Success")
.color(Color.green);
// Sizes
Button button = button("Click me")
.size(Size.lg);
Title title = title(1, "Heading")
.size(Size._2xl);
Typed Modifiers
Use TypedModifier for type-safe modifier application:
TypedModifier<Size> sizeModifier = new TypedModifier<>(
"size",
size -> "pf-m-" + size.value
);
// Apply to element
element.classList.add(sizeModifier.modifier(Size.lg));
Additional Enums
The package includes enums for specific styling concerns:
Brightness- Light/dark theme variantsExpandableModifier- Expandable/non-expandable section modifierGridBreakpoint- Responsive grid breakpoints for data list and tableInset- Inset spacing sizes for component paddingNotificationStatus- Notification read/unread/attention statusOrientation- Horizontal/vertical orientationPadding- Padding/no-padding modifierPlacement- Popover/tooltip placement positions (top, bottom, start, end)Rect- Simple width/height rectangle value typeStatus- Status colors (success, warning, danger, info, custom)Sticky- Sticky positioning (top/bottom)Theme- Dark/light theme enumerationVisibility- Element visibility statesWidth- Column width percentages for table cells
- See Also:
-
ClassDescriptionThe
Breakpointclass represents different breakpoints for responsive design.TheBreakpointCollectorcollects tuples ofBreakpointand a generic valueVas CSS modifier classes and returns the collected data as aString.Breakpoints<V>This class represents a collection of breakpoints and associated values.Defines the available brightness levels for component backgrounds.Provides CSS class name constants and helper methods for building PatternFly component and modifier class names.Defines the available color options for components such as labels and badges.Defines whether a component section is expandable or non-expandable.Union enum of the differentgridBreakpointproperties for data list and table.Defines the available inset sizes for component spacing.Contains modifier interfaces that toggle CSS modifier classes on component elements.Defines the read status of a notification item.Defines horizontal or vertical orientation for a component.Defines whether a component has padding or no padding.Defines the placement position (top, bottom, left, right) and alignment (start, end) for overlays and tooltips.Represents a width-height dimension pair.Defines the available sizes for a component.Defines the severity status variants for alerts, icons, and other status-aware components.Defines sticky positioning for a component at the top or bottom of its container.Defines the available color themes for a component.Interface for enums that represent a CSS modifier class, providing both the raw value and the fully qualified modifier.Provides methods to build and apply PatternFly global and component variables.Provides fluent builders for assigning values to PatternFly CSS custom properties on HTML and SVG elements.Provides constants for common CSS custom property element names used when building PatternFly variables.Defines visibility modifiers to show or hide a component.Defines the available percentage-based width modifiers for a component.