kitbash Sign in Connect agent
Components

Daylight readout

A thin rule with a sun or moon riding along it by the local hour, uppercase readouts on both ends and a [LIGHT] switch that turns the band pale.

Part of the style

Lights-Out Pill Index

7 parts that belong together, with their tokens, type and rules.

Preview

Code
<style>
/* Goes after the pack's base.css */
:root {
  --paper: #251a1a;
  --paper-raised: #291e1e;
  --tile: #302525;
  --veil: rgba(37, 26, 26, 0.76);
  --ink: #fbf4ee;
  --ink-soft: rgba(245, 238, 232, 0.58);
  --line: rgba(245, 238, 232, 0.14);
  --line-strong: rgba(245, 238, 232, 0.32);
  --pill-fill: rgba(245, 238, 232, 0.1);
  --day-paper: #f6eee8;
  --day-ink: #251a1a;
  --glow-a: #87645e;
  --glow-b: #866d69;
}
</style>

<section class="daylight" data-sunrise="7" data-sunset="19" aria-label="Studio daylight">
  <div class="daylight__bar">
    <p class="daylight__local">LOCAL / <time class="daylight__clock">00:00</time> <span class="daylight__zone">UTC</span></p>
    <div class="daylight__rail" aria-hidden="true">
      <span class="daylight__line"></span>
      <span class="daylight__body">
        <svg class="daylight__moon" viewBox="0 0 16 16" width="14" height="14"><path d="M10.6 1.4a6.6 6.6 0 1 0 4 10.1A5.6 5.6 0 0 1 10.6 1.4Z" fill="none" stroke="currentColor" stroke-width="1.2"/></svg>
        <svg class="daylight__sun" viewBox="0 0 16 16" width="14" height="14"><circle cx="8" cy="8" r="3.2" fill="none" stroke="currentColor" stroke-width="1.2"/><path d="M8 0.8v2M8 13.2v2M0.8 8h2M13.2 8h2M2.9 2.9l1.4 1.4M11.7 11.7l1.4 1.4M2.9 13.1l1.4-1.4M11.7 4.3l1.4-1.4" stroke="currentColor" stroke-width="1.2"/></svg>
      </span>
    </div>
    <p class="daylight__next">LIGHT AT 07:00 · IN 00H 00M</p>
    <button class="daylight__switch" type="button" aria-pressed="false">[LIGHT]</button>
  </div>
  <div class="daylight__row">
    <p class="daylight__label">INDEX / 01 / SELECTED WORK</p>
    <a class="daylight__more" href="#">Journal</a>
  </div>
</section>

