Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box may accept all system props. #1315

Merged
merged 32 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e97fdc7
add utility props to Box
VanAnderson Jun 22, 2021
4ccefb0
update box docs
VanAnderson Jun 22, 2021
26d08f6
export box props
VanAnderson Jun 22, 2021
29e6d9f
update snapshots
VanAnderson Jun 22, 2021
64adf68
Create green-worms-nail.md
VanAnderson Jun 22, 2021
6556f3f
AvatarStack story in storybook
VanAnderson Jun 22, 2021
3456605
Update .changeset/green-worms-nail.md
VanAnderson Jul 2, 2021
52143fc
Update docs/content/Box.md
VanAnderson Jul 2, 2021
403f03d
Remove duplicate border system prop definitions
colebemis Jul 19, 2021
8a2827b
Remove duplicate grid system props definitions
colebemis Jul 19, 2021
ae5efe8
Update FlexProps definition
colebemis Jul 19, 2021
3c58217
Remove duplicate position system prop definitions
colebemis Jul 19, 2021
9b15427
Update Box documentation
colebemis Jul 19, 2021
8f86f1f
Merge remote-tracking branch 'origin/main' into VanAnderson/add-box-p…
colebemis Jul 19, 2021
e24ab6f
Merge branch 'VanAnderson/add-box-props' of github.com:primer/compone…
colebemis Jul 19, 2021
b726076
Update BoxProps
colebemis Jul 19, 2021
12eeb7e
Update Box docs
colebemis Jul 19, 2021
54768f4
Update Box props
colebemis Jul 19, 2021
409d6a8
fix: Type 'DropdownButton' as 'button' (#1318)
smockle Jun 23, 2021
7f99eb6
chore: Set test directory via config rather than flag (#1319)
smockle Jun 23, 2021
f499d79
feat(useFocusZone): update active-descendant on mousemove (#1308)
dgreif Jun 24, 2021
bf779e2
fix: Split `<Item>` labels (#1320)
smockle Jun 25, 2021
c07b9cc
feat(Overlay): slide away from anchor based on position (#1322)
dgreif Jun 29, 2021
52c189e
Generate prop documentation (#1323)
colebemis Jul 2, 2021
78d0ca4
Improve treeshaking by setting package.json sideEffects (#1332)
mattcosta7 Jul 19, 2021
bc3991a
Update Box documentation
colebemis Jul 19, 2021
93f5932
Update BoxProps
colebemis Jul 19, 2021
5809e4c
Update Box docs
colebemis Jul 19, 2021
7a14818
Update Box props
colebemis Jul 19, 2021
f5d8302
Remove AvatarStack story
colebemis Jul 19, 2021
04d655d
Merge branch 'VanAnderson/add-box-props' of github.com:primer/compone…
colebemis Jul 19, 2021
ab9fb1f
Update .changeset/green-worms-nail.md
colebemis Jul 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-worms-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
colebemis marked this conversation as resolved.
Show resolved Hide resolved
---

`Box` now accepts all [styled system props](https://styled-system.com/table/).
86 changes: 62 additions & 24 deletions docs/content/Box.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Box can be used to create both{' '}
<Box as="span" color="text.inverse" bg="bg.successInverse">
inline
</Box>{' '}
and
<Box color="text.inverse" bg="bg.dangerInverse">
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
<Box color="text.secondary" bg="bg.tertiary" p={3}>
Hello
</Box>
```

## Props

<Props of={Box} />

Box also accepts all [styled system props](https://styled-system.com/table/).

## Examples

### Border on all sides

```jsx live
<Box borderColor="border.primary" borderWidth={1} borderStyle="solid" p={3}>
Hello
</Box>
```

### Border on one side

```jsx live
<Box borderColor="border.primary" borderBottomWidth={1} borderBottomStyle="solid" pb={3}>
Hello
</Box>
```

### Flexbox

Use Box to create [flexbox](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox) layouts.

```jsx live
<Box display="flex">
<Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid">
1
</Box>
<Box color="text.inverse" bg="bg.warningInverse" width={[1, 1, 1 / 2]}>
elements with fixed or responsive width and height,
<Box flexGrow={1} p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid">
2
</Box>
<Box color="text.inverse" bg="bg.infoInverse" p={4} mt={2}>
and more!
<Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid">
3
</Box>
</Box>
```

## 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
<Box display="grid" gridTemplateColumns="1fr 1fr" gridGap={3}>
<Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid">
1
</Box>
<Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid">
2
</Box>
<Box p={3} borderColor="border.primary" borderWidth={1} borderStyle="solid">
3
</Box>
</Box>
```
13 changes: 4 additions & 9 deletions src/BorderBox.tsx
Original file line number Diff line number Diff line change
@@ -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)<SystemBorderProps>`
${BORDER};
${sx};
`
export type BorderBoxProps = BoxProps

const BorderBox = styled(Box)``

BorderBox.defaultProps = {
borderWidth: '1px',
Expand All @@ -16,5 +12,4 @@ BorderBox.defaultProps = {
borderRadius: 2
}

export type BorderBoxProps = ComponentProps<typeof BorderBox>
export default BorderBox
54 changes: 47 additions & 7 deletions src/Box.tsx
Original file line number Diff line number Diff line change
@@ -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<SystemCommonProps & SystemFlexProps & SystemLayoutProps & SxProp>`
${COMMON}
${FLEX}
${LAYOUT}
${sx};
`
type StyledBoxProps = SpaceProps &
ColorProps &
TypographyProps &
LayoutProps &
FlexboxProps &
GridProps &
BackgroundProps &
BorderProps &
PositionProps &
ShadowProps &
SxProp

const Box = styled.div<StyledBoxProps>(
space,
color,
typography,
layout,
flexbox,
grid,
background,
border,
position,
shadow,
sx
)

export type BoxProps = ComponentProps<typeof Box>
export default Box
6 changes: 3 additions & 3 deletions src/Flex.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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)``

Flex.defaultProps = {
display: 'flex'
}

export type FlexProps = ComponentProps<typeof Flex>
export default Flex
11 changes: 4 additions & 7 deletions src/Grid.tsx
Original file line number Diff line number Diff line change
@@ -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)<SystemGridProps>`
${GRID};
`
export type GridProps = BoxProps

const Grid = styled(Box)``

Grid.defaultProps = {
display: 'grid'
}

export type GridProps = ComponentProps<typeof Grid>
export default Grid
9 changes: 2 additions & 7 deletions src/Position.tsx
Original file line number Diff line number Diff line change
@@ -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)<StyledPositionProps>`
${POSITION};
${sx};
`
const Position = styled(Box)<StyledPositionProps>``

export type PositionProps = ComponentProps<typeof Position>
export default Position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
exports[`Pagination renders consistently 1`] = `
.c1 {
display: inline-block;
display: inline-block;
}

.c2 {
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/__snapshots__/AvatarStack.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 0 additions & 16 deletions src/__tests__/__snapshots__/Box.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ exports[`Box renders padding 3`] = `
exports[`Box respects display 1`] = `
.c0 {
display: inline;
display: inline;
}

<div
Expand All @@ -153,7 +152,6 @@ exports[`Box respects display 1`] = `
exports[`Box respects display 2`] = `
.c0 {
display: inline-block;
display: inline-block;
}

<div
Expand All @@ -165,7 +163,6 @@ exports[`Box respects display 2`] = `
exports[`Box respects display 3`] = `
.c0 {
display: none;
display: none;
}

<div
Expand All @@ -177,19 +174,6 @@ exports[`Box respects display 3`] = `
exports[`Box respects display 4`] = `
.c0 {
display: none;
display: none;
}

@media screen and (min-width:544px) {
.c0 {
display: none;
}
}

@media screen and (min-width:768px) {
.c0 {
display: block;
}
}

@media screen and (min-width:544px) {
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/__snapshots__/Button.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ exports[`ButtonDanger renders correct disabled styles 1`] = `

exports[`ButtonGroup renders consistently 1`] = `
.c0 {
display: inline-block;
display: inline-block;
vertical-align: middle;
}
Expand Down
8 changes: 2 additions & 6 deletions src/__tests__/__snapshots__/CircleOcticon.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ exports[`CircleOcticon renders consistently 1`] = `
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 32px;
height: 32px;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
Expand All @@ -24,12 +26,6 @@ exports[`CircleOcticon renders consistently 1`] = `
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 32px;
height: 32px;
}

<div
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/__snapshots__/Dialog.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ exports[`Dialog Dialog.Header renders consistently 1`] = `
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
border-radius: 6px 6px 0px 0px;
border-bottom: 1px solid #e1e4e8;
}
Expand Down Expand Up @@ -122,10 +118,6 @@ Array [
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
border-radius: 6px 6px 0px 0px;
border-bottom: 1px solid #e1e4e8;
}
Expand Down
Loading