mui-ethiopian-datepicker
v0.3.2
Published
An Ethiopian date picker component designed for React applications. Built on top of Material-UI.
Downloads
497
Readme
MUI Ethiopian DatePicker
Current Version: 0.3.2
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.
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.