Skip to content

Commit

Permalink
Configure preferred calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmale committed Aug 22, 2023
1 parent 5e20bd7 commit 5b04af7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/framework/esm-styleguide/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export const esmStyleGuideSchema = {
_default: "#007d79",
_type: Type.String,
},
datePicker: {
preferredEthiopicLocale: {
_default: "am-AM-u-ca-ethiopic",
_type: Type.String,
preferredCalendar: {
_type: Type.Object,
_default: {
am: "ethiopic",
},
},
};
19 changes: 8 additions & 11 deletions packages/framework/esm-styleguide/src/datepicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,21 @@ export const OpenmrsDatePicker: React.FC<OpenmrsDatePickerProps> = ({
invalidText,
onChange,
}) => {
const [preferredEthiopicLocale, setPreferredEthiopicLocale] = useState();
const [preferredCalendar, setPreferredCalendar] = useState();

const locale = useMemo(() => {
if (preferredLocale) {
return preferredLocale;
}
const currentLocale = getLocale();
if (currentLocale === "am" && preferredEthiopicLocale) {
return preferredEthiopicLocale;
const currentLocale = preferredLocale || getLocale();
if (preferredCalendar?.[currentLocale]) {
return new Intl.Locale(currentLocale, {
calendar: preferredCalendar[currentLocale],
}).toString();
}
return currentLocale;
}, [preferredLocale, preferredEthiopicLocale]);
}, [preferredLocale, preferredCalendar]);

getConfigStore("@openmrs/esm-styleguide").subscribe((store) => {
if (store.loaded && store.config) {
setPreferredEthiopicLocale(
store.config["datePicker"].preferredEthiopicLocale
);
setPreferredCalendar(store.config["preferredCalendar"]);
}
});

Expand Down

0 comments on commit 5b04af7

Please sign in to comment.