ar-design 0.4.42 → 0.4.44

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.
@@ -1,23 +1,25 @@
1
1
  import { KanbanBoardColumnType } from "../../../libs/types";
2
- interface IProps<T, TColumnProperties> {
2
+ export type Config<T extends object> = {
3
+ locale?: Intl.LocalesArgument;
4
+ safeAreaOffset?: {
5
+ top?: number;
6
+ right?: number;
7
+ bottom?: number;
8
+ left?: number;
9
+ };
10
+ filter?: {
11
+ search?: (item: T, value: string) => boolean;
12
+ keys: (item: T) => {
13
+ name: string;
14
+ key: string;
15
+ type: "select" | "date";
16
+ }[];
17
+ };
18
+ };
19
+ interface IProps<T extends object, TColumnProperties> {
3
20
  trackBy: (item: T) => string;
4
21
  columns: KanbanBoardColumnType<T, TColumnProperties>[];
5
22
  onChange?: (item: T, columnKey: string, columnProperties: TColumnProperties, hoverIndex: number) => void;
6
- config?: {
7
- safeAreaOffset?: {
8
- top?: number;
9
- right?: number;
10
- bottom?: number;
11
- left?: number;
12
- };
13
- filter?: {
14
- search?: (item: T, value: string) => boolean;
15
- keys: (item: T) => {
16
- name: string;
17
- key: string;
18
- type: "select" | "date";
19
- }[];
20
- };
21
- };
23
+ config?: Config<T>;
22
24
  }
23
25
  export default IProps;
@@ -1,5 +1,6 @@
1
- import React, { Dispatch, SetStateAction } from "react";
2
- interface IProps {
1
+ import { Dispatch, JSX, SetStateAction } from "react";
2
+ import { Config } from "../IProps";
3
+ interface IProps<T extends object> {
3
4
  states: {
4
5
  dateFilters: {
5
6
  get: Record<string, {
@@ -18,6 +19,7 @@ interface IProps {
18
19
  methods: {
19
20
  open: (name: string | null) => void;
20
21
  };
22
+ config?: Config<T>;
21
23
  }
22
- declare const _default: React.MemoExoticComponent<({ states, methods }: IProps) => React.JSX.Element[]>;
24
+ declare const _default: <T extends object>(props: IProps<T>) => JSX.Element;
23
25
  export default _default;
@@ -4,8 +4,11 @@ import { ARIcon } from "../../../icons";
4
4
  import Grid from "../../grid-system";
5
5
  import Button from "../../../form/button";
6
6
  import Divider from "../../divider";
7
+ import { useTranslation } from "../../../../libs/core/application/hooks";
7
8
  const { Row, Column, Box } = Grid;
8
- const DateFilters = ({ states, methods }) => {
9
+ function DateFilters({ states, methods, config }) {
10
+ // hooks
11
+ const { t } = useTranslation(String(config?.locale ?? "tr"));
9
12
  return Object.entries(states.dateFilters.get).map(([name, range], index) => {
10
13
  const isEqualsName = states.openName.get === name;
11
14
  const className = [];
@@ -46,7 +49,7 @@ const DateFilters = ({ states, methods }) => {
46
49
  ...prev,
47
50
  [name]: { from: null, to: null },
48
51
  }));
49
- } }, "Clear")))))));
52
+ } }, t("KanbanBoard.Search.Button.Clear.Text"))))))));
50
53
  });
51
- };
54
+ }
52
55
  export default memo(DateFilters);
@@ -1,5 +1,6 @@
1
- import React, { Dispatch, SetStateAction } from "react";
2
- interface IProps {
1
+ import { Dispatch, JSX, SetStateAction } from "react";
2
+ import { Config } from "../IProps";
3
+ interface IProps<T extends object> {
3
4
  states: {
4
5
  selectFilters: {
5
6
  get: {
@@ -20,6 +21,7 @@ interface IProps {
20
21
  methods: {
21
22
  open: (name: string | null) => void;
22
23
  };
24
+ config?: Config<T>;
23
25
  }
24
- declare const SelectFilters: ({ states, methods }: IProps) => React.JSX.Element[];
25
- export default SelectFilters;
26
+ declare const _default: <T extends object>(props: IProps<T>) => JSX.Element;
27
+ export default _default;
@@ -1,11 +1,14 @@
1
- import React from "react";
1
+ import React, { memo } from "react";
2
2
  import { ARIcon } from "../../../icons";
3
3
  import Checkbox from "../../../form/checkbox";
4
4
  import Grid from "../../grid-system";
5
5
  import Button from "../../../form/button";
6
6
  import Divider from "../../divider";
7
+ import { useTranslation } from "../../../../libs/core/application/hooks";
7
8
  const { Box } = Grid;
8
- const SelectFilters = ({ states, methods }) => {
9
+ function SelectFilters({ states, methods, config }) {
10
+ // hooks
11
+ const { t } = useTranslation(String(config?.locale ?? "tr"));
9
12
  return Object.entries(states.selectFilters.get).map(([name, values], index) => {
10
13
  const isEqualsName = states.openName.get === name;
11
14
  const className = [];
@@ -34,7 +37,7 @@ const SelectFilters = ({ states, methods }) => {
34
37
  delete next[name];
35
38
  return next;
36
39
  });
37
- } }, "Clear"))))));
40
+ } }, t("KanbanBoard.Search.Button.Clear.Text")))))));
38
41
  });
