Skip to content

Improve compatibility with @tailwindcss/typography and @tailwindcss/forms #14221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Aug 22, 2024

Conversation

thecrypticace
Copy link
Contributor

@thecrypticace thecrypticace commented Aug 19, 2024

This PR enables compatibility for the @tailwindcss/typography and @tailwindcss/forms plugins. This required the addition of new Plugin APIs and new package exports.

New Plugin APIs and compatibility improvements

We added support for addComponents, matchComponents, and prefix. The component APIs are an alias for the utilities APIs because the sorting in V4 is different and emitting components in a custom @layer is not necessary. Since prefix is not supported in V4, the prefix() API is currently an identity function.

 addComponents({
  '.btn': {
    padding: '.5rem 1rem',
    borderRadius: '.25rem',
    fontWeight: '600',
  },
  '.btn-blue': {
    backgroundColor: '#3490dc',
    color: '#fff',
    '&:hover': {
      backgroundColor: '#2779bd',
    },
  },
  '.btn-red': {
    backgroundColor: '#e3342f',
    color: '#fff',
    '&:hover': {
      backgroundColor: '#cc1f1a',
    },
  },
})

The behavioral changes effect the addUtilities and matchUtilities functions, we now:

  • Allow arrays of CSS property objects to be emitted:
    addUtilities({
      '.text-trim': [
        {'text-box-trim': 'both'},
        {'text-box-edge': 'cap alphabetic'},
      ],
    })
  • Allow arrays of utilities
    addUtilities([
      {
        '.text-trim':{
          'text-box-trim': 'both',
          'text-box-edge': 'cap alphabetic',
        },
      }
    ])
  • Allow more complicated selector names
    addUtilities({
      '.form-input, .form-select, .form-radio': {
        /* styles here */
      },
      '.form-input::placeholder': {
        /* styles here */
      },
      '.form-checkbox:indeterminate:checked': {
        /* styles here */
      }
    })

New tailwindcss/color and tailwindcss/defaultTheme export

To be compatible to v3, we're adding two new exports to the tailwindcss package. These match the default theme values as defined in v3:

import colors from 'tailwindcss/colors'

console.log(colors.red[600])
import theme from 'tailwindcss/defaultTheme'

console.log(theme.spacing[4])

Base automatically changed from feat/v4-plugin-theme-function to next August 20, 2024 15:05
@thecrypticace thecrypticace force-pushed the feat/v4-plugin-typography-compat branch from 7e00750 to 4834d48 Compare August 20, 2024 19:50
@thecrypticace thecrypticace force-pushed the feat/v4-plugin-typography-compat branch from 4834d48 to 6d5cbae Compare August 21, 2024 12:37
@philipp-spiess philipp-spiess force-pushed the feat/v4-plugin-typography-compat branch from 2abeb95 to c8126d6 Compare August 22, 2024 10:53
@philipp-spiess philipp-spiess force-pushed the feat/v4-plugin-typography-compat branch from 4fc9892 to 248851f Compare August 22, 2024 11:42
@philipp-spiess philipp-spiess changed the title Work on plugin compatibility Plugins: Improve compatibility with typography and forms Aug 22, 2024
@thecrypticace thecrypticace changed the title Plugins: Improve compatibility with typography and forms Improve compatibility with @tailwindcss/typography and @tailwindcss/forms Aug 22, 2024
@philipp-spiess philipp-spiess force-pushed the feat/v4-plugin-typography-compat branch from 4bc2f35 to 1c7e429 Compare August 22, 2024 11:47
@thecrypticace thecrypticace marked this pull request as ready for review August 22, 2024 11:52
Copy link
Member

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seal of approval

@thecrypticace thecrypticace merged commit 30bbe51 into next Aug 22, 2024
2 checks passed
@thecrypticace thecrypticace deleted the feat/v4-plugin-typography-compat branch August 22, 2024 12:06
philipp-spiess added a commit that referenced this pull request Aug 27, 2024
…s/forms` (#14221)

This PR enables compatibility for the `@tailwindcss/typography` and
`@tailwindcss/forms` plugins. This required the addition of new Plugin
APIs and new package exports.

## New Plugin APIs and compatibility improvements

We added support for `addComponents`, `matchComponents`, and `prefix`.
The component APIs are an alias for the utilities APIs because the
sorting in V4 is different and emitting components in a custom `@layer`
is not necessary. Since `prefix` is not supported in V4, the `prefix()`
API is currently an identity function.

```js
 addComponents({
  '.btn': {
    padding: '.5rem 1rem',
    borderRadius: '.25rem',
    fontWeight: '600',
  },
  '.btn-blue': {
    backgroundColor: '#3490dc',
    color: '#fff',
    '&:hover': {
      backgroundColor: '#2779bd',
    },
  },
  '.btn-red': {
    backgroundColor: '#e3342f',
    color: '#fff',
    '&:hover': {
      backgroundColor: '#cc1f1a',
    },
  },
})
```

The behavioral changes effect the `addUtilities` and `matchUtilities`
functions, we now:

- Allow arrays of CSS property objects to be emitted:
  ```js
  addUtilities({
    '.text-trim': [
      {'text-box-trim': 'both'},
      {'text-box-edge': 'cap alphabetic'},
    ],
  })
  ```
- Allow arrays of utilities
  ```js
  addUtilities([
    {
      '.text-trim':{
        'text-box-trim': 'both',
        'text-box-edge': 'cap alphabetic',
      },
    }
  ])
  ```
- Allow more complicated selector names
  ```js
  addUtilities({
    '.form-input, .form-select, .form-radio': {
      /* styles here */
    },
    '.form-input::placeholder': {
      /* styles here */
    },
    '.form-checkbox:indeterminate:checked': {
      /* styles here */
    }
  })
  ```

## New `tailwindcss/color` and `tailwindcss/defaultTheme` export

To be compatible to v3, we're adding two new exports to the tailwindcss
package. These match the default theme values as defined in v3:

```ts
import colors from 'tailwindcss/colors'

console.log(colors.red[600])
```

```ts
import theme from 'tailwindcss/defaultTheme'

console.log(theme.spacing[4])
```

---------

Co-authored-by: Philipp Spiess <hello@philippspiess.com>
philipp-spiess added a commit that referenced this pull request Aug 29, 2024
In #14221 we added a new export to the `tailwindcss` package:
`tailwindcss/defaultTheme`. This is build on top of the full config from
V3 and will allow plugins to keep being compatible.

However, spreading in from this package has overwritten the bare value
callback handler. This PR fixes it by sharing the bare value callbacks
with the compat config.
philipp-spiess added a commit that referenced this pull request Aug 29, 2024
In #14221 we added a new export to the `tailwindcss` package:
`tailwindcss/defaultTheme`. This is build on top of the full config from
V3 and will allow plugins to keep being compatible.

However, spreading in from this package has overwritten the bare value
callback handler. This PR fixes it by sharing the bare value callbacks
with the compat config.
philipp-spiess added a commit that referenced this pull request Aug 29, 2024
In #14221 we added a new export to the `tailwindcss` package:
`tailwindcss/defaultTheme`. This is build on top of the full config from
V3 and will allow plugins to keep being compatible.

However, spreading in from this package has overwritten the bare value
callback handler. This PR fixes it by sharing the bare value callbacks
with the compat config.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants