-
-
Notifications
You must be signed in to change notification settings - Fork 557
fix(color): Preserve alpha/opacity in color formatting #247
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
base: main
Are you sure you want to change the base?
Conversation
|
@abbas10to8 is attempting to deploy a commit to the tweakcn OSS program Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughColor formatter enhanced with comprehensive alpha channel support across HSL, oklch, and hex formats. The Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
utils/color-converter.ts (1)
73-73: Consider whether v4 format would be more intuitive.The function defaults to Tailwind v3 format (e.g.,
"0 100% 50%"without thehsl()wrapper). For a function namedconvertToHSL, developers might expect standard CSS format. Consider whether defaulting totailwindVersion: "4"would provide a more intuitive API for general HSL conversion.That said, the current default is consistent with
colorFormatter's default and may be intentional for Tailwind config usage.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
utils/color-converter.ts(2 hunks)
🔇 Additional comments (6)
utils/color-converter.ts (6)
5-9: LGTM! Clean null-safety and formatting logic.The explicit handling of undefined/null/zero makes the function's behavior clear and predictable. The toFixed(4) precision is appropriate for color values.
11-13: LGTM! Correct alpha detection logic.The helper correctly identifies when alpha transparency should be included in the output (when defined and less than 1). This ensures colors without transparency or with full opacity remain in their simpler format.
15-24: LGTM! Proper CSS Color Module Level 4 syntax.The function correctly formats HSL colors with alpha support using the standard
hsl(h s% l% / alpha)syntax. The conditional inclusion of alpha keeps colors without transparency in their simpler format.
36-46: LGTM! Appropriate handling for both Tailwind versions.The implementation correctly distinguishes between Tailwind v3 (config format without wrapper) and v4 (standard CSS format with wrapper), while preserving alpha in both cases when present.
49-58: LGTM! Fixes the core issue with oklch opacity.This directly addresses issue #246 by preserving alpha in oklch colors. The implementation correctly uses the CSS Color Module Level 4 syntax
oklch(l c h / alpha)to ensure transparency is maintained in previews.
59-63: LGTM! Proper alpha handling in hex format.The implementation correctly uses
formatHex8to include alpha in the 8-digit hex format when transparency is present, and falls back to standard 6-digit hex otherwise. This ensures alpha is preserved across all color formats.
Fixes #246
This PR fixes the issue where oklch colors with percentage-based opacity (e.g., oklch(1 0 0 / 10%)) were rendering at full opacity in previews instead of respecting the transparency value.
Problem
When users input oklch colors with alpha/opacity values, the color picker correctly displayed the color, but the preview rendered it at full opacity. This occurred because the colorFormatter function was stripping the alpha channel when converting colors.
Solution
Updated /utils/color-converter.ts to preserve alpha values across all color format outputs:
Changes
Backward Compatibility
Colors without alpha (or with alpha = 1) continue to output in the same format as before, ensuring no breaking changes for existing themes.
Test Plan
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.