ar-design 0.2.61 → 0.2.63

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 (36) hide show
  1. package/dist/components/data-display/card/IProps.d.ts +20 -3
  2. package/dist/components/data-display/chip/IProps.d.ts +11 -2
  3. package/dist/components/data-display/dnd/IProps.d.ts +32 -0
  4. package/dist/components/data-display/grid-system/column/IProps.d.ts +40 -0
  5. package/dist/components/data-display/grid-system/index.d.ts +1 -1
  6. package/dist/components/data-display/grid-system/row/IProps.d.ts +4 -0
  7. package/dist/components/data-display/grid-system/row/Row.d.ts +2 -2
  8. package/dist/components/data-display/table/IProps.d.ts +113 -0
  9. package/dist/components/data-display/tabs/IProps.d.ts +43 -4
  10. package/dist/components/data-display/typography/paragraph/IProps.d.ts +26 -2
  11. package/dist/components/data-display/typography/title/IProps.d.ts +48 -2
  12. package/dist/components/feedback/alert/IProps.d.ts +27 -2
  13. package/dist/components/feedback/modal/IProps.d.ts +29 -5
  14. package/dist/components/feedback/notification/IProps.d.ts +63 -2
  15. package/dist/components/feedback/popover/IProps.d.ts +68 -0
  16. package/dist/components/feedback/progress/IProps.d.ts +30 -0
  17. package/dist/components/feedback/tooltip/IProps.d.ts +25 -0
  18. package/dist/components/form/button/IProps.d.ts +55 -2
  19. package/dist/components/form/checkbox/IProps.d.ts +13 -3
  20. package/dist/components/form/date-picker/Props.d.ts +36 -3
  21. package/dist/components/form/input/IProps.d.ts +31 -4
  22. package/dist/components/form/input-tag/IProps.d.ts +2 -3
  23. package/dist/components/form/radio/IProps.d.ts +24 -3
  24. package/dist/components/form/select/Props.d.ts +118 -7
  25. package/dist/components/form/switch/IProps.d.ts +13 -2
  26. package/dist/components/form/text-editor/IProps.d.ts +85 -4
  27. package/dist/components/form/upload/Props.d.ts +96 -3
  28. package/dist/components/navigation/menu/IProps.d.ts +25 -0
  29. package/dist/components/navigation/pagination/IProps.d.ts +10 -3
  30. package/dist/components/navigation/steps/IProps.d.ts +12 -4
  31. package/dist/libs/types/IGlobalProps.d.ts +91 -45
  32. package/package.json +4 -12
  33. package/dist/components/data-display/grid-system/row/Types.d.ts +0 -4
  34. package/dist/components/data-display/table/_index.d.ts +0 -13
  35. package/dist/components/data-display/table/_index.js +0 -411
  36. /package/dist/components/data-display/grid-system/row/{Types.js → IProps.js} +0 -0
