Box
Box
is the base component for all our other components and provides a convenient way to use our design tokens and set element styles without having to write any custom CSS.
#
Documentation
#
#
Using design tokens
#
import { Box } from "@optiaxiom/react";
export function App() {
return (
<Box bg="bg.information.subtle" m="24" p="24" rounded="sm">
This is a Box
</Box>
);
}
#
Composition
#
Box
component uses the Radix Composition approach and accepts an asChild
prop. By default it renders a <div>
element but when asChild
is enabled it will forward all of its own props to its child and only render the child element instead.
import { Box } from "@optiaxiom/react";
import { useState } from "react";
export function App() {
const [isHovered, setIsHovered] = useState(false);
return (
<Box
asChild
bg="bg.information.subtle"
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
p="8"
rounded="md"
>
<span>I am a span {isHovered && "hovered"}</span>
</Box>
);
}
#
BoxProps
#
We export a BoxProps
generic type that can be used to define prop types for components that extend Box
.
The first argument is the element or component type which defaults to div
.
The second argument is any additional custom prop types that component accepts.
import { Box, type BoxProps, extractBoxProps } from "@optiaxiom/react";
import { forwardRef } from "react";
type ButtonProps = BoxProps<"button", { icon?: string }>;
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ children, icon, ...props }, ref) => {
const { boxProps, restProps } = extractBoxProps(props);
return (
<Box asChild {...boxProps}>
<button ref={ref} {...restProps}>
{icon}
{children}
</button>
</Box>
);
},
);
Button.displayName = "@optiaxiom/docs/Button";
#
Related
#
Flex
Use Flex component to stack items vertically or horizontally.
Grid
Use Grid component to place items in a grid using equal width columns.
Text
Display body or any other form of text. By default it outputs the <p> paragraph element.
#
Props
#
#
Box
#
Renders a <div>
element.
Prop |
---|
alignItems Set the element’s
|
alignSelf Set the element’s
|
animation Animate element with CSS animations
|
asChild Change the default rendered element for the one passed as a child, merging their props and behavior. Read the Composition guide for more details.
|
bg Set the element’s background color
|
border Set the element’s
|
borderB Set the element’s
|
borderColor Set the element’s
|
borderL Set the element’s
|
borderR Set the element’s
|
borderT Set the element’s
|
className
|
color Set the element’s text color
|
cursor Set the element’s
|
display Set the element’s
|
empty Toggle element visibility based on
|
flex Set the element’s
|
flexDirection Set the element’s
|
flexWrap Set the element’s
|
fontFamily Set the element’s font family
|
fontSize Set the element’s
|
fontWeight Set the element’s
|
gap Set the element’s
|
gridColumn Set the element’s size across grid columns
|
gridTemplateColumns Control number of columns in a grid layout
|
h Set the element’s height
|
justifyContent Set the element’s
|
justifyItems Set the element’s
|
m Set the element’s margin on all sides
|
maxH Set the element’s max-height
|
maxW Set the element’s max-width
|
mb Set the element’s bottom margin
|
ml Set the element’s left margin
|
mr Set the element’s right margin
|
mt Set the element’s top margin
|
mx Set the element’s left and right margin
|
my Set the element’s top and bottom margin
|
objectFit Set the element’s
|
overflow Set the element’s
|
overflowX Set the element’s
|
overflowY Set the element’s
|
p Set the element’s padding on all sides
|
pb Set the element’s bottom padding
|
pl Set the element’s left padding
|
placeItems Set the element’s
|
pointerEvents Set the element’s
|
pr Set the element’s right padding
|
pt Set the element’s top padding
|
px Set the element’s left and right padding
|
py Set the element’s top and bottom padding
|
rounded Set the element’s border radius on all corners
|
shadow Set the element’s box shadow
|
size Set the element’s width and height
|
textAlign Set the element’s
|
textTransform Set the element’s
|
transition Control which CSS properties should transition
|
w Set the element’s width
|
whiteSpace Set the element’s
|
z Set the element’s stack order
|
#
Changelog
#
#
0.1.0
#
- Added component