feat: add kitchen-tabs utility, CSS, token and test
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/* Modul: Kitchen Tabs Bar
|
||||
* Sticky Segment-Control für Mahlzeiten/Rezepte/Einkauf + Sub-Modul Layout-Fixes
|
||||
*/
|
||||
|
||||
.kitchen-tabs-bar {
|
||||
display: flex;
|
||||
gap: var(--space-1);
|
||||
padding: var(--space-2) var(--space-4);
|
||||
height: var(--kitchen-tabs-height);
|
||||
box-sizing: border-box;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: var(--z-sticky);
|
||||
background-color: var(--color-bg);
|
||||
border-bottom: 1px solid var(--color-border-subtle);
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.kitchen-tabs-bar::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.kitchen-tab {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
padding: 0 var(--space-3);
|
||||
height: 36px;
|
||||
border-radius: var(--radius-full);
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--color-text-secondary);
|
||||
font-family: inherit;
|
||||
font-size: var(--text-sm);
|
||||
font-weight: var(--font-weight-medium);
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
transition: background-color var(--transition-fast), color var(--transition-fast);
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
.kitchen-tab:active {
|
||||
transform: scale(0.96);
|
||||
transition-duration: 0.06s;
|
||||
}
|
||||
|
||||
.kitchen-tab--active {
|
||||
background-color: color-mix(in srgb, var(--active-module-accent, var(--color-accent)) 14%, transparent);
|
||||
color: var(--active-module-accent, var(--color-accent));
|
||||
}
|
||||
|
||||
.kitchen-tab__icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.kitchen-tab__label {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* Mahlzeiten: sticky day-header unterhalb der Tab-Leiste */
|
||||
.has-kitchen-tabs .day-header {
|
||||
top: var(--kitchen-tabs-height);
|
||||
}
|
||||
|
||||
/* Einkauf: Viewport-Höhe um Tab-Leiste reduzieren (Mobile) */
|
||||
.has-kitchen-tabs .shopping-page {
|
||||
height: calc(
|
||||
100dvh
|
||||
- var(--nav-bottom-height)
|
||||
- var(--safe-area-inset-bottom)
|
||||
- var(--kitchen-tabs-height)
|
||||
);
|
||||
}
|
||||
|
||||
/* Einkauf: Viewport-Höhe (Desktop) */
|
||||
@media (min-width: 1024px) {
|
||||
.has-kitchen-tabs .shopping-page {
|
||||
height: calc(100dvh - var(--kitchen-tabs-height));
|
||||
}
|
||||
}
|
||||
@@ -351,6 +351,7 @@
|
||||
--content-max-width: 1280px;
|
||||
--content-max-width-narrow: 720px;
|
||||
--cal-hour-height: 56px;
|
||||
--kitchen-tabs-height: 56px;
|
||||
|
||||
/* --------------------------------------------------------
|
||||
* 13. Sidebar
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { t } from '/i18n.js';
|
||||
|
||||
export const KITCHEN_ROUTES = ['/meals', '/recipes', '/shopping'];
|
||||
export const KITCHEN_STORAGE_KEY = 'oikos-kitchen-tab';
|
||||
|
||||
const TABS = () => [
|
||||
{ route: '/meals', labelKey: 'nav.meals', icon: 'utensils' },
|
||||
{ route: '/recipes', labelKey: 'nav.recipes', icon: 'book-text' },
|
||||
{ route: '/shopping', labelKey: 'nav.shopping', icon: 'shopping-cart' },
|
||||
];
|
||||
|
||||
export function getLastKitchenRoute() {
|
||||
try {
|
||||
const stored = sessionStorage.getItem(KITCHEN_STORAGE_KEY);
|
||||
return KITCHEN_ROUTES.includes(stored) ? stored : '/meals';
|
||||
} catch {
|
||||
return '/meals';
|
||||
}
|
||||
}
|
||||
|
||||
export function isKitchenRoute(path) {
|
||||
return KITCHEN_ROUTES.includes(path);
|
||||
}
|
||||
|
||||
export function renderKitchenTabsBar(container, activeRoute) {
|
||||
try {
|
||||
sessionStorage.setItem(KITCHEN_STORAGE_KEY, activeRoute);
|
||||
} catch { /* ignore */ }
|
||||
|
||||
container.classList.add('has-kitchen-tabs');
|
||||
|
||||
const bar = document.createElement('div');
|
||||
bar.className = 'kitchen-tabs-bar';
|
||||
bar.setAttribute('role', 'tablist');
|
||||
bar.setAttribute('aria-label', t('nav.kitchen'));
|
||||
|
||||
TABS().forEach(({ route, labelKey, icon }) => {
|
||||
const btn = document.createElement('button');
|
||||
btn.className = 'kitchen-tab' + (route === activeRoute ? ' kitchen-tab--active' : '');
|
||||
btn.dataset.route = route;
|
||||
btn.type = 'button';
|
||||
btn.setAttribute('role', 'tab');
|
||||
btn.setAttribute('aria-selected', route === activeRoute ? 'true' : 'false');
|
||||
|
||||
const i = document.createElement('i');
|
||||
i.dataset.lucide = icon;
|
||||
i.className = 'kitchen-tab__icon';
|
||||
i.setAttribute('aria-hidden', 'true');
|
||||
|
||||
const span = document.createElement('span');
|
||||
span.className = 'kitchen-tab__label';
|
||||
span.textContent = t(labelKey);
|
||||
|
||||
btn.appendChild(i);
|
||||
btn.appendChild(span);
|
||||
bar.appendChild(btn);
|
||||
});
|
||||
|
||||
bar.addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('[data-route]');
|
||||
if (!btn || btn.dataset.route === activeRoute) return;
|
||||
window.oikos?.navigate(btn.dataset.route);
|
||||
});
|
||||
|
||||
container.insertAdjacentElement('afterbegin', bar);
|
||||
|
||||
if (window.lucide) window.lucide.createIcons({ el: bar });
|
||||
}
|
||||
Reference in New Issue
Block a user