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

How to use css properties (needed for Spacing, Text Styles, etc) in Typescript? #821

Open
flyingnobita opened this issue Mar 10, 2021 · 4 comments

Comments

@flyingnobita
Copy link

flyingnobita commented Mar 10, 2021

In my Landing.tsx file:

import { Main, textStyle } from "@aragon/ui";
import React from "react";

const Landing = () => {
  return (
    <Main>
      <div
        css={`
          ${textStyle("title1")};
        `}
      >
        Title 1
      </div>
    </Main>
  );
};
export default Landing;

I get the error:

Property 'css' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.ts(2322)

I tried to add the type declaration in my .d.ts file (taken from here):

import { CSSProp } from "styled-components";
declare module "styled-components" {
  export interface DefaultTheme {}
}

declare module "react" {
  interface Attributes {
    css?: CSSProp;
  }
}

This suppressed the error but my text was still not formatted.

Perhaps a separate issue, I noticed that even if my file was renamed to Landing.js, the text was still not formated. Perhaps this is related to something else... 🤔 (I haven't encountered problems with other components TextInput, Field, yet though)

For context, I'm using aragin UI in a vanilla create-eth-app.

@welcome
Copy link

welcome bot commented Mar 10, 2021

Thanks for opening your first issue in aragonUI! Someone will circle back soon ⚡

@yuetloo
Copy link
Contributor

yuetloo commented Jun 23, 2021

You also need to enable Babel plugin, see doc here https://styled-components.com/docs/api#css-prop.

I was able to enable it by making these changes..
aragon/govern@33b94f9

@flyingnobita
Copy link
Author

Thanks for the reply.

Do you know if it'll work without react-app-rewired?

@yuetloo
Copy link
Contributor

yuetloo commented Jun 25, 2021

react-app-rewired was used to set up babel. If you set up babel differently, without react-app-rewired, I think it'll work.

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

No branches or pull requests

2 participants