From b84648b8cd75efe56e3bc0243dc1b0669117c87c Mon Sep 17 00:00:00 2001 From: mst-mkt <131662659+mst-mkt@users.noreply.github.com> Date: Wed, 4 Sep 2024 23:52:13 +0900 Subject: [PATCH] fix: type of optional props (errorMessages) --- src/components/Camera/Camera.tsx | 17 ++++++++++------- src/components/Camera/types.ts | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/Camera/Camera.tsx b/src/components/Camera/Camera.tsx index 3e79223..9b927ee 100644 --- a/src/components/Camera/Camera.tsx +++ b/src/components/Camera/Camera.tsx @@ -10,6 +10,14 @@ import { } from './types'; import { Container, Wrapper, Canvas, Cam, ErrorMsg } from './styles'; +const defaultErrorMessages = { + noCameraAccessible: 'No camera device accessible. Please connect your camera or try a different browser.', + permissionDenied: 'Permission denied. Please refresh and give camera permission.', + switchCamera: + 'It is not possible to switch camera to different one because there is only one video device accessible.', + canvas: 'Canvas is not supported.', +}; + export const Camera = React.forwardRef( ( { @@ -17,13 +25,7 @@ export const Camera = React.forwardRef( aspectRatio = 'cover', numberOfCamerasCallback = () => null, videoSourceDeviceId = undefined, - errorMessages = { - noCameraAccessible: 'No camera device accessible. Please connect your camera or try a different browser.', - permissionDenied: 'Permission denied. Please refresh and give camera permission.', - switchCamera: - 'It is not possible to switch camera to different one because there is only one video device accessible.', - canvas: 'Canvas is not supported.', - }, + errorMessages: propsErrorMessages = defaultErrorMessages, videoReadyCallback = () => null, }, ref, @@ -40,6 +42,7 @@ export const Camera = React.forwardRef( const [torchSupported, setTorchSupported] = useState(false); const [torch, setTorch] = useState(false); const mounted = useRef(false); + const errorMessages = { ...defaultErrorMessages, ...propsErrorMessages }; useEffect(() => { mounted.current = true; diff --git a/src/components/Camera/types.ts b/src/components/Camera/types.ts index 361bc33..89dad47 100644 --- a/src/components/Camera/types.ts +++ b/src/components/Camera/types.ts @@ -10,7 +10,7 @@ export interface CameraProps { aspectRatio?: AspectRatio; numberOfCamerasCallback?(numberOfCameras: number): void; videoSourceDeviceId?: string | undefined; - errorMessages: { + errorMessages?: { noCameraAccessible?: string; permissionDenied?: string; switchCamera?: string;