cemtrik-dependencies 1.0.4

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 (92) hide show
  1. package/README copy.md +54 -0
  2. package/README.md +29 -0
  3. package/components.js +47 -0
  4. package/hooks.js +4 -0
  5. package/package.json +58 -0
  6. package/postcss.config.js +6 -0
  7. package/src/assets/cemtrik-icons-v1.0/Read Me.txt +7 -0
  8. package/src/assets/cemtrik-icons-v1.0/demo-files/demo.css +152 -0
  9. package/src/assets/cemtrik-icons-v1.0/demo-files/demo.js +30 -0
  10. package/src/assets/cemtrik-icons-v1.0/demo.html +318 -0
  11. package/src/assets/cemtrik-icons-v1.0/fonts/cemtrik-icons.eot +0 -0
  12. package/src/assets/cemtrik-icons-v1.0/fonts/cemtrik-icons.svg +31 -0
  13. package/src/assets/cemtrik-icons-v1.0/fonts/cemtrik-icons.ttf +0 -0
  14. package/src/assets/cemtrik-icons-v1.0/fonts/cemtrik-icons.woff +0 -0
  15. package/src/assets/cemtrik-icons-v1.0/selection.json +1 -0
  16. package/src/assets/cemtrik-icons-v1.0/style.css +96 -0
  17. package/src/assets/icons/actions.svg +4 -0
  18. package/src/assets/icons/attributes.svg +5 -0
  19. package/src/assets/icons/bars.svg +3 -0
  20. package/src/assets/icons/bell.svg +4 -0
  21. package/src/assets/icons/cemtrik.svg +9 -0
  22. package/src/assets/icons/clipboardCheck.svg +4 -0
  23. package/src/assets/icons/clipboardList.svg +5 -0
  24. package/src/assets/icons/clock.svg +3 -0
  25. package/src/assets/icons/flag.svg +3 -0
  26. package/src/assets/icons/folder.svg +3 -0
  27. package/src/assets/icons/graph_indicators.svg +3 -0
  28. package/src/assets/icons/group.svg +3 -0
  29. package/src/assets/icons/letter.svg +3 -0
  30. package/src/assets/icons/measuring_points.svg +3 -0
  31. package/src/assets/icons/reports.svg +4 -0
  32. package/src/assets/icons/roboot.svg +3 -0
  33. package/src/assets/icons/user.svg +4 -0
  34. package/src/assets/icons/user_point.svg +10 -0
  35. package/src/assets/icons/vector.svg +3 -0
  36. package/src/assets/icons/vector2.svg +3 -0
  37. package/src/components/atoms/Alert/index.js +104 -0
  38. package/src/components/atoms/Alert/index.test.js +36 -0
  39. package/src/components/atoms/Avatar/index.js +63 -0
  40. package/src/components/atoms/Avatar/index.test.js +30 -0
  41. package/src/components/atoms/Bullets/Bullets.test.js +22 -0
  42. package/src/components/atoms/Bullets/index.js +51 -0
  43. package/src/components/atoms/ButtonOutline/index.js +43 -0
  44. package/src/components/atoms/ButtonOutline/index.test.js +36 -0
  45. package/src/components/atoms/ButtonPagination/index.js +37 -0
  46. package/src/components/atoms/ButtonPagination/index.test.js +36 -0
  47. package/src/components/atoms/ButtonSolid/index.js +74 -0
  48. package/src/components/atoms/ButtonSolid/index.test.js +59 -0
  49. package/src/components/atoms/Checkbox/index.js +52 -0
  50. package/src/components/atoms/Checkbox/index.test.js +15 -0
  51. package/src/components/atoms/ConfirmationAbandoningCreation/index.js +70 -0
  52. package/src/components/atoms/ConfirmationAbandoningCreation/index.test.js +70 -0
  53. package/src/components/atoms/Divider/index.js +10 -0
  54. package/src/components/atoms/Divider/index.test.js +12 -0
  55. package/src/components/atoms/GoBack/index.js +30 -0
  56. package/src/components/atoms/GoBack/index.test.js +24 -0
  57. package/src/components/atoms/Input/index.js +107 -0
  58. package/src/components/atoms/Input/index.test.js +63 -0
  59. package/src/components/atoms/InputDropdown/index.js +111 -0
  60. package/src/components/atoms/InputDropdown/index.test.js +86 -0
  61. package/src/components/atoms/Select/index.js +199 -0
  62. package/src/components/atoms/Select/index.test.js +86 -0
  63. package/src/components/atoms/Spinner/index.js +49 -0
  64. package/src/components/atoms/Spinner/index.test.js +9 -0
  65. package/src/components/atoms/Switch/index.js +46 -0
  66. package/src/components/atoms/Switch/index.test.js +18 -0
  67. package/src/components/atoms/Textarea/index.js +136 -0
  68. package/src/components/atoms/Textarea/index.spec.js +51 -0
  69. package/src/components/atoms/Tooltip/index.js +64 -0
  70. package/src/components/atoms/Tooltip/index.test.js +31 -0
  71. package/src/components/atoms/UploadImage/index.js +55 -0
  72. package/src/components/atoms/UploadImage/index.test.js +36 -0
  73. package/src/components/molecules/Dropdown/index.js +315 -0
  74. package/src/components/molecules/Dropdown/index.test.js +190 -0
  75. package/src/components/molecules/Modal/index.js +103 -0
  76. package/src/components/molecules/Modal/index.test.js +42 -0
  77. package/src/components/molecules/Pagination/index.js +126 -0
  78. package/src/components/molecules/Pagination/index.test.js +57 -0
  79. package/src/components/templates/Accordion/index.js +174 -0
  80. package/src/components/templates/Accordion/index.test.js +130 -0
  81. package/src/hooks/useCloseModal/index.js +27 -0
  82. package/src/hooks/useCloseModal/index.test.js +26 -0
  83. package/src/hooks/useForm/index.js +70 -0
  84. package/src/hooks/useForm/useForm.test.js +104 -0
  85. package/src/hooks/useMediaQuery/index.js +53 -0
  86. package/src/hooks/useMediaQuery/useMediaQuery.test.js +46 -0
  87. package/src/hooks/useWindowDimensions/index.js +34 -0
  88. package/src/hooks/useWindowDimensions/useWindowDimensions.test.js +19 -0
  89. package/src/utils/index.js +32 -0
  90. package/src/utils/index.test.js +56 -0
  91. package/tailwind.config.js +117 -0
  92. package/utils.js +8 -0
