CORE/CONTENT test5593 и адаптация UI

This commit is contained in:
AidarKC
2026-11-27 00:47:13 +03:00
parent 205b7ad971
commit 873535654e
1271 changed files with 219621 additions and 1900 deletions
@@ -0,0 +1,108 @@
// Строка человека в списках (связи, поиск людей, списки профиля): аватар, имя, строка под
// ним и действия справа. Вид совпадает со строками списка чатов.
import { renderUserAvatar } from './avatar-image.js';
import { iconHtml } from './ui-icon.js';
import { createSpinner } from './feedback.js';
/**
* @param {Object} opts
* @param {string} opts.login
* @param {string} [opts.name] – как показывать (по умолчанию логин)
* @param {string} [opts.firstName] [opts.lastName] – для инициалов
* @param {Object|null} [opts.avatar]
* @param {string} [opts.sub] – строка под именем
* @param {string} [opts.note] – личная заметка (третья строка, курсивом)
* @param {string} [opts.markColor] – метка заметки: green/yellow/red/blue/violet, 'note' – без цвета, '' – нет
* @param {'close'|'shining'|''} [opts.ring] – цветное кольцо вокруг аватара
* @param {boolean} [opts.official]
* @param {string} [opts.tag] – короткая пометка цветом в начале второй строки («ждёт ответа»)
* @param {Function} [opts.onClick]
* @param {Array<{icon:string,label:string,onClick:Function,primary?:boolean,busy?:boolean}>} [opts.actions]
* primary – главное действие строки (цветом), busy – идёт сохранение (спиннер, кнопка неактивна)
*/
export function createPersonRow({
login, name = '', firstName = '', lastName = '', avatar = null, sub = '', note = '', markColor = '',
ring = '', official = false, tag = '', onClick = null, actions = [],
} = {}) {
const row = document.createElement('div');
row.className = `person-row${ring ? ` person-row--${ring}` : ''}`;
row.dataset.login = String(login || '');
const main = document.createElement('button');
main.type = 'button';
main.className = 'person-row__main';
const avatarWrap = document.createElement('span');
avatarWrap.className = 'person-row__avatar';
// Имя и фамилию отдельно знают не все источники (поиск по сети отдаёт одно «displayName») –
// тогда инициалы берутся из показанного имени, а не из логина.
const nameParts = name && name !== login ? String(name).trim().split(/\s+/) : [];
const initialsFirst = firstName || nameParts[0] || '';
const initialsLast = lastName || (nameParts.length > 1 ? nameParts[nameParts.length - 1] : '');
avatarWrap.append(renderUserAvatar({ login, firstName: initialsFirst, lastName: initialsLast, avatar, size: 'md', official }));
if (markColor) {
// Метка заметки – та же цветная точка, что на карте связей; 'note' – заметка без цвета.
const mark = document.createElement('span');
mark.className = 'person-row__mark';
mark.dataset.mark = markColor;
mark.setAttribute('aria-hidden', 'true');
avatarWrap.append(mark);
}
const text = document.createElement('span');
text.className = 'person-row__text';
const title = document.createElement('span');
title.className = 'person-row__name';
const titleText = document.createElement('span');
titleText.className = 'person-row__name-text';
titleText.textContent = name || login;
title.append(titleText);
text.append(title);
if (sub || tag) {
// Пометка («ждёт ответа») – в начале второй строки, чтобы не съедать место у имени.
const subEl = document.createElement('span');
subEl.className = 'person-row__sub';
if (tag) {
const tagEl = document.createElement('span');
tagEl.className = 'person-row__tag';
tagEl.textContent = tag;
subEl.append(tagEl);
if (sub) subEl.append(' · ');
}
if (sub) subEl.append(sub);
text.append(subEl);
}
if (note) {
const noteEl = document.createElement('span');
noteEl.className = 'person-row__note';
noteEl.textContent = note;
text.append(noteEl);
}
main.append(avatarWrap, text);
if (typeof onClick === 'function') main.addEventListener('click', onClick);
row.append(main);
for (const action of actions) {
if (!action) continue;
const button = document.createElement('button');
button.type = 'button';
button.className = `icon-btn person-row__action${action.primary ? ' person-row__action--primary' : ''}`;
if (action.busy) {
button.disabled = true;
button.append(createSpinner({ size: 'sm', label: action.label }));
} else {
button.innerHTML = iconHtml(action.icon);
}
button.setAttribute('aria-label', action.label);
button.title = action.label;
button.addEventListener('click', (event) => action.onClick?.(event, button));
row.append(button);
}
return row;
}
// Заголовок группы в списке («Друзья · 58», «А»).
export function createListSection(text) {
const el = document.createElement('div');
el.className = 'person-list-section';
el.textContent = text;
return el;
}