SHA256
Исправить мелкие баги дизайна UI
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { createDropdownMenu } from './dropdown-menu.js';
|
||||
import { iconHtml } from './ui-icon.js';
|
||||
|
||||
/** Заголовок-переключатель для списков; не создаёт собственный TopBar или меню. */
|
||||
export function createTopBarFilterTitle({ section, choices, value, onSelect, minWidth = 210 } = {}) {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'topbar-filter-title';
|
||||
button.title = `Выбрать раздел «${section}»`;
|
||||
|
||||
const caption = document.createElement('span');
|
||||
caption.className = 'topbar-filter-title__caption';
|
||||
const chevron = document.createElement('span');
|
||||
chevron.className = 'topbar-filter-title__chevron';
|
||||
chevron.setAttribute('aria-hidden', 'true');
|
||||
chevron.innerHTML = iconHtml('chevron-down');
|
||||
button.append(caption, chevron);
|
||||
|
||||
let selected = value;
|
||||
const setValue = (nextValue) => {
|
||||
selected = nextValue;
|
||||
const label = choices.find(([key]) => key === selected)?.[1] || '';
|
||||
caption.textContent = `${section}: ${label}`;
|
||||
button.setAttribute('aria-label', `${section}: ${label}. Выбрать раздел`);
|
||||
};
|
||||
setValue(value);
|
||||
|
||||
const menu = createDropdownMenu({
|
||||
anchorEl: button,
|
||||
placement: 'bottom-start',
|
||||
minWidth,
|
||||
transparent: true,
|
||||
items: () => choices.map(([key, label]) => ({
|
||||
label,
|
||||
selected: key === selected,
|
||||
action: () => onSelect?.(key),
|
||||
})),
|
||||
});
|
||||
|
||||
return { element: button, setValue, close: () => menu.close(), destroy: () => menu.destroy() };
|
||||
}
|
||||
Reference in New Issue
Block a user