Skip to content

Commit

Permalink
Merge branch 'fix/datepicker-locales' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Sep 6, 2024
2 parents 7bed715 + 3e4c4b0 commit bd39040
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/common/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Field from "@/common/Field";
import { WidgetProps } from "@/types";
import { Date as DateOoui } from "@gisce/ooui";
import dayjs from "@/helpers/dayjs";
import { useDatePickerLocale } from "@/helpers/useDatePickerLocale";
const { useToken } = theme;

type DatePickerProps = WidgetProps & {
Expand Down Expand Up @@ -48,6 +49,7 @@ const DatePickerInput: React.FC<DatePickerInputProps> = (
const { value, onChange, ooui, showTime } = props;
const { id, readOnly, required } = ooui as DateOoui;
const { token } = useToken();
const datePickerLocale = useDatePickerLocale();

const requiredStyle =
required && !readOnly
Expand Down Expand Up @@ -91,6 +93,7 @@ const DatePickerInput: React.FC<DatePickerInputProps> = (
showNow={false}
showToday={false}
changeOnBlur={true}
locale={datePickerLocale}
/>
);
};
Expand Down
15 changes: 15 additions & 0 deletions src/helpers/useDatePickerLocale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import enUS from "antd/es/date-picker/locale/en_US";
import esES from "antd/es/date-picker/locale/es_ES";
import caES from "antd/es/date-picker/locale/ca_ES";
import { useLocale } from "@gisce/react-formiga-components";

const antdLocales = {
en_US: enUS,
es_ES: esES,
ca_ES: caES,
};

export const useDatePickerLocale = () => {
const { locale } = useLocale();
return antdLocales[locale];
};
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import ActionView from "./views/ActionView";
import { ErpAllFeatureKeys, ErpFeatureKeys } from "./models/erpFeature";
import type { ErpFeaturesMap } from "./models/erpFeature";
import { GraphCard } from "./widgets/views/Graph";
import dayjs from "./helpers/dayjs";

export {
Button,
Expand Down Expand Up @@ -173,4 +174,5 @@ export {
ConfigContextProvider,
HTMLPreview,
Alert,
dayjs,
};
5 changes: 4 additions & 1 deletion src/widgets/views/searchFilter/DateRangePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { DatePicker } from "antd";

import React from "react";
import Field from "@/common/Field";
import { WidgetProps } from "@/types";
import { useDatePickerLocale } from "@/helpers/useDatePickerLocale";

export const DateRangePicker = (props: WidgetProps) => {
const datePickerLocale = useDatePickerLocale();

return (
<Field {...props} layout={"vertical"}>
<DatePicker.RangePicker
allowEmpty={[true, true]}
format={"DD/MM/YYYY"}
locale={datePickerLocale}
></DatePicker.RangePicker>
</Field>
);
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/views/searchFilter/DateTimeRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { Field as FieldOoui, Label as LabelOoui } from "@gisce/ooui";
import { WidgetProps } from "@/types";
import Label from "@/widgets/base/Label";
import { TimePicker } from "../../../common/TimePicker";
import { useDatePickerLocale } from "@/helpers/useDatePickerLocale";

export const DateTimeRangePicker = (props: WidgetProps) => {
const { ooui, showLabel = false } = props;
const { label, id } = ooui;
const datePickerLocale = useDatePickerLocale();

const fields = [
new FieldOoui({
Expand Down Expand Up @@ -42,6 +44,7 @@ export const DateTimeRangePicker = (props: WidgetProps) => {
className="w-60"
allowEmpty={[true, true]}
format={"DD/MM/YYYY"}
locale={datePickerLocale}
></DatePicker.RangePicker>
</Field>
</Col>
Expand Down

0 comments on commit bd39040

Please sign in to comment.