Box

A general-purpose layout primitive for applying token-based padding, background, border, and border-radius without writing custom CSS.

import { ... } from '@corndev/ui'
padding sm + secondary background
padding md + border + radius md
padding lg + border + radius lg
paddingX xl, paddingY sm

HTML

No JavaScript required — these classes are the whole component.

<div class="corn-box" data-padding="md" data-background="secondary" data-radius="md">Content</div>

Classes

Class
.corn-box

Attributes

AttributeValues
data-paddingxs|sm|md|lg|xl
data-padding-xxs|sm|md|lg|xl
data-padding-yxs|sm|md|lg|xl
data-backgroundprimary|secondary|tertiary
data-borderpresent or absent
data-radiussm|md|lg

Vanilla JS

Optional. createBox only adds and removes the classes and attributes above, so the HTML is equivalent. Reach for it when you need to change options at runtime.

import { createBox } from '@corndev/ui';
import '@corndev/ui/theme';

const el = document.querySelector('#target');
const instance = createBox(el, { /* options */ });

Options

OptionTypeDefaultDescription
padding'xs'|'sm'|'md'|'lg'|'xl'|'none''none'
paddingX'xs'|'sm'|'md'|'lg'|'xl'|'none'undefinedOverrides horizontal padding
paddingY'xs'|'sm'|'md'|'lg'|'xl'|'none'undefinedOverrides vertical padding
background'primary'|'secondary'|'tertiary'|'none''none'
borderbooleanfalse
radius'sm'|'md'|'lg'|'none''none'

React

Box — from @corndev/ui-react.

Props

PropTypeDefaultDescription
padding'xs'|'sm'|'md'|'lg'|'xl'|'none''none'
paddingX'xs'|'sm'|'md'|'lg'|'xl'|'none'undefinedOverrides horizontal padding
paddingY'xs'|'sm'|'md'|'lg'|'xl'|'none'undefinedOverrides vertical padding
background'primary'|'secondary'|'tertiary'|'none''none'
borderbooleanfalse
radius'sm'|'md'|'lg'|'none''none'
asReact.ElementType'div'
childrenReact.ReactNodeundefined
classNamestringundefined

Padding

padding xs
padding sm
padding md
padding lg
padding xl
<Box padding="xs">...</Box>
<Box padding="sm">...</Box>
<Box padding="md">...</Box>
<Box padding="lg">...</Box>
<Box padding="xl">...</Box>

Independent X / Y padding

Wide horizontal, tight vertical
<Box paddingX="xl" paddingY="sm">...</Box>

Background

primary
secondary
tertiary
<Box background="primary">...</Box>
<Box background="secondary">...</Box>
<Box background="tertiary">...</Box>

Border and radius

radius sm
radius md
radius lg
<Box border radius="sm">...</Box>
<Box border radius="md">...</Box>
<Box border radius="lg">...</Box>

Polymorphic as prop

Rendered as a <section>

<Box as="section" padding="md" background="secondary">...</Box>
<Box as="article" padding="md">...</Box>