Box
The primitive every other component is built on. Renders a `div` on web and a `View` on mobile. Use when nothing more specific fits.
compliant
- Overview
- Props
Box is the most abstract component on top of which other components are built. By default, it renders a div element on the web (with some default styles, see Web behavior drift section) and a View on mobile.
Box
Styling
It is a good building block for styling.
Box
Shadows
Predefined shadows can be set through the shadowPreset sx prop.
xs
sm
md
lg
It's also possible to invert the direction of the shadow by suffixing the preset with -inverted.
Polymorphic
You can use the asChild prop. Instead of rendering its own element, it will pass all props to that child, merging together any event handling props.
Hello
Web Behavior Drift
It renders a div but not an unstyled raw div. It has some standard react-native-web flex styles to get the same behavior on the web and mobile.
Its default styles are:
display: 'flex'
alignItems: 'stretch'
flexDirection: 'column'
flexBasis: 'auto'
boxSizing: 'border-box'
position: 'relative'
minHeight: 0
minWidth: 0
flexShrink: 0
In some web-only cases, especially when you don't know the composition of the children in your components, you may want to restore the default div behavior.
<Box sx={{ display: "block", flexShrink: 1, flexGrow: 1 }}>{/* ... */}</Box>
Playground
murray and murray/mobile.Box props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| css | Interpolation<Theme> | |||
| onKeyDown | (e: KeyboardEvent) => void | |||
| sx | 2 possibilitiesStackStyle & { shadowPreset?: ShadowPresetShadowPresetInverted } |
Undocumented props
| Name | Type | Default Value | Description | Usage count |
|---|---|---|---|---|
| $platform-web | any | |||
| accessibilityRole | any | |||
| accessibilityState | any | |||
| accessible | any | |||
| aria-checked | any | |||
| aria-disabled | any | |||
| aria-hidden | any | |||
| aria-label | any | |||
| aria-labelledby | any | |||
| aria-live | any | |||
| aria-orientation | any | |||
| aria-pressed | any | |||
| aria-selected | any | |||
| aria-valuemax | any | |||
| aria-valuemin | any | |||
| aria-valuenow | any | |||
| asChild | any | |||
| className | any | |||
| collapsable | any | |||
| data-animation-state | any | |||
| data-brand-icon | any | |||
| data-caret | any | |||
| data-phone-frame | any | |||
| data-pill | any | |||
| data-product | any | |||
| data-reveal | any | |||
| data-shift-slot-key | any | |||
| data-tab | any | |||
| data-tool-details-trigger | any | |||
| disabled | any | |||
| id | any | |||
| importantForAccessibility | any | |||
| inert | any | |||
| onBlur | any | |||
| onClick | any | |||
| onFocus | any | |||
| onHoverIn | any | |||
| onHoverOut | any | |||
| onLayout | any | |||
| onMouseDown | any | |||
| onMouseEnter | any | |||
| onMouseLeave | any | |||
| onPointerLeave | any | |||
| onPress | any | |||
| onPressIn | any | |||
| onPressOut | any | |||
| onTouchStart | any | |||
| ref | any | |||
| role | any | |||
| style | any | |||
| tabIndex | any | |||
| tag | any | |||
| testID | any |
Style API
Use sx for one-off adjustments. It accepts these style keys:
Each can be overridden per breakpoint with: