tw-fns
v0.0.1
Published
A js/ts tailwindcss library implemented using pure functions
Readme
tw-fns
A js/ts tailwindcss library implemented using pure functions
Install
npm install tw-fns
yarn add tw-fns
pnpm add tw-fns
bun install tw-fnsUsage
import { twfns, flex, flex_col, items_center, justify_center } from "tw-fns";
const css = twfns(flex, flex_col, items_center, justify_center);
console.log(css);API
All api is designed from tailwindcss, about ~20000 api.
Utilities with some naming rules
- utilities: use underscore-connected property access
ml-1isml_1ml-1.5isml_1_dot_5ml-1/5isml_1_slash_5@containerisat_container- ..
- size: put number in the end
w-2xlisw_xl22xl:text-2xlisxl2(text_2xl)
Hover, focus, and other states
- use function to wrap
hover:ml-1ishover(ml_1)hover:active:ml-1ishover(active(ml_1))hover:active:ml-1 hover:active:bg-gray-100ishover(active(ml_1, bg_gray_100))- ..
Arbitrary value
- utilities: use function to wrap arbitrary value
ml-[20px]isml_("20px")w-[500px]isml_("500px")- ..
- states: use function to wrap arbitrary value
aria-[role=user]:text-blue-500isaria('role="user"', text_blue_500)has-[:active]:bg-amber-50ishas(':active', bg_amber_50)- ..
- named group
group-hover/some:text-blue-500isgroup_by("some", hover(text_blue_500))peer-hover/some:text-blue-500ispeer_by("some", hover(text_blue_500))- ..
There are some special api
Use aria-[...] to match combined styles
<div aria-group>- below element use
group(text_2xl, ...)
- below element use
<div aria-group="some">- below element use
group_by("some")(text_2xl, ...)
- below element use
<div aria-peer>- sibling element use
peer(text_2xl, ...)
- sibling element use
<div aria-peer="some">- sibling element use
peer_by("some")(text_2xl, ...)
- sibling element use
Container api
<div class={at_container}><div class={at_sm(text_2xl, ...)}>
License
MIT
