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.
You can install the package using npm:
npm install mui-ethiopian-datepicker
"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
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
/>
);
}
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.
import { EtLocalizationProvider } from 'mui-ethiopian-datepicker';
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>
);
}
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>
);
}
import { EtDateViewer } from "mui-ethiopian-datepicker";
<EtDateViewer date={new Date()} sx={{ color: "red" }} variant="h6" />
EthiopianDateUtil
is a utility module that provides various functions for working with Ethiopian dates. Here are some of the key functionalities:
import { EthiopianDate } from 'mui-ethiopian-datepicker';
const date = EthiopianDate.createEthiopianDateFromParts(23, 7, 2013);
import { EthiopianDate } from 'mui-ethiopian-datepicker';
const etDate = EthiopianDate.toEth(new Date());
const grDate = EthiopianDate.toGreg(etDate);
import { EthiopianDate } from 'mui-ethiopian-datepicker';
const months = EthiopianDate.ethMonths;
const etDate = EthiopianDate.toEth(new Date());
const grDate = EthiopianDate.toGreg({ Day: 23, Month: 7, Year: 2013 });
const months = EthiopianDate.ethMonths;
For more functionalities, refer to the source code.
Feel free to open issues or PRs if you find any problems or have suggestions for improvements.