dhre-component-lib 0.1.6 → 0.1.7
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.
- package/dist/components/Avatar/Avatar.d.ts +9 -0
- package/dist/components/Avatar/Avatar.js +6 -0
- package/dist/components/Avatar/Avatar.test.d.ts +1 -0
- package/dist/components/Avatar/Avatar.test.js +39 -0
- package/dist/components/Avatar/index.d.ts +1 -0
- package/dist/components/Avatar/index.js +1 -0
- package/dist/components/Badge/Badge.d.ts +8 -0
- package/dist/components/Badge/Badge.js +6 -0
- package/dist/components/Badge/Badge.test.d.ts +1 -0
- package/dist/components/Badge/Badge.test.js +44 -0
- package/dist/components/Badge/index.d.ts +2 -0
- package/dist/components/Badge/index.js +2 -0
- package/dist/components/BreadCrumb/BreadCrumb.d.ts +14 -0
- package/dist/components/BreadCrumb/BreadCrumb.js +8 -0
- package/dist/components/BreadCrumb/BreadCrumb.test.d.ts +1 -0
- package/dist/components/BreadCrumb/BreadCrumb.test.js +55 -0
- package/dist/components/BreadCrumb/index.d.ts +2 -0
- package/dist/components/BreadCrumb/index.js +2 -0
- package/dist/components/Button/Button.d.ts +10 -0
- package/dist/components/Button/Button.js +6 -0
- package/dist/components/Button/Button.test.d.ts +1 -0
- package/dist/components/Button/Button.test.js +36 -0
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/Button/index.js +2 -0
- package/dist/components/Checkbox/Checkbox.d.ts +11 -0
- package/dist/components/Checkbox/Checkbox.js +7 -0
- package/dist/components/Checkbox/Checkbox.test.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.test.js +59 -0
- package/dist/components/Checkbox/index.d.ts +1 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/CircularProgress/CircularProgress.d.ts +10 -0
- package/dist/components/CircularProgress/CircularProgress.js +15 -0
- package/dist/components/CircularProgress/CircularProgress.test.d.ts +1 -0
- package/dist/components/CircularProgress/CircularProgress.test.js +31 -0
- package/dist/components/CircularProgress/index.d.ts +2 -0
- package/dist/components/CircularProgress/index.js +2 -0
- package/dist/components/Divider/Divider.d.ts +8 -0
- package/dist/components/Divider/Divider.js +7 -0
- package/dist/components/Divider/Divider.test.d.ts +1 -0
- package/dist/components/Divider/Divider.test.js +30 -0
- package/dist/components/Divider/index.d.ts +1 -0
- package/dist/components/Divider/index.js +1 -0
- package/dist/components/Enum.d.ts +17 -0
- package/dist/components/Enum.js +17 -0
- package/dist/components/InputTextField/InputTextField.d.ts +16 -0
- package/dist/components/InputTextField/InputTextField.js +9 -0
- package/dist/components/InputTextField/InputTextField.test.d.ts +1 -0
- package/dist/components/InputTextField/InputTextField.test.js +98 -0
- package/dist/components/InputTextField/index.d.ts +1 -0
- package/dist/components/InputTextField/index.js +1 -0
- package/dist/components/Link/Link.d.ts +10 -0
- package/dist/components/Link/Link.js +6 -0
- package/dist/components/Link/Link.test.d.ts +1 -0
- package/dist/components/Link/Link.test.js +47 -0
- package/dist/components/Link/index.d.ts +1 -0
- package/dist/components/Link/index.js +1 -0
- package/dist/components/Map/Directions.d.ts +13 -0
- package/dist/components/Map/Directions.js +9 -0
- package/dist/components/Map/GoogleMap.d.ts +12 -0
- package/dist/components/Map/GoogleMap.js +104 -0
- package/dist/components/Map/GoogleMapsLoader.d.ts +4 -0
- package/dist/components/Map/GoogleMapsLoader.js +10 -0
- package/dist/components/Map/index.d.ts +3 -0
- package/dist/components/Map/index.js +3 -0
- package/dist/components/Modal/Modal.d.ts +10 -0
- package/dist/components/Modal/Modal.js +14 -0
- package/dist/components/Modal/Modal.test.d.ts +1 -0
- package/dist/components/Modal/Modal.test.js +52 -0
- package/dist/components/Modal/index.d.ts +2 -0
- package/dist/components/Modal/index.js +2 -0
- package/dist/components/Notification/Notification.d.ts +10 -0
- package/dist/components/Notification/Notification.js +21 -0
- package/dist/components/Notification/Notification.test.d.ts +1 -0
- package/dist/components/Notification/Notification.test.js +40 -0
- package/dist/components/Notification/index.d.ts +2 -0
- package/dist/components/Notification/index.js +2 -0
- package/dist/components/OtpInput/OtpInput.d.ts +14 -0
- package/dist/components/OtpInput/OtpInput.js +68 -0
- package/dist/components/OtpInput/OtpInput.test.d.ts +1 -0
- package/dist/components/OtpInput/OtpInput.test.js +36 -0
- package/dist/components/OtpInput/index.d.ts +2 -0
- package/dist/components/OtpInput/index.js +2 -0
- package/dist/components/PdfView/PdfView.d.ts +18 -0
- package/dist/components/PdfView/PdfView.js +59 -0
- package/dist/components/PdfView/PdfView.test.d.ts +1 -0
- package/dist/components/PdfView/PdfView.test.js +41 -0
- package/dist/components/PdfView/index.d.ts +2 -0
- package/dist/components/PdfView/index.js +2 -0
- package/dist/components/Progress/Progress.d.ts +12 -0
- package/dist/components/Progress/Progress.js +9 -0
- package/dist/components/Progress/Progress.test.d.ts +1 -0
- package/dist/components/Progress/Progress.test.js +34 -0
- package/dist/components/Progress/index.d.ts +1 -0
- package/dist/components/Progress/index.js +1 -0
- package/dist/components/RadioButton/RadioButton.d.ts +14 -0
- package/dist/components/RadioButton/RadioButton.js +7 -0
- package/dist/components/RadioButton/RadioButton.test.d.ts +1 -0
- package/dist/components/RadioButton/RadioButton.test.js +29 -0
- package/dist/components/RadioButton/index.d.ts +1 -0
- package/dist/components/RadioButton/index.js +1 -0
- package/dist/components/Switch/Switch.d.ts +13 -0
- package/dist/components/Switch/Switch.js +10 -0
- package/dist/components/Switch/Switch.test.d.ts +1 -0
- package/dist/components/Switch/Switch.test.js +45 -0
- package/dist/components/Switch/index.d.ts +1 -0
- package/dist/components/Switch/index.js +1 -0
- package/dist/components/Tag/Tag.d.ts +9 -0
- package/dist/components/Tag/Tag.js +6 -0
- package/dist/components/Tag/Tag.test.d.ts +1 -0
- package/dist/components/Tag/Tag.test.js +43 -0
- package/dist/components/Tag/index.d.ts +1 -0
- package/dist/components/Tag/index.js +1 -0
- package/dist/components/Tooltip/Tooltip.d.ts +9 -0
- package/dist/components/Tooltip/Tooltip.js +11 -0
- package/dist/components/Tooltip/Tooltip.test.d.ts +1 -0
- package/dist/components/Tooltip/Tooltip.test.js +48 -0
- package/dist/components/Tooltip/index.d.ts +2 -0
- package/dist/components/Tooltip/index.js +2 -0
- package/dist/components/index.d.ts +15 -0
- package/dist/components/index.js +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/theme/colors.d.ts +1 -0
- package/dist/theme/colors.js +2 -0
- package/package.json +16 -7
- package/src/components/Badge/index.ts +2 -1
- package/src/components/BreadCrumb/index.ts +2 -1
- package/src/components/Button/index.ts +2 -1
- package/src/components/CircularProgress/index.ts +2 -1
- package/src/components/Map/index.ts +1 -0
- package/src/components/Modal/index.ts +2 -1
- package/src/components/Notification/index.ts +2 -1
- package/src/components/OtpInput/index.ts +2 -1
- package/src/components/PdfView/index.ts +2 -1
- package/src/components/Tooltip/index.ts +2 -1
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface PdfViewerProps {
|
|
3
|
+
content: string;
|
|
4
|
+
contentType?: string;
|
|
5
|
+
buttonText?: string;
|
|
6
|
+
loadingText?: string;
|
|
7
|
+
errorText?: string;
|
|
8
|
+
cleanUpDelay?: number;
|
|
9
|
+
buttonVariant?: "text" | "outlined" | "contained";
|
|
10
|
+
buttonColor?: "inherit" | "primary" | "secondary" | "error" | "info" | "success" | "warning";
|
|
11
|
+
buttonSize?: "small" | "medium" | "large";
|
|
12
|
+
showLoadingSpinner?: boolean;
|
|
13
|
+
spinnerSize?: number;
|
|
14
|
+
spinnerColor?: "inherit" | "primary" | "secondary";
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
declare const PdfView: React.FC<PdfViewerProps>;
|
|
18
|
+
export default PdfView;
|
|
@@ -0,0 +1,59 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface ProgressProps {
|
|
3
|
+
value: number;
|
|
4
|
+
max: number;
|
|
5
|
+
className?: string;
|
|
6
|
+
barContainerClassName?: string;
|
|
7
|
+
barClassName?: string;
|
|
8
|
+
labelClassName?: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const Progress: React.FC<ProgressProps>;
|
|
12
|
+
export default Progress;
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Progress";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Progress";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface RadioButtonProps {
|
|
3
|
+
name: string;
|
|
4
|
+
value: string;
|
|
5
|
+
checked?: boolean;
|
|
6
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
7
|
+
className?: string;
|
|
8
|
+
inputClassName?: string;
|
|
9
|
+
labelClassName?: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
declare const CustomRadioButton: React.FC<RadioButtonProps>;
|
|
14
|
+
export default CustomRadioButton;
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./RadioButton";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./RadioButton";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import './Switch.css';
|
|
3
|
+
export interface SwitchProps {
|
|
4
|
+
checked: boolean;
|
|
5
|
+
handleChange: () => void;
|
|
6
|
+
switchClassName: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
labelClassName?: string;
|
|
9
|
+
containerClassName?: string;
|
|
10
|
+
toggleClassName?: string;
|
|
11
|
+
}
|
|
12
|
+
declare const Switch: React.FC<SwitchProps>;
|
|
13
|
+
export default Switch;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Switch";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Switch";
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import Tag from './Tag';
|
|
5
|
+
describe('Tag Component', () => {
|
|
6
|
+
let handleClick;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
handleClick = jest.fn(); // Reset the mock function before each test
|
|
9
|
+
});
|
|
10
|
+
// Function to generate default props for each test
|
|
11
|
+
const getDefaultProps = () => ({
|
|
12
|
+
content: 'Sample Tag',
|
|
13
|
+
tagClassName: 'tag-class',
|
|
14
|
+
handleClick,
|
|
15
|
+
});
|
|
16
|
+
it('renders the tag with the correct content', () => {
|
|
17
|
+
render(React.createElement(Tag, { ...getDefaultProps() }));
|
|
18
|
+
const tagElement = screen.getByText('Sample Tag');
|
|
19
|
+
expect(tagElement).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
it('applies the correct className to the tag', () => {
|
|
22
|
+
render(React.createElement(Tag, { ...getDefaultProps() }));
|
|
23
|
+
const tagElement = screen.getByText('Sample Tag');
|
|
24
|
+
expect(tagElement).toHaveClass('tag-class');
|
|
25
|
+
});
|
|
26
|
+
it('calls the handleClick function when the tag is clicked', () => {
|
|
27
|
+
render(React.createElement(Tag, { ...getDefaultProps() }));
|
|
28
|
+
const tagElement = screen.getByText('Sample Tag');
|
|
29
|
+
fireEvent.click(tagElement);
|
|
30
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
31
|
+
});
|
|
32
|
+
it('does not call handleClick when the tag is not clicked', () => {
|
|
33
|
+
render(React.createElement(Tag, { ...getDefaultProps() }));
|
|
34
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
it('renders correctly with different content', () => {
|
|
37
|
+
const newContent = 'New Tag Content';
|
|
38
|
+
render(React.createElement(Tag, { ...getDefaultProps(), content: newContent }));
|
|
39
|
+
const tagElement = screen.getByText(newContent);
|
|
40
|
+
expect(tagElement).toBeInTheDocument();
|
|
41
|
+
expect(tagElement).toHaveTextContent(newContent);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Tag";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Tag";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import styles from './Tooltip.module.scss';
|
|
3
|
+
const Tooltip = ({ content, tooltipClassName, children, containerClassName = "", }) => {
|
|
4
|
+
const [visible, setVisible] = useState(false);
|
|
5
|
+
const showTooltip = () => setVisible(true);
|
|
6
|
+
const hideTooltip = () => setVisible(false);
|
|
7
|
+
return (React.createElement("div", { className: `${styles.tooltipWrapper} ${containerClassName}`, onMouseEnter: showTooltip, onMouseLeave: hideTooltip },
|
|
8
|
+
children,
|
|
9
|
+
visible && (React.createElement("div", { className: `${styles.customTooltipClass} ${tooltipClassName}` }, content))));
|
|
10
|
+
};
|
|
11
|
+
export default Tooltip;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
3
|
+
import "@testing-library/jest-dom";
|
|
4
|
+
import Tooltip from "./Tooltip";
|
|
5
|
+
describe("Tooltip Component", () => {
|
|
6
|
+
const defaultProps = {
|
|
7
|
+
content: "Tooltip content",
|
|
8
|
+
tooltipClassName: "tooltip-class",
|
|
9
|
+
children: React.createElement("button", null, "Hover me"),
|
|
10
|
+
};
|
|
11
|
+
it("renders the children correctly", () => {
|
|
12
|
+
render(React.createElement(Tooltip, { ...defaultProps }));
|
|
13
|
+
const childElement = screen.getByText("Hover me");
|
|
14
|
+
expect(childElement).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
it("does not show tooltip content by default", () => {
|
|
17
|
+
render(React.createElement(Tooltip, { ...defaultProps }));
|
|
18
|
+
const tooltipElement = screen.queryByText(defaultProps.content);
|
|
19
|
+
expect(tooltipElement).not.toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
it("shows tooltip content on mouse enter and hides it on mouse leave", () => {
|
|
22
|
+
render(React.createElement(Tooltip, { ...defaultProps }));
|
|
23
|
+
const childElement = screen.getByText("Hover me");
|
|
24
|
+
// Trigger mouse enter
|
|
25
|
+
fireEvent.mouseEnter(childElement);
|
|
26
|
+
let tooltipElement = screen.queryByText(defaultProps.content);
|
|
27
|
+
expect(tooltipElement).toBeInTheDocument();
|
|
28
|
+
expect(tooltipElement).toHaveClass(defaultProps.tooltipClassName);
|
|
29
|
+
// Trigger mouse leave
|
|
30
|
+
fireEvent.mouseLeave(childElement);
|
|
31
|
+
tooltipElement = screen.queryByText(defaultProps.content);
|
|
32
|
+
// Ensure tooltipElement is null if it was not found
|
|
33
|
+
expect(tooltipElement).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
it("applies the correct container className", () => {
|
|
36
|
+
const customClassName = "custom-container-class";
|
|
37
|
+
render(React.createElement(Tooltip, { ...defaultProps, containerClassName: customClassName }));
|
|
38
|
+
const containerElement = screen.getByText("Hover me").parentElement;
|
|
39
|
+
expect(containerElement).toHaveClass(customClassName);
|
|
40
|
+
});
|
|
41
|
+
it("handles tooltip visibility correctly", () => {
|
|
42
|
+
render(React.createElement(Tooltip, { ...defaultProps }));
|
|
43
|
+
const childElement = screen.getByText("Hover me");
|
|
44
|
+
fireEvent.mouseEnter(childElement);
|
|
45
|
+
const tooltipElement = screen.queryByText(defaultProps.content);
|
|
46
|
+
expect(tooltipElement).toBeInTheDocument();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { default as Button } from "./Button";
|
|
2
|
+
export { default as Avatar } from "./Avatar";
|
|
3
|
+
export { default as Badge } from "./Badge";
|
|
4
|
+
export { default as BreadCrumb } from "./BreadCrumb";
|
|
5
|
+
export { default as Checkbox } from "./Checkbox";
|
|
6
|
+
export { default as CircularProgress } from "./CircularProgress";
|
|
7
|
+
export { default as Divider } from "./Divider";
|
|
8
|
+
export { default as Link } from "./Link";
|
|
9
|
+
export { default as Progress } from "./Progress";
|
|
10
|
+
export { default as RadioButton } from "./RadioButton";
|
|
11
|
+
export { default as InputTextField } from "./InputTextField";
|
|
12
|
+
export { default } from "./PdfView";
|
|
13
|
+
export { default as Directions } from "./Map/Directions";
|
|
14
|
+
export { default as GoogleMap } from "./Map/GoogleMap";
|
|
15
|
+
export { default as OtpInput } from "./OtpInput/OtpInput";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { default as Button } from "./Button";
|
|
2
|
+
export { default as Avatar } from "./Avatar";
|
|
3
|
+
export { default as Badge } from "./Badge";
|
|
4
|
+
export { default as BreadCrumb } from "./BreadCrumb";
|
|
5
|
+
export { default as Checkbox } from "./Checkbox";
|
|
6
|
+
export { default as CircularProgress } from "./CircularProgress";
|
|
7
|
+
export { default as Divider } from "./Divider";
|
|
8
|
+
export { default as Link } from "./Link";
|
|
9
|
+
export { default as Progress } from "./Progress";
|
|
10
|
+
export { default as RadioButton } from "./RadioButton";
|
|
11
|
+
export { default as InputTextField } from "./InputTextField";
|
|
12
|
+
export { default } from "./PdfView";
|
|
13
|
+
export { default as Directions } from "./Map/Directions";
|
|
14
|
+
export { default as GoogleMap } from "./Map/GoogleMap";
|
|
15
|
+
export { default as OtpInput } from "./OtpInput/OtpInput";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const COLORS: {};
|