ar-design 0.2.16 → 0.2.18

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.
@@ -10,13 +10,25 @@
10
10
  .ar-tabs > .tabs > .item {
11
11
  position: relative;
12
12
  display: flex;
13
- justify-content: center;
13
+ justify-content: space-between;
14
14
  align-items: center;
15
+ gap: 1rem;
15
16
  height: 100%;
16
17
  padding: 0 0.75rem;
17
18
  font-weight: 900;
18
19
  cursor: pointer;
19
20
  }
21
+ .ar-tabs > .tabs > .item > .close-button {
22
+ display: flex;
23
+ justify-content: center;
24
+ align-items: center;
25
+ background-color: rgba(var(--danger-rgb), 0.25);
26
+ width: 1rem;
27
+ height: 1rem;
28
+ border-radius: var(--border-radius-pill);
29
+ color: rgba(var(--danger-rgb), 0.5);
30
+ font-size: 0.75rem;
31
+ }
20
32
  .ar-tabs > .tabs > .item.selection::before {
21
33
  position: absolute;
22
34
  left: 0;
@@ -19,6 +19,7 @@ interface IProps<T> extends IChildren {
19
19
  filterClear?: ActionType;
20
20
  };
21
21
  selections?: (selectionItems: T[]) => void;
22
+ previousSelections?: T[];
22
23
  searchedParams?: (params: SearchedParam | undefined, query: string) => void;
23
24
  pagination?: {
24
25
  totalRecords: number;
@@ -8,7 +8,7 @@ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef,
8
8
  import Actions from "./Actions";
9
9
  import Input from "../../form/input";
10
10
  import Popover from "../../feedback/popover";
11
- const TableWithRef = forwardRef(({ children, title, description, data, columns, actions, selections, searchedParams, pagination, config = { isSearchable: false }, }, ref) => {
11
+ const TableWithRef = forwardRef(({ children, title, description, data, columns, actions, selections, previousSelections, searchedParams, pagination, config = { isSearchable: false }, }, ref) => {
12
12
  // refs
13
13
  const _tableWrapper = useRef(null);
14
14
  const _table = useRef(null);
@@ -28,7 +28,12 @@ const TableWithRef = forwardRef(({ children, title, description, data, columns,
28
28
  const [searchedText, setSearchedText] = useState(undefined);
29
29
  const [_searchedParams, setSearchedParams] = useState(undefined);
30
30
  const [checkboxSelectedParams, setCheckboxSelectedParams] = useState(undefined);
31
- const [selectedfilterCheckboxItems, setSelectedfilterCheckboxItems] = useState(undefined);
31
+ // const [selectedfilterCheckboxItems, setSelectedfilterCheckboxItems] = useState<
32
+ // {
33
+ // selectedCount: number;
34
+ // columnKey: string;
35
+ // }[]
36
+ // >([]);
32
37
  // const [searchedFilters, setSearchedFilters] = useState<string | undefined>(undefined);
33
38
  // const [totalRecords, setTotalRecords] = useState<number>(0);
34
39
  const [currentPage, setCurrentPage] = useState(1);
@@ -195,6 +200,14 @@ const TableWithRef = forwardRef(({ children, title, description, data, columns,
195
200
  return _data;
196
201
  }, [data, searchedText, currentPage]);
197
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]);
198
211
  useEffect(() => {
199
212
  if (!selections || selectionItems.length === 0)
200
213
  return;
@@ -222,7 +235,24 @@ const TableWithRef = forwardRef(({ children, title, description, data, columns,
222
235
  }
223
236
  setCurrentPage(1);
224
237
  pagination && pagination.onChange(1);
225
- setSelectedfilterCheckboxItems(_filterCheckboxItems.current.filter((x) => x?.checked).length);
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
+ // });
226
256
  }, [checkboxSelectedParams]);
227
257
  useEffect(() => {
228
258
  if (!selections)
@@ -232,7 +262,7 @@ const TableWithRef = forwardRef(({ children, title, description, data, columns,
232
262
  allChecked = _checkboxItems.current.every((item) => item?.checked === true);
233
263
  }
234
264
  setSelectAll(allChecked);
235
- }, [currentPage]);
265
+ }, [selectionItems, currentPage]);
236
266
  // useEffect(() => {
237
267
  // if (!_tableContent.current) return;
238
268
  // const th = _tableContent.current?.querySelectorAll("table > thead > tr:first-child > th");
@@ -309,16 +339,6 @@ const TableWithRef = forwardRef(({ children, title, description, data, columns,
309
339
  return (React.createElement("div", null,
310
340
  React.createElement(Checkbox, { ref: (element) => (_filterCheckboxItems.current[fIndex] = element), label: filter.text, name: name, status: "primary", value: filter.value, checked: checkboxSelectedParams?.[name]?.includes(String(filter.value)), onChange: async (event) => await handleCheckboxChange(event) })));
311
341
  }))), windowBlur: true },
312
- (selectedfilterCheckboxItems ?? 0) > 0 && (React.createElement("div", { style: {
313
- position: "absolute",
314
- top: "0.35rem",
315
- right: "0.35rem",
316
- width: "0.5rem",
317
- height: "0.5rem",
318
- backgroundColor: "var(--danger)",
319
- borderRadius: "var(--border-radius-pill)",
320
- zIndex: 1,
321
- } })),
322
342
  React.createElement(Button, { variant: "borderless", icon: { element: React.createElement(ARIcon, { icon: "Filter", stroke: "var(--primary)", size: 16 }) } }))))));
323
343
  })))),
