// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as Lit from '../lit/lit.js';
import * as VisualLogging from '../visual_logging/visual_logging.js';
import {UIUtils} from './legacy.js';
const {html} = Lit;
export function render(container: HTMLElement) {
function createDivWithP(text: string): HTMLDivElement {
const div = document.createElement('div');
div.style.paddingLeft = '25px';
const p = document.createElement('p');
p.style.marginLeft = '-25px';
p.textContent = text;
div.appendChild(p);
container.appendChild(div);
return div;
}
function onChange(event: Event): void {
const menu = event.target;
if (menu instanceof HTMLSelectElement) {
console.log('Option selected: ', menu.value);
}
}
{
const simpleMenuHTML = createDivWithP('Simple item select with lit-html');
Lit.render(
html``,
simpleMenuHTML);
}
{
const disabledMenuHTML = createDivWithP('Disabled select with lit-html');
// clang-format off
Lit.render(
html``,
disabledMenuHTML);
// clang-format on
}
{
const groupMenuHTML = createDivWithP('Select with groups with lit-html');
Lit.render(
html``,
groupMenuHTML);
}
{
const simpleMenuImperative = createDivWithP('Simple item select with imperative API');
const simpleSelect = UIUtils.createSelect('Select an option', [
'Option 1',
'Option 2',
'Option 3',
]);
simpleSelect.addEventListener('change', event => onChange(event));
simpleMenuImperative.appendChild(simpleSelect);
}
{
const groupMenuImperative = createDivWithP('Select with groups with imperative API');
const group1 = new Map([['Group 1', ['Option 1']]]);
const group2 = new Map([['Group 2', ['Option 2', 'Option 3']]]);
const groupSelect = UIUtils.createSelect('Select an option', [group1, group2]);
groupSelect.addEventListener('change', event => onChange(event));
groupMenuImperative.appendChild(groupSelect);
}
}