react-widgets icon indicating copy to clipboard operation
react-widgets copied to clipboard

implement availableTimes property for DateTimePicker

Open zhisme opened this issue 5 years ago • 6 comments

Hello!

I needed one feature for my work project, so I implemented this in your library. Business task was set like so:

Person need to select time only in working hours e.g. (8 AM - 8 PM)

As I couldn't achieve it by timeComponent, because it renders empty li tags that can be clicked, I modified getDates function in order to achieve this goal. Hope you will find my PR useful

zhisme avatar Jan 24 '20 12:01 zhisme

@jquense any feedback? 🙂

zhisme avatar Nov 04 '20 13:11 zhisme

hey, sorry, its too easy to lose track of pending GH PRs. Thanks for this, I think it's neat and useful, but i'm not sure it's a good fit here. It may be better to provide a more general API for achieving this, such as filterTimes: (date) => true

jquense avatar Nov 05 '20 13:11 jquense

nice feature, thanks!

OpakAlex avatar Nov 05 '20 14:11 OpakAlex

@jquense hey. can you describe a little more, how can I adjust the code? filterTimes: (arrayOfDates) => true at least needs to get an array to achieve this on my opinion

zhisme avatar Nov 06 '20 10:11 zhisme

I was thinking something like array.filter so you only provide the rejector function and the component here will only use dates you return true for

jquense avatar Nov 06 '20 14:11 jquense

Here is my workaround - to empty timeList options if time out of range and hide empty options by css style.

css

  .rw-list-option:empty {
    display: none;
  }

component:

    <DateTimePicker
      {...tail}
      timeComponent={({ value, text }) => {
        return value.getHours() >= 7 && value.getHours() <= 18 ? text : '';
      }}
    />

siropkin avatar Apr 14 '21 07:04 siropkin