@apia/table 0.2.4 → 0.3.2

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.
package/dist/index.js CHANGED
@@ -6,9 +6,10 @@ import { uniqueId } from 'lodash-es';
6
6
  import { createSlice, injectReducers, shallowEqual as shallowEqual$1 } from '@apia/store';
7
7
  import { addBoundary, useLatest, useUpdateEffect, getSpecificParent, isChild, autoDisconnectMutationObserver, getFocusSelector, cantFocusSelector, globalFocus, scrollParentIntoElement, customEvents, debugDispatcher, persistentStorage, EventEmitter, downloadUrl, arrayOrArray, useMount as useMount$1, getDateFormat } from '@apia/util';
8
8
  import { shallowEqual } from 'react-redux';
9
- import { useOtherTagButton, ApiaFilter, IconButton, AccordionItem, Accordion } from '@apia/components';
9
+ import { useOtherTagButton, AutoEllipsis, ApiaFilter, IconButton, AccordionItem, Accordion } from '@apia/components';
10
10
  import { Icon } from '@apia/icons';
11
- import { FaSortUp, FaSortDown, FaSort, FaMinusSquare, FaPlusSquare, FaSquare } from '@meronex/icons/fa';
11
+ import { FaSortUp, FaSortDown, FaSort, FaSquare } from '@meronex/icons/fa';
12
+ import { MdKeyboardArrowDown, MdKeyboardArrowRight } from '@meronex/icons/md/';
12
13
  import dayjs from 'dayjs';
13
14
 
14
15
  const defaultLabels = {
@@ -372,7 +373,7 @@ function makeKeyHandler(actions, id, config) {
372
373
  )
373
374
  );
374
375
  const selectedRowsRef = useLatest(selectedRows);
375
- const focusedRow = useResponsiveTable((global) => {
376
+ useResponsiveTable((global) => {
376
377
  var _a3;
377
378
  const state = config.stateSelector(global);
378
379
  return (_a3 = state == null ? void 0 : state.focusedRow) != null ? _a3 : -1;
@@ -445,9 +446,12 @@ function makeKeyHandler(actions, id, config) {
445
446
  return;
446
447
  ev.preventDefault();
447
448
  if (onSelectRows)
448
- onSelectRows(selectedRowsRef.current, focusedRow);
449
+ onSelectRows(
450
+ selectedRowsRef.current,
451
+ config.stateSelector(responsiveTableStore.getState()).focusedRow
452
+ );
449
453
  },
450
- [focusedRow, onSelectRows, selectedRowsRef]
454
+ [onSelectRows, selectedRowsRef]
451
455
  );
452
456
  const initialized = React.useRef(true);
453
457
  const running = React.useRef(false);
@@ -654,12 +658,12 @@ function makeKeyHandler(actions, id, config) {
654
658
  if (props.onKeyDown)
655
659
  props.onKeyDown(ev);
656
660
  if (ev.key === "Enter" && onSelectRows && state.focusedRow >= 0) {
657
- onSelectRows(currentSelectedRows, focusedRow);
661
+ onSelectRows(currentSelectedRows, state.focusedRow);
658
662
  }
659
663
  keyHandler(ev);
660
664
  }
661
665
  },
662
- [allowKeyboardSorting, focusedRow, keyHandler, onSelectRows, props]
666
+ [allowKeyboardSorting, keyHandler, onSelectRows, props]
663
667
  ),
664
668
  children
665
669
  })
