Skip to content

Commit

Permalink
Style engine: refine Box type (#38894)
Browse files Browse the repository at this point in the history
* Style engine: refine `Box` type

* Allow for `BoxVariant` to be `undefined`
  • Loading branch information
ciampo authored Feb 21, 2022
1 parent 74201da commit 499fc36
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/style-engine/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
*/
import type { CSSProperties } from 'react';

export type Box = {
top?: CSSProperties[ 'top' ];
right?: CSSProperties[ 'right' ];
bottom?: CSSProperties[ 'bottom' ];
left?: CSSProperties[ 'left' ];
type BoxVariants = 'margin' | 'padding' | undefined;
export type Box< T extends BoxVariants = undefined > = {
top?: CSSProperties[ T extends undefined ? 'top' : `${ T }Top` ];
right?: CSSProperties[ T extends undefined ? 'right' : `${ T }Right` ];
bottom?: CSSProperties[ T extends undefined ? 'bottom' : `${ T }Bottom` ];
left?: CSSProperties[ T extends undefined ? 'left' : `${ T }Left` ];
};

export interface Style {
spacing?: {
margin?: CSSProperties[ 'margin' ] | Box;
padding?: CSSProperties[ 'padding' ] | Box;
margin?: CSSProperties[ 'margin' ] | Box< 'margin' >;
padding?: CSSProperties[ 'padding' ] | Box< 'padding' >;
};
typography?: {
fontSize?: CSSProperties[ 'fontSize' ];
Expand Down

0 comments on commit 499fc36

Please sign in to comment.