diginet-core-ui 1.4.51-beta.0 → 1.4.51-beta.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.
@@ -7,7 +7,7 @@ import locale from "../../../locale";
7
7
  import PropTypes from 'prop-types';
8
8
  import { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
9
9
  import { render } from 'react-dom';
10
- import { bgColor, borderRadius4px, cursorPointer, displayBlock, displayFlex, displayNone, flexCol, flexRow, invisible, justifyEnd, left, parseHeight, parseMaxWidth, parseMinWidth, pointerEventsNone, positionFixed, shadowLarge, textCenter, top, userSelectNone, whiteSpaceNoWrap, z } from "../../../styles/general";
10
+ import { bgColor, borderRadius4px, cursorPointer, displayBlock, displayFlex, displayNone, flexCol, flexRow, invisible, justifyBetween, justifyEnd, left, parseHeight, parseMaxWidth, parseMinWidth, pointerEventsNone, positionFixed, shadowLarge, textCenter, top, userSelectNone, whiteSpaceNoWrap, z } from "../../../styles/general";
11
11
  import { useTheme } from "../../../theme";
12
12
  import { capitalizeSentenceCase, classNames, isEqual, date as moment, randomString, updatePosition } from "../../../utils";
13
13
  import { generateCalendarCSS, onUpdateNavigator, renderHeader, renderNavigator } from "../calendar/function";
@@ -128,6 +128,7 @@ const DateRangePicker = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, refe
128
128
  const [, setValueFr] = useState(Date.now());
129
129
  const [, setValueTo] = useState(Date.now());
130
130
  const [, setSelected] = useState(Date.now());
131
+ const [focusBtn, setFocusBtn] = useState('today');
131
132
  const [valueState, setValueState] = useState();
132
133
  const navigatorFromRefs = {
133
134
  doubleLeft: useRef(null),
@@ -148,7 +149,13 @@ const DateRangePicker = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, refe
148
149
  const cancelText = getGlobal(['cancel']);
149
150
  const confirmText = getGlobal(['confirm']);
150
151
  const unitText = getGlobal([unitCount]);
152
+ const todayText = getGlobal(['today']);
153
+ const yesterdayText = getGlobal(['yesterday']);
154
+ const thisWeekText = getGlobal(['thisWeek']);
155
+ const thisMonthText = getGlobal(['thisMonth']);
151
156
  const _ControlContainerCSS = ControlContainerCSS(theme);
157
+ const _FooterContainerCSS = FooterContainerCSS(theme);
158
+ const _DateOptionsCSS = DateOptionsCSS(theme);
152
159
  const updateValues = useCallback(v => {
153
160
  values.current = v;
154
161
  setValues();
@@ -761,6 +768,46 @@ const DateRangePicker = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, refe
761
768
  !!onChange && onChange(e);
762
769
  onSwap(true);
763
770
  };
771
+ const onClickPresetDate = type => {
772
+ if (!type) return;
773
+ setFocusBtn(type);
774
+ let value = [];
775
+ const currentDay = new Date();
776
+ switch (type) {
777
+ case 'today':
778
+ value = [new Date(Date.now() - 25200000).valueOf()];
779
+ break;
780
+ case 'yesterday':
781
+ {
782
+ const yesterday = new Date(Date.now() - 86400000 - 25200000);
783
+ value = [new Date(Date.now() - 86400000 - 25200000).valueOf()];
784
+ valueFr.current = yesterday;
785
+ break;
786
+ }
787
+ case 'thisWeek':
788
+ {
789
+ const first = currentDay.getDate() - currentDay.getDay() + 1; // First day is the day of the month - the day of the week
790
+ const last = first + 6; // last day is the first day + 6
791
+ const firstday = new Date(currentDay.setDate(first)).setHours(0, 0, 0).valueOf();
792
+ const lastday = new Date(currentDay.setDate(last)).setHours(0, 0, 0).valueOf();
793
+ value = [firstday, lastday];
794
+ break;
795
+ }
796
+ case 'thisMonth':
797
+ {
798
+ let firstday = new Date(currentDay.getFullYear(), currentDay.getMonth(), 1).valueOf();
799
+ let lastday = new Date(currentDay.getFullYear(), currentDay.getMonth() + 1, 0).valueOf();
800
+ value = [firstday, lastday];
801
+ break;
802
+ }
803
+ default:
804
+ break;
805
+ }
806
+ updateValues(value);
807
+ updateSelected(countDay(values.current));
808
+ renderPicker();
809
+ controls ? setButtonState() : onChangeValue(values.current);
810
+ };
764
811
  useEffect(() => {
765
812
  update(defaultValue);
766
813
  return () => {
@@ -768,9 +815,11 @@ const DateRangePicker = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, refe
768
815
  };
769
816
  }, []);
770
817
  useEffect(() => {
771
- if (value) {
818
+ if (value && value[0] && value[1]) {
772
819
  update(value);
773
820
  closePicker();
821
+ } else {
822
+ ipRef.current.value = '';
774
823
  }
775
824
  }, [value]);
776
825
  useEffect(() => {
@@ -856,6 +905,50 @@ const DateRangePicker = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, refe
856
905
  const endIcon = actionIconAt === 'end' && iconComp;
857
906
  const startIcon = actionIconAt === 'start' && iconComp;
858
907
  const footerMemo = jsx("div", {
908
+ css: _FooterContainerCSS
909
+ }, jsx("div", {
910
+ css: _DateOptionsCSS
911
+ }, jsx(Button, {
912
+ size: "medium",
913
+ labelProps: {
914
+ type: 'h4',
915
+ style: {
916
+ textTransform: 'initial'
917
+ }
918
+ },
919
+ onClick: () => onClickPresetDate('today'),
920
+ color: focusBtn === 'today' && 'primary'
921
+ }, todayText), jsx(Button, {
922
+ size: "medium",
923
+ labelProps: {
924
+ type: 'h4',
925
+ style: {
926
+ textTransform: 'initial'
927
+ }
928
+ },
929
+ onClick: () => onClickPresetDate('yesterday'),
930
+ color: focusBtn === 'yesterday' && 'primary'
931
+ }, yesterdayText), jsx(Button, {
932
+ size: "medium",
933
+ labelProps: {
934
+ type: 'h4',
935
+ style: {
936
+ textTransform: 'initial'
937
+ }
938
+ },
939
+ onClick: () => onClickPresetDate('thisWeek'),
940
+ color: focusBtn === 'thisWeek' && 'primary'
941
+ }, thisWeekText), jsx(Button, {
942
+ size: "medium",
943
+ labelProps: {
944
+ type: 'h4',
945
+ style: {
946
+ textTransform: 'initial'
947
+ }
948
+ },
949
+ onClick: () => onClickPresetDate('thisMonth'),
950
+ color: focusBtn === 'thisMonth' && 'primary'
951
+ }, thisMonthText)), jsx("div", {
859
952
  css: _ControlContainerCSS,
860
953
  className: unique.footer,
861
954
  ref: footerRef
@@ -874,7 +967,7 @@ const DateRangePicker = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, refe
874
967
  color: 'info',
875
968
  className: unique.confirm,
876
969
  onClick: onConfirm
877
- }, confirmText));
970
+ }, confirmText)));
878
971
  const leftCalendarComp = jsx("div", {
879
972
  css: generateCalendarCSS(unique, false, false, theme)
880
973
  }, renderNavigator(unique, navigatorFromRefs, e => setPrevTime(e, 'year', valueFr.current, 'from'), e => setPrevTime(e, 'month', valueFr.current, 'from'), e => setNextTime(e, 'month', valueFr.current, 'from'), e => setNextTime(e, 'year', valueFr.current, 'from')), jsx("div", {
@@ -1029,6 +1122,16 @@ const ControlContainerCSS = ({
1029
1122
  ${justifyEnd};
1030
1123
  margin: ${spacing([0, 4, 4])};
1031
1124
  `;
1125
+ const FooterContainerCSS = () => css`
1126
+ ${displayFlex};
1127
+ ${justifyBetween};
1128
+ `;
1129
+ const DateOptionsCSS = ({
1130
+ spacing
1131
+ }) => css`
1132
+ ${displayFlex};
1133
+ padding-left: ${spacing(4)}px;
1134
+ `;
1032
1135
  const pickerCSS = {
1033
1136
  backGr: ({
1034
1137
  zIndex
package/global/index.js CHANGED
@@ -45,6 +45,11 @@ const globalObject = {
45
45
  label: 'Thời gian',
46
46
  weekdaysLong: ['Hai', 'Ba', 'Tư', 'Năm', 'Sáu', 'Bảy', 'CN'],
47
47
  weekdaysShort: ['H', 'B', 'T', 'N', 'S', 'B', 'C'],
48
+ // Daterange Picker
49
+ today: 'Hôm nay',
50
+ yesterday: 'Hôm qua',
51
+ thisWeek: 'Tuần này',
52
+ thisMonth: 'Tháng này',
48
53
  // Time Picker
49
54
  months: {
50
55
  full: ['tháng 01', 'tháng 02', 'tháng 03', 'tháng 04', 'tháng 05', 'tháng 06', 'tháng 07', 'tháng 08', 'tháng 09', 'tháng 10', 'tháng 11', 'tháng 12'],
@@ -120,6 +125,11 @@ const globalObject = {
120
125
  label: 'Time',
121
126
  weekdaysLong: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
122
127
  weekdaysShort: ['M', 'T', 'W', 'T', 'F', 'S', 'S'],
128
+ // Daterange Picker
129
+ today: 'Today',
130
+ yesterday: 'Yesterday',
131
+ thisWeek: 'This week',
132
+ thisMonth: 'This month',
123
133
  // Time Picker
124
134
  months: {
125
135
  full: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.4.51-beta.0",
3
+ "version": "1.4.51-beta.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",