tabulator icon indicating copy to clipboard operation
tabulator copied to clipboard

Tailwind CSS support

Open leodip opened this issue 1 year ago • 4 comments

I love the library, I must say.

I hope one day it supports Tailwind CSS. Most modern applications are being written with Tailwind today...

Thanks!

leodip avatar Oct 24 '23 18:10 leodip

Can you assign this to me!

Mstanic05 avatar Oct 26 '23 03:10 Mstanic05

@Mstanic05 hey absolutely, if you want to do a PR with a new theme then please do, I would love that!

Oli :)

olifolkerd avatar Oct 26 '23 18:10 olifolkerd

Tailwind needs a build process where it scans your (html) files, so you can not just add the class names, because Tailwind will not recognize them. There is a better way to use Tailwind with third-party components like Tabulator: component classes

Example from my project:

/* File: app.css */
@import  "tabulator-tables/dist/css/tabulator_simple.min.css";

@tailwind base;
@tailwind components;
@tailwind utilities;

/*@layer components {  /* --- do not use layer if you want to force inclusion   */

  .tabulator {

        .tabulator-headers, .tabulator-row {
            @apply flex border-b border-dotted border-neutral-400;
        }

        .tabulator-cell[tabulator-field='field1'], .tabulator-col[tabulator-field='field1'] {
            @apply border-r border-neutral-300 mr-4;
        }

        .tabulator-cell[tabulator-field='field2'], .tabulator-cell[tabulator-field='field3'] {
            @apply bg-neutral-100;
        }

   }
  /* ... */
/*}*/

This way you can edit the complete table with tailwind according to your needs.

(There is one improvement you could do for tailwind users: i needed an unstyled base theme, so i removed all background, color, border and font styles from your tabulator.scss. Then i could start styling from scratch with tailwind. But the component classes also works with pre-styled versions. Regex for lines i removed: ^([^$\n].*(background|color|border|font)(?!-box).*)$)

Update: Leave out the @layer components line, to make sure the css code will be included. (https://tailwindcss.com/docs/adding-custom-styles#removing-unused-custom-css)

FaBay89 avatar Oct 27 '23 11:10 FaBay89

@FaBay89

What would be your recommendation for Tabulator then? is there something i could add to the docs to make this clearer to users?

Cheers

Oli :)

olifolkerd avatar Feb 04 '24 21:02 olifolkerd