Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-time-picker-digital

HosseinAzadpour355MIT0.5.3

This advanced, fully-responsive digital time picker library is designed to provide a seamless and dynamic time selection experience for modern web applications. Whether you're building an application for international users or aiming for an elegant and in

react, react-component, ui, component, javascript, js, react time picker, digital time picker, time picker component, English and Persian time picker, responsive time picker, time picker UI, customizable theme, date and time picker, react widget, easy to use time picker, open source time picker, clock component, digital time picker UI, react time picker widget, bilingual time picker, mobile-friendly time picker

readme

TimePicker Demo

⏰ TimePicker

This advanced, fully-responsive digital time picker library is designed to provide a seamless and dynamic time selection experience for modern web applications. Whether you're building an application for international users or aiming for an elegant and intuitive design, this library offers everything you need to manage time selection effortlessly.

Table of Contents

Installation

You can install the package using npm or yarn:

npm install react-time-picker-digital

or

yarn add react-time-picker-digital

Introduction

TimePicker is a versatile and user-friendly React component designed to allow users to select time easily. With its intuitive interface and responsive design, TimePicker ensures a seamless experience across all devices.


Key Features:

Bilingual Support: TimePicker supports both English and Persian languages, making it accessible for a wider audience.
Responsive Design: The component adapts to various screen sizes and devices, ensuring a consistent user experience whether on mobile or desktop.
Customizable Color Options: Choose from a variety of color options to match your application's design and theme.
Smooth Scrolling: Navigate through hours and minutes with smooth scrolling functionality.
Easy Integration: Simply import the component and use it in your project with minimal
Customizable Scroll and UI Behavior: Fine-tune the scroll behavior, the appearance of time elements, and even the active item’s color to match your application’s style. This level of customization helps ensure that the time picker fits perfectly within your app's design.
Seamless User Experience: From dynamic language switching to intuitive time scrolling, every detail of the user interface is crafted to provide an effortless and engaging user experience. Users can interact with the time picker with minimal effort and enjoy a modern, stylish interface.

Features

  • Customizable Styling: Adjust the appearance of the time picker with customizable properties such as activeColor, backgroundColor, textColor, and numbersColor to match your design needs.
  • Language Support: The component supports both English and Persian (fa). It automatically adjusts text and layout direction based on the selected language.
  • Responsive Design: The time picker is designed to be responsive and works well across different screen sizes and devices.
  • Smooth Scrolling: The hour and minute selectors scroll smoothly, providing a seamless user experience.
  • Active State Highlighting: The selected hour and minute are highlighted to give users clear feedback on their choices.
  • Parent Communication: The data function allows you to send the selected hour and minute back to the parent component.
  • Navigation Links: Easily navigate between pages with customizable cancelPage and confirmPage links.

What's New

v0.2.8

  • Fixed several bugs.

v0.2.9

  • Fixed bundle.js bugs.

v0.3.0

  • Fixed useRef issues.

v0.5.1

  • Fixed useRef issues.
  • Improved and rebuild structure.
  • Improve functions and constants name .
  • Added constant file to store constant datas such as hours and minutes.

v0.5.2

  • Enhanced Safety Checks.
  • Implemented Optional Chaining (?.).
  • Optimized Query Selection.
  • Added Cleanup (return function).
  • Improved Event Listener Logic.

v0.5.3

  • Simplifying Hours and Minutes.
  • Creating Custom Hooks.
  • Code Cleanup.
  • Implementing Tailwind CSS.
  • Benefits of the Changes.

For more details, see CHANGELOG.md.

Example

Here is an example of how to use the TimePicker component in your React application:


import React, { useState } from "react";
import { TimePicker } from "react-time-picker-digital";

function App() {
  var [hour, setHour] = useState();
  var [minute, setMinute] = useState();
  function handleData(data) {
    setHour(data.hour);
    setMinute(data.minute);
    console.log("hour", hour);
    console.log("minute", minute);
  }

  return (

      <TimePicker
        backgroundColor={"black"}
        activeColor={"crimson"}
        textColor={"black"}
        numbersColor={"gray"}
        language={"en"}
        cancelPage={"/"}
        confirmPage={"/about"}
        data={handleData}
      />

  );
}

export default App;

props

Prop Type Default Description data function Required Function to send the selected time to the parent. cancelPage string Required Link to the previous page. confirmPage string Required Link to the next page.

Prop Type Default Description
data function Required A callback function to send the selected hour and minute to the parent component.
cancelPage string Required The URL to navigate to when the back button is clicked.
confirmPage string Required The URL to navigate to when the confirm button is clicked.
language string "en" Determines the language of the timepicker. The user can select between Persian ('fa') and English ('en').
activeColor string "#2088B4" Sets the color theme of the timepicker selected hour and minute. The user can select any valid CSS color.
backgroundColor string "#fff" Sets the color theme of the timepicker background color. The user can select any valid CSS color.
textColor string "#000000" Sets the color theme of the timepicker text color. The user can select any valid CSS color.
numbersColor string "#bababa" Sets the color theme of the timepicker numbers list color. The user can select any valid CSS color.

Tips and Tricks

Smooth Scrolling: Ensure that your container has sufficient height to enable smooth scrolling. Adjust CSS styles if you encounter performance issues.
Custom Styling: Use the activeColor, backgroundColor, textColor, and numbersColor props to tailor the appearance of the time picker to match your application's theme.
Language Direction: The component automatically adjusts text direction based on the selected language. For right-to-left languages (like Persian), the layout will adapt accordingly.
Initial Values: If you want to set default values for the hour and minute, consider using the scrollTo method in useEffect to programmatically set the initial scroll position.
Testing: When testing the component, ensure to test across different devices and screen sizes to confirm that the responsive design works as expected.

FAQ

