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

Add warning to Tailwind plugin if colors.white is not a string #1726

Merged
merged 2 commits into from
Apr 9, 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
5 changes: 5 additions & 0 deletions .changeset/strange-tips-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight-tailwind': patch
---

Adds warning log if a user tries to set `colors.white` in their Tailwind theme config with an object instead of a string.
14 changes: 12 additions & 2 deletions packages/tailwind/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ const StarlightTailwindPlugin = () =>
? theme(`colors.accent.${shade}`, theme(`colors.accent.900`, fallback))
: theme(`colors.accent.${shade}`, fallback);

let white: string = theme('colors.white');
if (typeof white !== 'string') {
console.warn(
`Expected \`colors.white\` in Tailwind theme to be a string, received ${typeof white}.\n` +
`Try setting a single value, for example \`white: '#fafaf9'\` or \`white: colors.stone[50]\`.`
);
// Ensure a usable value for white if the user-configured one is wrong.
white = '#fff';
}

addBase({
// Restore crucial styles from Tailwind Preflight: https://tailwindcss.com/docs/preflight
// Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
Expand All @@ -65,7 +75,7 @@ const StarlightTailwindPlugin = () =>
'--sl-font': theme('fontFamily.sans'),
'--sl-font-mono': theme('fontFamily.mono'),
// Dark mode Starlight theme variables.
'--sl-color-white': theme('colors.white'),
'--sl-color-white': white,
'--sl-color-gray-1': theme('colors.gray.200'),
'--sl-color-gray-2': theme('colors.gray.300'),
'--sl-color-gray-3': theme('colors.gray.400'),
Expand All @@ -86,7 +96,7 @@ const StarlightTailwindPlugin = () =>
'--sl-color-gray-5': theme('colors.gray.300'),
'--sl-color-gray-6': theme('colors.gray.200'),
'--sl-color-gray-7': theme('colors.gray.100'),
'--sl-color-black': theme('colors.white'),
'--sl-color-black': white,
'--sl-color-accent-low': themeAccent(200, '#c7d2fe'),
'--sl-color-accent': themeAccent(600, '#4f46e5'),
'--sl-color-accent-high': themeAccent(900, '#312e81'),
Expand Down
Loading