Skip to content

Commit

Permalink
XS-414 Fixed issue
Browse files Browse the repository at this point in the history
  • Loading branch information
manojx031 committed Sep 16, 2024
1 parent 8b60e7b commit 16bac1e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/components/DatePicker/DatePicker.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { DayPickerProps } from "react-day-picker";
export type LocaleCode = keyof typeof locales;

interface ExtendedDayPickerProps extends DayPickerProps {
monthsShort?: string;
monthsShort?: string[];
}

export type LocalizationProps = Pick<
Expand All @@ -19,12 +19,12 @@ export type LocalizationProps = Pick<

const locales = {
en: en,
en_US: en,
en_GB: enGB,
"en-US": en,
"en-GB": enGB,

es: es,
es_ES: es,
es_MX: esMX,
"es-ES": es,
"es-MX": esMX,

fr: fr,
de: de,
Expand Down
8 changes: 6 additions & 2 deletions src/components/DatePicker/LocalizedDayPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import clsx from "clsx";
import React, { forwardRef, useContext, useEffect, useState } from "react";
import DayPicker, { DayPickerProps } from "react-day-picker";
import { kebabCase } from "lodash";
import { Context } from "../Provider";
import { getLocalizationProps, LocaleCode, LocalizationProps } from "./DatePicker.helpers";

export const LocalizedDayPicker = forwardRef<any, DayPickerProps>(({ className, ...rest }, ref) => {
const { locale } = useContext(Context);
const [localizationProps, setLocalizationProps] = useState<Partial<LocalizationProps>>({});
console.log("Locale", locale);

useEffect(() => {
setLocalizationProps({});
const localeCode = kebabCase(locale).toLowerCase();

/** We don't want any localization-related props for "English" */
if (!locale || locale === "en" || locale === "en_US") return;
if (!localeCode || localeCode === "en" || localeCode === "en-us") return;

getLocalizationProps(locale as LocaleCode).then(setLocalizationProps);
}, [locale]);

/**
* Note: DayPicker expects locale in en-US, es, en-GB format
*/
return <DayPicker ref={ref} className={clsx(className)} {...localizationProps} {...rest} />;
});

0 comments on commit 16bac1e

Please sign in to comment.