kitbash Sign in Connect agent
Components

Question wheel

Questions sit on a vertical wheel: the centre one is sharp, the others blur and fade with distance. Arrow buttons, arrow keys or a click turn the wheel, and the answer appears in a terminal-style card with IN and OUT rows. Without JavaScript it is a plain list with one answer.

Part of the style

Blueprint Manual

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

Preview

Code
<style>
/* Goes after the pack's base.css */
:root {
  --paper: #fdfd55;
  --card: #feff83;
  --ink: #480f62;
  --ink-soft: #949421;
  --ink-faint: #e1e13a;
  --blue-wash: #f8f850;
  --blue: #282ec5;
  --blue-light: #c1c9df;
  --blue-mid: #859ce2;
  --grid-dot: #a9b6db;
}
</style>

<section class="questions">
  <div class="questions__layout">
    <div class="questions__wheel" tabindex="0" aria-label="Questions. Use the up and down arrow keys.">
      <ul class="questions__list">
        <li class="questions__slot"><button class="questions__pick" type="button">Is this a repair guide?</button></li>
        <li class="questions__slot"><button class="questions__pick" type="button">Who draws the figures?</button></li>
        <li class="questions__slot"><button class="questions__pick" type="button">When is the first printing?</button></li>
        <li class="questions__slot is-current"><button class="questions__pick" type="button">Will there be a paper edition?</button></li>
        <li class="questions__slot"><button class="questions__pick" type="button">What typeface is that?</button></li>
        <li class="questions__slot"><button class="questions__pick" type="button">Can I suggest a machine?</button></li>
        <li class="questions__slot"><button class="questions__pick" type="button">Do schools get a discount?</button></li>
      </ul>
      <div class="questions__steps">
        <button class="questions__step" type="button" data-step="-1" aria-label="Previous question">&uarr;</button>
        <button class="questions__step" type="button" data-step="1" aria-label="Next question">&darr;</button>
      </div>
    </div>

    <div class="questions__panel">
      <h2 class="questions__heading">Common Questions.</h2>
      <div class="questions__card" aria-live="polite">
        <div class="questions__line">
          <span class="questions__io">In:</span>
          <p class="questions__asked">Will there be a paper edition?</p>
        </div>
        <div class="questions__line">
          <span class="questions__io">Out:</span>
          <div class="questions__answers">
            <div class="questions__answer" hidden>
              <p>No, and please do not use it as one.</p>
              <p>It explains why a thing works. If yours has stopped working, the drawings may help you find the part to blame, but the manual will not tell you which screwdriver to buy.</p>
            </div>
            <div class="questions__answer" hidden>
              <p>One person, at a bench, with the machine in pieces next to the keyboard.</p>
              <p>Every figure starts as a real object taken apart and measured. That is also why chapters arrive slowly.</p>
            </div>
            <div class="questions__answer" hidden>
              <p>When chapter twenty-one is drawn. <em>Probably</em> spring.</p>
              <p>Until then the manual ships in parts, and people who reserve a copy get each chapter the week it is finished.</p>
            </div>
            <div class="questions__answer">
              <p>Yes, once the digital one is <em>actually</em> done.</p>
              <p>A printed manual wants thick paper, a lay-flat spine and one extra ink for the blue. That takes money and patience, so it comes last.</p>
              <p>Anyone who reserves the full digital edition gets first call on the print run.</p>
            </div>
            <div class="questions__answer" hidden>
              <p>Three of them. A serif for reading, a pixel face for labels and a scanline face for the title.</p>
              <p>The labels are set in capitals everywhere, the way parts are named on a real drawing.</p>
            </div>
            <div class="questions__answer" hidden>
              <p>Please do. The stranger and more ordinary, the better.</p>
              <p>The only rule is that it must live in a kitchen and come apart without a blowtorch.</p>
            </div>
            <div class="questions__answer" hidden>
              <p>Yes. Classrooms and libraries pay half.</p>
              <p>Write from a school address and say how many copies you need.</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

