Skip to content

Commit 64497e3

Browse files
Template migrations: Migrate bg-gradient-* utilities to bg-linear-* (#14537)
In v4, we're making room for more gradient primitives with the addition of [gradient and conic gradient utilities](#14467). To make this clearer, we are renaming all v3 `bg-gradient-*` utilities to `bg-linear-*` to make it clear that these refer to linear gradients. This PR adds a migration that will automatically update the class names based on this migration.
1 parent d3440c1 commit 64497e3

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Add support for prefixes ([#14501](https://github.com/tailwindlabs/tailwindcss/pull/14501))
13+
- _Experimental_: Add template codemods for migrating `bg-gradient-*` utilities to `bg-linear-*` ([#14537](https://github.com/tailwindlabs/tailwindcss/pull/14537]))
1314

1415
### Fixed
1516

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { __unstable__loadDesignSystem } from '@tailwindcss/node'
2+
import { expect, test } from 'vitest'
3+
import { printCandidate } from '../candidates'
4+
import { bgGradient } from './bg-gradient'
5+
6+
test.each([
7+
['bg-gradient-to-t', 'bg-linear-to-t'],
8+
['bg-gradient-to-tr', 'bg-linear-to-tr'],
9+
['bg-gradient-to-r', 'bg-linear-to-r'],
10+
['bg-gradient-to-br', 'bg-linear-to-br'],
11+
['bg-gradient-to-b', 'bg-linear-to-b'],
12+
['bg-gradient-to-bl', 'bg-linear-to-bl'],
13+
['bg-gradient-to-l', 'bg-linear-to-l'],
14+
['bg-gradient-to-tl', 'bg-linear-to-tl'],
15+
16+
['max-lg:hover:bg-gradient-to-t', 'max-lg:hover:bg-linear-to-t'],
17+
])('%s => %s', async (candidate, result) => {
18+
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
19+
base: __dirname,
20+
})
21+
22+
let migrated = bgGradient(designSystem.parseCandidate(candidate)[0]!)
23+
expect(migrated ? printCandidate(migrated) : migrated).toEqual(result)
24+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Candidate } from '../../../../tailwindcss/src/candidate'
2+
3+
const DIRECTIONS = ['t', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl']
4+
5+
export function bgGradient(candidate: Candidate): Candidate | null {
6+
if (candidate.kind === 'static' && candidate.root.startsWith('bg-gradient-to-')) {
7+
let direction = candidate.root.slice(15)
8+
9+
if (!DIRECTIONS.includes(direction)) {
10+
return null
11+
}
12+
13+
candidate.root = `bg-linear-to-${direction}`
14+
return candidate
15+
}
16+
return null
17+
}

0 commit comments

Comments
 (0)