Coder Social home page Coder Social logo

a-kasaaian / react-advance-jalaali-datepicker Goto Github PK

View Code? Open in Web Editor NEW
86.0 2.0 17.0 2.11 MB

An advance Jalaali (shamsi, persian) datepicker containing multiple datepicker types such as, range datepicker

License: MIT License

JavaScript 100.00%
datepicker range jalaali jalaali-datepicker persian-datepicker shamsi-date-picker shamsi-datepicker react-datepicker react-persian-datepicker picker

react-advance-jalaali-datepicker's Introduction

Advance React Date and Time Picker for jalaali (persian, shamsi) calender

It contains 3 types of jalaali (persian) date pickers, which are date and time range (from, to) picker, date range picker, date picker, and date and time picker.

این ماژول شامل ۴ نوع مختلف از باکس انتخاب تاریخ و زمان جلالی (شمسی) است. انواع باکس های انتخاب تاریخ و زمان (پیاده سازی شده تا کنون) عبارتند از: بازه تاریخ و زمان (از، تا)، بازه تاریخ (از، تا)، انتخاب تاریخ و انتخاب تاریخ زمان.

This module is written using moment-jalali, which is relied on momentjs.

Instalation

Use npm i react-advance-jalaali-datepicker in order to install the module. Yes that's it. There is no extra font or css file to include. It's designed simple to prevent any issue during customization. Customize it in the way you need.

Usage

In order to use this module, import the package into your react component and use the module as below. The below example is the code that is used in the sample usage video.

demo of react advance jalaali (persian) datepicker

import React from "react";
import {
  DatePicker,
  DateTimePicker,
  DateRangePicker,
  DateTimeRangePicker
} from "react-advance-jalaali-datepicker";
export class Home extends React.component {
  change(unix, formatted) {
    console.log(unix); // returns timestamp of the selected value, for example.
    console.log(formatted); // returns the selected value in the format you've entered, forexample, "تاریخ: 1396/02/24 ساعت: 18:30".
  }
  DatePickerInput(props) {
    return <input className="popo" {...props} />;
  }
  render() {
    return (
      <div className="datePicker">
        <DatePicker
          inputComponent={this.DatePickerInput}
          placeholder="انتخاب تاریخ"
          format="jYYYY/jMM/jDD"
          onChange={this.change}
          id="datePicker"
          preSelected="1396/05/15"
        />
        <DateTimePicker
          placeholder="انتخاب تاریخ و ساعت"
          format="تاریخ: jYYYY/jMM/jDD ساعت: HH:mm"
          id="dateTimePicker"
          onChange={this.changeTimeDate}
          preSelected="تاریخ: 1396/02/24 ساعت: 18:30"
        />
        <DateRangePicker
          placeholderStart="تاریخ شروع"
          placeholderEnd="تاریخ پایان"
          format="jYYYY/jMM/jDD"
          onChangeStart={this.change}
          onChangeEnd={this.changeTimeDate}
          idStart="rangePickerStart"
          idEnd="rangePickerEnd"
        />
        <DateTimeRangePicker
          placeholderStart="تاریخ و ساعت شروع"
          placeholderEnd="تاریخ و ساعت پایان"
          format="تاریخ: jYYYY/jMM/jDD ساعت: HH:mm"
          onChangeStart={this.change}
          onChangeEnd={this.changeTimeDate}
          idStart="rangePickerStart"
          idEnd="rangePickerEnd"
        />
      </div>
    );
  }
}

component types:

name Description
DatePicker shows a box allowing you pick just a date
DateTimePicker shows a box allowing you pick just a date and time
DateRangePicker shows a box twice, allowing you pick two dates. The first box allows you to pick the beginnig date and second one lets you pick end date
DateTimeRangePicker shows a box twice, allowing you pick two dates and time. The first box allows you to pick the beginnig date and time and second one lets you pick end date and time

Options

Each type has its' own options.

"DatePicker" and "DateTimePicker":

Name type Description
placeholder string Placeholder of the datepicker input
format string Format of showing date in the input and styled output. Accepts moment-jalali formats (required)
onChange function On change call of the input (required)
id string Adds id attribute to the input elment
preSelected string Previously selected date, it should be formatted exactly the same as the format option
customClass string To add "className" to the datepicker
inputTextAlign string Text align of the date input. default "right"
containerClass string To add "className" to the datepicker input container
monthTitleEnable boolean To add a title before month controller row
inputComponent JSX element To add customized input field to your datepicker
cancelOnBackgroundClick boolean To add background, which closes the datepicker on click event. It's customizable with class name "JDBackground"
controlValue boolean By setting to true, It will make preselected value control the input value
newThemeColor string Set the new theme colorto render new theme with the provided color. Otherwise, render the default simple theme and customize it yourself

DateRangePicker:

