USAGE
Basic styling
How to do basic styling with tailwindest.
Overview
- Define reusable style using
stylefunction - Define inline styles using
deffunction - Define conditional styles using
toggle,rotaryandvariantsfunctions
Example 1: Define style tokens
Extract and define common styles tokens in your components to maximize reusability.
const layout = tw.style({
// ... Core layout
})
const border = tw.style({
// ... Border styles
})Export utility styles
export const token = {
layout,
border,
} as constExample 2: Compose(Merge) styles
tw.style returns a styler instance with three main methods:
class(): returns classNamestringstyle(): returns styleSheetobjectcompose(...styles): returns a new styler instance with composed styles.
The
composefunction allows you to overwrite styles without the need for aclassNamemerging library liketailwind-merge.
Usage 1 - merge styleSheets
The last style object passed to compose has the highest priority.
const basic = tw
.style({
alignItems: "items-start",
})
.compose(
{
alignItems: "items-end",
},
{
alignItems: "items-stretch",
}
)
// ✨ items-stretchUsage 2 - separate util styles and compose it
Define design token
const container = tw.style({
// ... Container styles
})
export const token = {
container,
} as constCompose utility styles where you need.
import { token } from "@/token"
const box = tw
.style({
display: "flex",
alignItems: "items-center",
justifyContent: "justify-center",
})
.compose(token.container.style())
.class()
const Box = ({ children }) => <div className={box}>{children}</div>