@mezzanine-ui/react 0.14.5 → 0.14.7

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.
@@ -63,6 +63,7 @@ const DateRangePicker = forwardRef(function DateRangePicker(props, ref) {
63
63
  value: valueProp,
64
64
  inputFromRef,
65
65
  inputToRef,
66
+ mode,
66
67
  onChange: onChangeProp,
67
68
  });
68
69
  useEffect(() => {
@@ -2,16 +2,21 @@ import { DateType } from '@mezzanine-ui/core/calendar';
2
2
  import { RangePickerPickingValue, RangePickerValue } from '@mezzanine-ui/core/picker';
3
3
  import { ChangeEventHandler, KeyboardEventHandler } from 'react';
4
4
  import { UseRangePickerValueProps } from '../Picker/useRangePickerValue';
5
+ import { DateRangePickerCalendarProps } from './DateRangePickerCalendar';
5
6
  export interface UseDateRangePickerValueProps extends Omit<UseRangePickerValueProps, 'onChange'> {
7
+ mode?: DateRangePickerCalendarProps['mode'];
6
8
  onChange?: (value?: RangePickerValue) => void;
7
9
  }
8
- export declare function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, onChange: onChangeProp, value: valueProp, }: UseDateRangePickerValueProps): {
10
+ export declare function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, mode, onChange: onChangeProp, value: valueProp, }: UseDateRangePickerValueProps): {
9
11
  calendarValue: string[] | undefined;
10
12
  inputFromValue: string;
11
13
  inputToValue: string;
12
14
  onCalendarChange: (val?: DateType) => void;
13
15
  onCalendarHover: import("react").Dispatch<import("react").SetStateAction<string | undefined>> | undefined;
14
- onChange: (target?: RangePickerPickingValue | undefined) => RangePickerPickingValue | undefined;
16
+ onChange: (target?: RangePickerPickingValue | undefined, callback?: {
17
+ from: (date?: string | undefined) => string | undefined;
18
+ to: (date?: string | undefined) => string | undefined;
19
+ }) => RangePickerPickingValue | undefined;
15
20
  onClear: () => void;
16
21
  onFromBlur: import("react").FocusEventHandler<HTMLInputElement>;
17
22
  onFromKeyDown: KeyboardEventHandler<HTMLInputElement>;
@@ -1,7 +1,9 @@
1
1
  import { useState, useMemo } from 'react';
2
2
  import { useRangePickerValue } from '../Picker/useRangePickerValue.js';
3
+ import { useCalendarContext } from '../Calendar/CalendarContext.js';
3
4
 
4
- function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, onChange: onChangeProp, value: valueProp, }) {
5
+ function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, mode, onChange: onChangeProp, value: valueProp, }) {
6
+ const { addDay, } = useCalendarContext();
5
7
  const { inputFromValue, inputToValue, onChange, onFromBlur, onFromKeyDown, onInputFromChange, onInputToChange, onToBlur, onToKeyDown, value, } = useRangePickerValue({
6
8
  format,
7
9
  formats,
@@ -25,7 +27,15 @@ function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, on
25
27
  ? [val, undefined]
26
28
  : [firstVal, val];
27
29
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
28
- const [sortedFrom, sortedTo] = onChange(newValue);
30
+ const [sortedFrom, sortedTo] = onChange(newValue, {
31
+ from: (nextFrom) => nextFrom,
32
+ to: (nextTo) => {
33
+ if (!nextTo)
34
+ return nextTo;
35
+ /** week mode should use the last day of the week (default is the first day) */
36
+ return mode === 'week' ? addDay(nextTo, 6) : nextTo;
37
+ },
38
+ });
29
39
  if (sortedFrom && sortedTo) {
30
40
  onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([sortedFrom, sortedTo]);
31
41
  }
@@ -9,7 +9,10 @@ export interface UseRangePickerValueProps extends Pick<UsePickerValueProps, 'for
9
9
  export declare function useRangePickerValue({ format, formats, inputFromRef, inputToRef, value: valueProp, }: UseRangePickerValueProps): {
10
10
  inputFromValue: string;
11
11
  inputToValue: string;
12
- onChange: (target?: RangePickerPickingValue) => RangePickerPickingValue | undefined;
12
+ onChange: (target?: RangePickerPickingValue, callback?: {
13
+ from: (date?: string) => string | undefined;
14
+ to: (date?: string) => string | undefined;
15
+ }) => RangePickerPickingValue | undefined;
13
16
  onFromBlur: import("react").FocusEventHandler<HTMLInputElement>;
14
17
  onFromKeyDown: KeyboardEventHandler<HTMLInputElement>;
15
18
  onInputFromChange: ChangeEventHandler<HTMLInputElement>;
@@ -23,16 +23,21 @@ function useRangePickerValue({ format, formats, inputFromRef, inputToRef, value:
23
23
  inputRef: inputToRef,
24
24
  });
25
25
  const value = [from, to];
26
- const onChange = (target) => {
26
+ const onChange = (target, callback = {
27
+ from: (date) => date,
28
+ to: (date) => date,
29
+ }) => {
27
30
  const [newFrom, newTo] = target || [];
28
31
  if (newFrom && newTo) {
29
32
  const sortedVal = sortValues([newFrom, newTo]);
30
- onFromChange(sortedVal[0]);
31
- onToChange(sortedVal[1]);
32
- return sortedVal;
33
+ const resolvedFrom = callback.from(sortedVal[0]);
34
+ const resolvedTo = callback.to(sortedVal[1]);
35
+ onFromChange(resolvedFrom);
36
+ onToChange(resolvedTo);
37
+ return [resolvedFrom, resolvedTo];
33
38
  }
34
- onFromChange(target === null || target === void 0 ? void 0 : target[0]);
35
- onToChange(target === null || target === void 0 ? void 0 : target[1]);
39
+ onFromChange(callback.from(target === null || target === void 0 ? void 0 : target[0]));
40
+ onToChange(callback.to(target === null || target === void 0 ? void 0 : target[1]));
36
41
  return target;
37
42
  };
38
43
  const onOrderGuardedInputFromChange = (event) => {
package/Table/Table.d.ts CHANGED
@@ -10,7 +10,7 @@ export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndR
10
10
  /**
11
11
  * customized body row className
12
12
  */
13
- bodyRowClassName?: string;
13
+ bodyRowClassName?: string | ((source: TableDataSource) => string);
14
14
  /**
15
15
  * Columns of table <br />
16
16
  * `column.render` allowed customizing the column body cell rendering. <br />
package/Table/Table.js CHANGED
@@ -143,6 +143,15 @@ const Table = forwardRef(function Table(props, ref) {
143
143
  });
144
144
  }, [(_a = components === null || components === void 0 ? void 0 : components.body) === null || _a === void 0 ? void 0 : _a.cell]);
145
145
  const tableRefs = useComposeRefs([ref, scrollBody.target]);
146
+ const rowClassName = useMemo(() => {
147
+ if (bodyRowClassName) {
148
+ if (typeof bodyRowClassName === 'string') {
149
+ return (() => bodyRowClassName);
150
+ }
151
+ return ((source) => bodyRowClassName === null || bodyRowClassName === void 0 ? void 0 : bodyRowClassName(source));
152
+ }
153
+ return undefined;
154
+ }, [bodyRowClassName]);
146
155
  return (jsx(TableContext.Provider, { value: tableContextValue, children: jsx(TableDataContext.Provider, { value: tableDataContextValue, children: jsx(TableComponentContext.Provider, { value: tableComponentContextValue, children: jsx(DragDropContext, { onBeforeDragStart: onBeforeDragStart, onDragEnd: onDragEnd, children: jsx(Loading, { loading: loading, stretch: true, tip: loadingTip, overlayProps: {
147
156
  className: tableClasses.loading,
148
157
  }, children: jsx(Droppable, { droppableId: "mzn-table-dnd", isDropDisabled: !(draggableProp === null || draggableProp === void 0 ? void 0 : draggableProp.enabled), children: (provided) => (jsxs(Fragment, { children: [jsx("div", { ...provided.droppableProps, ref: composeRefs([scrollBody.ref, provided.innerRef]), className: cx(tableClasses.scrollContainer, scrollContainerClassName), onScroll: scrollBody.onScroll, style: tableContextValue.scroll ? {
@@ -152,7 +161,7 @@ const Table = forwardRef(function Table(props, ref) {
152
161
  '--table-scroll-y': tableContextValue.scroll.y
153
162
  ? `${tableContextValue.scroll.y}px`
154
163
  : 'unset',
155
- } : undefined, children: jsxs("table", { ref: tableRefs, ...rest, className: cx(tableClasses.host, className), children: [isRefreshShow ? (jsx("tbody", { children: jsx("tr", { children: jsx("td", { "aria-label": "Refresh", children: jsx(TableRefresh, { onClick: refreshProp.onClick }) }) }) })) : null, jsx(TableHeader, { className: headerClassName }), jsx(TableBody, { ref: bodyRef, className: bodyClassName, rowClassName: bodyRowClassName }), jsx("tbody", { children: provided.placeholder })] }) }), paginationProp ? (jsx(TablePagination, { bodyRef: bodyRef })) : null, jsx("div", { ref: scrollElement.trackRef, "aria-label": "Scroll Track", style: scrollElement.trackStyle, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, role: "button", tabIndex: -1, className: "mzn-table-scroll-bar-track", children: jsx("div", { style: {
164
+ } : undefined, children: jsxs("table", { ref: tableRefs, ...rest, className: cx(tableClasses.host, className), children: [isRefreshShow ? (jsx("tbody", { children: jsx("tr", { children: jsx("td", { "aria-label": "Refresh", children: jsx(TableRefresh, { onClick: refreshProp.onClick }) }) }) })) : null, jsx(TableHeader, { className: headerClassName }), jsx(TableBody, { ref: bodyRef, className: bodyClassName, rowClassName: rowClassName }), jsx("tbody", { children: provided.placeholder })] }) }), paginationProp ? (jsx(TablePagination, { bodyRef: bodyRef })) : null, jsx("div", { ref: scrollElement.trackRef, "aria-label": "Scroll Track", style: scrollElement.trackStyle, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, role: "button", tabIndex: -1, className: "mzn-table-scroll-bar-track", children: jsx("div", { style: {
156
165
  width: '100%',
157
166
  height: '100%',
158
167
  position: 'relative',
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
+ import { TableDataSource } from '@mezzanine-ui/core/table';
2
3
  import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
3
4
  export interface TableBodyProps extends NativeElementPropsWithoutKeyAndRef<'div'> {
4
5
  /**
5
6
  * customize row className
6
7
  */
7
- rowClassName?: string;
8
+ rowClassName?: (source: TableDataSource) => string;
8
9
  }
9
10
  declare const TableBody: import("react").ForwardRefExoticComponent<TableBodyProps & import("react").RefAttributes<HTMLTableSectionElement>>;
10
11
  export default TableBody;
@@ -18,7 +18,7 @@ const TableBody = forwardRef(function TableBody(props, ref) {
18
18
  const currentStartCount = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.pageSize) && currentPage ? ((paginationOptions.pageSize) * (currentPage - 1)) : 0;
19
19
  const currentEndCount = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.pageSize) && currentPage && total ? (Math.min(((paginationOptions.pageSize) * currentPage), total)) : 0;
20
20
  const currentDataSource = pagination && !disableAutoSlicing ? (dataSource.slice(currentStartCount, currentEndCount)) : dataSource;
21
- return (jsxs("tbody", { ...rest, ref: ref, className: cx(tableClasses.body, className), children: [currentDataSource.length ? currentDataSource.map((rowData, index) => (jsx(TableBodyRow, { className: rowClassName, rowData: rowData, rowIndex: index }, (rowData.key || rowData.id)))) : (jsx("tr", { children: jsx("td", { children: jsx(Empty, { ...restEmptyProps, className: cx(tableClasses.bodyEmpty, emptyComponentClassName), fullHeight: emptyComponentFullHeight, children: emptyComponentChildren }) }) })), (fetchMore === null || fetchMore === void 0 ? void 0 : fetchMore.isFetching) ? (jsx("tr", { className: tableClasses.bodyFetchMore, children: jsx("td", { "aria-label": "Loading", children: jsx(Loading, { loading: true }) }) })) : null] }));
21
+ return (jsxs("tbody", { ...rest, ref: ref, className: cx(tableClasses.body, className), children: [currentDataSource.length ? currentDataSource.map((rowData, index) => (jsx(TableBodyRow, { className: rowClassName === null || rowClassName === void 0 ? void 0 : rowClassName(rowData), rowData: rowData, rowIndex: index }, (rowData.key || rowData.id)))) : (jsx("tr", { children: jsx("td", { children: jsx(Empty, { ...restEmptyProps, className: cx(tableClasses.bodyEmpty, emptyComponentClassName), fullHeight: emptyComponentFullHeight, children: emptyComponentChildren }) }) })), (fetchMore === null || fetchMore === void 0 ? void 0 : fetchMore.isFetching) ? (jsx("tr", { className: tableClasses.bodyFetchMore, children: jsx("td", { "aria-label": "Loading", children: jsx(Loading, { loading: true }) }) })) : null] }));
22
22
  });
23
23
  var TableBody$1 = TableBody;
24
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mezzanine-ui/react",
3
- "version": "0.14.5",
3
+ "version": "0.14.7",
4
4
  "description": "React components for mezzanine-ui",
5
5
  "author": "Mezzanine",
6
6
  "repository": {
@@ -28,9 +28,9 @@
28
28
  "react-dom": "^18.2.0"
29
29
  },
30
30
  "dependencies": {
31
- "@mezzanine-ui/core": "^0.14.5",
32
- "@mezzanine-ui/icons": "^0.14.5",
33
- "@mezzanine-ui/system": "^0.14.5",
31
+ "@mezzanine-ui/core": "^0.14.7",
32
+ "@mezzanine-ui/icons": "^0.14.7",
33
+ "@mezzanine-ui/system": "^0.14.7",
34
34
  "@popperjs/core": "^2.11.6",
35
35
  "@types/react-transition-group": "^4.4.8",
36
36
  "clsx": "^2.0.0",