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.
Want to skip the docs? Try our MCP Server
#
Documentation
#
#
Using design tokens
#
You can use props on the <Box /> component to control styles:
import { Box } from "@optiaxiom/react";
export function App() {
return (
<Box bg="bg.success.subtle" color="fg.success.strong" p="16">
Using component props
</Box>
);
}Visit the Styling section to learn more about how to consume our design tokens.
#
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.
"use client";
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
#
Grid
Use Grid component to place items in a grid using equal width columns.
Group
A flexbox layout component for grouping items horizontally or vertically.
Text
Display body or any other form of text. By default it outputs the <p> paragraph element.
#
Props
#
#
Box
#
Renders a <div> element.
Prop |
|---|
alignItemsSet the element’s
|
alignSelfSet the element’s
|
animationAnimate element with CSS animations
|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read the Composition guide for more details.
|
backgroundImageSet the element’s
|
bgSet the element’s background color. Only accepts predefined color tokens starting with
|
borderSet the element’s
|
borderBSet the element’s
|
borderColorSet the element’s border color. Only accepts predefined color tokens starting with
|
borderLSet the element’s
|
borderRSet the element’s
|
borderTSet the element’s
|
children
|
className
|
colorSet the element’s text color. Only accepts predefined color tokens starting with
|
cursorSet the element’s
|
displaySet the element’s
|
flexSet the element’s
|
flexDirectionSet the element’s |
flexWrapSet the element’s
|
fontFamilySet the element’s font family. Only accepts predefined fontFamily tokens.
|
fontSizeSet the element’s font size and line height (both properties are set together). Only accepts predefined fontSize tokens.
|
fontWeightSet the element’s
|
gapSet the element’s
|
gridColumnSet the element’s size across grid columns
|
gridTemplateColumnsControl number of columns in a grid layout
|
hSet the element’s height. Only accepts predefined size tokens.
|
justifyContentSet the element’s |
justifyItemsSet the element’s
|
mSet the element’s margin on all sides. Only accepts predefined spacing tokens.
|
maxHSet the element’s maximum height. Only accepts predefined maxSize tokens.
|
maxWSet the element’s maximum width. Only accepts predefined maxSize tokens.
|
mbSet the element’s bottom margin. Only accepts predefined spacing tokens.
|
mlSet the element’s left margin. Only accepts predefined spacing tokens.
|
mrSet the element’s right margin. Only accepts predefined spacing tokens.
|
mtSet the element’s top margin. Only accepts predefined spacing tokens.
|
mxSet the element’s left and right margin. Only accepts predefined spacing tokens.
|
mySet the element’s top and bottom margin. Only accepts predefined spacing tokens.
|
objectFitSet the element’s
|
overflowSet the element’s
|
overflowXSet the element’s
|
overflowYSet the element’s
|
pSet the element’s padding on all sides. Only accepts predefined spacing tokens.
|
pbSet the element’s bottom padding. Only accepts predefined spacing tokens.
|
plSet the element’s left padding. Only accepts predefined spacing tokens.
|
placeItemsSet the element’s
|
pointerEventsSet the element’s
|
prSet the element’s right padding. Only accepts predefined spacing tokens.
|
ptSet the element’s top padding. Only accepts predefined spacing tokens.
|
pxSet the element’s left and right padding. Only accepts predefined spacing tokens.
|
pySet the element’s top and bottom padding. Only accepts predefined spacing tokens.
|
roundedSet the element’s border radius. Only accepts predefined borderRadius tokens.
|
shadowSet the element’s box shadow. Only accepts predefined boxShadow tokens.
|
sizeSet the element’s width and height. Only accepts predefined size tokens. When width and height are the same, use
|
textAlignSet the element’s
|
textTransformSet the element’s
|
transitionControl which CSS properties should transition
|
wSet the element’s width. Only accepts predefined size tokens.
|
whiteSpaceSet the element’s
|
zSet the element’s stacking order. Only accepts predefined zIndex tokens (e.g., popover, toast, tooltip) or numeric values (0, 10, 20, 30, auto).
|
#
Changelog
#
#
0.1.0
#
- Added component