-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(web_components): implement basic web components and catalog adapters #2074
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
Draft
josemontespg
wants to merge
2
commits into
a2ui-project:main
Choose a base branch
from
josemontespg:agent/wt_8e39d767
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
renderers/lit/src/v0_9/catalogs/basic/components/Dialog.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * 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 {html, nothing, css, PropertyValues} from 'lit'; | ||
| import {customElement, query} from 'lit/decorators.js'; | ||
| import {DialogApi} from '@a2ui/web_core/v0_9/basic_catalog'; | ||
| import {BasicCatalogA2uiLitElement} from '../basic-catalog-a2ui-lit-element.js'; | ||
| import {A2uiController} from '../../../a2ui-controller.js'; | ||
|
|
||
| @customElement('a2ui-dialog') | ||
| export class A2uiDialogElement extends BasicCatalogA2uiLitElement<typeof DialogApi> { | ||
| @query('dialog') accessor dialogElement!: HTMLDialogElement; | ||
| static override styles = css` | ||
| :host { | ||
| display: block; | ||
| } | ||
| dialog { | ||
| border: var(--a2ui-border-width, 1px) solid var(--a2ui-color-border, #ccc); | ||
| border-radius: var(--a2ui-border-radius, 12px); | ||
| padding: var(--a2ui-spacing-l, 24px); | ||
| background-color: var(--a2ui-color-surface, #fff); | ||
| color: var(--a2ui-color-on-surface, #333); | ||
| box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); | ||
| max-width: 500px; | ||
| width: 90%; | ||
| } | ||
| dialog::backdrop { | ||
| background: rgba(0, 0, 0, 0.5); | ||
| backdrop-filter: blur(2px); | ||
| } | ||
| .dialog-header { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| margin-bottom: var(--a2ui-spacing-m, 16px); | ||
| } | ||
| .dialog-title { | ||
| font-size: var(--a2ui-font-size-l, 1.25rem); | ||
| font-weight: 600; | ||
| margin: 0; | ||
| } | ||
| .close-btn { | ||
| background: none; | ||
| border: none; | ||
| font-size: 1.25rem; | ||
| cursor: pointer; | ||
| color: var(--a2ui-color-on-surface, #666); | ||
| } | ||
| `; | ||
|
|
||
| protected createController() { | ||
| return new A2uiController(this, DialogApi); | ||
| } | ||
|
|
||
| override updated(changedProperties: PropertyValues) { | ||
| super.updated(changedProperties); | ||
| const isOpen = Boolean(this.controller.props?.open); | ||
| if (this.dialogElement) { | ||
| if (isOpen && !this.dialogElement.open) { | ||
| this.dialogElement.showModal(); | ||
| } else if (!isOpen && this.dialogElement.open) { | ||
| this.dialogElement.close(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private handleNativeClose() { | ||
| this.closeDialog(); | ||
| } | ||
|
|
||
| private closeDialog() { | ||
| this.dispatchEvent( | ||
| new CustomEvent('a2uiclose', { | ||
| bubbles: true, | ||
| composed: true, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| override render() { | ||
| const props = this.controller.props; | ||
| if (!props) return nothing; | ||
|
|
||
| return html` | ||
| <dialog @close=${this.handleNativeClose}> | ||
| <div class="dialog-header"> | ||
| ${props.title ? html`<h3 class="dialog-title">${props.title}</h3>` : nothing} | ||
| <button class="close-btn" @click=${this.closeDialog}>×</button> | ||
| </div> | ||
| <div class="dialog-body"> | ||
| ${props.child ? html`${this.renderNode(props.child)}` : nothing} | ||
| </div> | ||
| </dialog> | ||
| `; | ||
| } | ||
| } | ||
|
|
||
| export const A2uiDialog = { | ||
| ...DialogApi, | ||
| tagName: 'a2ui-dialog', | ||
| }; | ||
99 changes: 99 additions & 0 deletions
99
renderers/lit/src/v0_9/catalogs/basic/components/Select.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* | ||
| * 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 {html, nothing, css} from 'lit'; | ||
| import {customElement} from 'lit/decorators.js'; | ||
| import {SelectApi} from '@a2ui/web_core/v0_9/basic_catalog'; | ||
| import {BasicCatalogA2uiLitElement} from '../basic-catalog-a2ui-lit-element.js'; | ||
| import {A2uiController} from '../../../a2ui-controller.js'; | ||
|
|
||
| @customElement('a2ui-select') | ||
| export class A2uiSelectElement extends BasicCatalogA2uiLitElement<typeof SelectApi> { | ||
| static override styles = css` | ||
| :host { | ||
| display: block; | ||
| margin: var(--a2ui-select-margin, var(--a2ui-spacing-m, 8px)); | ||
| font-family: inherit; | ||
| } | ||
| .a2ui-select-container { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--a2ui-spacing-xs, 4px); | ||
| } | ||
| label { | ||
| font-size: var(--a2ui-font-size-s, 0.875rem); | ||
| color: var(--a2ui-color-on-surface, #333); | ||
| font-weight: 500; | ||
| } | ||
| select { | ||
| padding: var(--a2ui-select-padding, 8px 12px); | ||
| border: var(--a2ui-border-width, 1px) solid var(--a2ui-color-border, #ccc); | ||
| border-radius: var(--a2ui-border-radius, 6px); | ||
| background-color: var(--a2ui-color-surface, #fff); | ||
| color: var(--a2ui-color-on-surface, #333); | ||
| font-size: var(--a2ui-font-size-m, 1rem); | ||
| cursor: pointer; | ||
| } | ||
| select:focus { | ||
| outline: 2px solid var(--a2ui-color-primary, #17e); | ||
| } | ||
| `; | ||
|
|
||
| protected createController() { | ||
| return new A2uiController(this, SelectApi); | ||
| } | ||
|
|
||
| private onChange(e: Event) { | ||
| const target = e.target as HTMLSelectElement; | ||
| const props = this.controller.props; | ||
| if (props) { | ||
| props.setValue?.(target.value); | ||
| } | ||
| // Dispatch custom event for binding update | ||
| this.dispatchEvent( | ||
| new CustomEvent('a2uichange', { | ||
| detail: {value: target.value}, | ||
| bubbles: true, | ||
| composed: true, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| override render() { | ||
| const props = this.controller.props; | ||
| if (!props) return nothing; | ||
|
|
||
| const options = props.options || []; | ||
|
|
||
| return html` | ||
| <div class="a2ui-select-container"> | ||
| ${props.label ? html`<label>${props.label}</label>` : nothing} | ||
| <select .value=${props.value || ''} @change=${this.onChange}> | ||
| ${options.map( | ||
| (opt) => html`<option value=${opt.value} ?selected=${opt.value === props.value}> | ||
| ${opt.label} | ||
| </option>`, | ||
| )} | ||
| </select> | ||
| </div> | ||
| `; | ||
| } | ||
| } | ||
|
|
||
| export const A2uiSelect = { | ||
| ...SelectApi, | ||
| tagName: 'a2ui-select', | ||
| }; |
124 changes: 124 additions & 0 deletions
124
renderers/lit/src/v0_9/catalogs/basic/components/Switch.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| * 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 {html, nothing, css} from 'lit'; | ||
| import {customElement} from 'lit/decorators.js'; | ||
| import {SwitchApi} from '@a2ui/web_core/v0_9/basic_catalog'; | ||
| import {BasicCatalogA2uiLitElement} from '../basic-catalog-a2ui-lit-element.js'; | ||
| import {A2uiController} from '../../../a2ui-controller.js'; | ||
|
|
||
| @customElement('a2ui-switch') | ||
| export class A2uiSwitchElement extends BasicCatalogA2uiLitElement<typeof SwitchApi> { | ||
| static override styles = css` | ||
| :host { | ||
| display: inline-block; | ||
| margin: var(--a2ui-switch-margin, var(--a2ui-spacing-m, 8px)); | ||
| font-family: inherit; | ||
| } | ||
| .a2ui-switch-wrapper { | ||
| display: inline-flex; | ||
| align-items: center; | ||
| gap: var(--a2ui-spacing-s, 8px); | ||
| cursor: pointer; | ||
| } | ||
| .switch { | ||
| position: relative; | ||
| display: inline-block; | ||
| width: 44px; | ||
| height: 24px; | ||
| } | ||
| .switch input { | ||
| opacity: 0; | ||
| width: 0; | ||
| height: 0; | ||
| } | ||
| .slider { | ||
| position: absolute; | ||
| cursor: pointer; | ||
| top: 0; | ||
| left: 0; | ||
| right: 0; | ||
| bottom: 0; | ||
| background-color: var(--a2ui-switch-off-bg, #ccc); | ||
| transition: 0.3s; | ||
| border-radius: 24px; | ||
| } | ||
| .slider:before { | ||
| position: absolute; | ||
| content: ''; | ||
| height: 18px; | ||
| width: 18px; | ||
| left: 3px; | ||
| bottom: 3px; | ||
| background-color: white; | ||
| transition: 0.3s; | ||
| border-radius: 50%; | ||
| } | ||
| input:checked + .slider { | ||
| background-color: var(--a2ui-color-primary, #17e); | ||
| } | ||
| input:checked + .slider:before { | ||
| transform: translateX(20px); | ||
| } | ||
| .label-text { | ||
| font-size: var(--a2ui-font-size-m, 1rem); | ||
| color: var(--a2ui-color-on-surface, #333); | ||
| } | ||
| `; | ||
|
|
||
| protected createController() { | ||
| return new A2uiController(this, SwitchApi); | ||
| } | ||
|
|
||
| private onChange(e: Event) { | ||
| const target = e.target as HTMLInputElement; | ||
| const props = this.controller.props; | ||
| if (props) { | ||
| props.setValue?.(target.checked); | ||
| } | ||
| this.dispatchEvent( | ||
| new CustomEvent('a2uichange', { | ||
| detail: {value: target.checked}, | ||
| bubbles: true, | ||
| composed: true, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| override render() { | ||
| const props = this.controller.props; | ||
| if (!props) return nothing; | ||
|
|
||
| return html` | ||
| <label class="a2ui-switch-wrapper"> | ||
| <span class="switch"> | ||
| <input | ||
| type="checkbox" | ||
| .checked=${Boolean(props.value)} | ||
| @change=${this.onChange} | ||
| /> | ||
| <span class="slider"></span> | ||
| </span> | ||
| ${props.label ? html`<span class="label-text">${props.label}</span>` : nothing} | ||
| </label> | ||
| `; | ||
| } | ||
| } | ||
|
|
||
| export const A2uiSwitch = { | ||
| ...SwitchApi, | ||
| tagName: 'a2ui-switch', | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
dialog::backdroppseudo-element is only rendered by browsers when the dialog is opened using the native.showModal()method. Since this component renders<dialog open>declaratively, the native backdrop will not be displayed. Consider rendering a custom backdrop element in the template or managing the dialog opening/closing imperatively using.showModal()and.close()in the Lit lifecycle.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.
Done. Managed open/close imperatively using showModal() and close() in updated lifecycle to ensure native backdrop rendering.