All Projects → muhammadsammy → Tailwindcss Classnames

muhammadsammy / Tailwindcss Classnames

Licence: mit
TypeScript support for TailwindCSS

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Tailwindcss Classnames

tailwind-cascade
Override TailwindCSS classes for component composition
Stars: ✭ 28 (-90.82%)
Mutual labels:  composition, tailwindcss
Vim Quantum
A Material color scheme for Vim.
Stars: ✭ 304 (-0.33%)
Mutual labels:  neovim
Go Client
Nvim Go client
Stars: ✭ 284 (-6.89%)
Mutual labels:  neovim
Windmill Dashboard React
❄ A multi theme, completely accessible, ready for production dashboard.
Stars: ✭ 283 (-7.21%)
Mutual labels:  tailwindcss
Vim Colors Github
A Vim colorscheme based on Github's syntax highlighting as of 2018.
Stars: ✭ 286 (-6.23%)
Mutual labels:  neovim
Laravel Form Components
A set of Blade components to rapidly build forms with Tailwind CSS (v1.0 and v2.0) and Bootstrap 4. Supports validation, model binding, default values, translations, Laravel Livewire, includes default vendor styling and fully customizable!
Stars: ✭ 295 (-3.28%)
Mutual labels:  tailwindcss
Vim Terraform Completion
A (Neo)Vim Autocompletion and linter for Terraform, a HashiCorp tool
Stars: ✭ 280 (-8.2%)
Mutual labels:  neovim
Chromatica.nvim
Clang based syntax highlighting for Neovim
Stars: ✭ 306 (+0.33%)
Mutual labels:  neovim
Dotfiles
Configuration files I use on my main machine
Stars: ✭ 299 (-1.97%)
Mutual labels:  neovim
Blamer.nvim
A git blame plugin for neovim inspired by VS Code's GitLens plugin
Stars: ✭ 283 (-7.21%)
Mutual labels:  neovim
Stampit
OOP is better with stamps: Composable object factories.
Stars: ✭ 3,021 (+890.49%)
Mutual labels:  composition
Kickoff tailwind
A rapid Rails 6 application template for personal use bundled with Tailwind CSS
Stars: ✭ 287 (-5.9%)
Mutual labels:  tailwindcss
Vimtex
VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
Stars: ✭ 3,609 (+1083.28%)
Mutual labels:  neovim
Spacevim
A community-driven modular vim/neovim distribution - The ultimate vimrc
Stars: ✭ 17,558 (+5656.72%)
Mutual labels:  neovim
Intellij Elm
Elm language support for IntelliJ, WebStorm, PhpStorm and PyCharm (JetBrains)
Stars: ✭ 305 (+0%)
Mutual labels:  webstorm
Vlime
A Common Lisp dev environment for Vim (and Neovim)
Stars: ✭ 279 (-8.52%)
Mutual labels:  neovim
Sapper Ecommerce
Svelte ecommerce - Headless, Authentication, Cart & Checkout, TailwindCSS, Server Rendered, Proxy + API Integrated, Animations, Stores, Lazy Loading, Loading Indicators, Carousel, Instant Search, Faceted Filters, 1 command deploy to production, Open Source, MIT license. Join us as contributor ([email protected])
Stars: ✭ 289 (-5.25%)
Mutual labels:  tailwindcss
Spaceduck
🚀 🦆 An intergalactic space theme for Vim, Terminal, and more!
Stars: ✭ 177 (-41.97%)
Mutual labels:  neovim
Vimpyter
Edit your Jupyter notebooks in Vim/Neovim
Stars: ✭ 308 (+0.98%)
Mutual labels:  neovim
Dashboard Nvim
vim dashboard
Stars: ✭ 294 (-3.61%)
Mutual labels:  neovim

tailwindcss-classnames NPM npm bundle size npm version

Functional typed classnames for TailwindCSS

TailwindCSS is a CSS library that has gained a lot of traction. The developer experience is pretty epic and you ensure a low footprint on your css by composing existing classes for most of your css.

So why mess with it?

