The ✨first✨ online playground for Twin.macro. Check out the FAQ below for details.
Created by Luke Murray.
<buttontw="text-white bg-gradient-to-r from-purple-500 to-pink-500 hover:bg-gradient-to-l focus:ring-4 focus:outline-none focus:ring-purple-200 dark:focus:ring-purple-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center mr-2 mb-2">Purple to Pink</button>
const buttonBaseStyles = tw`py-2 px-4 text-sm font-medium text-gray-900 bg-transparent border-gray-900 hover:bg-gray-900 hover:text-white focus:z-10 focus:ring-2 focus:ring-gray-500 focus:bg-gray-900 focus:text-white dark:border-white dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:bg-gray-700`;const Button = styled.button`${buttonBaseStyles};${({ variant }) => variant === "left" && tw`rounded-l-lg border`}${({ variant }) => variant === "right" && tw`rounded-r-lg border`}${({ variant }) => variant === "center" && tw`border-t border-b`}`const ButtonGroup = tw.div`inline-flex rounded-md shadow-sm`;// note the render function. you must call this to render a componentrender(<ButtonGroup><Button variant="left">Profile</Button><Button variant="center">Settings</Button><Button variant="right">Download</Button></ButtonGroup>)
Inline
Inline mode renders simple code that can be wrapped in a return statement.
<input tw="border hover:border-black" />
Multi-line
Multi-line line mode renders more complex code with multiple statements. But you need to call "render" at the end of the code to render your component.
const Input = tw.input`border hover:border-black`
const PurpleInput = tw(Input)`border-purple-500`
// note the render function!
render(<PurpleInput />)
// you need to call render! this would not work :(
// <PurpleInput />
The playground gives you access to the following imports.
import tw, { css, styled, screen, theme } from "twin.macro";
import React from "react";
No, not yet.
Yes! checkout the component and hooks example.
To see more examples check a page with all the examples from the twin.macro readme.
Not yet! However, all of the code for this site can be found on github. Feel free to open an issue or submit a pull request.
Most of the changes necessary to make this work can be found in this commit. If there is interest I may put together a write up explaining it. Let me know!
Credit to flowbite for the components used in the default examples.