@majoo-ui/react 1.60.8 → 1.60.9

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,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Column, Row } from 'react-table';
2
+ import { Column, Row, SortingRule } from 'react-table';
3
3
  import { CSS } from '../../config/stitches.config';
4
4
  import { EmptyDataProps } from '../table/Table';
5
5
  interface CustomRows {
@@ -84,6 +84,10 @@ interface EditableTableProps<Data extends object> {
84
84
  * Activate table row virtualizer support
85
85
  */
86
86
  virtualized?: boolean;
87
+ /**
88
+ * Sort by changes callback
89
+ */
90
+ onSortByChange?: (sortBy: SortingRule<object>[]) => void;
87
91
  }
88
92
  interface RemoveProps {
89
93
  position?: 'leftBottom' | 'rightBottom' | 'leftTop' | 'rightTop';
package/index.esm.js CHANGED
@@ -33553,6 +33553,9 @@ function EditableTableMobile(props) {
33553
33553
  toggleAllRowsExpanded,
33554
33554
  setHiddenColumns
33555
33555
  } = instance;
33556
+ const {
33557
+ t
33558
+ } = useTranslation('MajooUI/table');
33556
33559
  useEffect(() => {
33557
33560
  if (hiddenColumns === null || hiddenColumns === void 0 ? void 0 : hiddenColumns.length) {
33558
33561
  setHiddenColumns(hiddenColumns);
@@ -33722,17 +33725,41 @@ function EditableTableMobile(props) {
33722
33725
  }), visibleHeaders.map((column, index) => {
33723
33726
  const isMobileHeader = column === null || column === void 0 ? void 0 : column.isMobileHeader;
33724
33727
  const isSelector = (column === null || column === void 0 ? void 0 : column.id) === 'selection';
33725
- return (isMobileHeader || isSelector) && /*#__PURE__*/createElement$2(TableHeadCell$2, Object.assign({}, column.getHeaderProps({
33728
+ const headerRender = column.render('Header');
33729
+ return (isMobileHeader || isSelector) && /*#__PURE__*/createElement$2(TableHeadCell$2, Object.assign({}, column.getHeaderProps(props => [props, column.sortable ? column.getSortByToggleProps({
33730
+ title: t('sortColumnTitle', 'Urutkan') || 'Urutkan'
33731
+ }) : {
33732
+ onClick: column.onToggle
33733
+ }, {
33726
33734
  style: {
33727
33735
  minWidth: column.minWidth,
33728
33736
  width: isSelector ? 10 : column.width,
33729
33737
  maxWidth: isSelector ? 10 : column.maxWidth
33730
33738
  }
33731
- }), {
33739
+ }]), {
33732
33740
  key: `head-cell-${index}`
33733
- }), column.render('Header'), (column === null || column === void 0 ? void 0 : column.isRequired) ? jsx(Required$2, {
33734
- children: "*"
33735
- }, void 0) : '');
33741
+ }), typeof headerRender === 'string' ? jsx(TableHeaderCellContainer, Object.assign({
33742
+ isMobile: true,
33743
+ isSortedDesc: column.isSortedDesc,
33744
+ unsortable: !column.sortable,
33745
+ isToggleable: !!column.onToggle,
33746
+ isToggled: column.isToggled,
33747
+ css: {
33748
+ padding: 0
33749
+ }
33750
+ }, {
33751
+ children: jsxs(TableHeadCellContent, Object.assign({
33752
+ heading: "headerTable"
33753
+ }, {
33754
+ children: [headerRender.toUpperCase(), (column === null || column === void 0 ? void 0 : column.isRequired) ? jsx(Required$2, {
33755
+ children: "*"
33756
+ }, void 0) : '']
33757
+ }), void 0)
33758
+ }), void 0) : jsxs(Fragment, {
33759
+ children: [headerRender, (column === null || column === void 0 ? void 0 : column.isRequired) ? jsx(Required$2, {
33760
+ children: "*"
33761
+ }, void 0) : '']
33762
+ }, void 0));
33736
33763
  }));
33737
33764
  })
33738
33765
  }, void 0), jsxs(TableBody$2, Object.assign({}, getTableBodyProps(), {
@@ -51280,7 +51307,8 @@ function EditableTable(props) {
51280
51307
  isMobileLayout,
51281
51308
  hiddenColumns,
51282
51309
  customEmptyDataProps: emptyDataProps,
51283
- virtualized = false
51310
+ virtualized = false,
51311
+ onSortByChange
51284
51312
  } = props;
51285
51313
  const {
51286
51314
  t
@@ -51314,8 +51342,10 @@ function EditableTable(props) {
51314
51342
  data,
51315
51343
  initialState: getInitialState(),
51316
51344
  autoResetExpanded: false,
51317
- getRowId: row => row[keyId] || JSON.stringify(row)
51318
- }, useExpanded, useRowSelect, hooks => {
51345
+ getRowId: row => row[keyId] || JSON.stringify(row),
51346
+ defaultCanSort: false,
51347
+ autoResetSortBy: false
51348
+ }, useSortBy, useExpanded, useRowSelect, hooks => {
51319
51349
  showCheckbox && hooks.visibleColumns.push(columns => {
51320
51350
  return [{
51321
51351
  id: 'selection',
@@ -51342,7 +51372,8 @@ function EditableTable(props) {
51342
51372
  visibleColumns,
51343
51373
  setHiddenColumns,
51344
51374
  state: {
51345
- selectedRowIds
51375
+ selectedRowIds,
51376
+ sortBy
51346
51377
  }
51347
51378
  } = instance;
51348
51379
  const tableContainerRef = useRef(null);
@@ -51424,6 +51455,11 @@ function EditableTable(props) {
51424
51455
  }), void 0);
51425
51456
  };
51426
51457
  const tableRowData = virtualized ? virtualRows : rows;
51458
+ useEffect(() => {
51459
+ if (onSortByChange) {
51460
+ onSortByChange(sortBy);
51461
+ }
51462
+ }, [sortBy]);
51427
51463
  return !isMobile ? jsx(TableContainer$1, Object.assign({
51428
51464
  ref: tableContainerRef,
51429
51465
  css: props === null || props === void 0 ? void 0 : props.css
@@ -51436,17 +51472,42 @@ function EditableTable(props) {
51436
51472
  return !(column === null || column === void 0 ? void 0 : column.isSubRow) && (typeof (column === null || column === void 0 ? void 0 : column.hidden) === 'boolean' ? !(column === null || column === void 0 ? void 0 : column.hidden) : !((_a = column === null || column === void 0 ? void 0 : column.hidden) === null || _a === void 0 ? void 0 : _a.call(column, column)));
51437
51473
  });
51438
51474
  return jsx(TableHeadRow$1, Object.assign({}, headerGroup.getHeaderGroupProps(), {
51439
- children: visibleHeaders.map(column => !(column === null || column === void 0 ? void 0 : column.isMobileOnly) && jsxs(TableHeadCell$1, Object.assign({}, column.getHeaderProps({
51440
- style: {
51441
- minWidth: column.minWidth,
51442
- width: column.width,
51443
- maxWidth: column.maxWidth
51444
- }
51445
- }), {
51446
- children: [column.render('Header'), (column === null || column === void 0 ? void 0 : column.isRequired) ? jsx(Required$1, {
51447
- children: "*"
51448
- }, void 0) : '']
51449
- }), void 0))
51475
+ children: visibleHeaders.map(column => {
51476
+ const headerRender = column.render('Header');
51477
+ return !(column === null || column === void 0 ? void 0 : column.isMobileOnly) && jsx(TableHeadCell$1, Object.assign({}, column.getHeaderProps(props => [props, column.sortable ? column.getSortByToggleProps({
51478
+ title: t('sortColumnTitle', 'Urutkan') || 'Urutkan'
51479
+ }) : {
51480
+ onClick: column.onToggle
51481
+ }, {
51482
+ style: {
51483
+ minWidth: column.minWidth,
51484
+ width: column.width,
51485
+ maxWidth: column.maxWidth
51486
+ }
51487
+ }]), {
51488
+ children: typeof headerRender === 'string' ? jsx(TableHeaderCellContainer, Object.assign({
51489
+ isSortedDesc: column.isSortedDesc,
51490
+ unsortable: !column.sortable,
51491
+ isToggleable: !!column.onToggle,
51492
+ isToggled: column.isToggled,
51493
+ css: {
51494
+ padding: 0
51495
+ }
51496
+ }, {
51497
+ children: jsxs(TableHeadCellContent, Object.assign({
51498
+ heading: "headerTable"
51499
+ }, {
51500
+ children: [headerRender.toUpperCase(), (column === null || column === void 0 ? void 0 : column.isRequired) ? jsx(Required$1, {
51501
+ children: "*"
51502
+ }, void 0) : '']
51503
+ }), void 0)
51504
+ }), void 0) : jsxs(Fragment, {
51505
+ children: [headerRender, (column === null || column === void 0 ? void 0 : column.isRequired) ? jsx(Required$1, {
51506
+ children: "*"
51507
+ }, void 0) : '']
51508
+ }, void 0)
51509
+ }), void 0);
51510
+ })
51450
51511
  }), void 0);
51451
51512
  })
51452
51513
  }, void 0), jsxs(TableBody$1, Object.assign({}, getTableBodyProps(), {
package/index.umd.js CHANGED
@@ -34043,6 +34043,7 @@
34043
34043
  state = instance.state,
34044
34044
  toggleAllRowsExpanded = instance.toggleAllRowsExpanded,
34045
34045
  setHiddenColumns = instance.setHiddenColumns;
34046
+ var t = reactI18next.useTranslation('MajooUI/table').t;
34046
34047
  React.useEffect(function () {
34047
34048
  if (hiddenColumns === null || hiddenColumns === void 0 ? void 0 : hiddenColumns.length) {
34048
34049
  setHiddenColumns(hiddenColumns);
@@ -34213,17 +34214,43 @@
34213
34214
  }), visibleHeaders.map(function (column, index) {
34214
34215
  var isMobileHeader = column === null || column === void 0 ? void 0 : column.isMobileHeader;
34215
34216
  var isSelector = (column === null || column === void 0 ? void 0 : column.id) === 'selection';
34216
- return (isMobileHeader || isSelector) && /*#__PURE__*/React.createElement(TableHeadCell$2, __assign({}, column.getHeaderProps({
34217
- style: {
34218
- minWidth: column.minWidth,
34219
- width: isSelector ? 10 : column.width,
34220
- maxWidth: isSelector ? 10 : column.maxWidth
34221
- }
34217
+ var headerRender = column.render('Header');
34218
+ return (isMobileHeader || isSelector) && /*#__PURE__*/React.createElement(TableHeadCell$2, __assign({}, column.getHeaderProps(function (props) {
34219
+ return [props, column.sortable ? column.getSortByToggleProps({
34220
+ title: t('sortColumnTitle', 'Urutkan') || 'Urutkan'
34221
+ }) : {
34222
+ onClick: column.onToggle
34223
+ }, {
34224
+ style: {
34225
+ minWidth: column.minWidth,
34226
+ width: isSelector ? 10 : column.width,
34227
+ maxWidth: isSelector ? 10 : column.maxWidth
34228
+ }
34229
+ }];
34222
34230
  }), {
34223
34231
  key: "head-cell-".concat(index)
34224
- }), column.render('Header'), (column === null || column === void 0 ? void 0 : column.isRequired) ? jsxRuntime.jsx(Required$2, {
34225
- children: "*"
34226
- }, void 0) : '');
34232
+ }), typeof headerRender === 'string' ? jsxRuntime.jsx(TableHeaderCellContainer, __assign({
34233
+ isMobile: true,
34234
+ isSortedDesc: column.isSortedDesc,
34235
+ unsortable: !column.sortable,
34236
+ isToggleable: !!column.onToggle,
34237
+ isToggled: column.isToggled,
34238
+ css: {
34239
+ padding: 0
34240
+ }
34241
+ }, {
34242
+ children: jsxRuntime.jsxs(TableHeadCellContent, __assign({
34243
+ heading: "headerTable"
34244
+ }, {
34245
+ children: [headerRender.toUpperCase(), (column === null || column === void 0 ? void 0 : column.isRequired) ? jsxRuntime.jsx(Required$2, {
34246
+ children: "*"
34247
+ }, void 0) : '']
34248
+ }), void 0)
34249
+ }), void 0) : jsxRuntime.jsxs(jsxRuntime.Fragment, {
34250
+ children: [headerRender, (column === null || column === void 0 ? void 0 : column.isRequired) ? jsxRuntime.jsx(Required$2, {
34251
+ children: "*"
34252
+ }, void 0) : '']
34253
+ }, void 0));
34227
34254
  }));
34228
34255
  })
34229
34256
  }, void 0), jsxRuntime.jsxs(TableBody$2, __assign({}, getTableBodyProps(), {
@@ -51772,7 +51799,8 @@
51772
51799
  hiddenColumns = props.hiddenColumns,
51773
51800
  emptyDataProps = props.customEmptyDataProps,
51774
51801
  _d = props.virtualized,
51775
- virtualized = _d === void 0 ? false : _d;
51802
+ virtualized = _d === void 0 ? false : _d,
51803
+ onSortByChange = props.onSortByChange;
51776
51804
  var t = reactI18next.useTranslation('MajooUI/table').t;
51777
51805
  var _e = React.useState(null),
51778
51806
  selectedIndex = _e[0],
@@ -51807,8 +51835,10 @@
51807
51835
  autoResetExpanded: false,
51808
51836
  getRowId: function (row) {
51809
51837
  return row[keyId] || JSON.stringify(row);
51810
- }
51811
- }, reactTable.useExpanded, reactTable.useRowSelect, function (hooks) {
51838
+ },
51839
+ defaultCanSort: false,
51840
+ autoResetSortBy: false
51841
+ }, reactTable.useSortBy, reactTable.useExpanded, reactTable.useRowSelect, function (hooks) {
51812
51842
  showCheckbox && hooks.visibleColumns.push(function (columns) {
51813
51843
  return __spreadArray([{
51814
51844
  id: 'selection',
@@ -51835,7 +51865,9 @@
51835
51865
  prepareRow = instance.prepareRow,
51836
51866
  visibleColumns = instance.visibleColumns,
51837
51867
  setHiddenColumns = instance.setHiddenColumns,
51838
- selectedRowIds = instance.state.selectedRowIds;
51868
+ _f = instance.state,
51869
+ selectedRowIds = _f.selectedRowIds,
51870
+ sortBy = _f.sortBy;
51839
51871
  var tableContainerRef = React.useRef(null);
51840
51872
  var rowVirtualizer = reactVirtual.useVirtual({
51841
51873
  parentRef: tableContainerRef,
@@ -51918,6 +51950,11 @@
51918
51950
  }), void 0);
51919
51951
  };
51920
51952
  var tableRowData = virtualized ? virtualRows : rows;
51953
+ React.useEffect(function () {
51954
+ if (onSortByChange) {
51955
+ onSortByChange(sortBy);
51956
+ }
51957
+ }, [sortBy]);
51921
51958
  return !isMobile ? jsxRuntime.jsx(TableContainer$1, __assign({
51922
51959
  ref: tableContainerRef,
51923
51960
  css: props === null || props === void 0 ? void 0 : props.css
@@ -51931,16 +51968,41 @@
51931
51968
  });
51932
51969
  return jsxRuntime.jsx(TableHeadRow$1, __assign({}, headerGroup.getHeaderGroupProps(), {
51933
51970
  children: visibleHeaders.map(function (column) {
51934
- return !(column === null || column === void 0 ? void 0 : column.isMobileOnly) && jsxRuntime.jsxs(TableHeadCell$1, __assign({}, column.getHeaderProps({
51935
- style: {
51936
- minWidth: column.minWidth,
51937
- width: column.width,
51938
- maxWidth: column.maxWidth
51939
- }
51971
+ var headerRender = column.render('Header');
51972
+ return !(column === null || column === void 0 ? void 0 : column.isMobileOnly) && jsxRuntime.jsx(TableHeadCell$1, __assign({}, column.getHeaderProps(function (props) {
51973
+ return [props, column.sortable ? column.getSortByToggleProps({
51974
+ title: t('sortColumnTitle', 'Urutkan') || 'Urutkan'
51975
+ }) : {
51976
+ onClick: column.onToggle
51977
+ }, {
51978
+ style: {
51979
+ minWidth: column.minWidth,
51980
+ width: column.width,
51981
+ maxWidth: column.maxWidth
51982
+ }
51983
+ }];
51940
51984
  }), {
51941
- children: [column.render('Header'), (column === null || column === void 0 ? void 0 : column.isRequired) ? jsxRuntime.jsx(Required$1, {
51942
- children: "*"
51943
- }, void 0) : '']
51985
+ children: typeof headerRender === 'string' ? jsxRuntime.jsx(TableHeaderCellContainer, __assign({
51986
+ isSortedDesc: column.isSortedDesc,
51987
+ unsortable: !column.sortable,
51988
+ isToggleable: !!column.onToggle,
51989
+ isToggled: column.isToggled,
51990
+ css: {
51991
+ padding: 0
51992
+ }
51993
+ }, {
51994
+ children: jsxRuntime.jsxs(TableHeadCellContent, __assign({
51995
+ heading: "headerTable"
51996
+ }, {
51997
+ children: [headerRender.toUpperCase(), (column === null || column === void 0 ? void 0 : column.isRequired) ? jsxRuntime.jsx(Required$1, {
51998
+ children: "*"
51999
+ }, void 0) : '']
52000
+ }), void 0)
52001
+ }), void 0) : jsxRuntime.jsxs(jsxRuntime.Fragment, {
52002
+ children: [headerRender, (column === null || column === void 0 ? void 0 : column.isRequired) ? jsxRuntime.jsx(Required$1, {
52003
+ children: "*"
52004
+ }, void 0) : '']
52005
+ }, void 0)
51944
52006
  }), void 0);
51945
52007
  })
51946
52008
  }), void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@majoo-ui/react",
3
- "version": "1.60.8",
3
+ "version": "1.60.9",
4
4
  "dependencies": {
5
5
  "@majoo-ui/core": "^1.31.3",
6
6
  "@majoo-ui/helpers": "^1.30.5",