39
- };
40
- export default SelectFilters;
42
+ }
43
+ export default memo(SelectFilters);
@@ -1,6 +1,7 @@
1
1
  import { Dispatch, SetStateAction } from "react";
2
2
  import React from "react";
3
- interface IProps {
3
+ import { Config } from "../IProps";
4
+ interface IProps<T extends object> {
4
5
  states: {
5
6
  search: {
6
7
  get: string;
@@ -29,6 +30,7 @@ interface IProps {
29
30
  set: Dispatch<SetStateAction<Record<string, Set<string | null>>>>;
30
31
  };
31
32
  };
33
+ config?: Config<T>;
32
34
  }
33
- declare const Filter: ({ states }: IProps) => React.JSX.Element;
35
+ declare function Filter<T extends object>({ states, config }: IProps<T>): React.JSX.Element;
34
36
  export default Filter;
@@ -4,13 +4,16 @@ import DateFilters from "./DateFilters";
4
4
  import SelectFilters from "./SelectFilters";
5
5
  import React from "react";
6
6
  import Input from "../../../form/input";
7
- const Filter = ({ states }) => {
7
+ import { useTranslation } from "../../../../libs/core/application/hooks";
8
+ function Filter({ states, config }) {
8
9
  // states
9
10
  const [openName, setOpenName] = useState(null);
11
+ // hooks
12
+ const { t } = useTranslation(String(config?.locale ?? "tr"));
10
13
  // methods
11
14
  const handleOpen = (name) => setOpenName(openName === name ? null : name);
12
15
  return (React.createElement("div", { className: "filters" },
13
- React.createElement(Input, { variant: "borderless", placeholder: "Filter by keyword", onChange: (event) => states.search.set(event.target.value.toLocaleLowerCase()) }),
16
+ React.createElement(Input, { variant: "borderless", placeholder: t("KanbanBoard.Search.Input.Placeholder"), onChange: (event) => states.search.set(event.target.value.toLocaleLowerCase()) }),
14
17
  React.createElement("ul", null,
15
18
  React.createElement(DateFilters, { states: {
16
19
  dateFilters: {
@@ -20,7 +23,7 @@ const Filter = ({ states }) => {
20
23
  openName: { get: openName },
21
24
  }, methods: {
22
25
  open: handleOpen,
23
- } }),
26
+ }, config: config }),
24
27
  React.createElement(SelectFilters, { states: {
25
28
  selectFilters: {
26
29
  get: states.selectFilters.get,
@@ -31,6 +34,6 @@ const Filter = ({ states }) => {
31
34
  set: states.selectedFilters.set,
32
35
  },
33
36
  openName: { get: openName },
34
- }, methods: { open: handleOpen } }))));
35
- };
37
+ }, methods: { open: handleOpen }, config: config }))));
38
+ }
36
39
  export default Filter;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
2
  import IProps from "./IProps";
3
3
  import "../../../assets/css/components/data-display/kanban-board/styles.css";
4
- declare const KanbanBoard: <T, TColumnProperties>({ trackBy, columns, onChange, config, }: IProps<T, TColumnProperties>) => React.JSX.Element;
4
+ declare const KanbanBoard: <T extends object, TColumnProperties>({ trackBy, columns, onChange, config, }: IProps<T, TColumnProperties>) => React.JSX.Element;
5
5
  export default KanbanBoard;
