@@ -7,6 +7,7 @@ import styles from './Box.scss';
77
88type Element = 'div' | 'span' | 'button' ;
99
10+ // TODO: Bring logic to extract token values into `polaris-tokens`
1011type ColorsTokenGroup = typeof colors ;
1112type ColorsTokenName = keyof ColorsTokenGroup ;
1213type BackgroundColorTokenScale = Extract <
@@ -22,18 +23,15 @@ type BackgroundColorTokenScale = Extract<
2223type DepthTokenGroup = typeof depth ;
2324type DepthTokenName = keyof DepthTokenGroup ;
2425type ShadowsTokenName = Exclude < DepthTokenName , `shadows-${string } `> ;
25-
2626type DepthTokenScale = ShadowsTokenName extends `shadow-${infer Scale } `
2727 ? Scale
2828 : never ;
2929
3030type ShapeTokenGroup = typeof shape ;
3131type ShapeTokenName = keyof ShapeTokenGroup ;
32-
3332type BorderShapeTokenScale = ShapeTokenName extends `border-${infer Scale } `
3433 ? Scale
3534 : never ;
36-
3735type BorderTokenScale = Exclude <
3836 BorderShapeTokenScale ,
3937 `radius-${string } ` | `width-${string } `
@@ -62,8 +60,6 @@ interface BorderRadius {
6260
6361type SpacingTokenGroup = typeof spacing ;
6462type SpacingTokenName = keyof SpacingTokenGroup ;
65-
66- // TODO: Bring this logic into tokens
6763type SpacingTokenScale = SpacingTokenName extends `space-${infer Scale } `
6864 ? Scale
6965 : never ;
@@ -76,34 +72,48 @@ interface Spacing {
7672}
7773
7874export interface BoxProps {
75+ /** Used to indicate the element is being modified */
76+ ariaBusy ?: boolean ;
77+ /** Used to identify the ID of the element that describes Box */
78+ ariaDescribedBy ?: string ;
79+ /** Used to identify the Id of element used as aria-labelledby */
80+ ariaLabelledBy ?: string ;
81+ /** Used to indicate the element will be updated */
82+ ariaLive ?: string ;
83+ /** Used to describe the semantic element type */
84+ ariaRoleType ?: string ;
7985 /** HTML Element type */
8086 as ?: Element ;
81- /** Background color of the Box */
87+ /** Background color */
8288 background ?: BackgroundColorTokenScale ;
83- /** Border styling of the Box */
89+ /** Border styling */
8490 border ?: BorderTokenScale ;
85- /** Bottom border styling of the Box */
91+ /** Bottom border styling */
8692 borderBottom ?: BorderTokenScale ;
87- /** Left border styling of the Box */
93+ /** Left border styling */
8894 borderLeft ?: BorderTokenScale ;
89- /** Right border styling of the Box */
95+ /** Right border styling */
9096 borderRight ?: BorderTokenScale ;
91- /** Top border styling of the Box */
97+ /** Top border styling */
9298 borderTop ?: BorderTokenScale ;
93- /** Border radius of the Box */
99+ /** Border radius styling */
94100 borderRadius ?: BorderRadiusTokenScale ;
95- /** Bottom left border radius of the Box */
101+ /** Bottom left border radius styling */
96102 borderRadiusBottomLeft ?: BorderRadiusTokenScale ;
97- /** Bottom right border radius of the Box */
103+ /** Bottom right border radius styling */
98104 borderRadiusBottomRight ?: BorderRadiusTokenScale ;
99- /** Top left border radius of the Box */
105+ /** Top left border radius styling */
100106 borderRadiusTopLeft ?: BorderRadiusTokenScale ;
101- /** Top right border radius of the Box */
107+ /** Top right border radius styling */
102108 borderRadiusTopRight ?: BorderRadiusTokenScale ;
103109 /** Inner content of the Box */
104110 children : ReactNode ;
105- /** Custom styling for the Box */
111+ /** A custom class name to apply styles to the Box */
106112 className ?: string ;
113+ /** Set disabled state on the Box */
114+ disabled ?: boolean ;
115+ /** A unique identifier */
116+ id ?: string ;
107117 /** Spacing outside of the Box */
108118 margin ?: SpacingTokenScale ;
109119 /** Bottom spacing outside of the Box */
@@ -124,15 +134,28 @@ export interface BoxProps {
124134 paddingRight ?: SpacingTokenScale ;
125135 /** Top spacing inside of the Box */
126136 paddingTop ?: SpacingTokenScale ;
127- /** Shadow on the Box */
137+ /** Shadow styling */
128138 shadow ?: DepthTokenScale ;
139+ /** Used to indicate the element is focusable in sequential order */
140+ tabIndex ?: number ;
141+ /** Callback triggered when focus is removed */
142+ onBlur ?( event : React . FocusEvent < HTMLElement > ) : void ;
129143 /** Callback triggered on click */
130144 onClick ?( event : React . MouseEvent < HTMLElement > ) : void ;
145+ /** Callback triggered on key up */
146+ onKeyUp ?( event : React . KeyboardEvent < HTMLElement > ) : void ;
147+ /** Callback triggered on mouse up */
148+ onMouseUp ?( event : React . MouseEvent < HTMLElement > ) : void ;
131149}
132150
133151export const Box = forwardRef < HTMLElement , BoxProps > (
134152 (
135153 {
154+ ariaBusy,
155+ ariaDescribedBy,
156+ ariaLabelledBy,
157+ ariaLive,
158+ ariaRoleType,
136159 as = 'div' ,
137160 background,
138161 border,
@@ -147,6 +170,8 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
147170 borderRadiusTopRight,
148171 className,
149172 children,
173+ disabled = false ,
174+ id,
150175 margin,
151176 marginBottom,
152177 marginLeft,
@@ -158,7 +183,11 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
158183 paddingRight,
159184 paddingTop,
160185 shadow,
186+ tabIndex,
187+ onBlur,
161188 onClick,
189+ onKeyUp,
190+ onMouseUp,
162191 } ,
163192 ref ,
164193 ) => {
@@ -265,9 +294,20 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
265294 as ,
266295 {
267296 className : boxClassName ,
268- style : sanitizeCustomProperties ( style ) ,
297+ 'aria-busy' : ariaBusy ,
298+ 'aria-describedby' : ariaDescribedBy ,
299+ 'aria-labelledby' : ariaLabelledBy ,
300+ 'aria-live' : ariaLive ,
301+ role : ariaRoleType ,
302+ disabled,
303+ id,
269304 ref,
305+ style : sanitizeCustomProperties ( style ) ,
306+ tabIndex,
307+ ...( onBlur ? { onBlur} : undefined ) ,
270308 ...( onClick ? { onClick} : undefined ) ,
309+ ...( onKeyUp ? { onKeyUp} : undefined ) ,
310+ ...( onMouseUp ? { onMouseUp} : undefined ) ,
271311 } ,
272312 children ,
273313 ) ;
0 commit comments