ircam-ismm / sc-components

Web Component library for audio applications
https://ircam-ismm.github.io/sc-components/
BSD 3-Clause "New" or "Revised" License
19 stars 2 forks source link

sc-separator - create component #32

Closed b-ma closed 11 months ago

b-ma commented 11 months ago
    // generalize, i.e. handle position / size of container
    _resize(e, direction) {
      const { width, height } = e.currentTarget.parentElement.getBoundingClientRect();
      const $prev = e.currentTarget.previousElementSibling;
      const $next = e.currentTarget.nextElementSibling;

      document.body.style.userSelect = 'none';
      document.body.style.cursor = direction === 'vertical' ? 'ns-resize' : 'ex-resize';

      const resize = e => {
        if (direction === 'horizontal') {
          // clientX should be relative to parentElement
          const ratio = Math.max(0.02, Math.min(0.98, e.clientX / width));
          $prev.style.width = `${ratio * 100}%`;
          $next.style.width = `${(1 - ratio) * 100}%`;
        } else if (direction === 'vertical') {
           //clientY should be relative to parentElement
          const ratio = Math.max(0.02, Math.min(0.98, e.clientY / height));
          $prev.style.height = `${ratio * 100}%`;
          $next.style.height = `${(1 - ratio) * 100}%`;
        }
      }

      window.addEventListener('mousemove', resize);
      window.addEventListener('mouseup', () => {
        document.body.style.userSelect = 'auto';
        document.body.style.cursor = 'auto';
        window.removeEventListener('mousemove', resize);
      });
    },
b-ma commented 11 months ago

released in 3.0.0-alpha.49