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

[v4] Support negative values for {col,row}-{start,end} utilities #13780

Merged
merged 2 commits into from
Jun 3, 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 @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Use `length` data type for `background-size` instead of `background-position` ([#13771](https://github.com/tailwindlabs/tailwindcss/pull/13771))
- Support negative values for `{col,row}-{start,end}` utilities ([#13780](https://github.com/tailwindlabs/tailwindcss/pull/13780))

## [4.0.0-alpha.15] - 2024-05-08

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@ exports[`getClassList 1`] = `
"-bottom-1",
"-bottom-3",
"-bottom-4",
"-col-end-1",
"-col-end-10",
"-col-end-11",
"-col-end-12",
"-col-end-13",
"-col-end-2",
"-col-end-3",
"-col-end-4",
"-col-end-5",
"-col-end-6",
"-col-end-7",
"-col-end-8",
"-col-end-9",
"-col-start-1",
"-col-start-10",
"-col-start-11",
"-col-start-12",
"-col-start-13",
"-col-start-2",
"-col-start-3",
"-col-start-4",
"-col-start-5",
"-col-start-6",
"-col-start-7",
"-col-start-8",
"-col-start-9",
"-end-0.5",
"-end-1",
"-end-3",
Expand Down Expand Up @@ -118,6 +144,32 @@ exports[`getClassList 1`] = `
"-rotate-z-45",
"-rotate-z-6",
"-rotate-z-90",
"-row-end-1",
"-row-end-10",
"-row-end-11",
"-row-end-12",
"-row-end-13",
"-row-end-2",
"-row-end-3",
"-row-end-4",
"-row-end-5",
"-row-end-6",
"-row-end-7",
"-row-end-8",
"-row-end-9",
"-row-start-1",
"-row-start-10",
"-row-start-11",
"-row-start-12",
"-row-start-13",
"-row-start-2",
"-row-start-3",
"-row-start-4",
"-row-start-5",
"-row-start-6",
"-row-start-7",
"-row-start-8",
"-row-start-9",
"-scale-0",
"-scale-100",
"-scale-105",
Expand Down
90 changes: 54 additions & 36 deletions packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,13 @@ test('col', () => {
})

test('col-start', () => {
expect(run(['col-start-auto', 'col-start-4', 'col-start-99', 'col-start-[123]']))
expect(run(['col-start-auto', 'col-start-4', 'col-start-99', 'col-start-[123]', '-col-start-4']))
.toMatchInlineSnapshot(`
".col-start-4 {
".-col-start-4 {
grid-column-start: calc(4 * -1);
}

.col-start-4 {
grid-column-start: 4;
}

Expand All @@ -719,28 +723,33 @@ test('col-start', () => {
grid-column-start: auto;
}"
`)
expect(run(['col-start', '-col-start-4', 'col-start-unknown'])).toEqual('')
expect(run(['col-start', 'col-start-unknown'])).toEqual('')
})

test('col-end', () => {
expect(run(['col-end-auto', 'col-end-4', 'col-end-99', 'col-end-[123]'])).toMatchInlineSnapshot(`
".col-end-4 {
grid-column-end: 4;
}
expect(run(['col-end-auto', 'col-end-4', 'col-end-99', 'col-end-[123]', '-col-end-4']))
.toMatchInlineSnapshot(`
".-col-end-4 {
grid-column-end: calc(4 * -1);
}

.col-end-99 {
grid-column-end: 99;
}
.col-end-4 {
grid-column-end: 4;
}

.col-end-\\[123\\] {
grid-column-end: 123;
}
.col-end-99 {
grid-column-end: 99;
}

.col-end-auto {
grid-column-end: auto;
}"
`)
expect(run(['col-end', '-col-end-4', 'col-end-unknown'])).toEqual('')
.col-end-\\[123\\] {
grid-column-end: 123;
}

.col-end-auto {
grid-column-end: auto;
}"
`)
expect(run(['col-end', 'col-end-unknown'])).toEqual('')
})

test('row', () => {
Expand Down Expand Up @@ -782,9 +791,13 @@ test('row', () => {
})

test('row-start', () => {
expect(run(['row-start-auto', 'row-start-4', 'row-start-99', 'row-start-[123]']))
expect(run(['row-start-auto', 'row-start-4', 'row-start-99', 'row-start-[123]', '-row-start-4']))
.toMatchInlineSnapshot(`
".row-start-4 {
".-row-start-4 {
grid-row-start: calc(4 * -1);
}

.row-start-4 {
grid-row-start: 4;
}

Expand All @@ -800,28 +813,33 @@ test('row-start', () => {
grid-row-start: auto;
}"
`)
expect(run(['row-start', '-row-start-4', 'row-start-unknown'])).toEqual('')
expect(run(['row-start', 'row-start-unknown'])).toEqual('')
})

test('row-end', () => {
expect(run(['row-end-auto', 'row-end-4', 'row-end-99', 'row-end-[123]'])).toMatchInlineSnapshot(`
".row-end-4 {
grid-row-end: 4;
}
expect(run(['row-end-auto', 'row-end-4', 'row-end-99', 'row-end-[123]', '-row-end-4']))
.toMatchInlineSnapshot(`
".-row-end-4 {
grid-row-end: calc(4 * -1);
}

.row-end-99 {
grid-row-end: 99;
}
.row-end-4 {
grid-row-end: 4;
}

.row-end-\\[123\\] {
grid-row-end: 123;
}
.row-end-99 {
grid-row-end: 99;
}

.row-end-auto {
grid-row-end: auto;
}"
`)
expect(run(['row-end', '-row-end-4', 'row-end-unknown'])).toEqual('')
.row-end-\\[123\\] {
grid-row-end: 123;
}

.row-end-auto {
grid-row-end: auto;
}"
`)
expect(run(['row-end', 'row-end-unknown'])).toEqual('')
})

test('float', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ export function createUtilities(theme: Theme) {
*/
staticUtility('col-start-auto', [['grid-column-start', 'auto']])
functionalUtility('col-start', {
supportsNegative: true,
handleBareValue: ({ value }) => {
if (!Number.isInteger(Number(value))) return null
return value
Expand All @@ -666,6 +667,7 @@ export function createUtilities(theme: Theme) {
*/
staticUtility('col-end-auto', [['grid-column-end', 'auto']])
functionalUtility('col-end', {
supportsNegative: true,
handleBareValue: ({ value }) => {
if (!Number.isInteger(Number(value))) return null
return value
Expand All @@ -683,13 +685,15 @@ export function createUtilities(theme: Theme) {

suggest('col-start', () => [
{
supportsNegative: true,
values: Array.from({ length: 13 }, (_, i) => `${i + 1}`),
valueThemeKeys: ['--grid-column-start'],
},
])

suggest('col-end', () => [
{
supportsNegative: true,
values: Array.from({ length: 13 }, (_, i) => `${i + 1}`),
valueThemeKeys: ['--grid-column-end'],
},
Expand Down Expand Up @@ -718,6 +722,7 @@ export function createUtilities(theme: Theme) {
*/
staticUtility('row-start-auto', [['grid-row-start', 'auto']])
functionalUtility('row-start', {
supportsNegative: true,
handleBareValue: ({ value }) => {
if (!Number.isInteger(Number(value))) return null
return value
Expand All @@ -731,6 +736,7 @@ export function createUtilities(theme: Theme) {
*/
staticUtility('row-end-auto', [['grid-row-end', 'auto']])
functionalUtility('row-end', {
supportsNegative: true,
handleBareValue: ({ value }) => {
if (!Number.isInteger(Number(value))) return null
return value
Expand All @@ -748,13 +754,15 @@ export function createUtilities(theme: Theme) {

suggest('row-start', () => [
{
supportsNegative: true,
values: Array.from({ length: 13 }, (_, i) => `${i + 1}`),
valueThemeKeys: ['--grid-row-start'],
},
])

suggest('row-end', () => [
{
supportsNegative: true,
values: Array.from({ length: 13 }, (_, i) => `${i + 1}`),
valueThemeKeys: ['--grid-row-end'],
},
Expand Down
Loading