Usage
This example demonstrates how to use Box with the default configuration.
- Create layouts with ease.
- Use it as a container for other components.
- Provide a shorthand way to pass styles via props, example: (bgColor instead of backgroundColor).
<Box bgColor="blue" border="xl" p="xs">
<Text>This is the Box</Text>
</Box>
Import
To use this component in your project, include the following import statement in your file.
import { Box } from "@design-blocks/primitives";
Props
Rest assured that Box inherits all the properties of the React Native View component.
styles props
Style props are a way to alter the style of a component by simply passing props to it. It helps to save time by providing helpful shorthand ways to style components.
<Box w="lg" h="lg" bgColor="blue" border="xl" m="lg" p="xs" borderRadius="md">
<Text>This is the Box</Text>
</Box>
To find out which properties are theme-aware, see the Style Props.
sx
The system prop that allows defining system overrides as well as additional CSS styles.
<Box bgColor="blue" border="xl" p="xs" sx={{ bgColor: "red" }}>
<Text>This is the Box</Text>
</Box>
In this case, sx
will overwrite the bgColor
passed as a prop, resulting in a Box with a red backgroundColor
.
See the sx
page for more details.
Unstyled
It's important to note that primitive components come without predefined styles. For more information, please refer to this link.