Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XS-414 weekdays bug fix and removed unnecessary console log #348

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xola/ui-kit",
"version": "2.3.12",
"version": "2.3.13",
"description": "Xola UI Kit",
"license": "MIT",
"repository": {
Expand Down
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are getting the locale in en-US format, not in en_US format. and english locale object won't have weekdays key in the locale obj, so getting the issue .weekdays doesn't exist.


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} />;
});
Loading