Skip to content

[lit] Wire A2UI primaryColor on basic catalog elements.#1343

Open
ditman wants to merge 10 commits intogoogle:mainfrom
ditman:lit-wire-primarycolor
Open

[lit] Wire A2UI primaryColor on basic catalog elements.#1343
ditman wants to merge 10 commits intogoogle:mainfrom
ditman:lit-wire-primarycolor

Conversation

@ditman
Copy link
Copy Markdown
Collaborator

@ditman ditman commented May 6, 2026

Description

This PR modifies the Lit renderer to wire the theme.primaryColor property coming from the A2UI responses that use the basic catalog.

There's some minor changes to other packages to make this easier to test:

  • specification: adds a "primary" button to the basic catalog example 5
  • web_core: adds a mechanism to recompute the "light"/"dark"/"hover" colors using the same formula across the default stylesheet and Lit components later.
  • lit/a2ui_explorer: (optional) adds a way to override the theme.primaryColor of the sample apps that gets updated in real time as the user changes it.

Issues

Pre-launch Checklist

If you need help, consider asking for advice on the discussion board.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for agent-provided primary colors across basic catalog components. Key changes include the addition of a computeColor utility in web_core to generate CSS formulas for color variants and the integration of these styles into the Lit renderer. The explorer tool was also updated with a color picker for live testing. Review feedback recommends adding type safety checks when processing messages to avoid potential runtime errors and optimizing the Lit component lifecycle by moving style property updates to willUpdate to minimize repaints and avoid flashes of unstyled content.

Comment thread renderers/lit/a2ui_explorer/src/local-gallery.ts
Comment thread renderers/lit/src/v0_9/catalogs/basic/basic-catalog-a2ui-lit-element.ts Outdated
Copy link
Copy Markdown
Collaborator Author

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments/questions for myself and the reviewers!

Comment thread renderers/lit/a2ui_explorer/src/local-gallery.ts Outdated
Comment thread renderers/lit/a2ui_explorer/src/local-gallery.ts Outdated
Comment thread renderers/lit/a2ui_explorer/src/local-gallery.ts Outdated
Comment thread renderers/lit/a2ui_explorer/src/local-gallery.ts Outdated
Comment on lines +66 to +68
this.style.removeProperty('--a2ui-color-primary-light');
this.style.removeProperty('--a2ui-color-primary-dark');
this.style.removeProperty('--a2ui-color-primary-hover');
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we can compute light/dark/hover programmatically, would it make sense to remove them from the core stylesheet, and let the components that need light/dark/hover variants of a color use the formulas inline with per-widget overrides? That would simplify this a lot, and make the set of CSS variables exposed from web_core smaller. WDYT @josemontespg?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. Would that affect React also?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josemontespg once we land the formulas to compute light/dark/hover modes for the colors, we'd go into each basic catalog implementation and use that based on the defined --a2ui-xxx-color variable, and remove the usages of the specific "hover"/"dark"/"light" variants. Then we can remove the variables from the core css :)

Comment thread renderers/web_core/src/v0_9/basic_catalog/styles/default.ts Outdated
Comment thread renderers/lit/src/v0_9/tests/basic-catalog-a2ui-lit-element.test.ts Outdated
Comment thread renderers/lit/src/v0_9/tests/basic-catalog-a2ui-lit-element.test.ts Outdated
* @param options Options containing the dark and light variant variable names.
* @returns The CSS formula string.
*/
export function computeColor(type: 'hover', options: ComputeColorHoverOptions): string;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about renaming this to computeHoverColor to be more clear about what it's used for?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I need this to be computeColor across all 3 aliases so I can only export a single function to end users, I didn't want to bloat the public API with color-related methods)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But....it really is multiple APIs "hiding" behind a single function :-)

Using explicitly named functions would seem to reduce cognitive load on developers.

Unless you're expecting to grow the list of acceptable values for the type parameter over time?

* @param options Options containing the base color variable and optional percentage.
* @returns The CSS formula string.
*/
export function computeColor(type: 'light' | 'dark', options: ComputeColorLightDarkOptions): string;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to have separate computeLightColor and computeDarkColor to have a more explicit API?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, the way that I wanted this to work is to just export a single function that supports all 3 cases to not bloat the API surface with color-related methods.

All the methods are called the same to leverage TS function overloading so I get some type safety on the "options" types, but they all need to be named "computeColor".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this method to computeColorVariant so it's a little bit more clear what it does!

Comment on lines +66 to +68
this.style.removeProperty('--a2ui-color-primary-light');
this.style.removeProperty('--a2ui-color-primary-dark');
this.style.removeProperty('--a2ui-color-primary-hover');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. Would that affect React also?

Copy link
Copy Markdown
Collaborator

@josemontespg josemontespg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@ditman
Copy link
Copy Markdown
Collaborator Author

ditman commented May 6, 2026

OK I did some more tweaks to the Lit explorer app, it looks like this now:

Screenshot 2026-05-06 at 4 47 14 PM

@ditman ditman requested review from jgindin and josemontespg May 6, 2026 23:50
@ditman
Copy link
Copy Markdown
Collaborator Author

ditman commented May 6, 2026

Requesting a PTAL from @josemontespg and @jgindin! (thanks for taking a look Jay!)

@ditman ditman force-pushed the lit-wire-primarycolor branch from e6e6396 to f65cd8b Compare May 7, 2026 02:19
}
}

advanceMessages(all = false) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this code is not changed in this PR, but can we add typing to the all function parameter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

[v0.9] Wire up agent-provided primary color in Lit renderer

3 participants