@mezzanine-ui/react 0.8.1 → 0.9.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.
@@ -18,7 +18,7 @@ import { FormControlContext } from '../Form/FormControlContext.js';
18
18
  const DatePicker = forwardRef(function DatePicker(props, ref) {
19
19
  const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
20
20
  const { defaultDateFormat, getNow, } = useCalendarContext();
21
- const { calendarProps, className, clearable, defaultValue, disableOnNext, disableOnPrev, disabled = disabledFromFormControl || false, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultDateFormat, fullWidth = fullWidthFromFormControl || false, inputProps, isDateDisabled, isMonthDisabled, isYearDisabled, mode = 'day', onCalendarToggle: onCalendarToggleProp, onChange: onChangeProp, placeholder, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl || false, size, value: valueProp, ...restTriggerProps } = props;
21
+ const { calendarProps, className, clearable = true, defaultValue, disableOnNext, disableOnPrev, disabled = disabledFromFormControl || false, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultDateFormat, fullWidth = fullWidthFromFormControl || false, inputProps, isDateDisabled, isMonthDisabled, isYearDisabled, mode = 'day', onCalendarToggle: onCalendarToggleProp, onChange: onChangeProp, placeholder, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl || false, size, value: valueProp, ...restTriggerProps } = props;
22
22
  const { onBlur: onBlurProp, onKeyDown: onKeyDownProp, onFocus: onFocusProp, size: inputSize = format.length + 2, ...restInputProp } = inputProps || {};
23
23
  const formats = useMemo(() => [
24
24
  format,
@@ -18,7 +18,7 @@ import { FormControlContext } from '../Form/FormControlContext.js';
18
18
  const DateRangePicker = forwardRef(function DateRangePicker(props, ref) {
19
19
  const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
20
20
  const { defaultDateFormat, getNow, isBetween, } = useCalendarContext();
21
- const { calendarProps, className, clearable, defaultValue, disabled = disabledFromFormControl || false, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultDateFormat, fullWidth = fullWidthFromFormControl || false, inputFromPlaceholder, inputFromProps, inputToPlaceholder, inputToProps, isDateDisabled, isMonthDisabled, isYearDisabled, mode = 'day', onCalendarToggle: onCalendarToggleProp, onChange: onChangeProp, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl || false, size, value: valueProp, } = props;
21
+ const { calendarProps, className, clearable = true, defaultValue, disabled = disabledFromFormControl || false, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultDateFormat, fullWidth = fullWidthFromFormControl || false, inputFromPlaceholder, inputFromProps, inputToPlaceholder, inputToProps, isDateDisabled, isMonthDisabled, isYearDisabled, mode = 'day', onCalendarToggle: onCalendarToggleProp, onChange: onChangeProp, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl || false, size, value: valueProp, } = props;
22
22
  const { onBlur: onFromBlurProp, onKeyDown: onFromKeyDownProp, onFocus: onFromFocusProp, ...restInputFromProps } = inputFromProps || {};
23
23
  const { onBlur: onToBlurProp, onKeyDown: onToKeyDownProp, onFocus: onToFocusProp, ...restInputToProps } = inputToProps || {};
24
24
  const formats = useMemo(() => [
@@ -156,7 +156,9 @@ const DateRangePicker = forwardRef(function DateRangePicker(props, ref) {
156
156
  const [from, to] = internalValue;
157
157
  if (from && to) {
158
158
  const newValue = onChange([from, to]);
159
- onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(newValue);
159
+ if (onChangeProp) {
160
+ onChangeProp(newValue);
161
+ }
160
162
  }
161
163
  else {
162
164
  onChange(valueProp);
@@ -18,7 +18,7 @@ const DateTimePicker = forwardRef(function DateTimePicker(props, ref) {
18
18
  const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
19
19
  const { defaultDateFormat, defaultTimeFormat, getNow, startOf, } = useCalendarContext();
20
20
  const defaultFormat = `${defaultDateFormat} ${defaultTimeFormat}`;
21
- const { calendarProps, className, clearable, confirmText, defaultValue, disableOnNext, disableOnPrev, disabled = disabledFromFormControl, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultFormat, fullWidth = fullWidthFromFormControl, hideHour, hideMinute, hideSecond, hourPrefix, hourStep, inputProps, isDateDisabled, isMonthDisabled, isYearDisabled, minutePrefix, minuteStep, onChange: onChangeProp, onPanelToggle: onPanelToggleProp, placeholder, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl, secondPrefix, secondStep, size: sizeProp, value: valueProp, } = props;
21
+ const { calendarProps, className, clearable = true, confirmText, defaultValue, disableOnNext, disableOnPrev, disabled = disabledFromFormControl, displayMonthLocale, error = severity === 'error' || false, fadeProps, format = defaultFormat, fullWidth = fullWidthFromFormControl, hideHour, hideMinute, hideSecond, hourPrefix, hourStep, inputProps, isDateDisabled, isMonthDisabled, isYearDisabled, minutePrefix, minuteStep, onChange: onChangeProp, onPanelToggle: onPanelToggleProp, placeholder, popperProps, prefix, readOnly, referenceDate: referenceDateProp, required = requiredFromFormControl, secondPrefix, secondStep, size: sizeProp, value: valueProp, } = props;
22
22
  const { onBlur: onBlurProp, onKeyDown: onKeyDownProp, onFocus: onFocusProp, size: inputSize = format.length + 2, ...restInputProp } = inputProps || {};
23
23
  const formats = useMemo(() => [format, defaultFormat], [defaultFormat, format]);
24
24
  /** Panel open control */
@@ -22,7 +22,7 @@ const TableBody = forwardRef(function TableBody(props, ref) {
22
22
  const currentStartCount = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.pageSize) && currentPage ? ((paginationOptions.pageSize) * (currentPage - 1)) : 0;
23
23
  const currentEndCount = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.pageSize) && currentPage && total ? (Math.min(((paginationOptions.pageSize) * currentPage), total)) : 0;
24
24
  const currentDataSource = pagination && !disableAutoSlicing ? (dataSource.slice(currentStartCount, currentEndCount)) : dataSource;
25
- return (jsxs("div", Object.assign({}, rest, { ref: composedRefs, className: cx(tableClasses.body, className), onScroll: tableBody.onScroll, role: "rowgroup" }, { children: [currentDataSource.length ? currentDataSource.map((rowData) => (jsx(TableBodyRow, { className: rowClassName, rowData: rowData }, (rowData.key || rowData.id)))) : (jsx(Empty, Object.assign({}, restEmptyProps, { className: cx(tableClasses.bodyEmpty, emptyComponentClassName), fullHeight: emptyComponentFullHeight }, { children: emptyComponentChildren }), void 0)),
25
+ return (jsxs("div", Object.assign({}, rest, { ref: composedRefs, className: cx(tableClasses.body, className), onScroll: tableBody.onScroll, role: "rowgroup" }, { children: [currentDataSource.length ? currentDataSource.map((rowData, index) => (jsx(TableBodyRow, { className: rowClassName, rowData: rowData, rowIndex: index }, (rowData.key || rowData.id)))) : (jsx(Empty, Object.assign({}, restEmptyProps, { className: cx(tableClasses.bodyEmpty, emptyComponentClassName), fullHeight: emptyComponentFullHeight }, { children: emptyComponentChildren }), void 0)),
26
26
  (fetchMore === null || fetchMore === void 0 ? void 0 : fetchMore.isFetching) ? (jsx("div", Object.assign({ className: tableClasses.bodyFetchMore }, { children: jsx(Loading, { loading: true }, void 0) }), void 0)) : null,
27
27
  jsx("div", Object.assign({ ref: scrollElement.ref, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, onMouseEnter: scrollElement.onMouseEnter, onMouseLeave: scrollElement.onMouseLeave, role: "button", style: scrollElement.style, tabIndex: -1 }, { children: jsx("div", { style: {
28
28
  width: `${scrollBarSize}px`,
@@ -6,6 +6,7 @@ export interface TableBodyRowProps extends NativeElementPropsWithoutKeyAndRef<'d
6
6
  * table body row dataSource
7
7
  */
8
8
  rowData: TableDataSource;
9
+ rowIndex: number;
9
10
  }
10
11
  declare const TableBodyRow: import("react").ForwardRefExoticComponent<TableBodyRowProps & import("react").RefAttributes<HTMLDivElement>>;
11
12
  export default TableBodyRow;
@@ -1,9 +1,10 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { forwardRef, useContext, useState, useMemo, useCallback, Fragment } from 'react';
3
- import { tableClasses } from '@mezzanine-ui/core/table';
1
+ import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
+ import { forwardRef, useContext, useState, useMemo, Fragment } from 'react';
3
+ import { tableClasses, getColumnStyle, getCellStyle } from '@mezzanine-ui/core/table';
4
4
  import get from 'lodash/get';
5
5
  import { TableContext, TableDataContext } from './TableContext.js';
6
6
  import TableCell from './TableCell.js';
7
+ import TableExpandedTable from './TableExpandedTable.js';
7
8
  import TableRowSelection from './rowSelection/TableRowSelection.js';
8
9
  import TableExpandable from './expandable/TableExpandable.js';
9
10
  import TableEditRenderWrapper from './editable/TableEditRenderWrapper.js';
@@ -11,7 +12,7 @@ import AccordionDetails from '../Accordion/AccordionDetails.js';
11
12
  import cx from 'clsx';
12
13
 
13
14
  const TableBodyRow = forwardRef(function TableBodyRow(props, ref) {
14
- const { className, rowData, ...rest } = props;
15
+ const { className, rowData, rowIndex, ...rest } = props;
15
16
  const { rowSelection, expanding, } = useContext(TableContext) || {};
16
17
  const { columns, } = useContext(TableDataContext) || {};
17
18
  /** Feature rowSelection */
@@ -26,39 +27,17 @@ const TableBodyRow = forwardRef(function TableBodyRow(props, ref) {
26
27
  var _a, _b;
27
28
  return ((_b = (_a = expanding === null || expanding === void 0 ? void 0 : expanding.expandedRowRender) === null || _a === void 0 ? void 0 : _a.call(expanding, rowData)) !== null && _b !== void 0 ? _b : null);
28
29
  }, [expanding, rowData]);
29
- /** styling */
30
- const getColumnStyle = useCallback((column) => {
31
- let style = {};
32
- if (column.width) {
33
- style = {
34
- ...style,
35
- width: column.width,
36
- maxWidth: column.width,
37
- };
38
- }
39
- return style;
40
- }, []);
41
- const getCellStyle = useCallback((column) => {
42
- let style = {};
43
- if (column.align) {
44
- style = {
45
- ...style,
46
- justifyContent: column.align === 'center' ? column.align : `flex-${column.align}`,
47
- };
48
- }
49
- return style;
50
- }, []);
51
30
  return (jsxs(Fragment, { children: [jsxs("div", Object.assign({}, rest, { ref: ref, className: cx(tableClasses.bodyRow, {
52
31
  [tableClasses.bodyRowHighlight]: selected || expanded,
53
32
  }, className), role: "row" }, { children: [rowSelection ? (jsx(TableRowSelection, { role: "gridcell", rowKey: (rowData.key || rowData.id), setChecked: (status) => setSelected(status), showDropdownIcon: false }, void 0)) : null,
54
- expanding ? (jsx(TableExpandable, { expandable: isExpandable, expanded: expanded, role: "gridcell", setExpanded: setExpanded }, void 0)) : null,
55
- (columns !== null && columns !== void 0 ? columns : []).map((column, index) => {
33
+ expanding ? (jsx(TableExpandable, { expandable: isExpandable, expanded: expanded, role: "gridcell", setExpanded: setExpanded, onExpand: (status) => { var _a; return (_a = expanding.onExpand) === null || _a === void 0 ? void 0 : _a.call(expanding, rowData, status); } }, void 0)) : null,
34
+ (columns !== null && columns !== void 0 ? columns : []).map((column) => {
56
35
  var _a, _b, _c, _d;
57
36
  const ellipsis = !!(get(rowData, column.dataIndex)) && ((_a = column.ellipsis) !== null && _a !== void 0 ? _a : true);
58
37
  const tooltipTitle = ((_c = (_b = column.renderTooltipTitle) === null || _b === void 0 ? void 0 : _b.call(column, rowData)) !== null && _c !== void 0 ? _c : get(rowData, column.dataIndex));
59
- return (jsx("div", Object.assign({ className: cx(tableClasses.bodyRowCellWrapper, column.bodyClassName), style: getColumnStyle(column) }, { children: jsx(TableEditRenderWrapper, Object.assign({}, column, { rowData: rowData }, { children: jsx(TableCell, Object.assign({ ellipsis: ellipsis, forceShownTooltipWhenHovered: column.forceShownTooltipWhenHovered, style: getCellStyle(column), tooltipTitle: tooltipTitle }, { children: ((_d = column.render) === null || _d === void 0 ? void 0 : _d.call(column, column, rowData, index)) || get(rowData, column.dataIndex) }), void 0) }), void 0) }), `${column.dataIndex}-${column.title}`));
38
+ return (jsx("div", Object.assign({ className: cx(tableClasses.bodyRowCellWrapper, column.bodyClassName), style: getColumnStyle(column) }, { children: jsx(TableEditRenderWrapper, Object.assign({}, column, { rowData: rowData }, { children: jsx(TableCell, Object.assign({ ellipsis: ellipsis, forceShownTooltipWhenHovered: column.forceShownTooltipWhenHovered, style: getCellStyle(column), tooltipTitle: tooltipTitle }, { children: ((_d = column.render) === null || _d === void 0 ? void 0 : _d.call(column, column, rowData, rowIndex)) || get(rowData, column.dataIndex) }), void 0) }), void 0) }), `${column.dataIndex}-${column.title}`));
60
39
  })] }), void 0),
61
- renderedExpandedContent ? (jsx(AccordionDetails, Object.assign({ className: expanding.className, expanded: expanded }, { children: renderedExpandedContent }), void 0)) : null] }, void 0));
40
+ renderedExpandedContent ? (jsx(Fragment$1, { children: typeof renderedExpandedContent === 'string' ? (jsx(AccordionDetails, Object.assign({ className: expanding.className, expanded: expanded }, { children: renderedExpandedContent }), void 0)) : (jsx(Fragment$1, { children: renderedExpandedContent.dataSource.length > 0 ? (jsx(AccordionDetails, Object.assign({ className: cx(expanding.className, tableClasses.bodyRowExpandedTableWrapper), expanded: expanded }, { children: jsx(TableExpandedTable, { renderedExpandedContent: renderedExpandedContent }, void 0) }), void 0)) : null }, void 0)) }, void 0)) : null] }, void 0));
62
41
  });
63
42
  var TableBodyRow$1 = TableBodyRow;
64
43
 
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { TableDataSource, ExpandedTableColumn } from '@mezzanine-ui/core/table';
3
+ import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
4
+ export interface TableExpandedTableProps extends NativeElementPropsWithoutKeyAndRef<'div'> {
5
+ renderedExpandedContent: {
6
+ dataSource: TableDataSource[];
7
+ columns?: ExpandedTableColumn[];
8
+ className?: string;
9
+ };
10
+ }
11
+ declare const TableExpandedTable: import("react").ForwardRefExoticComponent<TableExpandedTableProps & import("react").RefAttributes<HTMLDivElement>>;
12
+ export default TableExpandedTable;
@@ -0,0 +1,27 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { forwardRef, useContext } from 'react';
3
+ import { tableClasses, getColumnStyle, getCellStyle } from '@mezzanine-ui/core/table';
4
+ import get from 'lodash/get';
5
+ import { TableDataContext } from './TableContext.js';
6
+ import TableCell from './TableCell.js';
7
+ import TableExpandable from './expandable/TableExpandable.js';
8
+ import cx from 'clsx';
9
+
10
+ const TableExpandedTable = forwardRef(function TableExpandedTable(props, ref) {
11
+ const { renderedExpandedContent, } = props;
12
+ const { columns, } = useContext(TableDataContext) || {};
13
+ return (jsx("div", Object.assign({ className: tableClasses.bodyRowExpandedTable }, { children: renderedExpandedContent.dataSource.map((source, sourceIndex) => {
14
+ var _a;
15
+ return (jsxs("div", Object.assign({ ref: ref, className: cx(tableClasses.bodyRow, tableClasses.bodyRowExpandedTableRow, renderedExpandedContent.className), role: "row" }, { children: [jsx(TableExpandable, { showIcon: false }, void 0),
16
+ ((_a = (renderedExpandedContent.columns || columns)) !== null && _a !== void 0 ? _a : [])
17
+ .map((column, index) => {
18
+ var _a, _b, _c, _d;
19
+ const ellipsis = !!(get(source, column.dataIndex)) && ((_a = column.ellipsis) !== null && _a !== void 0 ? _a : true);
20
+ const tooltipTitle = ((_c = (_b = column.renderTooltipTitle) === null || _b === void 0 ? void 0 : _b.call(column, source)) !== null && _c !== void 0 ? _c : get(source, column.dataIndex));
21
+ return (jsx("div", Object.assign({ className: cx(tableClasses.bodyRowCellWrapper, column.bodyClassName), style: getColumnStyle((columns !== null && columns !== void 0 ? columns : [])[index]) }, { children: jsx(TableCell, Object.assign({ ellipsis: ellipsis, forceShownTooltipWhenHovered: column.forceShownTooltipWhenHovered, style: getCellStyle((columns !== null && columns !== void 0 ? columns : [])[index]), tooltipTitle: tooltipTitle || '' }, { children: ((_d = column.render) === null || _d === void 0 ? void 0 : _d.call(column, column, source, sourceIndex)) || get(source, column.dataIndex) }), void 0) }), `${column.dataIndex}-${index}`));
22
+ })] }), (source.key || source.id)));
23
+ }) }), void 0));
24
+ });
25
+ var TableExpandedTable$1 = TableExpandedTable;
26
+
27
+ export { TableExpandedTable$1 as default };
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { forwardRef, useContext, useCallback } from 'react';
3
- import { tableClasses } from '@mezzanine-ui/core/table';
2
+ import { forwardRef, useContext } from 'react';
3
+ import { tableClasses, getColumnStyle, getCellStyle } from '@mezzanine-ui/core/table';
4
4
  import { TableContext, TableDataContext } from './TableContext.js';
5
5
  import { SELECTED_ALL_KEY } from './rowSelection/useTableRowSelection.js';
6
6
  import TableCell from './TableCell.js';
@@ -13,34 +13,12 @@ const TableHeader = forwardRef(function TableHeader(props, ref) {
13
13
  const { className, ...rest } = props;
14
14
  const { rowSelection, expanding, } = useContext(TableContext) || {};
15
15
  const { columns, } = useContext(TableDataContext) || {};
16
- /** styling */
17
- const getColumnStyle = useCallback((column) => {
18
- let style = {};
19
- if (column.width) {
20
- style = {
21
- ...style,
22
- width: column.width,
23
- maxWidth: column.width,
24
- };
25
- }
26
- return style;
27
- }, []);
28
- const getCellStyle = useCallback((column) => {
29
- let style = {};
30
- if (column.align) {
31
- style = {
32
- ...style,
33
- justifyContent: column.align === 'center' ? column.align : `flex-${column.align}`,
34
- };
35
- }
36
- return style;
37
- }, []);
38
16
  return (jsxs("div", Object.assign({ ref: ref }, rest, { className: cx(tableClasses.header, className), role: "rowgroup" }, { children: [rowSelection ? (jsx(TableRowSelection, { rowKey: SELECTED_ALL_KEY, showDropdownIcon: true }, void 0)) : null,
39
17
  expanding && !rowSelection ? (jsx(TableExpandable, { showIcon: false }, void 0)) : null,
40
18
  (columns !== null && columns !== void 0 ? columns : []).map((column) => {
41
19
  var _a;
42
20
  return (jsx("div", Object.assign({ className: cx(tableClasses.headerCellWrapper, column.headerClassName), style: getColumnStyle(column) }, { children: jsxs(TableCell, Object.assign({ ellipsis: false, role: "columnheader", style: getCellStyle(column) }, { children: [((_a = column.renderTitle) === null || _a === void 0 ? void 0 : _a.call(column, tableClasses)) || column.title,
43
- typeof column.sorter === 'function' ? (jsx(TableSortingIcon, { column: column }, void 0)) : null] }), void 0) }), `${column.dataIndex}-${column.title}`));
21
+ typeof column.sorter === 'function' || typeof column.onSorted === 'function' ? (jsx(TableSortingIcon, { column: column }, void 0)) : null] }), void 0) }), `${column.dataIndex}-${column.title}`));
44
22
  })] }), void 0));
45
23
  });
46
24
  var TableHeader$1 = TableHeader;
@@ -10,6 +10,10 @@ export interface TableExpandableProps extends NativeElementPropsWithoutKeyAndRef
10
10
  * whether is expanded or not
11
11
  */
12
12
  expanded?: boolean;
13
+ /**
14
+ * Invoked by expanded status changed.
15
+ */
16
+ onExpand?(status: boolean): void;
13
17
  /**
14
18
  * toggle expanded
15
19
  */
@@ -6,10 +6,19 @@ import Icon from '../../Icon/Icon.js';
6
6
  import cx from 'clsx';
7
7
 
8
8
  const TableExpandable = forwardRef(function TableExpandable(props, ref) {
9
- const { className, expandable = true, expanded, setExpanded, showIcon = true, ...rest } = props;
9
+ const { className, expandable = true, expanded, onExpand, setExpanded, showIcon = true, ...rest } = props;
10
+ const onClick = () => {
11
+ if (expandable) {
12
+ const nextStatus = !expanded;
13
+ setExpanded === null || setExpanded === void 0 ? void 0 : setExpanded(nextStatus);
14
+ if (onExpand) {
15
+ onExpand(nextStatus);
16
+ }
17
+ }
18
+ };
10
19
  return (jsx("div", Object.assign({}, rest, { ref: ref, className: cx(tableClasses.collapseAction, className) }, { children: jsx("div", Object.assign({ className: tableClasses.icon }, { children: showIcon ? (jsx(Icon, { className: cx(tableClasses.icon, {
11
20
  [tableClasses.iconClickable]: expandable,
12
- }), color: expandable ? 'primary' : 'disabled', icon: ChevronDownIcon, onClick: () => expandable && (setExpanded === null || setExpanded === void 0 ? void 0 : setExpanded(!expanded)), style: { transform: `rotate(${expanded ? '180deg' : '0'})` } }, void 0)) : null }), void 0) }), void 0));
21
+ }), color: expandable ? 'primary' : 'disabled', icon: ChevronDownIcon, onClick: onClick, style: { transform: `rotate(${expanded ? '180deg' : '0'})` } }, void 0)) : null }), void 0) }), void 0));
13
22
  });
14
23
  var TableExpandable$1 = TableExpandable;
15
24
 
@@ -51,15 +51,15 @@ function useTableSorting(props) {
51
51
  }, []);
52
52
  const onChange = useLastCallback((opts) => {
53
53
  const { dataIndex, sorter, onSorted } = opts;
54
+ const isChosenFromOneToAnother = sortedOn && dataIndex !== sortedOn;
55
+ const nextSortedType = getNextSortedType(isChosenFromOneToAnother ? 'none' : sortedType);
54
56
  const onMappingSources = (sources) => {
55
57
  setDataSource(sources);
56
- onSorted === null || onSorted === void 0 ? void 0 : onSorted(sources);
58
+ onSorted === null || onSorted === void 0 ? void 0 : onSorted(dataIndex, nextSortedType);
57
59
  };
58
60
  // only apply changes when column sorter is given
59
- if (typeof sorter === 'function') {
61
+ if (typeof sorter === 'function' || typeof onSorted === 'function') {
60
62
  // should update next sorted type first
61
- const isChosenFromOneToAnother = sortedOn && dataIndex !== sortedOn;
62
- const nextSortedType = getNextSortedType(isChosenFromOneToAnother ? 'none' : sortedType);
63
63
  setSortedType(nextSortedType);
64
64
  switch (nextSortedType) {
65
65
  case 'desc':
@@ -68,10 +68,12 @@ function useTableSorting(props) {
68
68
  setSortedOn(dataIndex);
69
69
  // getting new source instance (when switch between sorter, should use origin dataSource)
70
70
  let newSource = (isChosenFromOneToAnother ? dataSourceProp : dataSource).slice(0);
71
- // sort by given sorter
72
- newSource = newSource.sort((a, b) => (
73
- // reverse result when sorted type is ascending
74
- (sorter(get(a, dataIndex), get(b, dataIndex))) * (nextSortedType === 'asc' ? -1 : 1)));
71
+ if (typeof sorter === 'function') {
72
+ // sort by given sorter
73
+ newSource = newSource.sort((a, b) => (
74
+ // reverse result when sorted type is ascending
75
+ (sorter(get(a, dataIndex), get(b, dataIndex))) * (nextSortedType === 'asc' ? -1 : 1)));
76
+ }
75
77
  // map back the data source
76
78
  onMappingSources(newSource);
77
79
  break;
@@ -1,26 +1,10 @@
1
1
  import { useState, useEffect } from 'react';
2
- import { useWindowWidth } from '../hooks/useWindowWidth.js';
3
2
 
4
3
  function useTabsOverflow(tabsRef) {
5
4
  const [isOverflowing, setIsOverflowing] = useState(false);
6
5
  const [scrollState, setScrollState] = useState('begin');
7
6
  const isScrollToBegin = scrollState === 'begin';
8
7
  const isScrollToEnd = scrollState === 'end';
9
- const windowWidth = useWindowWidth();
10
- function handleScrollState() {
11
- if (tabsRef.current) {
12
- const offsetRight = tabsRef.current.scrollWidth - tabsRef.current.clientWidth;
13
- if (tabsRef.current.scrollLeft === 0) {
14
- setScrollState('begin');
15
- }
16
- else if (tabsRef.current.scrollLeft >= offsetRight) {
17
- setScrollState('end');
18
- }
19
- else {
20
- setScrollState('middle');
21
- }
22
- }
23
- }
24
8
  function scrollToLeft() {
25
9
  if (tabsRef.current) {
26
10
  tabsRef.current.scrollTo(0, 0);
@@ -34,16 +18,35 @@ function useTabsOverflow(tabsRef) {
34
18
  }
35
19
  useEffect(() => {
36
20
  if (tabsRef.current) {
37
- const isXOverflowing = tabsRef.current.scrollWidth > tabsRef.current.clientWidth;
38
- if (isOverflowing !== isXOverflowing) {
39
- setIsOverflowing(isXOverflowing);
40
- }
41
- }
42
- }, [isOverflowing, windowWidth]);
43
- useEffect(() => {
44
- if (tabsRef.current) {
21
+ const handleOverflowingState = () => {
22
+ if (tabsRef.current) {
23
+ setIsOverflowing(tabsRef.current.scrollWidth > tabsRef.current.clientWidth);
24
+ }
25
+ };
26
+ const handleScrollState = () => {
27
+ if (tabsRef.current) {
28
+ const offsetRight = tabsRef.current.scrollWidth - tabsRef.current.clientWidth;
29
+ if (tabsRef.current.scrollLeft === 0) {
30
+ setScrollState('begin');
31
+ }
32
+ else if (tabsRef.current.scrollLeft >= offsetRight) {
33
+ setScrollState('end');
34
+ }
35
+ else {
36
+ setScrollState('middle');
37
+ }
38
+ }
39
+ };
40
+ // init isOverflowing when mounting
41
+ handleOverflowingState();
42
+ window.addEventListener('resize', handleOverflowingState);
45
43
  tabsRef.current.addEventListener('scroll', handleScrollState);
46
- return () => { var _a; return (_a = tabsRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('scroll', handleScrollState); };
44
+ return () => {
45
+ if (tabsRef.current) {
46
+ window.removeEventListener('resize', handleOverflowingState);
47
+ tabsRef.current.removeEventListener('scroll', handleScrollState);
48
+ }
49
+ };
47
50
  }
48
51
  }, [tabsRef.current]);
49
52
  return {
@@ -20,12 +20,13 @@ const TimePanelColumn = forwardRef(function TimePanelColumn(props, ref) {
20
20
  };
21
21
  const prevetSmoothScrollTo = useRef(true);
22
22
  useEffect(() => {
23
- var _a;
24
23
  const activeIndex = units.findIndex(({ value }) => value === activeUnit);
25
- (_a = cellsRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
26
- top: activeIndex * cellHeight,
27
- behavior: prevetSmoothScrollTo.current ? 'auto' : 'smooth',
28
- });
24
+ if (cellsRef.current) {
25
+ cellsRef.current.scrollTo({
26
+ top: activeIndex * cellHeight,
27
+ behavior: prevetSmoothScrollTo.current ? 'auto' : 'smooth',
28
+ });
29
+ }
29
30
  prevetSmoothScrollTo.current = false;
30
31
  }, [activeUnit, cellHeight, units]);
31
32
  return (jsxs("div", Object.assign({ ref: ref, className: timePanelClasses.column }, { children: [prefix && jsx("div", Object.assign({ className: timePanelClasses.columnPrefix }, { children: prefix }), void 0),
@@ -17,7 +17,7 @@ import { FormControlContext } from '../Form/FormControlContext.js';
17
17
  const TimePicker = forwardRef(function TimePicker(props, ref) {
18
18
  const { disabled: disabledFromFormControl, fullWidth: fullWidthFromFormControl, required: requiredFromFormControl, severity, } = useContext(FormControlContext) || {};
19
19
  const { defaultTimeFormat, } = useCalendarContext();
20
- const { className, clearable, confirmText, defaultValue, disabled = disabledFromFormControl, error = severity === 'error' || false, format = defaultTimeFormat, fullWidth = fullWidthFromFormControl, hideHour, hideMinute, hideSecond, hourPrefix, hourStep, inputProps, minutePrefix, minuteStep, onChange: onChangeProp, onPanelToggle: onPanelToggleProp, placeholder, popperProps, prefix, readOnly, required = requiredFromFormControl, secondPrefix, secondStep, size: sizeProp, value: valueProp, } = props;
20
+ const { className, clearable = true, confirmText, defaultValue, disabled = disabledFromFormControl, error = severity === 'error' || false, format = defaultTimeFormat, fullWidth = fullWidthFromFormControl, hideHour, hideMinute, hideSecond, hourPrefix, hourStep, inputProps, minutePrefix, minuteStep, onChange: onChangeProp, onPanelToggle: onPanelToggleProp, placeholder, popperProps, prefix, readOnly, required = requiredFromFormControl, secondPrefix, secondStep, size: sizeProp, value: valueProp, } = props;
21
21
  const { onBlur: onBlurProp, onKeyDown: onKeyDownProp, onFocus: onFocusProp, size: inputSize = format.length + 2, ...restInputProp } = inputProps || {};
22
22
  const formats = useMemo(() => [format], [format]);
23
23
  /** Panel open control */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mezzanine-ui/react",
3
- "version": "0.8.1",
3
+ "version": "0.9.2",
4
4
  "description": "React components for mezzanine-ui",
5
5
  "author": "Mezzanine",
6
6
  "repository": {
@@ -32,8 +32,8 @@
32
32
  "react-dom": "^17.0.1"
33
33
  },
34
34
  "dependencies": {
35
- "@mezzanine-ui/core": "^0.8.1",
36
- "@mezzanine-ui/icons": "^0.7.3",
35
+ "@mezzanine-ui/core": "^0.9.2",
36
+ "@mezzanine-ui/icons": "^0.9.2",
37
37
  "@mezzanine-ui/system": "^0.7.0",
38
38
  "@popperjs/core": "^2.9.2",
39
39
  "@types/react-transition-group": "4.4.1",