@yusufalperendumlu/component-library 0.0.4 → 0.0.6

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 (45) hide show
  1. package/dist/cjs/index.css +1 -1
  2. package/dist/cjs/index.css.map +1 -1
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/esm/index.css +1 -1
  6. package/dist/esm/index.css.map +1 -1
  7. package/dist/esm/index.js +1 -1
  8. package/dist/esm/index.js.map +1 -1
  9. package/dist/index.d.ts +65 -7
  10. package/dist/tailwind.css +1 -1
  11. package/eslint.config.js +23 -0
  12. package/jest.config.ts +13 -0
  13. package/package.json +20 -14
  14. package/prettier.config.js +84 -0
  15. package/src/components/Autocomplete/Autocomplete.stories.tsx +65 -0
  16. package/src/components/Autocomplete/Autocomplete.tsx +127 -0
  17. package/src/components/Autocomplete/Autocomplete.types.ts +14 -0
  18. package/src/components/Autocomplete/index.ts +3 -0
  19. package/src/components/Button/Button.stories.tsx +12 -2
  20. package/src/components/Button/Button.tsx +55 -38
  21. package/src/components/Button/Button.types.ts +7 -0
  22. package/src/components/Button/index.ts +3 -3
  23. package/src/components/Dialog/Dialog.stories.tsx +102 -0
  24. package/src/components/Dialog/Dialog.tsx +90 -0
  25. package/src/components/Dialog/Dialog.types.ts +7 -0
  26. package/src/components/Dialog/index.ts +3 -0
  27. package/src/components/Input/Input.stories.tsx +34 -0
  28. package/src/components/Input/Input.tsx +31 -9
  29. package/src/components/Input/Input.types.ts +6 -0
  30. package/src/components/Input/index.ts +3 -0
  31. package/src/components/Table/Table.stories.tsx +53 -0
  32. package/src/components/Table/Table.tsx +104 -0
  33. package/src/components/Table/Table.types.ts +13 -0
  34. package/src/components/Table/index.ts +3 -0
  35. package/src/components/index.ts +5 -2
  36. package/src/index.ts +3 -3
  37. package/src/tests/Autocomplete.test.tsx +81 -0
  38. package/src/tests/Button.test.tsx +36 -25
  39. package/src/tests/Dialog.test.tsx +86 -0
  40. package/src/tests/Input.test.tsx +42 -0
  41. package/src/tests/Table.test.tsx +55 -0
  42. package/src/tests/styleMock.ts +1 -1
  43. package/tailwind.config.js +6 -1
  44. package/tsconfig.json +6 -2
  45. package/src/components/Input/index.tsx +0 -3