<style>
  .questions {
    container-type: inline-size;
    padding: var(--space-section) var(--gutter) 0;
  }

  .questions__layout {
    --row: 3rem;
    display: grid;
    gap: 2.5rem;
    max-width: 58rem;
    margin: 0 auto;
  }

  .questions__wheel {
    position: relative;
    outline: none;
  }

  .questions__list {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .questions__slot {
    height: var(--row);
    padding-right: 5.75rem;
    transition:
      transform var(--time) var(--ease-settle),
      filter var(--time) var(--ease),
      opacity var(--time) var(--ease);
  }

  .questions__pick {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    overflow: hidden;
    border: 0;
    background: none;
    font: inherit;
    font-size: var(--text-small);
    font-weight: 600;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
    cursor: pointer;
  }

  .questions__pick:focus-visible {
    outline: none;
    text-decoration: underline dotted;
    text-underline-offset: 0.3em;
  }

  .questions__steps {
    display: none;
  }

  .questions__step {
    width: var(--tap);
    height: var(--tap);
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: none;
    font-family: var(--font-text);
    font-size: 1.125rem;
    color: var(--ink);
    cursor: pointer;
    transition: color var(--time-quick) var(--ease);
  }

  .questions__step:hover,
  .questions__step:focus-visible {
    color: var(--blue);
    outline: none;
  }

  .questions__wheel:focus-visible .questions__steps {
    color: var(--blue);
    outline: 1px dashed var(--blue);
    outline-offset: -4px;
  }

  .questions--live .questions__wheel {
    height: calc(var(--row) * 5);
  }

  .questions--live .questions__slot {
    position: absolute;
    top: calc(50% - var(--row) / 2);
    left: 0;
    width: 100%;
    opacity: max(0, calc(1 - var(--away) * 0.34));
    filter: blur(calc(var(--away) * 1.1px));
    transform: translateY(calc(var(--offset) * var(--row))) translateX(calc(var(--away) * -3px))
      rotate(calc(var(--offset) * -1.3deg));
    transform-origin: 0 50%;
  }

  .questions--live .questions__steps {
    position: absolute;
    top: calc(50% - var(--tap) / 2);
    right: 0;
    display: flex;
  }

  .questions__heading {
    margin: 0 0 1.75rem;
    font-size: var(--text-body);
    font-weight: 400;
  }

  .questions__card {
    border: 1px solid var(--ink-faint);
    border-radius: var(--radius);
    background: var(--card);
  }

  .questions__line {
    display: grid;
    grid-template-columns: 3rem minmax(0, 1fr);
    padding: 0.875rem 1rem;
  }

  .questions__line + .questions__line {
    border-top: 1px solid var(--ink-faint);
  }

  .questions__io,
  .questions__asked {
    margin: 0;
    font-family: var(--font-label);
    font-size: var(--text-label);
    letter-spacing: var(--tracking-label);
    line-height: 1.6;
    text-transform: uppercase;
  }

  .questions__io {
    padding-top: 0.05rem;
    color: var(--ink-soft);
  }

  .questions__answer {
    font-size: var(--text-small);
    line-height: 1.65;
    animation: questions-arrive var(--time) var(--ease);
  }

  .questions__answer p {
    margin: 0 0 1rem;
  }

  .questions__answer p:first-child {
    margin-top: -0.2rem;
  }

  .questions__answer p:last-child {
    margin-bottom: 0;
  }

  @container (min-width: 50rem) {
    .questions__layout {
      grid-template-columns: minmax(0, 0.62fr) minmax(0, 1fr);
      gap: 2.5rem;
      align-items: start;
    }

    .questions--live .questions__wheel {
      height: calc(var(--row) * 7);
    }

    .questions__panel {
      min-height: 26rem;
      padding-top: calc(var(--row) * 2 - 0.75rem);
    }
  }

  @keyframes questions-arrive {
    from {
      opacity: 0;
      filter: blur(4px);
      transform: translateY(4px);
    }
    to {
      opacity: 1;
      filter: blur(0);
      transform: none;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .questions__slot {
      transition: none;
    }

    .questions__answer {
      animation: none;
    }
  }
</style>

<script>
  (() => {
    const setUpWheel = (root) => {
      const slots = [...root.querySelectorAll('.questions__slot')];
      const answers = [...root.querySelectorAll('.questions__answer')];
      const asked = root.querySelector('.questions__asked');
      const wheel = root.querySelector('.questions__wheel');
      const half = Math.floor(slots.length / 2);
      let current = Math.max(0, slots.findIndex((slot) => slot.classList.contains('is-current')));

      const offsetFromCurrent = (index) => ((index - current + slots.length + half) % slots.length) - half;

      const show = (index) => {
        current = (index + slots.length) % slots.length;
        slots.forEach((slot, slotIndex) => {
          const offset = offsetFromCurrent(slotIndex);
          slot.style.setProperty('--offset', offset);
          slot.style.setProperty('--away', Math.abs(offset));
          slot.classList.toggle('is-current', offset === 0);
          slot.firstElementChild.tabIndex = Math.abs(offset) > 2 ? -1 : 0;
        });
        answers.forEach((answer, answerIndex) => (answer.hidden = answerIndex !== current));
        asked.textContent = slots[current].textContent.trim();
      };

      slots.forEach((slot, index) => slot.firstElementChild.addEventListener('click', () => show(index)));
      root
        .querySelectorAll('.questions__step')
        .forEach((step) => step.addEventListener('click', () => show(current + Number(step.dataset.step))));
      wheel.addEventListener('keydown', (event) => {
        const step = { ArrowUp: -1, ArrowDown: 1 }[event.key];
        if (!step) return;
        event.preventDefault();
        show(current + step);
      });

      show(current);
      root.classList.add('questions--live');
    };

    document.querySelectorAll('.questions').forEach(setUpWheel);
  })();
</script>

Similar components

Questions

Questions

Information accordion

Information accordion

Keypad and knob

Keypad and knob

Pillar ring

Pillar ring

Showcase with progress tabs

Showcase with progress tabs

Contents with buttons

Contents with buttons

Chapter stepper

Chapter stepper

Film player

Film player