tailwindcss/packages
Jordan Pittman b1e22e121e
Allow configs to override default CSS theme values in theme() function provided to plugins and configs (#14359)
Previously, given the following CSS and configuration:

```css
/* app.css */

@theme default {
  --font-size-base: 1.25rem;
  --font-size-base--line-height: 1.5rem;
}
@tailwind utilities;
@config "./config.js";
```

```js
// config.js

export default {
  theme: {
    fontSize: {
      // …
      base: ['1rem', { lineHeight: '1.75rem' }],
    },

    // …
  },
};
```

When a config or a plugin asked for the value of `theme(fontSize.base)`
like so:

```js
// config.js
export default {
  theme: {
    // …

    typography: ({ theme }) => ({
      css: {
        '[class~="lead"]': {
          fontSize: theme('fontSize.base')[0],
          ...theme('fontSize.base')[1],
        },
      }
    }),
  },
};
```

We would instead pull the values from the CSS theme even through they're
marked with `@theme default`. This would cause the incorrect font size
and line height to be used resulting in something like this (in the case
of the typography plugin with custom styles):

  ```css
  .prose [class~="lead"] {
    font-size: 1.25rem;
    line-height: 1.5rem;
  }
  ```

After this change we'll now pull the values from the appropriate place
(the config in this case) and the correct font size and line height will
be used:

  ```css
  .prose [class~="lead"] {
    font-size: 1rem;
    line-height: 1.75rem;
  }
  ```

This will work even when some values are overridden in the CSS theme:

  ```css
  /* app.css */
  @theme default {
    --font-size-base: 1.25rem;
    --font-size-base--line-height: 1.5rem;
  }
  @theme {
    --font-size-base: 2rem;
  }
  @tailwind utilities;
  @config "./config.js";
  ```

which would result in the following CSS:

  ```css
  .prose [class~="lead"] {
    font-size: 2rem;
    line-height: 1.75rem;
  }
  ```

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2024-09-06 16:05:26 -04:00
..
@tailwindcss-cli Improve the CLI output when nothing changed (#14351) 2024-09-05 17:00:57 -04:00
@tailwindcss-node v4.0.0-alpha.23 2024-09-05 10:43:07 -04:00
@tailwindcss-postcss v4.0.0-alpha.23 2024-09-05 10:43:07 -04:00
@tailwindcss-standalone v4.0.0-alpha.23 2024-09-05 10:43:07 -04:00
@tailwindcss-vite v4.0.0-alpha.23 2024-09-05 10:43:07 -04:00
internal-example-plugin Prefix internal modules with internal-* (#14074) 2024-07-29 10:58:07 -04:00
internal-postcss-fix-relative-paths Support loading config files via @config (#14239) 2024-09-02 18:03:16 +02:00
tailwindcss Allow configs to override default CSS theme values in theme() function provided to plugins and configs (#14359) 2024-09-06 16:05:26 -04:00
tsconfig.base.json introduce v4 codebase 2024-03-05 14:29:15 +01:00