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

RFC: useCompiledCSS() "hook" #618

Closed
itsdouges opened this issue Mar 8, 2021 · 1 comment
Closed

RFC: useCompiledCSS() "hook" #618

itsdouges opened this issue Mar 8, 2021 · 1 comment
Labels
low priority 👇 This isn't on the immediate roadmap - it could use community inolvement to get it over the line. new feature 🆕 New feature or request rfc 💬 Request for comments

Comments

@itsdouges
Copy link
Collaborator

itsdouges commented Mar 8, 2021

Currently when wanting a class name directly you can use the ClassNames component, but it's a bit convoluted. We can streamline usage by the creation of a "hook" instead.

There will be one limitation however - it can't be used in a custom hook. This is because the code would be transformed to essentially be the output of the ClassNames component - however just have a streamlined usage flow.

Input

import { useCompiledCSS } from '@compiled/react';

const Button = ({ color }) => {
  const [className, styles] = useCompiledCSS({
    background: '#8777d9',
    color,
  });

  // Wiring up of styles and class name needs to be done by hand.
  return <button styles={styles} className={className}>Hello, world!</button>
};

Output

import * as React from 'react';
import { ix, CC, CS } from '@compiled/react/runtime';
const _ = '._irr3mlcl{background-color:#8777d9}';

export const Button = ({ color }) => {
  return (
    <CC>
      <CS>{[_]}</CS>
      {
        <button
          type="button"
          style={{ '_133asw': ix(color) }}
          className={'_irr3mlcl _ect4pa23'}>
          {children}
        </button>
      }
    </CC>
  );
};
@itsdouges itsdouges added the new feature 🆕 New feature or request label Mar 8, 2021
@itsdouges itsdouges added the rfc 💬 Request for comments label Mar 9, 2021
@itsdouges itsdouges changed the title useCompiledCSS() hook RFC: useCompiledCSS() hook Mar 9, 2021
@itsdouges itsdouges changed the title RFC: useCompiledCSS() hook RFC: useCompiledCSS() "hook" Mar 9, 2021
@itsdouges itsdouges added the low priority 👇 This isn't on the immediate roadmap - it could use community inolvement to get it over the line. label Mar 29, 2021
@itsdouges
Copy link
Collaborator Author

Closing for now. Will revisit in the future, maybe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority 👇 This isn't on the immediate roadmap - it could use community inolvement to get it over the line. new feature 🆕 New feature or request rfc 💬 Request for comments
Projects
None yet
Development

No branches or pull requests

1 participant