dhre-component-lib 0.0.1

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 (60) hide show
  1. package/jest.config.ts +10 -0
  2. package/package.json +47 -0
  3. package/rollup.config.mjs +37 -0
  4. package/setupTests.ts +1 -0
  5. package/src/__mocks__/styleMock.js +1 -0
  6. package/src/components/Avatar/Avatar.tsx +26 -0
  7. package/src/components/Avatar/index.ts +1 -0
  8. package/src/components/Badge/Badge.css +15 -0
  9. package/src/components/Badge/Badge.tsx +25 -0
  10. package/src/components/Badge/index.ts +1 -0
  11. package/src/components/BreadCrumb/BreadCrumb.tsx +36 -0
  12. package/src/components/BreadCrumb/Breadcrumb.css +21 -0
  13. package/src/components/BreadCrumb/index.ts +0 -0
  14. package/src/components/Button/Button.css +92 -0
  15. package/src/components/Button/Button.tsx +22 -0
  16. package/src/components/Button/index.ts +1 -0
  17. package/src/components/Checkbox/Checkbox.test.tsx +61 -0
  18. package/src/components/Checkbox/Checkbox.tsx +35 -0
  19. package/src/components/Checkbox/index.ts +1 -0
  20. package/src/components/Circular_Progress/CircularProgress.css +19 -0
  21. package/src/components/Circular_Progress/CircularProgress.test.tsx +47 -0
  22. package/src/components/Circular_Progress/CircularProgress.tsx +37 -0
  23. package/src/components/Circular_Progress/index.ts +1 -0
  24. package/src/components/Divider/Divider.test.tsx +19 -0
  25. package/src/components/Divider/Divider.tsx +24 -0
  26. package/src/components/Divider/index.ts +1 -0
  27. package/src/components/Enum.ts +19 -0
  28. package/src/components/InputTextField/InputTextField.test.tsx +48 -0
  29. package/src/components/InputTextField/InputTextField.tsx +46 -0
  30. package/src/components/InputTextField/index.ts +1 -0
  31. package/src/components/Link/Link.test.tsx +47 -0
  32. package/src/components/Link/Link.tsx +33 -0
  33. package/src/components/Link/index.ts +1 -0
  34. package/src/components/Modal/Modal.test.tsx +51 -0
  35. package/src/components/Modal/Modal.tsx +19 -0
  36. package/src/components/Modal/index.ts +1 -0
  37. package/src/components/Notification/Notification.css +20 -0
  38. package/src/components/Notification/Notification.test.tsx +53 -0
  39. package/src/components/Notification/Notification.tsx +42 -0
  40. package/src/components/Notification/index.ts +1 -0
  41. package/src/components/PdfView/PdfView.test.tsx +79 -0
  42. package/src/components/PdfView/PdfView.tsx +93 -0
  43. package/src/components/PdfView/index.ts +1 -0
  44. package/src/components/Progress/Progress.test.tsx +35 -0
  45. package/src/components/Progress/Progress.tsx +35 -0
  46. package/src/components/Progress/index.ts +1 -0
  47. package/src/components/RadioButton/RadioButton.test.tsx +38 -0
  48. package/src/components/RadioButton/RadioButton.tsx +43 -0
  49. package/src/components/RadioButton/index.ts +1 -0
  50. package/src/components/Switch/Switch.tsx +38 -0
  51. package/src/components/Switch/index.ts +1 -0
  52. package/src/components/Tag/Tag.css +15 -0
  53. package/src/components/Tag/Tag.tsx +25 -0
  54. package/src/components/Tag/index.ts +1 -0
  55. package/src/components/Tooltip/Tooltip.css +38 -0
  56. package/src/components/Tooltip/Tooltip.tsx +34 -0
  57. package/src/components/Tooltip/index.ts +1 -0
  58. package/src/components/index.ts +11 -0
  59. package/src/index.ts +1 -0
  60. package/tsconfig.json +121 -0
