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

Add TimeRangePicker component #206

Merged
merged 23 commits into from
May 21, 2024

Conversation

sashathor
Copy link
Contributor

@sashathor sashathor commented Mar 28, 2024

Description of changes

This PR implements Add Date & Time Picker component and syncs all the UI components with new design tokens introduced in #165.

Kapture 2024-04-18 at 16 02 50

New components:

  • Button
  • Divider
  • FormField
  • Input
  • Select
  • Option
  • DateTimeField
  • TimeRangePicker
  • Typography

Checklist

Before merging to main:

  • Tests
  • Manually tested in React apps
  • Changesets
  • Approved

Copy link

changeset-bot bot commented Mar 28, 2024

🦋 Changeset detected

Latest commit: ce41b55

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@propeldata/ui-kit Minor
dashboard-example Major
react-16 Patch
react-18 Patch
react-17 Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
ui-kit ⬜️ Ignored (Inspect) Visit Preview May 21, 2024 11:52am

@sashathor sashathor changed the title WIP: Add TimePicker component Add TimePicker component Apr 17, 2024
@sashathor sashathor marked this pull request as ready for review April 18, 2024 14:06
Copy link
Contributor

@felipecadavid felipecadavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component looks amazing! I left a few comments

Also, we've added a lot of primitive components (Button, Select, etc) in this PR, I'm thinking about not mixing those up in the components directory, how about having a primitives directory for those components?

Please also let's move the stories from having the 'pattern' tag to the devOnly array in manager.ts so those are visible in dev

@sashathor sashathor changed the title Add TimePicker component Add TimeRangePicker component Apr 26, 2024
Copy link
Contributor

@markandrus markandrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Left some questions/suggestions about prop names.

Also, suggest to use en dashes (–) and true ellipses (…) everywhere we can, rather than hyphens (-) and periods (...). Can you check that we do?

Finally, will spend some time playing with this in Storybook.

app/storybook/.storybook/manager.ts Outdated Show resolved Hide resolved
Comment on lines 230 to 231
? `${formatDateTime(datepickerRange?.from, locale)} - ${formatDateTime(datepickerRange?.to, locale)}`
: `${formatDateTime(datepickerRange?.from, locale)} - Now`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen there is also a formatRange API for locale-aware range formatting. I think we don't need to tackle that right now (or ever?). But it is interesting: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange

Main benefit seems to be for representing ranges when ranges share the same day, the same month, etc. (e.g., where to place the hyphen).

Copy link
Contributor

@markandrus markandrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 1. Tabbing behavior: I can tab to the dropdown to select it and hit enter/space to open it. But then, when I tab again, it jumps straight to the "In the last" option's numeric input, skipping over "Today", "This week", etc. I would expect to tab through those options first, no? EDIT: I just tried Radix's Dropdown Menu, and it seems like this may be expected? So maybe this behavior is good?

  • 2. Tabbing/keyboard behavior (numeric input): Same as above, I tab into the "In the last" option's numeric input, but then the keyboard up/down keys do not increment/decrement the input. They instead move my selection around.

  • 3. Tabbing/keyboard behavior (days/weeks/months dropdown): Same as above, I tab into the "In the last" option's numeric input, then tab again to the days/weeks/months dropdown, and hit enter/space to open it. But then the keyboard up/down keys do not move within the days/weeks/months dropdown. They instead move my selection around in the outer dropdown.

  • 4. Keyboard navigation (escape key): I would expect pressing escape to close the menu, wherever I am (can see this behavior in Radix, too).

  • 5. From custom date until now…: Should I be able to click within the range (not just outside the range) to shorten it? Currently, I cannot click "6" for example to change the start date.

    image

  • 6. Notes on text/copy: Something to discuss with @acossta but,

    • Why is it "Custom fixed date range"? Why is "fixed" significant? IMO, it should just be "Custom date range".
    • Why does "From custom date until now…" end in ellipsis? Why not the other option? IMO, we should get rid of the ellipsis.
    • Why emphasize "custom date"? It's more like, "From a specific date until now" or "From a particular date until now" or just "From date until now". IMO, we should do "From date until now".

    If we agree, that would leave us with just "From date until now" and "Custom date range".

    • ✅ Quick discussion in front-end sync today: we decided to go with "From date until now" and "Custom date range".
  • 7. Apply behavior: I haven't applied anything yet, but clicking on a date to deselect it will update the dropdown label ("- Now"). IMO, it should continue to show what was previously selected. Additionally, the "Apply" button should be disabled until I select a valid date range. This happens on both "From date until now" and "Custom date range".

    image

  • 8. Start/end bar being hidden: IMO, we should rethink whether the start/end bar should be hidden when a date range is not selected. It leads to the whole modal shifting, which is something to avoid, no? IMO, it would be better to just show something like "Start: — End: —" if no values are available yet. This applies to both "From date until now" and "Custom date range".

    image

    • ✅ Quick discussion in front-end sync today: we decided to keep this bar always visible with some placeholder, to avoid shifting.
  • 9. No "back" behavior?: We have "Cancel" button and "x" icon for closing the pickers, but I feel like I'd want to go back to the previous menu instead. 🤔 Like, if I click "Cancel", I'd want to just go back to the menu (maybe the button should even be "Back"?). Also, I'm not even sure if an "x" icon is necessary. We don't have an "x" icon on the initial menu. Why have it on the next one? IMO, we should get rid of it.

    • ✅ Quick discussion in front-end sync today: we decided to remove the "x" icon, and to let "Cancel" take you back to the preceding menu.

