0.3.0 • Published 2 days ago

mui-ethiopian-datepicker v0.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 days ago

MUI Ethiopian DatePicker

Current Version: 0.2.9

mui-ethiopian-datepicker is a React component for selecting Ethiopian dates. It's built on top of Material-UI and provides a culturally tailored date picker experience integrated seamlessly with other MUI components.

Screenshot of DatePicker

Installation

You can install the package using npm:

npm install mui-ethiopian-datepicker

Peer Dependencies

"peerDependencies": {
  "@emotion/react": "^11.11.0",
  "@emotion/styled": "^11.11.0",
  "@mui/icons-material": "^5.14.6",
  "@mui/material": "^5.14.6",
  "@mui/x-date-pickers": "^6.11.2",
  "date-fns": "^2.30.0",
  "react": "^18.2.0",
  "react-dom": "^18.2.0"
}

You can install them using:

npm install @mui/icons-material @mui/material @mui/x-date-pickers date-fns react react-dom

Usage

Basic Usage with EtDatePicker

import React, { useState } from "react";
import EtDatePicker from "mui-ethiopian-datepicker";

function MyComponent() {
  const [date, setDate] = useState(null);

  return (
    <EtDatePicker
      label="Document Date"
      onChange={(selectedDate: Date) => {
        setDate(selectedDate);
      }}
      value={date}
      minDate={new Date("2023-08-20")}
      maxDate={new Date("2023-08-26")}
      
      // other TextField props here, except InputProps
    />
  );
}

Localization Support in Version 0.1.7

Starting from version 0.1.7, mui-ethiopian-datepicker introduces localization support for different Ethiopian localizations. This feature allows a more tailored experience for users.

1. First, you need to import the EtLocalizationProvider from the mui-ethiopian-datepicker package.

import { EtLocalizationProvider } from 'mui-ethiopian-datepicker';

2. Wrap Your Application or Component:

Use the EtLocalizationProvider to wrap your entire application or just the section where the date picker is used. This will ensure that all date pickers within this context are localized.

function MyApp({ children }) {
  return (
    <EtLocalizationProvider localType="AMH">
      {children}
    </EtLocalizationProvider>
  );
}

3. Configure the Localization Provider:

The EtLocalizationProvider accepts the following props to configure the localization:

localType: This can be set to "AMH" (Amharic), "AO" (Afan Oromo), or "CUSTOM". It defines the type of localization you want to apply. "AMH" and "AO" are predefined localizations, while "CUSTOM" allows for more personalized configurations.

getLocalMonthName: This optional function is used only when localType is set to "CUSTOM". It allows you to provide a custom function to return the name of the month based on the month number.

function MyApp() {
  const getCustomMonthName = (month: number) => {
    // Define custom month names
    const customMonthNames = ["Custom Month 1", "Custom Month 2", ...];
    return customMonthNames[month - 1];
  };

  return (
    <EtLocalizationProvider localType="CUSTOM" getLocalMonthName={getCustomMonthName}>
      {children}
    </EtLocalizationProvider>
  );
}

Using EtDateViewer

import { EtDateViewer } from "mui-ethiopian-datepicker";

<EtDateViewer date={new Date()}  sx={{ color: "red" }} variant="h6" />

EthiopianDateUtil

EthiopianDateUtil is a utility module that provides various functions for working with Ethiopian dates. Here are some of the key functionalities:

Creating an Ethiopian Date

import { EthiopianDate } from 'mui-ethiopian-datepicker';

const date = EthiopianDate.createEthiopianDateFromParts(23, 7, 2013);

Convert To and From Gregorian

import { EthiopianDate } from 'mui-ethiopian-datepicker';

const etDate = EthiopianDate.toEth(new Date());
const grDate = EthiopianDate.toGreg(etDate);

Getting Ethiopian Months

import { EthiopianDate } from 'mui-ethiopian-datepicker';

const months = EthiopianDate.ethMonths;

Examples

Convert a Gregorian Date to Ethiopian Date

const etDate = EthiopianDate.toEth(new Date());

Convert an Ethiopian Date to Gregorian Date

const grDate = EthiopianDate.toGreg({ Day: 23, Month: 7, Year: 2013 });

Get the Names of Ethiopian Months

const months = EthiopianDate.ethMonths;

For more functionalities, refer to the source code.

Support and Contributions

Feel free to open issues or PRs if you find any problems or have suggestions for improvements.

0.3.0

2 days ago

0.2.9

25 days ago

0.2.8

25 days ago

0.2.7

1 month ago

0.2.6

1 month ago

0.2.5

5 months ago

0.2.1

5 months ago

0.2.0

5 months ago

0.1.8

5 months ago

0.1.7

5 months ago

0.1.9

5 months ago

0.2.3

5 months ago

0.2.2

5 months ago

0.1.6

7 months ago

0.2.4

5 months ago

0.1.5

7 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.4

8 months ago

0.1.3

9 months ago

0.1.0

9 months ago