dhre-component-lib 0.0.8 → 0.0.9

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 (82) hide show
  1. package/package.json +6 -3
  2. package/jest.config.ts +0 -10
  3. package/rollup.config.mjs +0 -37
  4. package/setupTests.ts +0 -1
  5. package/src/__mocks__/styleMock.js +0 -1
  6. package/src/components/Avatar/Avatar.test.tsx +0 -53
  7. package/src/components/Avatar/Avatar.tsx +0 -28
  8. package/src/components/Avatar/index.ts +0 -1
  9. package/src/components/Badge/Badge.module.scss +0 -14
  10. package/src/components/Badge/Badge.test.tsx +0 -59
  11. package/src/components/Badge/Badge.tsx +0 -25
  12. package/src/components/Badge/index.ts +0 -1
  13. package/src/components/BreadCrumb/BreadCrumb.test.tsx +0 -90
  14. package/src/components/BreadCrumb/BreadCrumb.tsx +0 -45
  15. package/src/components/BreadCrumb/Breadcrumb.module.scss +0 -20
  16. package/src/components/BreadCrumb/index.ts +0 -1
  17. package/src/components/Button/Button.module.scss +0 -66
  18. package/src/components/Button/Button.test.tsx +0 -49
  19. package/src/components/Button/Button.tsx +0 -29
  20. package/src/components/Button/index.ts +0 -1
  21. package/src/components/Checkbox/Checkbox.test.tsx +0 -93
  22. package/src/components/Checkbox/Checkbox.tsx +0 -35
  23. package/src/components/Checkbox/index.ts +0 -1
  24. package/src/components/CircularProgress/CircularProgress.module.scss +0 -19
  25. package/src/components/CircularProgress/CircularProgress.test.tsx +0 -39
  26. package/src/components/CircularProgress/CircularProgress.tsx +0 -37
  27. package/src/components/CircularProgress/index.ts +0 -1
  28. package/src/components/Divider/Divider.test.tsx +0 -44
  29. package/src/components/Divider/Divider.tsx +0 -24
  30. package/src/components/Divider/index.ts +0 -1
  31. package/src/components/Enum.ts +0 -19
  32. package/src/components/InputTextField/InputTextField.test.tsx +0 -118
  33. package/src/components/InputTextField/InputTextField.tsx +0 -48
  34. package/src/components/InputTextField/index.ts +0 -1
  35. package/src/components/Link/Link.test.tsx +0 -55
  36. package/src/components/Link/Link.tsx +0 -33
  37. package/src/components/Link/index.ts +0 -1
  38. package/src/components/Map/Directions.tsx +0 -36
  39. package/src/components/Map/GoogleMap.module.scss +0 -5
  40. package/src/components/Map/GoogleMap.tsx +0 -186
  41. package/src/components/Map/GoogleMapsLoader.tsx +0 -12
  42. package/src/components/Map/index.ts +0 -2
  43. package/src/components/Modal/Modal.module.scss +0 -26
  44. package/src/components/Modal/Modal.test.tsx +0 -74
  45. package/src/components/Modal/Modal.tsx +0 -39
  46. package/src/components/Modal/index.ts +0 -1
  47. package/src/components/Notification/Notification.module.scss +0 -20
  48. package/src/components/Notification/Notification.test.tsx +0 -53
  49. package/src/components/Notification/Notification.tsx +0 -42
  50. package/src/components/Notification/index.ts +0 -1
  51. package/src/components/OtpInput/OtpInput.module.scss +0 -49
  52. package/src/components/OtpInput/OtpInput.test.tsx +0 -53
  53. package/src/components/OtpInput/OtpInput.tsx +0 -137
  54. package/src/components/OtpInput/index.ts +0 -1
  55. package/src/components/PdfView/PdfView.module.scss +0 -69
  56. package/src/components/PdfView/PdfView.test.tsx +0 -52
  57. package/src/components/PdfView/PdfView.tsx +0 -116
  58. package/src/components/PdfView/index.ts +0 -1
  59. package/src/components/Progress/Progress.test.tsx +0 -43
  60. package/src/components/Progress/Progress.tsx +0 -35
  61. package/src/components/Progress/index.ts +0 -1
  62. package/src/components/RadioButton/RadioButton.test.tsx +0 -56
  63. package/src/components/RadioButton/RadioButton.tsx +0 -43
  64. package/src/components/RadioButton/index.ts +0 -1
  65. package/src/components/Switch/Switch.test.tsx +0 -83
  66. package/src/components/Switch/Switch.tsx +0 -38
  67. package/src/components/Switch/index.ts +0 -1
  68. package/src/components/Tag/Tag.css +0 -14
  69. package/src/components/Tag/Tag.test.tsx +0 -61
  70. package/src/components/Tag/Tag.tsx +0 -19
  71. package/src/components/Tag/index.ts +0 -1
  72. package/src/components/Tooltip/Tooltip.module.scss +0 -37
  73. package/src/components/Tooltip/Tooltip.test.tsx +0 -68
  74. package/src/components/Tooltip/Tooltip.tsx +0 -38
  75. package/src/components/Tooltip/index.ts +0 -1
  76. package/src/components/index.ts +0 -15
  77. package/src/index.ts +0 -1
  78. package/src/theme/Typography/typography.scss +0 -117
  79. package/src/theme/colors/colors.scss +0 -22
  80. package/src/theme/colors.ts +0 -3
  81. package/src/typings.d.ts +0 -1
  82. package/tsconfig.json +0 -16