@acossta
Copy link
Contributor

acossta commented May 9, 2024

The component looks great. I'm worried about the additional dependency on Google fonts.

A couple of questions:

  • Can we ship this with a font that doesn't require that, like Helvetica or Arial?
  • Ideally, customizing the font would be done at the theme level. If you need Inter or any other Google font, it would be expected that you have to install additional dependencies. Would this be a feasible approach?

@sashathor
Copy link
Contributor Author

The component looks great. I'm worried about the additional dependency on Google fonts.

A couple of questions:

  • Can we ship this with a font that doesn't require that, like Helvetica or Arial?
  • Ideally, customizing the font would be done at the theme level. If you need Inter or any other Google font, it would be expected that you have to install additional dependencies. Would this be a feasible approach?

@acossta I've added sans-serif as a fallback.

So, before the change and without Inter installed we had the following:
image

After the change and without Inter installed we will have:
image

With Inter installed:
image

@markandrus
Copy link
Contributor

markandrus commented May 13, 2024

Some more things I noticed

  • 1. "From date until now": Choose this, apply a date range, re-open the menu, choose this again, notice the previously chosen date range is no longer visible. If you do the same flow with "Custom date range", it's not reset. I.e., you can see the value you previously applied. IMO, it should remember the value that was last set, and the two options should behave the same.

  • 2. Keyboard navigation: If you tab into the numeric input, increment or decrement it, and then tab next to the days/weeks/months dropdown (because you want to see the time unit now), the outermost menu quickly closes. IMO, so long as an input/submenu is focused in the menu, the outermost menu should not close.

  • 3. Keyboard navigation: Tabbing out of the days/weeks/months dropdown does not close it.

    image

  • 4. Clearing: clearing a cleared date range leaves the button focused.

    image

  • 5. Closing: can't close the outermost menu via escape key or clicking outside of it. Within the inner date range pickers, escape key and clicking outside work to close the whole menu.

@sashathor
Copy link
Contributor Author

  1. Keyboard navigation: If you tab into the numeric input, increment or decrement it, and then tab next to the days/weeks/months dropdown (because you want to see the time unit now), the outermost menu quickly closes. IMO, so long as an input/submenu is focused in the menu, the outermost menu should not close.

@markandrus I followed Posthog's picker behavior. We can re-think it later if needed. Wdyt?

@sashathor sashathor requested a review from markandrus May 14, 2024 13:50
@markandrus
Copy link
Contributor

@sashathor sounds good for now!

@sashathor
Copy link
Contributor Author

@markandrus found a few more bugs. I'll let you know when the PR will be ready for the next round.

Copy link
Contributor

@felipecadavid felipecadavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments on the code, I think it's getting there

packages/ui-kit/src/components/Select/Select.tsx Outdated Show resolved Hide resolved
packages/ui-kit/src/components/Select/Select.tsx Outdated Show resolved Hide resolved
packages/ui-kit/src/components/Select/Select.tsx Outdated Show resolved Hide resolved
packages/ui-kit/src/components/Select/Select.tsx Outdated Show resolved Hide resolved
@felipecadavid
Copy link
Contributor

It seems like I cannot close the select by clicking back on it? it seems like it closes but quickly opens again. The behavior is a bit weird as I can tell sometimes it actually closes

Screen.Recording.2024-05-16.at.5.02.52.PM.mov

Comment on lines +16 to +36
switch (part.type) {
case 'year':
return 'yyyy'
case 'month':
return options?.month === 'long' ? 'MMM' : 'MM'
case 'day':
return 'dd'
case 'hour':
return is12HourFormat(locale) ? 'hh' : 'HH'
case 'minute':
return 'mm'
case 'second':
return 'ss'
case 'dayPeriod':
return is12HourFormat(locale) ? 'a' : ''
case 'literal':
// Replace non-breaking space with regular space
return part.value.charCodeAt(0) === 8239 ? ' ' : part.value
default:
return part.type
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an object literal makes more sense here

{
  year: 'yyyy',
  month: options?.month === 'long' ? 'MMM' : 'MM',
  day: 'dd'
  ...
}[part.type]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something wrong with switch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually an object literal brings a better readabilty, performance (evaluating multiple cases vs mapping) and maintainability. In some cases you may want to still use a switch for convenience e.g complex conditions or adding additional logic to each case, but I think for this case the object literal works much better

@sashathor sashathor merged commit ebdd0da into main May 21, 2024
3 checks passed
@sashathor sashathor deleted the sasha/pro-2111-add-date-time-picker-component branch May 21, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants