📆 DatePicker #6
Replies: 0 comments 3 replies
-
Yo! @JoeyDjr 😊 🕹️ UX remarks: 💄 UI remarks:
If necessary, I can transcribe everything I have just said into a small prototype. |
Beta Was this translation helpful? Give feedback.
-
Thanks for this discussion! Calendar:
DatePicker:
Also a detail, I wonder if an enum is not more suitable than a type for the days of the week? |
Beta Was this translation helpful? Give feedback.
-
💡 This discussion is about the DatePicker component.
✨ To build the DatePicker, I separated the logic, the UI, and the components.
I first built a Calendar component with its hook and selectors. Then I built the DatePicker component composed of a basic input and the Calendar.
📅 Calendar
👉 First of all, I built the Calendar component.
💄 UI proposition for the calendar.
🏗️ It has the following properties :
currentDate: string | Date
- sets the current date of the calendarweekStart: Day
- the first day of the week to displayonSelect?: (date: string) => void
- callback function called when a date is selectedonSelectRange?: (start: string, end: string) => void
- callback function called when a range of date is selectedIt also defines the following type :
export type Day = 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday'
👔 The Calendar component comes with the
useCalendar
hook to manage the calendar state. This hook provides the following actions :dateSelected
- executes when a date is selectedpreviousMonthReached
- executes when the previous month is reachednextMonthReached
- executes when the next month is reachedpreviousYearReached
- executes when the previous year is reachednextYearReached
- executes when the next year is reached🧐 And it maintains a state that saves the following data :
currentDate: string | Date
- the current calendar datestartDateSelected?: string | Date
- if it exists, the calendar is able to provide a range of dates and this property saves the start of that range.To access this data, the Calendar uses selectors functions.
🙈 Finally, to build the Calendar UI, it implements some private functions which allow the calendar to perform useful calculations such as the first day of the month, the number of days in the month, but also that allow the construction of the calendar display (retrieve of the days of the month to be displayed as well as retrieve the data of the days composing this month)
📆 DatePicker
👉 And then the DatePicker is the main component. It is an Input with a calendar icon that open the Calendar component on clicking.
💄 UI proposition for the DatePicker. (without the range)
🏗️ The DatePicker has the following properties :
defaultValue?: string
- the default value of the date picker that displays the current date of the Calendardisabled?: boolean
- defines whether the input is disabledformat?: DateFormat
- sets the format of the date that users can enter manuallyweekStart: Day
- the first day of the week to display the calendarrange?: boolean
- defines whether the date picker allows a range of dates to be selected . It isfalse
by default so that the user can only select one dateonChange: (date: string) => void
- callback method called when the date in the date picker changes (by selecting a date from the calendar or by entering a date manually)onRangeChange: (start: string, end: string) => void
- callback method called when the user selects a date range, or manually enters the start and end datesWith the following type :
💡 Ideas
🙏 Please do not hesitate to contribute and feel free to contribute and suggest features, design or ideas.
@fredericvilcot @ccamel @lolottetheclash @ErikssonJoakim
Two points come to my mind:
range
modeBeta Was this translation helpful? Give feedback.
All reactions