nntc-ui 0.0.70 → 0.0.72

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.
Files changed (3) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +44 -32
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { ButtonHTMLAttributes, ReactNode, DetailedHTMLProps, InputHTMLAttributes, PropsWithChildren, ChangeEvent, JSX, MutableRefObject, ReactElement, CSSProperties, HTMLProps, ElementType } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import defaultDayjs from 'dayjs';
4
5
  import { Placement } from '@floating-ui/react';
5
6
 
6
7
  type PropsObject = {
@@ -78,6 +79,8 @@ interface Props$k {
78
79
  defaultValues?: (string | undefined)[];
79
80
  onClear?: () => void;
80
81
  onValueChange?: (values: (string | undefined)[]) => void;
82
+ /** Локализованный инстанс dayjs из приложения (например, после dayjs.locale('ru')) */
83
+ dayjs?: typeof defaultDayjs;
81
84
  }
82
85
  declare function DateTime(props: UiProps<Props$k> & DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>): react_jsx_runtime.JSX.Element;
83
86
 
@@ -304,6 +307,7 @@ interface TableColumn {
304
307
 
305
308
  interface VirtualTableRef {
306
309
  resetFilters: () => void;
310
+ resetSorts: () => void;
307
311
  }
308
312
 
309
313
  type Size$1 = 'medium' | 'small';
package/index.js CHANGED
@@ -841,7 +841,7 @@ function Select(props) {
841
841
 
842
842
  // src/components/common/DateTime/DateTime.tsx
843
843
  import classnames7 from "classnames";
844
- import dayjs2 from "dayjs";
844
+ import defaultDayjs2 from "dayjs";
845
845
  import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef3, useState as useState5 } from "react";
846
846
  import { mergeRefs as mergeRefs3 } from "react-merge-refs";
847
847
 
@@ -879,7 +879,7 @@ var dateTime_default = {
879
879
 
880
880
  // src/components/common/DateTime/ui/CalendarPopover/CalendarPopover.tsx
881
881
  import classNames2 from "classnames";
882
- import dayjs from "dayjs";
882
+ import defaultDayjs from "dayjs";
883
883
  import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo2, useState as useState4 } from "react";
884
884
 
885
885
  // src/components/common/DateTime/ui/CalendarPopover/calendarPopover.module.css
@@ -948,6 +948,7 @@ var calendarPopover_default = {
948
948
  import { Fragment as Fragment2, jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
949
949
  function CalendarPopover(props) {
950
950
  const {
951
+ dayjs: dayjsFromProps,
951
952
  componentSize,
952
953
  isPeriod = true,
953
954
  valueType = "date",
@@ -957,20 +958,24 @@ function CalendarPopover(props) {
957
958
  onClear,
958
959
  classes
959
960
  } = props;
961
+ const dayjs3 = dayjsFromProps ?? defaultDayjs;
960
962
  const [viewType, setViewType] = useState4(valueType === "year" ? "yearsRange" : "month");
961
963
  const [currentItem, setCurrentItem] = useState4({
962
- year: dayjs().year(),
963
- month: dayjs().month()
964
+ year: dayjs3().year(),
965
+ month: dayjs3().month()
964
966
  });
965
- const [startDate, setStartDate] = useState4(initStartDate ? dayjs(initStartDate).startOf("D").valueOf() : void 0);
966
- const [endDate, setEndDate] = useState4(initEndDate ? dayjs(initEndDate).startOf("D").valueOf() : void 0);
967
- const startDateMonth = useMemo2(() => startDate ? dayjs(startDate).startOf("M").valueOf() : void 0, [startDate]);
968
- const endDateMonth = useMemo2(() => endDate ? dayjs(endDate).startOf("M").valueOf() : void 0, [endDate]);
969
- const startYear = useMemo2(() => startDate ? dayjs(startDate).year() : void 0, [startDate]);
970
- const endYear = useMemo2(() => endDate ? dayjs(endDate).year() : void 0, [endDate]);
967
+ const [startDate, setStartDate] = useState4(initStartDate ? dayjs3(initStartDate).startOf("D").valueOf() : void 0);
968
+ const [endDate, setEndDate] = useState4(initEndDate ? dayjs3(initEndDate).startOf("D").valueOf() : void 0);
969
+ const startDateMonth = useMemo2(
970
+ () => startDate ? dayjs3(startDate).startOf("M").valueOf() : void 0,
971
+ [startDate, dayjs3]
972
+ );
973
+ const endDateMonth = useMemo2(() => endDate ? dayjs3(endDate).startOf("M").valueOf() : void 0, [endDate, dayjs3]);
974
+ const startYear = useMemo2(() => startDate ? dayjs3(startDate).year() : void 0, [startDate, dayjs3]);
975
+ const endYear = useMemo2(() => endDate ? dayjs3(endDate).year() : void 0, [endDate, dayjs3]);
971
976
  const currentDate = useMemo2(
972
- () => dayjs(new Date(currentItem.year, currentItem.month, 1)).startOf(viewType === "month" ? "M" : "y"),
973
- [currentItem, viewType]
977
+ () => dayjs3(new Date(currentItem.year, currentItem.month, 1)).startOf(viewType === "month" ? "M" : "y"),
978
+ [currentItem, viewType, dayjs3]
974
979
  );
975
980
  const daysInMonth = currentDate.daysInMonth();
976
981
  const firstDayOfWeek = currentDate.startOf("M").day();
@@ -986,26 +991,26 @@ function CalendarPopover(props) {
986
991
  }
987
992
  if (valueType === "year") {
988
993
  if (!isPeriod && startDate) {
989
- changeDates(dayjs(startDate).format("YYYY"));
994
+ changeDates(dayjs3(startDate).format("YYYY"));
990
995
  return;
991
996
  }
992
997
  if (isPeriod && startDate && endDate) {
993
- changeDates(dayjs(startDate).format("YYYY"), dayjs(endDate).format("YYYY"));
998
+ changeDates(dayjs3(startDate).format("YYYY"), dayjs3(endDate).format("YYYY"));
994
999
  return;
995
1000
  }
996
1001
  return;
997
1002
  }
998
1003
  if (!isPeriod && startDate) {
999
- changeDates(dayjs(startDate).format());
1004
+ changeDates(dayjs3(startDate).format());
1000
1005
  return;
1001
1006
  }
1002
1007
  if (isPeriod && startDate && endDate) {
1003
- changeDates(dayjs(startDate).format(), dayjs(endDate).format());
1008
+ changeDates(dayjs3(startDate).format(), dayjs3(endDate).format());
1004
1009
  }
1005
1010
  }, [startDate, endDate, isPeriod, valueType, changeDates, onClear]);
1006
1011
  const changeCurrentItem = useCallback3(
1007
1012
  (count) => () => {
1008
- const baseDate = dayjs(new Date(currentItem.year, currentItem.month, 1));
1013
+ const baseDate = dayjs3(new Date(currentItem.year, currentItem.month, 1));
1009
1014
  const step = viewType === "yearsRange" ? count * 20 : count;
1010
1015
  const unit = viewType === "month" ? "month" : "year";
1011
1016
  const tempDate = baseDate.add(step, unit);
@@ -1037,7 +1042,7 @@ function CalendarPopover(props) {
1037
1042
  );
1038
1043
  const setYear = useCallback3(
1039
1044
  (cellYear) => () => {
1040
- const cellDate = dayjs(new Date(cellYear, 0, 1)).startOf("y").valueOf();
1045
+ const cellDate = dayjs3(new Date(cellYear, 0, 1)).startOf("y").valueOf();
1041
1046
  if (!isPeriod) {
1042
1047
  if (startDate === cellDate) {
1043
1048
  setStartDate(void 0);
@@ -1136,8 +1141,8 @@ function CalendarPopover(props) {
1136
1141
  const today = useCallback3(
1137
1142
  (e) => {
1138
1143
  setCurrentItem({
1139
- year: dayjs().year(),
1140
- month: dayjs().month()
1144
+ year: dayjs3().year(),
1145
+ month: dayjs3().month()
1141
1146
  });
1142
1147
  e.currentTarget.blur();
1143
1148
  },
@@ -1350,10 +1355,12 @@ function DateTime(props) {
1350
1355
  values,
1351
1356
  onClear,
1352
1357
  onValueChange,
1358
+ dayjs: dayjsFromProps,
1353
1359
  classes,
1354
1360
  ref,
1355
1361
  ...inputProps
1356
1362
  } = props;
1363
+ const dayjs3 = dayjsFromProps ?? defaultDayjs2;
1357
1364
  const [stateValues, setStateValues] = useState5(
1358
1365
  values !== void 0 ? values : defaultValues
1359
1366
  );
@@ -1401,9 +1408,9 @@ function DateTime(props) {
1401
1408
  className: classnames7(input3, classes?.input),
1402
1409
  placeholder,
1403
1410
  ...inputProps,
1404
- value: stateValues?.[0] ? isPeriod && stateValues[1] ? `${dayjs2(stateValues[0]).format(valueType === "year" ? "YYYY" : "DD.MM.YYYY")} - ${dayjs2(
1411
+ value: stateValues?.[0] ? isPeriod && stateValues[1] ? `${dayjs3(stateValues[0]).format(valueType === "year" ? "YYYY" : "DD.MM.YYYY")} - ${dayjs3(
1405
1412
  stateValues[1]
1406
- ).format(valueType === "year" ? "YYYY" : "DD.MM.YYYY")}` : `${dayjs2(stateValues[0]).format(valueType === "year" ? "YYYY" : "DD.MM.YYYY")}` : "",
1413
+ ).format(valueType === "year" ? "YYYY" : "DD.MM.YYYY")}` : `${dayjs3(stateValues[0]).format(valueType === "year" ? "YYYY" : "DD.MM.YYYY")}` : "",
1407
1414
  onChange: () => {
1408
1415
  },
1409
1416
  onClick: inputClickHandler
@@ -1419,6 +1426,7 @@ function DateTime(props) {
1419
1426
  description: /* @__PURE__ */ jsx14(
1420
1427
  CalendarPopover,
1421
1428
  {
1429
+ dayjs: dayjs3,
1422
1430
  classes,
1423
1431
  componentSize,
1424
1432
  isPeriod,
@@ -2754,7 +2762,7 @@ function Tabs(props) {
2754
2762
  import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
2755
2763
  import { defaultRangeExtractor, useVirtualizer } from "@tanstack/react-virtual";
2756
2764
  import classnames22 from "classnames";
2757
- import dayjs4 from "dayjs";
2765
+ import dayjs2 from "dayjs";
2758
2766
  import {
2759
2767
  Fragment as Fragment8,
2760
2768
  forwardRef as forwardRef8,
@@ -3473,14 +3481,14 @@ var getPrevHorizontalHeaders = (headers, currentIndex) => {
3473
3481
  };
3474
3482
 
3475
3483
  // src/components/view/VirtualTable/utils/recursiveFilter.ts
3476
- import dayjs3 from "dayjs";
3484
+ import dayjs from "dayjs";
3477
3485
  var recursiveFilter = (rows, filterBy) => {
3478
3486
  if (filterBy.length) {
3479
3487
  const filterByItem = filterBy[filterBy.length - 1];
3480
- const startDate = filterByItem.type === "dateRange" ? dayjs3(filterByItem.values[0]) : null;
3481
- const endDate = filterByItem.type === "dateRange" ? dayjs3(filterByItem.values[1]) : null;
3488
+ const startDate = filterByItem.type === "dateRange" ? dayjs(filterByItem.values[0]) : null;
3489
+ const endDate = filterByItem.type === "dateRange" ? dayjs(filterByItem.values[1]) : null;
3482
3490
  const filtered = filterByItem.values.length ? rows.filter((row) => {
3483
- const dateValue = filterByItem.type === "dateRange" ? dayjs3(row[filterByItem.columnName].value) : null;
3491
+ const dateValue = filterByItem.type === "dateRange" ? dayjs(row[filterByItem.columnName].value) : null;
3484
3492
  return (row[filterByItem.columnName] ? filterByItem.type === "dateRange" ? (dateValue.isAfter(startDate) || dateValue.isSame(startDate)) && (dateValue.isBefore(endDate) || dateValue.isSame(endDate)) : filterByItem.type === "numberRange" ? row[filterByItem.columnName].value >= filterByItem.values[0] && row[filterByItem.columnName].value <= filterByItem.values[1] : filterByItem.values.includes((row[filterByItem.columnName].value || "")?.toString()) : filterByItem.values.includes("")) || row.isNew?.value === 1;
3485
3493
  }) : rows;
3486
3494
  return recursiveFilter(filtered, filterBy.slice(0, filterBy.length - 1));
@@ -3558,15 +3566,15 @@ var VirtualTable = forwardRef8((props, ref) => {
3558
3566
  const memoizedData = useMemo8(() => {
3559
3567
  const newRows = [...rows];
3560
3568
  const nextFilterBy = filterBy.filter((filterByItem) => {
3561
- const startDate = filterByItem.type === "dateRange" ? dayjs4(filterByItem.values[0]) : null;
3562
- const endDate = filterByItem.type === "dateRange" ? dayjs4(filterByItem.values[1]) : null;
3569
+ const startDate = filterByItem.type === "dateRange" ? dayjs2(filterByItem.values[0]) : null;
3570
+ const endDate = filterByItem.type === "dateRange" ? dayjs2(filterByItem.values[1]) : null;
3563
3571
  return rows.some((row) => {
3564
- const dateValue = filterByItem.type === "dateRange" ? dayjs4(row[filterByItem.columnName].value) : null;
3572
+ const dateValue = filterByItem.type === "dateRange" ? dayjs2(row[filterByItem.columnName].value) : null;
3565
3573
  return row[filterByItem.columnName] ? filterByItem.type === "dateRange" ? (dateValue.isAfter(startDate) || dateValue.isSame(startDate)) && (dateValue.isBefore(endDate) || dateValue.isSame(endDate)) : filterByItem.type === "numberRange" ? row[filterByItem.columnName].value >= filterByItem.values[0] && row[filterByItem.columnName].value <= filterByItem.values[1] : filterByItem.values.includes((row[filterByItem.columnName].value || "")?.toString()) : filterByItem.values.includes("");
3566
3574
  });
3567
3575
  });
3568
3576
  const filtered = nextFilterBy.length ? recursiveFilter(newRows, nextFilterBy) : filterBy.some(
3569
- (fb) => fb.type === "numberRange" && fb.values.some((v) => v !== Infinity && v !== -Infinity) || fb.type === "dateRange" && fb.values.some((v) => !dayjs4(v).isSame(dayjs4(0)) && !dayjs4(v).isSame(dayjs4(Number.MAX_SAFE_INTEGER)))
3577
+ (fb) => fb.type === "numberRange" && fb.values.some((v) => v !== Infinity && v !== -Infinity) || fb.type === "dateRange" && fb.values.some((v) => !dayjs2(v).isSame(dayjs2(0)) && !dayjs2(v).isSame(dayjs2(Number.MAX_SAFE_INTEGER)))
3570
3578
  ) ? [] : newRows;
3571
3579
  const sorted = sortBy.length ? recursiveSort(filtered, sortBy) : filtered;
3572
3580
  const result = rowNumberColumnId ? sorted.map((row, index) => ({
@@ -3656,8 +3664,12 @@ var VirtualTable = forwardRef8((props, ref) => {
3656
3664
  const resetFilters = () => {
3657
3665
  setFilterBy([]);
3658
3666
  };
3667
+ const resetSorts = () => {
3668
+ setSortBy([{ columnName: "isNew", direction: "desc" }]);
3669
+ };
3659
3670
  useImperativeHandle(ref, () => ({
3660
- resetFilters
3671
+ resetFilters,
3672
+ resetSorts
3661
3673
  }));
3662
3674
  useEffect8(() => {
3663
3675
  if (tableContainerRef?.current) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nntc-ui",
3
- "version": "0.0.70",
3
+ "version": "0.0.72",
4
4
  "author": "NNTC",
5
5
  "description": "React UI-kit for NNTC",
6
6
  "type": "module",