Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethink useADateRange hook #1197

Open
brennarvo opened this issue Apr 7, 2022 · 0 comments
Open

Rethink useADateRange hook #1197

brennarvo opened this issue Apr 7, 2022 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@brennarvo
Copy link
Collaborator

brennarvo commented Apr 7, 2022

Is your feature request related to a problem? Please describe.

I'm starting to see some holes in the way I first implemented the useADateRange hook, specifically with the maxDays configuration option.

Take for example a hypothetical date range that must be within a particular month (let's use August as an example). To do so, one would have to render ADatePicker with minDate and maxDate props set to August 1 and August 31. However, if there was also the requirement to limit the range selection within August to just 7 days, then this would get complicated since the useADateRange sets this limit with the minDate and maxDate props, which clashes with the requirement of only enabling the user to select dates within August.

The main takeaway is that ADatePicker should be the component being configured, not useADateRange. The purpose behind useADateRange was to handle sequencing logic, but I've coupled it too much with ADatePicker logic.

Describe the solution you'd like

Remove all date picker configuration from useADateRange before it gets too large. It should not have an opinion on minDate and maxDate. A better name for useADateRange might be useDateRangeSequencer.

const {
  // The sequencer handler
  onChange,

  // Useful if developer ever wants control of range state
  setValue,
  
  // Value to be passed to the date picker
  value
} = useDateRangeSequencer();

return (
  <ADatePicker
    minDate={/* August 1 */}
    maxDate={/* August 31 */}
    maxSelectionLength={7}
    value={value}
    onChange={onChange}
  />
)

Describe alternatives you've considered

Removing useADateRange entirely in favor of adding startDate and endDate props, which would also keep a similar pattern with the minDate and maxDate props in ADatePicker.

<ADatePicker
  minDate={/* August 1 */}
  maxDate={/* August 31 */}
  startDate={/* some date */}
  endDate={/* another date */}
  maxSelectionLength={7}
  onChange={/* some handler */}
/>

Additional context

A good example of date picker configurations: https://reactdatepicker.com/#example-default

@brennarvo brennarvo added the help wanted Extra attention is needed label Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant