0.4.7 ā€¢ Published 4 years ago

@compiled/ts-transform-css-in-js v0.4.7

Weekly downloads
111
License
Apache-2.0
Repository
github
Last release
4 years ago

šŸ‘·ā€ā™€ ā€Compiled

The CSS in JS authoring experience you love without the runtime cost. Get started now āž”ļø

Installation

npm i @compiled/css-in-js

Babel

npm i @compiled/babel-plugin-css-in-js

Then add the plugin to your Babel config:

{
  "plugins": ["@compiled/babel-plugin-css-in-js"]
}

TypeScript compiler

Using either tsc directly, ts-loader with webpack, or the default Parcel configuration with TypeScript.

We use TypeScript transformers to control the transformation - strong suggestion to read the handbook for getting started with them.

npm i @compiled/ts-transform-css-in-js
npm i ttypescript

Why do I need ttypescript?

Good question! Unfortunately TypeScript doesn't come with support out-of-the-box to add transformers. ttypescript enables you to do just that - it has a peer dependency on TypeScript so you can use whatever version you want. Read about consuming transformers here.

Next add the transformer to your tsconfig.json plugins:

{
  "compilerOptions": {
+    "plugins": [{ "transform": "@compiled/ts-transform-css-in-js" }]
  }
}

Then it's just a matter of modifying what you're using to compile your code.

TypeScript CLI

Using tsc directly? Just switch it out for ttsc - the ttypescript equivalent.

-tsc
+ttsc

Webpack

Using Webpack? Add ttypescript as the compiler.

{
  loader: require.resolve('ts-loader'),
  options: {
+    compiler: 'ttypescript',
  },
},

Parcel

Using Parcel? Just install the ttypescript plugin and you're done!

npm i parcel-plugin-ttypescript --save-dev

Usage

css prop

import '@compiled/css-in-js';

<div css={{ fontSize: 12 }} />;

styled component

import { styled } from '@compiled/css-in-js';

styled.div`
  font-size: 12px;
`;

ClassNames component

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

<ClassNames>{({ css }) => <div className={css({ fontSize: 12 })} />}</ClassNames>;

Browser support

IE / EdgeFirefoxChromeSafariiOS Safari
IE11 āš ļø, Edgelast 2 versionslast 2 versionslast 2 versionslast 2 versions

āš ļø IE11 is partially supported. Compiled uses CSS variables for dynamic properties so unless you enable a ponyfill such as css-vars-ponyfill you won't be able to use them. Alternatively you can define static selectors and conditionally apply them in your code.

Local development

Compiled is a monorepo - where we deliver multiple small packages instead of one big package. You'll find them in the packages folder. Want to make changes to the website? You'll find it here.

Packages of note

  • css-in-js - entrypoint for consumers of Compiled - has a small amount of runtime code that blows up without the transformer enabled
  • ts-transform - main bulk of Compiled's code - it transforms consumer code into Compiled components
  • babel-plugin - thin wrapper around ts-transform to enable Babel environments to consume Compiled
  • jest - jest matcher to make testing Compiled css easier
  • style - small component to reconcile moving styles to the head of the document at runtime

Tests

We use Jest for tests. Find the folder you want to make changes to, and run that subset of tests. For example:

yarn test packages/ts-transform/src/css-prop --watch

Storybook

yarn start

Contributing

Thank you for considering a contribution to Compiled! Before doing so, please make sure to read our contribution guidelines.

Atlassian

0.4.7

4 years ago

0.4.6

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.16

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.2

4 years ago

0.1.0

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago