ar-design 0.4.30 → 0.4.32

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.
@@ -174,6 +174,10 @@
174
174
  align-items: center;
175
175
  gap: 0.5rem;
176
176
  min-width: 100%;
177
+
178
+ > .ar-date-picker {
179
+ width: 100%;
180
+ }
177
181
  }
178
182
  }
179
183
  }
@@ -375,7 +379,7 @@
375
379
  }
376
380
 
377
381
  > span {
378
- position: sticky;
382
+ /* position: sticky; */
379
383
  left: 0.5rem;
380
384
  }
381
385
  }
@@ -6,12 +6,14 @@
6
6
  > ul {
7
7
  display: flex;
8
8
  flex-direction: column;
9
+ gap: 1rem;
9
10
  padding: 0;
10
11
  margin: 0;
11
12
  list-style: none;
12
13
 
13
14
  li {
14
15
  list-style: none;
16
+ height: 2rem;
15
17
 
16
18
  > ul.submenu {
17
19
  display: grid;
@@ -19,7 +21,10 @@
19
21
  margin-left: 1.5rem;
20
22
  opacity: 0;
21
23
  transform: translateY(-4px);
22
- transition: grid-template-rows 250ms ease, opacity 200ms ease, transform 200ms ease;
24
+ transition:
25
+ grid-template-rows 250ms ease,
26
+ opacity 200ms ease,
27
+ transform 200ms ease;
23
28
  overflow: hidden;
24
29
 
25
30
  > .submenu-inner {
@@ -40,6 +45,8 @@
40
45
  display: flex;
41
46
  align-items: center;
42
47
  gap: 0.5rem;
48
+ width: 100%;
49
+ height: inherit;
43
50
  padding: 0.3rem;
44
51
  white-space: nowrap;
45
52
  cursor: pointer;
@@ -85,6 +92,17 @@
85
92
  }
86
93
  }
87
94
 
95
+ > .item {
96
+ width: 100%;
97
+ height: inherit;
98
+
99
+ > * {
100
+ display: flex;
101
+ align-items: center;
102
+ height: inherit;
103
+ }
104
+ }
105
+
88
106
  > .angel-down {
89
107
  position: absolute;
90
108
  right: 0.5rem;
@@ -17,11 +17,14 @@ interface IProps<T> {
17
17
  currentColumn: TableColumnType<T> | null;
18
18
  };
19
19
  };
20
+ methods: {
21
+ handleScroll: () => void;
22
+ };
20
23
  coordinate: {
21
24
  x: number;
22
25
  y: number;
23
26
  };
24
27
  }
25
- declare function PropertiesPopup<T extends object>({ refs, states, coordinate }: IProps<T>): false | React.ReactPortal;
28
+ declare function PropertiesPopup<T extends object>({ refs, states, methods, coordinate }: IProps<T>): false | React.ReactPortal;
26
29
  declare const _default: typeof PropertiesPopup;
27
30
  export default _default;
@@ -1,21 +1,19 @@
1
1
  "use client";
2
- import React, { memo, useCallback, useEffect, useMemo, useRef, } from "react";
2
+ import React, { memo, useEffect, useMemo, useRef } from "react";
3
3
  import ReactDOM from "react-dom";
4
4
  import { ARIcon } from "../../icons";
5
5
  import { ExtractKey } from "./Helpers";
6
- function PropertiesPopup({ refs, states, coordinate }) {
6
+ function PropertiesPopup({ refs, states, methods, coordinate }) {
7
7
  // refs
8
8
  const _arTablePropertiesPopup = useRef(null);
9
9
  // methods
10
- const handleClickOutSide = useCallback(() => {
11
- (event) => {
12
- const target = event.target;
13
- const clickedInsidePopup = _arTablePropertiesPopup.current && _arTablePropertiesPopup.current.contains(target);
14
- const isOneOfButtons = refs.buttons.current.some((button) => button === target || button?.contains(target));
15
- if (!clickedInsidePopup && !isOneOfButtons)
16
- handleClose();
17
- };
18
- }, []);
10
+ const handleClickOutSide = (event) => {
11
+ const target = event.target;
12
+ const clickedInsidePopup = _arTablePropertiesPopup.current && _arTablePropertiesPopup.current.contains(target);
13
+ const isOneOfButtons = target.closest('[data-properties-button="true"]');
14
+ if (!clickedInsidePopup && !isOneOfButtons)
15
+ handleClose();
16
+ };
19
17
  const handleSort = useMemo(() => {
20
18
  return (columnKey, direction) => {
21
19
  if (!columnKey)
@@ -31,10 +29,16 @@ function PropertiesPopup({ refs, states, coordinate }) {
31
29
  const handleKeys = (event) => {
32
30
  const key = event.key;
33
31
  if (key === "Escape")
34
- states.open.set(false);
32
+ handleClose();
33
+ };
34
+ const handleOpen = () => {
35
+ states.open.set(true);
36
+ methods.handleScroll();
37
+ };
38
+ const handleClose = () => {
39
+ states.open.set(false);
40
+ methods.handleScroll();
35
41
  };
36
- const handleOpen = () => states.open.set(true);
37
- const handleClose = () => states.open.set(false);
38
42
  // useEffects
39
43
  useEffect(() => {
40
44
  refs.buttons.current.map((button) => {
@@ -1,7 +1,7 @@
1
1
  import React, { Dispatch, SetStateAction } from "react";
2
2
  import { TableColumnType } from "../../../libs/types";
3
3
  import { Config, Sort } from "./IProps";
4
- declare const MemoizedTHeadCell: <T>({ refs, states, columns, config, }: {
4
+ declare const MemoizedTHeadCell: <T>({ refs, states, methods, columns, config, }: {
5
5
  refs: {
6
6
  propertiesButton: React.MutableRefObject<(HTMLSpanElement | null)[]>;
7
7
  };
@@ -24,6 +24,9 @@ declare const MemoizedTHeadCell: <T>({ refs, states, columns, config, }: {
24
24
  }>>;
25
25
  };
26
26
  };
27
+ methods: {
28
+ handleScroll: () => void;
29
+ };
27
30
  columns: TableColumnType<T>[];
28
31
  config: Config<T>;
29
32
  }) => React.JSX.Element;
@@ -2,7 +2,7 @@ import React, { memo } from "react";
2
2
  import Button from "../../form/button";
3
3
  import { ARIcon } from "../../icons";
4
4
  import { ExtractKey } from "./Helpers";
5
- const MemoizedTHeadCell = function ({ refs, states, columns, config, }) {
5
+ const MemoizedTHeadCell = function ({ refs, states, methods, columns, config, }) {
6
6
  return (React.createElement(React.Fragment, null, columns.map((c, cIndex) => {
7
7
  const { isProperties = true } = c.config ?? {};
8
8
  const _direction = states.sort.get.find((s) => s.key === c.key)?.direction;
@@ -30,7 +30,8 @@ const MemoizedTHeadCell = function ({ refs, states, columns, config, }) {
30
30
  _direction === "asc" && React.createElement(ARIcon, { icon: "ArrowUp" }),
31
31
  _direction === "desc" && React.createElement(ARIcon, { icon: "ArrowDown" }))),
32
32
  c.title),
33
- config.isProperties && isProperties && (React.createElement("span", { ref: (element) => (refs.propertiesButton.current[cIndex] = element), className: "properties-field", onClick: (event) => {
33
+ config.isProperties && isProperties && (React.createElement("span", { ref: (element) => (refs.propertiesButton.current[cIndex] = element), className: "properties-field", "data-properties-button": "true", onClick: (event) => {
34
+ event.preventDefault();
34
35
  event.stopPropagation();
35
36
  const rect = event.currentTarget.getBoundingClientRect();
36
37
  const screenCenterX = window.innerWidth / 2;
@@ -49,6 +50,7 @@ const MemoizedTHeadCell = function ({ refs, states, columns, config, }) {
49
50
  return prev;
50
51
  });
51
52
  states.open.set(true);
53
+ methods.handleScroll();
52
54
  } },
53
55
  React.createElement(Button, { variant: "borderless", icon: {
54
56
  element: React.createElement(ARIcon, { size: 16, icon: "ThreeDotsVertical", fill: "var(--dark)", strokeWidth: 0 }),
@@ -18,6 +18,7 @@ import PropertiesPopup from "./PropertiesPopup";
18
18
  import { ExtractKey } from "./Helpers";
19
19
  import Header from "./header/Header";
20
20
  import TBody from "./body/TBody";
21
+ import DatePicker from "../../form/date-picker";
21
22
  const filterOption = [
22
23
  { value: FilterOperator.Contains, text: "İçerir" },
23
24
  { value: FilterOperator.DoesNotContains, text: "İçermez" },
@@ -165,8 +166,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
165
166
  setIsMobile(window.innerWidth <= 768);
166
167
  };
167
168
  }, []);
168
- const handleSearch = useCallback((event) => {
169
- const { name, value } = event.target;
169
+ const handleSearch = useCallback((name, value, dataType) => {
170
170
  const operator = filterPopupOption?.key == name
171
171
  ? filterPopupOption.option?.value
172
172
  : FilterOperator.Contains;
@@ -180,7 +180,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
180
180
  }));
181
181
  if (pagination)
182
182
  pagination.onChange?.(1, selectedPerPage);
183
- }, 750);
183
+ }, dataType === "date" ? 0 : 750);
184
184
  }
185
185
  else {
186
186
  setSearchedText((prev) => {
@@ -194,7 +194,6 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
194
194
  return _state;
195
195
  });
196
196
  }
197
- event.target.value = value;
198
197
  setCurrentPage(1);
199
198
  }, [filterPopupOption]);
200
199
  const handleCheckboxChange = useCallback(async (event) => {
@@ -221,8 +220,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
221
220
  const value = Array.isArray(searchedText?.[key])
222
221
  ? "" // veya ihtiyacına göre birleştirme yap: searchedText[key].map(v => v.value).join(", ").
223
222
  : searchedText?.[key]?.value;
224
- const handleChange = (event) => {
225
- const { value } = event.target;
223
+ const handleChange = (value) => {
226
224
  const input = _searchTextInputs.current[index ?? 0];
227
225
  if (input) {
228
226
  const event = new Event("input", { bubbles: true });
@@ -240,7 +238,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
240
238
  setFilterPopupOption({ key: c.key, option: option });
241
239
  }, placeholder: "Ko\u015Ful" })),
242
240
  React.createElement(Column, { size: 12 },
243
- React.createElement(Input, { value: value ?? "", onChange: handleChange, placeholder: "Ara" }))));
241
+ React.createElement(Input, { value: value ?? "", onChange: (event) => handleChange(event.target.value), placeholder: "Ara" }))));
244
242
  case "object":
245
243
  case "boolean":
246
244
  return (React.createElement(Row, null,
@@ -382,6 +380,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
382
380
  const indexOfFirstRow = indexOfLastRow - selectedPerPage;
383
381
  _data = _data.slice(indexOfFirstRow, indexOfLastRow);
384
382
  }
383
+ handleScroll();
385
384
  return _data;
386
385
  }, [data, searchedText, currentPage, selectedPerPage, sortConfig, config.isServerSide]);
387
386
  // useEffects
@@ -561,7 +560,6 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
561
560
  _tBody.current.ondragover = null;
562
561
  };
563
562
  }, [data]);
564
- useLayoutEffect(() => handleScroll(), [data]);
565
563
  useLayoutEffect(() => {
566
564
  if (!pagination?.currentPage)
567
565
  return;
@@ -605,7 +603,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
605
603
  sort: { get: sortConfig, set: setSortConfig },
606
604
  sortCurrentColumn: { set: setSortCurrentColumn },
607
605
  propertiesButtonCoordinate: { set: setPropertiesButtonCoordinate },
608
- }, columns: columns, config: config })),
606
+ }, methods: { handleScroll }, columns: columns, config: config })),
609
607
  config?.isSearchable && (React.createElement("tr", { key: "isSearchable" },
610
608
  selections && (React.createElement("th", { key: `column-selections`, className: "selection-col sticky-left", "data-sticky-position": "left" })),
611
609
  columns.map((c, cIndex) => {
@@ -626,9 +624,14 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
626
624
  className: `${_className.map((c) => c).join(" ")}`,
627
625
  }), ...(c.config?.sticky && {
628
626
  "data-sticky-position": c.config.sticky,
629
- }) }, c.key && (React.createElement("div", { className: "filter-field" },
630
- React.createElement(Input, { ref: (element) => (_searchTextInputs.current[cIndex] = element), variant: c.key && !c.filters ? "outlined" : "filled", style: { height: "2rem" }, value: (config.isServerSide ? ssrValue : csrValue) ?? "", name: key, onInput: handleSearch, disabled: !c.key || !!c.filters }),
627
+ }) }, c.key && (React.createElement("div", { className: "filter-field" }, c.filterDataType === "date" ? (React.createElement(DatePicker, { value: (config.isServerSide ? ssrValue : csrValue) ?? "", name: key, onClick: () => {
628
+ handleScroll();
629
+ }, onChange: (value) => handleSearch(key, value, c.filterDataType), style: { height: "2rem" }, config: { isClock: true, isFooterButton: true, locale: config.locale }, disabled: !c.key || !!c.filters })) : (React.createElement(React.Fragment, null,
630
+ React.createElement(Input, { ref: (element) => (_searchTextInputs.current[cIndex] = element), variant: c.key && !c.filters ? "outlined" : "filled", style: { height: "2rem" }, value: (config.isServerSide ? ssrValue : csrValue) ?? "", name: key, onClick: () => {
631
+ handleScroll();
632
+ }, onInput: (event) => handleSearch(event.currentTarget.name, event.currentTarget.value), disabled: !c.key || !!c.filters }),
631
633
  React.createElement("span", { ref: (element) => (_filterButton.current[cIndex] = element), onClick: (event) => {
634
+ event.preventDefault();
632
635
  event.stopPropagation();
633
636
  // Temizlik...
634
637
  setFilterPopupOptionSearchText("");
@@ -650,10 +653,11 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
650
653
  setFilterCurrentIndex(cIndex);
651
654
  setOpenFilter(true);
652
655
  handleFilterPopupContent(c, c.filterDataType ?? dataType, cIndex);
656
+ handleScroll();
653
657
  } },
654
658
  React.createElement(Button, { variant: "borderless", icon: {
655
659
  element: React.createElement(ARIcon, { size: 24, icon: "Filter", fill: "var(--dark)", strokeWidth: 0 }),
656
- } }))))));
660
+ } }))))))));
657
661
  })))),
