-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project import generated by Copybara
PiperOrigin-RevId: 721404516
- Loading branch information
1 parent
0bdfbf8
commit 739622b
Showing
6 changed files
with
261 additions
and
106 deletions.
There are no files selected for viewing
This file contains 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,115 @@ | ||
/** | ||
* Copyright 2025 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 | ||
* | ||
* http://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 '../ui-controls/config-section'; | ||
import '../ui-controls/configurator-checkbox'; | ||
import '../ui-controls/targeting-input'; | ||
|
||
import {localized} from '@lit/localize'; | ||
import {html, LitElement} from 'lit'; | ||
import {customElement, property, query, queryAll} from 'lit/decorators.js'; | ||
|
||
import { | ||
SamplePageConfig, | ||
SamplePrivacyConfig, | ||
} from '../../model/sample-config.js'; | ||
import { | ||
configNames, | ||
pageConfigNames, | ||
privacyConfigNames, | ||
} from '../../model/settings.js'; | ||
import {TargetingInput} from '../ui-controls/targeting-input.js'; | ||
|
||
/** | ||
* Page-level configurator settings. | ||
*/ | ||
@localized() | ||
@customElement('page-settings') | ||
export class PageSettings extends LitElement { | ||
@query('configurator-checkbox#sra') private sraInput!: HTMLInputElement; | ||
@queryAll('.privacy configurator-checkbox') | ||
private privacySettings!: HTMLInputElement[]; | ||
@query('targeting-input') private targetingInput!: TargetingInput; | ||
|
||
/** | ||
* Gets the active page-level configuration. | ||
*/ | ||
@property({attribute: 'config', type: Object}) config: SamplePageConfig = {}; | ||
|
||
private handleUpdate() { | ||
this.config.sra = this.sraInput.checked; | ||
|
||
this.config.privacy = this.config.privacy || {}; | ||
this.privacySettings.forEach(input => { | ||
this.config.privacy![input.id as keyof SamplePrivacyConfig] = | ||
input.checked; | ||
}); | ||
|
||
this.config.targeting = this.targetingInput.config; | ||
|
||
// Fire an event to let the configurator know a value has changed. | ||
this.dispatchEvent( | ||
new CustomEvent('update', {bubbles: true, composed: true}), | ||
); | ||
} | ||
|
||
private renderCheckbox(id: string, label: string, checked = false) { | ||
return html`<configurator-checkbox | ||
id="${id}" | ||
label="${label}" | ||
?checked="${checked}" | ||
@update="${this.handleUpdate}" | ||
></configurator-checkbox>`; | ||
} | ||
|
||
private renderGeneralSettings() { | ||
return this.renderCheckbox('sra', pageConfigNames.sra!(), this.config.sra); | ||
} | ||
|
||
private renderPrivacySettings() { | ||
const privacy = this.config.privacy || {}; | ||
return html`<config-section | ||
class="privacy" | ||
title="${pageConfigNames.privacy!()}" | ||
> | ||
${Object.keys(privacyConfigNames).map((setting: string) => { | ||
const key = setting as keyof SamplePrivacyConfig; | ||
return this.renderCheckbox( | ||
key, | ||
privacyConfigNames[key]!(), | ||
privacy[key], | ||
); | ||
})} | ||
</config-section>`; | ||
} | ||
|
||
private renderPageTargeting() { | ||
return html`<targeting-input | ||
class="page" | ||
title="${pageConfigNames.targeting!()}" | ||
.config="${this.config.targeting || []}" | ||
@update="${this.handleUpdate}" | ||
> | ||
</targeting-input>`; | ||
} | ||
|
||
render() { | ||
return html`<config-section title="${configNames.page!()}"> | ||
${this.renderGeneralSettings()} ${this.renderPrivacySettings()} | ||
${this.renderPageTargeting()} | ||
</config-section>`; | ||
} | ||
} |
This file contains 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 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,78 @@ | ||
/** | ||
* Copyright 2025 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 | ||
* | ||
* http://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 {localized} from '@lit/localize'; | ||
import {css, html, LitElement} from 'lit'; | ||
import {customElement, property} from 'lit/decorators.js'; | ||
import {ifDefined} from 'lit/directives/if-defined.js'; | ||
|
||
@localized() | ||
@customElement('configurator-checkbox') | ||
export class ConfiguratorCheckbox extends LitElement { | ||
static styles = css` | ||
:host { | ||
display: flex; | ||
width: 33%; | ||
min-width: 200px; | ||
} | ||
input[type='checkbox'] { | ||
align-self: flex-start; | ||
} | ||
`; | ||
|
||
/** | ||
* ID content attribute of the element. | ||
* | ||
* Will be automatically generated if not specified. | ||
*/ | ||
@property({type: String}) id = `checkbox-${Date.now().toString()}`; | ||
|
||
/** | ||
* User-friendly label for the element. | ||
*/ | ||
@property({type: String}) label?: string; | ||
|
||
/** | ||
* Name content attribute of the element. | ||
*/ | ||
@property({type: String}) name?: string; | ||
|
||
/** | ||
* Whether the checkbox is currently selected. | ||
*/ | ||
@property({type: Boolean}) checked = false; | ||
|
||
private handleClick(event: Event) { | ||
this.checked = (event.target as HTMLInputElement).checked; | ||
|
||
// Fire an event to let the configurator know a value has changed. | ||
this.dispatchEvent( | ||
new CustomEvent('update', {bubbles: true, composed: true}), | ||
); | ||
} | ||
|
||
render() { | ||
return html`<input | ||
type="checkbox" | ||
id="${this.id}" | ||
name="${ifDefined(this.name)}" | ||
?checked="${this.checked}" | ||
@click="${this.handleClick}" | ||
/> | ||
<label for="${this.id}">${this.label}</label>`; | ||
} | ||
} |
Oops, something went wrong.