Skip to content

Commit

Permalink
Merge pull request #346 from melfore/345-datetimepicker-add-timezone-…
Browse files Browse the repository at this point in the history
…in-context

[DateTimePicker] Added Timezone in context
  • Loading branch information
CrisGrud authored Oct 6, 2023
2 parents 46abb2e + 5b8672d commit ff2d79d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/components/DateTimePicker/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ MobileView.args = { ...SecondsView.args, mobileView: true };

export const FormatAmPm = Template.bind({});
FormatAmPm.args = { ...Primary.args, ampm: true };

export const TimeZone = Template.bind({});
TimeZone.args = { ...Primary.args, timeZone: "UTC+8" };
4 changes: 3 additions & 1 deletion src/components/DateTimePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { AdapterLuxon } from "@mui/x-date-pickers/AdapterLuxon";
import { DateTimePicker as MuiDateTimePicker } from "@mui/x-date-pickers/DateTimePicker";
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";

import { useMosaicContext } from "../../hooks/useMosaicContext";
import { DateTimePickerType, viewType } from "../../types/DateTimePicker";

export const DATA_CY_DEFAULT = "timePicker";

const DateTimePicker: FC<DateTimePickerType> = ({
dataCy = DATA_CY_DEFAULT,
timeZone,
label = "Date Time",
value,
onAccept,
Expand All @@ -31,6 +31,8 @@ const DateTimePicker: FC<DateTimePickerType> = ({
}
return ["year", "month", "day", "hours", "minutes"];
}, [timeView]);

const { timeZone } = useMosaicContext();
return (
<LocalizationProvider dateAdapter={AdapterLuxon}>
<MuiDateTimePicker
Expand Down
5 changes: 4 additions & 1 deletion src/contexts/Mosaic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export type ILocalizeMethod = (key: string) => string;
interface IMosaicContextOptions {
breakpoints?: IUseViewStateOptions;
localize?: ILocalizeMethod;
timeZone?: string;
}

export interface IMosaicContext {
localize?: ILocalizeMethod;
view: IViewState;
timeZone?: string;
}

export const MOSAIC_CONTEXT_DISPLAY_NAME = "MosaicContext";
Expand All @@ -24,7 +26,8 @@ export const MosaicContextProvider: FC<PropsWithChildren<IMosaicContextOptions>>
children,
localize,
breakpoints,
timeZone,
}) => {
const view = useViewState(breakpoints);
return <MosaicContext.Provider value={{ localize, view }}>{children}</MosaicContext.Provider>;
return <MosaicContext.Provider value={{ localize, view, timeZone }}>{children}</MosaicContext.Provider>;
};
1 change: 0 additions & 1 deletion src/types/DateTimePicker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IBase } from "./Base";

export type DateTimePickerType = IBase & {
timeZone?: string;
label: string;
value?: string;
onAccept?: (value: string | null) => void;
Expand Down

0 comments on commit ff2d79d

Please sign in to comment.