Styling
This page describes how styling works in Hopper, including how to customize spacing, sizing, and positioning, and how to create your own custom components using Hopper styles.
Introduction
Hopper components are designed to be consistent across all Workleap applications. They include built-in styling that has been considered carefully, and extensively tested. In general, customizing Hopper is discouraged, but most components do offer control over layout and other aspects. In addition, you can use Hopper's tokens to ensure your application conforms to design requirements, and is adaptive across color schemes.
Style props
A Hopper style property is a mapping of a CSS property to a component property. With style props, Hopper let you easily set style values for a curated set of CSS properties like font-size, margin, padding, width and many more.
All of the available style props are listed in the "Properties List" section below.
Usage
To use a style prop on a Hopper component, pass the prop as a camelCased string to the component. By default, only tokens are accepted as values for style props. They help promote consistency and maintainability across your application.
If you need to pass a custom value, you can use the UNSAFE_
prefix to bypass the token system. You can refer to the "Escape hatches" section for more information.
Shorthands
Props like border and paddingX are also provided to help you save keystrokes. An exhaustive list of all the supported props is available in the "Properties List" section.
Responsive styles
All style props support responsive values. You can pass an object with breakpoints as keys and values as values to a style prop to set different values for different breakpoints. More information is available in the Responsive Styles article.
Escape hatches
While we encourage teams to utilize Hopper styles as it is, we do realize that sometimes product specific customizations may be needed. In these cases, we encourage you or your designers to talk to us. We may be able to suggest an alternative implementation strategy, or perhaps your design can help inform future Hopper additions.
While the traditional className and style props are always supported in Hopper components, we also provide an escape hatch for passing custom values to style props. This is done by prefixing the prop name with UNSAFE_
.
The UNSAFE_
prefix might look scary, but it's there to remind you that you're bypassing the token system. It's a way to ensure that you're aware that you're doing something that might not be automatically updated when tokens change.
It will also help you to search for these usages when you want to update them, or help us to provide missing tokens.
Pseudo-classes
Style props doesn't support every CSS pseudo-classes. Location pseudo-classes, input pseudo-classes, tree-structural pseudo-classes, ::before and ::after are not supported and will most likely never be.
When a CSS pseudo-class is not supported by Hopper style props, we recommend using a CSS class.
Since the following user action pseudo-classes are often used, some style props support them. These behaves like their pseudo CSS counterparts.
Suffix | Pseudo state |
---|---|
active | :active |
hover | :hover |
focus | :focus |
Not all style props support user action pseudo-classes. Find out which props support user action pseudo-classes in the "Properties List" section.
HTML Elements
You might wonder how to use Hopper style props on your HTML elements?
Hopper provides a set of HTML element components already configured with Hopper styled system. You should choose these components over native HTML elements.
<A>
, <Address>
, <Article>
, <Aside>
, <HtmlButton>
, <Div>
, <HtmlFooter>
, <HtmlHeader>
, <Img>
, <Input>
, <List>
, <Main>
, <Nav>
, <Section>
, <Span>
, <Table>
For text elements, prefer a <Text>
or <Paragraph>
component rather than <Span>
or a <Div>
.
Custom components
Sometimes, you may find yourself needing to build a component that doesn't exist in Hopper, but this component would benefit from using Hopper's style props.
There are 2 ways to build a custom component with Hopper style properties, as seen below:
HTML Element
Instead of using a native HTML element to create your component, you can use one of the Hopper HTML Element components. This way, you can simply forward the style props to the component.
This is an example using a Div
, but you can use any of the HTML Element components.
useStyledSystem
If you need to build a more complex component, you can use the useStyledSystem
function. This function allows you to create a custom component with Hopper style props.
The useStyledSystem
function returns a stylingProps
object containing a resulting style object and a className. You can then spread the stylingProps
object on your component, or merge them with your existing className and style properties.
We don't automatically merge the className
and style
props because most of the className and style props in Hopper also accept a function.
Properties List
The following tables provide a list of all available style props by category.
Space
Prop | CSS property | Scale | Supports |
---|---|---|---|
margin | margin | Spacing | breakpoints |
marginTop | margin-top | Spacing | breakpoints |
marginBottom | margin-bottom | Spacing | breakpoints |
marginRight | margin-right | Spacing | breakpoints |
marginLeft | margin-left | Spacing | breakpoints |
marginX | margin-left & margin-right | Spacing | breakpoints |
marginY | margin-top & margin-bottom | Spacing | breakpoints |
padding | padding | Spacing | breakpoints |
paddingTop | padding-top | Spacing | breakpoints |
paddingBottom | padding-bottom | Spacing | breakpoints |
paddingRight | padding-right | Spacing | breakpoints |
paddingLeft | padding-left | Spacing | breakpoints |
paddingX | padding-left & padding-right | Spacing | breakpoints |
paddingY | padding-top & padding-bottom | Spacing | breakpoints |
whiteSpace | white-space | none | breakpoints |
Color
Prop | CSS property | Scale | Supports |
---|---|---|---|
color | color | Colors | breakpoints & focus/hover/active |
backgroundColor | background-color | Colors | breakpoints & focus/hover/active |
opacity | opacity | none | breakpoints & focus/hover/active |
fill | fill | Colors | breakpoints & focus/hover |
stroke | stroke | Colors | breakpoints |
filter | filter | none | breakpoints |
Typography
Prop | CSS property | Scale | Supports |
---|---|---|---|
fontSize | font-size | Typography | breakpoints |
fontWeight | font-weight | Typography | breakpoints |
lineHeight | line-height | Typography | breakpoints |
letterSpacing | letter-spacing | none | breakpoints |
textAlign | text-align | none | breakpoints |
textTransform | text-transform | none | breakpoints |
textDecoration | text-decoration | none | breakpoints |
textOverflow | text-overflow | none | breakpoints |
wordBreak | word-break | none | breakpoints |
fontStyle | font-style | none | breakpoints |
Layout
Prop | CSS property | Scale | Supports |
---|---|---|---|
width | width | Dimensions | breakpoints |
height | height | Dimensions | breakpoints |
minWidth | min-width | Dimensions | breakpoints |
maxWidth | max-width | Dimensions | breakpoints |
minHeight | min-height | Dimensions | breakpoints |
maxHeight | max-height | Dimensions | breakpoints |
display | display | none | breakpoints |
verticalAlign | vertical-align | none | breakpoints |
overflow | overflow | none | breakpoints |
overflowX | overflow-x | none | breakpoints |
overflowY | overflow-y | none | breakpoints |
gap | gap | none | breakpoints |
alignSelf | align-self | none | breakpoints |
aspectRatio | aspect-ratio | none | breakpoints |
justifyContent | justify-content | none | breakpoints |
justifyItems | justify-items | none | breakpoints |
justifySelf | justify-self | none | breakpoints |
contentVisibility | content-visibility | none | breakpoints |
transform | transform | none | breakpoints |
transformOrigin | transform-origin | none | breakpoints |
transformStyle | transform-style | none | breakpoints |
Flex Layout
Prop | CSS property | Scale | Supports |
---|---|---|---|
alignItems | align-items | none | breakpoints |
alignContent | align-content | none | breakpoints |
flex | flex (shorthand) | none | breakpoints |
flexBasis | flex-basis | none | breakpoints |
flexDirection | flex-direction | none | breakpoints |
flexFlow | flex-flow | none | breakpoints |
flexGrow | flex-grow | none | breakpoints |
flexShrink | flex-shrink | none | breakpoints |
flexWrap | flex-wrap | none | breakpoints |
order | order | none | breakpoints |
Grid Layout
Prop | CSS property | Scale | Supports |
---|---|---|---|
grid | grid (shorthand) | none | breakpoints |
gridArea | grid-area | none | breakpoints |
gridAutoColumns | grid-auto-columns | Dimensions | breakpoints |
gridAutoFlow | grid-auto-flow | none | breakpoints |
gridAutoRows | grid-auto-rows | Dimensions | breakpoints |
gridColumn | grid-column | none | breakpoints |
gridColumnEnd | grid-column-end | none | breakpoints |
gridColumnSpan | grid-column-span | none | breakpoints |
gridColumnStart | grid-column-start | none | breakpoints |
gridRow | grid-row | none | breakpoints |
gridRowEnd | grid-row-end | none | breakpoints |
gridRowSpan | grid-row-span | none | breakpoints |
gridRowStart | grid-row-start | none | breakpoints |
gridTemplate | grid-template | none | breakpoints |
gridTemplateAreas | grid-template-areas | none | breakpoints |
gridTemplateColumns | grid-template-columns | Dimensions | breakpoints |
gridTemplateRows | grid-template-rows | Dimensions | breakpoints |
columnGap | column-gap | Spacing | breakpoints |
rowGap | row-gap | Spacing | breakpoints |
Background
Prop | CSS property | Scale | Supports |
---|---|---|---|
backgroundImage | background-image | none | breakpoints |
backgroundPosition | background-position | none | breakpoints |
backgroundRepeat | background-repeat | none | breakpoints |
backgroundSize | background-size | none | breakpoints |
Border
Border props (border, borderBottom, borderTop, borderRight, borderLeft) uses an implicit style (solid) and width(1px). These properties only accepts colors for value.
Prop | CSS property | Scale | Supports |
---|---|---|---|
border | border-color | Colors | breakpoints & focus/hover/active |
borderBottom | border-bottom-color | Colors | breakpoints & focus/hover/active |
borderTop | border-top-color | Colors | breakpoints & focus/hover/active |
borderLeft | border-left-color | Colors | breakpoints & focus/hover/active |
borderRight | border-right-color | Colors | breakpoints & focus/hover/active |
borderRadius | border-radius | Shape | breakpoints |
borderTopLeftRadius | border-top-left-radius | Shape | breakpoints |
borderTopRightRadius | border-top-right-radius | Shape | breakpoints |
borderBottomLeftRadius | border-bottom-left-radius | Shape | breakpoints |
borderBottomRightRadius | border-bottom-right-radius | Shape | breakpoints |
outline | outline | none | breakpoints & focus |
Position
Prop | CSS property | Scale | Supports |
---|---|---|---|
position | position | none | breakpoints |
top | top | none | breakpoints |
bottom | bottom | none | breakpoints |
right | right | none | breakpoints |
left | left | none | breakpoints |
zIndex | z-index | none | breakpoints |
objectFit | object-fit | none | breakpoints |
objectPosition | object-position | none | breakpoints |
Shadow
Prop | CSS property | Scale | Supports |
---|---|---|---|
boxShadow | box-shadow | Shape | breakpoints & focus/hover/active |
Miscellaneous
Prop | CSS property | Scale | Supports |
---|---|---|---|
content | content | none | breakpoint |
cursor | cursor | none | breakpoint & hover |
pointerEvents | pointer-events | none | breakpoint |
resize | resize | none | breakpoint |
willChange | will-change | none | breakpoint |