@@ -1,411 +0,0 @@
1
- "use client";
2
- import "../../../assets/css/components/data-display/table/styles.css";
3
- import { ARIcon } from "../../icons";
4
- import Button from "../../form/button";
5
- import Checkbox from "../../form/checkbox";
6
- import Pagination from "../../navigation/pagination";
7
- import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
8
- import Actions from "./Actions";
9
- import Input from "../../form/input";
10
- import Popover from "../../feedback/popover";
11
- const TableWithRef = forwardRef(({ children, title, description, data, columns, actions, selections, previousSelections, searchedParams, pagination, config = { isSearchable: false }, }, ref) => {
12
- // refs
13
- const _tableWrapper = useRef(null);
14
- const _table = useRef(null);
15
- const _tableContent = useRef(null);
16
- const _checkboxItems = useRef([]);
17
- const _filterCheckboxItems = useRef([]);
18
- // refs -> Search
19
- const _searchTextInputs = useRef([]);
20
- const _searchTimeOut = useRef(null);
21
- // className
22
- const _tableClassName = ["ar-table", "scroll"];
23
- // states
24
- const [selectAll, setSelectAll] = useState(false);
25
- const [selectionItems, setSelectionItems] = useState([]);
26
- // const [thWidths, setThWidths] = useState<number[]>([]);
27
- // states -> Search
28
- const [searchedText, setSearchedText] = useState(undefined);
29
- const [_searchedParams, setSearchedParams] = useState(undefined);
30
- const [checkboxSelectedParams, setCheckboxSelectedParams] = useState(undefined);
31
- // const [selectedfilterCheckboxItems, setSelectedfilterCheckboxItems] = useState<
32
- // {
33
- // selectedCount: number;
34
- // columnKey: string;
35
- // }[]
36
- // >([]);
37
- // const [searchedFilters, setSearchedFilters] = useState<string | undefined>(undefined);
38
- // const [totalRecords, setTotalRecords] = useState<number>(0);
39
- const [currentPage, setCurrentPage] = useState(1);
40
- if (config && Object.keys(config.scroll || {}).length > 0) {
41
- if (_tableContent.current && config.scroll) {
42
- if (config.scroll.maxHeight) {
43
- _tableContent.current.style.maxHeight = `${config?.scroll?.maxHeight}rem`;
44
- }
45
- }
46
- }
47
- // Custom Attributes
48
- useImperativeHandle(ref, () => {
49
- const tableCurrent = _table.current;
50
- return {
51
- ...tableCurrent,
52
- filterCleaner: () => {
53
- if (config.isServerSide) {
54
- setSearchedParams({});
55
- // pagination && pagination.onChange(1);
56
- }
57
- else {
58
- setSearchedText({});
59
- }
60
- setCurrentPage(1);
61
- _searchTextInputs.current.map((item) => item && (item.value = ""));
62
- },
63
- };
64
- });
65
- // methods
66
- const handleScroll = () => {
67
- if (!_tableWrapper.current)
68
- return;
69
- const wrapperRect = _tableWrapper.current.getBoundingClientRect();
70
- const updateStickyPositions = (elements) => {
71
- elements.forEach((element) => {
72
- const leftChildren = Array.from(element.childNodes)
73
- .filter((node) => node.nodeType === Node.ELEMENT_NODE)
74
- .filter((child) => child.dataset.stickyPosition === "left");
75
- const rightChildren = Array.from(element.childNodes)
76
- .filter((node) => node.nodeType === Node.ELEMENT_NODE)
77
- .filter((child) => child.dataset.stickyPosition === "right")
78
- .reverse();
79
- // Calculate positions and minimize `getBoundingClientRect` calls
80
- const leftRects = leftChildren.map((child) => child.getBoundingClientRect());
81
- const rightRects = rightChildren.map((child) => child.getBoundingClientRect());
82
- const leftPrevious = leftRects.map((rect) => Math.abs(rect.right - wrapperRect.left));
83
- const rightPrevious = rightRects.map((rect) => Math.abs(rect.left - wrapperRect.right));
84
- // #region Left
85
- leftChildren.forEach((child, index) => {
86
- const prevLeft = index > 0 ? leftPrevious[index - 1] : 0;
87
- if (index > 0) {
88
- const childLeft = leftRects[index].left - wrapperRect.left;
89
- if (Math.floor(childLeft) === Math.floor(prevLeft)) {
90
- if (!child.classList.contains("active-sticky"))
91
- child.classList.add("active-sticky");
92
- }
93
- else
94
- child.classList.remove("active-sticky");
95
- child.style.left = `${prevLeft}px`;
96
- }
97
- else
98
- child.classList.add("sticky");
99
- if (child.nodeName === "TD")
100
- child.style.zIndex = `${leftChildren.length - index}`;
101
- });
102
- // #endregion
103
- // #region Right
104
- rightChildren.forEach((child, index) => {
105
- const prevRight = index > 0 ? rightPrevious[index - 1] : 0;
106
- if (index > 0) {
107
- const childRight = Math.abs(rightRects[index].right - wrapperRect.right);
108
- if (Math.floor(childRight) === Math.floor(prevRight)) {
109
- if (!child.classList.contains("active-sticky"))
110
- child.classList.add("active-sticky");
111
- }
112
- else
113
- child.classList.remove("active-sticky");
114
- child.style.right = `${prevRight}px`;
115
- }
116
- else
117
- child.classList.add("sticky");
118
- });
119
- // #endregion
120
- });
121
- };
122
- const theadElements = _tableWrapper.current.querySelectorAll("table > thead > tr");
123
- const tbodyElements = _tableWrapper.current.querySelectorAll("table > tbody > tr");
124
- requestAnimationFrame(() => {
125
- updateStickyPositions(theadElements);
126
- updateStickyPositions(tbodyElements);
127
- });
128
- };
129
- const handleSearch = (event) => {
130
- if (config.isServerSide) {
131
- if (_searchTimeOut.current)
132
- clearTimeout(_searchTimeOut.current);
133
- _searchTimeOut.current = setTimeout(() => {
134
- setSearchedParams((prev) => ({ ...prev, [event.target.name]: event.target.value }));
135
- setCurrentPage(1);
136
- // pagination && pagination.onChange(1);
137
- }, 750);
138
- }
139
- else {
140
- setCurrentPage(1);
141
- setSearchedText((prev) => ({ ...prev, [event.target.name]: event.target.value }));
142
- }
143
- };
144
- const handleCheckboxChange = useCallback(async (event) => {
145
- event.stopPropagation();
146
- setCheckboxSelectedParams((prev) => {
147
- const updatedValues = new Set(prev?.[event.target.name] || []);
148
- event.target.checked ? updatedValues.add(event.target.value) : updatedValues.delete(event.target.value);
149
- return {
150
- ...prev,
151
- ...(Array.from(updatedValues).length > 0
152
- ? { [event.target.name]: Array.from(updatedValues) }
153
- : { [event.target.name]: [] }),
154
- };
155
- });
156
- }, []);
157
- // Derinlemesine arama yapmak için özyinelemeli bir fonksiyon tanımlayalım.
158
- const deepSearch = (item, searchedText) => {
159
- if (!searchedText)
160
- return false;
161
- // Eğer değer bir sayı veya string ise, aranan metinle eşleşip eşleşmediğini kontrol ediyoruz.
162
- return Object.entries(searchedText).every(([key, value]) => {
163
- const _itemValue = item[key];
164
- if (typeof _itemValue === "number" || typeof _itemValue === "string") {
165
- if (Array.isArray(value)) {
166
- if (value.length === 0)
167
- return true;
168
- else
169
- return value.some((v) => _itemValue.toString().toLocaleLowerCase().includes(v.toLocaleLowerCase()));
170
- }
171
- return _itemValue.toString().toLocaleLowerCase().includes(value.toLocaleLowerCase());
172
- }
173
- if (typeof _itemValue === "object") {
174
- if (Array.isArray(value)) {
175
- if (value.length === 0)
176
- return true;
177
- else {
178
- return value.some((v) => Object.entries(_itemValue ?? {}).some(([_, objValue]) => String(objValue).toLocaleLowerCase().includes(v.toLocaleLowerCase())));
179
- }
180
- }
181
- return Object.entries(_itemValue ?? {}).some(([_, objValue]) => String(objValue).toLocaleLowerCase().includes(value.toLocaleLowerCase()));
182
- }
183
- if (Array.isArray(_itemValue)) {
184
- console.log("Buradasın", _itemValue);
185
- }
186
- return false;
187
- });
188
- };
189
- const getData = useCallback(() => {
190
- let _data = [...data];
191
- if (searchedText)
192
- _data = _data.filter((item) => deepSearch(item, searchedText));
193
- if (pagination && !config.isServerSide) {
194
- const indexOfLastRow = currentPage * pagination.perPage;
195
- const indexOfFirstRow = indexOfLastRow - pagination.perPage;
196
- _data = _data.slice(indexOfFirstRow, indexOfLastRow);
197
- }
198
- // Veriler yenilenmesi durumunda tablo üzerindeki hesaplamalar tekrar yapılacaktır.
199
- setTimeout(() => handleScroll(), 0);
200
- return _data;
201
- }, [data, searchedText, currentPage]);
202
- // useEffects
203
- useEffect(() => {
204
- // Eğer `previousSelections` özelliğinden değer geliyorsa bu daha önce seçim yapılmış öğeleri gönderiyorum
205
- // demektir ve otomatik olarak seçim yap demek anlamına gekmektedir.
206
- if (previousSelections && previousSelections.length > 0) {
207
- const validSelections = data.filter((item) => previousSelections.some((selected) => JSON.stringify(selected) === JSON.stringify(item)));
208
- setSelectionItems(validSelections);
209
- }
210
- }, [previousSelections]);
211
- useEffect(() => {
212
- if (!selections || selectionItems.length === 0)
213
- return;
214
- selections(selectionItems);
215
- }, [selectionItems]);
216
- useEffect(() => {
217
- if (config?.isServerSide && searchedParams) {
218
- // const query = Object.entries(_searchedParams ?? {})
219
- // .map(([key, value]) => {
220
- // return `${key}=${value}`;
221
- // })
222
- // .join("&");
223
- const query = new URLSearchParams(_searchedParams).toString();
224
- searchedParams(_searchedParams, query);
225
- }
226
- }, [_searchedParams]);
227
- useEffect(() => {
228
- if (config.isServerSide) {
229
- if (_searchTimeOut.current)
230
- clearTimeout(_searchTimeOut.current);
231
- setSearchedParams(checkboxSelectedParams);
232
- }
233
- else {
234
- setSearchedText(checkboxSelectedParams);
235
- }
236
- setCurrentPage(1);
237
- // pagination && pagination.onChange(1);
238
- // Filters...
239
- // setSelectedfilterCheckboxItems((prev) => {
240
- // debugger;
241
- // const columnKeys = Object.keys(checkboxSelectedParams ?? {});
242
- // const selectedCount = _filterCheckboxItems.current.filter((x) => x?.checked).length;
243
- // const updatedItems = [...prev];
244
- // columnKeys.forEach((columnKey) => {
245
- // const existingIndex = updatedItems.findIndex((item) => item.columnKey === columnKey);
246
- // if (existingIndex !== -1) {
247
- // // Eğer aynı key varsa, güncelle
248
- // updatedItems[existingIndex] = { columnKey, selectedCount };
249
- // } else {
250
- // // Eğer aynı key yoksa, ekle
251
- // updatedItems.push({ columnKey, selectedCount });
252
- // }
253
- // });
254
- // return updatedItems;
255
- // });
256
- }, [checkboxSelectedParams]);
257
- useEffect(() => {
258
- if (!selections)
259
- return;
260
- let allChecked = false;
261
- if (_checkboxItems.current.length > 0) {
262
- allChecked = _checkboxItems.current.every((item) => item?.checked === true);
263
- }
264
- setSelectAll(allChecked);
265
- }, [selectionItems, currentPage]);
266
- // useEffect(() => {
267
- // if (!_tableContent.current) return;
268
- // const th = _tableContent.current?.querySelectorAll("table > thead > tr:first-child > th");
269
- // th.forEach((item) => setThWidths((prev) => [...prev, item.getBoundingClientRect().width]));
270
- // }, []);
271
- return (React.createElement("div", { ref: _tableWrapper, className: _tableClassName.map((c) => c).join(" ") },
272
- (title || description || actions || React.Children.count(children) > 0) && (React.createElement("div", { className: "header" },
273
- React.createElement("div", { className: "title" },
274
- React.createElement("h3", null, title),
275
- React.createElement("h5", null, description)),
276
- React.createElement("div", { className: "actions" },
277
- React.Children.count(children) > 0 && React.createElement("div", null, React.Children.map(children, (child) => child)),
278
- actions && (React.createElement(React.Fragment, null, actions.create && (React.createElement(Button, { variant: "outlined", status: "dark", icon: { element: React.createElement(ARIcon, { icon: "Add", size: 16 }) }, tooltip: { text: actions.create.tooltip, direction: "top" }, onClick: actions.create.onClick }))))))),
279
- React.createElement("div", { ref: _tableContent, className: "content", onScroll: handleScroll },
280
- React.createElement("table", { ref: ref },
281
- React.createElement("thead", null,
282
- React.createElement("tr", { key: "selection" },
283
- selections && (React.createElement("th", { className: "selection-col sticky-left", "data-sticky-position": "left" },
284
- React.createElement(Checkbox, { variant: "filled", status: "primary", checked: selectAll, onChange: (event) => {
285
- if (_checkboxItems.current.length > 0) {
286
- setSelectAll(event.target.checked);
287
- _checkboxItems.current.forEach((item) => {
288
- if (item) {
289
- if (item.checked !== event.target.checked)
290
- item.click();
291
- }
292
- });
293
- }
294
- } }))),
295
- columns.map((c, cIndex) => {
296
- let _className = [];
297
- if (c.config?.sticky)
298
- _className.push(`sticky-${c.config.sticky}`);
299
- if (!c.config?.width)
300
- _className.push("min-w");
301
- if (c.config?.alignContent) {
302
- _className.push(`align-content-${c.config.alignContent}`);
303
- }
304
- return (React.createElement("th", { key: `column-${cIndex}-${Math.random()}`, ...(_className.length > 0 && {
305
- className: `${_className.map((c) => c).join(" ")}`,
306
- }), ...(c.config?.width
307
- ? {
308
- style: { minWidth: c.config.width },
309
- }
310
- : // : { style: { maxWidth: thWidths[cIndex], minWidth: thWidths[cIndex] } })}
311
- { style: {} }), ...(c.config?.sticky && {
312
- "data-sticky-position": c.config.sticky,
313
- }) }, c.title));
314
- })),
315
- config?.isSearchable && (React.createElement("tr", { key: "isSearchable" },
316
- selections && (React.createElement("th", { key: `column-selections`, className: "selection-col sticky-left", "data-sticky-position": "left" })),
317
- columns.map((c, cIndex) => {
318
- if (!c.key)
319
- return React.createElement("th", null);
320
- let _className = [];
321
- if (c.config?.sticky)
322
- _className.push(`sticky-${c.config.sticky}`);
323
- if (c.config?.alignContent) {
324
- _className.push(`align-content-${c.config.alignContent}`);
325
- }
326
- return (React.createElement("th", { key: `column-${cIndex}`, ...(_className.length > 0 && {
327
- className: `${_className.map((c) => c).join(" ")}`,
328
- }), ...(c.config?.sticky && {
329
- "data-sticky-position": c.config.sticky,
330
- }) },
331
- React.createElement("div", { className: "filter-field" },
332
- React.createElement(Input, { ref: (element) => (_searchTextInputs.current[cIndex] = element), variant: c.key && !c.filters ? "filled" : "outlined", status: "light", name: typeof c.key !== "object" ? String(c.key) : String(c.key.field), onChange: handleSearch, disabled: !c.key || !!c.filters }),
333
- c.filters && (React.createElement(Popover, { content: React.createElement(React.Fragment, null,
334
- React.createElement("div", null, c.filters.map((filter, fIndex) => {
335
- const name = typeof c.key !== "object" ? String(c.key) : String(c.key.field);
336
- return (React.createElement("div", null,
337
- React.createElement(Checkbox, { ref: (element) => (_filterCheckboxItems.current[fIndex] = element), label: filter.text, name: name, status: "primary",
338
- // value={filter.value}
339
- checked: checkboxSelectedParams?.[name]?.includes(String(filter.value)), onChange: async (event) => await handleCheckboxChange(event) })));
340
- }))), windowBlur: true },
341
- React.createElement(Button, { variant: "borderless", icon: { element: React.createElement(ARIcon, { icon: "Filter", stroke: "var(--primary)", size: 16 }) } }))))));
342
- })))),
343
- React.createElement("tbody", null, getData().length > 0 ? (getData().map((item, index) => (React.createElement("tr", { key: `row-${index}-${Math.random()}` },
344
- selections && (React.createElement("td", { key: `selection-${index}`, className: "sticky-left", "data-sticky-position": "left" },
345
- React.createElement(Checkbox, { ref: (element) => (_checkboxItems.current[index] = element), status: "primary", checked: selectionItems.some((selectionItem) => JSON.stringify(selectionItem) === JSON.stringify(item)), onChange: (event) => {
346
- if (event.target.checked)
347
- setSelectionItems((prev) => [...prev, item]);
348
- else
349
- setSelectionItems((prev) => prev.filter((_item) => _item !== item));
350
- } }))),
351
- columns.map((c, cIndex) => {
352
- let _className = [];
353
- let render; // TODO: Generic yapmak için çalışma yap. (Daha Sonra)
354
- // `c.key` bir string ise
355
- if (typeof c.key !== "object") {
356
- render = c.render ? c.render(item) : item[c.key];
357
- }
358
- // `c.key` bir nesne ise ve `nestedKey` mevcutsa
359
- else if (typeof c.key === "object") {
360
- const _item = item[c.key.field];
361
- if (_item && typeof _item === "object") {
362
- render = c.render ? c.render(item) : _item[c.key.nestedKey];
363
- }
364
- }
365
- // Diğer durumlarda `null` döndür
366
- else {
367
- render = null;
368
- }
369
- // const isTypeOfNumber = typeof render === "number" ? "type-of-number" : "";
370
- // if (isTypeOfNumber) _className.push(isTypeOfNumber);
371
- if (c.config?.sticky)
372
- _className.push(`sticky-${c.config.sticky}`);
373
- if (c.config?.alignContent)
374
- _className.push(`align-content-${c.config.alignContent}`);
375
- if (c.config?.textWrap)
376
- _className.push(`text-${c.config.textWrap}`);
377
- return (React.createElement("td", { key: `cell-${index}-${cIndex}`, ...(_className.length > 0 && {
378
- className: `${_className.map((c) => c).join(" ")}`,
379
- }), ...(c.config?.width
380
- ? {
381
- style: { minWidth: c.config.width },
382
- }
383
- : // : {
384
- // style: { maxWidth: thWidths[cIndex], minWidth: thWidths[cIndex] },
385
- // })}
386
- {
387
- style: {},
388
- }), ...(c.config?.sticky && {
389
- "data-sticky-position": c.config.sticky,
390
- }) }, React.isValidElement(render) ? render : String(render)));
391
- }))))) : (React.createElement("tr", null,
392
- React.createElement("td", { colSpan: columns.length + 1 }, "Herhangi bir kay\u0131t bulunamad\u0131!")))))),
393
- pagination && pagination.totalRecords > pagination.perPage && (React.createElement("div", { className: "footer" },
394
- React.createElement("span", null,
395
- React.createElement("strong", null,
396
- "Showing ",
397
- getData().length),
398
- " ",
399
- React.createElement("span", null,
400
- "of ",
401
- pagination?.perPage ?? getData().length,
402
- " agreement")),
403
- React.createElement(Pagination, { totalRecords: pagination.totalRecords, currentPage: currentPage, perPage: pagination.perPage, onChange: (currentPage) => {
404
- // config.isServerSide && pagination.onChange(currentPage);
405
- setCurrentPage(currentPage);
406
- } })))));
407
- });
408
- // Actions'ı ekliyoruz.
409
- const Table = TableWithRef;
410
- Table.Actions = Actions;
411
- export default Table;