-
Notifications
You must be signed in to change notification settings - Fork 1.1k
(Lit) Style widgets using CSS variables. #1079
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?
Changes from all commits
bf8a3e3
3e139bf
7ef3307
e11864f
e3050c6
a5039f6
775eede
041a413
b47259f
ad90be3
bb82f21
da9c42a
a717b3a
1f8eb6c
fdd76a6
5c7a074
a5b96d1
4d1cfdb
aa78c03
43e4f24
936b058
4e8f241
a7b2f21
5451776
66c3ed8
ad16d84
03456c0
838592d
f2658cc
2e933c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { ComponentApi } from "@a2ui/web_core/v0_9"; | ||
| import { A2uiLitElement } from "../../a2ui-lit-element.js"; | ||
| import { injectBasicCatalogStyles } from "@a2ui/web_core/v0_9/basic_catalog"; | ||
|
|
||
| /** | ||
| * A base class for A2UI basic catalog components. | ||
| * | ||
| * Handles some common features of all basic catalog A2ui elements, like | ||
| * injecting the basic CSS styles if needed, and setting the flex property | ||
| * if set by the framework. | ||
| */ | ||
| export abstract class BasicCatalogA2uiLitElement< | ||
| Api extends ComponentApi, | ||
| > extends A2uiLitElement<Api> { | ||
| connectedCallback() { | ||
| super.connectedCallback(); | ||
| injectBasicCatalogStyles(); | ||
| } | ||
|
|
||
| updated(changedProperties: Map<PropertyKey, unknown>) { | ||
| super.updated(changedProperties); | ||
| const props = this.controller?.props as any; | ||
| if (props && props.weight !== undefined) { | ||
| this.style.flex = String(props.weight); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,14 +14,86 @@ | |||||||||
| * limitations under the License. | ||||||||||
| */ | ||||||||||
|
|
||||||||||
| import { html, nothing } from "lit"; | ||||||||||
| import { html, nothing, css } from "lit"; | ||||||||||
| import { customElement } from "lit/decorators.js"; | ||||||||||
| import { classMap } from "lit/directives/class-map.js"; | ||||||||||
| import { ButtonApi } from "@a2ui/web_core/v0_9/basic_catalog"; | ||||||||||
| import { A2uiLitElement, A2uiController } from "@a2ui/lit/v0_9"; | ||||||||||
| import { BasicCatalogA2uiLitElement } from "../basic-catalog-a2ui-lit-element.js"; | ||||||||||
| import { A2uiController } from "@a2ui/lit/v0_9"; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * A button component that can be used to trigger an action. | ||||||||||
| */ | ||||||||||
| @customElement("a2ui-basic-button") | ||||||||||
| export class A2uiBasicButtonElement extends A2uiLitElement<typeof ButtonApi> { | ||||||||||
| export class A2uiBasicButtonElement extends BasicCatalogA2uiLitElement<typeof ButtonApi> { | ||||||||||
| /** | ||||||||||
| * The styles of the button can be customized by redefining the following | ||||||||||
| * CSS variables: | ||||||||||
| * | ||||||||||
| * - Primary variant: | ||||||||||
| * - `--a2ui-color-primary`: The color for the primary variant. | ||||||||||
| * - `--a2ui-color-on-primary`: The color of the text on the primary variant. | ||||||||||
| * - Standard/default variant: | ||||||||||
| * - `--a2ui-color-secondary`: The color for the default variant. | ||||||||||
| * - `--a2ui-color-on-secondary`: The color of the text on the default variant. | ||||||||||
| * - `--a2ui-button-border`: The styling for the button border. Defaults to `--a2ui-border-width` width and `--a2ui-color-border` color. | ||||||||||
| * - `--a2ui-button-border-radius`: The border radius of the button. Defaults to `--a2ui-border-radius`. | ||||||||||
| * - `--a2ui-button-padding`: The padding of the button. Defaults to `--a2ui-spacing-m`. | ||||||||||
| * - `--a2ui-button-margin`: The outer margin of the button. Defaults to `--a2ui-spacing-m`. | ||||||||||
| */ | ||||||||||
| static styles = css` | ||||||||||
| :host { | ||||||||||
| display: inline-block; | ||||||||||
| margin: var(--a2ui-button-margin, var(--a2ui-spacing-m)); | ||||||||||
| } | ||||||||||
| :where(:host) { | ||||||||||
| --_color-primary: var(--a2ui-color-primary, #17e); | ||||||||||
| --_button-border-radius: var( | ||||||||||
| --a2ui-button-border-radius, | ||||||||||
| var(--a2ui-spacing-s, 0.25rem) | ||||||||||
| ); | ||||||||||
| --_button-padding: var( | ||||||||||
| --a2ui-button-padding, | ||||||||||
| var(--a2ui-spacing-m, 0.5rem) var(--a2ui-spacing-l, 1rem) | ||||||||||
| ); | ||||||||||
| --_button-border: var( | ||||||||||
| --a2ui-button-border, | ||||||||||
| var(--a2ui-border-width, 1px) solid var(--a2ui-color-border, #ccc) | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| .a2ui-button { | ||||||||||
| --_a2ui-text-margin: 0; | ||||||||||
| --_a2ui-text-color: var(--a2ui-color-on-secondary, #333); | ||||||||||
| padding: var(--_button-padding); | ||||||||||
| background: var(--a2ui-button-background, var(--a2ui-color-surface, #fff)); | ||||||||||
| box-shadow: var(--a2ui-button-box-shadow, none); | ||||||||||
| font-weight: var(--a2ui-button-font-weight, normal); | ||||||||||
| color: var(--_a2ui-text-color); | ||||||||||
| border: var(--_button-border); | ||||||||||
| border-radius: var(--_button-border-radius); | ||||||||||
| cursor: pointer; | ||||||||||
| display: inline-flex; | ||||||||||
| align-items: center; | ||||||||||
| justify-content: center; | ||||||||||
| } | ||||||||||
| .a2ui-button.a2ui-button-primary { | ||||||||||
| --_a2ui-text-color: var(--a2ui-color-on-primary, #fff); | ||||||||||
| background-color: var(--_color-primary); | ||||||||||
| color: var(--_a2ui-text-color); | ||||||||||
| } | ||||||||||
ditman marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| .a2ui-button:hover { | ||||||||||
| background-color: var(--a2ui-color-secondary-hover, #ddd); | ||||||||||
| } | ||||||||||
| .a2ui-button.a2ui-button-primary:hover { | ||||||||||
| background-color: var(--a2ui-color-primary-hover, #fbd); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fallback color
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default hover background color
Suggested change
|
||||||||||
| } | ||||||||||
| .a2ui-button.a2ui-button-borderless { | ||||||||||
| background: none; | ||||||||||
| padding: 0; | ||||||||||
| color: var(--_color-primary); | ||||||||||
| } | ||||||||||
| `; | ||||||||||
|
|
||||||||||
| protected createController() { | ||||||||||
| return new A2uiController(this, ButtonApi); | ||||||||||
| } | ||||||||||
|
|
||||||||||
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.
The
weightproperty is applied to the host'sflexstyle, but it is never reset if the property is removed from the component's props. This can lead to unexpected layout behavior if the weight is dynamically changed toundefined.