px-react-ui-components 1.0.1 → 1.0.3

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 (63) hide show
  1. package/dist/components/MyAlert/MyAlert.js +34 -22
  2. package/dist/components/MyContainer/MyContainer.js +73 -46
  3. package/dist/components/MyContainer/MyContainerBody.js +16 -8
  4. package/dist/components/MyContainer/MyContainerFooter.js +16 -8
  5. package/dist/components/MyContainer/MyContainerRight.js +17 -9
  6. package/dist/components/MyEditor/MyEditor.js +160 -106
  7. package/dist/components/MyFileUpload/MyFileUpload.js +214 -140
  8. package/dist/components/MyImageCropper/MyImageCropper.js +92 -53
  9. package/dist/components/MyInput/MyInput.js +745 -548
  10. package/dist/components/MyInput/index.js +22 -0
  11. package/dist/components/MyMaps/YandexMaps.js +102 -61
  12. package/dist/components/MyMenu/MenuItem.js +96 -50
  13. package/dist/components/MyModal/MyModal.js +63 -39
  14. package/dist/components/MyModal/MyModalBody.js +16 -8
  15. package/dist/components/MyModal/MyModalFooter.js +16 -8
  16. package/dist/components/MyNotFound/MyNotFound.js +30 -17
  17. package/dist/components/MyScrollableCard/MyScrollableCard.js +60 -26
  18. package/dist/components/MyTable/MyTable.js +298 -189
  19. package/dist/components/MyTable/MyTableBody.js +16 -8
  20. package/dist/components/MyTable/MyTableHead.js +16 -8
  21. package/dist/components/MyTabs/MyTabPane.js +37 -16
  22. package/dist/components/MyTabs/MyTabs.js +88 -50
  23. package/dist/components/MyWaiting/MyWaiting.js +34 -22
  24. package/dist/components/MyZoomImage/MyZoomImage.js +143 -94
  25. package/dist/index.js +131 -15
  26. package/package.json +18 -4
  27. package/.babelrc +0 -3
  28. package/src/components/MyAlert/MyAlert.css +0 -113
  29. package/src/components/MyAlert/MyAlert.jsx +0 -96
  30. package/src/components/MyContainer/MyContainer.jsx +0 -90
  31. package/src/components/MyContainer/MyContainer.module.css +0 -110
  32. package/src/components/MyContainer/MyContainerBody.jsx +0 -8
  33. package/src/components/MyContainer/MyContainerFooter.jsx +0 -8
  34. package/src/components/MyContainer/MyContainerRight.jsx +0 -11
  35. package/src/components/MyEditor/MyEditor.jsx +0 -252
  36. package/src/components/MyEditor/MyEditor.scss +0 -277
  37. package/src/components/MyFileUpload/MyFileUpload.jsx +0 -371
  38. package/src/components/MyFileUpload/MyFileUpload.module.css +0 -86
  39. package/src/components/MyImageCropper/MyImageCropper.jsx +0 -108
  40. package/src/components/MyInput/MyInput.jsx +0 -895
  41. package/src/components/MyInput/MyInput.module.css +0 -420
  42. package/src/components/MyMaps/YandexMaps.jsx +0 -186
  43. package/src/components/MyMenu/MenuItem.jsx +0 -62
  44. package/src/components/MyMenu/MyMenu.module.css +0 -102
  45. package/src/components/MyModal/MyModal.css +0 -83
  46. package/src/components/MyModal/MyModal.jsx +0 -78
  47. package/src/components/MyModal/MyModalBody.jsx +0 -8
  48. package/src/components/MyModal/MyModalFooter.jsx +0 -8
  49. package/src/components/MyNotFound/MyNotFound.css +0 -22
  50. package/src/components/MyNotFound/MyNotFound.jsx +0 -11
  51. package/src/components/MyScrollableCard/MyScrollableCard.jsx +0 -86
  52. package/src/components/MyTable/MyTable.jsx +0 -459
  53. package/src/components/MyTable/MyTable.module.css +0 -350
  54. package/src/components/MyTable/MyTableBody.jsx +0 -8
  55. package/src/components/MyTable/MyTableHead.jsx +0 -10
  56. package/src/components/MyTabs/MyTabPane.jsx +0 -9
  57. package/src/components/MyTabs/MyTabs.css +0 -105
  58. package/src/components/MyTabs/MyTabs.jsx +0 -63
  59. package/src/components/MyWaiting/MyWaiting.css +0 -28
  60. package/src/components/MyWaiting/MyWaiting.jsx +0 -27
  61. package/src/components/MyZoomImage/MyZoomImage.css +0 -0
  62. package/src/components/MyZoomImage/MyZoomImage.jsx +0 -139
  63. package/src/index.js +0 -15
