Flex
Used to manage layout placement via Flexbox properties.
Anatomy
- Flex Container
- Flex Item
Import
import { Flex, FlexItem } from '@pluralsight/react'
Usage
Basic Example
function BasicExample() {
const itemStyles = {
backgroundColor: 'var(--ps-surface-medium)',
height: '9rem',
}
return (
<Flex align="center" justify="space-evenly">
<FlexItem grow="1" style={itemStyles}>
One
</FlexItem>
<FlexItem grow="1" style={itemStyles}>
Two
</FlexItem>
<FlexItem grow="1" style={itemStyles}>
Three
</FlexItem>
</Flex>
)
}
Customizing
There are 3 ways to customize the Flex components.
1. Unused Classes
Each component layer of the Flex family has a unused class name that can be utilized in your local CSS to customize the Flex components at any level.
pando-flex
: The element of the Flex.pando-flex-item
: The element of the FlexItem.
2. Passing a className
prop
You can pass a className
prop to the Flex components to customize Flex. This is useful if your project uses CSS Modules or a CSS-in-JS library like Emotion.
import customStyles from './customStyles.module.css'
function CustomFlex(props) {
return (
<Flex className={customStyles.custom}>
<FlexItem className={customStyles.customItem}>One</FlexItem>
</Flex>
)
}
3. Ejected Flex
For a low-level "ejected" approach, you can use the Headless-styles API to customize the Flex however you prefer while keeping the accessibility behavior.
import { getFlexProps, getFlexItemProps } from '@pluralsight/headless-styles'
To learn more about the Headless-styles API, check out the Headless-styles documentation.
Behavior
There are no behavior patterns required for Flex.
API
Flex
Parameters
interface FlexOptions extends HTMLAttributes<HTMLDivElement> {
align?: CSS.Property.AlignItems
direction?: FlexDirection
justify?: CSS.Property.JustifyContent
gap?: number
wrap?: CSS.Property.FlexWrap
}
align
: Thealign-items
property of the Flex.direction
: Theflex-direction
property of the Flex.justify
: Thejustify-content
property of the Flex.gap
: Thegap
property of the Flex.wrap
: Theflex-wrap
property of the Flex.
FlexItem
Parameters
interface FlexItemOptions extends HTMLAttributes<HTMLDivElement> {
basis?: CSS.Property.FlexBasis
grow?: CSS.Property.FlexGrow
shrink?: CSS.Property.FlexShrink
}
basis
: Theflex-basis
property of the FlexItem.grow
: Theflex-grow
property of the FlexItem.shrink
: Theflex-shrink
property of the FlexItem.
Accessibility
The Pando Flex APIs allow the Badge to be fully accessible and screen-readable by default.