dhre-component-lib 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/{src/components/Badge → dist}/Badge.module.scss +0 -1
  2. package/{src/components/BreadCrumb → dist}/Breadcrumb.module.scss +0 -3
  3. package/{src/components/Button → dist}/Button.module.scss +3 -16
  4. package/{src/components/CircularProgress → dist}/CircularProgress.module.scss +0 -1
  5. package/dist/assets/output-4Fi7j5sB.css +247 -0
  6. package/dist/components/Badge/index.d.ts +0 -1
  7. package/dist/components/BreadCrumb/index.d.ts +0 -1
  8. package/dist/components/Button/index.d.ts +0 -1
  9. package/dist/components/CircularProgress/index.d.ts +0 -1
  10. package/dist/components/Map/index.d.ts +0 -1
  11. package/dist/components/Modal/index.d.ts +0 -1
  12. package/dist/components/Notification/index.d.ts +0 -1
  13. package/dist/components/OtpInput/index.d.ts +0 -1
  14. package/dist/components/PdfView/index.d.ts +0 -1
  15. package/dist/components/Tooltip/index.d.ts +0 -1
  16. package/dist/dist/styles.css +2 -0
  17. package/dist/dist/styles.css.map +1 -0
  18. package/dist/index.d.ts +15 -1
  19. package/dist/index.esm.js +9323 -0
  20. package/dist/index.esm.js.map +1 -0
  21. package/dist/index.js +9359 -1
  22. package/dist/index.js.map +1 -0
  23. package/package.json +8 -7
  24. package/dist/components/Avatar/Avatar.js +0 -6
  25. package/dist/components/Avatar/Avatar.test.js +0 -39
  26. package/dist/components/Avatar/index.js +0 -1
  27. package/dist/components/Badge/Badge.js +0 -6
  28. package/dist/components/Badge/Badge.test.js +0 -44
  29. package/dist/components/Badge/index.js +0 -2
  30. package/dist/components/BreadCrumb/BreadCrumb.js +0 -8
  31. package/dist/components/BreadCrumb/BreadCrumb.test.js +0 -55
  32. package/dist/components/BreadCrumb/index.js +0 -2
  33. package/dist/components/Button/Button.js +0 -6
  34. package/dist/components/Button/Button.test.js +0 -36
  35. package/dist/components/Button/index.js +0 -2
  36. package/dist/components/Checkbox/Checkbox.js +0 -7
  37. package/dist/components/Checkbox/Checkbox.test.js +0 -59
  38. package/dist/components/Checkbox/index.js +0 -1
  39. package/dist/components/CircularProgress/CircularProgress.js +0 -15
  40. package/dist/components/CircularProgress/CircularProgress.test.js +0 -31
  41. package/dist/components/CircularProgress/index.js +0 -2
  42. package/dist/components/Divider/Divider.js +0 -7
  43. package/dist/components/Divider/Divider.test.js +0 -30
  44. package/dist/components/Divider/index.js +0 -1
  45. package/dist/components/Enum.js +0 -17
  46. package/dist/components/InputTextField/InputTextField.js +0 -9
  47. package/dist/components/InputTextField/InputTextField.test.js +0 -98
  48. package/dist/components/InputTextField/index.js +0 -1
  49. package/dist/components/Link/Link.js +0 -6
  50. package/dist/components/Link/Link.test.js +0 -47
  51. package/dist/components/Link/index.js +0 -1
  52. package/dist/components/Map/Directions.js +0 -9
  53. package/dist/components/Map/GoogleMap.js +0 -104
  54. package/dist/components/Map/GoogleMapsLoader.js +0 -10
  55. package/dist/components/Map/index.js +0 -3
  56. package/dist/components/Modal/Modal.js +0 -14
  57. package/dist/components/Modal/Modal.test.js +0 -52
  58. package/dist/components/Modal/index.js +0 -2
  59. package/dist/components/Notification/Notification.js +0 -21
  60. package/dist/components/Notification/Notification.test.js +0 -40
  61. package/dist/components/Notification/index.js +0 -2
  62. package/dist/components/OtpInput/OtpInput.js +0 -68
  63. package/dist/components/OtpInput/OtpInput.test.js +0 -36
  64. package/dist/components/OtpInput/index.js +0 -2
  65. package/dist/components/PdfView/PdfView.js +0 -59
  66. package/dist/components/PdfView/PdfView.test.js +0 -41
  67. package/dist/components/PdfView/index.js +0 -2
  68. package/dist/components/Progress/Progress.js +0 -9
  69. package/dist/components/Progress/Progress.test.js +0 -34
  70. package/dist/components/Progress/index.js +0 -1
  71. package/dist/components/RadioButton/RadioButton.js +0 -7
  72. package/dist/components/RadioButton/RadioButton.test.js +0 -29
  73. package/dist/components/RadioButton/index.js +0 -1
  74. package/dist/components/Switch/Switch.js +0 -10
  75. package/dist/components/Switch/Switch.test.js +0 -45
  76. package/dist/components/Switch/index.js +0 -1
  77. package/dist/components/Tag/Tag.js +0 -6
  78. package/dist/components/Tag/Tag.test.js +0 -43
  79. package/dist/components/Tag/index.js +0 -1
  80. package/dist/components/Tooltip/Tooltip.js +0 -11
  81. package/dist/components/Tooltip/Tooltip.test.js +0 -48
  82. package/dist/components/Tooltip/index.js +0 -2
  83. package/dist/components/index.d.ts +0 -15
  84. package/dist/components/index.js +0 -15
  85. package/dist/theme/colors.js +0 -2
  86. package/src/__mocks__/styleMock.js +0 -1
  87. package/src/components/Avatar/Avatar.test.tsx +0 -53
  88. package/src/components/Avatar/Avatar.tsx +0 -28
  89. package/src/components/Avatar/index.ts +0 -1
  90. package/src/components/Badge/Badge.test.tsx +0 -59
  91. package/src/components/Badge/Badge.tsx +0 -25
  92. package/src/components/Badge/index.ts +0 -2
  93. package/src/components/BreadCrumb/BreadCrumb.test.tsx +0 -90
  94. package/src/components/BreadCrumb/BreadCrumb.tsx +0 -45
  95. package/src/components/BreadCrumb/index.ts +0 -2
  96. package/src/components/Button/Button.test.tsx +0 -49
  97. package/src/components/Button/Button.tsx +0 -29
  98. package/src/components/Button/index.ts +0 -2
  99. package/src/components/Checkbox/Checkbox.test.tsx +0 -93
  100. package/src/components/Checkbox/Checkbox.tsx +0 -35
  101. package/src/components/Checkbox/index.ts +0 -1
  102. package/src/components/CircularProgress/CircularProgress.test.tsx +0 -39
  103. package/src/components/CircularProgress/CircularProgress.tsx +0 -37
  104. package/src/components/CircularProgress/index.ts +0 -2
  105. package/src/components/Divider/Divider.test.tsx +0 -44
  106. package/src/components/Divider/Divider.tsx +0 -24
  107. package/src/components/Divider/index.ts +0 -1
  108. package/src/components/Enum.ts +0 -19
  109. package/src/components/InputTextField/InputTextField.test.tsx +0 -118
  110. package/src/components/InputTextField/InputTextField.tsx +0 -48
  111. package/src/components/InputTextField/index.ts +0 -1
  112. package/src/components/Link/Link.test.tsx +0 -55
  113. package/src/components/Link/Link.tsx +0 -33
  114. package/src/components/Link/index.ts +0 -1
  115. package/src/components/Map/Directions.tsx +0 -36
  116. package/src/components/Map/GoogleMap.tsx +0 -186
  117. package/src/components/Map/GoogleMapsLoader.tsx +0 -12
  118. package/src/components/Map/index.ts +0 -3
  119. package/src/components/Modal/Modal.test.tsx +0 -74
  120. package/src/components/Modal/Modal.tsx +0 -39
  121. package/src/components/Modal/index.ts +0 -2
  122. package/src/components/Notification/Notification.test.tsx +0 -53
  123. package/src/components/Notification/Notification.tsx +0 -42
  124. package/src/components/Notification/index.ts +0 -2
  125. package/src/components/OtpInput/OtpInput.test.tsx +0 -53
  126. package/src/components/OtpInput/OtpInput.tsx +0 -137
  127. package/src/components/OtpInput/index.ts +0 -2
  128. package/src/components/PdfView/PdfView.test.tsx +0 -52
  129. package/src/components/PdfView/PdfView.tsx +0 -116
  130. package/src/components/PdfView/index.ts +0 -2
  131. package/src/components/Progress/Progress.test.tsx +0 -43
  132. package/src/components/Progress/Progress.tsx +0 -35
  133. package/src/components/Progress/index.ts +0 -1
  134. package/src/components/RadioButton/RadioButton.test.tsx +0 -56
  135. package/src/components/RadioButton/RadioButton.tsx +0 -43
  136. package/src/components/RadioButton/index.ts +0 -1
  137. package/src/components/Switch/Switch.test.tsx +0 -83
  138. package/src/components/Switch/Switch.tsx +0 -38
  139. package/src/components/Switch/index.ts +0 -1
  140. package/src/components/Tag/Tag.css +0 -14
  141. package/src/components/Tag/Tag.test.tsx +0 -61
  142. package/src/components/Tag/Tag.tsx +0 -19
  143. package/src/components/Tag/index.ts +0 -1
  144. package/src/components/Tooltip/Tooltip.test.tsx +0 -68
  145. package/src/components/Tooltip/Tooltip.tsx +0 -38
  146. package/src/components/Tooltip/index.ts +0 -2
  147. package/src/components/index.ts +0 -15
  148. package/src/index.ts +0 -1
  149. package/src/theme/colors.ts +0 -3
  150. package/src/typings.d.ts +0 -1
  151. /package/{src/components/Map → dist}/GoogleMap.module.scss +0 -0
  152. /package/{src/components/Modal → dist}/Modal.module.scss +0 -0
  153. /package/{src/components/Notification → dist}/Notification.module.scss +0 -0
  154. /package/{src/components/OtpInput → dist}/OtpInput.module.scss +0 -0
  155. /package/{src/components/PdfView → dist}/PdfView.module.scss +0 -0
  156. /package/{src/components/Tooltip → dist}/Tooltip.module.scss +0 -0
  157. /package/{src/theme/colors → dist}/colors.scss +0 -0
  158. /package/{src/theme/Typography → dist}/typography.scss +0 -0
