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

Rename --letter-spacing-* variables to --tracking-* #14921

Merged
merged 1 commit into from
Nov 8, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rename `--transition-timing-function-*` variables to `--ease-*` ([#14886](https://github.com/tailwindlabs/tailwindcss/pull/14886))
- Rename `--width-*` variables to `--container-*` ([#14898](https://github.com/tailwindlabs/tailwindcss/pull/14898))
- Rename `--font-size-*` variables to `--text-*` ([#14909](https://github.com/tailwindlabs/tailwindcss/pull/14909))
- Rename `--letter-spacing-*` variables to `--tracking-*` ([#14921](https://github.com/tailwindlabs/tailwindcss/pull/14921))
- Revert specificity of `*` variant to match v3 behavior ([#14920](https://github.com/tailwindlabs/tailwindcss/pull/14920))

## [4.0.0-alpha.31] - 2024-10-29
Expand Down
17 changes: 16 additions & 1 deletion integrations/upgrade/js-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ test(
'spin-clockwise': 'spin-clockwise 1s linear infinite',
'spin-counterclockwise': 'spin-counterclockwise 1s linear infinite',
},
letterSpacing: {
superWide: '0.25em',
},
},
},
plugins: [],
Expand All @@ -130,6 +133,11 @@ test(
'shouldNotMigrate': !border.test + '',
}
`,
'src/index.html': html`
<div
class="[letter-spacing:theme(letterSpacing.superWide)]"
></div>
`,
'node_modules/my-external-lib/src/template.html': html`
<div class="text-red-500">
Hello world!
Expand All @@ -140,8 +148,13 @@ test(
async ({ exec, fs }) => {
await exec('npx @tailwindcss/upgrade')

expect(await fs.dumpFiles('src/**/*.{css,js}')).toMatchInlineSnapshot(`
expect(await fs.dumpFiles('src/**/*.{css,js,html}')).toMatchInlineSnapshot(`
"
--- src/index.html ---
<div
class="[letter-spacing:var(--tracking-super-wide)]"
></div>

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

Expand Down Expand Up @@ -223,6 +236,8 @@ test(
--animate-spin-clockwise: spin-clockwise 1s linear infinite;
--animate-spin-counterclockwise: spin-counterclockwise 1s linear infinite;

--tracking-super-wide: 0.25em;

@keyframes spin-clockwise {
0% {
transform: rotate(0deg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
--font-weight-bold: 700;
--font-weight-extrabold: 800;
--font-weight-black: 900;
--letter-spacing-tighter: -.05em;
--letter-spacing-tight: -.025em;
--letter-spacing-normal: 0em;
--letter-spacing-wide: .025em;
--letter-spacing-wider: .05em;
--letter-spacing-widest: .1em;
--tracking-tighter: -.05em;
--tracking-tight: -.025em;
--tracking-normal: 0em;
--tracking-wide: .025em;
--tracking-wider: .05em;
--tracking-widest: .1em;
--line-height-none: 1;
--line-height-tight: 1.25;
--line-height-snug: 1.375;
Expand Down
12 changes: 6 additions & 6 deletions packages/tailwindcss/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ exports[`compiling CSS > \`@tailwind utilities\` is replaced by utilities using
--font-weight-bold: 700;
--font-weight-extrabold: 800;
--font-weight-black: 900;
--letter-spacing-tighter: -.05em;
--letter-spacing-tight: -.025em;
--letter-spacing-normal: 0em;
--letter-spacing-wide: .025em;
--letter-spacing-wider: .05em;
--letter-spacing-widest: .1em;
--tracking-tighter: -.05em;
--tracking-tight: -.025em;
--tracking-normal: 0em;
--tracking-wide: .025em;
--tracking-wider: .05em;
--tracking-widest: .1em;
--line-height-none: 1;
--line-height-tight: 1.25;
--line-height-snug: 1.375;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ test('config values can be merged into the theme', () => {
],
},

letterSpacing: {
superWide: '0.25em',
},

width: {
// Purposely setting to something different from the default
'1/2': '60%',
Expand Down Expand Up @@ -88,6 +92,7 @@ test('config values can be merged into the theme', () => {
'1rem',
{ '--line-height': '1.5' },
])
expect(theme.resolve('super-wide', ['--tracking'])).toEqual('0.25em')
expect(theme.resolve('1/2', ['--width'])).toEqual('60%')
expect(theme.resolve('0.5', ['--width'])).toEqual('60%')
expect(theme.resolve('100%', ['--width'])).toEqual('100%')
Expand Down
9 changes: 5 additions & 4 deletions packages/tailwindcss/src/compat/apply-config-to-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,16 @@ const IS_VALID_KEY = /^[a-zA-Z0-9-_%/\.]+$/
export function keyPathToCssProperty(path: string[]) {
path = structuredClone(path)

if (path[0] === 'colors') path[0] = 'color'
if (path[0] === 'screens') path[0] = 'breakpoint'
if (path[0] === 'animation') path[0] = 'animate'
if (path[0] === 'borderRadius') path[0] = 'radius'
if (path[0] === 'boxShadow') path[0] = 'shadow'
if (path[0] === 'animation') path[0] = 'animate'
if (path[0] === 'transitionTimingFunction') path[0] = 'ease'
if (path[0] === 'colors') path[0] = 'color'
if (path[0] === 'fontFamily') path[0] = 'font'
if (path[0] === 'fontSize') path[0] = 'text'
if (path[0] === 'letterSpacing') path[0] = 'tracking'
if (path[0] === 'maxWidth') path[0] = 'container'
if (path[0] === 'screens') path[0] = 'breakpoint'
if (path[0] === 'transitionTimingFunction') path[0] = 'ease'

for (let part of path) {
if (!IS_VALID_KEY.test(part)) return null
Expand Down
11 changes: 11 additions & 0 deletions packages/tailwindcss/src/compat/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,9 @@ test('old theme values are merged with their renamed counterparts in the CSS the

--container-a: 1;
--container-b: 2;

--tracking-a: 1;
--tracking-b: 2;
}

@plugin "./plugin.js";
Expand Down Expand Up @@ -1594,6 +1597,14 @@ test('old theme values are merged with their renamed counterparts in the CSS the

expect(theme('maxWidth.a')).toEqual('1')
expect(theme('maxWidth.b')).toEqual('2')

expect(theme('letterSpacing.a')).toEqual('1')
expect(theme('letterSpacing.b')).toEqual('2')

expect(theme('letterSpacing')).toMatchObject({
a: '1',
b: '2',
})
}),
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export function createCompatConfig(cssTheme: Theme): UserConfig {
...theme('breakpoint', {}),
}),

letterSpacing: ({ theme }) => ({
...theme('tracking', {}),
}),

transitionDuration: {
DEFAULT: cssTheme.get(['--default-transition-duration']) ?? null,
},
Expand Down
1 change: 1 addition & 0 deletions packages/tailwindcss/src/css-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ describe('theme function', () => {
],
['maxWidth.xs', '20rem'],
['transitionTimingFunction.in-out', 'cubic-bezier(.4, 0, .2, 1)'],
['letterSpacing.wide', '.025em'],
['backgroundColor.red.500', 'oklch(.637 .237 25.331)'],
])('theme(%s) → %s', async (value, result) => {
let defaultTheme = await fs.readFile(path.join(__dirname, '..', 'theme.css'), 'utf8')
Expand Down
16 changes: 8 additions & 8 deletions packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14095,17 +14095,17 @@ test('tracking', async () => {
await compileCss(
css`
@theme {
--letter-spacing-normal: 0em;
--letter-spacing-wide: 0.025em;
--tracking-normal: 0em;
--tracking-wide: 0.025em;
}
@tailwind utilities;
`,
['tracking-normal', 'tracking-wide', 'tracking-[var(--value)]', '-tracking-[var(--value)]'],
),
).toMatchInlineSnapshot(`
":root {
--letter-spacing-normal: 0em;
--letter-spacing-wide: .025em;
--tracking-normal: 0em;
--tracking-wide: .025em;
}

.-tracking-\\[var\\(--value\\)\\] {
Expand All @@ -14119,13 +14119,13 @@ test('tracking', async () => {
}

.tracking-normal {
--tw-tracking: var(--letter-spacing-normal);
letter-spacing: var(--letter-spacing-normal);
--tw-tracking: var(--tracking-normal);
letter-spacing: var(--tracking-normal);
}

.tracking-wide {
--tw-tracking: var(--letter-spacing-wide);
letter-spacing: var(--letter-spacing-wide);
--tw-tracking: var(--tracking-wide);
letter-spacing: var(--tracking-wide);
}

@supports (-moz-orient: inline) {
Expand Down
8 changes: 4 additions & 4 deletions packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3617,7 +3617,7 @@ export function createUtilities(theme: Theme) {

functionalUtility('tracking', {
supportsNegative: true,
themeKeys: ['--letter-spacing'],
themeKeys: ['--tracking'],
handle: (value) => [
atRoot([property('--tw-tracking')]),
decl('--tw-tracking', value),
Expand Down Expand Up @@ -3911,7 +3911,7 @@ export function createUtilities(theme: Theme) {
let value = theme.resolveWith(
candidate.value.value,
['--text'],
['--line-height', '--letter-spacing', '--font-weight'],
['--line-height', '--tracking', '--font-weight'],
)
if (value) {
let [fontSize, options = {}] = Array.isArray(value) ? value : [value]
Expand Down Expand Up @@ -3939,8 +3939,8 @@ export function createUtilities(theme: Theme) {
),
decl(
'letter-spacing',
options['--letter-spacing']
? `var(--tw-tracking, ${options['--letter-spacing']})`
options['--tracking']
? `var(--tw-tracking, ${options['--tracking']})`
: undefined,
),
decl(
Expand Down
6 changes: 3 additions & 3 deletions packages/tailwindcss/tests/ui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,9 @@ test('explicit tracking utilities are respected when overriding font-size', asyn
`,
css`
@theme {
--text-sm--letter-spacing: 5px;
--text-xl--letter-spacing: 10px;
--letter-spacing-tight: 1px;
--text-sm--tracking: 5px;
--text-xl--tracking: 10px;
--tracking-tight: 1px;
}
`,
)
Expand Down
14 changes: 7 additions & 7 deletions packages/tailwindcss/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@
--font-weight-extrabold: 800;
--font-weight-black: 900;

/* Letter spacing */
--letter-spacing-tighter: -0.05em;
--letter-spacing-tight: -0.025em;
--letter-spacing-normal: 0em;
--letter-spacing-wide: 0.025em;
--letter-spacing-wider: 0.05em;
--letter-spacing-widest: 0.1em;
/* Tracking */
--tracking-tighter: -0.05em;
--tracking-tight: -0.025em;
--tracking-normal: 0em;
--tracking-wide: 0.025em;
--tracking-wider: 0.05em;
--tracking-widest: 0.1em;

/* Line-height */
--line-height-none: 1;
Expand Down