uvarov-frontend / vanilla-calendar-pro

The Vanilla Calendar Pro is a versatile JavaScript date and time picker component with TypeScript support, making it compatible with any JavaScript frameworks and libraries. It is designed to be lightweight, easy to use, and feature-rich, without relying on external dependencies.
https://vanilla-calendar.pro
Other
482 stars 60 forks source link

feat: add `auto` option to `positionToInput` for auto-positioning #278

Closed ghiscoding closed 3 months ago

ghiscoding commented 4 months ago
{
  canShow: {top: true, bottom: true, left: false, right: true}
  parentPositions: ['top', 'left']
}

We can see that the parentPosition is something that we can then provide to the positionToInput because it uses the same structure.

Below are a couple of animated gifs of the auto-positioning depending on available space

brave_Cho3EM7Ioz

brave_ntV0cmTfxN

uvarov-frontend commented 3 months ago

Although I generally like the quality and style of your code, I took the liberty of refactoring the code a little. I don’t like a lot of if/esle, especially nested ones.

ghiscoding commented 3 months ago

sure go ahead and change as you like it, thanks for merging :)

SohanChotia commented 3 months ago

image

using auto position, its cutting off the calendar in browser window ?

ghiscoding commented 3 months ago

@SohanChotia your space is very tight in your print screen above, so it most probably cannot properly find the best position because none of the side have enough space to position itself. To troubleshoot that, you can maybe modify the code and add an alert on the canShow object to see if any side is true or not. There's not much more the auto position function can do if it can't find where to position itself.

https://github.com/uvarov-frontend/vanilla-calendar-pro/blob/7c61e39b754a80c8852348947cffc53ab7fa5a18/package/src/scripts/helpers/position.ts#L95-L113

I'm assuming the logic below is returning ['top', 'right'] in your use case

https://github.com/uvarov-frontend/vanilla-calendar-pro/blob/7c61e39b754a80c8852348947cffc53ab7fa5a18/package/src/scripts/helpers/position.ts#L130-L135

SohanChotia commented 3 months ago

if we assume it returns top right, why its still aligned from left corner, its right corner should be aligned from right side of the container