@@ -1,104 +0,0 @@
1
- import React, { useState, useRef, useEffect } from "react";
2
- import { GoogleMap, Marker, Circle, DirectionsRenderer, } from "@react-google-maps/api";
3
- import { useGoogleMapsLoader } from "./GoogleMapsLoader";
4
- import styles from './GoogleMap.module.scss';
5
- const MapComponent = ({ containerClassName = "map-container", zoom = 18, mapOptions = {
6
- zoomControl: true,
7
- tilt: 0,
8
- gestureHandling: "auto",
9
- mapTypeId: "roadmap",
10
- }, radius = 5000, googleMapsUrls, buttonText, buttonClassName, }) => {
11
- const [location, setLocation] = useState(null);
12
- const [mapVisible, setMapVisible] = useState(false);
13
- const [directionsResponse, setDirectionsResponse] = useState(null);
14
- const mapRef = useRef(null);
15
- const directionsService = useRef(null);
16
- const directionsRenderer = useRef(null);
17
- const handleLocationRequest = () => {
18
- if ("geolocation" in navigator) {
19
- navigator.geolocation.getCurrentPosition(({ coords }) => {
20
- const { latitude, longitude } = coords;
21
- setLocation({ latitude, longitude });
22
- setMapVisible(true);
23
- }, () => {
24
- alert("Failed to get location. Please try again.");
25
- });
26
- }
27
- else {
28
- alert("Geolocation is not supported by this browser.");
29
- }
30
- };
31
- const handleMarkerClick = (lat, lng) => {
32
- if (location) {
33
- const directionsServiceInstance = directionsService.current || new google.maps.DirectionsService();
34
- const directionsRendererInstance = directionsRenderer.current || new google.maps.DirectionsRenderer();
35
- if (!directionsService.current)
36
- directionsService.current = directionsServiceInstance;
37
- if (!directionsRenderer.current)
38
- directionsRenderer.current = directionsRendererInstance;
39
- const directionsRequest = {
40
- origin: { lat: location.latitude, lng: location.longitude },
41
- destination: { lat, lng },
42
- travelMode: google.maps.TravelMode.DRIVING,
43
- };
44
- directionsService.current.route(directionsRequest, (result, status) => {
45
- if (status === google.maps.DirectionsStatus.OK) {
46
- setDirectionsResponse(result);
47
- if (mapRef.current && directionsRenderer.current) {
48
- directionsRenderer.current.setMap(mapRef.current);
49
- directionsRenderer.current.setDirections(result);
50
- }
51
- }
52
- else {
53
- alert("Failed to get directions. Please try again.");
54
- }
55
- });
56
- }
57
- };
58
- const extractCoordinatesFromUrl = (url) => {
59
- const regex = /@(-?\d+\.\d+),(-?\d+\.\d+)/;
60
- const match = url.match(regex);
61
- if (match) {
62
- return {
63
- lat: parseFloat(match[1]),
64
- lng: parseFloat(match[2]),
65
- };
66
- }
67
- return null;
68
- };
69
- const { isLoaded } = useGoogleMapsLoader();
70
- useEffect(() => { }, [isLoaded]);
71
- useEffect(() => { }, [mapVisible]);
72
- if (!isLoaded) {
73
- return React.createElement("div", null, "Loading map...");
74
- }
75
- if (mapVisible && location) {
76
- return (React.createElement("div", { className: containerClassName },
77
- React.createElement("button", { onClick: handleLocationRequest, className: buttonClassName }, buttonText),
78
- React.createElement(GoogleMap, { mapContainerStyle: styles.mapContainerStyle, center: { lat: location.latitude, lng: location.longitude }, zoom: zoom, options: mapOptions, onLoad: (map) => {
79
- mapRef.current = map;
80
- directionsRenderer.current = new google.maps.DirectionsRenderer();
81
- directionsRenderer.current.setMap(map);
82
- } },
83
- React.createElement(Marker, { position: { lat: location.latitude, lng: location.longitude }, icon: "http://maps.google.com/mapfiles/ms/icons/red-dot.png" }),
84
- React.createElement(Circle, { center: { lat: location.latitude, lng: location.longitude }, radius: radius, options: {
85
- strokeColor: "#FF0000",
86
- strokeOpacity: 0.8,
87
- strokeWeight: 2,
88
- fillColor: "#FF0000",
89
- fillOpacity: 0,
90
- } }),
91
- googleMapsUrls.map((url, index) => {
92
- const coord = extractCoordinatesFromUrl(url);
93
- if (!coord)
94
- return null;
95
- return (React.createElement(Marker, { key: index, position: { lat: coord.lat, lng: coord.lng }, title: `Sample Location ${index + 1}`, icon: "http://maps.google.com/mapfiles/ms/icons/blue-dot.png", onClick: () => handleMarkerClick(coord.lat, coord.lng) }));
96
- }),
97
- directionsResponse && (React.createElement(DirectionsRenderer, { directions: directionsResponse, options: { suppressMarkers: true } })))));
98
- }
99
- else {
100
- return (React.createElement("div", { className: containerClassName },
101
- React.createElement("button", { onClick: handleLocationRequest, className: buttonClassName }, buttonText)));
102
- }
103
- };
104
- export default MapComponent;
@@ -1,10 +0,0 @@
1
- import { useJsApiLoader } from '@react-google-maps/api';
2
- const GOOGLE_MAPS_API_KEY = process.env.NEXT_PUBLIC_GOOGLE_MAP_API; // Ensure you are using environment variable
3
- export const useGoogleMapsLoader = () => {
4
- return useJsApiLoader({
5
- googleMapsApiKey: GOOGLE_MAPS_API_KEY, // Replace with your API key
6
- libraries: ['places', 'drawing', 'geometry'], // Include all libraries you need
7
- language: 'en',
8
- region: 'US',
9
- });
10
- };
@@ -1,3 +0,0 @@
1
- export { default as Directions } from "./Directions";
2
- export { default as GoogleMap } from "./GoogleMap";
3
- import "./GoogleMap.module.scss";
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import styles from './Modal.module.scss';
3
- const Modal = ({ isOpen, onClose, children, modalOverlayClassname = '', modalContentClassname = '' }) => {
4
- if (!isOpen)
5
- return null;
6
- const handleOverlayClick = (event) => {
7
- if (event.target === event.currentTarget) {
8
- onClose();
9
- }
10
- };
11
- return (React.createElement("button", { className: `${styles.modalOverlay} ${modalOverlayClassname}`, onClick: handleOverlayClick },
12
- React.createElement("div", { className: `${styles.modalContent} ${modalContentClassname}` }, children)));
13
- };
14
- export default Modal;
@@ -1,52 +0,0 @@
1
- import React from 'react';
2
- import { render, screen, fireEvent } from '@testing-library/react';
3
- import Modal from './Modal';
4
- describe('Modal Component', () => {
5
- const onCloseMock = jest.fn();
6
- const modalContentText = 'This is the modal content';
7
- const renderModal = (isOpen, modalOverlayClassname, modalContentClassname) => {
8
- render(React.createElement(Modal, { isOpen: isOpen, onClose: onCloseMock, modalOverlayClassname: modalOverlayClassname, modalContentClassname: modalContentClassname },
9
- React.createElement("div", null, modalContentText)));
10
- };
11
- afterEach(() => {
12
- jest.clearAllMocks();
13
- });
14
- it('renders the modal when isOpen is true', () => {
15
- renderModal(true);
16
- expect(screen.getByText(modalContentText)).toBeInTheDocument();
17
- });
18
- it('does not render the modal when isOpen is false', () => {
19
- renderModal(false);
20
- expect(screen.queryByText(modalContentText)).not.toBeInTheDocument();
21
- });
22
- it('calls onClose when clicking on the overlay', () => {
23
- renderModal(true);
24
- const overlay = screen.getByText(modalContentText).closest('button');
25
- fireEvent.click(overlay);
26
- expect(onCloseMock).toHaveBeenCalled();
27
- });
28
- it('does not call onClose when clicking inside the modal content', () => {
29
- renderModal(true);
30
- const modalContent = screen.getByText(modalContentText);
31
- fireEvent.click(modalContent);
32
- expect(onCloseMock).not.toHaveBeenCalled();
33
- });
34
- it('applies the provided modalOverlayClassname', () => {
35
- const overlayClass = 'customOverlayClass';
36
- renderModal(true, overlayClass);
37
- const overlay = screen.getByText(modalContentText).closest('button');
38
- expect(overlay).toHaveClass(overlayClass);
39
- });
40
- it('applies the provided modalContentClassname', () => {
41
- const contentClass = 'customContentClass';
42
- renderModal(true, undefined, contentClass);
43
- const modalContent = screen.getByText(modalContentText);
44
- expect(modalContent.parentElement).toHaveClass(contentClass);
45
- });
46
- it('does not render modal when isOpen is false, even if modalOverlayClassname and modalContentClassname are provided', () => {
47
- const overlayClass = 'customOverlayClass';
48
- const contentClass = 'customContentClass';
49
- renderModal(false, overlayClass, contentClass);
50
- expect(screen.queryByText(modalContentText)).not.toBeInTheDocument();
51
- });
52
- });
@@ -1,2 +0,0 @@
1
- export { default } from "./Modal";
2
- import "./Modal.module.scss";
@@ -1,21 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import './Notification.module.scss';
3
- const Notification = ({ message, severity = 'info', autoHideDuration = 6000, onClose, }) => {
4
- useEffect(() => {
5
- if (autoHideDuration && onClose) {
6
- const timer = setTimeout(() => {
7
- onClose(new Event('timeout'), 'timeout');
8
- }, autoHideDuration);
9
- return () => clearTimeout(timer);
10
- }
11
- }, [autoHideDuration, onClose]);
12
- const handleClose = (event, reason) => {
13
- if (onClose) {
14
- onClose(event, reason);
15
- }
16
- };
17
- return (React.createElement("div", { className: `notification ${severity}`, onClick: (e) => handleClose(e), role: "alert" },
18
- React.createElement("div", { className: "notification-message" }, message),
19
- React.createElement("button", { className: "close-button", onClick: (e) => handleClose(e, 'close'), "aria-label": "Close notification" }, "\u00D7")));
20
- };
21
- export default Notification;
@@ -1,40 +0,0 @@
1
- import React from 'react';
2
- import { render, screen, fireEvent, waitFor } from '@testing-library/react';
3
- import Notification from './Notification';
4
- describe('Notification Component', () => {
5
- const defaultProps = {
6
- message: 'Test Message',
7
- severity: 'info',
8
- autoHideDuration: 6000,
9
- onClose: jest.fn(),
10
- };
11
- const renderNotification = (props = {}) => {
12
- return render(React.createElement(Notification, { ...defaultProps, ...props }));
13
- };
14
- test('renders notification with the correct message', () => {
15
- render(React.createElement(Notification, { message: "Test Message", severity: "info" }));
16
- // Check if the element exists by querying it
17
- const notificationElement = screen.getByText('Test Message');
18
- expect(notificationElement).not.toBeNull(); // Equivalent to `toBeInTheDocument`
19
- // Alternatively, check for the presence of the role or className
20
- const alertElement = screen.getByRole('alert');
21
- expect(alertElement.className).toContain('info'); // Check if className includes "info"
22
- });
23
- test('calls onClose when the notification is clicked', () => {
24
- const onClose = jest.fn();
25
- renderNotification({ onClose });
26
- fireEvent.click(screen.getByRole('alert'));
27
- expect(onClose).toHaveBeenCalled();
28
- });
29
- test('calls onClose when the close button is clicked', () => {
30
- const onClose = jest.fn();
31
- renderNotification({ onClose });
32
- fireEvent.click(screen.getByLabelText('Close notification'));
33
- expect(onClose).toHaveBeenCalledWith(expect.anything(), 'close');
34
- });
35
- test('calls onClose after autoHideDuration expires', async () => {
36
- const onClose = jest.fn();
37
- renderNotification({ onClose, autoHideDuration: 1000 });
38
- await waitFor(() => expect(onClose).toHaveBeenCalledWith(expect.anything(), 'timeout'), { timeout: 1500 });
39
- });
40
- });
@@ -1,2 +0,0 @@
1
- export { default } from "./Notification";
2
- import "./Notification.module.scss";
@@ -1,68 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- import "./OtpInput.module.scss";
3
- const OTPInput = ({ length = 4, onChange, autoFocus = false, onResend, resendDelay = 60, error = false, errorText, resendText, }) => {
4
- const [otp, setOtp] = useState(Array(length).fill(""));
5
- const [timer, setTimer] = useState(resendDelay);
6
- const [isComplete, setIsComplete] = useState(false);
7
- useEffect(() => {
8
- const countdown = setInterval(() => {
9
- setTimer((prevTimer) => (prevTimer > 0 ? prevTimer - 1 : 0));
10
- }, 1000);
11
- return () => clearInterval(countdown);
12
- }, []);
13
- const handleChange = (value, index) => {
14
- if (isNaN(Number(value)))
15
- return;
16
- const newOtp = [...otp];
17
- newOtp[index] = value;
18
- setOtp(newOtp);
19
- onChange(newOtp.join(""));
20
- if (value && index < length - 1) {
21
- const nextInput = document.getElementById(`otp-input-${index + 1}`);
22
- if (nextInput) {
23
- nextInput.focus();
24
- }
25
- }
26
- };
27
- const handleKeyDown = (e, index) => {
28
- if (e.key === "Backspace" && !otp[index] && index > 0) {
29
- const prevInput = document.getElementById(`otp-input-${index - 1}`);
30
- if (prevInput) {
31
- prevInput.focus();
32
- }
33
- }
34
- };
35
- const handleResendClick = () => {
36
- onResend();
37
- setOtp(Array(length).fill(""));
38
- setTimer(resendDelay);
39
- setIsComplete(false);
40
- };
41
- useEffect(() => {
42
- setIsComplete(otp.every((digit) => digit !== ""));
43
- }, [otp]);
44
- useEffect(() => {
45
- if (error) {
46
- setTimer(0);
47
- }
48
- }, [error]);
49
- function getReadableStatus() {
50
- if (error) {
51
- return "#EB0542";
52
- }
53
- return isComplete ? "#00B578" : "#A7A7A7";
54
- }
55
- return (React.createElement("div", { className: "otpMainContainer" },
56
- React.createElement("div", { className: "otpInputDiv" }, Array(length)
57
- .fill("")
58
- .map((_, index) => (React.createElement("input", { key: index, type: "text", id: `otp-input-${index}`, value: otp[index], "data-testid": `otp-input-${index}`, role: "textbox", onChange: (e) => handleChange(e.target.value, index), onKeyDown: (e) => handleKeyDown(e, index), maxLength: 1, style: { border: `1px solid ${getReadableStatus()}` }, className: "otpInput", autoFocus: autoFocus && index === 0 })))),
59
- React.createElement("div", { className: "resendContainer" },
60
- error ? (React.createElement("div", { className: "errorText" }, errorText)) : (React.createElement("div", { className: "timerText" }, timer > 0 ? `00:${timer} secs` : "")),
61
- React.createElement("button", { onClick: handleResendClick, disabled: timer > 0, style: {
62
- border: "none",
63
- background: "none",
64
- cursor: timer > 0 ? "not-allowed" : "pointer",
65
- } },
66
- React.createElement("div", { className: "resendText" }, resendText)))));
67
- };
68
- export default OTPInput;
@@ -1,36 +0,0 @@
1
- import React from 'react';
2
- import { render, fireEvent, screen } from '@testing-library/react';
3
- import OTPInput from './OtpInput';
4
- import '@testing-library/jest-dom';
5
- describe('OTPInput Component', () => {
6
- it('renders the correct number of input fields based on the length prop', () => {
7
- render(React.createElement(OTPInput, { length: 4, onChange: () => { }, onResend: () => { }, resendText: "Resend OTP" }));
8
- const inputs = screen.getAllByRole('textbox');
9
- expect(inputs).toHaveLength(4);
10
- });
11
- it('calls onChange prop when input changes', () => {
12
- const handleChange = jest.fn();
13
- render(React.createElement(OTPInput, { length: 4, onChange: handleChange, onResend: () => { }, resendText: "Resend OTP" }));
14
- const inputs = screen.getAllByRole('textbox');
15
- fireEvent.change(inputs[0], { target: { value: '1' } });
16
- expect(handleChange).toHaveBeenCalledWith('1');
17
- });
18
- it('calls onResend prop when the resend button is clicked', async () => {
19
- const handleResend = jest.fn();
20
- render(React.createElement(OTPInput, { length: 4, onChange: () => { }, onResend: handleResend, resendText: "Resend OTP", resendDelay: 0 }));
21
- const resendButton = screen.getByRole('button', { name: /resend otp/i });
22
- fireEvent.click(resendButton);
23
- expect(handleResend).toHaveBeenCalled();
24
- });
25
- it('displays error text when the error prop is true', () => {
26
- const errorMessage = 'Invalid OTP';
27
- render(React.createElement(OTPInput, { length: 4, onChange: () => { }, onResend: () => { }, resendText: "Resend OTP", error: true, errorText: errorMessage }));
28
- const errorElement = screen.getByText(errorMessage);
29
- expect(errorElement).toBeInTheDocument();
30
- });
31
- it('changes border color to red when the error prop is true', () => {
32
- render(React.createElement(OTPInput, { length: 4, onChange: () => { }, onResend: () => { }, resendText: "Resend OTP", error: true }));
33
- const firstInput = screen.getByTestId('otp-input-0');
34
- expect(firstInput).toHaveStyle('border: 1px solid #EB0542');
35
- });
36
- });
@@ -1,2 +0,0 @@
1
- export { default } from "./OtpInput";
2
- import "./OtpInput.module.scss";
@@ -1,59 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import styles from './PdfView.module.scss';
3
- const PdfView = ({ content, contentType = "application/pdf", buttonText = "View PDF", loadingText = "Loading...", errorText = "Failed to load PDF", cleanUpDelay = 1000, buttonVariant = "contained", buttonColor = "primary", buttonSize = "medium", showLoadingSpinner = false, spinnerSize = 24, spinnerColor = "primary", className = "", }) => {
4
- const [isLoading, setIsLoading] = React.useState(false);
5
- const [isError, setIsError] = React.useState(false);
6
- const [errorMsg, setErrorMsg] = React.useState(errorText);
7
- useEffect(() => {
8
- if (btoa(atob(content)) !== content) {
9
- setIsError(true);
10
- }
11
- }, [content]);
12
- const base64ToBlob = (content, contentType = "application/pdf") => {
13
- try {
14
- const byteCharacters = atob(content);
15
- const byteArray = new Uint8Array(byteCharacters.length);
16
- for (let i = 0; i < byteCharacters.length; i++) {
17
- byteArray[i] = byteCharacters.charCodeAt(i);
18
- }
19
- return new Blob([byteArray], { type: contentType });
20
- }
21
- catch (error) {
22
- setIsError(true);
23
- setErrorMsg("Invalid base64 string:");
24
- return null;
25
- }
26
- };
27
- const handleViewPdf = async () => {
28
- setIsLoading(true);
29
- setIsError(false);
30
- const blob = base64ToBlob(content, contentType);
31
- if (blob) {
32
- const url = URL.createObjectURL(blob);
33
- window.open(url, "_blank");
34
- setTimeout(() => {
35
- URL.revokeObjectURL(url);
36
- }, cleanUpDelay);
37
- setIsLoading(false);
38
- }
39
- else {
40
- setIsLoading(false);
41
- setIsError(true);
42
- setErrorMsg("Failed to create Blob from base64 string.");
43
- }
44
- };
45
- const buttonClass = `
46
- ${styles.button}
47
- ${styles[`button${buttonVariant.charAt(0).toUpperCase() + buttonVariant.slice(1)}`]}
48
- ${styles[`button${buttonColor.charAt(0).toUpperCase() + buttonColor.slice(1)}`]}
49
- ${styles[`button${buttonSize.charAt(0).toUpperCase() + buttonSize.slice(1)}`]}
50
- `;
51
- const spinnerClass = `${styles.spinner} ${styles.spinnerInner}`;
52
- return (React.createElement("div", { className: `${styles.container} ${className}` },
53
- isLoading && showLoadingSpinner && (React.createElement("div", { "data-testid": "spinnertest", className: spinnerClass, style: { width: spinnerSize, height: spinnerSize, borderColor: spinnerColor } },
54
- React.createElement("div", { className: styles.spinnerInner }))),
55
- isError && React.createElement("p", { className: styles.errorText }, errorMsg),
56
- !isLoading && !isError && (React.createElement("button", { onClick: handleViewPdf, className: buttonClass }, buttonText)),
57
- isLoading && !showLoadingSpinner && React.createElement("p", null, loadingText)));
58
- };
59
- export default PdfView;
@@ -1,41 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import PdfView from './PdfView';
5
- // Dummy base64 content for testing
6
- const validBase64Content = 'JVBERi0xLjQKJeLjz9MNCjEgMCBvYmoKPDwvTGluay9QYWdlcyAyIDAgUj4+CnN0YXJ0eHJlZgoyNCAwIFIKZW5kb2JqCjEgMCBvYmoKPDwvTGluay9QYWdlcyAyIDAgUj4+CnN0YXJ0eHJlZgo2IDAgUgo+';
7
- const invalidBase64Content = 'invalid base64 content';
8
- const errorText = 'Failed to load PDF';
9
- const buttonText = 'View PDF';
10
- const loadingText = 'Loading...';
11
- // Save the original implementation of createObjectURL
12
- const originalCreateObjectURL = global.URL.createObjectURL;
13
- describe('PdfView Component', () => {
14
- beforeAll(() => {
15
- // Mock URL.createObjectURL directly
16
- global.URL.createObjectURL = jest.fn(() => 'mock-url');
17
- });
18
- afterAll(() => {
19
- // Restore the original implementation
20
- global.URL.createObjectURL = originalCreateObjectURL;
21
- });
22
- it('renders correctly with default props', () => {
23
- render(React.createElement(PdfView, { content: validBase64Content }));
24
- expect(screen.getByText(buttonText)).toBeInTheDocument();
25
- });
26
- it('shows error message if content is invalid', () => {
27
- render(React.createElement(PdfView, { content: invalidBase64Content }));
28
- expect(screen.getByText(errorText)).toBeInTheDocument();
29
- });
30
- it('applies the provided class names', () => {
31
- const className = 'custom-class';
32
- render(React.createElement(PdfView, { content: validBase64Content, className: className }));
33
- expect(screen.getByText(buttonText).parentElement).toHaveClass(className);
34
- });
35
- it('does not show spinner or loading text if isLoading is false', () => {
36
- render(React.createElement(PdfView, { content: validBase64Content }));
37
- // The component should not be in a loading state initially
38
- expect(screen.queryByTestId('spinnertest')).not.toBeInTheDocument();
39
- expect(screen.queryByText(loadingText)).not.toBeInTheDocument();
40
- });
41
- });
@@ -1,2 +0,0 @@
1
- export { default } from "./PdfView";
2
- import "./PdfView.module.scss";
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- const Progress = ({ value, max, className = '', barContainerClassName = '', barClassName = '', labelClassName = '', label, ...rest }) => {
3
- const percentage = (value / max) * 100;
4
- return (React.createElement("div", { className: className, ...rest },
5
- label && React.createElement("div", { className: labelClassName }, label),
6
- React.createElement("div", { className: barContainerClassName },
7
- React.createElement("div", { "data-testid": "progress-bar", className: barClassName, style: { width: `${percentage}%` } }))));
8
- };
9
- export default Progress;
@@ -1,34 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import Progress from './Progress';
5
- describe('Progress Component', () => {
6
- it('renders the progress bar with correct percentage width', () => {
7
- render(React.createElement(Progress, { value: 50, max: 100, barClassName: "progress-bar" }));
8
- const progressBar = screen.getByTestId('progress-bar');
9
- expect(progressBar).toHaveStyle('width: 50%');
10
- });
11
- it('renders the label when provided', () => {
12
- render(React.createElement(Progress, { value: 30, max: 100, label: "Loading", labelClassName: "label-class" }));
13
- expect(screen.getByText('Loading')).toHaveClass('label-class');
14
- });
15
- it('does not render the label when not provided', () => {
16
- render(React.createElement(Progress, { value: 30, max: 100 }));
17
- expect(screen.queryByText('Loading')).not.toBeInTheDocument();
18
- });
19
- it('handles zero values correctly', () => {
20
- render(React.createElement(Progress, { value: 0, max: 100, barClassName: "progress-bar" }));
21
- const progressBar = screen.getByTestId('progress-bar');
22
- expect(progressBar).toHaveStyle('width: 0%');
23
- });
24
- it('handles max values correctly', () => {
25
- render(React.createElement(Progress, { value: 100, max: 100, barClassName: "progress-bar" }));
26
- const progressBar = screen.getByTestId('progress-bar');
27
- expect(progressBar).toHaveStyle('width: 100%');
28
- });
29
- it('handles values greater than max', () => {
30
- render(React.createElement(Progress, { value: 150, max: 100, barClassName: "progress-bar" }));
31
- const progressBar = screen.getByTestId('progress-bar');
32
- expect(progressBar).toHaveStyle('width: 150%'); // Matches the component's behavior
33
- });
34
- });
@@ -1 +0,0 @@
1
- export { default } from "./Progress";
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- const CustomRadioButton = ({ name, value, checked = false, onChange, className = '', inputClassName = '', labelClassName = '', id, ...rest }) => {
3
- return (React.createElement("div", { className: className },
4
- React.createElement("input", { type: "radio", name: name, value: value, checked: checked, onChange: onChange, id: id, className: inputClassName, ...rest }),
5
- React.createElement("label", { htmlFor: id, className: labelClassName }, value)));
6
- };
7
- export default CustomRadioButton;
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import { render, screen, fireEvent } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import CustomRadioButton from './RadioButton';
5
- describe('CustomRadioButton', () => {
6
- it('should render with given props', () => {
7
- render(React.createElement(CustomRadioButton, { name: "testName", value: "testValue", checked: true, onChange: () => { }, className: "custom-class", inputClassName: "input-class", labelClassName: "label-class", id: "radio1" }));
8
- const radioInput = screen.getByRole('radio');
9
- const label = screen.getByText('testValue'); // Use text to find the label
10
- // Assert that the radio input is rendered correctly
11
- expect(radioInput).toBeInTheDocument();
12
- expect(radioInput).toHaveAttribute('name', 'testName');
13
- expect(radioInput).toHaveAttribute('value', 'testValue');
14
- expect(radioInput).toBeChecked();
15
- expect(radioInput).toHaveClass('input-class');
16
- // Assert that the label is rendered correctly
17
- expect(label).toBeInTheDocument();
18
- // Ensure the label has the correct class by finding the label element directly
19
- const labelElement = document.querySelector(`label[for="radio1"]`);
20
- expect(labelElement).toHaveClass('label-class');
21
- });
22
- it('should call onChange handler when clicked', () => {
23
- const handleChange = jest.fn();
24
- render(React.createElement(CustomRadioButton, { name: "testName", value: "testValue", onChange: handleChange, id: "radio1" }));
25
- const radioInput = screen.getByRole('radio');
26
- fireEvent.click(radioInput);
27
- expect(handleChange).toHaveBeenCalled();
28
- });
29
- });
@@ -1 +0,0 @@
1
- export { default } from "./RadioButton";
@@ -1,10 +0,0 @@
1
- import React from "react";
2
- import './Switch.css';
3
- const Switch = ({ checked, handleChange, switchClassName, label, labelClassName, containerClassName, toggleClassName }) => {
4
- return (React.createElement("div", { className: containerClassName },
5
- label && React.createElement("span", { className: labelClassName }, label),
6
- React.createElement("label", { className: toggleClassName },
7
- React.createElement("input", { type: "checkbox", checked: checked, onChange: handleChange }),
8
- React.createElement("span", { className: switchClassName }))));
9
- };
10
- export default Switch;
@@ -1,45 +0,0 @@
1
- import React, { useState } from 'react';
2
- import { render, screen, fireEvent } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import Switch from './Switch';
5
- describe('Switch Component', () => {
6
- it('renders with basic props', () => {
7
- const { container } = render(React.createElement(Switch, { checked: true, handleChange: () => { }, switchClassName: "switch-class" }));
8
- const switchInput = screen.getByRole('checkbox');
9
- const switchToggle = container.querySelector('.switch-class');
10
- expect(switchInput).toBeInTheDocument();
11
- expect(switchInput).toBeChecked();
12
- expect(switchToggle).toBeInTheDocument();
13
- });
14
- it('renders with a label', () => {
15
- render(React.createElement(Switch, { checked: true, handleChange: () => { }, switchClassName: "switch-class", label: "Toggle Switch", labelClassName: "label-class" }));
16
- const label = screen.getByText('Toggle Switch');
17
- const switchInput = screen.getByRole('checkbox');
18
- expect(label).toBeInTheDocument();
19
- expect(label).toHaveClass('label-class');
20
- expect(switchInput).toBeChecked();
21
- });
22
- it('calls handleChange handler when clicked', () => {
23
- // Simulate a component that manages its own state
24
- const TestComponent = () => {
25
- const [checked, setChecked] = useState(false);
26
- return (React.createElement(Switch, { checked: checked, handleChange: () => setChecked(!checked), switchClassName: "switch-class" }));
27
- };
28
- render(React.createElement(TestComponent, null));
29
- const switchInput = screen.getByRole('checkbox');
30
- expect(switchInput).not.toBeChecked();
31
- // Simulate the click event
32
- fireEvent.click(switchInput);
33
- // Check if the switchInput is now checked
34
- expect(switchInput).toBeChecked();
35
- });
36
- it('applies custom classes', () => {
37
- const { container } = render(React.createElement(Switch, { checked: true, handleChange: () => { }, switchClassName: "switch-class", containerClassName: "container-class", toggleClassName: "toggle-class", label: "Toggle Switch", labelClassName: "label-class" }));
38
- const containerDiv = container.querySelector('.container-class');
39
- const switchToggle = container.querySelector('.switch-class');
40
- const label = screen.getByText('Toggle Switch');
41
- expect(containerDiv).toHaveClass('container-class');
42
- expect(switchToggle).toHaveClass('switch-class');
43
- expect(label).toHaveClass('label-class');
44
- });
45
- });
@@ -1 +0,0 @@
1
- export { default } from "./Switch";
@@ -1,6 +0,0 @@
1
- import React from "react";
2
- import styles from "./Tag.module.scss";
3
- const Tag = ({ content, tagClassName = styles.customTagClass, handleClick, style }) => {
4
- return (React.createElement("button", { onClick: handleClick, style: style, className: tagClassName }, content));
5
- };
6
- export default Tag;