Skip to content

Commit 24be459

Browse files
authored
Merge branch 'main' into mp/rm-box-and-sx-from-listy-components
2 parents 3d86376 + 0f075d1 commit 24be459

File tree

15 files changed

+99
-74
lines changed

15 files changed

+99
-74
lines changed

.changeset/yummy-years-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': major
3+
---
4+
5+
Removes usage of Box component from other components.

packages/react/src/Button/ButtonBase.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, {forwardRef} from 'react'
22
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
3-
import Box from '../Box'
3+
import styled from 'styled-components'
4+
import sx from '../sx'
5+
import type {SxProp} from '../sx'
46
import type {ButtonProps} from './types'
57
import {getAlignContentSize} from './styles'
68
import {useRefObjectAsForwardedRef} from '../hooks/useRefObjectAsForwardedRef'
@@ -15,6 +17,12 @@ import {clsx} from 'clsx'
1517
import classes from './ButtonBase.module.css'
1618
import {isElement} from 'react-is'
1719

20+
// TODO: remove this when we remove the `sx` prop from buttons
21+
// Styled span component for button content that can handle sx prop
22+
const BoxTemporaryWorkaround = styled.span<SxProp>`
23+
${sx};
24+
`
25+
1826
const renderModuleVisual = (
1927
Visual: React.ElementType | React.ReactElement,
2028
loading: boolean,
@@ -92,7 +100,7 @@ const ButtonBase = forwardRef(
92100
className={block ? classes.ConditionalWrapper : undefined}
93101
data-loading-wrapper
94102
>
95-
<Box
103+
<BoxTemporaryWorkaround
96104
as={Component}
97105
sx={sxProp}
98106
aria-disabled={loading ? true : undefined}
@@ -129,8 +137,7 @@ const ButtonBase = forwardRef(
129137
)
130138
) : (
131139
<>
132-
<Box
133-
as="span"
140+
<BoxTemporaryWorkaround
134141
data-component="buttonContent"
135142
sx={getAlignContentSize(alignContent)}
136143
className={classes.ButtonContent}
@@ -182,7 +189,7 @@ const ButtonBase = forwardRef(
182189
)
183190
: null
184191
}
185-
</Box>
192+
</BoxTemporaryWorkaround>
186193
{
187194
/* If there is a trailing action, render it unless the button is in a loading state
188195
and there is no leading or trailing visual to replace with a loading spinner. */
@@ -196,7 +203,7 @@ const ButtonBase = forwardRef(
196203
}
197204
</>
198205
)}
199-
</Box>
206+
</BoxTemporaryWorkaround>
200207
{loading && (
201208
<VisuallyHidden>
202209
<AriaStatus id={loadingAnnouncementID}>{loadingAnnouncement}</AriaStatus>

packages/react/src/Label/Label.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: merge https://github.com/primer/react/pull/6631 which removes `Box` usage
2+
13
import {clsx} from 'clsx'
24
import Box from '../Box'
35
import classes from './Label.module.css'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.OverlayContainer {
2+
align-items: flex-start;
3+
display: flex;
4+
}
5+
6+
.OverlayInner {
7+
display: flex;
8+
flex-wrap: wrap;
9+
gap: var(--base-size-4);
10+
}
11+
12+
.CloseButton {
13+
flex-shrink: 0;
14+
}

packages/react/src/LabelGroup/LabelGroup.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import VisuallyHidden from '../_VisuallyHidden'
77
import {AnchoredOverlay} from '../AnchoredOverlay'
88
import {Button, IconButton} from '../Button'
99
import {useTheme} from '../ThemeProvider'
10+
import classes from './LabelGroup.module.css'
1011

1112
export type LabelGroupProps = {
1213
/** Customize the element type of the rendered container */
@@ -132,14 +133,14 @@ const OverlayToggle: React.FC<
132133
)}
133134
focusZoneSettings={{disabled: true}}
134135
>
135-
<div style={{alignItems: 'flex-start', display: 'flex', width: overlayWidth, padding: `${overlayPaddingPx}px`}}>
136-
<div style={{display: 'flex', flexWrap: 'wrap', gap: '4px'}}>{children}</div>
136+
<div className={classes.OverlayContainer} style={{width: overlayWidth, padding: `${overlayPaddingPx}px`}}>
137+
<div className={classes.OverlayInner}>{children}</div>
137138
<IconButton
138139
onClick={closeOverflowOverlay}
139140
icon={XIcon}
140141
aria-label="Close"
141142
variant="invisible"
142-
style={{flexShrink: 0}}
143+
className={classes.CloseButton}
143144
/>
144145
</div>
145146
</AnchoredOverlay>

packages/react/src/Pagination/Pagination.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@
120120
text-align: center;
121121
}
122122

123+
.TablePaginationSteps {
124+
display: inline-block;
125+
}
126+
123127
@media screen and (--viewportRange-narrow) {
124128
.TablePaginationSteps[data-hidden-viewport-ranges*='narrow'] > *:not(:first-child):not(:last-child) {
125129
display: none;

packages/react/src/Pagination/Pagination.stories.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,4 @@ Playground.argTypes = {
7878
disable: true,
7979
},
8080
},
81-
theme: {
82-
control: false,
83-
table: {
84-
disable: true,
85-
},
86-
},
8781
}

