npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-jalali-datepicker

v0.2.66

Published

a Simple and Flexible Datepicker for react and react-native

Downloads

145

Readme

React Jalali Datepicker

Rangepicker

This package is all about datepickers for react and new features of it will release very soon like SinglePicker, InputPicker and so on!

The General Idea

This datepicker component has been developed in a way that currenly supports the Jalaali and global Gregorian calendars and the base idea was to provide a prop called isJalaali, wich will accept a Boolean, to datepicker to keep track of usage for that!

components

  • RangePicker
  • SinglePicker - currently in development
  • InputPicker - currenly in development

RangePicker

This component main use case is for selecting a range from datepicker. our date picker has two locale which is based on Jalaali and Gregorian style whcih can be modefined by isJalaali prop that is been passed to RangePicker component. a simple use case of that would be like below:

import { RangePicker } from "react-jalali-datepicker";

const YourComponent = () => {
  return (
    <section>
      <RangePicker isJalaali={true} />
    </section>
  );
};

this will give you the Rangepicker Component to use!

How to get Date out of this picker?

there is a prop that os been shipped with this component called onChangeRange, which will accpet a function. the function will recieve an argument called selectedRange which is an Object that contains two keys:

  • startDate - selected start date, default will be null
  • stopDate - selected stop date, default will be null

these are the selected range that is being selected from range picker! you can do what ever you want to do with them like save in state or send it through api call or what ever you want to do with it!

a simple use case is like below where we just destructure the startDate and stopDate from selectedRange argument that is being passed to our handler and log it to the console:

import { RangePicker } from "react-jalali-datepicker";

const YourComponent = () => {
  // you can use `useCallback` here, but i just kept it simple
  const rangeHandler = ({ startDate, stopDate }) => {
    console.log("ON_CHANGE_RANGE: ", { startDate, stopDate });
  };

  return (
    <section>
      <RangePicker isJalaali={true} onChangeRange={rangeHandler} />
    </section>
  );
};

how to disable days before today?

RangePicker component has a handy prop called shouldDisableBeforeToday which recieves a Boolean indicates that should the days before today be disabled or not! simple use case would be like below:

import { RangePicker } from "react-jalali-datepicker";

const YourComponent = () => {
  // you can use `useCallback` here, but i just kept it simple
  const rangeHandler = ({ startDate, stopDate }) => {
    console.log("ON_CHANGE_RANGE: ", { startDate, stopDate });
  };

  return (
    <section>
      <RangePicker isJalaali={true} shouldDisableBeforeToday={true} />
    </section>
  );
};

how to show more month in table?

there is a props called numberOfMonths which most of the datepickers has these days, which will get a Number and it shows the number of monthes since today, for example if we are in May and the passed number was 2 the the rangepicker shows the May and June.

how to pass default selected range?

there is a props called defaultSelectedRange which will recieve an Object type with this shape:


  {
    startDate: null,
    stopDate: null
  }

keep in mind these important points

  1. the date might be in this format all time YYYY-MM-DD
  2. if your isJalaali prop is true you might pass date in Jalaali format like 1399-3-12 and in contrast if your isJalaali is false you might pass date in Gregorian format like 2020-5-25(also you can skip the leading 0 befor day and month it the day ot month has only one character); and for that you might have a mechanisem that keeps track of isJalaali and based on isJalaali it will give the proper values, you may need moment-jalaali for that to handle it in your side! and also note that there are some utils function like converDate which you can pull from package to handle this part a simple useCase is like below:
import { convertDate, DATE_FORMATS } from "react-jalali-datepicker";

const gregDate = "2020-5-25";
const jalaaliDate = "1399-3-5";
const { GEORGIAN_DATE_FORMAT, JALAALI_DATE_FORMAT } = DATE_FORMATS;
const resultInJalaali = convertDate({ gregDate, GEORGIAN_DATE_FORMAT });
const resultInGregorian = convertDate({ jalaaliDate, GEORGIAN_DATE_FORMAT });

console.log(resultInJalaali); // 1399-3-5
console.log(resultInGregorian); // 2020-5-25

some features of RangePicker component

  1. if you had a button that keeps track of isJalaali prop to convert tha datepicker type to Jalaali or Gregorian, the Rangepicker component wont lost the selected range between type cahnges, you alweays have your selected range in proper format!
  2. you can put some custome styles on you rangepicker to make it fully custome! since it written in BEM, you can keep track of .range-picker class and replace the subsequent classnames. just inspect and get the classnames to see what i mean, i will put the classnames here as soon as possible!

I will update the documentation as soon as it is possible, jut DM me or find me on social with @a_m_dev!