From 6d1d475847c1f5a56d8cd72be05580c7ff7fd47e Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Wed, 7 Jun 2017 09:24:24 -0700 Subject: [PATCH 1/3] Add TypeScript support of using other styled components in selectors --- typings/styled-components.d.ts | 6 +++--- typings/tests/nested-test.tsx | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 typings/tests/nested-test.tsx diff --git a/typings/styled-components.d.ts b/typings/styled-components.d.ts index 8b98f2186..8ac9bbe21 100644 --- a/typings/styled-components.d.ts +++ b/typings/styled-components.d.ts @@ -20,7 +20,7 @@ export type OuterStyledProps

= ThemedOuterStyledProps; export type Interpolation

= FlattenInterpolation

| ReadonlyArray | ReadonlyArray>>; export type FlattenInterpolation

= InterpolationValue | InterpolationFunction

; -export type InterpolationValue = string | number; +export type InterpolationValue = string | number | StyledComponentClass; export type SimpleInterpolation = InterpolationValue | ReadonlyArray>; export interface InterpolationFunction

{ (props: P): Interpolation

; @@ -105,13 +105,13 @@ interface StylesheetComponentProps { sheet: ServerStyleSheet; } -export class StyleSheetManager extends React.Component { } +export class StyleSheetManager extends React.Component { } export class ServerStyleSheet { collectStyles(tree: React.ReactNode): ReactElement; getStyleTags(): string; - getStyleElement(): ReactElement[]; + getStyleElement(): ReactElement<{}>[]; } export default styled; diff --git a/typings/tests/nested-test.tsx b/typings/tests/nested-test.tsx new file mode 100644 index 000000000..d1fc89250 --- /dev/null +++ b/typings/tests/nested-test.tsx @@ -0,0 +1,21 @@ +import * as React from "react"; + +import styled from "../.."; + +const Link = styled.a` + color: red; +`; + +const OtherLink = styled.a` + color: blue; +`; + +const Article = styled.section` + color: red; + & > ${Link} { + color: green; + } + ${p => p.alt ? OtherLink : Link} { + color: black + } +`; From da8e4b7d8fff370c8fbf7b61f11869f667447c82 Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Wed, 7 Jun 2017 10:19:05 -0700 Subject: [PATCH 2/3] Minor test update --- typings/tests/nested-test.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/typings/tests/nested-test.tsx b/typings/tests/nested-test.tsx index d1fc89250..de982b780 100644 --- a/typings/tests/nested-test.tsx +++ b/typings/tests/nested-test.tsx @@ -1,21 +1,30 @@ import * as React from "react"; -import styled from "../.."; +import styled, { css } from "../.."; const Link = styled.a` color: red; `; -const OtherLink = styled.a` +const AlternativeLink = styled.a` color: blue; `; +const freeStyles = css` + background-color: black; + color: white; + ${Link} { + color: blue; + } +`; + const Article = styled.section` color: red; + ${freeStyles} & > ${Link} { color: green; } - ${p => p.alt ? OtherLink : Link} { + ${p => p.theme.useAlternativeLink ? AlternativeLink : Link} { color: black } `; From 0037e305ba82fa83be842df63b3d6b926a2647c7 Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Wed, 7 Jun 2017 10:23:10 -0700 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f995ac64b..adc887a6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. If a contri - Added a test for `withComponent` followed by `attrs`, thanks to [@btmills](https://github.com/btmills). (see [#851](https://github.com/styled-components/styled-components/pull/851)) - Fix Flow type signatures for compatibility with Flow v0.47.0 (see [#840](https://github.com/styled-components/styled-components/pull/840)) - Upgraded stylis to v3.0. (see [#829](https://github.com/styled-components/styled-components/pull/829) and [#876](https://github.com/styled-components/styled-components/pull/876)) +- Added missing v2.0 APIs to TypeScript typings, thanks to [@patrick91](https://github.com/patrick91), [@igorbek](https://github.com/igorbek) (see [#837](https://github.com/styled-components/styled-components/pull/837), [#882](https://github.com/styled-components/styled-components/pull/882)) ## [v2.0.0] - 2017-05-25