6eDesign / svelte-calendar

A lightweight datepicker with neat animations and a unique UX.
https://6edesign.github.io/svelte-calendar/
MIT License
543 stars 90 forks source link

feat: positioning #74

Closed Grotlo closed 4 years ago

Grotlo commented 4 years ago

fixes #70

I've managed to place the datepicker on *five different positions: "middle-bottom", "bottom-left", "bottom-right", "left" and "right". Positioning is set as a prop, so you only need to put ´position="bottom-right"´ to set its position. When doing this, it made sense to make the button also close the datepicker, which is achieved as well. The calendar has the function to move based on viewport boundries, but since these will be set positions I've made it so that that won't happen if a position is set and defined.

I'm setting this as a draft because it might be a bit of brute forcing to get the component to line up correctly, but it seems to work with the default button and my custom one as well. Also, there's only *five positions, because I couldn't manage to do the top positions without putting in ridicously high numbers which made me believe that I did something wrong.

(I have some time now, so I can probably continue with #60 )

Grotlo commented 4 years ago

probably not a good solution. Closing this.

omaishar commented 4 years ago

Why not a good solution? Controlling the position would be great! 👍

Grotlo commented 4 years ago

Why not a good solution? Controlling the position would be great! 👍

It would be great and this solution does work somewhat! However, my solution was a very brute force way of doing it and not very elegant at all.

export let position;
  switch (position) {
    case "bottom-right":
      positionTop = 100;
      positionLeft = 0;
      positionTranslateX = 0;
      positionTranslateY = 0;
      margin = "5px 0 0 0";
      break;
    case "bottom-left":
      positionTop = 100;
      positionLeft = -13;
      positionTranslateX = 0;
      positionTranslateY = 0;
      margin = "5px 0 0 0";
      break;
    case "middle-bottom":
      positionTop = 100;
      positionTranslateY = 0;
      margin = "5px 0 0 0";
      break;
    case "right":
      positionLeft = 100;
      positionTranslateX = 0;
      margin = "0 0 0 5px";
      break;
    case "left": 
      positionRight = 100;
      positionLeft = null;
      positionTranslateX = 0;
      margin = "0 5px 0 0";
    default:
      break;
  }

If you know of a better way of doing it, feel free to make changes and make a new PR!

antony commented 4 years ago

Ah I really want this :)