System props
All of the components in Stacks UI are built with emotion
and implement a modified version theme-ui
. With this,
you can pass all css attributes to any component as props. Check out the page further reading to dig
deeper.
System props reference
See below for the various props and aliases you can pass for styling components. You can see the full spec on the Styled System docs.
Margin & padding
import { Box } from '@stacks/ui'; // 'base' is a custom named spacing unit <Box m="base">Tomato</Box>; // You can also use custom values <Box maxW="960px" mx="auto" />; // sets margin `16px` on all viewports and `20px` from the first breakpoint and up <Box m={['base', 'loose']} />;import { Box } from '@stacks/ui';// 'base' is a custom named spacing unit<Box m="base">Tomato</Box>;// You can also use custom values<Box maxW="960px" mx="auto" />;// sets margin `16px` on all viewports and `20px` from the first breakpoint and up<Box m={['base', 'loose']} />;
Prop | CSS Property | Theme Key |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Color & background color
import { Box } from "@stacks/ui"; // picks up a nested color value using dot notation // => `theme.colors.ink[50]` <Box color='ink.50' /> // raw CSS color value <Box color='#f00' /> // background colors <Box bg='tomato' /> // verbose prop <Box backgroundColor='tomato' />import { Box } from "@stacks/ui";// picks up a nested color value using dot notation// => `theme.colors.ink[50]`<Box color='ink.50' />// raw CSS color value<Box color='#f00' />// background colors<Box bg='tomato' />// verbose prop<Box backgroundColor='tomato' />
Prop | CSS Property | Theme Key |
---|---|---|
|
|
|
|
|
|
|
| none |
Typography
import { Text } from "@stacks/ui"; // font-size of `theme.textStyle.display.large <Text textStyle="display.large" /> // font-size `32px` <Text fontSize="32px" /> // font-size `'2em'` <Text fontSize='2em' /> // text-align `left` on all viewports and `center` from the first breakpoint and up <Text textAlign={[ 'left', 'center' ]} />import { Text } from "@stacks/ui";// font-size of `theme.textStyle.display.large<Text textStyle="display.large" />// font-size `32px`<Text fontSize="32px" />// font-size `'2em'`<Text fontSize='2em' />// text-align `left` on all viewports and `center` from the first breakpoint and up<Text textAlign={[ 'left', 'center' ]} />
Prop | CSS Property | Theme Key |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| none |
|
| none |
|
| none |
|
| none |
Layout, width and height
import { Box } from "@stacks/ui"; // verbose <Box width="100%" height={32} />; // shorthand <Box w="100%" h="32px" />; // width `50%` <Box w="50%" /> // width `'40px'` <Box w='40px' />import { Box } from "@stacks/ui";// verbose<Box width="100%" height={32} />;// shorthand<Box w="100%" h="32px" />;// width `50%`<Box w="50%" />// width `'40px'`<Box w='40px' />
Prop | CSS Property | Theme Key |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| none |
|
|
|
|
| none |
|
| none |
|
| none |
|
| none |
Flexbox
import { Box, Flex } from '@stacks/ui'; // verbose <Box display="flex" alignItems="center" justifyContent="space-between"> Box with Flex props </Box>; // shorthand using the `Flex` component <Flex alignItems="center" justifyContent="center"> Flex Container </Flex>;import { Box, Flex } from '@stacks/ui';// verbose<Box display="flex" alignItems="center" justifyContent="space-between"> Box with Flex props</Box>;// shorthand using the `Flex` component<Flex alignItems="center" justifyContent="center"> Flex Container</Flex>;
Prop | CSS Property | Theme Key |
---|---|---|
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
Grid Layout
import { Box, Grid } from '@stacks/ui'; // verbose <Box display="grid" gridGap="base" gridAutoFlow="row dense"> Grid </Box>; // shorthand using the `Grid` component <Grid gap="base" autoFlow="row dense"> Grid </Grid>;import { Box, Grid } from '@stacks/ui';// verbose<Box display="grid" gridGap="base" gridAutoFlow="row dense"> Grid</Box>;// shorthand using the `Grid` component<Grid gap="base" autoFlow="row dense"> Grid</Grid>;
Note: Props in
*
will only work if you use theGrid
component.
Prop | CSS Property | Theme Key |
---|---|---|
|
|
|
|
|
|
|
|
|
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
Background
import { Box } from '@stacks/ui'; // verbose <Box backgroundImage="url('/images/kitten.png')" backgroundPosition="center" backgroundRepeat="no-repeat" />; // shorthand <Box bgImage="url('/images/puppy.png')" bgPos="center" bgRepeat="no-repeat" />;import { Box } from '@stacks/ui';// verbose<Box backgroundImage="url('/images/kitten.png')" backgroundPosition="center" backgroundRepeat="no-repeat"/>;// shorthand<Box bgImage="url('/images/puppy.png')" bgPos="center" bgRepeat="no-repeat" />;
Prop | CSS Property | Theme Key |
---|---|---|
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
Borders
import { Box } from '@stacks/ui'; <Box border="1px" borderRadius="6px" borderColor="ink.i00"> Card </Box>;import { Box } from '@stacks/ui';<Box border="1px" borderRadius="6px" borderColor="ink.i00"> Card</Box>;
Prop | CSS Property | Theme Field |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Border Radius
import { Button } from '@stacks/ui'; // This button will have no right borderRadius <Button roundedRight="0">Button 1</Button>; // This button will have no left borderRadius*/ <Button roundedLeft="0">Button 2</Button>; // top left and top right radius will be `theme.radii.md` => 4px <Button roundedTop="md">Button 2</Button>;import { Button } from '@stacks/ui';// This button will have no right borderRadius<Button roundedRight="0">Button 1</Button>;// This button will have no left borderRadius*/<Button roundedLeft="0">Button 2</Button>;// top left and top right radius will be `theme.radii.md` => 4px<Button roundedTop="md">Button 2</Button>;
Prop | CSS Property | Theme Field |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Position
import { Box } from '@stacks/ui'; // verbose <Box position="absolute">Cover</Box>; // shorthand <Box pos="absolute">Cover</Box>; <Box pos="absolute" top="0" left="0"> Absolute with top and left </Box>; <Box pos="fixed" w="100%" zIndex={2}> Fixed with zIndex </Box>;import { Box } from '@stacks/ui';// verbose<Box position="absolute">Cover</Box>;// shorthand<Box pos="absolute">Cover</Box>;<Box pos="absolute" top="0" left="0"> Absolute with top and left</Box>;<Box pos="fixed" w="100%" zIndex={2}> Fixed with zIndex</Box>;
Prop | CSS Property | Theme Field |
---|---|---|
|
| none |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Shadow
import { Box, Text } from '@stacks/ui'; // text-shadow will be `theme.shadows.low` // box-shadow will be `theme.shadows.high` <Box textShadow="low" boxShadow="high" />; // raw CSS values <Text textShadow="0px 1px 2px rgba(0, 0, 0, 0.04)" boxShadow="0px 8px 16px rgba(27, 39, 51, 0.08)"> Text with shadows </Text>;import { Box, Text } from '@stacks/ui';// text-shadow will be `theme.shadows.low`// box-shadow will be `theme.shadows.high`<Box textShadow="low" boxShadow="high" />;// raw CSS values<Text textShadow="0px 1px 2px rgba(0, 0, 0, 0.04)" boxShadow="0px 8px 16px rgba(27, 39, 51, 0.08)"> Text with shadows</Text>;
Prop | CSS Property | Theme Field |
---|---|---|
|
|
|
|
|
|
Other Props
Asides all the common system props listed above, all component will accept the following props:
Prop | CSS Property | Theme Field |
---|---|---|
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
| none |
|
|
|
|
|
|
|
| none |
The as prop
The as
prop allows you to pass a HTML tag or another component to a Stacks UI component to be rendered as the
base tag of that component along with all its styles and props.
For example, say you are using a Button component, and you need to make it a
link instead. You can compose a
and Button like this:
<Button as="a" target="_blank" variant="link" href="https://blockstack.org"> This is now a link </Button><Button as="a" target="_blank" variant="link" href="https://blockstack.org"> This is now a link</Button>
This allows you to use all of the Button
props and all of the <a>
props
without having to wrap the Button in an a
component.
Note: this does have some limitations.
Let's say you wanted the button to take styles from a Flex
primitive. You'd do the following:
<Button as={Flex} onClick={() => console.log('button')}> This is now using a Flex as the primary wrapper component. </Button><Button as={Flex} onClick={() => console.log('button')}> This is now using a Flex as the primary wrapper component.</Button>
The issue with this, though, is the Button no long renders as a button
DOM element. It will be rendered as a div
because Flex
by default renders as a div
.
For these reasons, it's recommended only to use the as prop when you cannot achieve the same result by nesting components. The Flex / Button example could be done like so:
<Button display="flex" onClick={() => console.log('button')}>Some Button</Button> // or <Button as={p => <Flex as="button" {...p} />} onClick={() => console.log('button')}> Button with flex, but as a button html element. </Button><Button display="flex" onClick={() => console.log('button')}>Some Button</Button> // or<Button as={p => <Flex as="button" {...p} />} onClick={() => console.log('button')}> Button with flex, but as a button html element.</Button>