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 Generics to breakpoint #32

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

omonk
Copy link

@omonk omonk commented Oct 12, 2021

You'll have to forgive me if this is failing to build, I've cloned locally but usually I work with TS not flow and haven't been able to get it to run.

Anyway, motivation for this is as follows:

interface Props {
  readonly maxWidth: string;
}

const Comp = styled.div<Props>`
  ${(props) => {
    // TS doesn't mind
    console.log({ props: props.maxWidth });

    return null;
  }}

  ${breakpoint("tablet")`
    ${(p) => {
      // TS doesn't like bc of breakpoint args
      if (p.maxWidth) {
        return `max-width: ${p.maxWidth}`;
      }

      return null;
    }}
  `}
`;

This change enables you to pass the types into breakpoint

interface Props {
  readonly maxWidth: string;
}

const Comp = styled.div<Props>`
  ${breakpoint<Props>("tablet")`
    ${(p) => {
      // TS happy
      if (p.maxWidth) {
        return `max-width: ${p.maxWidth}`;
      }

      return null;
    }}
  `}
`;

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.

1 participant