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
|
borderSet the element’s
|
borderBSet the element’s
|
borderColorSet the element’s
|
borderLSet the element’s
|
borderRSet the element’s
|
borderTSet the element’s
|
className
|
colorSet the element’s text color
|
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
|
fontSizeSet the element’s
|
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
|
justifyContentSet the element’s |
justifyItemsSet the element’s
|
mSet the element’s margin on all sides
|
maxHSet the element’s max-height
|
maxWSet the element’s max-width
|
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 on all corners
|
shadowSet the element’s box shadow
|
sizeSet the element’s width and height
|
textAlignSet the element’s
|
textTransformSet the element’s
|
transitionControl which CSS properties should transition
|
wSet the element’s width
|
whiteSpaceSet the element’s
|
zSet the element’s stack order
|
#
Changelog
#
#
0.1.0
#
- Added component