kitbash Sign in Connect agent
Components

Shelf drawing

Fine-line isometric shelving with ten small models; hover fills a model black, click picks it and names it in the caption.

Part of the style

Shelf Atelier

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

Preview

Code
<style>
/* Goes after the pack's base.css */
:root {
  --ink: #1d0c0c;
  --paper: #a8a197;
  --line: #776f63;
  --line-soft: #8e867b;
  --scrim: rgba(29, 12, 12, 0.2);
}
</style>

<section class="shelf" aria-label="Objects on the shelf">
  <header class="shelf__head">
    <a class="shelf__mark" href="#">_mensula</a>
    <span class="shelf__count">10 objects, pick one</span>
  </header>
  <div class="shelf__stage">
    <svg class="shelf__drawing" xmlns="http://www.w3.org/2000/svg" role="group" aria-label="Isometric drawing of a three bay shelf holding ten models"></svg>
  </div>
  <p class="shelf__caption" aria-live="polite">
    <span class="shelf__code">_A04</span>
    <span class="shelf__name">Biblioteca Mínima</span>
    <span class="shelf__meta">Library, S, 2025</span>
  </p>
</section>

<style>
  .shelf {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: var(--space-s);
    min-height: clamp(460px, 62vw, 720px);
    padding: var(--edge);
    background: var(--paper);
    color: var(--ink);
  }
  .shelf__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--gap);
  }
  .shelf__mark {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    margin-block: -12px;
    color: inherit;
    font-weight: var(--weight-bold);
    text-decoration: none;
  }
  .shelf__mark:focus-visible {
    outline: var(--hair) solid var(--ink);
  }
  .shelf__count {
    color: var(--line);
  }
  .shelf__stage {
    display: grid;
    place-items: center;
    min-width: 0;
  }
  .shelf__drawing {
    width: auto;
    height: clamp(300px, 50vw, 560px);
    max-width: 100%;
    overflow: visible;
  }
  @media (max-width: 600px) {
    .shelf__drawing {
      height: min(520px, 120vw);
    }
  }
  .shelf__frame {
    fill: none;
    stroke: var(--line-soft);
    stroke-width: var(--stroke);
    vector-effect: non-scaling-stroke;
    pointer-events: none;
  }
  .shelf__item {
    cursor: pointer;
    outline: none;
  }
  .shelf__item > * {
    fill: var(--paper);
    stroke: var(--line);
    stroke-width: var(--stroke);
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
    transition: fill var(--time) var(--ease), stroke var(--time) var(--ease);
  }
  .shelf__item .shelf__ink {
    fill: none;
  }
  .shelf__item:hover > *,
  .shelf__item:focus-visible > *,
  .shelf__item.is-active > * {
    fill: var(--ink);
    stroke: var(--paper);
  }
  .shelf__item:hover .shelf__ink,
  .shelf__item:focus-visible .shelf__ink,
  .shelf__item.is-active .shelf__ink {
    fill: none;
  }
  .shelf__caption {
    display: flex;
    flex-wrap: wrap;
    gap: 0 0.6em;
    min-height: var(--leading);
    margin: 0;
  }
  .shelf__code,
  .shelf__name {
    font-weight: var(--weight-bold);
  }
</style>

