css-to-tailwindcss icon indicating copy to clipboard operation
css-to-tailwindcss copied to clipboard

Setting multiple selectors in the same CSS rule returns an unexpected result

Open fazdiu opened this issue 1 year ago • 0 comments

Setting multiple selectors in the same CSS rule returns an unexpected result: For example:

import { TailwindConverter } from 'css-to-tailwindcss';
import postcssNested from "postcss-nested";

const converter = new TailwindConverter({
  remInPx: 16, // set null if you don't want to convert rem to pixels
  postCSSPlugins: [postcssNested], // add any postcss plugins to this array
  tailwindConfig: {
    // your tailwind config here
    content: [],
    theme: {
      extend: {
        colors: {},
      },
    },
  },
});

const inputCSS = `
.test{
  color:red;

  &:hover, &:focus{
    color: blue;
  }
}`;

converter.convertCSS(inputCSS).then(({ convertedRoot, nodes }) => {
  console.log(convertedRoot.toString());
});

Obtained result:

.test {
  @apply text-[red];
}
.test:hover,
.test:focus {
  @apply text-[blue];
}

Expected result:

.test {
  @apply text-[red] focus:text-[blue] hover:text-[blue];
}

fazdiu avatar Jan 28 '24 18:01 fazdiu