From 1ec6cdc9d273a95462d636027f63e448e9a766c0 Mon Sep 17 00:00:00 2001 From: Angus Fretwell Date: Sun, 10 Feb 2019 18:11:12 +1100 Subject: [PATCH 1/5] [rebass] extend styled-system interfaces, support html attributes, stricter as and css props --- types/rebass/index.d.ts | 156 ++++++++++++++++++---------------- types/rebass/rebass-tests.tsx | 17 ++-- 2 files changed, 94 insertions(+), 79 deletions(-) diff --git a/types/rebass/index.d.ts b/types/rebass/index.d.ts index 20c73079ad..db40da76ac 100644 --- a/types/rebass/index.d.ts +++ b/types/rebass/index.d.ts @@ -4,99 +4,107 @@ // ryee-dev // jamesmckenzie // sara f-p +// angusfretwell // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 import * as React from "react"; +import * as StyledComponents from "styled-components"; +import * as StyledSystem from "styled-system"; -export interface BaseProps extends React.ClassAttributes { - className?: string; - as?: any; +type Omit = Pick>; + +export interface BaseProps extends React.Props { + as?: React.ReactType; + css?: StyledComponents.CSSObject; } -export interface SpaceProps extends BaseProps { - m?: number | string | ReadonlyArray; - mt?: number | string | ReadonlyArray; - mr?: number | string | ReadonlyArray; - mb?: number | string | ReadonlyArray; - ml?: number | string | ReadonlyArray; - mx?: number | string | ReadonlyArray; - my?: number | string | ReadonlyArray; - p?: number | string | ReadonlyArray; - pt?: number | string | ReadonlyArray; - pr?: number | string | ReadonlyArray; - pb?: number | string | ReadonlyArray; - pl?: number | string | ReadonlyArray; - px?: number | string | ReadonlyArray; - py?: number | string | ReadonlyArray; -} +interface BoxKnownProps + extends BaseProps, + StyledSystem.SpaceProps, + StyledSystem.WidthProps, + StyledSystem.FontSizeProps, + StyledSystem.ColorProps, + StyledSystem.FlexProps, + StyledSystem.OrderProps, + StyledSystem.AlignSelfProps {} +export interface BoxProps + extends BoxKnownProps, + Omit, keyof BoxKnownProps> {} +export const Box: React.FunctionComponent; -export interface BoxProps extends SpaceProps { - className?: string; - width?: number | string | ReadonlyArray; - fontSize?: number | ReadonlyArray; - css?: object; - color?: string; - bg?: string; -} -// tslint:disable-next-line:strict-export-declare-modifiers -type BoxClass = React.FunctionComponent; -export const Box: BoxClass; - -export interface ButtonProps extends BoxProps { - fontWeight?: string; - border?: number | string; - borderColor?: string; - borderRadius?: number | string; - variant?: string; -} +export interface ButtonKnownProps + extends BoxKnownProps, + StyledSystem.FontWeightProps, + StyledSystem.BorderProps, + StyledSystem.BordersProps, + StyledSystem.BorderColorProps, + StyledSystem.BorderRadiusProps, + StyledSystem.ButtonStyleProps {} +export interface ButtonProps + extends ButtonKnownProps, + Omit, keyof ButtonKnownProps> {} export const Button: React.FunctionComponent; -export interface CardProps extends BoxProps { - border?: number | string; - borderColor?: string; - borderRadius?: number | string; - boxShadow?: string; - backgroundImage?: string; - backgroundSize?: string; - backgroundPosition?: string; - backgroundRepeat?: string; - opacity?: number; - variant?: string; +export interface CardKnownProps + extends BoxKnownProps, + StyledSystem.BorderProps, + StyledSystem.BordersProps, + StyledSystem.BorderColorProps, + StyledSystem.BorderRadiusProps, + StyledSystem.BoxShadowProps, + StyledSystem.BackgroundImageProps, + StyledSystem.BackgroundSizeProps, + StyledSystem.BackgroundPositionProps, + StyledSystem.BackgroundRepeatProps, + StyledSystem.OpacityProps { + variant?: StyledSystem.ResponsiveValue; } +export interface CardProps + extends CardKnownProps, + Omit, keyof CardKnownProps> {} export const Card: React.FunctionComponent; -export interface FlexProps extends BoxProps { - alignItems?: string; - justifyContent?: string; - flexDirection?: string; - flexWrap?: string; -} +export interface FlexKnownProps + extends BoxKnownProps, + StyledSystem.FlexWrapProps, + StyledSystem.FlexDirectionProps, + StyledSystem.AlignItemsProps, + StyledSystem.JustifyContentProps {} +export interface FlexProps + extends FlexKnownProps, + Omit, keyof FlexKnownProps> {} export const Flex: React.FunctionComponent; -export interface ImageProps extends BoxProps { - height?: number | string; - borderRadius?: number | string; - src?: string; - alt?: string; -} +export interface ImageKnownProps + extends BoxKnownProps, + StyledSystem.HeightProps, + StyledSystem.BorderRadiusProps {} +export interface ImageProps + extends ImageKnownProps, + Omit, keyof ImageKnownProps> {} export const Image: React.FunctionComponent; -export interface LinkProps extends BoxProps { - href?: string; -} +export interface LinkKnownProps extends BoxKnownProps {} +export interface LinkProps + extends LinkKnownProps, + Omit, keyof LinkKnownProps> {} export const Link: React.FunctionComponent; -export interface TextProps extends BoxProps { - fontSize?: number | ReadonlyArray; - fontWeight?: string; - color?: string; - fontFamily?: string; - textAlign?: string; - lineHeight?: number | string; - letterSpacing?: number | string; -} +export interface TextKnownProps + extends BoxKnownProps, + StyledSystem.FontFamilyProps, + StyledSystem.FontWeightProps, + StyledSystem.TextAlignProps, + StyledSystem.LineHeightProps, + StyledSystem.LetterSpacingProps {} +export interface TextProps + extends TextKnownProps, + Omit, keyof TextKnownProps> {} export const Text: React.FunctionComponent; -export type HeadingProps = TextProps; +export interface HeadingKnownProps extends TextKnownProps {} +export interface HeadingProps + extends HeadingKnownProps, + Omit, keyof HeadingKnownProps> {} export const Heading: React.FunctionComponent; diff --git a/types/rebass/rebass-tests.tsx b/types/rebass/rebass-tests.tsx index 53735775ff..52e3e7de28 100644 --- a/types/rebass/rebass-tests.tsx +++ b/types/rebass/rebass-tests.tsx @@ -1,13 +1,17 @@ -import * as React from 'react'; -import { Box, Flex, Text, Heading, Button, Link, Image, Card } from 'rebass'; +import * as React from "react"; +import { Box, Flex, Text, Heading, Button, Link, Image, Card } from "rebass"; + +const CustomComponent: React.FunctionComponent = ({ children }) => { + return
{children}
; +}; () => ( - + Hi, I'm a heading. - + Hi, I'm text. - Link + + Link + + CustomComponent From 5ff828d9f07f52fa432b036ffeb6c386016ac67c Mon Sep 17 00:00:00 2001 From: Angus Fretwell Date: Sun, 10 Feb 2019 18:33:28 +1100 Subject: [PATCH 2/5] [rebass] add ExtendedBox to test, add prop to CustomComponent example --- types/rebass/rebass-tests.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/types/rebass/rebass-tests.tsx b/types/rebass/rebass-tests.tsx index 52e3e7de28..87df64f323 100644 --- a/types/rebass/rebass-tests.tsx +++ b/types/rebass/rebass-tests.tsx @@ -1,10 +1,19 @@ import * as React from "react"; +import styled from "styled-components"; import { Box, Flex, Text, Heading, Button, Link, Image, Card } from "rebass"; const CustomComponent: React.FunctionComponent = ({ children }) => { return
{children}
; }; +const ExtendedBox = styled(Box)` + color: red; +`; + +ExtendedBox.defaultProps = { + p: 3 +}; + () => ( @@ -33,10 +42,13 @@ const CustomComponent: React.FunctionComponent = ({ children }) => { Link - CustomComponent + + CustomComponent + + ExtendedBox ); From 5fff1de627a6d17ebc2276b2fb06cb898faf9ab1 Mon Sep 17 00:00:00 2001 From: Angus Fretwell Date: Sun, 10 Feb 2019 18:39:16 +1100 Subject: [PATCH 3/5] [rebass] resolve lint warnings --- types/rebass/index.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/rebass/index.d.ts b/types/rebass/index.d.ts index db40da76ac..8514783713 100644 --- a/types/rebass/index.d.ts +++ b/types/rebass/index.d.ts @@ -12,6 +12,8 @@ import * as React from "react"; import * as StyledComponents from "styled-components"; import * as StyledSystem from "styled-system"; +export {}; + type Omit = Pick>; export interface BaseProps extends React.Props { @@ -85,6 +87,7 @@ export interface ImageProps Omit, keyof ImageKnownProps> {} export const Image: React.FunctionComponent; +// tslint:disable-next-line no-empty-interface export interface LinkKnownProps extends BoxKnownProps {} export interface LinkProps extends LinkKnownProps, @@ -103,6 +106,7 @@ export interface TextProps Omit, keyof TextKnownProps> {} export const Text: React.FunctionComponent; +// tslint:disable-next-line no-empty-interface export interface HeadingKnownProps extends TextKnownProps {} export interface HeadingProps extends HeadingKnownProps, From d904c8218b11af59baee8a060a739bd64d507c80 Mon Sep 17 00:00:00 2001 From: Angus Fretwell Date: Sun, 10 Feb 2019 18:42:59 +1100 Subject: [PATCH 4/5] [rebass] bump typescript version to match styled-components --- types/rebass/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/rebass/index.d.ts b/types/rebass/index.d.ts index 8514783713..fb2634ac2f 100644 --- a/types/rebass/index.d.ts +++ b/types/rebass/index.d.ts @@ -6,7 +6,7 @@ // sara f-p // angusfretwell // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// TypeScript Version: 2.9 import * as React from "react"; import * as StyledComponents from "styled-components"; From 63b47923b064dacc90a632d4a06d99676dda7c50 Mon Sep 17 00:00:00 2001 From: Angus Fretwell Date: Sun, 10 Feb 2019 18:50:39 +1100 Subject: [PATCH 5/5] [rebass] don't export 'known props' interfaces --- types/rebass/index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/rebass/index.d.ts b/types/rebass/index.d.ts index fb2634ac2f..d52d032284 100644 --- a/types/rebass/index.d.ts +++ b/types/rebass/index.d.ts @@ -35,7 +35,7 @@ export interface BoxProps Omit, keyof BoxKnownProps> {} export const Box: React.FunctionComponent; -export interface ButtonKnownProps +interface ButtonKnownProps extends BoxKnownProps, StyledSystem.FontWeightProps, StyledSystem.BorderProps, @@ -48,7 +48,7 @@ export interface ButtonProps Omit, keyof ButtonKnownProps> {} export const Button: React.FunctionComponent; -export interface CardKnownProps +interface CardKnownProps extends BoxKnownProps, StyledSystem.BorderProps, StyledSystem.BordersProps, @@ -67,7 +67,7 @@ export interface CardProps Omit, keyof CardKnownProps> {} export const Card: React.FunctionComponent; -export interface FlexKnownProps +interface FlexKnownProps extends BoxKnownProps, StyledSystem.FlexWrapProps, StyledSystem.FlexDirectionProps, @@ -78,7 +78,7 @@ export interface FlexProps Omit, keyof FlexKnownProps> {} export const Flex: React.FunctionComponent; -export interface ImageKnownProps +interface ImageKnownProps extends BoxKnownProps, StyledSystem.HeightProps, StyledSystem.BorderRadiusProps {} @@ -88,13 +88,13 @@ export interface ImageProps export const Image: React.FunctionComponent; // tslint:disable-next-line no-empty-interface -export interface LinkKnownProps extends BoxKnownProps {} +interface LinkKnownProps extends BoxKnownProps {} export interface LinkProps extends LinkKnownProps, Omit, keyof LinkKnownProps> {} export const Link: React.FunctionComponent; -export interface TextKnownProps +interface TextKnownProps extends BoxKnownProps, StyledSystem.FontFamilyProps, StyledSystem.FontWeightProps, @@ -107,7 +107,7 @@ export interface TextProps export const Text: React.FunctionComponent; // tslint:disable-next-line no-empty-interface -export interface HeadingKnownProps extends TextKnownProps {} +interface HeadingKnownProps extends TextKnownProps {} export interface HeadingProps extends HeadingKnownProps, Omit, keyof HeadingKnownProps> {}