Skip to content
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

Add radius-* utilities and deprecate rounded-* utilities #14912

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support derived spacing scales based on a single `--spacing` theme value ([#14857](https://github.com/tailwindlabs/tailwindcss/pull/14857))
- Add `svh`, `dvh`, `svw`, `dvw`, and `auto` values to all width/height/size utilities ([#14857](https://github.com/tailwindlabs/tailwindcss/pull/14857))
- Add new `**` variant ([#14903](https://github.com/tailwindlabs/tailwindcss/pull/14903))
- Add new `radius-*` utilities that use the `--spacing` scale by default ([#14912](https://github.com/tailwindlabs/tailwindcss/pull/14912))
- Process `<style>` blocks inside Svelte files when using the Vite extension ([#14151](https://github.com/tailwindlabs/tailwindcss/pull/14151))
- Normalize date/time input styles in Preflight ([#14931](https://github.com/tailwindlabs/tailwindcss/pull/14931))
- _Upgrade (experimental)_: Migrate `grid-cols-[subgrid]` and `grid-rows-[subgrid]` to `grid-cols-subgrid` and `grid-rows-subgrid` ([#14840](https://github.com/tailwindlabs/tailwindcss/pull/14840))
Expand Down Expand Up @@ -50,7 +51,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rename `shadow` to `shadow-sm`, `shadow-sm` to `shadow-xs`, and `shadow-xs` to `shadow-2xs` ([#14849](https://github.com/tailwindlabs/tailwindcss/pull/14849))
- Rename `inset-shadow` to `inset-shadow-sm`, `inset-shadow-sm` to `inset-shadow-xs`, and `inset-shadow-xs` to `inset-shadow-2xs` ([#14849](https://github.com/tailwindlabs/tailwindcss/pull/14849))
- Rename `drop-shadow` to `drop-shadow-sm` and `drop-shadow-sm` to `drop-shadow-xs` ([#14849](https://github.com/tailwindlabs/tailwindcss/pull/14849))
- Rename `rounded` to `rounded-sm` and `rounded-sm` to `rounded-xs` ([#14849](https://github.com/tailwindlabs/tailwindcss/pull/14849))
Copy link
Member

Choose a reason for hiding this comment

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

With the change of moving the old scale to be deprecated as it was, I think we can revert this one, right?

Copy link
Member

Choose a reason for hiding this comment

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

This mostly affects the codemod stuff, I think instead of mapping rounded to rounded-sm etc. we should map it to the new radius-* utilities but leave the values as-is 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Ah wait this is more complicated, we can only migrate to radius-* when we the value is defined in the JS config, the compat layer only works rounded-* utilities

Copy link
Member

Choose a reason for hiding this comment

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

I guess also only if the theme is overwritten. 🤔

Consider this configuration:

{
  extend: {
    borderRadius: {
      '4xl': '2rem',
    },
  }
}

I expect this to create a --radius-4xl: 2rem variable (which it does currently) however, the other breakpoints will now be in the --rounded namespace, causing an inconsistency now because radius-4xl exists but radius-3xl doesn't.

Copy link
Member

@philipp-spiess philipp-spiess Nov 11, 2024

Choose a reason for hiding this comment

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

I think the v4 equivalent is actually

rounded => radius-1
rounded-sm => radius-0.5
rounded-md => radius-1.5
rounded-custom => radius-custom
etc.

if custom happens to be 4xl: not much we do here I think, although it would be cool if we can convert it to radius-8 but there might be an inherent meaning to the name so that's probably hard to do.

- Rename `blur` to `blur-sm` and `blur-sm` to `blur-xs` ([#14849](https://github.com/tailwindlabs/tailwindcss/pull/14849))
- Remove fixed line-height theme values and derive `leading-*` utilites from `--spacing-*` scale ([#14857](https://github.com/tailwindlabs/tailwindcss/pull/14857))
- Remove `--transition-timing-function-linear` from the default theme in favor of a static `ease-linear` utility ([#14880](https://github.com/tailwindlabs/tailwindcss/pull/14880))
Expand All @@ -66,6 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Replace `outline-none` with `outline-hidden`, add new simplified `outline-none` utility ([#14926](https://github.com/tailwindlabs/tailwindcss/pull/14926))
- Revert adding borders by default to form inputs ([#14929](https://github.com/tailwindlabs/tailwindcss/pull/14929))
- Deprecate `shadow-inner` utility ([#14933](https://github.com/tailwindlabs/tailwindcss/pull/14933))
- Deprecate `rounded-*` utilities ([#14912](https://github.com/tailwindlabs/tailwindcss/pull/14912))
- Remove `--leading-none` from the default theme in favor of a static `leading-none` utility ([#14934](https://github.com/tailwindlabs/tailwindcss/pull/14934))

## [4.0.0-alpha.31] - 2024-10-29
Expand Down
14 changes: 10 additions & 4 deletions integrations/upgrade/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@
class="!flex sm:!block bg-gradient-to-t bg-[--my-red] max-w-screen-md ml-[theme(screens.md)]"
></div>
<!-- Migrate to sm -->
<div class="blur shadow rounded inset-shadow drop-shadow"></div>
<div class="blur shadow inset-shadow drop-shadow"></div>

<!-- Migrate to xs -->
<div class="blur-sm shadow-sm rounded-sm inset-shadow-sm drop-shadow-sm"></div>
<div class="blur-sm shadow-sm inset-shadow-sm drop-shadow-sm"></div>

<!-- Migrate to 2xs -->
<div class="shadow-xs inset-shadow-xs"></div>

<!-- Migrate to \`radius-*\` -->
<div class="rounded rounded-sm rounded-xl"></div>
`,
'src/input.css': css`
@tailwind base;
Expand All @@ -104,14 +107,17 @@
class="flex! sm:block! bg-linear-to-t bg-[var(--my-red)] max-w-[var(--breakpoint-md)] ml-[var(--breakpoint-md)]"
></div>
<!-- Migrate to sm -->
<div class="blur-sm shadow-sm rounded-sm inset-shadow-sm drop-shadow-sm"></div>
<div class="blur-sm shadow-sm inset-shadow-sm drop-shadow-sm"></div>

<!-- Migrate to xs -->
<div class="blur-xs shadow-xs rounded-xs inset-shadow-xs drop-shadow-xs"></div>
<div class="blur-xs shadow-xs inset-shadow-xs drop-shadow-xs"></div>

<!-- Migrate to 2xs -->
<div class="shadow-2xs inset-shadow-2xs"></div>

<!-- Migrate to \`radius-*\` -->
<div class="radius radius-sm radius-xl"></div>

--- ./src/input.css ---
@import 'tailwindcss';

Expand Down Expand Up @@ -196,7 +202,7 @@
async ({ exec, fs }) => {
await exec('npx @tailwindcss/upgrade')

expect(await fs.dumpFiles('./src/**/*.{css,html}')).toMatchInlineSnapshot(`

Check failure on line 205 in integrations/upgrade/index.test.ts

View workflow job for this annotation

GitHub Actions / tests (20, namespace-profile-default, false)

upgrade/index.test.ts > upgrades a v3 project with prefixes to v4

Error: Snapshot `upgrades a v3 project with prefixes to v4 1` mismatched - Expected + Received @@ -24,8 +24,8 @@ border-color: var(--color-gray-200, currentColor); } } .btn { - @apply tw:rounded-md! tw:px-2 tw:py-1 tw:bg-blue-500 tw:text-white; + @apply tw:radius-md! tw:px-2 tw:py-1 tw:bg-blue-500 tw:text-white; } " ❯ upgrade/index.test.ts:205:57 ❯ utils.ts:424:14

Check failure on line 205 in integrations/upgrade/index.test.ts

View workflow job for this annotation

GitHub Actions / tests (20, namespace-profile-default, false)

upgrade/index.test.ts > upgrades a v3 project with prefixes to v4

Error: Snapshot `upgrades a v3 project with prefixes to v4 2` mismatched - Expected + Received @@ -24,8 +24,8 @@ border-color: var(--color-gray-200, currentColor); } } .btn { - @apply tw:rounded-md! tw:px-2 tw:py-1 tw:bg-blue-500 tw:text-white; + @apply tw:radius-md! tw:px-2 tw:py-1 tw:bg-blue-500 tw:text-white; } " ❯ upgrade/index.test.ts:205:57 ❯ utils.ts:424:14

Check failure on line 205 in integrations/upgrade/index.test.ts

View workflow job for this annotation

GitHub Actions / tests (20, namespace-profile-default, false)

upgrade/index.test.ts > upgrades a v3 project with prefixes to v4

Error: Snapshot `upgrades a v3 project with prefixes to v4 3` mismatched - Expected + Received @@ -24,8 +24,8 @@ border-color: var(--color-gray-200, currentColor); } } .btn { - @apply tw:rounded-md! tw:px-2 tw:py-1 tw:bg-blue-500 tw:text-white; + @apply tw:radius-md! tw:px-2 tw:py-1 tw:bg-blue-500 tw:text-white; } " ❯ upgrade/index.test.ts:205:57 ❯ utils.ts:424:14
"
--- ./src/index.html ---
<div
Expand Down Expand Up @@ -414,7 +420,7 @@
async ({ fs, exec }) => {
await exec('npx @tailwindcss/upgrade')

expect(await fs.dumpFiles('./src/**/*.css')).toMatchInlineSnapshot(`

Check failure on line 423 in integrations/upgrade/index.test.ts

View workflow job for this annotation

GitHub Actions / tests (20, namespace-profile-default, false)

upgrade/index.test.ts > migrate `@layer utilities` and `@layer components`

Error: Snapshot `migrate `@layer utilities` and `@layer components` 1` mismatched - Expected + Received @@ -19,11 +19,11 @@ border-color: var(--color-gray-200, currentColor); } } @Utility btn { - @apply rounded-md px-2 py-1 bg-blue-500 text-white; + @apply radius-md px-2 py-1 bg-blue-500 text-white; } @Utility no-scrollbar { &::-webkit-scrollbar { display: none; ❯ upgrade/index.test.ts:423:50 ❯ utils.ts:424:14

Check failure on line 423 in integrations/upgrade/index.test.ts

View workflow job for this annotation

GitHub Actions / tests (20, namespace-profile-default, false)

upgrade/index.test.ts > migrate `@layer utilities` and `@layer components`

Error: Snapshot `migrate `@layer utilities` and `@layer components` 2` mismatched - Expected + Received @@ -19,11 +19,11 @@ border-color: var(--color-gray-200, currentColor); } } @Utility btn { - @apply rounded-md px-2 py-1 bg-blue-500 text-white; + @apply radius-md px-2 py-1 bg-blue-500 text-white; } @Utility no-scrollbar { &::-webkit-scrollbar { display: none; ❯ upgrade/index.test.ts:423:50 ❯ utils.ts:424:14

Check failure on line 423 in integrations/upgrade/index.test.ts

View workflow job for this annotation

GitHub Actions / tests (20, namespace-profile-default, false)

upgrade/index.test.ts > migrate `@layer utilities` and `@layer components`

Error: Snapshot `migrate `@layer utilities` and `@layer components` 3` mismatched - Expected + Received @@ -19,11 +19,11 @@ border-color: var(--color-gray-200, currentColor); } } @Utility btn { - @apply rounded-md px-2 py-1 bg-blue-500 text-white; + @apply radius-md px-2 py-1 bg-blue-500 text-white; } @Utility no-scrollbar { &::-webkit-scrollbar { display: none; ❯ upgrade/index.test.ts:423:50 ❯ utils.ts:424:14
"
--- ./src/index.css ---
@import 'tailwindcss';
Expand Down Expand Up @@ -1496,7 +1502,7 @@
async ({ fs, exec }) => {
await exec('npx @tailwindcss/upgrade --force')

expect(await fs.dumpFiles('./src/**/*.css')).toMatchInlineSnapshot(`

Check failure on line 1505 in integrations/upgrade/index.test.ts

View workflow job for this annotation

GitHub Actions / tests (20, namespace-profile-default, false)

upgrade/index.test.ts > relative imports without a relative path prefix are migrated to include a relative path prefix

Error: Snapshot `relative imports without a relative path prefix are migrated to include a relative path prefix 1` mismatched - Expected + Received @@ -21,8 +21,8 @@ } } --- ./src/styles/components.css --- .btn { - @apply bg-black px-4 py-2 rounded-md text-white font-medium hover:bg-zinc-800; + @apply bg-black px-4 py-2 radius-md text-white font-medium hover:bg-zinc-800; } " ❯ upgrade/index.test.ts:1505:50 ❯ utils.ts:424:14

Check failure on line 1505 in integrations/upgrade/index.test.ts

View workflow job for this annotation

GitHub Actions / tests (20, namespace-profile-default, false)

upgrade/index.test.ts > relative imports without a relative path prefix are migrated to include a relative path prefix

Error: Snapshot `relative imports without a relative path prefix are migrated to include a relative path prefix 2` mismatched - Expected + Received @@ -21,8 +21,8 @@ } } --- ./src/styles/components.css --- .btn { - @apply bg-black px-4 py-2 rounded-md text-white font-medium hover:bg-zinc-800; + @apply bg-black px-4 py-2 radius-md text-white font-medium hover:bg-zinc-800; } " ❯ upgrade/index.test.ts:1505:50 ❯ utils.ts:424:14

Check failure on line 1505 in integrations/upgrade/index.test.ts

View workflow job for this annotation

GitHub Actions / tests (20, namespace-profile-default, false)

upgrade/index.test.ts > relative imports without a relative path prefix are migrated to include a relative path prefix

Error: Snapshot `relative imports without a relative path prefix are migrated to include a relative path prefix 3` mismatched - Expected + Received @@ -21,8 +21,8 @@ } } --- ./src/styles/components.css --- .btn { - @apply bg-black px-4 py-2 rounded-md text-white font-medium hover:bg-zinc-800; + @apply bg-black px-4 py-2 radius-md text-white font-medium hover:bg-zinc-800; } " ❯ upgrade/index.test.ts:1505:50 ❯ utils.ts:424:14
"
--- ./src/index.css ---
@import 'tailwindcss';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,6 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
--blur-xl: 24px;
--blur-2xl: 40px;
--blur-3xl: 64px;
--radius-xs: .125rem;
--radius-sm: .25rem;
--radius-md: .375rem;
--radius-lg: .5rem;
--radius-xl: .75rem;
--radius-2xl: 1rem;
--radius-3xl: 1.5rem;
--radius-4xl: 2rem;
--shadow-2xs: 0 1px #0000000d;
--shadow-xs: 0 1px 2px 0 #0000000d;
--shadow-sm: 0 1px 3px 0 #0000001a, 0 1px 2px -1px #0000001a;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { __unstable__loadDesignSystem } from '@tailwindcss/node'
import { expect, test } from 'vitest'
import { radius } from './radius'

test.each([
['hover:rounded', 'hover:radius'],
['hover:rounded-sm', 'hover:radius-sm'],
['hover:rounded-md', 'hover:radius-md'],
['hover:rounded-lg', 'hover:radius-lg'],
['hover:rounded-xl', 'hover:radius-xl'],
['hover:rounded-2xl', 'hover:radius-2xl'],
['hover:rounded-3xl', 'hover:radius-3xl'],
['hover:rounded-4xl', 'hover:radius-4xl'],
])('%s => %s', async (candidate, result) => {
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
base: __dirname,
})

expect(radius(designSystem, {}, candidate)).toEqual(result)
})
19 changes: 19 additions & 0 deletions packages/@tailwindcss-upgrade/src/template/codemods/radius.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Config } from 'tailwindcss'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import { printCandidate } from '../candidates'

export function radius(
designSystem: DesignSystem,
_userConfig: Config,
rawCandidate: string,
): string {
for (let candidate of designSystem.parseCandidate(rawCandidate)) {
if (candidate.kind === 'functional' && candidate.root === 'rounded') {
return printCandidate(designSystem, {
...candidate,
root: 'radius',
})
}
}
return rawCandidate
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ test.each([
['drop-shadow', 'drop-shadow-sm'],
['drop-shadow-sm', 'drop-shadow-xs'],

['rounded', 'rounded-sm'],
['rounded-sm', 'rounded-xs'],

['blur', 'blur-sm'],
['blur-sm', 'blur-xs'],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ const LEGACY_CLASS_MAP = {
'drop-shadow': 'drop-shadow-sm',
'drop-shadow-sm': 'drop-shadow-xs',

rounded: 'rounded-sm',
'rounded-sm': 'rounded-xs',

blur: 'blur-sm',
'blur-sm': 'blur-xs',

Expand Down
2 changes: 2 additions & 0 deletions packages/@tailwindcss-upgrade/src/template/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { important } from './codemods/important'
import { maxWidthScreen } from './codemods/max-width-screen'
import { modernizeArbitraryValues } from './codemods/modernize-arbitrary-values'
import { prefix } from './codemods/prefix'
import { radius } from './codemods/radius'
import { simpleLegacyClasses } from './codemods/simple-legacy-classes'
import { themeToVar } from './codemods/theme-to-var'
import { variantOrder } from './codemods/variant-order'
Expand All @@ -31,6 +32,7 @@ export const DEFAULT_MIGRATIONS: Migration[] = [
important,
bgGradient,
simpleLegacyClasses,
radius,
maxWidthScreen,
themeToVar,
variantOrder, // Has to happen before migrations that modify variants
Expand Down
8 changes: 0 additions & 8 deletions packages/tailwindcss/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,6 @@ exports[`compiling CSS > \`@tailwind utilities\` is replaced by utilities using
--blur-xl: 24px;
--blur-2xl: 40px;
--blur-3xl: 64px;
--radius-xs: .125rem;
--radius-sm: .25rem;
--radius-md: .375rem;
--radius-lg: .5rem;
--radius-xl: .75rem;
--radius-2xl: 1rem;
--radius-3xl: 1.5rem;
--radius-4xl: 2rem;
--shadow-2xs: 0 1px #0000000d;
--shadow-xs: 0 1px 2px 0 #0000000d;
--shadow-sm: 0 1px 3px 0 #0000001a, 0 1px 2px -1px #0000001a;
Expand Down
Loading
Loading