Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.
/ twind.macro Public archive

This package is been moved into tw-in-js/twind-jsx-preprocessor monorepo.

Notifications You must be signed in to change notification settings

tw-in-js/twind.macro

Repository files navigation

This package is been moved into tw-in-js/twind-jsx-preprocessor:packages/macro.

Please check out the new tw-in-js/twind-jsx-preprocessor monorepo.

@twind/macro

Enables the use of the tw prop, for use with twind

import "@twind/macro"
const Button = () => <button tw="bg-blue-500" />

// ⬇⬇⬇⬇⬇⬇

import { tw } from "twind"
const Button = () => <button className={tw`bg-blue-500`} />

More complex usage is supported:

import "@twind/macro"

const Button = () => (
	<button
		tw={[
			"bg-blue-500",
			condition && "text-red-500",
			{ "border-green-500": true },
		]}
	/>
)

// ⬇⬇⬇⬇⬇⬇

import { tw } from "twind"

const Button = () => (
	<button
		className={tw([
			"bg-blue-500",
			condition && "text-red-500",
			{ "border-green-500": true },
		])}
	/>
)

Installation

  1. Add babel-plugin-macros to your babel config (if you use Create React App, it's already installed!)
  2. Run npm install @twind/macro
  3. Enjoy ☺