Skip to content

Commit c53a525

Browse files
committed
Upgrade: Migrate ring to ring-3 (#15063)
This PR adds a codemod for migrating `ring` to `ring-3` if it is safe to do so. # Test plan Added a `ring` to the Catalyst project and then migrated it: <img width="864" alt="image" src="https://github.com/user-attachments/assets/163d9faa-c712-494e-b9d7-106508157915">
1 parent 3cf5c2d commit c53a525

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add consistent base styles for buttons and form controls ([#15036](https://github.com/tailwindlabs/tailwindcss/pull/15036))
1313
- _Upgrade (experimental)_: Convert `group-[]:flex` to `in-[.group]:flex` ([#15054](https://github.com/tailwindlabs/tailwindcss/pull/15054))
1414
- _Upgrade (experimental)_: Add form reset styles to CSS files for compatibility with v3 ([#15036](https://github.com/tailwindlabs/tailwindcss/pull/15036))
15+
- _Upgrade (experimental)_: Migrate `ring` to `ring-3` ([#15063](https://github.com/tailwindlabs/tailwindcss/pull/15063))
1516

1617
### Fixed
1718

integrations/upgrade/index.test.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ test(
7878
7979
<!-- Migrate to 2xs -->
8080
<div class="shadow-xs inset-shadow-xs"></div>
81+
82+
<!-- Migrate to -3 -->
83+
<div class="ring"></div>
8184
`,
8285
'src/input.css': css`
8386
@tailwind base;
@@ -111,6 +114,9 @@ test(
111114
<!-- Migrate to 2xs -->
112115
<div class="shadow-2xs inset-shadow-2xs"></div>
113116
117+
<!-- Migrate to -3 -->
118+
<div class="ring-3"></div>
119+
114120
--- ./src/input.css ---
115121
@import 'tailwindcss';
116122
@@ -2512,6 +2518,10 @@ test(
25122518
DEFAULT: '0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)',
25132519
},
25142520
2521+
ringWidth: {
2522+
DEFAULT: '4px',
2523+
},
2524+
25152525
extend: {
25162526
// Changes the "before" class definition. 'blur' -> 'blur-sm' is
25172527
// not safe because 'blur' has a custom value.
@@ -2541,6 +2551,7 @@ test(
25412551
<div class="shadow shadow-sm shadow-xs"></div>
25422552
<div class="blur blur-sm"></div>
25432553
<div class="rounded rounded-sm"></div>
2554+
<div class="ring"></div>
25442555
</div>
25452556
`,
25462557
},
@@ -2558,6 +2569,9 @@ test(
25582569
--shadow-*: initial;
25592570
--shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
25602571
2572+
--ring-width-*: initial;
2573+
--ring-width: 4px;
2574+
25612575
--blur: var(--custom-default-blur);
25622576
25632577
--radius-sm: var(--custom-rounded-sm);
@@ -2601,14 +2615,15 @@ test(
26012615
<div class="shadow shadow-sm shadow-xs"></div>
26022616
<div class="blur blur-xs"></div>
26032617
<div class="rounded rounded-sm"></div>
2618+
<div class="ring"></div>
26042619
</div>
26052620
"
26062621
`)
26072622
},
26082623
)
26092624
26102625
test(
2611-
'make suffix-less migrations safe (e.g.: `blur`, `rounded`, `shadow`)',
2626+
'make suffix-less migrations safe (e.g.: `blur`, `rounded`, `shadow`, `ring`)',
26122627
{
26132628
fs: {
26142629
'package.json': json`
@@ -2633,7 +2648,7 @@ test(
26332648
@tailwind utilities;
26342649
`,
26352650
'index.html': html`
2636-
<div class="rounded blur shadow"></div>
2651+
<div class="rounded blur shadow ring"></div>
26372652
`,
26382653
'example-component.tsx': ts`
26392654
type Star = [
@@ -2643,10 +2658,11 @@ test(
26432658
blur?: boolean,
26442659
rounded?: boolean,
26452660
shadow?: boolean,
2661+
ring?: boolean,
26462662
]
26472663
2648-
function Star({ point: [cx, cy, dim, blur, rounded, shadow] }: { point: Star }) {
2649-
return <svg class="rounded shadow blur" filter={blur ? 'url(…)' : undefined} />
2664+
function Star({ point: [cx, cy, dim, blur, rounded, shadow, ring] }: { point: Star }) {
2665+
return <svg class="rounded shadow blur ring" filter={blur ? 'url(…)' : undefined} />
26502666
}
26512667
`,
26522668
},
@@ -2694,7 +2710,7 @@ test(
26942710
}
26952711
26962712
--- index.html ---
2697-
<div class="rounded-sm blur-sm shadow-sm"></div>
2713+
<div class="rounded-sm blur-sm shadow-sm ring-3"></div>
26982714
26992715
--- example-component.tsx ---
27002716
type Star = [
@@ -2704,10 +2720,11 @@ test(
27042720
blur?: boolean,
27052721
rounded?: boolean,
27062722
shadow?: boolean,
2723+
ring?: boolean,
27072724
]
27082725
2709-
function Star({ point: [cx, cy, dim, blur, rounded, shadow] }: { point: Star }) {
2710-
return <svg class="rounded-sm shadow-sm blur-sm" filter={blur ? 'url(…)' : undefined} />
2726+
function Star({ point: [cx, cy, dim, blur, rounded, shadow, ring] }: { point: Star }) {
2727+
return <svg class="rounded-sm shadow-sm blur-sm ring-3" filter={blur ? 'url(…)' : undefined} />
27112728
}
27122729
"
27132730
`)

packages/@tailwindcss-upgrade/src/template/codemods/legacy-classes.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ test.each([
2020
['blur', 'blur-sm'],
2121
['blur-sm', 'blur-xs'],
2222

23+
['ring', 'ring-3'],
24+
2325
['blur!', 'blur-sm!'],
2426
['hover:blur', 'hover:blur-sm'],
2527
['hover:blur!', 'hover:blur-sm!'],
2628

2729
['hover:blur-sm', 'hover:blur-xs'],
2830
['blur-sm!', 'blur-xs!'],
2931
['hover:blur-sm!', 'hover:blur-xs!'],
30-
])('%s => %s', async (candidate, result) => {
32+
])('%s => %s (%#)', async (candidate, result) => {
3133
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
3234
base: __dirname,
3335
})

packages/@tailwindcss-upgrade/src/template/codemods/legacy-classes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const LEGACY_CLASS_MAP = new Map([
2828

2929
['blur', 'blur-sm'],
3030
['blur-sm', 'blur-xs'],
31+
32+
['ring', 'ring-3'],
3133
])
3234

3335
const THEME_KEYS = new Map([
@@ -47,6 +49,9 @@ const THEME_KEYS = new Map([
4749
['blur', '--blur'],
4850
['blur-sm', '--blur-sm'],
4951
['blur-xs', '--blur-xs'],
52+
53+
['ring', '--ring-width'],
54+
['ring-3', '--ring-width-3'],
5055
])
5156

5257
const DESIGN_SYSTEMS = new DefaultMap((base) => {
@@ -134,7 +139,7 @@ export async function legacyClasses(
134139

135140
// The new theme value is not defined, which means we can't safely
136141
// migrate the utility.
137-
if (customTo === undefined) {
142+
if (customTo === undefined && defaultTo !== undefined) {
138143
continue
139144
}
140145

0 commit comments

Comments
 (0)