Skip to content

Commit 6a6186c

Browse files
authored
Remove bare value support for translate utilities (#13289)
* make `themeKeys` optional and default to `[]` * remove `themeKeys` that already map 1:1 to a number or percentage These can be handled by bare values without issues. * remove fallback theme key lookup - In case of `columns`, bare values can be used for the amount of columns - In case of `divide-width`, we can always look at `--border-width` * drop theme keys from suggestions * drop bare value support for `translate-{axis}` * add todo * Revert "remove `themeKeys` that already map 1:1 to a number or percentage" This reverts commit ef3b47a. * Revert "remove fallback theme key lookup" This reverts commit 0a5fc2d. * Revert "drop theme keys from suggestions" This reverts commit 7179a19. * Revert "add todo" This reverts commit 7340cdf.
1 parent ec72fb6 commit 6a6186c

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

packages/tailwindcss/src/utilities.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export function createUtilities(theme: Theme) {
290290
type UtilityDescription = {
291291
supportsNegative?: boolean
292292
supportsFractions?: boolean
293-
themeKeys: ThemeKey[]
293+
themeKeys?: ThemeKey[]
294294
defaultValue?: string | null
295295
handleBareValue?: (value: NamedUtilityValue) => string | null
296296
handle: (value: string) => AstNode[] | undefined
@@ -315,11 +315,14 @@ export function createUtilities(theme: Theme) {
315315
// ever support both of these — `defaultValue` is for things like
316316
// `grayscale` whereas the `DEFAULT` in theme is for things like
317317
// `shadow` or `blur`.
318-
value = desc.defaultValue ?? theme.get(desc.themeKeys)
318+
value = desc.defaultValue ?? theme.get(desc.themeKeys ?? [])
319319
} else if (candidate.value.kind === 'arbitrary') {
320320
value = candidate.value.value
321321
} else {
322-
value = theme.resolve(candidate.value.fraction ?? candidate.value.value, desc.themeKeys)
322+
value = theme.resolve(
323+
candidate.value.fraction ?? candidate.value.value,
324+
desc.themeKeys ?? [],
325+
)
323326

324327
// Automatically handle things like `w-1/2` without requiring `1/2` to
325328
// exist as a theme value.
@@ -344,7 +347,7 @@ export function createUtilities(theme: Theme) {
344347
suggest(classRoot, () => [
345348
{
346349
supportsNegative: desc.supportsNegative,
347-
valueThemeKeys: desc.themeKeys,
350+
valueThemeKeys: desc.themeKeys ?? [],
348351
hasDefaultValue: desc.defaultValue !== undefined && desc.defaultValue !== null,
349352
},
350353
])
@@ -638,7 +641,6 @@ export function createUtilities(theme: Theme) {
638641
})
639642
staticUtility('col-span-full', [['grid-column', '1 / -1']])
640643
functionalUtility('col-span', {
641-
themeKeys: [],
642644
handleBareValue: ({ value }) => {
643645
if (!Number.isInteger(Number(value))) return null
644646
return value
@@ -1063,7 +1065,6 @@ export function createUtilities(theme: Theme) {
10631065
*/
10641066
functionalUtility('shrink', {
10651067
defaultValue: '1',
1066-
themeKeys: [],
10671068
handleBareValue: ({ value }) => {
10681069
if (Number.isNaN(Number(value))) return null
10691070
return value
@@ -1076,7 +1077,6 @@ export function createUtilities(theme: Theme) {
10761077
*/
10771078
functionalUtility('grow', {
10781079
defaultValue: '1',
1079-
themeKeys: [],
10801080
handleBareValue: ({ value }) => {
10811081
if (Number.isNaN(Number(value))) return null
10821082
return value
@@ -1255,10 +1255,6 @@ export function createUtilities(theme: Theme) {
12551255
supportsNegative: true,
12561256
supportsFractions: true,
12571257
themeKeys: ['--translate', '--spacing'],
1258-
handleBareValue: ({ value }) => {
1259-
if (Number.isNaN(Number(value))) return null
1260-
return `${value}%`
1261-
},
12621258
handle,
12631259
})
12641260
utilities.static(`translate-${axis}-px`, (candidate) => {
@@ -2997,7 +2993,6 @@ export function createUtilities(theme: Theme) {
29972993
staticUtility('font-stretch-extra-expanded', [['font-stretch', 'extra-expanded']])
29982994
staticUtility('font-stretch-ultra-expanded', [['font-stretch', 'ultra-expanded']])
29992995
functionalUtility('font-stretch', {
3000-
themeKeys: [],
30012996
handleBareValue: ({ value }) => {
30022997
if (!value.endsWith('%')) return null
30032998
let num = Number(value.slice(0, -1))

0 commit comments

Comments
 (0)