@@ -1404,14 +1408,28 @@ const NoMemoHeaderCell = ({
1404
1408
  role: "rowheader",
1405
1409
  className: `${isFilterRequired && window.SHOW_REQUIRED_POSITION ? "requiredFilterColumn" : ""}`,
1406
1410
  children: /* @__PURE__ */ jsxs(Box, { as: "span", className: "headButton__container", children: [
1407
- /* @__PURE__ */ jsx(Box, { as: "span", className: "headButton__label", children: /* @__PURE__ */ jsx(
1411
+ /* @__PURE__ */ jsx(
1408
1412
  Box,
1409
1413
  {
1410
1414
  as: "span",
1411
- className: `${isFilterRequired ? "requiredFilter__Column" : ""}`,
1412
- children: column.label
1415
+ className: `${isFilterRequired ? "requiredFilter__Column" : ""} headButton__label`,
1416
+ children: /* @__PURE__ */ jsx(
1417
+ AutoEllipsis,
1418
+ {
1419
+ overrideStyles: (el) => {
1420
+ const th = el.closest("th");
1421
+ return {
1422
+ width: `${Math.max(
1423
+ 100,
1424
+ Number.parseInt(window.getComputedStyle(th).width)
1425
+ )}px`
1426
+ };
1427
+ },
1428
+ children: column.label
1429
+ }
1430
+ )
1413
1431
  }
1414
- ) }),
1432
+ ),
1415
1433
  /* @__PURE__ */ jsxs(Box, { as: "span", className: "headButton__sortIcon", children: [
1416
1434
  column.allowSorting !== false && column.currentSorting === "A" && /* @__PURE__ */ jsx(FaSortUp, {}),
1417
1435
  column.allowSorting !== false && column.currentSorting === "D" && /* @__PURE__ */ jsx(FaSortDown, {}),
@@ -2029,7 +2047,8 @@ const NoMemoDefaultCellRenderer = React.forwardRef(
2029
2047
  () => ({
2030
2048
  "&.colored": {
2031
2049
  background: cell.background,
2032
- color: cell.color
2050
+ color: cell.color,
2051
+ fontWeight: "bold"
2033
2052
  }
2034
2053
  }),
2035
2054
  [cell.background, cell.color]
@@ -2037,7 +2056,18 @@ const NoMemoDefaultCellRenderer = React.forwardRef(
2037
2056
  ref: currentRef
2038
2057
  }, props), cell), {
2039
2058
  "aria-label": ariaLabel,
2040
- children: (_a2 = props.children) != null ? _a2 : cell.children
2059
+ children: /* @__PURE__ */ jsx(
2060
+ AutoEllipsis,
2061
+ {
2062
+ overrideStyles: (el) => {
2063
+ const td = el.closest("td");
2064
+ return {
2065
+ width: window.getComputedStyle(td).width
2066
+ };
2067
+ },
2068
+ children: (_a2 = props.children) != null ? _a2 : cell.children
2069
+ }
2070
+ )
2041
2071
  })
2042
2072
  );
2043
2073
  }
@@ -2290,8 +2320,10 @@ const NoMemoRow = ({ rowIndex }) => {
2290
2320
  ) : /* @__PURE__ */ jsxs(Fragment, { children: [
2291
2321
  (additionalCells.length > 0 || hasNonAdditionalFilters) && /* @__PURE__ */ jsx("td", __spreadProps$7(__spreadValues$8({ className: "additionalInfo__cell" }, additionalCellDomProps), { children: additionalCells.length > 0 && /* @__PURE__ */ jsx(
2292
2322
  IconButton,
2293
- __spreadProps$7(__spreadValues$8({}, getVariant("icon-outline")), {
2294
- icon: isExpanded ? FaMinusSquare : FaPlusSquare,
2323
+ __spreadProps$7(__spreadValues$8({
2324
+ size: "Lg"
2325
+ }, getVariant("icon-outline")), {
2326
+ icon: isExpanded ? MdKeyboardArrowDown : MdKeyboardArrowRight,
2295
2327
  "aria-label": isExpanded ? window.LBL_COLLAPSE_ROW : window.LBL_EXPAND_ROW,
2296
2328
  className: "moreInformationButton",
2297
2329
  onClick: handleExpandedState
@@ -2466,6 +2498,9 @@ const NoMemoAccordionElement = ({ row, rowIndex }) => {
2466
2498
  const isSelected = useResponsiveTable(
2467
2499
  (global) => global.responsiveTableSlice[name].allowSelection !== false ? global.responsiveTableSlice[name].selectedRows.includes(rowIndex) : void 0
2468
2500
  );
2501
+ const isFocused = useResponsiveTable(
2502
+ (global) => global.responsiveTableSlice[name].focusedRow === rowIndex
2503
+ );
2469
2504
  const buttonProps = useMemo(
2470
2505
  () => ({
2471
2506
  title,
@@ -2484,9 +2519,10 @@ const NoMemoAccordionElement = ({ row, rowIndex }) => {
2484
2519
  )
2485
2520
  })
2486
2521
  );
2487
- }
2522
+ },
2523
+ tabIndex: isFocused ? 0 : -1
2488
2524
  }),
2489
- [isSelected, name, rowIndex, title]
2525
+ [isFocused, isSelected, name, rowIndex, title]
2490
2526
  );
2491
2527
  if (!Array.isArray(indexColumns) || !columns)
2492
2528
  return null;
@@ -2525,7 +2561,6 @@ const NoMemoAccordionElement = ({ row, rowIndex }) => {
2525
2561
  };
2526
2562
  const AccordionElement = memo(NoMemoAccordionElement);
2527
2563
 
2528
- const isDebugging = false;
2529
2564
  const NoMemoAccordionRenderer = () => {
2530
2565
  const { name } = useResponsiveTableContext();
2531
2566
  const { columns, rows } = useResponsiveTable((global) => {
@@ -2553,7 +2588,7 @@ const NoMemoAccordionRenderer = () => {
2553
2588
  const columnsLength = columns.length;
2554
2589
  let indexColumn = null;
2555
2590
  let currentIndex = 0;
2556
- while (!indexColumn && !isDebugging && currentIndex < columns.length || isDebugging ) {
2591
+ while (!indexColumn && currentIndex < columns.length) {
2557
2592
  let isAnyEmptyRow = false;
2558
2593
  for (const row of rows) {
2559
2594
  if (!row.cells[currentIndex].children) {
@@ -2586,14 +2621,7 @@ const NoMemoAccordionRenderer = () => {
2586
2621
  }, [columns, name, rows]);
2587
2622
  return /* @__PURE__ */ jsxs(Accordion, { children: [
2588
2623
  !rows || rows.length === 0 && /* @__PURE__ */ jsx(NoRegistersRenderer, {}),
2589
- rows == null ? void 0 : rows.slice(0, void 0).map((current, rowIndex) => /* @__PURE__ */ jsx(
2590
- AccordionElement,
2591
- {
2592
- row: current,
2593
- rowIndex
2594
- },
2595
- current.id
2596
- ))
2624
+ rows == null ? void 0 : rows.map((current, rowIndex) => /* @__PURE__ */ jsx(AccordionElement, { row: current, rowIndex }, current.id))
2597
2625
  ] });
2598
2626
  };
2599
2627
  const AccordionRenderer = React.memo(NoMemoAccordionRenderer);