@@ -0,0 +1,104 @@
1
+ import { render, renderHook, fireEvent, waitFor, act } from "@testing-library/react";
2
+ import { useForm } from "./";
3
+ import Input from "../../components/atoms/Input";
4
+
5
+ describe("useForm", () => {
6
+ it("handleSubmit", () => {
7
+ const mockOnSubmit = jest.fn();
8
+ const {
9
+ result: { current },
10
+ } = renderHook(useForm);
11
+
12
+ const { getByTestId } = render(
13
+ <form onSubmit={current.handleSubmit(mockOnSubmit)}>
14
+ <button type="submit" data-testid="submit-button">
15
+ Submit
16
+ </button>
17
+ </form>,
18
+ );
19
+
20
+ const submitButton = getByTestId("submit-button");
21
+
22
+ fireEvent.click(submitButton);
23
+
24
+ expect(mockOnSubmit).toHaveBeenCalled();
25
+ });
26
+
27
+ it("handleChange", () => {
28
+ const changeMock = jest.fn();
29
+ const model = { email: "" };
30
+ const {
31
+ result: { current },
32
+ } = renderHook(useForm);
33
+
34
+ const { getByTestId } = render(
35
+ <Input
36
+ htmlFor="email"
37
+ label="Usuario"
38
+ id="email"
39
+ name="email"
40
+ type="email"
41
+ placeholder="Correo Electrónico"
42
+ handleChange={(e) => current.handleChange(e, changeMock, model)}
43
+ value={model.email}
44
+ />,
45
+ );
46
+
47
+ const input = getByTestId("input-email");
48
+
49
+ fireEvent.change(input, {
50
+ target: {
51
+ value: "test@gmail.com",
52
+ checked: false,
53
+ name: "email",
54
+ type: "email",
55
+ id: "email",
56
+ },
57
+ });
58
+
59
+ expect(changeMock).toHaveBeenCalledWith({ email: "test@gmail.com" });
60
+ });
61
+
62
+ it("setValuesDefault", async () => {
63
+ const { result } = renderHook(useForm);
64
+
65
+ await waitFor(() => {
66
+ result.current.setValuesDefault("email", "test@gmail.com");
67
+ expect(result.current.model).toEqual({ email: "test@gmail.com" });
68
+ });
69
+ });
70
+
71
+ it("validateFields", async () => {
72
+ const { result } = renderHook(useForm);
73
+
74
+ await act(async () => {
75
+ result.current.validateFields({ email: "test@gmail.com", name: "Pepito" }, [
76
+ "email",
77
+ "password",
78
+ ]);
79
+ });
80
+
81
+ expect(result.current.errors.toString()).toBe("password");
82
+
83
+ await act(async () => {
84
+ result.current.validateFields(
85
+ { email: "test@gmail.com", password: "123", name: "Pepito" },
86
+ ["email", "password"],
87
+ );
88
+ });
89
+
90
+ expect(JSON.stringify(result.current.errors)).toBe("[]");
91
+ });
92
+
93
+ it("handleError", async () => {
94
+ const { result } = renderHook(useForm);
95
+
96
+ await waitFor(() => {
97
+ result.current.handleError("err", ["email", "password"]);
98
+
99
+ expect(JSON.stringify(result.current.messageError)).toBe(
100
+ JSON.stringify({ email: "err", password: "err" }),
101
+ );
102
+ });
103
+ });
104
+ });
@@ -0,0 +1,53 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+
3
+ export const useMediaQuery = (breakpoint) => {
4
+ const [isCorrectBreakpoint, setIsCorrectBreakpoint] = useState(true);
5
+ const [isMatches, setIsMatches] = useState(false);
6
+
7
+ const getMatche = useCallback(
8
+ (isMinWidth, windowWidth) => {
9
+ const resolution = breakpoint.match(/[0-9]+/g);
10
+
11
+ if (resolution === null) return;
12
+
13
+ const [number] = resolution;
14
+ windowWidth = Math.min(window.innerWidth, window.outerWidth);
15
+
16
+ const matches = isMinWidth
17
+ ? windowWidth >= Number(number)
18
+ : windowWidth <= Number(number);
19
+ setIsMatches(matches);
20
+ },
21
+ [breakpoint],
22
+ );
23
+
24
+ useEffect(() => {
25
+ const isMinWidth = /\(min-width:\s?[0-9]+px\)/gi.test(breakpoint);
26
+ const isMaxWidth = /\(max-width:\s?[0-9]+px\)/gi.test(breakpoint);
27
+
28
+ !isMinWidth && !isMaxWidth && setIsCorrectBreakpoint(false);
29
+
30
+ if (!isMinWidth && !isMaxWidth) return;
31
+
32
+ const windowWidth = Math.min(window.innerWidth, window.outerWidth);
33
+
34
+ getMatche(isMinWidth, windowWidth);
35
+ }, [breakpoint, getMatche]);
36
+
37
+ useEffect(() => {
38
+ if (!isCorrectBreakpoint) return;
39
+
40
+ const windowWidth = Math.min(window.innerWidth, window.outerWidth);
41
+
42
+ function updateSize() {
43
+ const isMinWidth = /min-width/gi.test(breakpoint);
44
+ getMatche(isMinWidth, windowWidth);
45
+ }
46
+
47
+ window.addEventListener("resize", updateSize);
48
+
49
+ return () => window.removeEventListener("resize", updateSize);
50
+ }, [isCorrectBreakpoint, breakpoint, getMatche]);
51
+
52
+ return isMatches;
53
+ };
@@ -0,0 +1,46 @@
1
+ import { renderHook, act } from "@testing-library/react";
2
+ import { useMediaQuery } from "./";
3
+
4
+ describe("useMediaQuery", () => {
5
+ it("resize", () => {
6
+ window.innerWidth = 1024;
7
+ const { result } = renderHook(useMediaQuery, {
8
+ initialProps: "(max-width: 768px)",
9
+ });
10
+
11
+ act(() => {
12
+ window.innerWidth = 600;
13
+ window.dispatchEvent(new Event("resize"));
14
+ });
15
+
16
+ expect(result.current).toBe(true);
17
+ });
18
+
19
+ it("breakpoint incorrect", () => {
20
+ window.innerWidth = 1024;
21
+ const { result } = renderHook(useMediaQuery, {
22
+ initialProps: "(width: 768px)",
23
+ });
24
+
25
+ act(() => {
26
+ window.innerWidth = 600;
27
+ window.dispatchEvent(new Event("resize"));
28
+ });
29
+
30
+ expect(result.current).toBe(false);
31
+ });
32
+
33
+ it("min-width", () => {
34
+ window.innerWidth = 375;
35
+ const { result } = renderHook(useMediaQuery, {
36
+ initialProps: "(min-width: 1000px)",
37
+ });
38
+
39
+ act(() => {
40
+ window.innerWidth = 1280;
41
+ window.dispatchEvent(new Event("resize"));
42
+ });
43
+
44
+ expect(result.current).toBe(true);
45
+ });
46
+ });
@@ -0,0 +1,34 @@
1
+ // 1.- libraries
2
+ import { useState, useEffect } from "react";
3
+
4
+ export const useWindowDimensions = () => {
5
+ const [windowDimensions, setWindowDimensions] = useState({
6
+ width: 0,
7
+ height: 0,
8
+ });
9
+
10
+ useEffect(() => {
11
+ const width = Math.min(window.innerWidth, window.outerWidth);
12
+ const height = Math.min(window.innerHeight, window.outerHeight);
13
+
14
+ setWindowDimensions({ width, height });
15
+ }, []);
16
+
17
+ useEffect(() => {
18
+ let width = Math.min(window.innerWidth, window.outerWidth);
19
+ let height = Math.min(window.innerHeight, window.outerHeight);
20
+
21
+ const handleResize = () => {
22
+ width = Math.min(window.innerWidth, window.outerWidth);
23
+ height = Math.min(window.innerHeight, window.outerHeight);
24
+
25
+ setWindowDimensions({ width, height });
26
+ };
27
+
28
+ window.addEventListener("resize", handleResize);
29
+
30
+ return () => window.removeEventListener("resize", handleResize);
31
+ }, []);
32
+
33
+ return windowDimensions;
34
+ };
@@ -0,0 +1,19 @@
1
+ import { renderHook, act } from "@testing-library/react";
2
+ import { useWindowDimensions } from "./";
3
+
4
+ describe("useWindowDimensions", () => {
5
+ it("resize", () => {
6
+ const { result } = renderHook(useWindowDimensions);
7
+
8
+ window.innerWidth = 1024;
9
+ window.innerHeight = 800;
10
+
11
+ act(() => {
12
+ window.innerWidth = 600;
13
+ window.innerHeight = 380;
14
+ window.dispatchEvent(new Event("resize"));
15
+ });
16
+
17
+ expect(result.current).toEqual({ height: 380, width: 600 });
18
+ });
19
+ });
@@ -0,0 +1,32 @@
1
+ export const copyOptions = (data) => {
2
+ function copyObj(obj) {
3
+ if (typeof obj !== "object" || obj === null) return obj;
4
+ const copy = Array.isArray(obj) ? [] : {};
5
+ for (const key in obj) {
6
+ if (obj.hasOwnProperty(key)) copy[key] = copyObj(obj[key]);
7
+ }
8
+ return copy;
9
+ }
10
+
11
+ const copyData = data.map((option) => {
12
+ const copiaOption = copyObj(option);
13
+ return copiaOption;
14
+ });
15
+ return copyData;
16
+ };
17
+
18
+ export const validateEmail = (email) => {
19
+ return /^(?:[^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*|"[^\n"]+")@(?:[^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,63}$/i.test(
20
+ email,
21
+ );
22
+ };
23
+
24
+ export function classNames(...classes) {
25
+ return classes.filter(Boolean).join(" ");
26
+ }
27
+
28
+ export const isPromise = (prop) =>
29
+ typeof prop !== "string" && Promise.resolve(prop) instanceof Promise;
30
+
31
+ export const MESSAGE_ABORT_CONTROLLER = "The user aborted a request.";
32
+ export const MESSAGE_SIGNAL_ABORTED_WITHOUT_REASON = "signal is aborted without reason";
@@ -0,0 +1,56 @@
1
+ import {
2
+ copyOptions,
3
+ validateEmail,
4
+ classNames,
5
+ isPromise,
6
+ MESSAGE_ABORT_CONTROLLER,
7
+ MESSAGE_SIGNAL_ABORTED_WITHOUT_REASON,
8
+ } from "./";
9
+
10
+ const data = [
11
+ {
12
+ id: "0",
13
+ name: "Número de Respuestas de Experiencia",
14
+ text: "",
15
+ percent: "458",
16
+ openToolTip: false,
17
+ data: ["Eliminar"],
18
+ },
19
+ {
20
+ id: "1",
21
+ name: "NPS Net Promoter Score:",
22
+ text: "Valor esperado: Mayor a 50%.",
23
+ percent: "68.5%",
24
+ openToolTip: false,
25
+ data: ["Eliminar"],
26
+ },
27
+ ];
28
+
29
+ describe("utils", () => {
30
+ it("copyOptions", () => {
31
+ const copyData = copyOptions(data);
32
+ copyData[0].current = true;
33
+ expect(data[0]).not.toEqual(copyData[0]);
34
+ });
35
+
36
+ it("validateEmail", () => {
37
+ const isEmail1 = validateEmail("test@gmail.com");
38
+ const isEmail2 = validateEmail("testgmail.com");
39
+ expect(isEmail1).toBe(true);
40
+ expect(isEmail2).toBe(false);
41
+ });
42
+
43
+ it("classNames", () => {
44
+ const classes = classNames("class1", "class2", "class3");
45
+ expect(classes).toBe("class1 class2 class3");
46
+ });
47
+
48
+ it("isPromise", () => {
49
+ MESSAGE_ABORT_CONTROLLER && MESSAGE_ABORT_CONTROLLER;
50
+ MESSAGE_SIGNAL_ABORTED_WITHOUT_REASON && MESSAGE_SIGNAL_ABORTED_WITHOUT_REASON;
51
+ const promise1 = isPromise("");
52
+ const promise2 = isPromise(new Promise((resolve) => resolve("")));
53
+ expect(promise1).toBe(false);
54
+ expect(promise2).toBe(true);
55
+ });
56
+ });
@@ -0,0 +1,117 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ const defaultTheme = require("tailwindcss/defaultTheme");
3
+
4
+ module.exports = {
5
+ content: ["./src/**/*.{js,ts,jsx,tsx,mdx}"],
6
+ purge: {
7
+ enabled: false,
8
+ content: ["./src/components/**/*.{js,jsx}", "./src/layouts/**/*.{js,jsx}"],
9
+ },
10
+ theme: {
11
+ fontFamily: {
12
+ sans: ["Inter", "sans-serif"],
13
+ },
14
+ extend: {
15
+ colors: {
16
+ white: "#ffffff",
17
+ black: "#000000",
18
+
19
+ stone: {
20
+ 100: "#f5f5f4",
21
+ 300: "#d6d3d1",
22
+ 400: "#a8a29e",
23
+ 500: "#78716c",
24
+ 600: "#57534e",
25
+ 700: "#44403c",
26
+ 800: "#292524",
27
+ 900: "#1c1917",
28
+ },
29
+ rose: {
30
+ 100: "#ffe4e6",
31
+ 300: "#fda4af",
32
+ 400: "#fb7185",
33
+ 500: "#f43f5e",
34
+ 600: "#e11d48",
35
+ 700: "#be123c",
36
+ 800: "#9f1239",
37
+ 900: "#881337",
38
+ },
39
+ amber: {
40
+ 100: "#fef3c7",
41
+ 200: "#fde68a",
42
+ 300: "#fcd34d",
43
+ 400: "#fbbf24",
44
+ 500: "#f59e0b",
45
+ 600: "#d97706",
46
+ 700: "#b45309",
47
+ 800: "#92400e",
48
+ 900: "#78350f",
49
+ },
50
+
51
+ "white-1": "#E4E4E4",
52
+ "white-2": "#E8E8E8",
53
+ "white-3": "#F0F0F0",
54
+ "white-4": "#FFFFFF",
55
+
56
+ "default-1": "#C7CBD2",
57
+ "default-2": "#4A4C4D",
58
+ "default-3": "#2C2F36",
59
+ "default-4": "#020C1A",
60
+ "default-5": "#637381",
61
+ "default-6": "#DFE4EA",
62
+
63
+ "secondary-2": "#3758F9",
64
+ "secondary-3": "#243BBD",
65
+ "secondary-4": "#070080",
66
+
67
+ "success-1": "#1CB196",
68
+
69
+ "danger-1": "#FFFEFF",
70
+ "danger-2": "#FCCED8",
71
+ "danger-3": "#FE9CB3",
72
+ "danger-4": "#FF3768",
73
+
74
+ transparent: "transparent",
75
+ },
76
+ screens: {
77
+ xs: "320px",
78
+ "2xs": "375px",
79
+ "3xs": "470px",
80
+ sm: "640px",
81
+ md: "769px",
82
+ },
83
+ spacing: {
84
+ ...defaultTheme.spacing,
85
+ 30: "7.25rem",
86
+ },
87
+ fontSize: {
88
+ 6: "6px",
89
+ 10: "10px",
90
+ 11: "11px",
91
+ 13: "13px",
92
+ 15: "15px",
93
+ 17: "17px",
94
+ 19: "19px",
95
+ 23: "23px",
96
+ 25: "25px",
97
+ 26: "26px",
98
+ 28: "28px",
99
+ 29: "29px",
100
+ 31: "31px",
101
+ 35: "35px",
102
+ },
103
+ borderRadius: {
104
+ 20: "20px",
105
+ },
106
+ borderWidth: {
107
+ 1: "1px",
108
+ },
109
+ },
110
+ },
111
+ variants: {
112
+ extend: {
113
+ fontWeight: ["hover"],
114
+ },
115
+ },
116
+ plugins: [require("@tailwindcss/forms"), require("@tailwindcss/typography")],
117
+ };
package/utils.js ADDED
@@ -0,0 +1,8 @@
1
+ export {
2
+ copyOptions,
3
+ classNames,
4
+ isPromise,
5
+ validateEmail,
6
+ MESSAGE_ABORT_CONTROLLER,
7
+ MESSAGE_SIGNAL_ABORTED_WITHOUT_REASON,
8
+ } from "./src/utils/index";