@@ -7,6 +7,7 @@ import Filter from "./filter";
7
7
  const KanbanBoard = function ({ trackBy, columns, onChange, config, }) {
8
8
  // refs
9
9
  const _kanbanWrapper = useRef(null);
10
+ const _kanbanItems = useRef({});
10
11
  const _hoverItemIndex = useRef(null);
11
12
  const _scrollInterval = useRef(null);
12
13
  const _scrollAnimationFrame = useRef(null);
@@ -169,13 +170,23 @@ const KanbanBoard = function ({ trackBy, columns, onChange, config, }) {
169
170
  ...col,
170
171
  items: [...col.items],
171
172
  }));
173
+ let firstMatchedId = null;
172
174
  // Search varsa...
173
175
  if (config?.filter?.search && search?.trim()) {
174
176
  const q = search.trim();
175
- nextData = nextData.map((col) => ({
176
- ...col,
177
- items: col.items.filter((item) => config.filter.search(item, q)),
178
- }));
177
+ nextData = nextData.map((col) => {
178
+ const filteredItems = col.items.filter((item) => {
179
+ const isMatch = config.filter.search(item, q);
180
+ if (isMatch && !firstMatchedId)
181
+ firstMatchedId = trackBy(item);
182
+ return isMatch;
183
+ });
184
+ return { ...col, items: filteredItems };
185
+ });
186
+ }
187
+ else {
188
+ if (config?.filter?.search)
189
+ config.filter.search({}, "");
179
190
  }
180
191
  // Select ve Date varsa...
181
192
  nextData = nextData.map((col) => ({
@@ -209,6 +220,26 @@ const KanbanBoard = function ({ trackBy, columns, onChange, config, }) {
209
220
  }),
210
221
  }));
211
222
  setData(nextData);
223
+ // Focus / Scroll Control
224
+ if (search?.trim() && firstMatchedId) {
225
+ const element = _kanbanItems.current[firstMatchedId];
226
+ const container = _kanbanWrapper.current;
227
+ if (element && container) {
228
+ const elementRect = element.getBoundingClientRect();
229
+ const containerRect = container.getBoundingClientRect();
230
+ // Senin hesaplaman: Mevcut scroll + elemanın container'a göre konumu - ofset değerlerin
231
+ const scrollLeft = container.scrollLeft + (elementRect.left - containerRect.left) - 17.5;
232
+ const scrollTop = container.scrollTop + (elementRect.top - containerRect.top) - 100;
233
+ container.scrollTo({
234
+ left: scrollLeft,
235
+ top: scrollTop,
236
+ behavior: "smooth",
237
+ });
238
+ }
239
+ }
240
+ else if (!search?.trim() && _kanbanWrapper.current) {
241
+ _kanbanWrapper.current.scrollTo({ top: 0, left: 0, behavior: "smooth" });
242
+ }
212
243
  }, [columns, search, selectedFilters, dateFilters]);
