podman-desktop icon indicating copy to clipboard operation
podman-desktop copied to clipboard

feat(color-builder): add registration for transparent colors

Open vancura opened this issue 1 month ago • 3 comments

Introduced fluent builder API for color definitions with alpha support:

  • colorPalette(color).withAlpha(alpha) - wraps a color with optional opacity
  • colorDefinition(id).withLight(...).withDark(...).build() - builds complete color definitions
  • this.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 factory
  • color-builder.ts - ColorDefinitionBuilder, ColorBuilder, colorDefinition factory, and applyAlpha utility

Refactored 4 color definitions to use the new pattern:

  • item-disabled
  • link-hover-bg
  • button-close-hover-bg
  • button-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]

vancura avatar Nov 27 '25 16:11 vancura

📝 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.ts preserve 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.

❤️ Share

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

coderabbitai[bot] avatar Nov 27 '25 16:11 coderabbitai[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests.

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Nov 27 '25 16:11 codecov[bot]

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.

simonrey1 avatar Dec 10 '25 14:12 simonrey1