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
#
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
#
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 |
|---|
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).
|
justifyContentSet the element’s |
justifyItemsSet the element’s
|
mSet the element’s margin on all sides
|
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
|
mlSet the element’s left margin
|
mrSet the element’s right margin
|
mtSet the element’s top margin
|
mxSet the element’s left and right margin
|
mySet the element’s top and bottom margin
|
objectFitSet the element’s
|
overflowSet the element’s
|
overflowXSet the element’s
|
overflowYSet the element’s
|
pSet the element’s padding on all sides
|
pbSet the element’s bottom padding
|
plSet the element’s left padding
|
placeItemsSet the element’s
|
pointerEventsSet the element’s
|
prSet the element’s right padding
|
ptSet the element’s top padding
|
pxSet the element’s left and right padding
|
pySet the element’s top and bottom padding
|
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).
|
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).
|
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