@@ -20,8 +20,8 @@ import {
2020import styles from './Box.scss' ;
2121
2222type Element = 'div' | 'span' | 'section' ;
23-
2423type Overflow = 'hidden' | 'scroll' ;
24+ type Position = 'relative' | 'absolute' | 'fixed' | 'sticky' ;
2525
2626export type ColorTokenScale =
2727 | 'text'
@@ -49,13 +49,6 @@ export type BorderTokenAlias =
4949
5050type Spacing = ResponsiveProp < SpacingSpaceScale > ;
5151
52- interface Border {
53- blockStart : BorderTokenAlias ;
54- blockEnd : BorderTokenAlias ;
55- inlineStart : BorderTokenAlias ;
56- inlineEnd : BorderTokenAlias ;
57- }
58-
5952export type BorderRadiusTokenScale =
6053 | '05'
6154 | '1'
@@ -75,20 +68,6 @@ export type BackgroundColors =
7568 | ColorsActionTokenAlias
7669 | ColorsSurfaceTokenAlias ;
7770
78- interface BorderRadius {
79- startStart : BorderRadiusTokenScale ;
80- startEnd : BorderRadiusTokenScale ;
81- endStart : BorderRadiusTokenScale ;
82- endEnd : BorderRadiusTokenScale ;
83- }
84-
85- interface BorderWidth {
86- blockStart : ShapeBorderWidthScale ;
87- blockEnd : ShapeBorderWidthScale ;
88- inlineStart : ShapeBorderWidthScale ;
89- inlineEnd : ShapeBorderWidthScale ;
90- }
91-
9271export interface BoxProps {
9372 /** HTML Element type */
9473 as ?: Element ;
@@ -128,11 +107,11 @@ export interface BoxProps {
128107 color ?: ColorTokenScale ;
129108 /** HTML id attribute */
130109 id ?: string ;
131- /** Set minimum height of container */
110+ /** Minimum height of container */
132111 minHeight ?: string ;
133- /** Set minimum width of container */
112+ /** Minimum width of container */
134113 minWidth ?: string ;
135- /** Set maximum width of container */
114+ /** Maximum width of container */
136115 maxWidth ?: string ;
137116 /** Clip horizontal content of children */
138117 overflowX ?: Overflow ;
@@ -170,10 +149,27 @@ export interface BoxProps {
170149 paddingInlineEnd ?: Spacing ;
171150 /** Shadow */
172151 shadow ?: DepthShadowAlias ;
173- /** Set width of container */
152+ /** Width of container */
174153 width ?: string ;
175154 /** Elements to display inside box */
176155 children ?: React . ReactNode ;
156+ // These could be moved to new layout component(s) in the future
157+ /** Position of the box */
158+ position ?: Position ;
159+ /** Top position of the box */
160+ top ?: Spacing ;
161+ /** Bottom position of the box */
162+ right ?: Spacing ;
163+ /** Left position of the box */
164+ bottom ?: Spacing ;
165+ /** Right position of the box */
166+ left ?: Spacing ;
167+ /** Opcity of the box */
168+ opacity ?: string ;
169+ /** Visually hide the contents (still announced by screenreader) */
170+ visuallyHidden ?: boolean ;
171+ /** z-index of the box */
172+ zIndex ?: string ;
177173}
178174
179175export const Box = forwardRef < HTMLElement , BoxProps > (
@@ -211,75 +207,62 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
211207 paddingInlineEnd,
212208 shadow,
213209 width,
210+ visuallyHidden,
211+ position,
212+ top,
213+ right,
214+ bottom,
215+ left,
216+ zIndex,
217+ opacity,
214218 } ,
215219 ref ,
216220 ) => {
217- const borders = {
218- blockEnd : borderBlockEnd ,
219- inlineStart : borderInlineStart ,
220- inlineEnd : borderInlineEnd ,
221- blockStart : borderBlockStart ,
222- } as Border ;
223-
224- const borderRadiuses = {
225- endStart : borderRadiusEndStart ,
226- endEnd : borderRadiusEndEnd ,
227- startStart : borderRadiusStartStart ,
228- startEnd : borderRadiusStartEnd ,
229- } as BorderRadius ;
230-
231- const borderWidths = {
232- blockStart : borderBlockStartWidth ,
233- blockEnd : borderBlockEndWidth ,
234- inlineStart : borderInlineStartWidth ,
235- inlineEnd : borderInlineEndWidth ,
236- } as BorderWidth ;
237-
238221 const style = {
239222 '--pc-box-color' : color ? `var(--p-${ color } )` : undefined ,
240223 '--pc-box-background' : background ? `var(--p-${ background } )` : undefined ,
241224 '--pc-box-border' : border ? `var(--p-border-${ border } )` : undefined ,
242- '--pc-box-border-block-end' : borders . blockEnd
243- ? `var(--p-border-${ borders . blockEnd } )`
225+ '--pc-box-border-block-end' : borderBlockEnd
226+ ? `var(--p-border-${ borderBlockEnd } )`
244227 : undefined ,
245- '--pc-box-border-inline-start' : borders . inlineStart
246- ? `var(--p-border-${ borders . inlineStart } )`
228+ '--pc-box-border-inline-start' : borderInlineStart
229+ ? `var(--p-border-${ borderInlineStart } )`
247230 : undefined ,
248- '--pc-box-border-inline-end' : borders . inlineEnd
249- ? `var(--p-border-${ borders . inlineEnd } )`
231+ '--pc-box-border-inline-end' : borderInlineEnd
232+ ? `var(--p-border-${ borderInlineEnd } )`
250233 : undefined ,
251- '--pc-box-border-block-start' : borders . blockStart
252- ? `var(--p-border-${ borders . blockStart } )`
234+ '--pc-box-border-block-start' : borderBlockStart
235+ ? `var(--p-border-${ borderBlockStart } )`
253236 : undefined ,
254237 '--pc-box-border-radius' : borderRadius
255238 ? `var(--p-border-radius-${ borderRadius } )`
256239 : undefined ,
257- '--pc-box-border-radius-end-start' : borderRadiuses . endStart
258- ? `var(--p-border-radius-${ borderRadiuses . endStart } )`
240+ '--pc-box-border-radius-end-start' : borderRadiusEndStart
241+ ? `var(--p-border-radius-${ borderRadiusEndStart } )`
259242 : undefined ,
260- '--pc-box-border-radius-end-end' : borderRadiuses . endEnd
261- ? `var(--p-border-radius-${ borderRadiuses . endEnd } )`
243+ '--pc-box-border-radius-end-end' : borderRadiusEndEnd
244+ ? `var(--p-border-radius-${ borderRadiusEndEnd } )`
262245 : undefined ,
263- '--pc-box-border-radius-start-start' : borderRadiuses . startStart
264- ? `var(--p-border-radius-${ borderRadiuses . startStart } )`
246+ '--pc-box-border-radius-start-start' : borderRadiusStartStart
247+ ? `var(--p-border-radius-${ borderRadiusStartStart } )`
265248 : undefined ,
266- '--pc-box-border-radius-start-end' : borderRadiuses . startEnd
267- ? `var(--p-border-radius-${ borderRadiuses . startEnd } )`
249+ '--pc-box-border-radius-start-end' : borderRadiusStartEnd
250+ ? `var(--p-border-radius-${ borderRadiusStartEnd } )`
268251 : undefined ,
269252 '--pc-box-border-width' : borderWidth
270253 ? `var(--p-border-width-${ borderWidth } )`
271254 : undefined ,
272- '--pc-box-border-block-start-width' : borderWidths . blockStart
273- ? `var(--p-border-width-${ borderWidths . blockStart } )`
255+ '--pc-box-border-block-start-width' : borderBlockStartWidth
256+ ? `var(--p-border-width-${ borderBlockStartWidth } )`
274257 : undefined ,
275- '--pc-box-border-block-end-width' : borderWidths . blockEnd
276- ? `var(--p-border-width-${ borderWidths . blockEnd } )`
258+ '--pc-box-border-block-end-width' : borderBlockEndWidth
259+ ? `var(--p-border-width-${ borderBlockEndWidth } )`
277260 : undefined ,
278- '--pc-box-border-inline-start-width' : borderWidths . inlineStart
279- ? `var(--p-border-width-${ borderWidths . inlineStart } )`
261+ '--pc-box-border-inline-start-width' : borderInlineStartWidth
262+ ? `var(--p-border-width-${ borderInlineStartWidth } )`
280263 : undefined ,
281- '--pc-box-border-inline-end-width' : borderWidths . inlineEnd
282- ? `var(--p-border-width-${ borderWidths . inlineEnd } )`
264+ '--pc-box-border-inline-end-width' : borderInlineEndWidth
265+ ? `var(--p-border-width-${ borderInlineEndWidth } )`
283266 : undefined ,
284267 '--pc-box-min-height' : minHeight ,
285268 '--pc-box-min-width' : minWidth ,
@@ -313,9 +296,19 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
313296 ) ,
314297 '--pc-box-shadow' : shadow ? `var(--p-shadow-${ shadow } )` : undefined ,
315298 '--pc-box-width' : width ,
299+ position,
300+ '--pc-box-top' : top ? `var(--p-space-${ top } )` : undefined ,
301+ '--pc-box-right' : right ? `var(--p-space-${ right } )` : undefined ,
302+ '--pc-box-bottom' : bottom ? `var(--p-space-${ bottom } )` : undefined ,
303+ '--pc-box-left' : left ? `var(--p-space-${ left } )` : undefined ,
304+ zIndex,
305+ opacity,
316306 } as React . CSSProperties ;
317307
318- const className = classNames ( styles . Box ) ;
308+ const className = classNames (
309+ styles . Box ,
310+ visuallyHidden && styles . visuallyHidden ,
311+ ) ;
319312
320313 return createElement (
321314 as ,
0 commit comments