packages/react/src/Pagination/Pagination.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React from 'react'
2-
import Box from '../Box'
32
import {buildComponentData, buildPaginationModel, type PageDataProps} from './model'
43
import type {ResponsiveValue} from '../hooks/useResponsiveValue'
54
import {viewportRanges} from '../hooks/useResponsiveValue'
65
import {clsx} from 'clsx'
76
import classes from './Pagination.module.css'
8-
import {BoxWithFallback} from '../internal/components/BoxWithFallback'
97

108
const getViewportRangesToHidePages = (showPages: PaginationProps['showPages']) => {
119
if (showPages && typeof showPages !== 'boolean') {
@@ -33,7 +31,6 @@ export type PageProps = {
3331
} & Omit<PageDataProps['props'], 'as' | 'role'>
3432

3533
type UsePaginationPagesParameters = {
36-
theme?: Record<string, unknown> // set to theme type once /src/theme.js is converted
3734
pageCount: number
3835
currentPage: number
3936
onPageChange: (e: React.MouseEvent, n: number) => void
@@ -45,7 +42,6 @@ type UsePaginationPagesParameters = {
4542
}
4643

4744
function usePaginationPages({
48-
theme,
4945
pageCount,
5046
currentPage,
5147
onPageChange,
@@ -67,22 +63,22 @@ function usePaginationPages({
6763
if (renderPage && props.as !== 'span') {
6864
return renderPage({key, children: content, number: page.num, className: classes.Page, ...props})
6965
}
66+
const Component = props.as || 'a'
7067

7168
return (
7269
// @ts-ignore giving me grief about children and "as" props
73-
<BoxWithFallback as="a" key={key} theme={theme} className={clsx(classes.Page)} {...props}>
70+
<Component key={key} className={clsx(classes.Page)} {...props}>
7471
{content}
75-
</BoxWithFallback>
72+
</Component>
7673
)
7774
})
78-
}, [model, hrefBuilder, pageChange, renderPage, theme])
75+
}, [model, hrefBuilder, pageChange, renderPage])
7976

8077
return children
8178
}
8279

8380
export type PaginationProps = {
8481
className?: string
85-
theme?: Record<string, unknown>
8682
pageCount: number
8783
currentPage: number
8884
onPageChange?: (e: React.MouseEvent, n: number) => void
@@ -95,7 +91,6 @@ export type PaginationProps = {
9591

9692
function Pagination({
9793
className,
98-
theme: _theme,
9994
pageCount,
10095
currentPage,
10196
onPageChange = noop,
@@ -107,7 +102,6 @@ function Pagination({
107102
...rest
108103
}: PaginationProps) {
109104
const pageElements = usePaginationPages({
110-
theme: _theme,
111105
pageCount,
112106
currentPage,
113107
onPageChange,
@@ -119,20 +113,14 @@ function Pagination({
119113
})
120114

121115
return (
122-
<BoxWithFallback
123-
as="nav"
124-
className={clsx(classes.PaginationContainer, className)}
125-
aria-label="Pagination"
126-
{...rest}
127-
>
128-
<Box
129-
display="inline-block"
116+
<nav className={clsx(classes.PaginationContainer, className)} aria-label="Pagination" {...rest}>
117+
<div
130118
className={classes.TablePaginationSteps}
131119
data-hidden-viewport-ranges={getViewportRangesToHidePages(showPages).join(' ')}
132120
>
133121
{pageElements}
134-
</Box>
135-
</BoxWithFallback>
122+
</div>
123+
</nav>
136124
)
137125
}
138126

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.Placeholder {
2+
/* these are set in the component */
3+
--placeholder-width: ;
4+
--placeholder-height: ;
5+
6+
width: var(--placeholder-width, 100%);
7+
height: var(--placeholder-height);
8+
display: grid;
9+
place-items: center;
10+
background-color: var(--bgColor-inset);
11+
border-radius: var(--borderRadius-medium);
12+
border: var(--borderWidth-thin) solid var(--borderColor-muted);
13+
}

packages/react/src/Placeholder.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Box} from '.'
21
import type React from 'react'
2+
import classes from './Placeholder.module.css'
33

44
/** Private component used to render placeholders in storybook and documentation examples */
55
export const Placeholder: React.FC<
@@ -11,20 +11,17 @@ export const Placeholder: React.FC<
1111
}>
1212
> = ({width, height, id, label}) => {
1313
return (
14-
<Box
14+
<div
1515
id={id}
16-
sx={{
17-
width: width ?? '100%',
18-
height,
19-
display: 'grid',
20-
placeItems: 'center',
21-
bg: 'canvas.inset',
22-
borderRadius: 2,
23-
border: '1px solid',
24-
borderColor: 'border.subtle',
25-
}}
16+
className={classes.Placeholder}
17+
style={
18+
{
19+
'--placeholder-width': typeof width === 'number' ? `${width}px` : width,
20+
'--placeholder-height': typeof height === 'number' ? `${height}px` : height,
21+
} as React.CSSProperties
22+
}
2623
>
2724
{label}
28-
</Box>
25+
</div>
2926
)
3027
}

0 commit comments

Comments
 (0)