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 css-modules support 🎈 #4

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

add css-modules support 🎈 #4

wants to merge 1 commit into from

Conversation

mayank99
Copy link
Owner

this will now work:

import { css } from '@acab/ecsstatic/modules';

const styles = css`
  .wrapper {
    display: grid;
    place-items: center;
  }
  .button {
    font: inherit;
    color: hotpink;
  }
`;

export () => (
  <div class={styles.wrapper}>
   <button class={styles.button}>hi</button>
  </div>
);

see demo: https://stackblitz.com/edit/github-dsxixb?file=src%2FApp.tsx

Repository owner deleted a comment from netlify bot Jan 27, 2023
mayank99 added a commit that referenced this pull request Jan 29, 2023
mainly to reduce the diff of #4
@mayank99
Copy link
Owner Author

mayank99 commented Jan 29, 2023

going to put this one on hold indefinitely. it's a neat idea but there are problems. documenting here for if i revisit this in the future.

typescript is the biggest issue. currently the return type is Record<string, string>, which is obviously not great. i would like the return type to have all the classes inferred from the css string, but this doesn't seem to be possible with tagged template literals css`...` because TemplateStringsArray loses info and does not take a generic (microsoft/TypeScript#33304).

i made some progress with a regular css(...) function but then we lose syntax highlighting and intellisense from the vscode-styled-components extension, which is even worse than having no type-safety.

@tomahl
Copy link

tomahl commented Feb 15, 2023

If you disregard the problem with TS, CSS modules would have also solved the problem of creating global styles right? I'm thinking of the :global {} selector.

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

2 participants