diff --git a/types/rebass/index.d.ts b/types/rebass/index.d.ts index af656e8621..7682bbc68c 100644 --- a/types/rebass/index.d.ts +++ b/types/rebass/index.d.ts @@ -4,99 +4,111 @@ // ryee-dev // jamesmckenzie // 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"; +import * as StyledSystem from "styled-system"; -export interface BaseProps extends React.ClassAttributes { - className?: string; - as?: any; +export {}; + +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; -} +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; +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; -} +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; -} +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; -} +// tslint:disable-next-line no-empty-interface +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; -} +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; +// tslint:disable-next-line no-empty-interface +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..87df64f323 100644 --- a/types/rebass/rebass-tests.tsx +++ b/types/rebass/rebass-tests.tsx @@ -1,13 +1,26 @@ -import * as React from 'react'; -import { Box, Flex, Text, Heading, Button, Link, Image, Card } from 'rebass'; +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 +}; () => ( - + Hi, I'm a heading. - + Hi, I'm text. - Link + + Link + + + CustomComponent + + ExtendedBox );