@@ -0,0 +1,86 @@
1
+ import "@testing-library/jest-dom";
2
+
3
+ import React from "react";
4
+ import { render, screen, fireEvent } from "@testing-library/react";
5
+ import Dialog from "../components/Dialog";
6
+
7
+ describe("Dialog Component", () => {
8
+ const onCloseMock = jest.fn();
9
+
10
+ beforeEach(() => {
11
+ onCloseMock.mockClear();
12
+ });
13
+
14
+ test("renders children when open", () => {
15
+ render(
16
+ <Dialog isOpen={true} onClose={onCloseMock}>
17
+ <Dialog.Header>Header Text</Dialog.Header>
18
+ <Dialog.Body>Body Text</Dialog.Body>
19
+ <Dialog.Footer>Footer Text</Dialog.Footer>
20
+ </Dialog>
21
+ );
22
+
23
+ expect(screen.getByText("Header Text")).toBeInTheDocument();
24
+ expect(screen.getByText("Body Text")).toBeInTheDocument();
25
+ expect(screen.getByText("Footer Text")).toBeInTheDocument();
26
+ });
27
+
28
+ test("does not render when isOpen is false", () => {
29
+ const { container } = render(
30
+ <Dialog isOpen={false} onClose={onCloseMock}>
31
+ <Dialog.Body>Body Text</Dialog.Body>
32
+ </Dialog>
33
+ );
34
+
35
+ expect(container).toBeEmptyDOMElement();
36
+ });
37
+
38
+ test("calls onClose when clicking the close button", () => {
39
+ render(
40
+ <Dialog isOpen={true} onClose={onCloseMock}>
41
+ <Dialog.Body>Body Text</Dialog.Body>
42
+ </Dialog>
43
+ );
44
+
45
+ const closeButton = screen.getByRole("button");
46
+ fireEvent.click(closeButton);
47
+
48
+ expect(onCloseMock).toHaveBeenCalledTimes(1);
49
+ });
50
+
51
+ test("calls onClose when clicking outside the dialog", () => {
52
+ render(
53
+ <Dialog isOpen={true} onClose={onCloseMock}>
54
+ <Dialog.Body>Body Text</Dialog.Body>
55
+ </Dialog>
56
+ );
57
+
58
+ // dialog içerisine değil, overlay alanına tıklayalım
59
+ fireEvent.mouseDown(document.body); // dialog dışına tıklama simülasyonu
60
+
61
+ expect(onCloseMock).toHaveBeenCalledTimes(1);
62
+ });
63
+
64
+ test("calls onClose when pressing Escape key", () => {
65
+ render(
66
+ <Dialog isOpen={true} onClose={onCloseMock}>
67
+ <Dialog.Body>Body Text</Dialog.Body>
68
+ </Dialog>
69
+ );
70
+
71
+ fireEvent.keyDown(document, { key: "Escape", code: "Escape" });
72
+
73
+ expect(onCloseMock).toHaveBeenCalledTimes(1);
74
+ });
75
+
76
+ test("does not show close icon if showCloseIcon is false", () => {
77
+ render(
78
+ <Dialog isOpen={true} onClose={onCloseMock} showCloseIcon={false}>
79
+ <Dialog.Body>Body Text</Dialog.Body>
80
+ </Dialog>
81
+ );
82
+
83
+ const closeButton = screen.queryByRole("button");
84
+ expect(closeButton).toBeNull();
85
+ });
86
+ });
@@ -0,0 +1,42 @@
1
+ import "@testing-library/jest-dom";
2
+
3
+ import React from "react";
4
+ import { render, screen, fireEvent } from "@testing-library/react";
5
+ import Input from "../components/Input";
6
+
7
+ describe("Input Component", () => {
8
+ it("renders the input with placeholder", () => {
9
+ render(<Input placeholder="Enter your name" type="text" />);
10
+ const inputElement = screen.getByPlaceholderText("Enter your name");
11
+ expect(inputElement).toBeInTheDocument();
12
+ });
13
+
14
+ it("accepts and displays typed value", () => {
15
+ render(<Input placeholder="Type here" type="text" />);
16
+ const inputElement = screen.getByPlaceholderText(
17
+ "Type here"
18
+ ) as HTMLInputElement;
19
+
20
+ fireEvent.change(inputElement, { target: { value: "Hello" } });
21
+
22
+ expect(inputElement.value).toBe("Hello");
23
+ });
24
+
25
+ it("applies custom className", () => {
26
+ render(<Input placeholder="Test" type="text" className="custom-class" />);
27
+ const inputElement = screen.getByPlaceholderText("Test");
28
+ expect(inputElement).toHaveClass("custom-class");
29
+ });
30
+
31
+ it("is disabled when disabled prop is passed", () => {
32
+ render(<Input placeholder="Disabled input" type="text" disabled />);
33
+ const inputElement = screen.getByPlaceholderText("Disabled input");
34
+ expect(inputElement).toBeDisabled();
35
+ });
36
+
37
+ it("renders password input type correctly", () => {
38
+ render(<Input placeholder="Password" type="password" />);
39
+ const inputElement = screen.getByPlaceholderText("Password");
40
+ expect(inputElement).toHaveAttribute("type", "password");
41
+ });
42
+ });
@@ -0,0 +1,55 @@
1
+ import React from "react";
2
+ import { render, screen, fireEvent } from "@testing-library/react";
3
+ import Table from "../components/Table/Table";
4
+ import { TableColumn } from "../components/Table/Table.types";
5
+
6
+ interface TestData {
7
+ id: number;
8
+ name: string;
9
+ age: number;
10
+ }
11
+
12
+ const columns: TableColumn<TestData>[] = [
13
+ { key: "id", label: "ID", sortable: true },
14
+ { key: "name", label: "Name", sortable: true },
15
+ { key: "age", label: "Age" },
16
+ ];
17
+
18
+ const data: TestData[] = [
19
+ { id: 1, name: "Alice", age: 28 },
20
+ { id: 2, name: "Bob", age: 34 },
21
+ { id: 3, name: "Charlie", age: 22 },
22
+ ];
23
+
24
+ describe("Table Component", () => {
25
+ it("renders table headers correctly", () => {
26
+ render(<Table columns={columns} data={data} />);
27
+ columns.forEach((col) => {
28
+ expect(screen.getByText(col.label)).toBeInTheDocument();
29
+ });
30
+ });
31
+
32
+ it("renders table rows and cells", () => {
33
+ render(<Table columns={columns} data={data} />);
34
+ data.forEach((item) => {
35
+ expect(screen.getByText(item.name)).toBeInTheDocument();
36
+ expect(screen.getByText(item.age.toString())).toBeInTheDocument();
37
+ });
38
+ });
39
+
40
+ it("calls onRowClick when a row is clicked", () => {
41
+ const handleRowClick = jest.fn();
42
+ render(<Table columns={columns} data={data} onRowClick={handleRowClick} />);
43
+ const row = screen.getByText("Alice").closest("tr");
44
+ if (row) fireEvent.click(row);
45
+ expect(handleRowClick).toHaveBeenCalledWith(data[0]);
46
+ });
47
+
48
+ it("toggles sort order when header is clicked", () => {
49
+ render(<Table columns={columns} data={data} />);
50
+ const idHeader = screen.getByText("ID");
51
+ fireEvent.click(idHeader); // sort asc
52
+ fireEvent.click(idHeader); // sort desc
53
+ expect(screen.getByText("3")).toBeInTheDocument(); // highest id
54
+ });
55
+ });
@@ -1 +1 @@
1
- module.exports = {}
1
+ module.exports = {};
@@ -1,7 +1,12 @@
1
1
  module.exports = {
2
2
  content: ["./src/**/*.{js,ts,jsx,tsx}"],
3
+ darkMode: "class",
3
4
  theme: {
4
- extend: {},
5
+ extend: {
6
+ fontFamily: {
7
+ inter: ["Inter", "sans-serif"],
8
+ },
9
+ },
5
10
  },
6
11
  plugins: [],
7
12
  };
package/tsconfig.json CHANGED
@@ -12,10 +12,14 @@
12
12
  "esModuleInterop": true,
13
13
  "forceConsistentCasingInFileNames": true,
14
14
  "strict": true,
15
- "skipLibCheck": true
15
+ "skipLibCheck": true,
16
+ "types": ["node", "jest"]
16
17
  },
17
18
  "include": [
18
- "src/**/*"
19
+ "src/**/*",
20
+ "tests",
21
+ "**/*.test.ts",
22
+ "**/*.test.tsx",
19
23
  ],
20
24
  "exclude": [
21
25
  "node_modules",
@@ -1,3 +0,0 @@
1
- import Input from "./Input";
2
-
3
- export default Input;