Каркас админки расставляет части экрана и больше ничего не делает: данных он
не спрашивает. Его задача — чтобы полоса сообщений, меню и голова страницы
стояли на своих местах на любом экране, а содержимое прокручивалось вместе
с документом.
Места каркаса
У каркаса четыре именованных места и содержимое:
bar — полоса сообщений над всем экраном (sf-alert-bar);
menu — меню администратора (sf-admin-menu);
head — голова страницы (sf-header-page) со строкой пути;
top-end — конец тонкой верхней строки телефона: туда ставят второй
индикатор фоновых действий;
всё без slot — содержимое страницы, ориентир main.
Места каркаса на широком экране
flowchart TB
bar["bar — полоса сообщений"]
subgraph row[" "]
direction LR
menu["menu — меню"]
subgraph work["рабочая область"]
head["head — голова страницы"]
main["содержимое (main)"]
end
end
bar --> row
/* An example frame takes the height of its content, so a part as tall as the
window (100dvh) would make it grow without end. In this box the box is the
window: the frame is as tall as the box, the menu column too. On a page of
your own none of this is needed. */
.page-screen { block-size: var(--sf-g6); overflow: auto; }
.page-screen sf-admin-shell .sf-admin-shell { min-block-size: 100%; }
.page-screen sf-admin-shell .sf-admin-shell__nav { block-size: calc(var(--sf-g6) - var(--sf-admin-shell-stick, 0px)); }
.page-rows { display: flex; flex-direction: column; gap: var(--sf-space-1); }
.page-filler { block-size: var(--sf-g4); }
JavaScript
// The frame with the bar, the menu over the demo host, the page head and the
// content. On a phone width the menu goes behind the button of the top line.
AdminDemo.serve(AdminDemo.host({current: 'srv.dns'}));
const shell = document.querySelector('#shell');
shell.addEventListener('sf-admin-shell-menu-open', () => AdminDemo.log('Меню открыто'));
shell.addEventListener('sf-admin-shell-menu-close', (event) => AdminDemo.log(`Меню закрыто: ${event.detail?.reason ?? ''}`));
The example's events appear here
Каркас со всеми местами
Прокрутка документа
Прокручивается сам документ, а не внутренняя область каркаса. Полоса
сообщений, меню и на телефоне верхняя строка остаются на месте. Высоту того,
что прилипло сверху, каркас пишет в переменную --sf-admin-shell-stick:
по ней странице удобно прилеплять свои части — например, панель массовых
действий таблицы — сразу под каркасом.
Атрибут width задаёт ширину содержимого: list — вся рабочая область,
для таблиц и списков; read — ширина чтения у начала области, для форм и
текста.
Страница настроек на ширине чтения
HTML
<script src="assets/admin-demo.js"></script>
<div class="page-screen">
<sf-admin-shell product="Larena Panel" width="read">
<sf-admin-menu slot="menu" aria-label="Меню" expected-columns="2" current="panel.general"></sf-admin-menu>
<sf-header-page slot="head" heading="Общие настройки"></sf-header-page>
<section class="page-section" aria-labelledby="address">
<h2 id="address" class="page-section-title">Адрес панели</h2>
<sf-input size="1" label="Адрес" default-value="panel.larena.cloud"></sf-input>
<sf-input size="1" label="Порт" default-value="9443" hint="Число от 1 до 65535"></sf-input>
</section>
<section class="page-section" aria-labelledby="signin">
<h2 id="signin" class="page-section-title">Вход</h2>
<sf-switch label="Двухфакторный код для всех администраторов" checked></sf-switch>
<sf-switch label="Предупреждать за 2 минуты до конца сессии"></sf-switch>
</section>
<div class="page-save"><sf-button text="Сохранить"></sf-button></div>
</sf-admin-shell>
</div>
CSS
/* An example frame takes the height of its content, so a part as tall as the
window (100dvh) would make it grow without end. In this box the box is the
window: the frame is as tall as the box, the menu column too. On a page of
your own none of this is needed. */
.page-screen { block-size: var(--sf-g6); overflow: auto; }
.page-screen sf-admin-shell .sf-admin-shell { min-block-size: 100%; }
.page-screen sf-admin-shell .sf-admin-shell__nav { block-size: calc(var(--sf-g6) - var(--sf-admin-shell-stick, 0px)); }
.page-section { display: flex; flex-direction: column; gap: var(--sf-space-1); margin-block-end: var(--sf-space-2); }
.page-section-title { margin: 0; font-size: var(--sf-text-size-1); line-height: var(--sf-text-height-1); font-weight: var(--sf-font-weight-medium); }
.page-save { display: flex; gap: var(--sf-space-1); }
JavaScript
// A settings page: the frame at the reading width (width="read").
AdminDemo.serve(AdminDemo.host({current: 'panel.general'}));
Страница настроек на ширине чтения
Телефон
Уже 44rem меню прячется, а сверху остаётся тонкая строка с кнопкой меню,
названием продукта (product) и местом top-end. Кнопка открывает меню на
месте рабочей области; Escape, выбор страницы в меню или расширение окна
закрывают его, и фокус возвращается на кнопку. Открыть и закрыть меню из
кода — действия open-menu и close-menu.
Страница без меню
menu-reserve="none" не держит места под меню: так выглядят мастер
установки или страница ошибки внутри админки.
Каркас без меню
HTML
<div class="page-screen">
<sf-admin-shell product="Larena Panel" menu-reserve="none">
<sf-header-page slot="head" heading="Мастер установки"></sf-header-page>
<p class="m-0">Каркас без меню: содержимое во всю ширину, ссылка к содержимому и голова страницы остаются.</p>
</sf-admin-shell>
</div>
CSS
/* An example frame takes the height of its content, so a part as tall as the
window (100dvh) would make it grow without end. In this box the box is the
window: the frame is as tall as the box, the menu column too. On a page of
your own none of this is needed. */
.page-screen { block-size: var(--sf-f6); overflow: auto; }
.page-screen sf-admin-shell .sf-admin-shell { min-block-size: 100%; }
.page-screen sf-admin-shell .sf-admin-shell__nav { block-size: calc(var(--sf-f6) - var(--sf-admin-shell-stick, 0px)); }