tw classed
@tw-classed
TW分類項目的Monorepo。由核心和反應軟件包組成。
完整的文檔
React軟件包是圍繞核心軟件包的包裝器,它提供了一種易於創建分類組件的方法。查看React文檔
// Button.tsx
import { classed } from "@tw-classed/react" ;
const Button = classed . button ( "px-4 py-2" , {
variants : {
color : {
primary : "bg-blue-500 text-white" ,
secondary : "bg-gray-500 text-white" ,
} ,
} ,
} ) ;
// In your App
const App = ( ) => {
return (
< >
< Button color = "primary" > Primary </ Button >
< Button color = "secondary" > Secondary </ Button >
</ >
) ;
} ; 核心包是一個提供一組功能的庫,可以幫助您構建自己的分類組件。
查看核心文檔
import { classed } from "@tw-classed/core" ;
const button = classed ( "px-4 py-2" , {
variants : {
color : {
primary : "bg-blue-500 text-white" ,
secondary : "bg-gray-500 text-white" ,
} ,
} ,
} ) ;
// In your template
const Button = document . createElement ( "button" ) ;
Button . className = button ( { color : "primary" } ) ;
// Or with a framework (Like lit-html)
const Button = ( ) => html ` < button class =" ${ button ( { color : "primary" } ) } " /> ` ; 麻省理工學院