@@ -1,459 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- import styles from "./MyTable.module.css";
3
-
4
- export const MyTableIsNumeric = (value) => {
5
- if (value === null || value === undefined || value === "") return false;
6
- return !isNaN(value) && !isNaN(parseFloat(value));
7
- };
8
-
9
- export const CountBlock = ({ count }) => {
10
- const { t } = useTranslation();
11
-
12
- return (
13
- <div className={styles.rowsCount}>
14
- <span>{count}</span>
15
- <small>{t("kayıt listelendi")}</small>
16
- </div>
17
- );
18
- };
19
-
20
- function MyTable({
21
- columns = [], //
22
- data = null,
23
- emptyText = "",
24
-
25
- children,
26
- height = null,
27
- totalCount = null,
28
- onSearchText = null,
29
- searchable = false,
30
- showCount = false,
31
-
32
- pageSize = 0,
33
-
34
- selectedRow = null,
35
- onRowClick = null,
36
- onPageChange = null,
37
- }) {
38
-
39
- const tableid = `key${Date.now() + Math.random().toString(36).substr(2, 9)}`;
40
-
41
- const [curEmptyText, setCurEmptyText] = useState(emptyText);
42
- const [curTotalCount, setCurTotalCount] = useState(data ? data.length : totalCount);
43
-
44
- const [searchTerm, setSearchTerm] = useState("");
45
- const [filteredRows, setFilteredRows] = useState([]);
46
-
47
- const [currentPage, setCurrentPage] = useState(1);
48
- const [totalPages, setTotalPages] = useState(0);
49
- const [sortConfig, setSortConfig] = useState({ key: null, direction: "asc" });
50
- const [displayData, setDisplayData] = useState([]);
51
-
52
- const arrChild = React.Children.toArray(children);
53
-
54
- let childHeader = null;
55
- let childBody = null;
56
-
57
- if (arrChild.length > 0) {
58
- for (let i = 0; i < arrChild.length; i++) {
59
- const el = arrChild[i];
60
- if (el.type.toString().includes("MyTableTagHead")) {
61
- childHeader = el;
62
- } else if (el.type.toString().includes("MyTableTagBody")) {
63
- childBody = el;
64
- } else if (childBody == null) {
65
- childBody = el;
66
- }
67
- }
68
- }
69
-
70
- // Veri işleme ve sıralama
71
- useEffect(() => {
72
-
73
-
74
- let processedData = Array.isArray(data) ? [...data] : [];
75
-
76
- // Arama işlemi
77
- if (searchTerm != "") {
78
- processedData = processedData.filter((record) => {
79
- let _status = false;
80
-
81
- Object.keys(record).forEach((key) => {
82
- if (
83
- record[key] &&
84
- record[key]
85
- .toString()
86
- .toLocaleLowerCase()
87
- .includes(searchTerm.toLocaleLowerCase())
88
- ) {
89
- _status = true;
90
- }
91
- });
92
-
93
- return _status;
94
- });
95
- }
96
-
97
- setTotalPages(Math.ceil(processedData.length / pageSize));
98
-
99
- // Sıralama işlemi
100
- if (sortConfig.key) {
101
- processedData.sort((a, b) => {
102
- const aValue = a[sortConfig.key];
103
- const bValue = b[sortConfig.key];
104
-
105
- if (MyTableIsNumeric(aValue) && MyTableIsNumeric(bValue)) {
106
- return sortConfig.direction === "asc"
107
- ? Number(aValue) - Number(bValue)
108
- : Number(bValue) - Number(aValue);
109
- }
110
-
111
- return sortConfig.direction === "asc"
112
- ? String(aValue).localeCompare(String(bValue))
113
- : String(bValue).localeCompare(String(aValue));
114
- });
115
- }
116
-
117
- // Sayfalama
118
- if (pageSize > 0) {
119
- const startIndex = (currentPage - 1) * pageSize;
120
- processedData = processedData.slice(
121
- startIndex,
122
- startIndex + pageSize
123
- );
124
- }
125
-
126
- setDisplayData(processedData);
127
- if (data) {
128
- setCurTotalCount(data.length);
129
- } else {
130
- setCurTotalCount(0);
131
- }
132
- }, [data, searchTerm, sortConfig, currentPage, pageSize]);
133
-
134
- useEffect(() => {
135
- if (emptyText == "") {
136
- // setCurEmptyText(t("Henüz bir kayıt mevcut değil!"));
137
- setCurEmptyText("No records found!");
138
- }
139
-
140
- return () => { };
141
- }, [tableid]);
142
-
143
-
144
-
145
- // Arama işlevi
146
- const filterRows = (row) => {
147
- if (!searchTerm) return true;
148
-
149
- const cells = row.props.children;
150
- return React.Children.toArray(cells).some((cell) => {
151
- const cellText = cell.props.children
152
- ? cell.props.children.toString().trim().toLocaleLowerCase()
153
- : "";
154
-
155
- const cleanCellText = cellText.replace(/[^a-zA-Z0-9\s]/g, ""); // Virgül ve diğer özel karakterleri temizle
156
- const cleanSearchTerm = searchTerm
157
- .replace(/[^a-zA-Z0-9\s]/g, "")
158
- .toLocaleLowerCase(); // Aynı şekilde arama terimini temizle
159
-
160
- return cleanCellText.includes(cleanSearchTerm);
161
- });
162
- };
163
-
164
- // Sıralama işleyicisi
165
- const handleSort = (key) => {
166
- setSortConfig((prevSort) => ({
167
- key,
168
- direction:
169
- prevSort.key === key && prevSort.direction === "asc"
170
- ? "desc"
171
- : "asc",
172
- }));
173
- };
174
-
175
- // Sütun başlığı render fonksiyonu
176
- const renderColumnHeader = (column) => {
177
- const isSorted = sortConfig.key === column.key;
178
- const sortDirection = isSorted ? sortConfig.direction : null;
179
- let style = {};
180
-
181
- if (column.style) style = { ...style, ...column.style };
182
-
183
- if (column.width) style = { ...style, width: column.width };
184
-
185
- //style = { ...style, minWidth: column.width || "150px" };
186
-
187
- return (
188
- <th
189
- key={"head" + column.key + btoa(Math.random().toString(36).substr(2, 9))}
190
- onClick={
191
- column.sortable ? () => handleSort(column.key) : undefined
192
- }
193
- className={`
194
- ${styles.th}
195
- ${(column.className && column.className) || ""}
196
- ${column.sortable ? styles.sortable : ""}
197
- ${isSorted ? styles[`sort-${sortDirection}`] : ""}
198
- `}
199
- style={style}
200
- >
201
- {column.title}
202
- </th>
203
- );
204
- };
205
-
206
- // Hücre render fonksiyonu
207
- const renderCell = (item, column, index) => {
208
- const value = item[column.key];
209
- const content = column.render ? column.render(value, item, index, currentPage) : value;
210
- const key = "cell" + column.key + btoa(Math.random().toString(36).substr(2, 9));
211
-
212
- // If the content is already a React element (like from a render function that returns MathJax),
213
- // just return it directly in the cell
214
- if (React.isValidElement(content)) {
215
- return (
216
- <td
217
- key={key}
218
- style={column.tdStyle}
219
- className={`${styles.td} ${(column.tdClassName && column.tdClassName) || ""}`}
220
- data-row-index={index}
221
- >
222
- {content}
223
- </td>
224
- );
225
- }
226
-
227
- return (
228
- <td
229
- key={key}
230
- style={column.tdStyle}
231
- className={`${styles.td} ${(column.tdClassName && column.tdClassName) || ""}`}
232
- data-row-index={index}
233
- >
234
- {typeof content === 'string' ? (<span dangerouslySetInnerHTML={{ __html: content }} />)
235
- : (
236
- content
237
- )}
238
- </td>
239
- );
240
- };
241
-
242
- // Filtrelenen satırları güncelle
243
- useEffect(() => {
244
- if (onSearchText == null) {
245
- if (childBody) {
246
- const rows = React.Children.toArray(childBody.props.children);
247
- const filtered = rows.filter((row) => filterRows(row));
248
-
249
- setFilteredRows(filtered);
250
- }
251
- } else {
252
- onSearchText(searchTerm);
253
- }
254
- }, [searchTerm, children]);
255
-
256
- // Sayfa değiştirme işleyicisi
257
- const handlePageChange = (page) => {
258
- setCurrentPage(page);
259
- };
260
- // Sayfalama render fonksiyonu
261
- const renderPagination = () => {
262
- if (pageSize == 0 || totalPages <= 1) return null;
263
-
264
- const maxVisiblePages = 10;
265
- let pagesToShow = [];
266
-
267
- if (totalPages <= maxVisiblePages) {
268
- // Toplam sayfa sayısı 10 veya daha az ise hepsini göster
269
- pagesToShow = Array.from({ length: totalPages }, (_, i) => i + 1);
270
- } else {
271
- // Her zaman ilk ve son sayfayı göster
272
- // Aktif sayfanın etrafında dengeli dağılım yap
273
- const sidePages = 4; // Aktif sayfanın her iki yanında kaç sayfa gösterileceği
274
-
275
- if (currentPage <= sidePages + 1) {
276
- // Başlangıçtayız
277
- pagesToShow = [...Array(maxVisiblePages - 1).keys()].map(
278
- (i) => i + 1
279
- );
280
- pagesToShow.push(totalPages);
281
- } else if (currentPage >= totalPages - sidePages) {
282
- // Sondayız
283
- pagesToShow = [1];
284
- pagesToShow.push(
285
- ...Array.from(
286
- { length: maxVisiblePages - 1 },
287
- (_, i) => totalPages - (maxVisiblePages - 2) + i
288
- )
289
- );
290
- } else {
291
- // Ortadayız
292
- pagesToShow = [1];
293
- const start =
294
- currentPage - Math.floor((maxVisiblePages - 4) / 2);
295
- const end = currentPage + Math.floor((maxVisiblePages - 4) / 2);
296
- pagesToShow.push(
297
- ...Array.from(
298
- { length: end - start + 1 },
299
- (_, i) => start + i
300
- )
301
- );
302
- pagesToShow.push(totalPages);
303
- }
304
- }
305
-
306
- return (
307
- <div className={styles.pagination}>
308
- <button
309
- onClick={() => handlePageChange(currentPage - 1)}
310
- disabled={currentPage === 1}
311
- className={styles.pageButton}
312
- >
313
- &lt;
314
- </button>
315
-
316
- {pagesToShow.map((page, index) => (
317
- <React.Fragment key={page}>
318
- {index > 0 &&
319
- pagesToShow[index] - pagesToShow[index - 1] > 1 && (
320
- <span className={styles.pageEllipsis}>...</span>
321
- )}
322
- <button
323
- onClick={() => handlePageChange(page)}
324
- className={`${styles.pageButton} ${currentPage === page ? styles.activePage : ""
325
- }`}
326
- >
327
- {page}
328
- </button>
329
- </React.Fragment>
330
- ))}
331
-
332
- <button
333
- onClick={() => handlePageChange(currentPage + 1)}
334
- disabled={currentPage === totalPages}
335
- className={styles.pageButton}
336
- >
337
- &gt;
338
- </button>
339
- </div>
340
- );
341
- };
342
-
343
- const headerCellsCount =
344
- columns.filter(column => column.title).length > 0
345
- ? columns.filter(column => column.title).length
346
- : childBody
347
- ? React.Children.count(childBody.props.children.props.children)
348
- : 0;
349
-
350
- return (
351
- <div
352
- id={tableid}
353
- className={`${styles.myTableContainer} ${searchable && styles.searchable
354
- } ${totalPages > 0 && styles.myTablePagination}`}
355
- style={{ height: height }}
356
- >
357
- {(searchable && (
358
- <div className={styles.searchContainer}>
359
- <input
360
- type="text"
361
- // placeholder={t("Ara")}
362
- placeholder="Search"
363
- value={searchTerm}
364
- className={styles.searchInput}
365
- onChange={(e) => setSearchTerm(e.target.value)}
366
- />
367
- <CountBlock
368
- count={
369
- (curTotalCount && curTotalCount) ||
370
- (childBody && childBody.props.children.length) ||
371
- 0
372
- }
373
- />
374
- </div>
375
- )) ||
376
- (showCount && (
377
- <CountBlock
378
- count={
379
- (curTotalCount && curTotalCount) ||
380
- (childBody && childBody.props.children.length) ||
381
- 0
382
- }
383
- />
384
- ))}
385
-
386
- <div className={styles.myTable}>
387
- <table className={styles.table}>
388
- {columns.filter(column => column.title).length > 0 ? (
389
- <thead className={styles.thead}>
390
- <tr className={styles.tr}>
391
- {columns.filter(column => column.title).map(renderColumnHeader)}
392
- </tr>
393
- </thead>
394
- ) : (
395
- childHeader
396
- )}
397
-
398
- <tbody>
399
- {(onSearchText &&
400
- childBody &&
401
- childBody.props.children.length > 0 &&
402
- childBody.props.children) ||
403
- (filteredRows &&
404
- filteredRows.length > 0 &&
405
- filteredRows) ||
406
- (displayData.length > 0 &&
407
- displayData.map((item, index) => (
408
- <tr
409
- key={index}
410
- onClick={() =>
411
- onRowClick && onRowClick(item)
412
- }
413
- className={`
414
- ${styles.tr}
415
- ${onRowClick ? styles.clickable : ""}
416
- ${selectedRow === item ? styles.selected : ""}
417
- `}
418
- >
419
- {columns.filter(column => column.title).map((column) =>
420
- renderCell(item, column, index)
421
- )}
422
- {children && (
423
- <td>
424
- {typeof children === "function"
425
- ? children(item)
426
- : children}
427
- </td>
428
- )}
429
- </tr>
430
- ))) || (
431
- <tr className={styles.noData + " " + styles.tr}>
432
- <td
433
- colSpan={headerCellsCount}
434
- className={styles.td}
435
- >
436
- {(searchTerm != "" && (
437
- <span
438
- dangerouslySetInnerHTML={{
439
- __html: `${
440
- // t("Aradığınız kriterlere uygun kayıt bulunamadı!")
441
- "No records found for the criteria you searched for!"
442
- }<br/><b>(${searchTerm})</b>`,
443
- }}
444
- ></span>
445
- )) ||
446
- curEmptyText}
447
- </td>
448
- </tr>
449
- )}
450
- </tbody>
451
- </table>
452
- </div>
453
-
454
- {totalPages > 0 && renderPagination()}
455
- </div>
456
- );
457
- }
458
-
459
- export default MyTable;