GithubHelp home page GithubHelp logo

thedemodev / compiled-css-in-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from atlassian-labs/compiled

0.0 0.0 0.0 1.08 MB

πŸ‘·β€β™€ The CSS in JS authoring experience we love without the runtime cost.

Home Page: https://compiledcssinjs.com

License: Apache License 2.0

TypeScript 98.04% JavaScript 1.57% Shell 0.33% HTML 0.06%

compiled-css-in-js's Introduction

πŸ‘·β€β™€ ‍Compiled

The CSS in JS authoring experience we love without the runtime cost. Get started now ➑️

Installation

npm i @compiled/css-in-js

Babel

Click to expand...
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.

Click to expand...

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 we'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 / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
iOS Safari
IE11 ⚠️, Edge last 2 versions last 2 versions last 2 versions last 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

compiled-css-in-js's People

Contributors

itsdouges avatar madou avatar marionebl avatar danieldelcore avatar ankeetmaini avatar obweger avatar gwyneplaine avatar flexdinesh avatar alexytsu avatar highvoltag3 avatar jdanil avatar pgmanutd avatar dependabot[bot] avatar vanya829 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.