Skip to content

Cleaned up color_to_rgba template helper#28392

Draft
EvanHahn wants to merge 1 commit into
mainfrom
color_to_rgba-cleanups
Draft

Cleaned up color_to_rgba template helper#28392
EvanHahn wants to merge 1 commit into
mainfrom
color_to_rgba-cleanups

Conversation

@EvanHahn
Copy link
Copy Markdown
Contributor

@EvanHahn EvanHahn commented Jun 5, 2026

no ref

This makes several fixes to our color_to_rgba template helper:

  • Handles more invalid alpha values: non-numbers, non-strings, and NaN.

  • Converts everything to TypeScript.

  • Uses "color" in all variable names, instead of both "color" and "background color".

  • Uses "alpha" in all variable names, instead of both "alpha" and "opacity".

  • Adds additional tests.

This shouldn't change anything for folks using the helper correctly. If they were using it incorrectly (e.g., passing an invalid alpha value), we now normalize it a little better. I followed the docs when deciding how things should work.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Too much diff to scan? Review this PR in Change Stack to start with the highest-impact changes.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ed67e473-f9bc-4474-b41f-ddda75c003ef

📥 Commits

Reviewing files that changed from the base of the PR and between 5d8ad04 and e987c3d.

📒 Files selected for processing (4)
  • ghost/core/core/frontend/helpers/color_to_rgba.js
  • ghost/core/core/frontend/helpers/color_to_rgba.ts
  • ghost/core/test/unit/frontend/helpers/color-to-rgba.test.js
  • ghost/core/test/unit/frontend/helpers/color-to-rgba.test.ts
💤 Files with no reviewable changes (2)
  • ghost/core/test/unit/frontend/helpers/color-to-rgba.test.js
  • ghost/core/core/frontend/helpers/color_to_rgba.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • ghost/core/core/frontend/helpers/color_to_rgba.ts

Walkthrough

The JavaScript helper for color_to_rgba was removed and replaced by a new TypeScript implementation that parses and sanitizes raw color and alpha inputs, clamps alpha to [0,1], applies the alpha using @tryghost/color-utils, and exports the result. The PR also adds a TypeScript test suite covering valid conversions, alpha parsing/clamping (including infinities and string input), and fallback behavior for invalid colors or alpha values.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: converting and cleaning up the color_to_rgba helper, which aligns with the TypeScript conversion and bug fixes across the changeset.
Description check ✅ Passed The description directly explains the changes made to the color_to_rgba helper, including TypeScript conversion, improved alpha handling, naming standardization, and additional tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch color_to_rgba-cleanups

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

no ref

This makes several fixes to our `color_to_rgba` template helper:

- Handles more invalid `alpha` values: non-numbers, non-strings, and
  `NaN`.

- Converts everything to TypeScript.

- Uses "color" in all variable names, instead of both "color" and
  "background color".

- Uses "alpha" in all variable names, instead of both "alpha" and
  "opacity".

- Adds additional tests.

This shouldn't change anything for folks using the helper correctly. If
they were using it *incorrectly* (e.g., passing an invalid `alpha`
value), we now normalize it a little better. I followed [the docs][0]
when deciding how things should work.

[0]: https://docs.ghost.org/themes/helpers/utility/color_to_rgba
@EvanHahn EvanHahn force-pushed the color_to_rgba-cleanups branch from 5d8ad04 to e987c3d Compare June 5, 2026 20:28
@EvanHahn EvanHahn marked this pull request as draft June 5, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant