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

Unable to customize css tagged template with string expressions #113

Open
avdotion opened this issue May 1, 2020 · 1 comment
Open

Unable to customize css tagged template with string expressions #113

avdotion opened this issue May 1, 2020 · 1 comment

Comments

@avdotion
Copy link

avdotion commented May 1, 2020

There is a goal to assign all length in css code by multiplication to fix value. For example, let us take a segment 12px as a common, then all applicable lengths are in range [ 12, 24, ... ]. There is a reason to use string expressions in the reshadow css tagged template.

Down here there is an example to customize the width of children that way. Webpack answers with the following:

CssSyntaxError: /Users/avdotion/sandbox/reshadow-issue/src/App.js: reshadow/macro: /Users/avdotion/sandbox/reshadow-issue/src/App.js:2:3: Unclosed block Learn more: https://www.npmjs.com/package/reshadow

import React from 'react';
import {css} from 'reshadow/macro';

import Child from './Child';

const CHILD_WIDTH = '150px';

const childStyles = css`
  |child {
    width: ${CHILD_WIDTH};
    background-color: red;
  }
`;

const App = () => (
  <Child styles={childStyles} />
);

export default App;
import React from 'react';
import styled, {use} from 'reshadow/macro';

const Child = ({styles}) => styled(styles)(
  <use.child>
    child
  </use.child>
);

export default Child;

Please help to figure out how to solve the task with the reshadow tools.

@avdotion
Copy link
Author

avdotion commented May 1, 2020

These hacks work! 🚩

import React from 'react';
import {css} from 'reshadow/macro';

import Child from './Child';

const buildParsedExpression = body => {
  const parsedExpression = [body];
  parsedExpression.raw = [body];

  return parsedExpression;
};

const CHILD_WIDTH = '150px';

const childStyles = css(buildParsedExpression(`
  section {
    background-color: red;
    width: ${CHILD_WIDTH};
  }
`));

const App = () => (
  <Child styles={childStyles} />
);

export default App;
import React from 'react';
import styled, {use} from 'reshadow/macro';

const Child = ({styles}) => styled(styles)(
  <use.child as="section">
    child
  </use.child>
);

export default Child;

I see two common problems upper here:

  • First of all, there is unable to customize child by namespace from parent component (matching to native html tags is supporting).
  • Secondly, the expression which passed to css function is being parsed immediately.

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

1 participant