Need some first guidiance to upgrade from v3 to v4 when using plugins #18648
-
This is my /* eslint-disable import/no-extraneous-dependencies */
import defaultTheme from 'tailwindcss/defaultTheme';
import tailwindcssPlugin from 'tailwindcss/plugin';
import tailwindcssBaseFontSizePlugin from 'tailwindcss-base-font-size';
import tailwindcssAnimatePlugin from 'tailwindcss-animate';
import type { Config as tailwindConfig } from 'tailwindcss/types/config';
/* eslint-enable import/no-extraneous-dependencies */
const taperThemePlugin = tailwindcssPlugin(
({ addBase, addUtilities, matchUtilities, addVariant, theme }) => {
// imported CSS classes from original updated global.scss file by ShadcnUI
addBase({
body: {
// for debugging purpose add this style
// textTransform: 'uppercase'
},
':root': {
'--background': '0 0% 100%',
'--foreground': '222.2 84% 4.9%',
'--card': '0 0% 100%',
'--card-foreground': '222.2 84% 4.9%',
'--popover': '0 0% 100%',
'--popover-foreground': '222.2 84% 4.9%',
'--primary': '222.2 47.4% 11.2%',
'--primary-foreground': '189 60.7% 54.1%',
'--secondary': '210 40% 96.1%',
'--secondary-foreground': '222.2 47.4% 11.2%',
'--muted': '210 40% 96.1%',
'--muted-foreground': '215.4 16.3% 46.9%',
'--accent': '210 40% 96.1%',
'--accent-foreground': '222.2 47.4% 11.2%',
'--destructive': '0 84.2% 60.2%',
'--destructive-foreground': '210 40% 98%',
'--shadow': '214.3 31.8% 85.4%',
'--border': '214.3 31.8% 91.4%',
'--input': '214.3 31.8% 91.4%',
'--ring': '189 60.7% 54.1%',
'--radius': '0.5rem',
},
'.dark': {
'--background': '222.2 84% 4.9%',
'--foreground': '210 40% 98%',
'--card': '222.2 84% 4.9%',
'--card-foreground': '210 40% 98%',
'--popover': '222.2 84% 4.9%',
'--popover-foreground': '210 40% 98%',
'--primary': '210 40% 98%',
'--primary-foreground': '222.2 47.4% 11.2%',
'--secondary': '217.2 32.6% 17.5%',
'--secondary-foreground': '210 40% 98%',
'--muted': '217.2 32.6% 17.5%',
'--muted-foreground': '215 20.2% 65.1%',
'--accent': '217.2 32.6% 17.5%',
'--accent-foreground': '210 40% 98%',
'--destructive': '0 62.8% 30.6%',
'--destructive-foreground': '210 40% 98%',
'--shadow': '217 4% 38%',
'--border': '217.2 32.6% 17.5%',
'--input': '217.2 32.6% 17.5%',
'--ring': '212.7 26.8% 83.9%',
},
});
// imported CSS styles on components
addBase({
'*': {
'@apply border-border': {},
'--tw-shadow-color': 'hsl(var(--shadow))',
},
html: {
'scroll-behavior': 'smooth',
},
body: {
'@apply font-sans': {},
'@apply bg-background text-foreground': {},
},
});
addUtilities({
'.inherit-font-weight': {
fontWeight: 'inherit',
},
'.inherit-font-size': {
fontSize: 'inherit',
},
'.inherit-line-height': {
lineHeight: 'inherit',
},
});
// config additional plugin function
matchUtilities(
{
'text-shadow': (value) => ({
textShadow: value,
}),
},
{
values: theme('textShadow'),
}
);
// append @media selectors
// using screens is deprecated
addVariant('ws', '@media (min-aspect-ratio: 3/2) and (max-height: 399px)');
},
// extend the theme configuration
{
// per default we set the light / dark theme by activating
// className="dark" on <html> main
darkMode: 'class',
// config the theme and align to css styles from base
theme: {
container: {
center: true,
padding: '2rem',
},
screens: {
// it is important to override the screens config
// otherwise the css is not sorted correctly and
// then some of the new states will overrule the
// more fitting rules while later in source.
xs: '360px',
...defaultTheme.screens,
},
extend: {
fontFamily: {
sans: ['var(--font-sans-app)', 'Verdana', 'Helvetica', 'sans-serif'],
mono: ['var(--font-mono-app)', 'Courier', 'Courier New', 'Andale Mono', 'mono'],
serif: ['var(--font-serif-app)', 'Times', 'Times New Roman', 'Georgia', 'serif'],
highlight: ['Comic Sans MS', 'Helvetica', 'sans', 'sans-serif'],
},
backgroundImage: {
// hero-background is loaded from global scss while tailwind does not support image-set
'hero-background': '', // 'url("/assets/hero-background.webp")',
},
colors: {
// custom colors
'nd-blue': '#00adbc',
'nd-blue-200': '#00bedd',
'nd-blue-ui': '#009fad',
'nd-blue-text': '#00838f',
'nd-red': '#cf2463',
'nd-red-200': '#de266a',
'tonies-red': '#d3000f',
'tonies-lblue': '#94cedc',
// overwrite styles
border: 'hsl(var(--border))',
input: 'hsl(var(--input))',
ring: 'hsl(var(--ring))',
background: 'hsl(var(--background))',
foreground: 'hsl(var(--foreground))',
primary: {
DEFAULT: 'hsl(var(--primary))',
foreground: 'hsl(var(--primary-foreground))',
},
secondary: {
DEFAULT: 'hsl(var(--secondary))',
foreground: 'hsl(var(--secondary-foreground))',
},
destructive: {
DEFAULT: 'hsl(var(--destructive))',
foreground: 'hsl(var(--destructive-foreground))',
},
muted: {
DEFAULT: 'hsl(var(--muted))',
foreground: 'hsl(var(--muted-foreground))',
},
accent: {
DEFAULT: 'hsl(var(--accent))',
foreground: 'hsl(var(--accent-foreground))',
},
popover: {
DEFAULT: 'hsl(var(--popover))',
foreground: 'hsl(var(--popover-foreground))',
},
card: {
DEFAULT: 'hsl(var(--card))',
foreground: 'hsl(var(--card-foreground))',
},
},
borderRadius: {
lg: 'var(--radius)',
md: 'calc(var(--radius) - 2px)',
sm: 'calc(var(--radius) - 4px)',
},
textShadow: {
sm: '1px 1px 2px var(--tw-shadow-color)',
DEFAULT: '2px 2px 4px var(--tw-shadow-color)',
lg: '4px 4px 8px var(--tw-shadow-color)',
xl: '8px 8px 16px var(--tw-shadow-color)',
},
keyframes: {
'accordion-down': {
from: { height: '0' },
to: { height: 'var(--radix-accordion-content-height)' },
},
'accordion-up': {
from: { height: 'var(--radix-accordion-content-height)' },
to: { height: '0' },
},
'slow-in': {
from: { opacity: '0' },
to: { opacity: '1' },
},
'scale-in': {
from: { opacity: '0', transform: 'scale(1.3)' },
to: { opacity: '1', transform: 'scale(1)' },
},
},
animation: {
'accordion-down': 'accordion-down 0.2s ease-out',
'accordion-up': 'accordion-up 0.2s ease-out',
'slow-in': 'slow-in 0.5s cubic-bezier(0.1, 0, 0.3, 1)',
'scale-in': 'scale-in 0.3s cubic-bezier(0.2, 0, 0.7, 1)',
},
},
},
}
);
// apply some theming necessaries
const taperThemePluginAddons = [
tailwindcssBaseFontSizePlugin({
baseFontSize: 18,
}),
tailwindcssAnimatePlugin,
];
const withTaperThemePlugin = (config: Partial<tailwindConfig>) => {
// the order will define latest setting wins
return [taperThemePluginAddons, taperThemePlugin, config];
};
export { withTaperThemePlugin }; I tried to understand the migration to v4 but I struggle on:
I really would be happy if some could guide me with some links or patterns. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
1.
|
Beta Was this translation helpful? Give feedback.
1.
import defaultTheme from 'tailwindcss/defaultTheme';
There is no real equivalent. I can see you're only using it here:
But this hasn't been neccessary since perhaps v3.3 or v3.4 - breakpoints are sorted for you most of the time. You can do: