diff --git a/.changeset/green-worms-nail.md b/.changeset/green-worms-nail.md new file mode 100644 index 00000000000..61c682d288e --- /dev/null +++ b/.changeset/green-worms-nail.md @@ -0,0 +1,5 @@ +--- +"@primer/components": minor +--- + +`Box` now accepts all [styled system props](https://styled-system.com/table/). diff --git a/docs/content/Box.md b/docs/content/Box.md index ea2b5dd8ac0..a5d101c9bb8 100644 --- a/docs/content/Box.md +++ b/docs/content/Box.md @@ -2,35 +2,73 @@ title: Box --- -The Box component serves as a wrapper component for most layout related needs. Use Box to set values such as `display`, `width`, `height`, and more. See the LAYOUT section of our [System Props](/system-props) documentation for the full list of available props. In practice, this component is used frequently as a wrapper around other components to achieve Box Model related styling. - -## Default example - -```jsx live live - - Box can be used to create both{' '} - - inline - {' '} - and - - block-level elements, +import {Props} from '../src/props' +import {Box} from '@primer/components' + +Box is a low-level utility component that accepts [styled system props](https://styled-system.com/table/) to enable custom theme-aware styling. + +```jsx live + + Hello + +``` + +## Props + + + +Box also accepts all [styled system props](https://styled-system.com/table/). + +## Examples + +### Border on all sides + +```jsx live + + Hello + +``` + +### Border on one side + +```jsx live + + Hello + +``` + +### Flexbox + +Use Box to create [flexbox](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox) layouts. + +```jsx live + + + 1 - - elements with fixed or responsive width and height, + + 2 - - and more! + + 3 ``` -## System props +### Grid -Box components get the `COMMON`, `LAYOUT`, and `FLEX` categories of system props. Read our [System Props](/system-props) doc page for a full list of available props. +Use Box to create [grid](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids) layouts. -## Component props - -| Prop name | Type | Default | Description | -| :-------- | :----- | :-----: | :---------------------------------- | -| as | String | `div` | sets the HTML tag for the component | +```jsx live + + + 1 + + + 2 + + + 3 + + +``` diff --git a/src/BorderBox.tsx b/src/BorderBox.tsx index 3890718cbfe..8b835069130 100644 --- a/src/BorderBox.tsx +++ b/src/BorderBox.tsx @@ -1,13 +1,9 @@ import styled from 'styled-components' -import Box from './Box' -import {BORDER, SystemBorderProps} from './constants' -import sx from './sx' -import {ComponentProps} from './utils/types' +import Box, {BoxProps} from './Box' -const BorderBox = styled(Box)` - ${BORDER}; - ${sx}; -` +export type BorderBoxProps = BoxProps + +const BorderBox = styled(Box)`` BorderBox.defaultProps = { borderWidth: '1px', @@ -16,5 +12,4 @@ BorderBox.defaultProps = { borderRadius: 2 } -export type BorderBoxProps = ComponentProps export default BorderBox diff --git a/src/Box.tsx b/src/Box.tsx index d5790f69ddd..12c2309dbe0 100644 --- a/src/Box.tsx +++ b/src/Box.tsx @@ -1,14 +1,54 @@ import styled from 'styled-components' -import {COMMON, FLEX, LAYOUT, SystemCommonProps, SystemFlexProps, SystemLayoutProps} from './constants' +import { + background, + BackgroundProps, + border, + BorderProps, + color, + ColorProps, + flexbox, + FlexboxProps, + grid, + GridProps, + layout, + LayoutProps, + position, + PositionProps, + shadow, + ShadowProps, + space, + SpaceProps, + typography, + TypographyProps +} from 'styled-system' import sx, {SxProp} from './sx' import {ComponentProps} from './utils/types' -const Box = styled.div` - ${COMMON} - ${FLEX} - ${LAYOUT} - ${sx}; -` +type StyledBoxProps = SpaceProps & + ColorProps & + TypographyProps & + LayoutProps & + FlexboxProps & + GridProps & + BackgroundProps & + BorderProps & + PositionProps & + ShadowProps & + SxProp + +const Box = styled.div( + space, + color, + typography, + layout, + flexbox, + grid, + background, + border, + position, + shadow, + sx +) export type BoxProps = ComponentProps export default Box diff --git a/src/Flex.tsx b/src/Flex.tsx index b026b8675f8..4218fc3daa5 100644 --- a/src/Flex.tsx +++ b/src/Flex.tsx @@ -1,6 +1,7 @@ import styled from 'styled-components' -import Box from './Box' -import {ComponentProps} from './utils/types' +import Box, {BoxProps} from './Box' + +export type FlexProps = BoxProps const Flex = styled(Box)`` @@ -8,5 +9,4 @@ Flex.defaultProps = { display: 'flex' } -export type FlexProps = ComponentProps export default Flex diff --git a/src/Grid.tsx b/src/Grid.tsx index 04d7e2e0676..9d8c5880881 100644 --- a/src/Grid.tsx +++ b/src/Grid.tsx @@ -1,15 +1,12 @@ import styled from 'styled-components' -import Box from './Box' -import {GRID, SystemGridProps} from './constants' -import {ComponentProps} from './utils/types' +import Box, {BoxProps} from './Box' -const Grid = styled(Box)` - ${GRID}; -` +export type GridProps = BoxProps + +const Grid = styled(Box)`` Grid.defaultProps = { display: 'grid' } -export type GridProps = ComponentProps export default Grid diff --git a/src/Position.tsx b/src/Position.tsx index 41153e5c9a1..51806af7cb0 100644 --- a/src/Position.tsx +++ b/src/Position.tsx @@ -1,16 +1,11 @@ import React from 'react' import styled from 'styled-components' import Box from './Box' -import {POSITION, SystemPositionProps} from './constants' -import sx from './sx' import {ComponentProps} from './utils/types' -type StyledPositionProps = {as?: React.ElementType} & SystemPositionProps +type StyledPositionProps = {as?: React.ElementType} -const Position = styled(Box)` - ${POSITION}; - ${sx}; -` +const Position = styled(Box)`` export type PositionProps = ComponentProps export default Position diff --git a/src/__tests__/Pagination/__snapshots__/Pagination.tsx.snap b/src/__tests__/Pagination/__snapshots__/Pagination.tsx.snap index a8933148916..a591902ba47 100644 --- a/src/__tests__/Pagination/__snapshots__/Pagination.tsx.snap +++ b/src/__tests__/Pagination/__snapshots__/Pagination.tsx.snap @@ -3,7 +3,6 @@ exports[`Pagination renders consistently 1`] = ` .c1 { display: inline-block; - display: inline-block; } .c2 { diff --git a/src/__tests__/__snapshots__/AvatarStack.tsx.snap b/src/__tests__/__snapshots__/AvatarStack.tsx.snap index d2d0d3c1302..1ad913e36db 100644 --- a/src/__tests__/__snapshots__/AvatarStack.tsx.snap +++ b/src/__tests__/__snapshots__/AvatarStack.tsx.snap @@ -2,10 +2,6 @@ exports[`Avatar renders consistently 1`] = ` .c1 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -194,10 +190,6 @@ exports[`Avatar renders consistently 1`] = ` exports[`Avatar respects alignRight props 1`] = ` .c1 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; diff --git a/src/__tests__/__snapshots__/Box.tsx.snap b/src/__tests__/__snapshots__/Box.tsx.snap index aafa44314d3..d897c47fe0f 100644 --- a/src/__tests__/__snapshots__/Box.tsx.snap +++ b/src/__tests__/__snapshots__/Box.tsx.snap @@ -141,7 +141,6 @@ exports[`Box renders padding 3`] = ` exports[`Box respects display 1`] = ` .c0 { display: inline; - display: inline; }
and 1`] = ` .c0 { background-color: #ffeef0; - position: relative; border-width: 1px; border-style: solid; border-color: #e1e4e8; @@ -47,7 +46,6 @@ exports[`PointerBox passes the "bg" prop to both and 1`] = ` exports[`PointerBox passes the "borderColor" prop to both and 1`] = ` .c0 { - position: relative; border-color: #d73a49; border-width: 1px; border-style: solid; @@ -91,7 +89,6 @@ exports[`PointerBox passes the "borderColor" prop to both and in with relative positioning 1`] = ` .c0 { - position: relative; border-width: 1px; border-style: solid; border-color: #e1e4e8; @@ -135,7 +132,6 @@ exports[`PointerBox renders a in with relative positioning 1 exports[`PointerBox renders consistently 1`] = ` .c0 { - position: relative; border-width: 1px; border-style: solid; border-color: #e1e4e8; diff --git a/src/__tests__/__snapshots__/Timeline.tsx.snap b/src/__tests__/__snapshots__/Timeline.tsx.snap index 528e91a3765..93109ee50c1 100644 --- a/src/__tests__/__snapshots__/Timeline.tsx.snap +++ b/src/__tests__/__snapshots__/Timeline.tsx.snap @@ -2,10 +2,6 @@ exports[`Timeline renders consistently 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -23,10 +19,6 @@ exports[`Timeline renders consistently 1`] = ` exports[`Timeline renders with clipSidebar prop 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -57,10 +49,13 @@ exports[`Timeline.Badge renders consistently 1`] = ` } .c1 { - color: #586069; - background-color: #e1e4e8; margin-right: 8px; margin-left: -15px; + color: #586069; + background-color: #e1e4e8; + overflow: hidden; + width: 32px; + height: 32px; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -76,13 +71,6 @@ exports[`Timeline.Badge renders consistently 1`] = ` -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; - overflow: hidden; - width: 32px; - height: 32px; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; border-radius: 50%; border: 2px solid #ffffff; } @@ -103,10 +91,6 @@ exports[`Timeline.Badge renders consistently 1`] = ` exports[`Timeline.Item renders consistently 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -139,10 +123,6 @@ exports[`Timeline.Item renders consistently 1`] = ` exports[`Timeline.Item renders with condensed prop 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox;