11import React , { createElement , forwardRef , ReactNode } from 'react' ;
2- import type { colors , depth , shape , spacing } from '@shopify/polaris-tokens' ;
2+ import type {
3+ ColorsTokenName ,
4+ DepthShadowAlias ,
5+ ShapeTokenName ,
6+ SpacingSpaceScale ,
7+ } from '@shopify/polaris-tokens' ;
38
49import { classNames , sanitizeCustomProperties } from '../../utilities/css' ;
510
611import styles from './Box.scss' ;
712
8- type ColorsTokenName = keyof typeof colors ;
9- export type BackgroundColorTokenScale = Extract <
13+ type BackgroundColorTokenScale = Extract <
1014 ColorsTokenName ,
1115 | 'background'
1216 | `background-${string } `
@@ -18,13 +22,6 @@ export type BackgroundColorTokenScale = Extract<
1822> ;
1923type ColorTokenScale = Extract < ColorsTokenName , 'text' | `text-${string } `> ;
2024
21- type DepthTokenName = keyof typeof depth ;
22- type ShadowsTokenName = Exclude < DepthTokenName , `shadows-${string } `> ;
23- export type DepthTokenScale = ShadowsTokenName extends `shadow-${infer Scale } `
24- ? Scale
25- : never ;
26-
27- type ShapeTokenName = keyof typeof shape ;
2825type BorderShapeTokenScale = ShapeTokenName extends `border-${infer Scale } `
2926 ? Scale
3027 : never ;
@@ -40,7 +37,7 @@ interface Border {
4037 top : BorderTokenScale ;
4138}
4239
43- export type BorderRadiusTokenScale = Extract <
40+ type BorderRadiusTokenScale = Extract <
4441 BorderShapeTokenScale ,
4542 `radius-${string } `
4643> extends `radius-${infer Scale } `
@@ -54,16 +51,11 @@ interface BorderRadius {
5451 topRight : BorderRadiusTokenScale ;
5552}
5653
57- type SpacingTokenName = keyof typeof spacing ;
58- export type SpacingTokenScale = SpacingTokenName extends `space-${infer Scale } `
59- ? Scale
60- : never ;
61-
6254interface Spacing {
63- bottom : SpacingTokenScale ;
64- left : SpacingTokenScale ;
65- right : SpacingTokenScale ;
66- top : SpacingTokenScale ;
55+ bottom : SpacingSpaceScale ;
56+ left : SpacingSpaceScale ;
57+ right : SpacingSpaceScale ;
58+ top : SpacingSpaceScale ;
6759}
6860
6961type Element = 'div' | 'span' ;
@@ -98,29 +90,29 @@ export interface BoxProps {
9890 /** Color of children */
9991 color ?: ColorTokenScale ;
10092 /** Spacing outside of container */
101- margin ?: SpacingTokenScale ;
93+ margin ?: SpacingSpaceScale ;
10294 /** Bottom spacing outside of container */
103- marginBottom ?: SpacingTokenScale ;
95+ marginBottom ?: SpacingSpaceScale ;
10496 /** Left spacing outside of container */
105- marginLeft ?: SpacingTokenScale ;
97+ marginLeft ?: SpacingSpaceScale ;
10698 /** Right spacing outside of container */
107- marginRight ?: SpacingTokenScale ;
99+ marginRight ?: SpacingSpaceScale ;
108100 /** Top spacing outside of container */
109- marginTop ?: SpacingTokenScale ;
101+ marginTop ?: SpacingSpaceScale ;
110102 /** Maximum width of container */
111103 maxWidth ?: string ;
112104 /** Spacing around children */
113- padding ?: SpacingTokenScale ;
105+ padding ?: SpacingSpaceScale ;
114106 /** Bottom spacing around children */
115- paddingBottom ?: SpacingTokenScale ;
107+ paddingBottom ?: SpacingSpaceScale ;
116108 /** Left spacing around children */
117- paddingLeft ?: SpacingTokenScale ;
109+ paddingLeft ?: SpacingSpaceScale ;
118110 /** Right spacing around children */
119- paddingRight ?: SpacingTokenScale ;
111+ paddingRight ?: SpacingSpaceScale ;
120112 /** Top spacing around children */
121- paddingTop ?: SpacingTokenScale ;
113+ paddingTop ?: SpacingSpaceScale ;
122114 /** Shadow */
123- shadow ?: DepthTokenScale ;
115+ shadow ?: DepthShadowAlias ;
124116}
125117
126118export const Box = forwardRef < HTMLElement , BoxProps > (
0 commit comments