feat(color-builder): add registration for transparent colors
Introduced fluent builder API for color definitions with alpha support:
colorPalette(color).withAlpha(alpha)- wraps a color with optional opacitycolorDefinition(id).withLight(...).withDark(...).build()- builds complete color definitionsthis.color(id).withLight(color, alpha).withDark(color, alpha).build()- simplified builder for use within ColorRegistry
Added registerColorDefinition() method to register colors using the builder pattern.
Added applyAlpha() helper function for internal alpha handling via culori.
Extracted helper classes to new modules:
color-palette-helper.ts- ColorPaletteHelper and colorPalette factorycolor-builder.ts- ColorDefinitionBuilder, ColorBuilder, colorDefinition factory, and applyAlpha utility
Refactored 4 color definitions to use the new pattern:
item-disabledlink-hover-bgbutton-close-hover-bgbutton-link-hover-bg
What issues does this PR fix or reference?
Fixes #15016
- [x] Tests are covering the bug fix or the new feature
Co-Authored-By: Claude [email protected]
📝 Walkthrough
Walkthrough
Adds a fluent color-building system (ColorPaletteHelper, ColorDefinitionBuilder, ColorBuilder, applyAlpha) and integrates it into ColorRegistry via protected helpers; includes comprehensive unit tests for builders and registry flows.
Changes
| Cohort / File(s) | Summary |
|---|---|
Color palette helper packages/main/src/plugin/color-palette-helper.ts |
New ColorPaletteHelper class and colorPalette() factory providing a fluent color wrapper with withAlpha() and validated alpha (0–1). |
Color builder implementation & tests packages/main/src/plugin/color-builder.ts, packages/main/src/plugin/color-builder.spec.ts |
New ColorDefinitionBuilder, ColorBuilder, colorDefinition() factory, and applyAlpha() utility (uses culori). Fluent API with withLight()/withDark(), alpha propagation/validation, parse/format error handling. Adds unit tests covering success and error flows. |
Color registry integration & tests packages/main/src/plugin/color-registry.ts, packages/main/src/plugin/color-registry.spec.ts |
Registry augmented with protected registerColorDefinition(def) and color(id) returning ColorBuilder; replaced direct color registrations with builder-based calls; tests updated to exercise new APIs, builder usage, and error cases. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
- Inspect culori usage, parsing/formatting and alpha application in
packages/main/src/plugin/color-builder.ts. - Verify that registry changes in
packages/main/src/plugin/color-registry.tspreserve previous color semantics and initialization ordering. - Confirm typings/visibility for new protected methods and exported builders.
- Review new tests (
*.spec.ts) for coverage of success/error paths and alignment with implementation.
Pre-merge checks
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly describes the main feature: adding registration for transparent colors with fluent builder API support for alpha/opacity operations. |
| Linked Issues check | ✅ Passed | The PR comprehensively addresses #15016 by replacing the single inline opacity implementation with reusable fluent builder APIs (colorPalette, colorDefinition, registerColorDefinition) that improve maintainability and enable reuse across color-processing code. |
| Out of Scope Changes check | ✅ Passed | All changes are directly scoped to the opacity/alpha registration objectives: new builder classes, refactored color definitions, and test coverage remain within the linked issue requirements. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Description check | ✅ Passed | The pull request description clearly relates to the changeset, detailing the fluent builder API for color definitions with alpha support, new helper modules, refactored color definitions, and test coverage. |
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 @coderabbitai help to get the list of available commands and usage tips.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:loudspeaker: Thoughts on this report? Let us know!
suggestion: we could remove some of the code to make it work for your issue. I have opened a PR to illustrate my suggestion https://github.com/vancura/podman-desktop/pull/2.