Giter Site home page Giter Site logo

amir2mi / antd-jalali Goto Github PK

View Code? Open in Web Editor NEW

This project forked from saeedrahimi/antd-jalali

1.0 0.0 1.0 381 KB

A wrapper for ant-design date picker and calendar to support Jalali calendar type

Home Page: https://saeedrahimi.github.io/antd-jalali/

JavaScript 29.05% TypeScript 63.54% HTML 7.41%

antd-jalali's Introduction

npm (scoped with tag) npm

Ant-Design Jalali DatePicker

A wrapper for ant-design date picker and calendar to support Jalali calendar type with Day.js and jalaliday

Demo

https://saeedrahimi.github.io/antd-jalali/

Next.js example

Repo: https://github.com/saeedrahimi/nextjs-antd-jalali-example Live Demo: https://nextjs-antd-jalali-example.vercel.app/

Installation

npm i antd-jalali

Usage

import React from "react";
import ReactDOM from "react-dom";
import { DatePicker, ConfigProvider } from "antd";
import { DatePicker as DatePickerJalali, Calendar, JalaliLocaleListener } from "antd-jalali";
import fa_IR from "antd/lib/locale/fa_IR";
import en_US from "antd/lib/locale/en_US";
import "antd/dist/antd.css";
import "./index.css";

ReactDOM.render(
    <div className="App">
        Gregorian: <DatePicker />
        <br />
        <br />
        <ConfigProvider locale={fa_IR}  direction="rtl">
          <JalaliLocaleListener/>
           Jalali: <DatePickerJalali />
           Jalali RangePicker: <DatePickerJalali.RangePicker />
           <br />
           <br />
           <Calendar />
        </ConfigProvider>
    </div>,
  document.getElementById("root")
);

How to set value

You should pass dayjs object with jalali calendar

import dayjs from 'dayjs'
import { DatePicker as DatePickerJalali, Calendar as CalendarJalali, useJalaliLocaleListener } from "antd-jalali";

// You should call this hook in child component of <ConfigProvider>
// You can also use component helper for this hook <JalaliLocaleListener> 
useJalaliLocaleListener();

// If you want to all new instanses of dayjs use jalali calendar (no matter what is the locale), 
// you can set default calendar for dayjs and remove useJalaliLocaleListener hook.
dayjs.calendar('jalali');

const date = dayjs("1399-01-01", {jalali:true});

<DatePickerJalali defaultValue={date}/>
<CalendarJalali  value={date}/>

also you can create a jalali date without changing default calendar

const date = dayjs()
const jalaliDate = date.calendar('jalali')

You can read more information about daysjs jalali on jalaliday repo.

antd-jalali's People

Contributors

saeedrahimi avatar mohas avatar

Stargazers

Reza Askari avatar

Forkers

rezsk

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.