- Notifications
You must be signed in to change notification settings - Fork0
Concatenate your classes (with shortcuts) 🔗
License
joe-bell/cx
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
⚠️ This project has been deprecated in favour ofcva
Concatenate your classes (with shortcuts)
cx
is atiny function that mimics and extends the popularclassnames
utility with"shortcuts" to re-use common classes (with TypeScript autocompletion)
💡 Works especially nicely withTailwind IntelliSense
Install the package via your favourite package manager:
npm i @joebell/cx
Create a custom
cx
function for later use.Common styles can be defined in the
shortcuts
and accessed by it's"key"
for re-use later.⚠️ FYI: At this point in time, your shortcuts must be a flat object with no nested keys.// styles/index.tsimport{createCx}from"@joebell/cx";constshortcuts={// Components"c-container":["block","max-w-5xl","mx-auto","px-4"],// Utilities"u-border":["border-dashed","border-black"],};exportconstcx=createCx(shortcuts);
Import
cx
into your component or layout.For example, in React.js:
// pages/index.tsximport{cx}from"../styles";constPage:React.FC=({ children})=>(<mainclassName={cx("c-container","mt-4")}>{children}</main>);
returns…
<mainclass="block max-w-5xl mx-auto px-4 mt-4">…</main>
💡Tip: If you're having issues withTailwind IntelliSense in VSCode, try reloading the window
Without these projects/people, this project wouldn't exist…
About
Concatenate your classes (with shortcuts) 🔗