Skip to content

Commit 4097d53

Browse files
authored
[Box] Code cleanup 💅 (#7435)
I found Box was getting a little tough to read. Removing unnecessary spread operators and shuffling some ternaries cleaned things up a bit Output remains the same and tests should pass ![image](https://screenshot.click/18-31-2t0bo-v9aq8.png)
1 parent c5cfe90 commit 4097d53

File tree

2 files changed

+50
-59
lines changed

2 files changed

+50
-59
lines changed

.changeset/eight-shoes-compare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Cleaned up styles on Box

polaris-react/src/components/Box/Box.tsx

Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {createElement, forwardRef, ReactNode} from 'react';
1+
import React, {createElement, forwardRef, PropsWithChildren} from 'react';
22
import type {
33
DepthShadowAlias,
44
SpacingSpaceScale,
@@ -135,7 +135,7 @@ interface Spacing {
135135
top: SpacingSpaceScale;
136136
}
137137

138-
export interface BoxProps {
138+
export interface BoxProps extends PropsWithChildren {
139139
/** HTML Element type */
140140
as?: Element;
141141
/** Background color */
@@ -160,8 +160,6 @@ export interface BoxProps {
160160
borderRadiusTopLeft?: BorderRadiusTokenScale;
161161
/** Top right border radius */
162162
borderRadiusTopRight?: BorderRadiusTokenScale;
163-
/** Inner content */
164-
children: ReactNode;
165163
/** Color of children */
166164
color?: ColorTokenScale;
167165
/** HTML id attribute */
@@ -245,61 +243,49 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
245243
} as Spacing;
246244

247245
const style = {
248-
...(background
249-
? {'--pc-box-background': `var(--p-${background})`}
250-
: undefined),
251-
...(borders.bottom
252-
? {'--pc-box-border-bottom': `var(--p-border-${borders.bottom})`}
253-
: undefined),
254-
...(borders.left
255-
? {'--pc-box-border-left': `var(--p-border-${borders.left})`}
256-
: undefined),
257-
...(borders.right
258-
? {'--pc-box-border-right': `var(--p-border-${borders.right})`}
259-
: undefined),
260-
...(borders.top
261-
? {'--pc-box-border-top': `var(--p-border-${borders.top})`}
262-
: undefined),
263-
...(borderRadiuses.bottomLeft
264-
? {
265-
'--pc-box-border-radius-bottom-left': `var(--p-border-radius-${borderRadiuses.bottomLeft})`,
266-
}
267-
: undefined),
268-
...(borderRadiuses.bottomRight
269-
? {
270-
'--pc-box-border-radius-bottom-right': `var(--p-border-radius-${borderRadiuses.bottomRight})`,
271-
}
272-
: undefined),
273-
...(borderRadiuses.topLeft
274-
? {
275-
'--pc-box-border-radius-top-left': `var(--p-border-radius-${borderRadiuses.topLeft})`,
276-
}
277-
: undefined),
278-
...(borderRadiuses.topRight
279-
? {
280-
'--pc-box-border-radius-top-right': `var(--p-border-radius-${borderRadiuses.topRight})`,
281-
}
282-
: undefined),
283-
...(color ? {'--pc-box-color': `var(--p-${color})`} : undefined),
284-
...(maxWidth ? {'--pc-box-max-width': `${maxWidth}`} : undefined),
285-
...(overflowX ? {'--pc-box-overflow-x': `${overflowX}`} : undefined),
286-
...(overflowY ? {'--pc-box-overflow-y': `${overflowY}`} : undefined),
287-
...(paddings.bottom
288-
? {'--pc-box-padding-bottom': `var(--p-space-${paddings.bottom})`}
289-
: undefined),
290-
...(paddings.left
291-
? {'--pc-box-padding-left': `var(--p-space-${paddings.left})`}
292-
: undefined),
293-
...(paddings.right
294-
? {'--pc-box-padding-right': `var(--p-space-${paddings.right})`}
295-
: undefined),
296-
...(paddings.top
297-
? {'--pc-box-padding-top': `var(--p-space-${paddings.top})`}
298-
: undefined),
299-
...(shadow
300-
? {'--pc-box-shadow': `var(--p-shadow-${shadow})`}
301-
: undefined),
302-
...(width ? {'--pc-box-width': `${width}`} : undefined),
246+
'--pc-box-color': color ? `var(--p-${color})` : undefined,
247+
'--pc-box-background': background ? `var(--p-${background})` : undefined,
248+
'--pc-box-border-bottom': borders.bottom
249+
? `var(--p-border-${borders.bottom})`
250+
: undefined,
251+
'--pc-box-border-left': borders.left
252+
? `var(--p-border-${borders.left})`
253+
: undefined,
254+
'--pc-box-border-right': borders.right
255+
? `var(--p-border-${borders.right})`
256+
: undefined,
257+
'--pc-box-border-top': borders.top
258+
? `var(--p-border-${borders.top})`
259+
: undefined,
260+
'--pc-box-border-radius-bottom-left': borderRadiuses.bottomLeft
261+
? `var(--p-border-radius-${borderRadiuses.bottomLeft})`
262+
: undefined,
263+
'--pc-box-border-radius-bottom-right': borderRadiuses.bottomRight
264+
? `var(--p-border-radius-${borderRadiuses.bottomRight})`
265+
: undefined,
266+
'--pc-box-border-radius-top-left': borderRadiuses.topLeft
267+
? `var(--p-border-radius-${borderRadiuses.topLeft})`
268+
: undefined,
269+
'--pc-box-border-radius-top-right': borderRadiuses.topRight
270+
? `var(--p-border-radius-${borderRadiuses.topRight})`
271+
: undefined,
272+
'--pc-box-max-width': maxWidth ?? undefined,
273+
'--pc-box-overflow-x': overflowX ?? undefined,
274+
'--pc-box-overflow-y': overflowY ?? undefined,
275+
'--pc-box-padding-bottom': paddings.bottom
276+
? `var(--p-space-${paddings.bottom})`
277+
: undefined,
278+
'--pc-box-padding-left': paddings.left
279+
? `var(--p-space-${paddings.left})`
280+
: undefined,
281+
'--pc-box-padding-right': paddings.right
282+
? `var(--p-space-${paddings.right})`
283+
: undefined,
284+
'--pc-box-padding-top': paddings.top
285+
? `var(--p-space-${paddings.top})`
286+
: undefined,
287+
'--pc-box-shadow': shadow ? `var(--p-shadow-${shadow})` : undefined,
288+
'--pc-box-width': width ?? undefined,
303289
} as React.CSSProperties;
304290

305291
const className = classNames(styles.Box);

0 commit comments

Comments
 (0)