658
662
  React.createElement("tbody", { ref: _tBody },
659
663
  React.createElement(TBody, { data: getData, columns: columns, refs: { _checkboxItems: _checkboxItems, _selectionItems: _selectionItems }, states: {
@@ -678,7 +682,7 @@ const Table = forwardRef(({ children, trackBy, title, description, data, columns
678
682
  }, states: {
679
683
  open: { get: openProperties, set: setOpenProperties },
680
684
  sort: { get: sortConfig, set: setSortConfig, currentColumn: sortCurrentColumn },
681
- }, coordinate: propertiesButtonCoordinate })),
685
+ }, methods: { handleScroll }, coordinate: propertiesButtonCoordinate })),
682
686
  React.createElement("div", { className: "footer" },
683
687
  React.createElement("span", null, isMobile ? (React.createElement(React.Fragment, null,
684
688
  React.createElement("strong", null,
@@ -25,6 +25,7 @@ export type MenuProps = {
25
25
  };
26
26
  export type MenuItemVariants = "vertical" | "horizontal";
27
27
  export type MenuItemType = "group" | "divider";
28
+ export type FilterDataType = "string" | "number" | "date" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
28
29
  export type TableColumnType<T> = {
29
30
  title: string;
30
31
  key?: keyof T | {
@@ -32,7 +33,7 @@ export type TableColumnType<T> = {
32
33
  nestedKey: string;
33
34
  };
34
35
  filters?: Option[];
35
- filterDataType?: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
36
+ filterDataType?: FilterDataType;
36
37
  render?: (item: T) => React.ReactNode;
37
38
  editable?: {
38
39
  type: "string" | "number" | "decimal" | "input-formatted-decimal" | "date-picker" | "single-select" | "multiple-select";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.4.30",
3
+ "version": "0.4.32",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",