babel-plugin-styled-components icon indicating copy to clipboard operation
babel-plugin-styled-components copied to clipboard

Pass dynamic components in the as prop

Open satya164 opened this issue 6 years ago • 17 comments
trafficstars

I haven't tried this in a real app :)

satya164 avatar Dec 26 '18 21:12 satya164

This won't work if the variable is re-assigned. Maybe we should always use the as prop?

satya164 avatar Dec 26 '18 21:12 satya164

Please let me know when I can pull and test this PR in my app and I'll let you know how it works! 👍

stevensacks avatar Dec 30 '18 07:12 stevensacks

@stevensacks you can give it a try now and let us know

satya164 avatar Dec 30 '18 15:12 satya164

Will do. Happy new year!

stevensacks avatar Dec 31 '18 07:12 stevensacks

@satya164 I've been trying to test this pull request but I'm getting an error:

npm i -S "git://github.com/styled-components/babel-plugin-styled-components.git#fd610c1e083f92678e8133fe807192d0d7cfba7c"
"babel-plugin-styled-components": "git://github.com/styled-components/babel-plugin-styled-components.git#fd610c1e083f92678e8133fe807192d0d7cfba7c"
./src/components/App/index.js
Error: Cannot find module 'babel-plugin-styled-components'

App/index.js has these imports

import {css, keyframes} from 'styled-components';
import React from 'react';
import styled from 'styled-components/macro';

stevensacks avatar Jan 03 '19 10:01 stevensacks

@satya164 can you please let me know how to npm install this pull request? Thanks!

stevensacks avatar Jan 06 '19 14:01 stevensacks

I think you need to install it from my fork. Anyway, isntalling with npm doesn't seem to work for me either. I tried with yarn and it doesn't run prepublish script (I think it should be prepare @mxstbr).

The following worked for me:

yarn add "styled-components@github:satya164/babel-plugin-styled-components#fd610c1e083f92678e8133fe807192d0d7cfba7c" && yarn --cwd node_modules/babel-plugin-styled-components run prepublish

satya164 avatar Jan 06 '19 22:01 satya164

@satya164 I tried that and I got the following error.

Error: Cannot find module 'styled-components/macro' from '/Users/steven/Development/project/src/components/App'

error

Both of the libs are showing up as not installed.

stevensacks avatar Jan 07 '19 01:01 stevensacks

I've no idea why this will happen. Maybe @mxstbr has encountered it?

Worst case, you could clone the branch, run npm build and copy it to your node_modules for trying.

satya164 avatar Jan 07 '19 01:01 satya164

@mxstbr Would you be willing to merge this into a release candidate to make things easier?

stevensacks avatar Jan 07 '19 03:01 stevensacks

I'll publish this under a tag—one second...

mxstbr avatar Jan 07 '19 08:01 mxstbr

yarn add --dev babel-plugin-styled-components@experimental

mxstbr avatar Jan 07 '19 08:01 mxstbr

Thanks! I’ll give it a shot.

stevensacks avatar Jan 07 '19 10:01 stevensacks

I'm hoping I have the correct version.

{
  "babel-plugin-styled-components": "^1.10.1-0",
}

It doesn't work, though.

@satya164 here's how you can test it yourself in a simple way. The below code throws the error.

import React from 'react';

const UI = {
  View: ({className, children}) => (
    <div className={className}>{children}</div>
  ),
};

const App = () => {
  const {View} = UI;
  return (
    <View css={viewStyle}>
      <p>Testing 1 2 3</p>
    </View>
  );
}

// From create-react-app's default css
const viewStyle = `
    background-color: #282c34;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: calc(10px + 2vmin);
    color: white;
`;

Let me know how that works!

stevensacks avatar Jan 07 '19 11:01 stevensacks

@satya164 any luck?

stevensacks avatar Jan 08 '19 16:01 stevensacks

@stevemao sorry, I didn't have much time to investigate. will try this weekend.

satya164 avatar Jan 08 '19 21:01 satya164

@satya164 Anything I can do to make working on this easier?

stevensacks avatar Jan 16 '19 04:01 stevensacks