Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript support of using other styled components in selectors #882

Merged

Conversation

Igorbek
Copy link
Contributor

@Igorbek Igorbek commented Jun 7, 2017

A following up PR to #837

  • adds support of using other components in interpolations
    • tests
  • removes a few unnecessary anys
  • update CHANGELOG

@Igorbek Igorbek mentioned this pull request Jun 7, 2017
5 tasks
@Igorbek
Copy link
Contributor Author

Igorbek commented Jun 7, 2017

@philpl @patrick91 @brunolemos please review.
BTW is it ok that I change the CHANGELOG?

@@ -20,7 +20,7 @@ export type OuterStyledProps<P> = ThemedOuterStyledProps<P, any>;

export type Interpolation<P> = FlattenInterpolation<P> | ReadonlyArray<FlattenInterpolation<P> | ReadonlyArray<FlattenInterpolation<P>>>;
export type FlattenInterpolation<P> = InterpolationValue | InterpolationFunction<P>;
export type InterpolationValue = string | number;
export type InterpolationValue = string | number | StyledComponentClass<any, any>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure an interpolation can be a StyledComponentClass?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can. So StyledComponentClass produced by a styled function:

const Link: StyledComponentClass<any, any> = styled.a` color: blue; `;

then it can be used in both functional and constant interpolations:

const Section = styled.section`
  color: black;
  ${Link} {
    color: red;
  }
  ${p => p.theme.linkClass || Link} {
    color: red;
  }
`;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, that's new from v2

@Igorbek Igorbek requested review from patrick91 and kitten June 7, 2017 18:13
@brunolemos
Copy link
Member

@Igorbek I'll let for people who use TypeScript to review your code

Copy link
Contributor

@patrick91 patrick91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@patrick91 patrick91 merged commit 82c84d9 into styled-components:master Jun 7, 2017
@Igorbek Igorbek deleted the feature/ts-nested-interpolations branch June 7, 2017 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants