This is a simple date picker application built with React and Webpack from scratch. The application allows users to navigate through calendar and select a date.
- Display a calendar with 6 rows regardless of the number of days in the month.
- Navigate to previous and next months.
- Clickable dates that alert the selected date.
- Days outside the current month shown in gray.
You can see the live demo of the date picker here.
Find the source code on GitHub at this link.
-
After unzipping the downloaded files and open the terminal in the project directory:
cd date-picker
-
Install dependencies:
npm i
-
To start the development server, run:
npm start
-
Open your browser and navigate to http://localhost:3000 to see the application in action.
date-picker/
├── public/ # Static assets
│ ├── favicon.ico # Favicon for the application
│ └── index.html # Main HTML file serving as entry point
├── src/ # Source code for the application
│ ├── components/ # Reusable React components
│ ├── redux/ # Redux store and slices
│ ├── utils/ # Utility functions
│ ├── App.jsx # Main application component
│ ├── index.jsx # Application entry point
│ └── styles.css # Global styles for the application
├── .gitattributes # Git attributes file
├── .gitignore # Files and directories to ignore in Git
├── .prettierrc # Prettier configuration file
├── LICENSE # Project license information
├── package.json # Project metadata and dependencies
├── postcss.config.js # PostCSS configuration file
├── README.md # Project documentation
├── tailwind.config.js # Tailwind CSS configuration file
└── webpack.config.js # Webpack configuration for module bundling
The calendar component is built using React and Redux, allowing users to select dates, months, and years easily. Here’s a brief overview of its functionality:
- Date Display: The calendar displays the current date and allows users to navigate through different months and years.
- Date Selection: Users can click on a date to select it. The selected date is highlighted, and the corresponding event handler (onDateClick) is triggered.
- Dynamic Views: The calendar can switch between date, month, and year views. Users can navigate using buttons that update the current view.
- Loading State: A loading spinner is displayed while data is being fetched or processed, providing visual feedback to users.
- Responsive Design: The calendar is designed to be responsive, ensuring usability on various screen sizes.
- Redux Integration: State management is handled through Redux, allowing for centralized state updates and easier management of selected dates and views.
Here's an updated API table including all relevant properties for the components in your calendar project:
Name | Type | Default | Description |
---|---|---|---|
currentDate | object | new Date() | Date today in ISO format . |
view | string | "date" | The current view of the calendar ("date", "month", or "year"). |
currentDate | object | new Date() | The currently selected date. |
openCalendar | boolean | false | Indicates whether the calendar is open or closed. |
Name | Type | Default | Description |
---|---|---|---|
currentDate | object | new Date() | The currently selected date displayed in the header. |
view | string | "date" | The current view of the calendar ("date", "month", or "year"). |
onPrevClick | function() | - | Called when the previous button is clicked. |
onNextClick | function() | - | Called when the next button is clicked. |
onMidClick | function() | - | Called when the mid button is clicked to switch views. |
Name | Type | Default | Description |
---|---|---|---|
selectedDate | string | null | The currently selected date in ISO format. |
openCalendar | boolean | false | Indicates whether the calendar is open or closed. |
onDateChange | function(date) | - | Called when the date input changes. |
Name | Type | Default | Description |
---|---|---|---|
value | string | "" | The value displayed in the input field. |
onChange | function(event) | - | Called when the input value changes. |
onKeyDown | function(event) | - | Called on key down events for the input. |
onFocus | function(event) | - | Called when the input field is focused. |
maxLength | number | 5 | The maximum length of the input value. |
title | string | "" | The title attribute for the input field. |
Name | Type | Default | Description |
---|---|---|---|
onDateClick | function(date) | - | Called when a date in the calendar is clicked. |
currentDate | object | new Date() | The currently selected date. |
selectedDate | object | null | The date currently selected by the user. |
Name | Type | Default | Description |
---|---|---|---|
onMonthClick | function(month) | - | Called when a month is clicked. |
selectedDate | object | null | The date currently selected by the user. |
Name | Type | Default | Description |
---|---|---|---|
onYearClick | function(year) | - | Called when a year is clicked. |
currentDate | object | new Date() | The currently selected date. |
selectedDate | object | null | The date currently selected by the user. |
Name | Type | Description |
---|---|---|
day | number | The day of the month to select. |
currentDate | string | The current date object. |
dispatch | function | Redux dispatch function for state updates. |
Name | Type | Description |
---|---|---|
direction | number | The direction to change the month (-1 for previous, 1 for next). |
currentDate | string | The current date object. |
dispatch | function | Redux dispatch function for state updates. |
Name | Type | Description |
---|---|---|
year | string | The year to validate. |
month | string | The month to validate (01-12). |
day | string | The day to validate (01-31). |
In addition to the above properties, there are other API properties available in the utils folder. Each utility function has parameters with descriptions to help you understand their usage.
- React: Enables reusable UI components, improving organization and maintainability.
- Webpack: Efficiently bundles JavaScript modules and assets, enhancing performance and loading times.
- Babel: Transforms modern JavaScript and JSX into backward-compatible code for broader browser support.
- Tailwind CSS: Allows rapid styling with utility classes, promoting consistency and responsive design.
- Redux: Manages application state globally, facilitating predictable state management and easier debugging.
- Prettier: An opinionated code formatter that enforces consistent style across your codebase.
- Font Awesome: Provides a vast library of icons, enhancing UI aesthetics and functionality.
- classnames: A utility for conditionally joining class names together, simplifying dynamic class management.
Yumi Takuma