From d46a380b475b71bede7a68c3e60e40102b2e54b1 Mon Sep 17 00:00:00 2001 From: Sebastian Sebald Date: Wed, 10 Jul 2019 01:18:35 +0200 Subject: [PATCH] Add position/grid style props + looser return value (#36744) --- types/styled-system__css/index.d.ts | 42 +++++++++++++++++-- .../styled-system__css-tests.ts | 23 ++++++++-- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/types/styled-system__css/index.d.ts b/types/styled-system__css/index.d.ts index 88ce00968e..a2e56fdfc7 100644 --- a/types/styled-system__css/index.d.ts +++ b/types/styled-system__css/index.d.ts @@ -39,6 +39,11 @@ export interface CSSProperties extends CSS.StandardProperties, */ export type CSSPseudoSelectorProps = { [Key in CSS.SimplePseudos]?: ResponsiveStyleProps }; +/** + * CSS as POJO that is compatible with CSS-in-JS libaries. + */ +export type CSSObject = CSS.PropertiesFallback & { [K in CSS.Pseudos]?: CSSObject }; + /** * Color system properties. * See: https://styled-system.com/api/#color @@ -130,7 +135,6 @@ export type ShadowProps = ResponsiveStyleProps<{ * See: https://styled-system.com/api/#layout */ export type LayoutProps = ResponsiveStyleProps<{ - zIndex: CSS.ZIndexProperty; width: CSS.WidthProperty; minWidth: CSS.MinWidthProperty; maxWidth: CSS.MaxWidthProperty; @@ -139,11 +143,43 @@ export type LayoutProps = ResponsiveStyleProps<{ maxHeight: CSS.MaxHeightProperty; }>; +/** + * Position system properties. + * See: https://styled-system.com/api/#position + */ +export type PositionProps = ResponsiveStyleProps<{ + zIndex: CSS.ZIndexProperty | string; + top: CSS.TopProperty; + right: CSS.RightProperty; + bottom: CSS.BottomProperty; + left: CSS.LeftProperty; +}>; + +/** + * Grid system properties. + * See: https://styled-system.com/api/#grid-layout + */ +export type GridProps = ResponsiveStyleProps<{ + gap: CSS.GapProperty; + gridGap: CSS.GapProperty; + columnGap: CSS.ColumnGapProperty; + gridColumnGap: CSS.ColumnGapProperty; + rowGap: CSS.RowGapProperty; + gridRowGap: CSS.RowGapProperty; +}>; + /** * All supported style props. * See: https://styled-system.com/css#theme-keys */ -export type StyleProps = ColorProps & SpaceProps & TypographyProps & BorderProps & ShadowProps & LayoutProps; +export type StyleProps = ColorProps & + SpaceProps & + TypographyProps & + BorderProps & + ShadowProps & + LayoutProps & + PositionProps & + GridProps; /** * Helper to define theme values. @@ -198,7 +234,7 @@ export type SystemStyleObject = StyleObject & CSSPseudoSelectorProps SystemStyleObject & { variant?: string }) -): (props?: Theme | { theme: Theme }) => CSS.Properties; +): (props?: Theme | { theme: Theme }) => CSSObject; export default css; /** diff --git a/types/styled-system__css/styled-system__css-tests.ts b/types/styled-system__css/styled-system__css-tests.ts index b3686cbb21..d96a232243 100644 --- a/types/styled-system__css/styled-system__css-tests.ts +++ b/types/styled-system__css/styled-system__css-tests.ts @@ -1,14 +1,31 @@ -import css, { Theme, TypographyProps, BorderProps } from '@styled-system/css'; +import css, { Theme, TypographyProps, BorderProps, StyleProps } from '@styled-system/css'; -export const typography: TypographyProps = { +const typography: TypographyProps = { fontFamily: 'sans-serif', fontSize: [1, 2, 3], }; -export const border: BorderProps = { +const border: BorderProps = { border: [1, 5], }; +const spacing: StyleProps = { + m: 'normal', + p: 5, + + top: 0, + right: 1, + bottom: 4, + left: 6, + + gridGap: 'gutter', + gridColumnGap: 'gutter', + gridRowGap: 'gutter', + gap: 'gutter', + columnGap: 'gutter', + rowGap: 0, +}; + const theme: Theme = { colors: { primary: 'tomato',