compiled

A familiar and performant compile time CSS-in-JS library for React.

APACHE-2.0 License

Downloads
186.9K
Stars
2K
Committers
46

Bot releases are visible (Hide)

compiled - https://github.com/atlassian-labs/compiled/releases/tag/@compiled/[email protected]

Published by github-actions[bot] over 3 years ago

Patch Changes

compiled - https://github.com/atlassian-labs/compiled/releases/tag/@compiled/[email protected]

Published by github-actions[bot] over 3 years ago

Patch Changes

compiled - https://github.com/atlassian-labs/compiled/releases/tag/@compiled/[email protected]

Published by github-actions[bot] over 3 years ago

Patch Changes

compiled - https://github.com/atlassian-labs/compiled/releases/tag/@compiled/[email protected]

Published by github-actions[bot] over 3 years ago

Patch Changes

compiled - https://github.com/atlassian-labs/compiled/releases/tag/@compiled/[email protected]

Published by github-actions[bot] over 3 years ago

Patch Changes

compiled - https://github.com/atlassian-labs/compiled/releases/tag/@compiled/[email protected]

Published by github-actions[bot] over 3 years ago

Patch Changes

compiled -

Published by itsdouges over 3 years ago

New features

  • @compiled/webpack-loader now supports Webpack v4 (#608)
compiled -

Published by itsdouges over 3 years ago

New features

Parcel transformer (#512)

Note Parcel v2 is currently in pre-release which makes this transformer experimental, it may break when updating Parcel. Use with caution.

The first cut of @compiled/parcel-transformer is now available. This will improve local developer experience when working with Parcel v2 when your imports have been statically evaluated into your CSS. See #344 for background.

npm install @compiled/parcel-transformer --save-dev
{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.{js,jsx,ts,tsx}": [
      "@compiled/parcel-transformer",
      "@parcel/transformer-babel",
      "@parcel/transformer-js"
    ]
  }
}

See installation docs for more information. There will be bugs - found one? Raise an issue.

compiled -

Published by itsdouges over 3 years ago

Bug fixes

  • Webpack loader now works with TypeScript and Flow languages (#559)
compiled -

Published by itsdouges over 3 years ago

New features

Webpack loader (https://github.com/atlassian-labs/compiled/pull/530)

The first cut of @compiled/webpack-loader is now available. This will improve local developer experience when working with Webpack when your imports have been statically evaluated into your CSS. See #344 for background.

npm install @compiled/webpack-loader --save-dev
module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|ts|tsx)$/,
        exclude: /node_modules/,
        use: [
          { loader: 'babel-loader' },
          {
            loader: '@compiled/webpack-loader',
          },
        ],
      },
    ],
  },
};

See Installation docs for more information. There will be bugs - found one? Raise an issue.

Chores

  • Dependencies have been upgraded to latest
compiled -

Published by itsdouges over 3 years ago

New features

