Paste

Design System

Box

A primitive component that can be used to create all block level styles in Paste

Status
alpha
Version
1.1.0
Sources
Storybook
Install
yarn add @twilio-paste/box

Guidelines#

The Box component is one of the pillars of our system. It can be any HTML element and can receive many of our token values as props. We use Box to build most of our other components.

About Box#

All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout. It consists of: margins, borders, padding, and the actual content.

The Box component is inspired from the “box model". It is a simple wrapper component that takes tokens instead of using CSS. The limited but scoped set of tokens allowed on Box act as guardrails. They provide quick and direct access to the Twilio design language while preventing any other value. We prevent other values to protect our product from inconsistent and inaccessible designs.

For this reason, we can use the Box component to build out most of the interfaces at Twilio. Using this component will make our products resilient to design changes and themeable.

Accessibility#

The Box component is an all purpose component. By default, it has no accessibility concerns. If you use the Box as a custom element, it is up to you to manage the resulting accessibility implications.

Be sure to use the as prop to select semantically meaningful HTML elements. By default the Box component renders as a div which doesn’t provide much meaning to the user.

Examples#

Parent box on the hill side
nested box 1 made out of ticky tacky
Nested box 2 may look the same

Composition Notes#

The Box component is used to compose other experiences. If you imagine everything on a webpage as a Box, you can see how they all come together. Let's assume we need to build a modal component: it has a header, a body and a footer. Here's how we’ll compose the modal using Box:

Header area
Body area
An inner box with margin and padding
Footer area

When to use Box#

The Paste component library aims to cover the widest range of base use-cases. Sometimes, product requirements are more specific than what is offered here. When no other component in Paste works, use the Box component to build new experiences.

Be wary of building slightly different versions of existing Paste components. If what you need is only a little different, try to constrain the design into one of our provided solutions. This will allow you to leverage more of our system and reduce your maintenance costs. On the surface our components may look simple or restrictive. They are often limited for very specific reasons, such as accessibility.

Do

Use Box to build new components and experiences.

Don't

Use Box to build slightly different versions of existing Paste components.

Do

Use Box to layout your page or to apply padding to your components.

Don't

Use inline CSS, the CSS Cascade, or classNames to add styles that Box can provide.

Do

Use Box with an 'as' prop to style custom HTML elements with tokens.

Don't

Use HTML elements for functionality covered by the Box component.


Usage Guide#

API#

Installation#

yarn add @twilio-paste/box

Usage#

import {Box} from '@twilio-paste/box';
<Box as="article" backgroundColor="colorBackgroundBody" padding="space60">
Foo
</Box>;

Props#

All the regular HTML attributes (role, aria-*, type, and so on) including the following custom props:

PropTypeDescriptionDefault
as?stringA custom HTML tag'div'
display?ResponsiveValue<CSS.DisplayProperty>
overflow?ResponsiveValue<CSS.OverflowProperty>
backgroundColor?ResponsiveValue<keyof ThemeShape['backgroundColors']>
width?ResponsiveValue<keyof ThemeShape['widths']>
minWidth?ResponsiveValue<keyof ThemeShape['minWidths']>
maxWidth?ResponsiveValue<keyof ThemeShape['maxWidths']>
height?ResponsiveValue<keyof ThemeShape['heights']>
minHeight?ResponsiveValue<keyof ThemeShape['minHeights']>
maxHeight?ResponsiveValue<keyof ThemeShape['maxHeights']>
margin?ResponsiveValue<keyof ThemeShape['space']>
marginTop?ResponsiveValue<keyof ThemeShape['space']>
marginRight?ResponsiveValue<keyof ThemeShape['space']>
marginBottom?ResponsiveValue<keyof ThemeShape['space']>
marginLeft?ResponsiveValue<keyof ThemeShape['space']>
padding?ResponsiveValue<keyof ThemeShape['space']>
paddingTop?ResponsiveValue<keyof ThemeShape['space']>
paddingRight?ResponsiveValue<keyof ThemeShape['space']>
paddingBottom?ResponsiveValue<keyof ThemeShape['space']>
paddingLeft?ResponsiveValue<keyof ThemeShape['space']>
borderRadius?ResponsiveValue<keyof ThemeShape['radii']>
borderTopLeftRadius?ResponsiveValue<keyof ThemeShape['radii']>
borderTopRightRadius?ResponsiveValue<keyof ThemeShape['radii']>
borderBottomRightRadius?ResponsiveValue<keyof ThemeShape['radii']>
borderBottomLeftRadius?ResponsiveValue<keyof ThemeShape['radii']>
borderWidth?ResponsiveValue<keyof ThemeShape['borderWidths']>
borderTopWidth?ResponsiveValue<keyof ThemeShape['borderWidths']>
borderRightWidth?ResponsiveValue<keyof ThemeShape['borderWidths']>
borderBottomWidth?ResponsiveValue<keyof ThemeShape['borderWidths']>
borderLeftWidth?ResponsiveValue<keyof ThemeShape['borderWidths']>
borderColor?ResponsiveValue<keyof ThemeShape['borderColors']>
borderTopColor?ResponsiveValue<keyof ThemeShape['borderColors']>
borderRightColor?ResponsiveValue<keyof ThemeShape['borderColors']>
borderBottomColor?ResponsiveValue<keyof ThemeShape['borderColors']>
borderLeftColor?ResponsiveValue<keyof ThemeShape['borderColors']>
borderStyle?ResponsiveValue<CSS.BorderStyleProperty>
boxshadow?ResponsiveValue<keyof ThemeShape['shadows']>
zIndex?ResponsiveValue<keyof ThemeShape['zIndices']>

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

1.1.0 (2019-10-31)

Features#

  • update types package to styled-system v5 format (#154) (117c41e)

1.0.0 (2019-10-29)

Features#

BREAKING CHANGES#

  • box: many Box API changes

  • fix(theme-tokens): add sizes key for styled-system responsiveness

  • fix(absolute): update to newer Box

  • fix(types): allow for responsive values via array

  • fix(box): update story and light tweaks to OverflowProps

  • chore: update yarn.lock file

  • fix(types): many more types fixes

refactor: moved ValueOf into types package

  • fix(box): eslint error in story

  • fix(box): using the correct BorderProps definition

fix: we shouldn't allow users to pass the border shorthand, it circumvents tokens

  • fix: lint errors

  • fix(website): update box docs

  • fix(storybook): use theme breakpoints

0.3.1 (2019-09-16)

Note: Version bump only for package @twilio-paste/box

0.3.0 (2019-08-15)

Bug Fixes#

Features#

  • ComponentHeader component, component overview fixes, more (#20) (875e124)
  • website: Add the tokens page (#19) (878d3c5)