Skip to content

Commit 456480e

Browse files
committed
[Layout foundations] Refactor and add border and borderRadius props
1 parent ff6c76a commit 456480e

File tree

2 files changed

+105
-83
lines changed

2 files changed

+105
-83
lines changed

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

Lines changed: 8 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
padding-left: var(--pc-box-padding-left, initial);
1010
padding-right: var(--pc-box-padding-right, initial);
1111
padding-top: var(--pc-box-padding-top, initial);
12+
border-bottom-left-radius: var(--pc-box-border-radius-bottom-left, initial);
13+
border-bottom-right-radius: var(--pc-box-border-radius-bottom-right, initial);
14+
border-top-left-radius: var(--pc-box-border-radius-top-left, initial);
15+
border-top-right-radius: var(--pc-box-border-radius-top-right, initial);
16+
border-bottom: var(--pc-box-border-bottom, initial);
17+
border-left: var(--pc-box-border-left, initial);
18+
border-right: var(--pc-box-border-right, initial);
19+
border-top: var(--pc-box-border-top, initial);
1220
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
1321
}
1422

@@ -104,86 +112,6 @@
104112
background-color: var(--p-overlay);
105113
}
106114

107-
.radius-05 {
108-
border-radius: var(--p-border-radius-05);
109-
}
110-
111-
.radius-1 {
112-
border-radius: var(--p-border-radius-1);
113-
}
114-
115-
.radius-2 {
116-
border-radius: var(--p-border-radius-2);
117-
}
118-
119-
.radius-3 {
120-
border-radius: var(--p-border-radius-3);
121-
}
122-
123-
.radius-4 {
124-
border-radius: var(--p-border-radius-4);
125-
}
126-
127-
.radius-5 {
128-
border-radius: var(--p-border-radius-5);
129-
}
130-
131-
.radius-6 {
132-
border-radius: var(--p-border-radius-6);
133-
}
134-
135-
.radius-base {
136-
border-radius: var(--p-border-radius-base);
137-
}
138-
139-
.radius-large {
140-
border-radius: var(--p-border-radius-large);
141-
}
142-
143-
.radius-half {
144-
border-radius: var(--p-border-radius-half);
145-
}
146-
147-
.width-1 {
148-
border: var(--p-border-width-1) solid;
149-
}
150-
151-
.width-2 {
152-
border: var(--p-border-width-2) solid;
153-
}
154-
155-
.width-3 {
156-
border: var(--p-border-width-3) solid;
157-
}
158-
159-
.width-4 {
160-
border: var(--p-border-width-4) solid;
161-
}
162-
163-
.width-5 {
164-
border: var(--p-border-width-5) solid;
165-
}
166-
167-
.base {
168-
border: var(--p-border-base);
169-
}
170-
171-
.dark {
172-
border: var(--p-border-dark);
173-
}
174-
175-
.transparent {
176-
border: var(--p-border-transparent);
177-
}
178-
179-
.divider {
180-
border: var(--p-border-divider);
181-
}
182-
183-
.divider-on-dark {
184-
border: var(--p-border-divider-on-dark);
185-
}
186-
187115
.shadowBase {
188116
box-shadow: var(--p-shadow-base);
189117
}

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

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,34 @@ type Shadow = 'default' | 'transparent' | 'faint' | 'deep';
3636
type ShapeTokenGroup = typeof shape;
3737
type ShapeTokenName = keyof ShapeTokenGroup;
3838

39-
type BorderTokenScale = ShapeTokenName extends `border-${infer Scale}`
39+
type BorderShapeTokenScale = ShapeTokenName extends `border-${infer Scale}`
4040
? Scale
4141
: never;
4242

43+
type BorderTokenScale = Exclude<
44+
BorderShapeTokenScale,
45+
`radius-${string}` | `width-${string}`
46+
>;
47+
48+
type Border = {
49+
bottom: BorderTokenScale;
50+
left: BorderTokenScale;
51+
right: BorderTokenScale;
52+
top: BorderTokenScale;
53+
};
54+
55+
type BorderRadiusTokenScale = Extract<
56+
BorderShapeTokenScale,
57+
`radius-${string}`
58+
>;
59+
60+
type BorderRadius = {
61+
bottomLeft: BorderRadiusTokenScale | '';
62+
bottomRight: BorderRadiusTokenScale | '';
63+
topLeft: BorderRadiusTokenScale | '';
64+
topRight: BorderRadiusTokenScale | '';
65+
};
66+
4367
type SpacingTokenGroup = typeof spacing;
4468
type SpacingTokenName = keyof SpacingTokenGroup;
4569

@@ -60,6 +84,24 @@ interface BoxBaseProps {
6084
background?: Background;
6185
/** Border styling of the Box */
6286
border?: BorderTokenScale;
87+
/** Bottom border styling of the Box */
88+
borderBottom?: BorderTokenScale;
89+
/** Left border styling of the Box */
90+
borderLeft?: BorderTokenScale;
91+
/** Right border styling of the Box */
92+
borderRight?: BorderTokenScale;
93+
/** Top border styling of the Box */
94+
borderTop?: BorderTokenScale;
95+
/** Border radius of the Box */
96+
borderRadius?: BorderRadiusTokenScale;
97+
/** Bottom left border radius of the Box */
98+
borderRadiusBottomLeft?: BorderRadiusTokenScale;
99+
/** Bottom right border radius of the Box */
100+
borderRadiusBottomRight?: BorderRadiusTokenScale;
101+
/** Top left border radius of the Box */
102+
borderRadiusTopLeft?: BorderRadiusTokenScale;
103+
/** Top right border radius of the Box */
104+
borderRadiusTopRight?: BorderRadiusTokenScale;
63105
/** Inner content of the Box */
64106
children: ReactNode;
65107
/** Spacing outside of the Box */
@@ -95,7 +137,16 @@ export const Box = forwardRef(
95137
{
96138
as: Component = 'div',
97139
background,
98-
border,
140+
border = '',
141+
borderBottom = '',
142+
borderLeft = '',
143+
borderRight = '',
144+
borderTop = '',
145+
borderRadius = '',
146+
borderRadiusBottomLeft = '',
147+
borderRadiusBottomRight = '',
148+
borderRadiusTopLeft = '',
149+
borderRadiusTopRight = '',
99150
children,
100151
margin = '',
101152
marginBottom = '',
@@ -111,6 +162,26 @@ export const Box = forwardRef(
111162
},
112163
ref,
113164
) => {
165+
const borders = {
166+
bottom: borderBottom ? borderBottom : border,
167+
left: borderLeft ? borderLeft : border,
168+
right: borderRight ? borderRight : border,
169+
top: borderTop ? borderTop : border,
170+
} as Border;
171+
172+
console.log({borders});
173+
174+
const borderRadiuses = {
175+
bottomLeft: borderRadiusBottomLeft
176+
? borderRadiusBottomLeft
177+
: borderRadius,
178+
bottomRight: borderRadiusBottomRight
179+
? borderRadiusBottomRight
180+
: borderRadius,
181+
topLeft: borderRadiusTopLeft ? borderRadiusTopLeft : borderRadius,
182+
topRight: borderRadiusTopRight ? borderRadiusTopRight : borderRadius,
183+
} as BorderRadius;
184+
114185
const margins = {
115186
bottom: marginBottom ? marginBottom : margin,
116187
left: marginLeft ? marginLeft : margin,
@@ -148,12 +219,35 @@ export const Box = forwardRef(
148219
'--pc-box-padding-top': paddings.top
149220
? `var(--p-space-${paddings.top})`
150221
: '',
222+
'--pc-box-border-bottom': borders.bottom
223+
? `var(--p-border-${borders.bottom})`
224+
: '',
225+
'--pc-box-border-left': borders.left
226+
? `var(--p-border-${borders.left})`
227+
: '',
228+
'--pc-box-border-right': borders.right
229+
? `var(--p-border-${borders.right})`
230+
: '',
231+
'--pc-box-border-top': borders.top
232+
? `var(--p-border-${borders.top})`
233+
: '',
234+
'--pc-box-border-radius-bottom-left': borderRadiuses.bottomLeft
235+
? `var(--p-border-${borderRadiuses.bottomLeft})`
236+
: '',
237+
'--pc-box-border-radius-bottom-right': borderRadiuses.bottomRight
238+
? `var(--p-border-${borderRadiuses.bottomRight})`
239+
: '',
240+
'--pc-box-border-radius-top-left': borderRadiuses.topLeft
241+
? `var(--p-border-${borderRadiuses.topLeft})`
242+
: '',
243+
'--pc-box-border-radius-top-right': borderRadiuses.topRight
244+
? `var(--p-border-${borderRadiuses.topRight})`
245+
: '',
151246
} as React.CSSProperties;
152247

153248
const className = classNames(
154249
styles.root,
155250
background && styles[background],
156-
border && styles[border],
157251
shadow && styles[shadow],
158252
);
159253

0 commit comments

Comments
 (0)