diff --git a/src/CAREUI/interactive/Zoom.tsx b/src/CAREUI/interactive/Zoom.tsx new file mode 100644 index 00000000000..bf5747f9b91 --- /dev/null +++ b/src/CAREUI/interactive/Zoom.tsx @@ -0,0 +1,97 @@ +import { createContext, ReactNode, useContext, useState } from "react"; +import ButtonV2 from "../../Components/Common/components/ButtonV2"; +import CareIcon from "../icons/CareIcon"; + +type ProviderValue = { + scale: number; + zoomIn: () => void; + zoomOut: () => void; +}; + +const ZoomContext = createContext(null); + +type Props = { + initialScale?: number; + scaleRatio?: number; + children: ReactNode; +}; + +export const ZoomProvider = ({ + initialScale = 1, + scaleRatio = 1.25, + children, +}: Props) => { + const [scale, setScale] = useState(initialScale); + + return ( + setScale((scale) => scale * scaleRatio), + zoomOut: () => setScale((scale) => scale / scaleRatio), + }} + > + {children} + + ); +}; + +export const ZoomTransform = (props: { + children: ReactNode; + className?: string; +}) => { + const ctx = useContext(ZoomContext); + + if (ctx == null) { + throw new Error("Component must be used with ZoomProvider"); + } + + return ( +
+ {props.children} +
+ ); +}; + +export const ZoomControls = (props: { disabled?: boolean }) => { + const ctx = useContext(ZoomContext); + + if (ctx == null) { + throw new Error("Component must be used with ZoomProvider"); + } + + return ( +
+ + + + + {Math.round(ctx.scale * 100)}% + + + + +
+ ); +}; diff --git a/src/CAREUI/misc/PrintPreview.tsx b/src/CAREUI/misc/PrintPreview.tsx index 243826c7337..fe8b09b173c 100644 --- a/src/CAREUI/misc/PrintPreview.tsx +++ b/src/CAREUI/misc/PrintPreview.tsx @@ -3,6 +3,9 @@ import ButtonV2 from "../../Components/Common/components/ButtonV2"; import CareIcon from "../icons/CareIcon"; import { classNames } from "../../Utils/utils"; import Page from "../../Components/Common/components/Page"; +import useBreakpoints from "../../Common/hooks/useBreakpoints"; +import { useTranslation } from "react-i18next"; +import { ZoomControls, ZoomProvider, ZoomTransform } from "../interactive/Zoom"; type Props = { children: ReactNode; @@ -12,24 +15,31 @@ type Props = { }; export default function PrintPreview(props: Props) { + const normalScale = useBreakpoints({ default: 0.44, md: 1 }); + const { t } = useTranslation(); + return (
-
- window.print()}> +
+ - Print + {t("print")}
-
-
- {props.children} -
-
+ + +
+ {props.children} +
+
+ + +
); diff --git a/src/Locale/en/Common.json b/src/Locale/en/Common.json index 24855e05d70..0d021ba2f9e 100644 --- a/src/Locale/en/Common.json +++ b/src/Locale/en/Common.json @@ -66,6 +66,7 @@ "contact_person_number": "Contact person number", "referral_letter": "Referral Letter", "close": "Close", + "print": "Print", "print_referral_letter": "Print Referral Letter", "date_of_positive_covid_19_swab": "Date of Positive Covid 19 Swab", "patient_no": "OP/IP No", @@ -201,4 +202,4 @@ "oxygen_information": "Oxygen Information", "deleted_successfully": "{{name}} deleted successfully", "delete_item": "Delete {{name}}" -} +} \ No newline at end of file