ar-design 0.2.32 → 0.2.34

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.
@@ -157,4 +157,24 @@
157
157
  text-wrap: nowrap;
158
158
  }
159
159
 
160
+ .ar-table > .content > table > tbody > tr > td > span.subitem-open-button {
161
+ display: inline-block;
162
+ width: 0.75rem;
163
+ height: 0.75rem;
164
+ border: solid 2px transparent;
165
+ border-top-color: var(--primary);
166
+ border-right-color: var(--primary);
167
+ transform: rotate(45deg);
168
+ cursor: pointer;
169
+ transition: transform 100ms ease-in-out;
170
+ }
171
+ .ar-table > .content > table > tbody > tr > td > span.subitem-open-button.opened {
172
+ transform: rotate(135deg);
173
+ }
174
+ .ar-table > .content > table > tbody > tr > td > span.subitem-open-button.passive {
175
+ border-top-color: var(--gray-300);
176
+ border-right-color: var(--gray-300);
177
+ cursor: no-drop;
178
+ }
179
+
160
180
  @import url("./scroll.css");
@@ -1,88 +1,88 @@
1
1
  /* #region Border Color -> PRIMARY */
2
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.primary {
2
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.primary {
3
3
  box-shadow: 0 0 0 2.5px rgba(var(--primary-rgb), .1);
4
4
  }
5
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.primary > .handle {
5
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.primary > .handle {
6
6
  box-shadow: 0 0 0 2px rgba(var(--primary-rgb), .5);
7
7
  }
8
8
  /* #endregion */
9
9
  /* Border Color -> PRIMARY */
10
10
 
11
11
  /* #region Border Color -> PRIMARY-LIGHT */
12
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.primary-light {
12
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.primary-light {
13
13
  box-shadow: 0 0 0 2.5px rgba(var(--primary-light-rgb), .1);
14
14
  }
15
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.primary-light > .handle {
15
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.primary-light > .handle {
16
16
  box-shadow: 0 0 0 2px rgba(var(--primary-light-rgb), .5);
17
17
  }
18
18
  /* #endregion */
19
19
  /* Border Color -> PRIMARY-LIGHT */
20
20
 
21
21
  /* #region Border Color -> SECONDARY */
22
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.secondary {
22
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.secondary {
23
23
  box-shadow: 0 0 0 2.5px rgba(var(--secondary-rgb), .1);
24
24
  }
25
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.secondary > .handle {
25
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.secondary > .handle {
26
26
  box-shadow: 0 0 0 2px rgba(var(--secondary-rgb), .5);
27
27
  }
28
28
  /* #endregion */
29
29
  /* Border Color -> SECONDARY */
30
30
 
31
31
  /* #region Border Color -> SUCCESS */
32
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.success {
32
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.success {
33
33
  box-shadow: 0 0 0 2.5px rgba(var(--success-rgb), .1);
34
34
  }
35
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.success > .handle {
35
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.success > .handle {
36
36
  box-shadow: 0 0 0 2px rgba(var(--success-rgb), .5);
37
37
  }
38
38
  /* #endregion */
39
39
  /* Border Color -> SUCCESS */
40
40
 
41
41
  /* #region Border Color -> WARNING */
42
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.warning {
42
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.warning {
43
43
  box-shadow: 0 0 0 2.5px rgba(var(--warning-rgb), .1);
44
44
  }
45
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.warning > .handle {
45
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.warning > .handle {
46
46
  box-shadow: 0 0 0 2px rgba(var(--warning-rgb), .5);
47
47
  }
48
48
  /* #endregion */
49
49
  /* Border Color -> WARNING */
50
50
 
51
51
  /* #region Border Color -> DANGER */
52
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.danger {
52
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.danger {
53
53
  box-shadow: 0 0 0 2.5px rgba(var(--danger-rgb), .1);
54
54
  }
55
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.danger > .handle {
55
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.danger > .handle {
56
56
  box-shadow: 0 0 0 2px rgba(var(--danger-rgb), .5);
57
57
  }
58
58
  /* #endregion */
59
59
  /* Border Color -> DANGER */
60
60
 
61
61
  /* #region Border Color -> INFORMATION */
62
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.information {
62
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.information {
63
63
  box-shadow: 0 0 0 2.5px rgba(var(--information-rgb), .1);
64
64
  }
65
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.information > .handle {
65
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.information > .handle {
66
66
  box-shadow: 0 0 0 2px rgba(var(--information-rgb), .5);
67
67
  }
68
68
  /* #endregion */
69
69
  /* Border Color -> INFORMATION */
70
70
 
71
71
  /* #region Border Color -> DARK */
72
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.dark {
72
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.dark {
73
73
  box-shadow: 0 0 0 2.5px rgba(var(--dark-rgb), .1);
74
74
  }
75
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.dark > .handle {
75
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.dark > .handle {
76
76
  box-shadow: 0 0 0 2px rgba(var(--dark-rgb), .5);
77
77
  }
78
78
  /* #endregion */
79
79
  /* Border Color -> DARK */
80
80
 
81
81
  /* #region Border Color -> LIGHT */
82
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.light {
82
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.light {
83
83
  box-shadow: 0 0 0 2.5px rgba(var(--light-rgb), .1);
84
84
  }
85
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch.light > .handle {
85
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch.light > .handle {
86
86
  box-shadow: 0 0 0 2px rgba(var(--light-rgb), .5);
87
87
  }
88
88
  /* #endregion */
@@ -14,7 +14,7 @@
14
14
  /* width: 100%; */
15
15
  user-select: none;
16
16
  }
17
- .ar-switch-wrapper > label > :is(input[type="checkbox"]) {
17
+ .ar-switch-wrapper > label > input[type="checkbox"] {
18
18
  display: none;
19
19
  }
20
20
 
@@ -26,7 +26,7 @@
26
26
  transition: box-shadow 250ms ease-in-out;
27
27
  }
28
28
 
29
- .ar-switch-wrapper > label > :is(input[type="checkbox"]) + .ar-switch > .handle {
29
+ .ar-switch-wrapper > label > input[type="checkbox"] + .ar-switch > .handle {
30
30
  position: absolute;
31
31
  top: 50%;
32
32
  left: 0.15rem;
@@ -38,7 +38,7 @@
38
38
  height: 0.75rem;
39
39
  transition: left 150ms, width 150ms 150ms, height 150ms 150ms, box-shadow 150ms 150ms ease-in-out;
40
40
  }
41
- .ar-switch-wrapper > label > :is(input[type="checkbox"]):checked + .ar-switch > .handle {
41
+ .ar-switch-wrapper > label > input[type="checkbox"].checked + .ar-switch > .handle {
42
42
  left: calc(2.25rem - 0.9rem);
43
43
  width: 1rem;
44
44
  height: 1rem;
@@ -36,6 +36,7 @@ interface IProps<T> extends IChildren {
36
36
  scroll?: {
37
37
  maxHeight: number;
38
38
  };
39
+ subrowSelector?: string;
39
40
  };
40
41
  }
41
42
  export default IProps;
@@ -9,7 +9,7 @@ import Input from "../../form/input";
9
9
  import Popover from "../../feedback/popover";
10
10
  import Utils from "../../../libs/infrastructure/shared/Utils";
11
11
  import Upload from "../../form/upload";
12
- const Table = forwardRef(({ children, title, description, data, columns, actions, selections, previousSelections, searchedParams, pagination, config = { isSearchable: false }, }, ref) => {
12
+ const Table = forwardRef(({ children, title, description, data, columns, actions, selections, previousSelections, searchedParams, pagination, config = { isSearchable: false, subrowSelector: "subitems" }, }, ref) => {
13
13
  // refs
14
14
  const _tableWrapper = useRef(null);
15
15
  const _tableContent = useRef(null);
@@ -23,6 +23,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
23
23
  // states
24
24
  const [selectAll, setSelectAll] = useState(false);
25
25
  const [selectionItems, setSelectionItems] = useState([]);
26
+ const [showSubitems, setShowSubitems] = useState({});
26
27
  // states -> File
27
28
  const [files, setFiles] = useState([]);
28
29
  const [formData, setFormData] = useState(undefined);
@@ -140,7 +141,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
140
141
  };
141
142
  });
142
143
  }, []);
143
- // Derinlemesine arama yapmak için özyinelemeli bir fonksiyon tanımlayalım.
144
+ // Derinlemesine arama yapmak için özyinelemeli bir fonksiyon olarak kullanılmaktadır.
144
145
  const deepSearch = (item, searchedText) => {
145
146
  if (!searchedText || Object.keys(searchedText).length === 0)
146
147
  return true;
@@ -190,6 +191,69 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
190
191
  setTimeout(() => handleScroll(), 0);
191
192
  return _data;
192
193
  }, [data, searchedText, currentPage]);
194
+ const renderCell = (item, c, cIndex, index) => {
195
+ let render;
196
+ // `c.key` bir string ise
197
+ if (typeof c.key !== "object") {
198
+ render = c.render ? c.render(item) : item[c.key];
199
+ }
200
+ // `c.key` bir nesne ise ve `nestedKey` mevcutsa
201
+ else if (typeof c.key === "object") {
202
+ const _item = item[c.key.field];
203
+ if (_item && typeof _item === "object") {
204
+ render = c.render ? c.render(item) : _item[c.key.nestedKey];
205
+ }
206
+ }
207
+ // Diğer durumlarda `null` döndür
208
+ else {
209
+ render = null;
210
+ }
211
+ const _className = [];
212
+ if (c.config?.sticky)
213
+ _className.push(`sticky-${c.config.sticky}`);
214
+ if (c.config?.alignContent)
215
+ _className.push(`align-content-${c.config.alignContent}`);
216
+ if (c.config?.textWrap)
217
+ _className.push(`text-${c.config.textWrap}`);
218
+ return (React.createElement("td", { key: `cell-${index}-${cIndex}`, className: _className.join(" "), style: c.config?.width ? { minWidth: c.config.width, maxWidth: c.config.width } : {}, "data-sticky-position": c.config?.sticky }, React.isValidElement(render) ? render : String(render)));
219
+ };
220
+ const renderRow = (item, index) => {
221
+ return (React.createElement(React.Fragment, null,
222
+ React.createElement("tr", { key: `row-${index}` },
223
+ selections && (React.createElement("td", { className: "sticky-left", "data-sticky-position": "left" },
224
+ React.createElement(Checkbox, { ref: (element) => (_checkboxItems.current[index] = element), status: "primary", checked: selectionItems.some((selectionItem) => JSON.stringify(selectionItem) === JSON.stringify(item)), onChange: (event) => {
225
+ if (event.target.checked)
226
+ setSelectionItems((prev) => [...prev, item]);
227
+ else
228
+ setSelectionItems((prev) => prev.filter((_item) => _item !== item));
229
+ } }))),
230
+ data.some((item) => config.subrowSelector ?? "subitems" in item) && (React.createElement("td", { style: { width: 1 } }, item[config.subrowSelector] && (React.createElement("span", { className: `subitem-open-button ${showSubitems[index] && "opened"}`, onClick: () => {
231
+ setShowSubitems((prev) => ({
232
+ ...prev,
233
+ [`${index}`]: !prev[`${index}`],
234
+ }));
235
+ } })))),
236
+ columns.map((c, cIndex) => renderCell(item, c, cIndex, index))),
237
+ showSubitems[index] && item[config.subrowSelector] && (React.createElement(SubitemList, { items: item[config.subrowSelector], columns: columns, index: index, depth: 1.5 }))));
238
+ };
239
+ const SubitemList = ({ items, columns, index, depth }) => {
240
+ return items.map((subitem, subindex) => {
241
+ const x = subitem[config.subrowSelector];
242
+ return (React.createElement(React.Fragment, null,
243
+ React.createElement("tr", { key: `subitem-${index}-${subindex}` },
244
+ data.some((item) => config.subrowSelector ?? "subitems" in item) && (React.createElement("td", { style: { paddingLeft: `${depth * 1.5}rem` } },
245
+ React.createElement("span", { className: `subitem-open-button ${showSubitems[`${index}.${subindex}`] && "opened"} ${!x && "passive"}`, onClick: () => {
246
+ if (!x)
247
+ return;
248
+ setShowSubitems((prev) => ({
249
+ ...prev,
250
+ [`${index}.${subindex}`]: !prev[`${index}.${subindex}`],
251
+ }));
252
+ } }))),
253
+ columns.map((c, cIndex) => renderCell(subitem, c, cIndex, subindex))),
254
+ showSubitems[`${index}.${subindex}`] && x && (React.createElement(SubitemList, { items: x, columns: columns, index: subindex, depth: depth * 1.5 }))));
255
+ });
256
+ };
193
257
  // useEffects
194
258
  useEffect(() => {
195
259
  // Eğer `previousSelections` özelliğinden değer geliyorsa bu daha önce seçim yapılmış öğeleri gönderiyorum
@@ -252,6 +316,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
252
316
  React.createElement("table", { ref: ref },
253
317
  React.createElement("thead", null,
254
318
  React.createElement("tr", { key: "selection" },
319
+ data.some((item) => config.subrowSelector ?? "subitems" in item) && React.createElement("td", { style: { width: 1 } }),
255
320
  selections && (React.createElement("th", { className: "selection-col sticky-left", "data-sticky-position": "left" },
256
321
  React.createElement(Checkbox, { variant: "filled", status: "primary", checked: selectAll, onChange: (event) => {
257
322
  if (_checkboxItems.current.length > 0) {
@@ -306,53 +371,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
306
371
  })), windowBlur: true },
307
372
  React.createElement(Button, { variant: "borderless", icon: { element: React.createElement(ARIcon, { icon: "Filter", stroke: "var(--primary)", size: 16 }) } })))))));
308
373
  })))),
309
- React.createElement("tbody", null, getData.map((item, index) => (React.createElement("tr", { key: `row-${index}-${Math.random()}` },
310
- selections && (React.createElement("td", { key: `selection-${index}`, className: "sticky-left", "data-sticky-position": "left" },
311
- React.createElement(Checkbox, { ref: (element) => (_checkboxItems.current[index] = element), status: "primary", checked: selectionItems.some((selectionItem) => JSON.stringify(selectionItem) === JSON.stringify(item)), onChange: (event) => {
312
- if (event.target.checked)
313
- setSelectionItems((prev) => [...prev, item]);
314
- else
315
- setSelectionItems((prev) => prev.filter((_item) => _item !== item));
316
- } }))),
317
- columns.map((c, cIndex) => {
318
- let _className = [];
319
- let render; // TODO: Generic yapmak için çalışma yap. (Daha Sonra)
320
- // `c.key` bir string ise
321
- if (typeof c.key !== "object") {
322
- render = c.render ? c.render(item) : item[c.key];
323
- }
324
- // `c.key` bir nesne ise ve `nestedKey` mevcutsa
325
- else if (typeof c.key === "object") {
326
- const _item = item[c.key.field];
327
- if (_item && typeof _item === "object") {
328
- render = c.render ? c.render(item) : _item[c.key.nestedKey];
329
- }
330
- }
331
- // Diğer durumlarda `null` döndür
332
- else {
333
- render = null;
334
- }
335
- if (c.config?.sticky)
336
- _className.push(`sticky-${c.config.sticky}`);
337
- if (c.config?.alignContent)
338
- _className.push(`align-content-${c.config.alignContent}`);
339
- if (c.config?.textWrap)
340
- _className.push(`text-${c.config.textWrap}`);
341
- return (React.createElement("td", { key: `cell-${index}-${cIndex}`, ...(_className.length > 0 && {
342
- className: `${_className.map((c) => c).join(" ")}`,
343
- }), ...(c.config?.width
344
- ? {
345
- style: { minWidth: c.config.width, maxWidth: c.config.width },
346
- }
347
- : // : {
348
- // style: { maxWidth: thWidths[cIndex], minWidth: thWidths[cIndex] },
349
- // })}
350
- {
351
- style: {},
352
- }), ...(c.config?.sticky && {
353
- "data-sticky-position": c.config.sticky,
354
- }) }, React.isValidElement(render) ? render : String(render)));
355
- }))))))),
374
+ React.createElement("tbody", null, getData.map((item, index) => (React.createElement(React.Fragment, { key: index }, renderRow(item, index))))))),
356
375
  pagination && pagination.totalRecords > pagination.perPage && (React.createElement("div", { className: "footer" },
357
376
  React.createElement("span", null,
358
377
  React.createElement("strong", null,
@@ -5,9 +5,11 @@ import Utils from "../../../libs/infrastructure/shared/Utils";
5
5
  const Switch = ({ label, status = "primary", border = { radius: "pill" }, ...attributes }) => {
6
6
  // refs
7
7
  let _switch = useRef(null);
8
+ const _inputClassName = [];
8
9
  const _switchClassName = ["ar-switch"];
9
10
  // states
10
11
  const [checked, setChecked] = useState(attributes.checked ?? false);
12
+ _inputClassName.push(attributes.checked ? "checked" : "unchecked");
11
13
  _switchClassName.push(...Utils.GetClassName("filled", attributes.checked ? status : "light", border, undefined, undefined, attributes.className));
12
14
  // useEffects
13
15
  useEffect(() => {
@@ -15,7 +17,7 @@ const Switch = ({ label, status = "primary", border = { radius: "pill" }, ...att
15
17
  }, [attributes.checked]);
16
18
  return (React.createElement("div", { className: "ar-switch-wrapper" },
17
19
  React.createElement("label", null,
18
- React.createElement("input", { type: "checkbox", ...attributes, checked: checked, size: 0, onChange: (event) => {
20
+ React.createElement("input", { type: "checkbox", ...attributes, className: _inputClassName.map((c) => c).join(" "), checked: checked, size: 0, onChange: (event) => {
19
21
  event.stopPropagation();
20
22
  (() => {
21
23
  setChecked(event.target.checked);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.2.32",
3
+ "version": "0.2.34",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",