TailwindCSS is based on strings and with some nice tooling on top like TailwindCSS VSCode extension you get a pretty descent experience. That said, there are limitations to a purely declarative approach of strings. When using tailwindcss-classnames you will get additional power in the form of:

  • Validation of classnames: You can not write the wrong classname, cause the API only allows you to insert valid classnames
  • Functional approach: Since we are working in Typescript we get more freedom in using functional powers like composition and dynamic composition
  • Defining by variables: Even though it is nice to write TailwindCSS inline with your elements, it does not scale. You want to move definitions outside of the component for reusability and composition
  • Support for all editors and IDEs: Because it's just TypeScript types, you get these powers in all editors and IDEs that support TypeScript.

You can not get this experience using pure TailwindCSS and the VSCode extension, but you do get it with tailwindcss-classnames.

Edit tailwindcss-classnames

Install

Please follow the guide to set up TailwindCSS. Now do:

npm install tailwindcss-classnames

⚠️ NOTE: This project versions match with TailwindCSS versions except for semver patch releases

The project is literally the classnames project with custom typing. That means it arrives at your browser at approximately 484b minified and gzipped (bundlephobia).

Create classes

import {classnames} from 'tailwindcss-classnames';

classnames('border-none', 'rounded-sm');

The arguments passed to classnames is typed, which means you get discoverability. You can even search for the supported classes:

DISCOVER

Dynamic classes

Since we are using classnames you can also add your classes dynamically:

import {classnames} from 'tailwindcss-classnames';

classnames('border-none', 'rounded-sm', {
  ['bg-gray-200']: true,
});

Composing classes

Even though classnames just returns a string, it is a special typed string that you can compose into other definitions.

import {classnames} from 'tailwindcss-classnames';

export const button = classnames('border-none', 'rounded-sm');

export const redButton = classnames(button, 'bg-red-100');

Using with React

Since React has excellent typing support I want to give an example of how you could use it.

// styles.ts
import {classnames} from 'tailwindcss-classnames';

export const form = classnames('container', 'w-full');

export const button = classnames('border-none', 'rounded-sm');

export const alertButton = classnames(button, 'bg-red-100');

export const disabled = classnames('opacity-25', 'bg-gray-100');

export const submitButton = (disabled: boolean) =>
  classnames(styles.button, {
    [styles.disabled]: disabled,
  });

// App.tsx
import * as React from 'react';
import * as styles from './styles';

export const App: React.FC<{disabled}> = ({disabled}) => {
  return (
    <form className={styles.form}>
      <button type="submit" className={styles.submitButton(disabled)}>
        Submit
      </button>
      <button className={styles.alertButton}>Cancel</button>
    </form>
  );
};

Using the CLI

The types included in this package are the default tailwindcss classes, but if you modified your tailwind config file and/or want to add external custom classes, you can use the CLI tool to do this.

CLI arguments:

  -i, --input <input>    Name or relative path of the TailwindCSS config file **(if not provided, tries to find 'tailwind.config.js')**
  -o, --output <output>  Name or relative path of the generated types file **(optional, default: "tailwindcss-classnames.ts")**
  -x, --extra <extra>    Name or relative path of the file with the custom extra types **(optional)**
  -h, --help             display help for command

Example of CLI usage:

Add the CLI to npm scripts in your package.json then run npm run generate-css-types or yarn generate-css-types:

"scripts": {
  "generate-css-types": "tailwindcss-classnames -i path/to/tailwind.config.js -o path/to/output-file.ts"
}

⚠️ NOTE: that if you want to add custom types from external file, the type must be a default export:

export default MyCustomType;
type MyCustomType =
  | "btn"
  | "sidebar"
  ...

Known limitiations

  • Relative imports inside the config does not work. use __dirname instead. See #120 for details.
  • Don't run as npx tailwindcss-classnames, use as an npm script as mentioned above.
  • Backlog

Any help with these issues is very much appreciated.

Contributing

All contributions from everyone are very welcome.

Feel free to use the discussions to ask questions or discuss anything related to the project. Please use the issue template when submitting an issue.

To submit patches or features:

  1. Fork the repo
  2. Run yarn install
  3. Make changes
  4. Build and run the CLI by yarn run-cli
  5. Submit your changes via GitHub Pull Requests.

Credits

This project was started by Christian Alfoni and is now maintained by Muhammad Sammy. The full list of contributors can be found here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].