docs/components/layout/Box

Box

Base polymorphic container with spacing and color tokens.

import { Box } from '@ybouhjira/hyperkit';

#Playground

Edit the code — the preview recompiles and re-renders as you type.

Live playground
Loading preview…

#More Examples

With Border

<Box p="lg" bg="primary" border borderColor="accent" borderRadius="md">Box with accent border</Box>

With Shadow

<Box p="xl" bg="elevated" shadow="lg" borderRadius="lg">Box with shadow</Box>

#Props

PropTypeDefaultDescription
pSpaceTokenPadding on all sides.
pxSpaceTokenHorizontal padding (left and right).
pySpaceTokenVertical padding (top and bottom).
ptSpaceTokenPadding top.
prSpaceTokenPadding right.
pbSpaceTokenPadding bottom.
plSpaceTokenPadding left.
mSpaceTokenMargin on all sides.
mxSpaceTokenHorizontal margin (left and right).
mySpaceTokenVertical margin (top and bottom).
mtSpaceTokenMargin top.
mrSpaceTokenMargin right.
mbSpaceTokenMargin bottom.
mlSpaceTokenMargin left.
wstring | numberWidth. Accepts CSS value or number (converts to px).
hstring | numberHeight. Accepts CSS value or number (converts to px).
minWstring | numberMinimum width. Accepts CSS value or number (converts to px).
minHstring | numberMinimum height. Accepts CSS value or number (converts to px).
maxWstring | numberMaximum width. Accepts CSS value or number (converts to px).
maxHstring | numberMaximum height. Accepts CSS value or number (converts to px).
bgBgTokenBackground color token. Maps to theme CSS variables.
colorTextColorTokenText color token. Maps to theme CSS variables.
borderRadiusRadiusTokenBorder radius token. Maps to theme CSS variables.
shadowShadowTokenBox shadow token. Maps to theme CSS variables.
borderbooleanfalseEnable border on all sides.
borderColor'default' | 'subtle' | 'accent''default'Border color variant.
borderBottombooleanfalseEnable bottom border only.
borderTopbooleanfalseEnable top border only.
borderLeftbooleanfalseEnable left border only.
borderRightbooleanfalseEnable right border only.
position'relative' | 'absolute' | 'fixed' | 'sticky'CSS position property.
topstring | numberTop offset. Accepts CSS value or number (converts to px).
rightstring | numberRight offset. Accepts CSS value or number (converts to px).
bottomstring | numberBottom offset. Accepts CSS value or number (converts to px).
leftstring | numberLeft offset. Accepts CSS value or number (converts to px).
insetstring | numberInset shorthand for top/right/bottom/left. Accepts CSS value or number (converts to px).
zIndexZToken | numberZ-index. Accepts ZToken or raw number.
overflow'hidden' | 'auto' | 'scroll' | 'visible'Overflow behavior.
display'block' | 'flex' | 'grid' | 'inline' | 'inline-flex' | 'inline-block' | 'none'Display type.
hoverBgBgTokenBackground color token on hover. Applied via JavaScript.
hoverColorTextColorTokenText color token on hover. Applied via JavaScript.
cursor'pointer' | 'default' | 'grab' | 'not-allowed'Cursor style.
transitionbooleanfalseEnable transition animation on all properties.
opacitynumberOpacity value (0-1).
backdropFilterstringCSS backdrop-filter property.
filterstringCSS filter property.
transformstringCSS transform property.
pointerEvents'none' | 'auto'Pointer events behavior.
animationstringCSS animation property.
backgroundstringRaw CSS background property. Overrides bg token.
borderWidthstringCSS border-width property.
borderStyle'solid' | 'dashed' | 'dotted' | 'none'CSS border-style property.
flexstring | numberCSS flex property for flex children.
alignSelf'start' | 'center' | 'end' | 'stretch'Align-self for flex children.
asstring'div'HTML element to render as.
classstringAdditional CSS classes.
styleJSX.CSSPropertiesInline styles. Merged with computed styles.
childrenJSX.ElementContent to render inside the box.
onClickJSX.EventHandlerUnion<HTMLElement, MouseEvent>Click event handler.
onMouseDownJSX.EventHandlerUnion<HTMLElement, MouseEvent>Mouse down event handler.
onDragOverJSX.EventHandlerUnion<HTMLElement, DragEvent>Drag over event handler.
onDragLeaveJSX.EventHandlerUnion<HTMLElement, DragEvent>Drag leave event handler.
onDropJSX.EventHandlerUnion<HTMLElement, DragEvent>Drop event handler.
onSubmitJSX.EventHandlerUnion<HTMLFormElement, SubmitEvent>Form submit handler. Only meaningful when as="form".
onResetJSX.EventHandlerUnion<HTMLFormElement, Event>Form reset handler. Only meaningful when as="form".
onChangeJSX.EventHandlerUnion<HTMLElement, Event>Change event handler. Typed loosely to support form inputs bubbling.
refHTMLElement | ((el: HTMLElement) => void)Element ref callback or ref object.