tailwindlabs / tailwindcss-forms

A plugin that provides a basic reset for form styles that makes form elements easy to override with utilities.
https://tailwindcss-forms.vercel.app
MIT License
4.15k stars 219 forks source link

Add type declaration #117

Closed zanona closed 2 years ago

zanona commented 2 years ago

This PR adds the ability to import the package under typescript. My use case has been importing tailwind configuration directly inside vite.config.ts files and as such, I had to manually declare the types for @tailwindcss/forms.

Since my package was set to type: module I could not use require either.

// vite.config.ts
import autoprefixer from "autoprefixer";
import tailwindcss from "tailwindcss";
import tailwindcssForms from "@tailwindcss/forms";
import { defineConfig } from "vite";

export default defineConfig(() => ({
  css: {
    postcss: {
      plugins: [
        tailwindcss({
          content: ["./index.html", "../../{apps,libs}/**/*.{ts,tsx}"],
          plugins: [tailwindcssForms],
          //plugins: [tailwindcssForms({strategy: 'class'})],
          theme: {},
        }),
        autoprefixer(),
      ],
    },
  },
}));

The types added include support for the strategy option as well.

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
tailwindcss-forms ✅ Ready (Inspect) Visit Preview May 4, 2022 at 8:55AM (UTC)
RobinMalfait commented 2 years ago

Hey! Thank you for your PR! Much appreciated! 🙏

I've made some changes and create a new PR (#118) based on your initial work. Made a few changes so that we don't rely on the @types/tailwindcss since we will be release our own types so within the repo.

Also updated export default plugin to export = plugin since it is a cjs file and not a esm file. Did some testing and the import plugin from '@tailwindcss/forms' should just work even with the export = plugin 👍

zanona commented 2 years ago

That's great. Thanks a lot for your help and taking the time to improve it, Robin. 😀