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
|
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 values: size tokens (xs, sm, md, etc.), numeric spacing values (16, 24, 32), fractional percentages (1/2, 1/3), or special keywords (auto, full, fit, max, min). ⚠️ COMMON MISTAKE: Do not use arbitrary pixel values like “200” or “300”. Use the closest valid token from the allowed values instead. 💡 TIP: When width and height are the same, use
|
justifyContentSet the element’s |
justifyItemsSet the element’s
|
mSet the element’s margin on all sides ⚠️ WARNING: Do NOT use arbitrary values like “10px”, “5rem”, or negative numbers like “-8”. Only predefined spacing tokens are accepted.
|
maxHSet the element’s maximum height. Only accepts predefined maxSize tokens. ⚠️ COMMON MISTAKE: Do not use arbitrary pixel values like “200” or “300”. Use the closest valid token from the allowed values instead.
|
maxWSet the element’s maximum width. Only accepts predefined maxSize tokens. ⚠️ COMMON MISTAKE: Do not use arbitrary pixel values like “200” or “300”. Use the closest valid token from the allowed values instead.
|
mbSet the element’s bottom margin ⚠️ WARNING: Do NOT use arbitrary values like “10px”, “5rem”, or negative numbers like “-8”. Only predefined spacing tokens are accepted.
|
mlSet the element’s left margin ⚠️ WARNING: Do NOT use arbitrary values like “10px”, “5rem”, or negative numbers like “-8”. Only predefined spacing tokens are accepted.
|
mrSet the element’s right margin ⚠️ WARNING: Do NOT use arbitrary values like “10px”, “5rem”, or negative numbers like “-8”. Only predefined spacing tokens are accepted.
|
mtSet the element’s top margin ⚠️ WARNING: Do NOT use arbitrary values like “10px”, “5rem”, or negative numbers like “-8”. Only predefined spacing tokens are accepted.
|
mxSet the element’s left and right margin ⚠️ WARNING: Do NOT use arbitrary values like “10px”, “5rem”, or negative numbers like “-8”. Only predefined spacing tokens are accepted.
|
mySet the element’s top and bottom margin ⚠️ WARNING: Do NOT use arbitrary values like “10px”, “5rem”, or negative numbers like “-8”. Only predefined spacing tokens are accepted.
|
objectFitSet the element’s
|
overflowSet the element’s
|
overflowXSet the element’s
|
overflowYSet the element’s
|
pSet the element’s padding on all sides ⚠️ WARNING: Do NOT use arbitrary values like “10px” or “5rem”. Only predefined spacing tokens are accepted.
|
pbSet the element’s bottom padding ⚠️ WARNING: Do NOT use arbitrary values like “10px” or “5rem”. Only predefined spacing tokens are accepted.
|
plSet the element’s left padding ⚠️ WARNING: Do NOT use arbitrary values like “10px” or “5rem”. Only predefined spacing tokens are accepted.
|
placeItemsSet the element’s
|
pointerEventsSet the element’s
|
prSet the element’s right padding ⚠️ WARNING: Do NOT use arbitrary values like “10px” or “5rem”. Only predefined spacing tokens are accepted.
|
ptSet the element’s top padding ⚠️ WARNING: Do NOT use arbitrary values like “10px” or “5rem”. Only predefined spacing tokens are accepted.
|
pxSet the element’s left and right padding ⚠️ WARNING: Do NOT use arbitrary values like “10px” or “5rem”. Only predefined spacing tokens are accepted.
|
pySet the element’s top and bottom padding ⚠️ WARNING: Do NOT use arbitrary values like “10px” or “5rem”. Only predefined spacing tokens are accepted.
|
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 values: size tokens (xs, sm, md, etc.), numeric spacing values (16, 24, 32), fractional percentages (1/2, 1/3), or special keywords (auto, full, fit, max, min). ⚠️ COMMON MISTAKE: Do not use arbitrary pixel values like “200” or “300”. Use the closest valid token from the allowed values instead. 💡 TIP: 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 values: size tokens (xs, sm, md, etc.), numeric spacing values (16, 24, 32), fractional percentages (1/2, 1/3), or special keywords (auto, full, fit, max, min). ⚠️ COMMON MISTAKE: Do not use arbitrary pixel values like “200” or “300”. Use the closest valid token from the allowed values instead. 💡 TIP: When width and height are the same, use
|
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