Name type Description
placeholderStart, placeholderEnd string Placeholder of the datepickers inputs
format string Format of showing date in the input. Applies on both inputs. Accepts moment-jalali formats (required)
onChangeStart, onChangeEnd function On change call of inputs (required)
idStart, idEnd string Add id attributes to the input elments
customClassStart, customClassEnd string To add class name to start and end dattepickers
inputTextAlign string Text align of the date input. default "right"
containerClass string To add "className" to the datepicker input container
monthTitleEnable boolean to add a title before month controller row
inputComponent JSX element To add customized input field to your datepicker
preSelectedStart string Previously selected date, it should be formatted exactly the same as the format option
cancelOnBackgroundClick boolean To add background, which closes the datepicker on click event. It's customizable with class name "JDBackground"
controlValue boolean By setting to true, It will make preselected value control the input value
renderPointer boolean Shows the pointer to the end of range, if enabled. default: true
pointer JSX element Renders the passed pointer element instead of the default one
newThemeColor string Set the new theme colorto render new theme with the provided color. Otherwise, render the default simple theme and customize it yourself

Current date

You can use current-date class to style today. In the calendar you can find today has additional class of current-date.

Outside control sample

here you can find an example of code to control input from your parent component. This example shows how to reset values by a button.

Highlight specific date

Add format of the date. Add preSelected date with the mentioned format. The day will get "selected" class. Today is containing "current-date" class name.

More

More features will be provided.

I'll be glad to help if you faced any issue. Please, report issues here.

License

MIT

react-advance-jalaali-datepicker's People

Contributors

a-kasaaian avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-advance-jalaali-datepicker's Issues

ModuleNotFoundError: Module not found: Error: Can't resolve './Partials/Styles' in '***/node_modules/react-advance-jalaali-datepicker/dist'

Hello,
Using this library I have encountered an issue when webpack is trying to bundle the module:

[21:08:17] Starting 'bundle'...
ModuleNotFoundError: Module not found: Error: Can't resolve './Partials/Styles' in '***/node_modules/react-advance-jalaali-datepicker/dist'
    at factoryCallback (***/node_modules/webpack/lib/Compilation.js:269:40)
    at factory (***/node_modules/webpack/lib/NormalModuleFactory.js:235:20)
    at resolver (***/node_modules/webpack/lib/NormalModuleFactory.js:60:20)
    at asyncLib.parallel (***/node_modules/webpack/lib/NormalModuleFactory.js:127:20)
    at ***/node_modules/webpack/node_modules/async/dist/async.js:3861:9
    at ***/node_modules/webpack/node_modules/async/dist/async.js:421:16
    at iteratorCallback (***/node_modules/webpack/node_modules/async/dist/async.js:996:13)
    at ***/node_modules/webpack/node_modules/async/dist/async.js:906:16
    at ***/node_modules/webpack/node_modules/async/dist/async.js:3858:13
    at resolvers.normal.resolve (***/node_modules/webpack/lib/NormalModuleFactory.js:119:22)

Node version: v8.11.1
NPM version: 5.8.0
React version: ^16.2.0
Webpack version: ^4.2.0

I'd be really appreciated if you help me resolve the issue.

moment.weekday return invalid number

selectedMonthFirstDay: moment(
moment().format("jYYYY") + "/" + moment().format("jMM") + "/01",
"jYYYY/jMM/jDD"
).weekday()
notice:
moment("1398/10/01", "jYYYY/jMM/jDD").weekday() return 1 with loadPersian and return 0 without loadPersion but must be 2

Appears to be a git repo or submodule.

hi,
when i run "npm i" command on my machine, i get bellow error:

verbose stack Error: /var/www/----------/node_modules/react-advance-jalaali-datepicker:

the full log is:

62 verbose stack Error: /var/www/--------/node_modules/react-advance-jalaali-datepicker: Appears to be a git repo or submodule.
62 verbose stack at /usr/share/npm/node_modules/npm-install-checks/index.js:138:15
62 verbose stack at callback (/usr/share/nodejs/graceful-fs/polyfills.js:295:20)
62 verbose stack at FSReqWrap.oncomplete (fs.js:154:5)
63 verbose cwd /var/www/--------
64 verbose Linux 5.4.0-90-generic
65 verbose argv "/usr/bin/node" "/usr/bin/npm" "audit" "fix"
66 verbose node v10.19.0
67 verbose npm v6.14.4
68 error code EISGIT
69 error path /var/www/--------/node_modules/react-advance-jalaali-datepicker
70 error git /var/www/--------/node_modules/react-advance-jalaali-datepicker: Appears to be a git repo or submodule.
71 error git /var/www/--------/node_modules/react-advance-jalaali-datepicker
72 error git Refusing to remove it. Update manually,
72 error git or move it out of the way first.
73 verbose exit [ 1, true ]

  • OS: [Ubuntu 20.04.3]
  • react : [17.0.2]
  • Node : [v10.19.0]
  • npm : [6.14.4]

update the deprecated core-js

npm WARN deprecated [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.

npm ls core-js
-- [email protected] -- @babel/[email protected]
`-- [email protected]

Cant change minute when i don't wanna change hour

hi .thanks for this package
i have a problem with DateTimePicker .
when i want change just minute i cant change that because i must change hour first and then change minutes . but sometimes that default hour is exactly that hour i want so i should change hour to another time then change that hour again to previous hour and then change minutes .
please fix this bug . thank you

Request for Enhancement: Close Calendar When Clicked Outside Input

hi,
I hope this message finds you well. I wanted to bring to your attention an enhancement request.
Currently, when a user clicks on the input of datalist and the calendar opens, there is no built-in functionality to close the calendar when the user clicks outside of the input.
I believe it would greatly improve the user experience if the calendar automatically closes when the user interacts outside of the input area.

Dynamic preSelected date

hi
i want to load the preselected date form an api .
so i write preSelected={this.state.birthDate}
but i does not show the date

React Native version

Hello, Thanks for creating this library,
Do you have React Native version of this library to use in Android & IOS apps?
Do you have any plan to create that?

types for typescript?

seems there is not any types for this package , is there any future plan to add this :
@types/react-advance-jalaali-datepicker ?????

type a date

i want to have a option that user can types their date in datepickers. how can i change that?

Input can not be cleared!

Hi, Thanks for your useful component
The problem that I've faced into, is that it's impossible to clear the chosen date from the input! also Backspace and Delete buttons f keyboard not working!
I'm using it on a filtering page, so I need it to be cleared if client want to.
I also tried to add an external button which change the state and change the this.state.ChosenDate to an empty string, but I cannot change the input value grammatically! even with preSelected={this.state.ChosenDate} and controllValue={true}

Error clearing the TextBox(s) value of DateRangepicker

How to clear the TextBox(s) value of DateRangepicker?

Uncaught Error: Invalid Jalaali year -100721
at jalCal (index.js:95)
at d2j (index.js:157)
at Object.toJalaali (index.js:28)
at toJalaali (index.js:871)
at F.push../node_modules/moment-jalaali/index.js.jMoment.fn.jYear (index.js:595)
at F.jYYYY (index.js:77)
at Object.jYYYYjMMjDD (index.js:238)
at F.push../node_modules/moment-jalaali/index.js.jMoment.fn.format (index.js:578)
at JDatePicker.componentDidUpdate (index.js:145)
at commitLifeCycles (react-dom.development.js:18130)
at commitAllLifeCycles (react-dom.development.js:19674)
at HTMLUnknownElement.callCallback (react-dom.development.js:147)
at HTMLUnknownElement.sentryWrapped (index.js:3848)
at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
at invokeGuardedCallback (react-dom.development.js:250)
at commitRoot (react-dom.development.js:19898)
at react-dom.development.js:21446
at Object.unstable_runWithPriority (scheduler.development.js:255)
at completeRoot (react-dom.development.js:21445)
at performWorkOnRoot (react-dom.development.js:21368)
at performWork (react-dom.development.js:21273)
at performSyncWork (react-dom.development.js:21247)
at interactiveUpdates$1 (react-dom.development.js:21532)
at interactiveUpdates (react-dom.development.js:2268)
at dispatchInteractiveEvent (react-dom.development.js:5086)
at HTMLDocument.sentryWrapped (index.js:3848)

SUGGESTION:
https://github.com/A-Kasaaian/react-advance-jalaali-datepicker/blob/master/src/index.js
Line 68: preSelected.length > 1
? moment(preSelected, this.props.format).format("jYYYYjMMjDD")
: "",

disable some dates

hi
how can i to disable some days in some month
i mean that user could not pick it

thanks alot

Cannot read properties of undefined (reading 'value') when selecting hour

When using date time picker, As I want to choose time ( only hour ) , I receive an error stating that it Cannot read properties of undefined (reading 'value').

Error origin : node_modules\react-advance-jalaali-datepicker\dist\Partials\TimePicker.js (124:0)

  1. add date time picker to your page.
  2. Click on time.
  3. Select hour section.
  4. choose an hour.
  5. See error.
  • OS: Windows 10
  • Browser: Chrome latest version
  • React Version 18.2.0

Can't choose hour 00 AND can't choose minute 00

in DateTimePicker when we choose minute or hour 00, the DateTimePicker showes error "دقیقه حداکثر ۶۰ باشد"
react-advance-jalaali-datepicker/src/Partials/TimePicker.js
react-advance-jalaali-datepicker/dist/Partials/TimePicker.js

if( houraInt > 0 && houraInt < 24){
                if( minuteInt > 0 && minuteInt < 60){

should be

if( houraInt >= 0 && houraInt < 24){
                if( minuteInt >= 0 && minuteInt < 60){

آپدیت

سلام من ماژول شمارو نصب کردم قبلا و الان میخوام آپدیتش کنم تا از امکاناتی مثل cancelOnBackgroundClick استفاده کنم
اما با دستور
npm i react-advance-jalaali-datepicker
آپدیت نمیشه و پکیچ را هم که دانلود میکنم و بجای قبلی کپی میکنم بعد از استارت مجدد با ارور
Invalid Jalaali year -100721
مواجه میشم.
لطفا به بنده کمک کنید
سپاس

DateTimeRangePicker preSelected

hi I want to have preSelected values for DateTimeRangePicker how should I use it?
and also want to choose date by clicking on it not on accept button also close picker by clicking on any where not only cancel cancel button
thanks

change the style

would you please tell me how to add my custom style?
I import my style.js, but it will not work.

Thanks so much

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.