324
344
  React.createElement("tbody", null, getData().length > 0 ? (getData().map((item, index) => (React.createElement("tr", { key: `row-${index}-${Math.random()}` },
@@ -8,5 +8,8 @@ interface IProps {
8
8
  * Her bir `Tab için gerekli özellikler `TabProps` tipinde olmalıdır.
9
9
  */
10
10
  tabs: TabProps[];
11
+ activeTab?: number;
12
+ onChange?: (currentTab: number) => void;
13
+ onClose?: (closeTab: number) => void;
11
14
  }
12
15
  export default IProps;
@@ -1,17 +1,28 @@
1
1
  "use client";
2
- import React, { useState } from "react";
2
+ import React, { useEffect, useState } from "react";
3
3
  import "../../../assets/css/components/data-display/tabs/tabs.css";
4
- const Tabs = ({ tabs = [] }) => {
4
+ const Tabs = ({ tabs = [], activeTab, onChange, onClose }) => {
5
5
  // states
6
6
  const [currentTab, setCurrentTab] = useState(0);
7
+ // useEffects
8
+ useEffect(() => {
9
+ setCurrentTab(activeTab ?? 0);
10
+ }, [activeTab]);
7
11
  return (React.createElement("div", { className: "ar-tabs" },
8
12
  React.createElement("div", { className: "tabs" }, tabs.length > 0 &&
9
13
  tabs.map((tab, index) => {
10
14
  let className = ["item"];
11
15
  if (currentTab === index)
12
16
  className.push("selection");
13
- return (React.createElement("div", { key: tab.title ?? index, className: className.map((c) => c).join(" "), onClick: () => setCurrentTab(index) },
14
- React.createElement("span", null, tab.title)));
17
+ return (React.createElement("div", { key: tab.title ?? index, className: className.map((c) => c).join(" "), onClick: () => {
18
+ setCurrentTab(index);
19
+ onChange && onChange(index);
20
+ } },
21
+ React.createElement("span", null, tab.title),
22
+ tab.config?.canBeClosed && (React.createElement("span", { className: "close-button", onClick: (event) => {
23
+ event.stopPropagation();
24
+ onClose && onClose(index);
25
+ } }, "\u2716"))));
15
26
  })),
16
27
  React.createElement("div", { className: "content" }, tabs.map((tab, index) => currentTab === index && tab.content))));
17
28
  };
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import React, { forwardRef, useRef, useState } from "react";
2
+ import React, { forwardRef, useEffect, useRef, useState } from "react";
3
3
  import "../../../assets/css/components/form/checkbox/checkbox.css";
4
4
  import Utils from "../../../libs/infrastructure/shared/Utils";
5
5
  const Checkbox = forwardRef(({ label, size = "normal", status, border = { radius: "sm" }, upperCase, ...attributes }, ref) => {
@@ -9,6 +9,10 @@ const Checkbox = forwardRef(({ label, size = "normal", status, border = { radius
9
9
  // states
10
10
  const [checked, setChecked] = useState(attributes.checked ?? false);
11
11
  _checkboxClassName.push(...Utils.GetClassName("filled", checked ? status : "light", border, size, undefined, attributes.className));
12
+ // useEffects
13
+ useEffect(() => {
14
+ setChecked(attributes.checked ?? false);
15
+ }, [attributes.checked]);
12
16
  return (React.createElement("div", { className: "ar-checkbox-wrapper" },
13
17
  React.createElement("label", null,
14
18
  React.createElement("input", { ref: ref, type: "checkbox", ...attributes, size: 0, onChange: (event) => {
@@ -48,6 +48,9 @@ export type StepProps = {
48
48
  export type TabProps = {
49
49
  title: string;
50
50
  content: React.ReactNode;
51
+ config?: {
52
+ canBeClosed: boolean;
53
+ };
51
54
  };
52
55
  export type ValidationShape = {
53
56
  type: "required" | "minimum" | "maximum" | "email";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",