food logger context tips
This commit is contained in:
@@ -26,12 +26,38 @@ body[data-theme="dark"]{--food-surface:#202923;--food-border:#3b473f;--food-ink:
|
||||
.food-macro p,.food-product-list small{color:var(--food-muted)}
|
||||
body[data-theme="dark"] .food-tabs a[aria-current=page]{color:#102317}
|
||||
|
||||
/* Keep the three macro summaries on one compact row on phones. */
|
||||
/* Four goals fit the existing nutrition sidebar in a compact two-column grid. */
|
||||
.food-macros{grid-template-columns:repeat(2,minmax(0,1fr));gap:.45rem}
|
||||
.food-macro{display:flex;flex-direction:column;align-items:center;gap:.25rem;min-width:0;margin:0;padding:.7rem .3rem;text-align:center}
|
||||
.food-ring{width:54px;height:54px;margin:0}
|
||||
.food-ring span{width:42px;height:42px;font-size:.75rem}
|
||||
.food-macro h3{font-size:.82rem;line-height:1.15;margin:0;white-space:nowrap}
|
||||
.food-macro p{font-size:.72rem;line-height:1.2;margin:.1rem 0;overflow-wrap:anywhere}
|
||||
.food-macro--green{--accent:var(--food-green)}
|
||||
|
||||
/* Keep the four nutrition goals readable on phones. */
|
||||
@media(max-width:760px){
|
||||
.food-macros{grid-template-columns:repeat(3,minmax(0,1fr));gap:.4rem}
|
||||
.food-macro{display:flex;flex-direction:column;align-items:center;gap:.35rem;min-width:0;padding:.55rem .25rem;text-align:center}
|
||||
.food-ring{width:48px;height:48px;margin:0}
|
||||
.food-ring span{width:38px;height:38px;font-size:.7rem}
|
||||
.food-macro h3{font-size:.8rem;line-height:1.15;margin:0;overflow-wrap:anywhere}
|
||||
.food-macro p{font-size:.7rem;line-height:1.2;margin:.1rem 0;overflow-wrap:anywhere}
|
||||
.food-macros{grid-template-columns:repeat(2,minmax(0,1fr));gap:.45rem}
|
||||
.food-macro{display:flex;flex-direction:column;align-items:center;gap:.25rem;min-width:0;padding:.7rem .3rem;text-align:center}
|
||||
.food-ring{width:54px;height:54px;margin:0}
|
||||
.food-ring span{width:42px;height:42px;font-size:.75rem}
|
||||
.food-macro h3{font-size:.82rem;line-height:1.15;margin:0;white-space:nowrap}
|
||||
.food-macro p{font-size:.72rem;line-height:1.2;margin:.1rem 0;overflow-wrap:anywhere}
|
||||
}
|
||||
|
||||
/* Nutrient guidance sits above the card content and stays within the viewport. */
|
||||
.food-macro{position:relative;padding-top:2.8rem}
|
||||
.food-help-trigger{position:absolute;top:.25rem;right:.25rem;display:grid;place-items:center;width:44px;height:44px;padding:0;border:0;background:transparent;color:var(--food-ink);cursor:pointer}
|
||||
.food-help-trigger span{display:grid;place-items:center;width:24px;height:24px;border:1px solid var(--food-muted);border-radius:50%;font:700 .85rem/1 inherit}
|
||||
.food-help-trigger:hover span,.food-help-trigger[aria-expanded="true"] span{background:var(--food-progress-track)}
|
||||
.food-help-trigger:focus-visible,.food-help-close:focus-visible{outline:2px solid var(--food-green);outline-offset:2px;border-radius:.4rem}
|
||||
.food-help-popover{position:fixed;z-index:100;width:min(320px,calc(100vw - 24px));max-height:calc(100dvh - 24px);overflow:auto;padding:1rem;text-align:left;background:var(--food-surface);color:var(--food-ink);border:1px solid var(--food-border);border-radius:1rem;box-shadow:0 12px 32px #0008;font-size:.9rem;line-height:1.4}
|
||||
.food-help-popover[hidden]{display:none}
|
||||
.food-help-heading{display:flex;align-items:center;justify-content:space-between;gap:1rem}
|
||||
.food-help-heading h4{margin:0;font-size:1.05rem}
|
||||
.food-help-close{display:grid;place-items:center;flex:none;width:44px;height:44px;padding:0;border:0;background:transparent;color:var(--food-ink);font-size:1.5rem;cursor:pointer}
|
||||
.food-help-popover p{margin:.45rem 0 .75rem;color:var(--food-ink)}
|
||||
.food-help-popover ul{margin:.4rem 0;padding-left:1.25rem}
|
||||
.food-help-popover li{margin:.25rem 0}
|
||||
.food-help-popover .food-help-tip{margin-top:.75rem;color:var(--food-muted)}
|
||||
@media(max-width:600px){.food-help-popover{top:auto!important;left:12px!important;right:12px;bottom:max(12px,env(safe-area-inset-bottom));width:auto;max-height:min(70dvh,560px)}}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
(() => {
|
||||
let active = null;
|
||||
|
||||
function close(restoreFocus = false) {
|
||||
if (!active) return;
|
||||
const { trigger, popover } = active;
|
||||
popover.hidden = true;
|
||||
trigger.setAttribute('aria-expanded', 'false');
|
||||
active = null;
|
||||
if (restoreFocus && trigger.isConnected) trigger.focus();
|
||||
}
|
||||
|
||||
function position(trigger, popover) {
|
||||
if (window.matchMedia('(max-width: 600px)').matches) {
|
||||
popover.style.left = '';
|
||||
popover.style.top = '';
|
||||
return;
|
||||
}
|
||||
const rect = trigger.getBoundingClientRect();
|
||||
const width = popover.getBoundingClientRect().width;
|
||||
const left = Math.max(12, Math.min(rect.right - width, window.innerWidth - width - 12));
|
||||
const below = rect.bottom + 8;
|
||||
const height = popover.getBoundingClientRect().height;
|
||||
const top = below + height <= window.innerHeight - 12
|
||||
? below : Math.max(12, rect.top - height - 8);
|
||||
popover.style.left = `${left}px`;
|
||||
popover.style.top = `${top}px`;
|
||||
}
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const trigger = event.target.closest('[data-food-help-trigger]');
|
||||
if (trigger) {
|
||||
if (active?.trigger === trigger) { close(); return; }
|
||||
close();
|
||||
const popover = document.getElementById(trigger.getAttribute('aria-controls'));
|
||||
if (!popover) return;
|
||||
popover.hidden = false;
|
||||
trigger.setAttribute('aria-expanded', 'true');
|
||||
active = { trigger, popover };
|
||||
position(trigger, popover);
|
||||
popover.querySelector('[data-food-help-close]').focus();
|
||||
return;
|
||||
}
|
||||
if (event.target.closest('[data-food-help-close]')) { close(true); return; }
|
||||
if (active && !active.popover.contains(event.target)) close();
|
||||
});
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Escape' && active) { event.preventDefault(); close(true); }
|
||||
});
|
||||
window.addEventListener('resize', () => {
|
||||
if (active) position(active.trigger, active.popover);
|
||||
});
|
||||
document.addEventListener('htmx:beforeSwap', () => close());
|
||||
})();
|
||||
Reference in New Issue
Block a user