Skip to content

Commit d3926d1

Browse files
authored
chore(Box): Mark Box and its props as deprecated (#5763)
1 parent bd4ac58 commit d3926d1

File tree

6 files changed

+75
-7
lines changed

6 files changed

+75
-7
lines changed

.changeset/dry-crabs-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
chore(Box): Mark Box and its props as deprecated
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Migration away from `Box`
2+
3+
## Why Migrate?
4+
5+
The `Box` component is a utility component that provides a convenient way to apply styles to elements and is simply a `div` element by default. However, it can be less performant than using standard HTML elements with CSS Modules. It has now been deprecated.
6+
7+
### Box using the `sx` prop
8+
9+
Replace the Box component with a standard HTML element such as `div`.
10+
11+
```jsx
12+
<Box sx={{p: 3, bg: 'gray.1'}}>Content here</Box>
13+
```
14+
15+
```jsx
16+
<div className={classes.example}>Content here</div>
17+
```
18+
19+
### Box using the `as` prop
20+
21+
If the Box is currently using the `as` prop to render a different HTML element, make sure to use that element instead.
22+
23+
```jsx
24+
<Box as="section" sx={{p: 3, bg: 'gray.1'}}>
25+
Content here
26+
</Box>
27+
```
28+
29+
```jsx
30+
<section className={classes.example}>Content here</section>
31+
```
32+
33+
### Box using style attributes
34+
35+
If the Box is using style attributes, you can replace it with a standard HTML element and use CSS Modules to apply the styles.
36+
37+
```jsx
38+
<Box minWidth={200} maxWidth={400} sx={{p: 3, bg: 'gray.1'}}>
39+
Content here
40+
</Box>
41+
```
42+
43+
```jsx
44+
<div className={clsx(classes.example)}>Content here</div>
45+
```
46+
47+
```css
48+
.example {
49+
padding: 16px;
50+
background-color: var(--gray-1);
51+
min-width: 200px;
52+
max-width: 400px;
53+
}
54+
```

packages/react/src/Box/Box.docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "box",
33
"name": "Box",
4-
"status": "beta",
4+
"status": "deprecated",
55
"a11yReviewed": false,
66
"stories": [],
77
"importPath": "@primer/react",

packages/react/src/Box/Box.features.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {Meta} from '@storybook/react'
33
import Box from './Box'
44

55
export default {
6-
title: 'Components/Box/Features',
6+
title: 'Deprecated/Components/Box/Features',
77
component: Box,
88
} as Meta<typeof Box>
99

packages/react/src/Box/Box.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {Meta, StoryFn} from '@storybook/react'
33
import Box from './Box'
44

55
export default {
6-
title: 'Components/Box',
6+
title: 'Deprecated/Components/Box',
77
component: Box,
88
} as Meta<typeof Box>
99

packages/react/src/Box/Box.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ import type {
1212
TypographyProps,
1313
} from 'styled-system'
1414
import {background, border, color, flexbox, grid, layout, position, shadow, space, typography} from 'styled-system'
15-
import type {BetterSystemStyleObject} from '../sx'
15+
import type {SxProp} from '../sx'
1616
import sx from '../sx'
1717
import type {ComponentProps} from '../utils/types'
1818

19-
type StyledBoxProps = {
20-
sx?: BetterSystemStyleObject
21-
} & SpaceProps &
19+
type StyledBoxProps = SxProp &
20+
SpaceProps &
2221
ColorProps &
2322
TypographyProps &
2423
LayoutProps &
@@ -29,6 +28,11 @@ type StyledBoxProps = {
2928
PositionProps &
3029
ShadowProps
3130

31+
/**
32+
* @deprecated The Box component is deprecated. Replace with a `div` or
33+
* appropriate HTML element instead, with CSS modules for styling.
34+
* @see https://github.com/primer/react/blob/main/contributor-docs/migration-from-box.md
35+
*/
3236
const Box = styled.div<StyledBoxProps>(
3337
space,
3438
color,
@@ -43,5 +47,10 @@ const Box = styled.div<StyledBoxProps>(
4347
sx,
4448
)
4549

50+
/**
51+
* @deprecated The Box component is deprecated. Replace with a `div` or
52+
* appropriate HTML element instead, with CSS modules for styling.
53+
* @see https://github.com/primer/react/blob/main/contributor-docs/migration-from-box.md
54+
*/
4655
export type BoxProps = ComponentProps<typeof Box>
4756
export default Box

0 commit comments

Comments
 (0)