Skip to content

Commit

Permalink
fix(screens): fix @screen resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Sep 10, 2022
1 parent d001a39 commit a725da9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"postcss-nested": "^5.0.6",
"recast": "^0.21.2",
"scule": "^0.3.2",
"style-dictionary-esm": "^1.0.13",
"style-dictionary-esm": "^1.0.14",
"unplugin": "^0.9.5"
},
"devDependencies": {
Expand All @@ -96,7 +96,7 @@
"tsup": "^6.2.3",
"typescript": "^4.8.3",
"vite": "^3.1.0",
"vitest": "^0.23.1",
"vitest": "^0.23.2",
"webpack": "^5.74.0"
},
"pnpm": {
Expand Down
66 changes: 33 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions src/transforms/css.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json5 from 'json5'
import { referencesRegex, stringify } from '../utils'
import chalk from 'chalk'
import { logger, referencesRegex, stringify } from '../utils'
import type { TokensFunction } from '../types'

const cssContentRegex = /css\(({.*?\})\)/mgs
Expand Down Expand Up @@ -84,9 +85,16 @@ export const transformCssFunction = (
}
}
if (screenMatches) {
const screenToken = $tokens(`screens.${screenMatches[1]}` as any, { key: undefined })
const screen = screenMatches[1]
const screenToken = $tokens(`screens.${screen}` as any, { key: undefined })
const tokenValue = (screenToken as any)?.original?.value

if (!tokenValue) {
logger.warn(`This screen size is not defined: ${chalk.red(screen)}\n`)
}

return {
[`@media (min-width: ${(screenToken as any).original.value})`]: value,
[`@media (min-width: ${tokenValue || '0px'})`]: value,
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/transforms/vue/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ export function transformScreens(code = '', $tokens: TokensFunction): string {
return `@media (min-width: ${screenToken.value}) {`
}

logger.warn(
`This screen size is not defined: ${chalk.red(screenSize)}\n\n`,
'Available screen sizes: ', Object.keys(screens).map(screen => chalk.green(screen)).join(', '),
)
logger.warn(`This screen size is not defined: ${chalk.red(screenSize)}\n`)

return '@media (min-width: 0px) {'
},
Expand Down

0 comments on commit a725da9

Please sign in to comment.