package/jest.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ require('ts-node').register();
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'jsdom',
5
+ setupFilesAfterEnv: ['./setupTests.ts'],
6
+ moduleNameMapper: {
7
+ '\\.(css|less|sass|scss)$': '<rootDir>/src/__mocks__/styleMock.js', // Mock CSS files
8
+ },
9
+ };
10
+
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "dhre-component-lib",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "scripts": {
6
+ "test": "jest",
7
+ "rollup": "rollup -c"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "description": "",
12
+ "devDependencies": {
13
+ "@rollup/plugin-commonjs": "^26.0.1",
14
+ "@rollup/plugin-node-resolve": "^15.2.3",
15
+ "@rollup/plugin-typescript": "^11.1.6",
16
+ "@testing-library/jest-dom": "^6.4.8",
17
+ "@types/jest": "^29.5.12",
18
+ "@types/react": "^18.3.3",
19
+ "@types/testing-library__jest-dom": "^6.0.0",
20
+ "jest": "^29.7.0",
21
+ "jest-dom": "^4.0.0",
22
+ "jest-environment-jsdom": "^29.7.0",
23
+ "react": "^18.3.1",
24
+ "react-testing-library": "^8.0.1",
25
+ "rollup": "^4.18.1",
26
+ "rollup-plugin-dts": "^6.1.1",
27
+ "rollup-plugin-peer-deps-external": "^2.2.4",
28
+ "ts-jest": "^29.2.4",
29
+ "ts-node": "^10.9.2",
30
+ "typescript": "^5.5.3"
31
+ },
32
+ "dependencies": {
33
+ "@emotion/react": "^11.13.3",
34
+ "@emotion/styled": "^11.13.0",
35
+ "@mui/icons-material": "^5.16.7",
36
+ "@mui/material": "^5.16.7",
37
+ "@testing-library/react": "^16.0.0",
38
+ "tslib": "^2.6.3"
39
+ },
40
+ "peerDependencies": {
41
+ "react": "^18.3.1",
42
+ "react-dom": "^18.3.1"
43
+ },
44
+ "main": "dist/cjs/index.js",
45
+ "module": "dist/esm/index.js",
46
+ "types": "dist/index.d.ts"
47
+ }
@@ -0,0 +1,37 @@
1
+ import resolve from "@rollup/plugin-node-resolve";
2
+ import commonjs from "@rollup/plugin-commonjs";
3
+ import typescript from "@rollup/plugin-typescript";
4
+ import dts from "rollup-plugin-dts";
5
+ import PeerDepsExternalPlugin from 'rollup-plugin-peer-deps-external';
6
+
7
+ import packageJson from "./package.json" assert { type: "json" };
8
+
9
+ export default [
10
+ {
11
+ input: "src/index.ts",
12
+ output: [
13
+ {
14
+ file: packageJson.main,
15
+ format: "cjs",
16
+ sourcemap: true,
17
+ },
18
+ {
19
+ file: packageJson.module,
20
+ format: "esm",
21
+ sourcemap: true,
22
+ },
23
+ ],
24
+ plugins: [
25
+ resolve(),
26
+ commonjs(),
27
+ typescript({ tsconfig: "./tsconfig.json" }),
28
+ PeerDepsExternalPlugin(),
29
+ ],
30
+ //external: ['react', 'react-dom', '@mui/material', '@emotion/react', '@emotion/styled'],
31
+ },
32
+ {
33
+ input: "dist/esm/types/index.d.ts",
34
+ output: [{ file: "dist/index.d.ts", format: "esm" }],
35
+ plugins: [dts()],
36
+ },
37
+ ];
package/setupTests.ts ADDED
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1 @@
1
+ module.exports = {};
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+
3
+ export interface AvatarProps {
4
+ src: string;
5
+ alt: string;
6
+ imgClassName: string;
7
+ handleClick?: () => void;
8
+ }
9
+
10
+ const Avatar: React.FC<AvatarProps> = ({
11
+ src,
12
+ alt,
13
+ imgClassName,
14
+ handleClick,
15
+ }) => {
16
+ return (
17
+ <img
18
+ src={src}
19
+ alt={alt}
20
+ onClick={handleClick}
21
+ className={imgClassName}
22
+ />
23
+ );
24
+ };
25
+
26
+ export default Avatar;
@@ -0,0 +1 @@
1
+ export { default } from "./Avatar";
@@ -0,0 +1,15 @@
1
+ .custom-badge-class {
2
+ display: inline-block;
3
+ padding: 6px 12px;
4
+ background-color: red;
5
+ color: white;
6
+ border-radius: 12px;
7
+ font-size: 14px;
8
+ text-align: center;
9
+ cursor: pointer;
10
+ }
11
+
12
+ .custom-badge-class:hover {
13
+ background-color: darkred;
14
+ }
15
+
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import './Badge.css';
3
+
4
+ export interface BadgeProps {
5
+ content: string | number;
6
+ badgeClassName: string;
7
+ handleClick?: () => void;
8
+ }
9
+
10
+ const Badge: React.FC<BadgeProps> = ({
11
+ content,
12
+ badgeClassName,
13
+ handleClick,
14
+ }) => {
15
+ return (
16
+ <span
17
+ onClick={handleClick}
18
+ className={badgeClassName}
19
+ >
20
+ {content}
21
+ </span>
22
+ );
23
+ };
24
+
25
+ export default Badge;
@@ -0,0 +1 @@
1
+ export { default } from "./Badge";
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import './Breadcrumb.css';
3
+
4
+ export interface BreadcrumbItem {
5
+ label: string;
6
+ handleClick?: () => void;
7
+ }
8
+
9
+ export interface BreadcrumbProps {
10
+ items: BreadcrumbItem[];
11
+ breadcrumbClassName: string;
12
+ itemClassName?: string;
13
+ separator?: string;
14
+ separatorClassName?: string,
15
+ }
16
+
17
+ const Breadcrumb: React.FC<BreadcrumbProps> = ({
18
+ items,
19
+ breadcrumbClassName,
20
+ itemClassName,
21
+ separator = "/",
22
+ separatorClassName,
23
+ }) => {
24
+ return (
25
+ <nav className={breadcrumbClassName}>
26
+ {items.map((item, index) => (
27
+ <span key={index} className={itemClassName} onClick={item.handleClick}>
28
+ {item.label}
29
+ {index < items.length - 1 && <span className={separatorClassName}>{separator}</span>}
30
+ </span>
31
+ ))}
32
+ </nav>
33
+ );
34
+ };
35
+
36
+ export default Breadcrumb;
@@ -0,0 +1,21 @@
1
+ .custom-breadcrumb-class {
2
+ display: flex;
3
+ align-items: center;
4
+ font-size: 16px;
5
+ }
6
+
7
+ .custom-breadcrumb-item {
8
+ color: blue;
9
+ cursor: pointer;
10
+ margin-right: 8px;
11
+ }
12
+
13
+ .custom-breadcrumb-item:hover {
14
+ text-decoration: underline;
15
+ }
16
+
17
+ .breadcrumb-separator {
18
+ margin: 0 8px;
19
+ color: grey;
20
+ }
21
+
File without changes
@@ -0,0 +1,92 @@
1
+ /* Base button styling */
2
+ .button {
3
+ padding: 8px 16px;
4
+ font-size: 14px;
5
+ border-radius: 4px;
6
+ border: none;
7
+ cursor: pointer;
8
+ transition: background-color 0.3s ease;
9
+ }
10
+
11
+ /* Variants */
12
+ .button.text {
13
+ background-color: transparent;
14
+ color: inherit;
15
+ }
16
+
17
+ .button.outlined {
18
+ background-color: transparent;
19
+ border: 2px solid currentColor;
20
+ }
21
+
22
+ .button.contained {
23
+ background-color: currentColor;
24
+ color: #fff;
25
+ }
26
+
27
+ /* Colors */
28
+ .button.primary {
29
+ color: #1976d2;
30
+ }
31
+
32
+ .button.secondary {
33
+ color: #9c27b0;
34
+ }
35
+
36
+ .button.success {
37
+ color: #4caf50;
38
+ }
39
+
40
+ .button.error {
41
+ color: #f44336;
42
+ }
43
+
44
+ .button.warning {
45
+ color: #ff9800;
46
+ }
47
+
48
+ .button.info {
49
+ color: #2196f3;
50
+ }
51
+
52
+ /* Sizes */
53
+ .button.small {
54
+ padding: 4px 8px;
55
+ font-size: 12px;
56
+ }
57
+
58
+ .button.medium {
59
+ padding: 8px 16px;
60
+ font-size: 14px;
61
+ }
62
+
63
+ .button.large {
64
+ padding: 12px 24px;
65
+ font-size: 16px;
66
+ }
67
+
68
+ /* Hover effects for contained buttons */
69
+ .button.contained.primary:hover {
70
+ background-color: #1565c0;
71
+ }
72
+
73
+ .button.contained.secondary:hover {
74
+ background-color: #7b1fa2;
75
+ }
76
+
77
+ .button.contained.success:hover {
78
+ background-color: #388e3c;
79
+ }
80
+
81
+ .button.contained.error:hover {
82
+ background-color: #d32f2f;
83
+ }
84
+
85
+ .button.contained.warning:hover {
86
+ background-color: #f57c00;
87
+ }
88
+
89
+ .button.contained.info:hover {
90
+ background-color: #1976d2;
91
+ }
92
+
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import './Button.css';
3
+
4
+ export interface ButtonProps {
5
+ label: string;
6
+ labelClassName: string;
7
+ handleClick: () => void;
8
+ }
9
+
10
+ const Button: React.FC<ButtonProps> = ({
11
+ label,
12
+ labelClassName,
13
+ handleClick,
14
+ }) => {
15
+ return (
16
+ <button onClick={handleClick} className={labelClassName}>
17
+ {label}
18
+ </button>
19
+ );
20
+ };
21
+
22
+ export default Button;
@@ -0,0 +1 @@
1
+ export { default } from "./Button";
@@ -0,0 +1,61 @@
1
+ import React from "react";
2
+ import { render, fireEvent } from "@testing-library/react";
3
+ import Checkbox from "./Checkbox";
4
+
5
+ describe("Checkbox Component", () => {
6
+ it("should render without crashing", () => {
7
+ const { getByTestId } = render(
8
+ <Checkbox data-testid="checkbox-rendered" />
9
+ );
10
+ expect(getByTestId("checkbox-rendered")).toBeInTheDocument();
11
+ });
12
+
13
+ it("should render with default props", () => {
14
+ const { getByRole } = render(<Checkbox />);
15
+ const checkboxElement = getByRole("checkbox");
16
+
17
+ expect(checkboxElement).not.toBeChecked();
18
+
19
+ expect(checkboxElement).toHaveAttribute("type", "checkbox");
20
+ expect(checkboxElement).not.toBeDisabled();
21
+ });
22
+
23
+ it("should render with the checked prop", () => {
24
+ const { getByRole } = render(<Checkbox checked={true} />);
25
+ const checkboxElement = getByRole("checkbox");
26
+
27
+ expect(checkboxElement).toBeChecked();
28
+ });
29
+
30
+ it("should handle the onChange event", () => {
31
+ const handleChange = jest.fn();
32
+ const { getByRole } = render(<Checkbox onChange={handleChange} />);
33
+ const checkboxElement = getByRole("checkbox");
34
+
35
+ fireEvent.click(checkboxElement);
36
+
37
+ expect(handleChange).toHaveBeenCalledTimes(1);
38
+ expect(handleChange).toHaveBeenCalledWith(expect.any(Object), true);
39
+ });
40
+
41
+ it("should render with the specified color", () => {
42
+ const { getByRole } = render(<Checkbox color="secondary" />);
43
+ const checkboxElement = getByRole("checkbox");
44
+
45
+ expect(checkboxElement).toBeInTheDocument();
46
+ });
47
+
48
+ it("should render with the specified size", () => {
49
+ const { getByRole } = render(<Checkbox size="small" />);
50
+ const checkboxElement = getByRole("checkbox");
51
+
52
+ expect(checkboxElement).toBeInTheDocument();
53
+ });
54
+
55
+ it("should render as disabled when the disabled prop is true", () => {
56
+ const { getByRole } = render(<Checkbox disabled />);
57
+ const checkboxElement = getByRole("checkbox");
58
+
59
+ expect(checkboxElement).toBeDisabled();
60
+ });
61
+ });
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+
3
+ interface CustomCheckboxProps {
4
+ label?: string;
5
+ checked?: boolean;
6
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
7
+ className?: string;
8
+ checkboxClassName?: string;
9
+ labelClassName?: string;
10
+ }
11
+
12
+ const CustomCheckbox: React.FC<CustomCheckboxProps> = ({
13
+ label,
14
+ checked = false,
15
+ onChange,
16
+ className = '',
17
+ checkboxClassName = '',
18
+ labelClassName = '',
19
+ ...rest
20
+ }) => {
21
+ return (
22
+ <div className={className}>
23
+ <input
24
+ type="checkbox"
25
+ checked={checked}
26
+ onChange={onChange}
27
+ className={checkboxClassName}
28
+ {...rest}
29
+ />
30
+ {label && <label className={labelClassName}>{label}</label>}
31
+ </div>
32
+ );
33
+ };
34
+
35
+ export default CustomCheckbox;
@@ -0,0 +1 @@
1
+ export { default } from "./Checkbox";
@@ -0,0 +1,19 @@
1
+ .spinner {
2
+ border-style: solid;
3
+ border-radius: 50%;
4
+ border-color: transparent;
5
+ border-top-color: currentColor;
6
+ animation: spin 1s linear infinite;
7
+ }
8
+
9
+ .spinner.primary { color: #007bff; }
10
+ .spinner.secondary { color: #6c757d; }
11
+ .spinner.error { color: #dc3545; }
12
+ .spinner.success { color: #28a745; }
13
+ .spinner.info { color: #17a2b8; }
14
+ .spinner.warning { color: #ffc107; }
15
+
16
+ @keyframes spin {
17
+ 0% { transform: rotate(0deg); }
18
+ 100% { transform: rotate(360deg); }
19
+ }
@@ -0,0 +1,47 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react";
3
+ import CircularProgress, { CircularProgressProps } from "./CircularProgress";
4
+
5
+ describe("Loading Component", () => {
6
+ const renderComponent = (props: CircularProgressProps) =>
7
+ render(<CircularProgress {...props} />);
8
+
9
+ it("applies the correct color class", () => {
10
+ const { container } = renderComponent({ color: "success" });
11
+ const spinner = container.firstChild as HTMLElement;
12
+
13
+ expect(spinner).not.toBeNull();
14
+ expect(spinner.className).toContain("success");
15
+ });
16
+
17
+ it("applies the correct size and thickness", () => {
18
+ const { container } = renderComponent({ size: 60, thickness: 5 });
19
+ const spinner = container.firstChild as HTMLElement;
20
+
21
+ expect(spinner).not.toBeNull();
22
+ expect(spinner.style.width).toBe("60px");
23
+ expect(spinner.style.height).toBe("60px");
24
+ expect(spinner.style.borderWidth).toBe("5px");
25
+ });
26
+
27
+ it("renders the determinate spinner with the correct rotation", () => {
28
+ const { container } = renderComponent({
29
+ variant: "determinate",
30
+ value: 75,
31
+ });
32
+ const spinner = container.firstChild as HTMLElement;
33
+
34
+ const expectedRotation = `rotate(${(75 / 100) * 360}deg)`;
35
+ expect(spinner).not.toBeNull();
36
+ expect(spinner.style.transform).toBe(expectedRotation);
37
+ });
38
+
39
+ it("handles string size correctly", () => {
40
+ const { container } = renderComponent({ size: "50%" });
41
+ const spinner = container.firstChild as HTMLElement;
42
+
43
+ expect(spinner).not.toBeNull();
44
+ expect(spinner.style.width).toBe("50%");
45
+ expect(spinner.style.height).toBe("50%");
46
+ });
47
+ });
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import './CircularProgress.css';
3
+
4
+ export interface CircularProgressProps {
5
+ value?: number;
6
+ variant?: 'determinate' | 'indeterminate';
7
+ color?: 'primary' | 'secondary' | 'error' | 'success' | 'info' | 'warning';
8
+ thickness?: number;
9
+ size?: number | string;
10
+ }
11
+
12
+ const CircularProgress: React.FC<CircularProgressProps> = ({
13
+ value = 0,
14
+ variant = 'indeterminate',
15
+ color = 'primary',
16
+ thickness = 4,
17
+ size = 100,
18
+ }) => {
19
+ const isDeterminate = variant === 'determinate';
20
+ const rotationStyle = isDeterminate
21
+ ? { transform: `rotate(${(value / 100) * 360}deg)` }
22
+ : {};
23
+
24
+ return (
25
+ <div
26
+ className={`spinner ${color}`}
27
+ style={{
28
+ width: typeof size === 'number' ? `${size}px` : size,
29
+ height: typeof size === 'number' ? `${size}px` : size,
30
+ borderWidth: `${thickness}px`,
31
+ ...rotationStyle,
32
+ }}
33
+ />
34
+ );
35
+ };
36
+
37
+ export default CircularProgress;
@@ -0,0 +1 @@
1
+ export { default } from "./CircularProgress";
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react";
3
+ import Divider from "./Divider";
4
+
5
+ describe("Divider Component", () => {
6
+ it("should render without crashing", () => {
7
+ const { getByTestId } = render(<Divider data-testid="divider-rendered" />);
8
+ expect(getByTestId("divider-rendered")).toBeInTheDocument();
9
+ });
10
+
11
+ it("should render with default props", () => {
12
+ const { container } = render(<Divider />);
13
+ const dividerElement = container.querySelector(".MuiDivider-root");
14
+
15
+ expect(dividerElement).not.toHaveClass("MuiDivider-vertical");
16
+
17
+ expect(dividerElement).toHaveClass("MuiDivider-fullWidth");
18
+ });
19
+ });
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import { DIVIDER_ORIENTATION } from "../Enum";
3
+
4
+ interface CustomDividerProps {
5
+ orientation?: string;
6
+ className?: string;
7
+ dividerClassName?: string;
8
+
9
+ }
10
+
11
+ const CustomDivider: React.FC<CustomDividerProps> = ({
12
+ orientation = DIVIDER_ORIENTATION.Horizontal,
13
+ className = "",
14
+ dividerClassName = "",
15
+ ...rest
16
+ }) => {
17
+ return (
18
+ <div className={`${className} ${orientation}`} {...rest}>
19
+ <div className={dividerClassName} />
20
+ </div>
21
+ );
22
+ };
23
+
24
+ export default CustomDivider;
@@ -0,0 +1 @@
1
+ export { default } from "./Divider";
@@ -0,0 +1,19 @@
1
+ export const INPUT_TYPES ={
2
+ PASSWORD : 'password',
3
+ TEXT : 'text',
4
+ EMAIL : 'email',
5
+ NUMBER : 'number',
6
+ DATE : 'date',
7
+ }
8
+
9
+ export const DIVIDER_ORIENTATION = {
10
+ Horizontal : "horizontal",
11
+ Vertical : "vertical",
12
+ }
13
+
14
+ export const LINK_TARGET = {
15
+ Self : '_self',
16
+ Blank : '_blank',
17
+ Parent : '_parent',
18
+ Top : '_top',
19
+ }