Functions with arguments static evaluation (https://github.com/atlassian-labs/compiled/pull/476)

Functions that take arguments can now be statically evaluated further, meaning you can further create reusable CSS atoms to reuse between components.

import '@compiled/react';

const font = color => ({
  color,
  fontSize: 20,
});

<div css={font('red')} />
.color-red { color: red; }
.font-size-20px { font-size: 20px; }
compiled -

Published by itsdouges almost 4 years ago

BREAKING CHANGES

Remove babel plugin entrypoint from @compiled/react (https://github.com/atlassian-labs/compiled/pull/504)

The babel plugin entrypoint has been removed from the @compiled/react package, along with the package dependency. This means how you install and consume Compiled has slightly changed now.

-npm i @compiled/react
+npm i @compiled/react @compiled/babel-plugin
{
-  "plugins": ["@compiled/react/babel-plugin"]
+  "plugins": ["@compiled/babel-plugin"]
}

Bug fixes

Chores

compiled -

Published by itsdouges almost 4 years ago

Chores

compiled -

Published by itsdouges almost 4 years ago

New features

CommonJS bundle (#419)

@compiled/react is now available as a CommonJS bundle - sourced via the usual main field in package.json. This means if you're using NextJS and other tools where your node module dependencies can't use ES modules you can now use Compiled!

Bug fixes

Browser bundle split points (#417)

Previously we were splitting server/browser module points via require() calls. Unfortunately this doesn't work in snowpack, and other strict bundlers. This code has now been consolidated into a single module. As an added bonus it also reduced the runtime bundle slightly.

Dynamic interpolations (#418 #423)

Previously this was a mess. There were a ton of edge case bugs, and the code wasn't something I'd want to tell my grandma about. Well - the code has now been mostly re-written - and definitely improved.

These changes closed a few bugs:

The one I'm really liking though is now dynamic interpolations (which are powered by CSS variables) will no longer leak to children if the child has an interpolation which resolved to undefined. Awesome!

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

const Box = styled.div`
  border: 2px solid ${props => props.color};
`;

<Box color="pink">
  Has a pink border
  <Box>Now has a black border, previously would have a pink border!</Box>
</Box>

JSX automatic runtime (#421)

With the new automatic runtime available in @babel/preset-react we wanted to ensure @compiled/react works great with it. A few changes were needed to get it working - but not much.

If you're using the new automatic runtime make sure to turn off automatic importing of React.

{
  "presets": [
      ["@babel/preset-react", { "runtime": "automatic" }]
  ],
  "plugins": [
    ["@compiled/react/babel-plugin", { "importReact": false }]
  ]
}

Normalize input CSS (#427)

Previously Compiled would generate different atomic CSS rules for CSS declarations that are semantically the same, but are written slightly different, for example selectors/at rules having different whitespace, and empty values being slightly different (0 vs. 0px).

A fix has been put in place where for all builds, whitespace will no longer affect atomic groups. This means the following example would generate the same atomic rule now:

> :first-child { color: red; }
>:first-child{ color: red; }

This same behavior also applies to at rules.

More advanced optimization happens when building for production, when NODE_ENV is set to production CSS values will be normalized and shrunk to their smallest possible values.

Chores

compiled -

Published by itsdouges almost 4 years ago

Bug fixes

Unguarded styled destructuring (https://github.com/atlassian-labs/compiled/pull/415)

When we added support for destructuring in styled interpolations, for example:

styled.div`
  font-size: ${({ isBig }) => isBig ? '20px' : '10px'};
`;

There were some scenarios where it would blow up because of unguarded code, which has now been fixed.

compiled - v0.5.0

Published by itsdouges almost 4 years ago

Compiled has been re-written as a Babel Plugin and has been architected for the future. The primary entry point to use Compiled now is via @compiled/react.

Installation

npm i @compiled/react

Read the installation docs for more help.

New features

All React APIs and behavior that was available in v0.4.x are still available in v0.5.0.

Consistent style overrides

When overriding styles now they will be applied consistently. Previously depending on the order you rendered them they could have the wrong styles! Now when using for example the styled API:

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

const RedText = styled.span`
  color: red;
`;

export const BlueText = styled(RedText)`
  color: blue;
`;

The text ends up always being blue! Awesome!

Conditional CSS rules

This one is huge! Now you can conditionally apply your CSS rules when using CSS prop.

import * as React from 'react';
import '@compiled/react';

export const Lozenge = (props) => (
  <span
    css={[
      props.primary && {
        border: '3px solid pink',
        color: 'pink',
      },
      !props.primary && {
        border: '3px solid blue',
        color: 'blue',
      },
    ]}>
    {props.children}
  </span>
);

Conditional CSS support for the styled and ClassNames apis are coming soon https://github.com/atlassian-labs/compiled/issues/390 https://github.com/atlassian-labs/compiled/issues/391.

Atomic CSS

The library now delivers atomic CSS when baked into the JavaScript. Previously this wasn't the case! But as we were re-writing the library as a Babel Plugin we quickly realized that the behavior when extracted to CSS would end up being different to when baked. Not good! To ensure we have a consistent experience throughout the life-cycle of components styled with Compiled we shifted gears earlier.

Instead of the output CSS looking like:

.aw2g43 {
  border: none;
  font-size: 14px;
  background-color: purple;
  border-radius: 3px;
}

It now looks more like:

._1ss5hd22 {
  border: none;
}

._f3a09ddd {
  font-size: 14px;
}

._7ssk3a2s {
  background-color: purple;
}

.uue229zs {
  border-radius: 3px;
}

However at the end of the day it's just an implementation detail. As a developer you won't actually be writing CSS like this. Interestingly shifting to atomic CSS has enabled both style overrides and CSS rules to be implemented - without it they could not work.

Module traversal

When importing things from other modules they are now able to be known and used in your CSS! Think of functions that return a CSS object, strings and numbers, and really anything else you'd want to use.

export const largeFont = {
  fontSize: 50,
};
import { styled } from '@compiled/react';
import { largeFont } from './mixins';

const Text = styled.h1`
  ${largeFont};
`;

This is a work-in-progress and there will definitely be edge cases that need to be fixed. Found one? Please raise an issue.

Static evaluation

Thanks to moving to Babel we can now evaluate expressions more easily. This means that code such as this:

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

const gridSize = 8;

const Box = styled.div`
  padding-top: ${gridSize * 3}px;
`;

Ends up generating static CSS:

padding-top: 24px;

This is a work-in-progress and there will definitely be edge cases that need to be fixed. Found one? Please raise an issue.

CLI & Codemods

To make migrating to Compiled easier we've made a CLI runner with its first preset - codemods! To run we recommend using npx:

npx @compiled/cli --preset codemods

Make sure to have @compiled/react installed locally before running - that's where the codemods live!

And then follow the prompts. There are known missing features and behavior that are on the roadmap to be implemented in the future - so you probably won't be able to convert everything using the codemods just yet.

This is a work-in-progress and there will definitely be edge cases that need to be fixed. Found one? Please raise an issue.

Array CSS

All APIs now support writing CSS with arrays, with the styled API also supporting multi arguments.

styled.div([
  `
  font-size: 12px;
`,
  { color: (props) => props.color },
])

styled.div(
  `
  font-size: 12px;
`,
  { color: (props) => props.color }
)

<div css={[`font-size: 12px;`, isPrimary && { color: 'blue' }]} />

<ClassNames>
  {({ css, style }) =>
    children({
      style,
      className: css([`font-size: 12px`, { color: 'blue' }]),
    })
  }
</ClassNames>

Breaking changes

  • TypeScript transformer support has been dropped.
compiled -

Published by itsdouges over 4 years ago

You know when you start working on something and then you get new information that changes things - but you forget to go back and fix up your stuff to use the new assumptions? Yeah.

Bug fixes

Template literal css extraction blows up when referencing an unknown import

When the transformer doesn't know what the import is (such as when it's being used in Babel, or when type checking is turned off) it would blow up instead of just... working. Not ideal.

...So now this code will work!

import { gridSize } from '@styles/my-lib';
import { styled } from '@compiled/css-in-js';

export const MySweetDiv = styled.div`
 padding: ${gridSize}px;
`;

This is an overarching pull & tug of utilizing TypeScript transformers in different contexts - the "fix" will probably come by others means, hopefully #217, but also maybe #67 #66 too.

compiled -

Published by itsdouges over 4 years ago

More bug fixes.

Bug fixes

  • Adds missing config to babel plugin to parse flow (#216)
  • Fixes hashing exploding when using a node creating during transformation (#219)
compiled -

Published by itsdouges over 4 years ago

Fixing an oopsie!

Bug fixes

Infinite loop when running Babel Flow (#215)

The code was inheriting the parent babelrc and caused an infinite loop - whoops! Should work great now though.

Edit:

Narrator: It didn't work great. Back to the drawing board 😎

These nightlies have it working:

compiled -

Published by itsdouges over 4 years ago

Few bug fixes and some nice features this release!

New features

Honor browserlist options via config/env vars (#211)

Thanks to @ankeetmaini browserlist options are now honored! This means if you have one set in your package json, browserlistrc file, or environment variables, it will be picked up! That's potential for big savings from reducing the amount of autoprefixing needed.

Bug fixes

Fix interpolations that are delimited by spaces being picked up as suffixes (#209)

There was a bug where some interpolations were breaking our CSS! This is fixed now - so the following code will work as expected.

import '@compiled/css-in-js';
import React from 'react';

const gridSize = () => 8;
const HORIZONTAL_SPACING = `${gridSize() / 2}px`;

<div css={{
  padding: `0 ${HORIZONTAL_SPACING}`,
  color: 'red',
}}>hello world</div>

Fix not working with Babel Flow (#214)

Before when using Compiled with Babel Flow types it would blow up. Now it should be smooth sailing to reach that pinnacle of compiled goodness!

Misc