Q: How do I customize the appearance of the time picker?
A: You can customize the appearance using the activeColor, backgroundColor, textColor, and numbersColor props. These allow you to set colors for different elements within the time picker.
Q: What languages are supported by the time picker?
A: The time picker supports English and Persian. You can switch between these languages using the language prop.
Q: Can I use the time picker in a non-React project?
A: The time picker is built for React and requires React to be installed in your project. For non-React projects, you may need to find or build an alternative component.
Q: How do I handle the selected time data?
A: The selected time data is passed to the data callback function when the user confirms their selection. The data will include the selected hour and minute.
Q: What should I do if the component is not rendering correctly?
A: Ensure that the component is correctly imported and that all required props are provided. Check the console for any errors and make sure that your environment meets the necessary requirements.

Contributing

Contributions are welcome! Please create an issue or a pull request.

Contact Information

For any questions or feedback, please contact me via:

Email: [hossein.azp94@gmail.com]

LinkedIn: [https://www.linkedin.com/in/hosseinazadpour]

License

This project is licensed under the MIT License - see the LICENSE file for details.

https://github.com/HosseinAzadpour/react-time-picker-digital

changelog

Changelog

[0.2.6] - 2025-03-03

Fixed

  • Resolved multiple bugs that could cause crashes in specific scenarios.
  • Improved error handling to enhance stability.

Removed

  • Eliminated unnecessary dependencies to reduce package size.
  • Cleaned up unused code and redundant functions.

Improved

  • Optimized internal processes for better performance and efficiency.
  • Reduced memory usage and improved execution speed.

[0.2.7] - 2025-03-03

Fixed

  • Resolved multiple bugs.

Added

  • Added emojis throughout the entire README file to improve visual presentation and make the documentation more engaging.

[0.2.8] - 2025-03-03

Fixed

  • Resolved multiple bugs.

[0.2.9] - 2025-03-03

Fixed

  • Resolved the issue where bundle.js was not being generated properly, causing the error when using the library.
  • Updated webpack configuration to ensure proper output and avoid "No such file or directory" errors when using the package.

[0.3.0] - 2025-03-03

Fixed

  • Resolved the issue where useRef was not properly updating the reference value, causing unexpected behavior in the component.
  • Adjusted the logic to ensure that the reference is correctly maintained across renders, preventing any inconsistencies in the state.

[0.5.1] - 2025-03-03

Fixed

  • Resolved the issue where useRef was not properly updating the reference value, causing unexpected behavior in the component.
  • Adjusted the logic to ensure that the reference is correctly maintained across renders, preventing any inconsistencies in the state.

Improved

  • Improved and rebuild structure.
  • Improve functions and constants name .

Added

  • Added constant file to store constant datas such as hours and minutes.

Removed

  • Webpack Removed

[0.5.2] - 2025-03-03

Fixed

  • Enhanced Safety Checks: Added if conditions to ensure hourEl.current and minuteEl.current exist before calling .scrollTo(), preventing potential runtime errors.
  • Optimized Query Selection: Stored document.querySelector(":root") in a variable to avoid redundant DOM queries and improve performance.
  • Implemented Optional Chaining (?.): Prevented potential crashes by ensuring document.querySelectorAll("#hour")[activeHourIndx]?.offsetTop || 0 handles out-of-range indices gracefully.
  • Expanded Dependency Array: Included activeHourIndx, activeMinuteIndx, activeColor, backgroundColor, numbersColor, and textColor to ensure proper reactivity in useEffect().
  • Added Cleanup (return function): Prevents memory leaks by properly removing event listeners when the component unmounts and Ensures that duplicate event listeners are not added on re-renders.
  • Improved Event Listener Logic: Now, scroll events are only added if hourEl.current and minuteEl.current exist and Prevents errors caused by missing references.

[0.5.3] - 2025-11-03

Improved

Optimized Hour and Minute Management:

  • Streamlined active hour and minute index management for better performance and easier integration with the app.
  • Simplified the structure for hours and minutes, reducing unnecessary complexity. Code Cleanup and Readability:
  • Divided the code into smaller, more manageable parts to improve maintainability and understanding.
  • Removed redundant code by consolidating similar tasks into functions and custom hooks.
  • Improved variable and function names to make the codebase easier to read. Performance Enhancements:
  • Faster and smoother user interactions due to optimizations.
  • Reduced page load time, improving overall performance. Tailwind CSS Implementation:
  • Applied Tailwind's @apply directive to style various elements of the time picker, reducing CSS size and boosting performance.
  • Implemented responsive design to ensure the app displays properly across all screen sizes.
  • Centralized color and design property management through custom variables in the Tailwind config file. Simplified State Management:
    • State handling is now simpler and more efficient, leading to an improved user experience.

Added

Custom Hooks:

  • Introduced the useTimeScroller hook to manage scrolling of hours and minutes, automatically scrolling to the active item based on its index. Benefits of Using Hooks:
  • Reduced complexity in components by encapsulating logic into reusable hooks.
  • Reusable hooks make the codebase more maintainable and reduce duplication.

Fixed

Scroll Management:

  • The scrolling issue for active hours and minutes was fixed to ensure the active items are always brought into view correctly.

Removed

Redundant Code:

  • Removed duplicate functions and unnecessary code blocks that were previously scattered throughout the application. Complexity:
  • Eliminated unnecessary complexity in the hour and minute management logic, improving the flow and readability of the code.

Changed

User Interface Design:

  • Updated the design to be fully responsive, ensuring the application works seamlessly on different devices and screen sizes.
  • Adjusted font sizes and layout properties for better viewing on mobile, tablet, and desktop devices.

Miscellaneous

Support for All Devices:

  • Ensured the app is now fully compatible with all devices, providing a consistent experience across desktop, tablet, and smartphone.