213
244
  return (React.createElement(React.Fragment, null,
214
245
  config?.filter && (React.createElement(Filter, { states: {
@@ -228,7 +259,7 @@ const KanbanBoard = function ({ trackBy, columns, onChange, config, }) {
228
259
  get: selectedFilters,
229
260
  set: setSelectedFilters,
230
261
  },
231
- } })),
262
+ }, config: config })),
232
263
  React.createElement("div", { ref: _kanbanWrapper, className: "ar-kanban-board", style: {
233
264
  height: `calc(100dvh - (${_kanbanWrapper.current?.getBoundingClientRect().top}px + ${config?.safeAreaOffset?.bottom ?? 0}px))`,
234
265
  }, onDragOver: handleBoardDragOver, onDragEnd: stopScrolling, onDrop: stopScrolling },
@@ -248,7 +279,11 @@ const KanbanBoard = function ({ trackBy, columns, onChange, config, }) {
248
279
  React.createElement("div", { className: "columns" }, data.map((board, index) => (React.createElement("div", { key: index, className: "column", onDrop: handleDrop(board.key) },
249
280
  React.createElement("div", { className: "items", onDragOver: handleItemsDragOver, onDragLeave: handleItemsDragLeave, onDrop: handleItemsDrop },
250
281
  React.createElement(DnD, { key: board.key, data: board.items, renderItem: (item, dndIndex) => {
251
- return (React.createElement("div", { key: dndIndex, className: "item", onDragOver: (event) => {
282
+ return (React.createElement("div", { key: dndIndex, ref: (el) => {
283
+ if (!el)
284
+ return;
285
+ _kanbanItems.current[trackBy(item)] = el;
286
+ }, className: "item", onDragOver: (event) => {
252
287
  event.preventDefault();
253
288
  const rect = event.currentTarget.getBoundingClientRect();
254
289
  const mouseY = event.clientY;
@@ -8,9 +8,9 @@ const Editable = function ({ c, item, trackByValue, onEditable, config }) {
8
8
  // variables
9
9
  const key = c.key;
10
10
  const itemValue = item[c.key];
11
- const selectItem = c.editable?.options?.find((x) => x.value === itemValue);
11
+ const selectItem = c.editable?.(item)?.options?.find((x) => x.value === itemValue);
12
12
  const selectItems = Array.isArray(itemValue)
13
- ? c.editable?.options?.filter((x) => itemValue.includes(x.value))
13
+ ? c.editable?.(item)?.options?.filter((x) => itemValue.includes(x.value))
14
14
  : [];
15
15
  const validation = config.validation;
16
16
  const _vText = validation?.errors?.[`${c.key}_${trackByValue}`];
@@ -18,39 +18,39 @@ const Editable = function ({ c, item, trackByValue, onEditable, config }) {
18
18
  const [_value, setValue] = useState(itemValue);
19
19
  // useEffects
20
20
  useEffect(() => setValue(itemValue), [item]);
21
- switch (c.editable?.type) {
21
+ switch (c.editable?.(item)?.type) {
22
22
  case "string":
23
23
  case "number":
24
24
  return (React.createElement(Input, { variant: "borderless", value: _value, onChange: (event) => {
25
25
  const { value } = event.target;
26
26
  setValue(value);
27
- onEditable({ ...item, [key]: c.editable?.type === "number" ? Number(value) : value }, trackByValue, ExtractKey(c.key));
28
- }, validation: { text: _vText }, ...(c.editable.where ? { disabled: c.editable.where(item) } : {}) }));
27
+ onEditable({ ...item, [key]: c.editable?.(item)?.type === "number" ? Number(value) : value }, trackByValue, ExtractKey(c.key));
28
+ }, validation: { text: _vText }, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
29
29
  case "decimal":
30
30
  return (React.createElement(Input.Decimal, { variant: "borderless", name: c.key, value: _value, onChange: (event) => {
31
31
  const { value } = event.target;
32
32
  setValue(value);
33
33
  onEditable({ ...item, [key]: value }, trackByValue, ExtractKey(c.key));
34
- }, validation: { text: _vText }, locale: config.locale, ...(c.editable.where ? { disabled: c.editable.where(item) } : {}) }));
34
+ }, validation: { text: _vText }, locale: config.locale, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
35
35
  case "input-formatted-decimal":
36
36
  return (React.createElement(Input.FormattedDecimal, { variant: "borderless", name: c.key, value: _value, onChange: (event) => {
37
37
  const { value } = event.target;
38
38
  setValue(value);
39
39
  onEditable({ ...item, [key]: value }, trackByValue, ExtractKey(c.key));
40
- }, validation: { text: _vText }, locale: config.locale, ...(c.editable.where ? { disabled: c.editable.where(item) } : {}) }));
40
+ }, validation: { text: _vText }, locale: config.locale, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
41
41
  case "date-picker":
42
42
  return (React.createElement(DatePicker, { variant: "borderless", value: _value, onChange: (value) => {
43
43
  setValue(value);
44
44
  onEditable({ ...item, [key]: value }, trackByValue, ExtractKey(c.key));
45
- }, validation: { text: _vText }, ...(c.editable.where ? { disabled: c.editable.where(item) } : {}) }));
45
+ }, validation: { text: _vText }, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
46
46
  case "single-select":
47
- return (React.createElement(Select, { variant: "borderless", value: selectItem, options: c.editable.options, onClick: async () => await c.editable?.method?.(), onChange: (option) => {
47
+ return (React.createElement(Select, { variant: "borderless", value: selectItem, options: c.editable?.(item).options, onClick: async () => await c.editable?.(item)?.method?.(), onChange: (option) => {
48
48
  onEditable({ ...item, [key]: option?.value }, trackByValue, ExtractKey(c.key));
49
- }, validation: { text: _vText }, ...(c.editable.where ? { disabled: c.editable.where(item) } : {}) }));
49
+ }, validation: { text: _vText }, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
50
50
  case "multiple-select":
51
- return (React.createElement(Select, { variant: "borderless", value: selectItems, options: c.editable.options, onClick: async () => await c.editable?.method?.(), onChange: (options) => {
51
+ return (React.createElement(Select, { variant: "borderless", value: selectItems, options: c.editable?.(item).options, onClick: async () => await c.editable?.(item)?.method?.(), onChange: (options) => {
52
52
  onEditable({ ...item, [key]: options.map((option) => option.value) }, trackByValue, ExtractKey(c.key));
53
- }, validation: { text: _vText }, multiple: true, ...(c.editable.where ? { disabled: c.editable.where(item) } : {}) }));
53
+ }, validation: { text: _vText }, multiple: true, ...(c.editable?.(item).where ? { disabled: c.editable?.(item).where } : {}) }));
54
54
  default:
55
55
  return null;
56
56
  }
@@ -1,8 +1,9 @@
1
1
  import { INotificationLocale } from "../locales";
2
+ import IKanbanBoardLocale from "../locales/kanban-board/IKanbanBoardLocale";
2
3
  import ITableLocale from "../locales/table/ITableLocale";
3
4
  type LocaleMap = Record<string, Record<string, any>>;
4
5
  declare const useTranslation: <TBaseLocale>(currentLanguage: string | undefined, translations?: LocaleMap) => {
5
- t: (key: Extract<keyof TBaseLocale | keyof ITableLocale | keyof INotificationLocale, string>, ...args: any[]) => string;
6
+ t: (key: Extract<keyof TBaseLocale | keyof ITableLocale | keyof IKanbanBoardLocale | keyof INotificationLocale, string>, ...args: any[]) => string;
6
7
  currentLanguage: string | undefined;
7
8
  };
8
9
  export default useTranslation;
@@ -1,12 +1,14 @@
1
1
  import Utils from "../../../infrastructure/shared/Utils";
2
2
  import { NotificationEN, NotificationTR } from "../locales";
3
+ import KanbanBoardEN from "../locales/kanban-board/en";
4
+ import KanbanBoardTR from "../locales/kanban-board/tr";
3
5
  import TableEN from "../locales/table/en";
4
6
  import TableTR from "../locales/table/tr";
5
7
  const useTranslation = function (currentLanguage, translations = {}) {
6
8
  const merged = {};
7
9
  const ExtraLocales = {
8
- tr: { ...TableTR, ...NotificationTR },
9
- en: { ...TableEN, ...NotificationEN },
10
+ tr: { ...TableTR, ...KanbanBoardTR, ...NotificationTR },
11
+ en: { ...TableEN, ...KanbanBoardEN, ...NotificationEN },
10
12
  };
11
13
  const allLanguages = new Set([...Object.keys(translations), ...Object.keys(ExtraLocales)]);
12
14
  allLanguages.forEach((lang) => {
@@ -0,0 +1,5 @@
1
+ interface IKanbanBoardLocale {
2
+ "KanbanBoard.Search.Input.Placeholder": string;
3
+ "KanbanBoard.Search.Button.Clear.Text": string;
4
+ }
5
+ export default IKanbanBoardLocale;
@@ -0,0 +1,3 @@
1
+ import IKanbanBoardLocale from "./IKanbanBoardLocale";
2
+ declare const KanbanBoardEN: IKanbanBoardLocale;
3
+ export default KanbanBoardEN;
@@ -0,0 +1,5 @@
1
+ const KanbanBoardEN = {
2
+ "KanbanBoard.Search.Input.Placeholder": "Filter by keyword",
3
+ "KanbanBoard.Search.Button.Clear.Text": "Clear",
4
+ };
5
+ export default KanbanBoardEN;
@@ -0,0 +1,3 @@
1
+ import IKanbanBoardLocale from "./IKanbanBoardLocale";
2
+ declare const KanbanBoardTR: IKanbanBoardLocale;
3
+ export default KanbanBoardTR;
@@ -0,0 +1,5 @@
1
+ const KanbanBoardTR = {
2
+ "KanbanBoard.Search.Input.Placeholder": "Anahtar kelimeye göre filtrele",
3
+ "KanbanBoard.Search.Button.Clear.Text": "Temizle",
4
+ };
5
+ export default KanbanBoardTR;
@@ -35,11 +35,11 @@ export type TableColumnType<T> = {
35
35
  filters?: Option[];
36
36
  filterDataType?: FilterDataType;
37
37
  render?: (item: T) => React.ReactNode;
38
- editable?: {
38
+ editable?: (item: T) => {
39
39
  type: "string" | "number" | "decimal" | "input-formatted-decimal" | "date-picker" | "single-select" | "multiple-select";
40
40
  options?: Option[];
41
41
  method?: () => void | Promise<void>;
42
- where?: (item: T) => boolean;
42
+ where?: boolean;
43
43
  };
44
44
  config?: {
45
45
  width?: number | "auto" | "fit-content" | "max-content" | "min-content";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.4.42",
3
+ "version": "0.4.44",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",