@@ -1,137 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- import "./OtpInput.module.scss";
3
- interface OTPInputProps {
4
- length?: number;
5
- // eslint-disable-next-line no-unused-vars
6
- onChange: (otp: string) => void;
7
- autoFocus?: boolean;
8
- onResend: () => void;
9
- resendDelay?: number;
10
- error?: boolean;
11
- errorText?: string;
12
- resendText: string;
13
- }
14
-
15
- const OTPInput: React.FC<OTPInputProps> = ({
16
- length = 4,
17
- onChange,
18
- autoFocus = false,
19
- onResend,
20
- resendDelay = 60,
21
- error = false,
22
- errorText,
23
- resendText,
24
- }) => {
25
- const [otp, setOtp] = useState<string[]>(Array(length).fill(""));
26
- const [timer, setTimer] = useState<number>(resendDelay);
27
- const [isComplete, setIsComplete] = useState<boolean>(false);
28
-
29
- useEffect(() => {
30
- const countdown = setInterval(() => {
31
- setTimer((prevTimer) => (prevTimer > 0 ? prevTimer - 1 : 0));
32
- }, 1000);
33
-
34
- return () => clearInterval(countdown);
35
- }, []);
36
- const handleChange = (value: string, index: number) => {
37
- if (isNaN(Number(value))) return;
38
-
39
- const newOtp = [...otp];
40
- newOtp[index] = value;
41
- setOtp(newOtp);
42
- onChange(newOtp.join(""));
43
-
44
- if (value && index < length - 1) {
45
- const nextInput = document.getElementById(
46
- `otp-input-${index + 1}`
47
- ) as HTMLInputElement;
48
- if (nextInput) {
49
- nextInput.focus();
50
- }
51
- }
52
- };
53
-
54
- const handleKeyDown = (
55
- e: React.KeyboardEvent<HTMLInputElement>,
56
- index: number
57
- ) => {
58
- if (e.key === "Backspace" && !otp[index] && index > 0) {
59
- const prevInput = document.getElementById(
60
- `otp-input-${index - 1}`
61
- ) as HTMLInputElement;
62
- if (prevInput) {
63
- prevInput.focus();
64
- }
65
- }
66
- };
67
-
68
- const handleResendClick = () => {
69
- onResend();
70
- setOtp(Array(length).fill(""));
71
- setTimer(resendDelay);
72
- setIsComplete(false);
73
- };
74
-
75
- useEffect(() => {
76
- setIsComplete(otp.every((digit) => digit !== ""));
77
- }, [otp]);
78
-
79
- useEffect(() => {
80
- if (error) {
81
- setTimer(0);
82
- }
83
- }, [error]);
84
-
85
- function getReadableStatus() {
86
- if (error) {
87
- return "#EB0542";
88
- }
89
- return isComplete ? "#00B578" : "#A7A7A7";
90
- }
91
- return (
92
- <div className="otpMainContainer">
93
- <div className="otpInputDiv">
94
- {Array(length)
95
- .fill("")
96
- .map((_, index) => (
97
- <input
98
- key={index}
99
- type="text"
100
- id={`otp-input-${index}`}
101
- value={otp[index]}
102
- data-testid={`otp-input-${index}`}
103
- role="textbox"
104
- onChange={(e) => handleChange(e.target.value, index)}
105
- onKeyDown={(e) => handleKeyDown(e, index)}
106
- maxLength={1}
107
- style={{ border: `1px solid ${getReadableStatus()}` }}
108
- className="otpInput"
109
- autoFocus={autoFocus && index === 0}
110
- />
111
- ))}
112
- </div>
113
- <div className="resendContainer">
114
- {error ? (
115
- <div className="errorText">{errorText}</div>
116
- ) : (
117
- <div className="timerText">
118
- {timer > 0 ? `00:${timer} secs` : ""}
119
- </div>
120
- )}
121
- <button
122
- onClick={handleResendClick}
123
- disabled={timer > 0}
124
- style={{
125
- border: "none",
126
- background: "none",
127
- cursor: timer > 0 ? "not-allowed" : "pointer",
128
- }}
129
- >
130
- <div className="resendText">{resendText}</div>
131
- </button>
132
- </div>
133
- </div>
134
- );
135
- };
136
-
137
- export default OTPInput;
@@ -1 +0,0 @@
1
- export { default } from "./OtpInput";
@@ -1,69 +0,0 @@
1
- .container {
2
- display: flex;
3
- flex-direction: column;
4
- align-items: center;
5
- justify-content: center;
6
- }
7
-
8
- .spinner {
9
- border: 2px solid transparent;
10
- border-radius: 50%;
11
- border-top: 2px solid currentColor;
12
- animation: spin 1s linear infinite;
13
- }
14
-
15
- .spinnerInner {
16
- width: 100%;
17
- height: 100%;
18
- border-radius: 50%;
19
- }
20
-
21
- .errorText {
22
- color: red;
23
- }
24
-
25
- .button {
26
- padding: 8px 16px;
27
- border: none;
28
- border-radius: 4px;
29
- cursor: pointer;
30
- font-size: 16px;
31
-
32
- &-text {
33
- background: none;
34
- }
35
-
36
- &-outlined {
37
- border: 1px solid currentColor;
38
- }
39
-
40
- &-contained {
41
- background-color: currentColor;
42
- color: white;
43
- }
44
-
45
- &-primary {
46
- color: blue;
47
- }
48
-
49
- &-secondary {
50
- color: gray;
51
- }
52
-
53
- &-small {
54
- font-size: 12px;
55
- }
56
-
57
- &-medium {
58
- font-size: 16px;
59
- }
60
-
61
- &-large {
62
- font-size: 20px;
63
- }
64
- }
65
-
66
- @keyframes spin {
67
- 0% { transform: rotate(0deg); }
68
- 100% { transform: rotate(360deg); }
69
- }
@@ -1,52 +0,0 @@
1
- import React from 'react';
2
- import { render, screen, fireEvent, waitFor } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import PdfView from './PdfView';
5
-
6
- // Dummy base64 content for testing
7
- const validBase64Content = 'JVBERi0xLjQKJeLjz9MNCjEgMCBvYmoKPDwvTGluay9QYWdlcyAyIDAgUj4+CnN0YXJ0eHJlZgoyNCAwIFIKZW5kb2JqCjEgMCBvYmoKPDwvTGluay9QYWdlcyAyIDAgUj4+CnN0YXJ0eHJlZgo2IDAgUgo+';
8
- const invalidBase64Content = 'invalid base64 content';
9
- const errorText = 'Failed to load PDF';
10
- const buttonText = 'View PDF';
11
- const loadingText = 'Loading...';
12
-
13
- // Save the original implementation of createObjectURL
14
- const originalCreateObjectURL = global.URL.createObjectURL;
15
-
16
- describe('PdfView Component', () => {
17
- beforeAll(() => {
18
- // Mock URL.createObjectURL directly
19
- global.URL.createObjectURL = jest.fn(() => 'mock-url');
20
- });
21
-
22
- afterAll(() => {
23
- // Restore the original implementation
24
- global.URL.createObjectURL = originalCreateObjectURL;
25
- });
26
-
27
- it('renders correctly with default props', () => {
28
- render(<PdfView content={validBase64Content} />);
29
- expect(screen.getByText(buttonText)).toBeInTheDocument();
30
- });
31
-
32
- it('shows error message if content is invalid', () => {
33
- render(<PdfView content={invalidBase64Content} />);
34
- expect(screen.getByText(errorText)).toBeInTheDocument();
35
- });
36
-
37
- it('applies the provided class names', () => {
38
- const className = 'custom-class';
39
- render(<PdfView content={validBase64Content} className={className} />);
40
- expect(screen.getByText(buttonText).parentElement).toHaveClass(className);
41
- });
42
-
43
-
44
-
45
- it('does not show spinner or loading text if isLoading is false', () => {
46
- render(<PdfView content={validBase64Content} />);
47
-
48
- // The component should not be in a loading state initially
49
- expect(screen.queryByTestId('spinnertest')).not.toBeInTheDocument();
50
- expect(screen.queryByText(loadingText)).not.toBeInTheDocument();
51
- });
52
- });
@@ -1,116 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import styles from './PdfView.module.scss';
3
-
4
- export interface PdfViewerProps {
5
- content: string;
6
- contentType?: string;
7
- buttonText?: string;
8
- loadingText?: string;
9
- errorText?: string;
10
- cleanUpDelay?: number;
11
- buttonVariant?: "text" | "outlined" | "contained";
12
- buttonColor?: "inherit" | "primary" | "secondary" | "error" | "info" | "success" | "warning";
13
- buttonSize?: "small" | "medium" | "large";
14
- showLoadingSpinner?: boolean;
15
- spinnerSize?: number;
16
- spinnerColor?: "inherit" | "primary" | "secondary";
17
- className?: string;
18
- }
19
-
20
- const PdfView: React.FC<PdfViewerProps> = ({
21
- content,
22
- contentType = "application/pdf",
23
- buttonText = "View PDF",
24
- loadingText = "Loading...",
25
- errorText = "Failed to load PDF",
26
- cleanUpDelay = 1000,
27
- buttonVariant = "contained",
28
- buttonColor = "primary",
29
- buttonSize = "medium",
30
- showLoadingSpinner = false,
31
- spinnerSize = 24,
32
- spinnerColor = "primary",
33
- className = "",
34
- }) => {
35
- const [isLoading, setIsLoading] = React.useState(false);
36
- const [isError, setIsError] = React.useState(false);
37
- const [errorMsg, setErrorMsg] = React.useState(errorText);
38
-
39
- useEffect(() => {
40
- if (btoa(atob(content)) !== content) {
41
- setIsError(true);
42
- }
43
- }, [content]);
44
-
45
- const base64ToBlob = (content: string, contentType: string = "application/pdf"): Blob | null => {
46
- try {
47
- const byteCharacters = atob(content);
48
- const byteArray = new Uint8Array(byteCharacters.length);
49
-
50
- for (let i = 0; i < byteCharacters.length; i++) {
51
- byteArray[i] = byteCharacters.charCodeAt(i);
52
- }
53
-
54
- return new Blob([byteArray], { type: contentType });
55
- } catch (error) {
56
- setIsError(true);
57
- setErrorMsg("Invalid base64 string:");
58
- return null;
59
- }
60
- };
61
-
62
- const handleViewPdf = async () => {
63
- setIsLoading(true);
64
- setIsError(false);
65
- const blob = base64ToBlob(content, contentType);
66
- if (blob) {
67
- const url = URL.createObjectURL(blob);
68
-
69
- window.open(url, "_blank");
70
-
71
- setTimeout(() => {
72
- URL.revokeObjectURL(url);
73
- }, cleanUpDelay);
74
- setIsLoading(false);
75
- } else {
76
- setIsLoading(false);
77
- setIsError(true);
78
- setErrorMsg("Failed to create Blob from base64 string.");
79
- }
80
- };
81
-
82
- const buttonClass = `
83
- ${styles.button}
84
- ${styles[`button${buttonVariant.charAt(0).toUpperCase() + buttonVariant.slice(1)}`]}
85
- ${styles[`button${buttonColor.charAt(0).toUpperCase() + buttonColor.slice(1)}`]}
86
- ${styles[`button${buttonSize.charAt(0).toUpperCase() + buttonSize.slice(1)}`]}
87
- `;
88
-
89
- const spinnerClass = `${styles.spinner} ${styles.spinnerInner}`;
90
-
91
- return (
92
- <div className={`${styles.container} ${className}`}>
93
- {isLoading && showLoadingSpinner && (
94
- <div
95
- data-testid="spinnertest"
96
- className={spinnerClass}
97
- style={{ width: spinnerSize, height: spinnerSize, borderColor: spinnerColor }}
98
- >
99
- <div className={styles.spinnerInner}></div>
100
- </div>
101
- )}
102
- {isError && <p className={styles.errorText}>{errorMsg}</p>}
103
- {!isLoading && !isError && (
104
- <button
105
- onClick={handleViewPdf}
106
- className={buttonClass}
107
- >
108
- {buttonText}
109
- </button>
110
- )}
111
- {isLoading && !showLoadingSpinner && <p>{loadingText}</p>}
112
- </div>
113
- );
114
- };
115
-
116
- export default PdfView;
@@ -1 +0,0 @@
1
- export { default } from "./PdfView";
@@ -1,43 +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
-
6
- describe('Progress Component', () => {
7
- it('renders the progress bar with correct percentage width', () => {
8
- render(<Progress value={50} max={100} barClassName="progress-bar" />);
9
- const progressBar = screen.getByTestId('progress-bar');
10
- expect(progressBar).toHaveStyle('width: 50%');
11
- });
12
-
13
- it('renders the label when provided', () => {
14
- render(<Progress value={30} max={100} label="Loading" labelClassName="label-class" />);
15
- expect(screen.getByText('Loading')).toHaveClass('label-class');
16
- });
17
-
18
- it('does not render the label when not provided', () => {
19
- render(<Progress value={30} max={100} />);
20
- expect(screen.queryByText('Loading')).not.toBeInTheDocument();
21
- });
22
-
23
-
24
-
25
- it('handles zero values correctly', () => {
26
- render(<Progress value={0} max={100} barClassName="progress-bar" />);
27
- const progressBar = screen.getByTestId('progress-bar');
28
- expect(progressBar).toHaveStyle('width: 0%');
29
- });
30
-
31
- it('handles max values correctly', () => {
32
- render(<Progress value={100} max={100} barClassName="progress-bar" />);
33
- const progressBar = screen.getByTestId('progress-bar');
34
- expect(progressBar).toHaveStyle('width: 100%');
35
- });
36
-
37
- it('handles values greater than max', () => {
38
- render(<Progress value={150} max={100} barClassName="progress-bar" />);
39
- const progressBar = screen.getByTestId('progress-bar');
40
- expect(progressBar).toHaveStyle('width: 150%'); // Matches the component's behavior
41
- });
42
-
43
- })
@@ -1,35 +0,0 @@
1
- import React from 'react';
2
-
3
- export interface ProgressProps {
4
- value: number;
5
- max: number;
6
- className?: string;
7
- barContainerClassName?: string;
8
- barClassName?: string;
9
- labelClassName?: string;
10
- label?: string;
11
- }
12
-
13
- const Progress: React.FC<ProgressProps> = ({
14
- value,
15
- max,
16
- className = '',
17
- barContainerClassName = '',
18
- barClassName = '',
19
- labelClassName = '',
20
- label,
21
- ...rest
22
- }) => {
23
- const percentage = (value / max) * 100;
24
-
25
- return (
26
- <div className={className} {...rest}>
27
- {label && <div className={labelClassName}>{label}</div>}
28
- <div className={barContainerClassName}>
29
- <div data-testid="progress-bar" className={barClassName} style={{ width: `${percentage}%` }} />
30
- </div>
31
- </div>
32
- );
33
- };
34
-
35
- export default Progress;
@@ -1 +0,0 @@
1
- export { default } from "./Progress";
@@ -1,56 +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
-
6
- describe('CustomRadioButton', () => {
7
- it('should render with given props', () => {
8
- render(
9
- <CustomRadioButton
10
- name="testName"
11
- value="testValue"
12
- checked={true}
13
- onChange={() => {}}
14
- className="custom-class"
15
- inputClassName="input-class"
16
- labelClassName="label-class"
17
- id="radio1"
18
- />
19
- );
20
-
21
- const radioInput = screen.getByRole('radio');
22
- const label = screen.getByText('testValue'); // Use text to find the label
23
-
24
- // Assert that the radio input is rendered correctly
25
- expect(radioInput).toBeInTheDocument();
26
- expect(radioInput).toHaveAttribute('name', 'testName');
27
- expect(radioInput).toHaveAttribute('value', 'testValue');
28
- expect(radioInput).toBeChecked();
29
- expect(radioInput).toHaveClass('input-class');
30
-
31
- // Assert that the label is rendered correctly
32
- expect(label).toBeInTheDocument();
33
-
34
- // Ensure the label has the correct class by finding the label element directly
35
- const labelElement = document.querySelector(`label[for="radio1"]`);
36
- expect(labelElement).toHaveClass('label-class');
37
- });
38
-
39
- it('should call onChange handler when clicked', () => {
40
- const handleChange = jest.fn();
41
-
42
- render(
43
- <CustomRadioButton
44
- name="testName"
45
- value="testValue"
46
- onChange={handleChange}
47
- id="radio1"
48
- />
49
- );
50
-
51
- const radioInput = screen.getByRole('radio');
52
- fireEvent.click(radioInput);
53
-
54
- expect(handleChange).toHaveBeenCalled();
55
- });
56
- });
@@ -1,43 +0,0 @@
1
- import React from 'react';
2
-
3
- interface RadioButtonProps {
4
- name: string;
5
- value: string;
6
- checked?: boolean;
7
- onChange?: React.ChangeEventHandler<HTMLInputElement>;
8
- className?: string;
9
- inputClassName?: string;
10
- labelClassName?: string;
11
- id?: string;
12
- [key: string]: any;
13
- }
14
-
15
- const CustomRadioButton: React.FC<RadioButtonProps> = ({
16
- name,
17
- value,
18
- checked = false,
19
- onChange,
20
- className = '',
21
- inputClassName = '',
22
- labelClassName = '',
23
- id,
24
- ...rest
25
- }) => {
26
- return (
27
- <div className={className}>
28
- <input
29
- type="radio"
30
- name={name}
31
- value={value}
32
- checked={checked}
33
- onChange={onChange}
34
- id={id}
35
- className={inputClassName}
36
- {...rest}
37
- />
38
- <label htmlFor={id} className={labelClassName}>{value}</label>
39
- </div>
40
- );
41
- };
42
-
43
- export default CustomRadioButton;
@@ -1 +0,0 @@
1
- export { default } from "./RadioButton";
@@ -1,83 +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
-
6
- describe('Switch Component', () => {
7
- it('renders with basic props', () => {
8
- const { container } = render(<Switch checked={true} handleChange={() => {}} switchClassName="switch-class" />);
9
-
10
- const switchInput = screen.getByRole('checkbox');
11
- const switchToggle = container.querySelector('.switch-class');
12
-
13
- expect(switchInput).toBeInTheDocument();
14
- expect(switchInput).toBeChecked();
15
- expect(switchToggle).toBeInTheDocument();
16
- });
17
-
18
- it('renders with a label', () => {
19
- render(
20
- <Switch
21
- checked={true}
22
- handleChange={() => {}}
23
- switchClassName="switch-class"
24
- label="Toggle Switch"
25
- labelClassName="label-class"
26
- />
27
- );
28
-
29
- const label = screen.getByText('Toggle Switch');
30
- const switchInput = screen.getByRole('checkbox');
31
-
32
- expect(label).toBeInTheDocument();
33
- expect(label).toHaveClass('label-class');
34
- expect(switchInput).toBeChecked();
35
- });
36
-
37
- it('calls handleChange handler when clicked', () => {
38
- // Simulate a component that manages its own state
39
- const TestComponent = () => {
40
- const [checked, setChecked] = useState(false);
41
- return (
42
- <Switch
43
- checked={checked}
44
- handleChange={() => setChecked(!checked)}
45
- switchClassName="switch-class"
46
- />
47
- );
48
- };
49
-
50
- render(<TestComponent />);
51
-
52
- const switchInput = screen.getByRole('checkbox');
53
- expect(switchInput).not.toBeChecked();
54
-
55
- // Simulate the click event
56
- fireEvent.click(switchInput);
57
-
58
- // Check if the switchInput is now checked
59
- expect(switchInput).toBeChecked();
60
- });
61
-
62
- it('applies custom classes', () => {
63
- const { container } = render(
64
- <Switch
65
- checked={true}
66
- handleChange={() => {}}
67
- switchClassName="switch-class"
68
- containerClassName="container-class"
69
- toggleClassName="toggle-class"
70
- label="Toggle Switch"
71
- labelClassName="label-class"
72
- />
73
- );
74
-
75
- const containerDiv = container.querySelector('.container-class');
76
- const switchToggle = container.querySelector('.switch-class');
77
- const label = screen.getByText('Toggle Switch');
78
-
79
- expect(containerDiv).toHaveClass('container-class');
80
- expect(switchToggle).toHaveClass('switch-class');
81
- expect(label).toHaveClass('label-class');
82
- });
83
- });
@@ -1,38 +0,0 @@
1
- import React from "react";
2
- import './Switch.css';
3
-
4
- export interface SwitchProps {
5
- checked: boolean;
6
- handleChange: () => void;
7
- switchClassName: string;
8
- label?: string;
9
- labelClassName?: string;
10
- containerClassName?: string;
11
- toggleClassName?:string,
12
- }
13
-
14
- const Switch: React.FC<SwitchProps> = ({
15
- checked,
16
- handleChange,
17
- switchClassName,
18
- label,
19
- labelClassName,
20
- containerClassName,
21
- toggleClassName
22
- }) => {
23
- return (
24
- <div className={containerClassName}>
25
- {label && <span className={labelClassName}>{label}</span>}
26
- <label className={toggleClassName}>
27
- <input
28
- type="checkbox"
29
- checked={checked}
30
- onChange={handleChange}
31
- />
32
- <span className={switchClassName}></span>
33
- </label>
34
- </div>
35
- );
36
- };
37
-
38
- export default Switch;
@@ -1 +0,0 @@
1
- export { default } from "./Switch";