0.0.8 • Published 4 years ago

blossom-design v0.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

🔥 Demo this example on CodeSandbox →

Getting started

1. Install Create React App

npx create-react-app my-app

2. Install the dependencies

npm install --save twin.macro styled-components
yarn add twin.macro styled-components

3. Add the global styles

Projects using Twin also use the Tailwind preflight base styles to smooth over cross-browser inconsistencies.

Twin adds the preflight base styles with the GlobalStyles import which you can add in src/App.js:

// src/App.js
import { GlobalStyles } from 'twin.macro'

const App = () => (
  <div>
    <GlobalStyles />
    {/* ... */}
  </div>
)

export default App

GlobalStyles also includes some @keyframes so the animate-xxx classes have animations. But if you’re not using the animate classes then you can avoid adding the extra keyframes.

4. Add the recommended config

Twin’s recommended config can get added in a couple of different places.

a) In a new file named babel-plugin-macros.config.js placed in your project root:

// babel-plugin-macros.config.js
module.exports = {
  twin: {
    config: 'tailwind.config.js',
    preset: 'styled-components',
    autoCssProp: true,
    debugProp: true,
    debugPlugins: false,
    debug: false
  }
}

b) Or in your package.json:

// package.json
"babelMacros": {
    "twin": {
      "config": "tailwind.config.js",
      "preset": "styled-components",
      "autoCssProp": true,
      "debugProp": true,
      "debugPlugins": false,
      "debug": false,
    }
},

5. Complete the TypeScript support (TypeScript only)

Twin comes with types for every import except the css and styled imports.

Add the remaining types →

Options

NameTypeDefaultDescription
configstring"tailwind.config.js"The path to your Tailwind config
presetstring"emotion"The css-in-js library behind the scenes - also supports 'styled-components' and 'goober'
autoCssPropbooleanfalseThis code automates the import of 'styled-components/macro' so you can use their css prop. Enable it if you're using styled-components with React, CRA or Gatsby. If you're using Emotion, setting to true does nothing.
hasSuggestionsbooleantrueDisplay class suggestions when a class isn't found
debugPluginsbooleanfalseDisplay generated class information in your terminal from your plugins
debugPropbooleanfalseAdd a prop to your elements in development so you can see the original tailwind classes, eg: <div data-tw="bg-black" />
debugbooleanfalseDisplay information in your terminal about the Tailwind class conversions
disableColorVariablesbooleanfalseDisable css variables in colors (not gradients) to help support IE11/react native

Customized imports

Instead of using preset: "styled-components", you can also customize the styled, css and GlobalStyles imports with the following config:

// babel-plugin-macros.config.js
module.exports = {
  twin: {
    styled: {
      import: 'default',
      from: 'styled-components'
    },
    css: {
      import: 'css',
      from: 'styled-components/macro'
    },
    global: {
      import: 'createGlobalStyle',
      from: 'styled-components'
    }
  }
}
// package.json
"babelMacros": {
  "twin": {
    "styled": {
      "import": "default",
      "from": "styled-components"
    },
    "css": {
      "import": "css",
      "from": "styled-components/macro"
    },
    "global": {
      "import": "createGlobalStyle",
      "from": "styled-components"
    }
  }
},

Note: Make sure you remove the preset option as that value disables these custom options.

Next steps

More examples with Styled Components

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago