-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add TimeRangePicker component #206
Conversation
🦋 Changeset detectedLatest commit: ce41b55 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
bc060e8
to
5a04145
Compare
981dfd5
to
28c3b93
Compare
There was a problem hiding this 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
packages/examples/dashboard/src/components/CounterConnected/CounterConnected.tsx
Outdated
Show resolved
Hide resolved
packages/examples/dashboard/src/components/LeaderboardConnected/LeaderboardConnected.tsx
Show resolved
Hide resolved
packages/ui-kit/src/components/TimeRangePicker/DateTimeField/DateTimeField.tsx
Show resolved
Hide resolved
packages/ui-kit/src/components/TimeRangePicker/TimeRangePicker.tsx
Outdated
Show resolved
Hide resolved
packages/ui-kit/src/components/TimeRangePicker/TimeRangePicker.tsx
Outdated
Show resolved
Hide resolved
packages/ui-kit/src/components/TimeRangePicker/TimeRangePicker.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
packages/ui-kit/src/components/TimeRangePicker/TimeRangePicker.tsx
Outdated
Show resolved
Hide resolved
? `${formatDateTime(datepickerRange?.from, locale)} - ${formatDateTime(datepickerRange?.to, locale)}` | ||
: `${formatDateTime(datepickerRange?.from, locale)} - Now`, |
There was a problem hiding this comment.
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).
packages/ui-kit/src/components/TimeRangePicker/TimeRangePicker.tsx
Outdated
Show resolved
Hide resolved
packages/ui-kit/src/components/TimeRangePicker/TimeRangePicker.tsx
Outdated
Show resolved
Hide resolved
packages/ui-kit/src/components/TimeRangePicker/TimeRangePicker.types.ts
Outdated
Show resolved
Hide resolved
packages/ui-kit/src/components/TimeRangePicker/TimeRangePicker.types.ts
Outdated
Show resolved
Hide resolved
packages/ui-kit/src/components/TimeRangePicker/TimeRangePicker.types.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
-
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".
-
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".
- ✅ 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.
The component looks great. I'm worried about the additional dependency on Google fonts. A couple of questions:
|
@acossta I've added So, before the change and without |
Some more things I noticed
|
@markandrus I followed Posthog's picker behavior. We can re-think it later if needed. Wdyt? |
@sashathor sounds good for now! |
@markandrus found a few more bugs. I'll let you know when the PR will be ready for the next round. |
There was a problem hiding this 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/TimeRangePicker/TimeRangePicker.tsx
Outdated
Show resolved
Hide resolved
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 |
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 | ||
} |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
Description of changes
This PR implements Add Date & Time Picker component and syncs all the UI components with new design tokens introduced in #165.
New components:
Button
Divider
FormField
Input
Select
Option
DateTimeField
TimeRangePicker
Typography
Checklist
Before merging to main: