11import React , { createElement , forwardRef , ReactNode } from 'react' ;
22import type { colors , depth , shape , spacing } from '@shopify/polaris-tokens' ;
33
4- import { classNames } from '../../utilities/css' ;
4+ import { classNames , sanitizeCustomProperties } from '../../utilities/css' ;
55
66import styles from './Box.scss' ;
77
@@ -186,64 +186,68 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
186186 } as Spacing ;
187187
188188 const style = {
189- ...( background ? { '--pc-box-background' : `var(--p-${ background } )` } : { } ) ,
189+ ...( background
190+ ? { '--pc-box-background' : `var(--p-${ background } )` }
191+ : undefined ) ,
190192 ...( borders . bottom
191193 ? { '--pc-box-border-bottom' : `var(--p-border-${ borders . bottom } )` }
192- : { } ) ,
194+ : undefined ) ,
193195 ...( borders . left
194196 ? { '--pc-box-border-left' : `var(--p-border-${ borders . left } )` }
195- : { } ) ,
197+ : undefined ) ,
196198 ...( borders . right
197199 ? { '--pc-box-border-right' : `var(--p-border-${ borders . right } )` }
198- : { } ) ,
200+ : undefined ) ,
199201 ...( borders . top
200202 ? { '--pc-box-border-top' : `var(--p-border-${ borders . top } )` }
201- : { } ) ,
203+ : undefined ) ,
202204 ...( borderRadiuses . bottomLeft
203205 ? {
204206 '--pc-box-border-radius-bottom-left' : `var(--p-border-radius-${ borderRadiuses . bottomLeft } )` ,
205207 }
206- : { } ) ,
208+ : undefined ) ,
207209 ...( borderRadiuses . bottomRight
208210 ? {
209211 '--pc-box-border-radius-bottom-right' : `var(--p-border-radius-${ borderRadiuses . bottomRight } )` ,
210212 }
211- : { } ) ,
213+ : undefined ) ,
212214 ...( borderRadiuses . topLeft
213215 ? {
214216 '--pc-box-border-radius-top-left' : `var(--p-border-radius-${ borderRadiuses . topLeft } )` ,
215217 }
216- : { } ) ,
218+ : undefined ) ,
217219 ...( borderRadiuses . topRight
218220 ? {
219221 '--pc-box-border-radius-top-right' : `var(--p-border-radius-${ borderRadiuses . topRight } )` ,
220222 }
221- : { } ) ,
223+ : undefined ) ,
222224 ...( margins . bottom
223225 ? { '--pc-box-margin-bottom' : `var(--p-space-${ margins . bottom } )` }
224- : { } ) ,
226+ : undefined ) ,
225227 ...( margins . left
226228 ? { '--pc-box-margin-left' : `var(--p-space-${ margins . left } )` }
227- : { } ) ,
229+ : undefined ) ,
228230 ...( margins . right
229231 ? { '--pc-box-margin-right' : `var(--p-space-${ margins . right } )` }
230- : { } ) ,
232+ : undefined ) ,
231233 ...( margins . top
232234 ? { '--pc-box-margin-top' : `var(--p-space-${ margins . top } )` }
233- : { } ) ,
235+ : undefined ) ,
234236 ...( paddings . bottom
235237 ? { '--pc-box-padding-bottom' : `var(--p-space-${ paddings . bottom } )` }
236- : { } ) ,
238+ : undefined ) ,
237239 ...( paddings . left
238240 ? { '--pc-box-padding-left' : `var(--p-space-${ paddings . left } )` }
239- : { } ) ,
241+ : undefined ) ,
240242 ...( paddings . right
241243 ? { '--pc-box-padding-right' : `var(--p-space-${ paddings . right } )` }
242- : { } ) ,
244+ : undefined ) ,
243245 ...( paddings . top
244246 ? { '--pc-box-padding-top' : `var(--p-space-${ paddings . top } )` }
245- : { } ) ,
246- ...( shadow ? { '--pc-box-shadow' : `var(--p-shadow-${ shadow } )` } : { } ) ,
247+ : undefined ) ,
248+ ...( shadow
249+ ? { '--pc-box-shadow' : `var(--p-shadow-${ shadow } )` }
250+ : undefined ) ,
247251 } as React . CSSProperties ;
248252
249253 const className = classNames ( styles . Box ) ;
@@ -252,7 +256,7 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
252256 as ,
253257 {
254258 className,
255- style,
259+ style : sanitizeCustomProperties ( style ) ,
256260 ref,
257261 } ,
258262 children ,
0 commit comments