π¦ΉββοΈ Twin blends the magic of Tailwind with the flexibility of css-in-js (emotion, styled-components, solid-styled-components, stitches and goober) at build time.
MIT License
Bot releases are hidden (Show)
Published by ben-rogerson over 4 years ago
Twin now supports popular plugins like Tailwind UI and Custom forms.
See the list of supported plugins β
It takes a while to convert the free Tailwind UI components over to React, so I've saved you some hassle. These will be replaced with the official Tailwind React components once they are released.
Twin + Tailwind UI React components β
Twin is now full to the brim with built-in variants!
In addition to the base Tailwind variants, the following variants are now available on your classes:
// Before/after
tw`before:content`
tw`after:content`
// Interactive links/buttons
tw`hocus:flex`
tw`link:flex`
tw`target:flex`
tw`focus-visible:flex`
// Form element states
tw`checked:flex`
tw`not-checked:flex`
tw`default:flex`
tw`enabled:flex`
tw`indeterminate:flex`
tw`invalid:flex`
tw`valid:flex`
tw`optional:flex`
tw`required:flex`
tw`placeholder-shown:flex`
tw`read-only:flex`
tw`read-write:flex`
// Not things
tw`not-first:flex`
tw`not-last:flex`
tw`not-only-child:flex`
// Only things
tw`only-child:flex`
tw`only-of-type:flex`
// Group states
tw`group-hocus:flex`
tw`group-active:flex`
tw`group-visited:flex`
See the config for more information β
Check mdn for pseudo-class descriptions β
I've seen class lists where the pipe character is used as a divider so I've added the feature in Twin:
tw="flex | bg-black"
tw`flex | bg-black`
I've added a new demo for styling with emotion + twin in vue.
There's no css/tw prop support yet but it's pretty cool to know it's possible.
See the vue + emotion + twin codepen β
Published by ben-rogerson over 4 years ago
tw
prop users (dev only)Feature request from #62
Once your classes have been converted to css, there's no way to tell in your devtools what the classes were. By activating the debugProp, the classes will show in a special data-tw
prop in development, much like you're used to seeing in vanilla Tailwind:
<div data-tw="flex flex-col justify-center h-full space-y-6" class="App___StyledDiv2-e1igrf-1 jkPhmw">
Activate the class display by adding debugProp: true
to your twin config:
twin: {
debugProp: true,
},
To help out with some linting setups, curly brackets can now be used with the tw prop:
<div tw={'flex flex-col justify-center h-full space-y-6'}>
Fixes #79
All variants are now working again with your custom utility plugins.
There's no need to define which variants are applied to your classes, they'll accept the entire range of variants available on the base classes:
// tailwind.config.js
module.exports = {
// ...
plugins: [breakPlugin],
}
function breakPlugin({ addUtilities }) {
addUtilities({
'.break-anywhere': {
'overflow-wrap': 'anywhere',
hyphens: 'auto',
},
})
}
// App.js
export default () => <div tw="md:break-anywhere">ThisBreaksUpWhenNeededWithAHyphen</div>
Published by rbutera over 4 years ago
Version 1.1.0 was a major improvement to developer experience but required further changes to support TypeScript projects.
This version fixes the problems with those improvements:
tw
as named export (must only be used as default export again)TwStyle
css
and styled
import shortcuts - styled-components / emotion
Thank you for using Twin!
Published by ben-rogerson over 4 years ago
Published by ben-rogerson over 4 years ago
In this version, Twin has a whole bunch of developer experience improvements.
Let me run through the changes:
Aligned the type definitions with the string interpolation feature added in the previous release - Issue ref
Validation for twin imports - Twin will provide feedback if you happen to get any of its imports wrong
import tw, { styled, css } from 'twin.macro'
Behind-the-scenes, Twin adds the necessary css library imports for you based on your Twin config.
The imports will only be added if you use them within your code.
Note: If you're not using Emotion then you'll need to adjust your config to use the new css import.
You can either add the import with the css
config option that works just like the existing styled option or use the new preset feature below ({ preset: 'styled-components' }
).
import 'twin.macro'
<input tw="w-full" />
This fixes all those tw is unused
warnings π β Thanks to @zaguiini for the PR!
If you're using styled-components
, you can now add a preset and Twin will take care of adding the correct imports for styled-components (in the right order too):
// In package.json or in your babel macro config:
{ preset: 'styled-components' }
This option defaults to { preset: 'emotion' }
and setting a preset will override any custom imports.
By adding { autoCssProp: true }
to your config, Twin will import styled-components/macro
on your behalf - but only when you need it. Check the Twin config docs for more info.
Styled components can also be fussy with the import order so this option will let Twin take care of it for you.
That's all for now!
Ben
Published by ben-rogerson over 4 years ago
Twin has hit v1 π
To help celebrate, we've added support for Tailwind v1.4, tw variables and better suggestions!
Support for basic variables added within tw backticks
You can now use variables within your tw calls. This means you can import and reuse styles.
Only basic evaluations are supported so no functions or conditionals can be used:
const basicVariable = 'bg-purple-500'
const PurpleBox = tw.div`${basicVariable}`
Better suggestions from your config
To help with misspellings and class discovery, Twin can now fuzzy match suggestions from your config.
Added a checked:
variant
Great for radios and checkbox styling: checked:text-purple-500
- See all variants
Added container
margins
Expanding on the custom paddings introduced in Tailwind v1.4 is the ability to set custom left/right margins on the container:
// tailwind.config.js
module.exports = {
theme: {
container: {
// Twin v1.0.0 feature
margin: {
default: '1rem',
sm: ['2rem', '3rem'],
lg: ['4rem', '5rem'],
xl: ['5rem', '6rem'],
},
// Tailwind v1.4 feature
padding: {
default: '1rem',
sm: '2rem',
lg: '4rem',
xl: '5rem',
},
},
},
}
Jump in our new Twin Discord channel for further Twin v1.0.0 discussion.
Published by ben-rogerson over 4 years ago
Twin now has TypeScript support! Thanks to @kingdaro, Twin should feel a little more "integrated" with your editor.
In addition to group-hover
, you now have some new custom classes to work with:
tw`group-hocus:bg-red-500`
tw`group-focus:bg-red-500`
tw`group-active:bg-red-500`
tw`group-visited:bg-red-500`
// β β β β β β
;({
'.group:hover &, .group:focus &': {
backgroundColor: '#f56565'
}
})
;({
'.group:focus &': {
backgroundColor: '#f56565'
}
})
;({
'.group:active &': {
backgroundColor: '#f56565'
}
})
;({
'.group:visited &': {
backgroundColor: '#f56565'
}
})
To use these group classes, you'll first need to add a group
className on a container element.
<div className="group"><button tw="group-hocus:bg-red-500">Test</button></div>
Stay healthy!
Published by ben-rogerson over 4 years ago
Twin now supports addUtilities
in your config plugin section.
// In tailwind.config.js
module.exports = {
theme: {
extend: {},
},
plugins: [
({ addUtilities, theme }) => {
const newUtilities = {
".type-sm": {
fontSize: theme("fontSize.sm"),
fontWeight: theme("fontWeight.medium"),
lineHeight: theme("lineHeight.tight")
}
};
addUtilities(newUtilities);
}
]
};
Further plugin support is planned for the future.
Suggestions have been upgraded and now look at more of your config. This feature will help fix mistakes and improve class discoverability.
β bloc was not found
Did you mean block?
β flex-0 was not found
Try one of these classes:
flex-grow-0 [0] / flex-grow [1] / flex-shrink-0 [0] / flex-shrink [1] / flex-1 [1 1 0%] / flex-auto [1 1 auto]
flex-initial [0 1 auto] / flex-none [none] / flex / flex-row / flex-row-reverse
flex-col / flex-col-reverse / flex-no-wrap / flex-wrap / flex-wrap-reverse
More soon, cheers
Published by ben-rogerson over 4 years ago
This release added the following features:
transform
and translate-...
classes!important
within the tw
blocks, just add a bang on the end of any Tailwind class:// In
tw`flex! bg-purple-500!`
// Out
styled.div({
"display": "flex !important",
"backgroundColor": "#9f7aea !important"
})
:hocus
variant - Tackle both hover and focus pseudo-classes at once with this magic sounding variant:// Old
tw.div`hover:bg-purple-500 focus:bg-purple-500`
// New
tw.div`hocus:bg-purple-500`
> β βflex-testβ was not found in the Tailwind config.
>
> Available flex classes:
> flex-1 [1 1 0%] / flex-auto [1 1 auto] / flex-initial [0 1 auto] / flex-none [none]
These suggestions will be rolled out to the rest of the classes in coming releases.
Published by ben-rogerson over 4 years ago
variants
config. This is only possible because Twin.macro doesn't pre-generate styles before you use them.Take a look at the installation instructions to get started.