vkurko / calendar

Full-sized drag & drop JavaScript event calendar with resource & timeline views
https://vkurko.github.io/calendar/
MIT License
964 stars 82 forks source link

Time grid mobile styling #224

Open MaCleodWalker opened 5 months ago

MaCleodWalker commented 5 months ago

Is it possible to make the the column a set width and the left time bar sticky in the resourceTimeGridDay and resourceTimeGridWeek views for better mobile experience? Similar to Google calendar's 3 day mobile view.

vkurko commented 5 months ago

Can you provide a screenshot, please? I looked at the web version of Google Calendar on my mobile device, but didn't see anything similar there.

MaCleodWalker commented 5 months ago

Screenshot_20240127_120119_Calendar.jpg

vkurko commented 4 months ago

Thank you. So the left time bar does not scroll, but always remains in the visibility area.

I don't currently have a ready solution, but it might be possible to do it in CSS. I'll try later.

mrweiner commented 3 months ago

One solution to this is e.g.

    .ec-time-grid.ec-week-view {
      .ec-day {
        min-width: 300px;
      }

      .ec-days {
        overflow: auto;
      }
    }

// From https://stackoverflow.com/a/31084338
<script>

    var scrollers = document.querySelectorAll('.ec-time-grid.ec-week-view .ec-days');

    var scrollerDivs = Array.prototype.filter.call(scrollers, function (testElement) {
      return testElement.nodeName === 'DIV';
    });

    function scrollAll(scrollLeft) {
      scrollerDivs.forEach(function (element, index, array) {
        element.scrollLeft = scrollLeft;
      });
    }

    scrollerDivs.forEach(function (element, index, array) {
      element.addEventListener('scroll', function (e) {
        scrollAll(e.target.scrollLeft);
      });
    });

</script>

Don't even need to use display: sticky on the sidebar elements. Slight limitations are that scrollbars are exposed, and moving to the next/previous week does not scroll back the left. Can probably be handled with a handler somewhere but haven't tried yet.

mrweiner commented 3 months ago

Looks like scrollbars can be hidden with like:

.ec-days {
  overflow: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;

  &::-webkit-scrollbar {
    display: none;
  }
}
MaCleodWalker commented 1 month ago

How are you adding these classes to the component?