Skip to content

Commit

Permalink
dark + light class suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-rogerson committed Nov 24, 2020
1 parent 8d14eb4 commit 7a2e050
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/darkLightMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { throwIf } from './utils'
import { logBadGood } from './logging'

const checkDarkLightClasses = className =>
throwIf(
['dark', 'light'].includes(className),
() =>
`\n\n"${className}" must be added as className:\n\n${logBadGood(
`tw\`${className}\``,
`<div className="${className}">`
)}\n\nRead more at https://twinredirect.page.link/darkLightMode\n`
)

export { checkDarkLightClasses }
4 changes: 3 additions & 1 deletion src/logging.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from 'chalk'
import getSuggestions from './suggestions'
import { checkDarkLightClasses } from './darkLightMode'

const color = {
error: chalk.hex('#ff8383'),
Expand Down Expand Up @@ -123,8 +124,9 @@ const errorSuggestions = properties => {
pieces: { className },
} = properties

const textNotFound = logNoClass(properties)
checkDarkLightClasses(className)

const textNotFound = logNoClass(properties)
if (!hasSuggestions) return spaced(textNotFound)

const suggestions = getSuggestions(properties)
Expand Down
2 changes: 1 addition & 1 deletion src/macro/tw.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const handleTwProperty = ({ path, t, state }) => {
// Feedback for unsupported usage
throwIf(nodeValue.expression && !expressionValue, () =>
logGeneralError(
`Only plain strings can be used with the "tw" prop.\nEg: <div tw="text-black" /> or <div tw={"text-black"} />`
`Only plain strings can be used with the "tw" prop.\nEg: <div tw="text-black" /> or <div tw={"text-black"} />\nRead more at https://twinredirect.page.link/template-literals`
)
)

Expand Down
2 changes: 1 addition & 1 deletion src/prechecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const precheckGroup = ({ classNameRaw }) =>
throwIf(
classNameRaw === 'group',
() =>
`"group" must be added as className:\n\n${logBadGood(
`\n\n"group" must be added as className:\n\n${logBadGood(
'tw`group`',
'<div className="group">'
)}\n`
Expand Down

0 comments on commit 7a2e050

Please sign in to comment.