@@ -109,6 +109,83 @@ export const App: React.FC<{ disabled }> = ({ disabled }) => {
109109};
110110```
111111
112+ Custom button component example:
113+
114+ <!-- prettier-ignore -->
115+ ``` tsx
116+ import React from " react"
117+ import {
118+ classnames as tw ,
119+ hover ,
120+ TTailwindString ,
121+ } from " ../tailwindcss-classnames"
122+
123+ type Props = {
124+ type: " button" | " submit" | " reset"
125+ className? : TTailwindString | string
126+ variant? : " minimal" | " default" | " primary" | " outline"
127+ }
128+
129+ export const Button: React .FunctionComponent <Props &
130+ React .ButtonHTMLAttributes <HTMLButtonElement >> = (props ) => {
131+ const {type, children, className, variant = " default" , onClick} = props
132+ return (
133+ <button
134+ type = { type }
135+ onClick = { onClick }
136+ className = { ` ${buttonClasses [variant ]} ${className } ` }
137+ >
138+ { children }
139+ </button >
140+ )
141+ }
142+
143+ const baseClasses = tw (" rounded" , " py-2" , " px-4" , " font-semibold" )
144+ export const buttonClasses = {
145+ default: tw (
146+ baseClasses ,
147+ hover (" bg-gray-100" ),
148+ " text-gray-700" ,
149+ " border" ,
150+ " bg-gray-200" ,
151+ " border-gray-300"
152+ ),
153+ primary: tw (baseClasses , hover (" bg-blue-500" ), " bg-blue-600" , " text-white" ),
154+ outline: tw (
155+ baseClasses ,
156+ hover (" bg-blue-500" ),
157+ hover (" text-white" ),
158+ hover (" border-transparent" ),
159+ " bg-transparent" ,
160+ " text-blue-700" ,
161+ " border" ,
162+ " border-blue-500"
163+ ),
164+ minimal: tw (baseClasses , hover (" bg-gray-200" ), " bg-transparent" ),
165+ }
166+ ```
167+
168+ ## Generating types from tailwind config
169+
170+ The default types exported from this package are tailwindcss default ones.
171+ But if you modified some classes in your tailwind config file, you can use the CLI tool to create a file with generated types for these classes.
172+
173+ ### Use per project:
174+
175+ Add it in your package.json scripts:
176+
177+ ``` json
178+ "scripts" : {
179+ "generate" : " tailwindcss-classnames"
180+ }
181+ ```
182+
183+ or simply run ` npx tailwindcss-classnames `
184+
185+ ### Install globally:
186+
187+ just ` npm i -g tailwindcss-classnames ` and run the command where the config file is located.
188+
112189## Custom typing
113190
114191By default you have all the classes available as types, though you might not use all of them. You can customize your own by:
0 commit comments