Skip to content

gc-victor/c-c

Repository files navigation

c-c

Tiny CSS-in-JS atomic classes at run-time and compile-time.

Let's Play

Create your first styles. Each declaration will return a class name and inject them to a stylesheet.

c({
    padding: '1rem', 
    marginTop: '1rem'
});

Returns:

c4218071375 c3162900569

You can use media queries.

c({
    '@media (min-width: 1px)': {
        padding: '1rem',
        margin: '1rem'
    }
});

Even classes, pseudo-classes, pseudo-elements, child combinator, adjacent sibling combinator and general sibling combinator.

c({
    '.class-name': {
        padding: '1rem'
    },
    '> p': {
        ':hover': { padding: '1rem' }
    },
    '+ p': {
        padding: '1rem'
    },
    '~ p': {
        padding: '1rem'
    },
    ':hover': { padding: '1rem' },
    '::after': { content: '"»"', color: 'red' },
});

Using styles() you will get all the styles for your Server Side Rendering (SSR) or Static Site Generation (SSG) projects.

Returns:

.c4218071375{padding:1rem}

Compile time

You have to import the macro to use c-c at compile time.

import { c } from 'c-c/macro';

You have to have installed babeljs and babel-plugin-macros and add the last one to the babel plugins config.

It will generate a styles.css file in your current working directory.

Your code will be transformed from:

import { c } from 'c-c/macro';

const css0 = c({ padding: 0, margin: 0 });
const css1 = c({ padding: '1rem' });
const css2 = c({ padding: '1rem' });

To:

const css0 = "c2343579090 c2342591469";
const css1 = "c4218071375";
const css2 = "c4218071375";

As you can see, the import is removed, and the classes names have replaced the function.

Extra ball

The styles.js file is a modified version of TailwindCSS config file to copy to your project and modify it to fit your needs.

import { color, fontSize, spacing } form './styles';

c({
    color: color.black,
    fontSize: fontSize.xl,
    margin: spacing.x4,
    paddingTop: spacing.x10
});

Acknowledgments

Inspiration

Compatible Versioning

Summary

Given a version number MAJOR.MINOR, increment the:

  • MAJOR version when you make backwards-incompatible updates of any kind
  • MINOR version when you make 100% backwards-compatible updates

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR format.

ComVer

Contribute

First off, thanks for taking the time to contribute! Now, take a moment to be sure your contributions make sense to everyone else.

Reporting Issues

Found a problem? Want a new feature? First of all, see if your issue or idea has already been reported. If it hasn't, just open a new clear and descriptive issue.

Commit message conventions

A specification for adding human and machine readable meaning to commit messages.

Submitting pull requests

Pull requests are the greatest contributions, so be sure they are focused in scope and do avoid unrelated commits.

  • Fork it!
  • Clone your fork: git clone http://github.com/<your-username>/c-c
  • Navigate to the newly cloned directory: cd c-c
  • Create a new branch for the new feature: git checkout -b my-new-feature
  • Install the tools necessary for development: npm install
  • Make your changes.
  • npm run build to verify your change doesn't increase output size.
  • npm test to make sure your change doesn't break anything.
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request with full remarks documenting your changes.

License

MIT License

Copyright (c) 2020 Víctor García

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.