<style>
  .daylight {
    --day-bg: var(--paper);
    --day-fg: var(--ink);
    padding: var(--space-xl) var(--edge);
    background: var(--day-bg);
    color: var(--day-fg);
    transition: background-color var(--theme) ease, color var(--theme) ease;
  }
  .daylight.is-light {
    --day-bg: var(--day-paper);
    --day-fg: var(--day-ink);
  }
  .daylight__bar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: var(--space-l);
  }
  .daylight__local,
  .daylight__next,
  .daylight__label {
    margin: 0;
    font-size: var(--text-xs);
    line-height: 1;
    letter-spacing: var(--track-caps);
    opacity: 0.58;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  .daylight__rail {
    position: relative;
    height: 16px;
  }
  .daylight__line {
    position: absolute;
    inset: 50% 0 auto;
    height: var(--rule);
    background: currentColor;
    opacity: 0.18;
  }
  .daylight__body {
    position: absolute;
    top: 50%;
    left: var(--at, 50%);
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    translate: -50% -50%;
    background: var(--day-bg);
    color: currentColor;
    opacity: 0.7;
    transition: left var(--move) var(--ease), background-color var(--theme) ease;
  }
  .daylight__moon,
  .daylight__sun {
    grid-area: 1 / 1;
    transition: opacity var(--quick) var(--ease);
  }
  .daylight__sun { opacity: 0; }
  .daylight.is-day .daylight__sun { opacity: 1; }
  .daylight.is-day .daylight__moon { opacity: 0; }
  .daylight__switch {
    min-height: var(--tap);
    margin: calc((var(--tap) - 12px) / -2) 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: 400 var(--text-xs) / 1 var(--font-body);
    letter-spacing: var(--track-caps);
    opacity: 0.58;
    cursor: pointer;
    transition: opacity var(--quick) var(--ease);
  }
  .daylight__switch:hover,
  .daylight__switch:focus-visible {
    opacity: 1;
    outline: none;
    text-decoration: underline;
  }
  .daylight__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-m);
    margin-top: var(--space-xl);
  }
  .daylight__more {
    position: relative;
    z-index: 0;
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding: 0 22px;
    color: inherit;
    font-size: var(--text-s);
    text-decoration: none;
  }
  .daylight__more::before {
    content: "";
    position: absolute;
    inset: calc((var(--tap) - var(--pill-h)) / 2) 0;
    z-index: -1;
    border: var(--rule) solid currentColor;
    border-radius: var(--radius-pill);
    opacity: 0.3;
    transition: opacity var(--quick) var(--ease);
  }
  .daylight__more:hover::before,
  .daylight__more:focus-visible::before {
    opacity: 0.7;
  }
  .daylight__more:focus-visible { outline: none; }

  @media (max-width: 720px) {
    .daylight__bar {
      grid-template-columns: 1fr auto;
      gap: var(--space-m) var(--space-m);
    }
    .daylight__rail {
      grid-column: 1 / -1;
      grid-row: 2;
    }
    .daylight__next { grid-row: 3; }
    .daylight__switch { grid-row: 1; grid-column: 2; }
    .daylight__row { margin-top: var(--space-l); }
  }
</style>

<script>
(() => {
  const pad = (n) => String(n).padStart(2, '0');
  for (const root of document.querySelectorAll('.daylight')) {
    const rise = Number(root.dataset.sunrise);
    const set = Number(root.dataset.sunset);
    const clock = root.querySelector('.daylight__clock');
    const zone = root.querySelector('.daylight__zone');
    const next = root.querySelector('.daylight__next');
    const body = root.querySelector('.daylight__body');
    const button = root.querySelector('.daylight__switch');
    const offset = -new Date().getTimezoneOffset() / 60;
    zone.textContent = 'UTC' + (offset >= 0 ? '+' : '') + offset;
    const tick = () => {
      const now = new Date();
      const hours = now.getHours() + now.getMinutes() / 60;
      const day = hours >= rise && hours < set;
      const target = day ? set : rise;
      const left = (target - hours + 24) % 24;
      clock.textContent = pad(now.getHours()) + ':' + pad(now.getMinutes());
      next.textContent = (day ? 'DARK AT ' : 'LIGHT AT ') + pad(target) + ':00 · IN ' +
        pad(Math.floor(left)) + 'H ' + pad(Math.floor((left % 1) * 60)) + 'M';
      root.classList.toggle('is-day', day);
      body.style.setProperty('--at', (hours / 24 * 100).toFixed(2) + '%');
    };
    let timer = 0;
    const seen = new IntersectionObserver(([entry]) => {
      clearInterval(timer);
      if (entry.isIntersecting) { tick(); timer = setInterval(tick, 30000); }
    });
    seen.observe(root);
    tick();
    button.addEventListener('click', () => {
      const light = root.classList.toggle('is-light');
      button.setAttribute('aria-pressed', String(light));
      button.textContent = light ? '[DARK]' : '[LIGHT]';
    });
  }
})();
</script>

Similar components

Usage calculator

Usage calculator

Collections

Collections

Service cells

Service cells

Sound notice

Sound notice

Dot-grid crafts

Dot-grid crafts

Lift Panel Floors

Lift Panel Floors

Type tester

Type tester

Instrument panel

Instrument panel