<script>
  (() => {
    const NS = 'http://www.w3.org/2000/svg';
    const COS30 = Math.cos(Math.PI / 6);
    const BAY = 110;
    const DEPTH = 36;
    const LEVELS = [0, 64, 128, 192, 256];
    const POST_TOP = 300;

    const project = ([x, y, z]) => [(x - y) * COS30, (x + y) * 0.5 - z];
    const pointsOf = (corners) => corners.map((corner) => project(corner).map((n) => n.toFixed(2)).join(',')).join(' ');

    function shape(tag, attributes) {
      const node = document.createElementNS(NS, tag);
      for (const [name, value] of Object.entries(attributes)) node.setAttribute(name, value);
      return node;
    }
    const face = (corners) => shape('polygon', { points: pointsOf(corners) });
    const line = (from, to, className) => shape('polyline', { points: pointsOf([from, to]), class: className || '' });

    /* The three faces a viewer from the front right sees: top, the +x side and the +y side. */
    function box(x, y, z, w, d, h) {
      return [
        face([[x + w, y, z], [x + w, y + d, z], [x + w, y + d, z + h], [x + w, y, z + h]]),
        face([[x, y + d, z], [x + w, y + d, z], [x + w, y + d, z + h], [x, y + d, z + h]]),
        face([[x, y, z + h], [x + w, y, z + h], [x + w, y + d, z + h], [x, y + d, z + h]]),
      ];
    }
    function house(x, y, z, w, d, h, roof) {
      const eave = z + h;
      return [
        ...box(x, y, z, w, d, h).slice(0, 2),
        face([[x, y, eave], [x + w, y, eave], [x + w, y + d / 2, eave + roof], [x, y + d / 2, eave + roof]]),
        face([[x, y + d, eave], [x + w, y + d, eave], [x + w, y + d / 2, eave + roof], [x, y + d / 2, eave + roof]]),
        face([[x + w, y, eave], [x + w, y + d, eave], [x + w, y + d / 2, eave + roof]]),
      ];
    }
    const stack = (boxes) => boxes.sort((a, b) => a[0] + a[1] + a[2] - (b[0] + b[1] + b[2])).flatMap((b) => box(...b));

    /* A frame leaning on the shelf front: u runs along x, v runs up the lean. */
    function leaningFrame(x0, width) {
      const base = [x0, DEPTH + 30, 0];
      const lean = [0, -24, 92];
      const at = (u, v) => [base[0] + u, base[1] + lean[1] * v, base[2] + lean[2] * v];
      const outer = face([at(0, 0), at(width, 0), at(width, 1), at(0, 1)]);
      const inner = face([at(5, 0.06), at(width - 5, 0.06), at(width - 5, 0.94), at(5, 0.94)]);
      const glyph = shape('polyline', {
        class: 'shelf__ink',
        points: pointsOf([at(22, 0.3), at(30, 0.3), at(30, 0.36), at(30, 0.46), at(34, 0.46), at(34, 0.36), at(34, 0.46), at(38, 0.46), at(38, 0.36)]),
      });
      return [outer, inner, glyph];
    }

    const OBJECTS = [
      { code: '_A01', name: 'Casa Ribera', meta: 'House, M, 2024', parts: () => house(18, 8, LEVELS[3], 34, 22, 24, 14) },
      { code: '_A02', name: 'Escalera Norte', meta: 'Stair, S, 2022', parts: () => stack([[120, 10, LEVELS[3], 40, 20, 8], [128, 10, LEVELS[3] + 8, 32, 20, 8], [136, 10, LEVELS[3] + 16, 24, 20, 8], [144, 10, LEVELS[3] + 24, 16, 20, 8]]) },
      { code: '_A03', name: 'Pabellón del Agua', meta: 'Pavilion, L, 2026', parts: () => stack([[232, 6, LEVELS[1], 76, 26, 3], [244, 12, LEVELS[1] + 3, 14, 10, 12], [266, 14, LEVELS[1] + 3, 22, 8, 6], [292, 8, LEVELS[1] + 3, 8, 14, 18]]) },
      { code: '_A04', name: 'Biblioteca Mínima', meta: 'Library, S, 2025', parts: () => stack([[132, 8, LEVELS[1], 36, 24, 4], [134, 9, LEVELS[1] + 4, 32, 22, 4], [131, 10, LEVELS[1] + 8, 34, 20, 3], [135, 9, LEVELS[1] + 11, 28, 22, 5]]) },
      { code: '_A05', name: 'Torre Lenta', meta: 'Tower, XL, 2023', parts: () => stack([[262, 8, LEVELS[3], 22, 22, 14], [265, 11, LEVELS[3] + 14, 16, 16, 14], [268, 14, LEVELS[3] + 28, 10, 10, 12]]) },
      { code: '_A06', name: 'Banco Largo', meta: 'Bench, M, 2021', parts: () => stack([[14, 14, LEVELS[1], 4, 10, 10], [80, 14, LEVELS[1], 4, 10, 10], [10, 12, LEVELS[1] + 10, 78, 14, 3]]) },
      { code: '_A07', name: 'Patio Doble', meta: 'Housing, L, 2024', parts: () => stack([[234, 6, LEVELS[2], 40, 8, 10], [234, 22, LEVELS[2], 40, 8, 10], [234, 14, LEVELS[2], 8, 8, 10], [266, 14, LEVELS[2], 8, 8, 10], [284, 10, LEVELS[2], 18, 18, 16]]) },
      { code: '_A08', name: 'Mesa Plegable', meta: 'Table, S, 2020', parts: () => stack([[132, 12, LEVELS[2], 2, 2, 14], [160, 12, LEVELS[2], 2, 2, 14], [132, 24, LEVELS[2], 2, 2, 14], [160, 24, LEVELS[2], 2, 2, 14], [128, 10, LEVELS[2] + 14, 38, 18, 2]]) },
      { code: '_A09', name: 'Faro Pequeño', meta: 'Lamp, S, 2026', parts: () => stack([[40, 14, LEVELS[4], 14, 10, 2], [46, 18, LEVELS[4] + 2, 2, 2, 26], [38, 12, LEVELS[4] + 28, 18, 14, 8]]) },
      { code: '_A10', name: 'Marco Apoyado', meta: 'Exhibition, M, 2025', parts: () => leaningFrame(120, 52) },
    ];

    function drawFrame(svg) {
      const group = shape('g', { class: 'shelf__frame' });
      const posts = [0, 1, 2, 3].map((bay) => bay * BAY);
      for (const x of posts) group.append(line([x, 0, 0], [x, 0, POST_TOP]));
      for (const z of LEVELS) group.append(face([[0, 0, z], [3 * BAY, 0, z], [3 * BAY, DEPTH, z], [0, DEPTH, z]]));
      svg.append(group);
    }
    function drawFrontPosts(svg) {
      const group = shape('g', { class: 'shelf__frame' });
      for (const bay of [0, 1, 2, 3]) group.append(line([bay * BAY, DEPTH, 0], [bay * BAY, DEPTH, POST_TOP - (bay % 2) * 16]));
      svg.append(group);
    }

    function setUp(root) {
      const svg = root.querySelector('.shelf__drawing');
      const caption = {
        code: root.querySelector('.shelf__code'),
        name: root.querySelector('.shelf__name'),
        meta: root.querySelector('.shelf__meta'),
      };
      const show = (item) => {
        caption.code.textContent = item.code;
        caption.name.textContent = item.name;
        caption.meta.textContent = item.meta;
      };
      let picked = OBJECTS[3];

      drawFrame(svg);
      const groups = OBJECTS.map((item) => {
        const group = shape('g', { class: 'shelf__item', tabindex: '0', 'aria-label': `${item.code} ${item.name}` });
        group.append(...item.parts());
        group.addEventListener('pointerenter', () => show(item));
        group.addEventListener('pointerleave', () => show(picked));
        group.addEventListener('focus', () => show(item));
        group.addEventListener('blur', () => show(picked));
        svg.append(group);
        return group;
      });
      drawFrontPosts(svg);

      const pick = (index) => {
        picked = OBJECTS[index];
        groups.forEach((group, order) => group.classList.toggle('is-active', order === index));
        show(picked);
      };
      groups.forEach((group, index) => {
        group.addEventListener('click', () => pick(index));
        group.addEventListener('keydown', (event) => {
          if (event.key !== 'Enter' && event.key !== ' ') return;
          event.preventDefault();
          pick(index);
        });
      });
      pick(3);

      const box = svg.getBBox();
      svg.setAttribute('viewBox', `${box.x - 4} ${box.y - 4} ${box.width + 8} ${box.height + 8}`);
    }

    document.querySelectorAll('.shelf').forEach(setUp);
  })();
</script>

Similar components

Work globe

Work globe

Project windows

Project windows

Work grid with pill

Work grid with pill

Black work cards with device frames

Black work cards with device frames

Work grid

Work grid

Artefact scatter

Artefact scatter

Staggered work grid

Staggered work grid

Inset project tiles

Inset project tiles