diginet-core-ui 1.4.51-beta.0 → 1.4.51-beta.1

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 () => {
@@ -856,6 +903,50 @@ const DateRangePicker = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, refe
856
903
  const endIcon = actionIconAt === 'end' && iconComp;
857
904
  const startIcon = actionIconAt === 'start' && iconComp;
858
905
  const footerMemo = jsx("div", {
906
+ css: _FooterContainerCSS
907
+ }, jsx("div", {
908
+ css: _DateOptionsCSS
909
+ }, jsx(Button, {
910
+ size: "medium",
911
+ labelProps: {
912
+ type: 'h4',
913
+ style: {
914
+ textTransform: 'initial'
915
+ }
916
+ },
917
+ onClick: () => onClickPresetDate('today'),
918
+ color: focusBtn === 'today' && 'primary'
919
+ }, todayText), jsx(Button, {
920
+ size: "medium",
921
+ labelProps: {
922
+ type: 'h4',
923
+ style: {
924
+ textTransform: 'initial'
925
+ }
926
+ },
927
+ onClick: () => onClickPresetDate('yesterday'),
928
+ color: focusBtn === 'yesterday' && 'primary'
929
+ }, yesterdayText), jsx(Button, {
930
+ size: "medium",
931
+ labelProps: {
932
+ type: 'h4',
933
+ style: {
934
+ textTransform: 'initial'
935
+ }
936
+ },
937
+ onClick: () => onClickPresetDate('thisWeek'),
938
+ color: focusBtn === 'thisWeek' && 'primary'
939
+ }, thisWeekText), jsx(Button, {
940
+ size: "medium",
941
+ labelProps: {
942
+ type: 'h4',
943
+ style: {
944
+ textTransform: 'initial'
945
+ }
946
+ },
947
+ onClick: () => onClickPresetDate('thisMonth'),
948
+ color: focusBtn === 'thisMonth' && 'primary'
949
+ }, thisMonthText)), jsx("div", {
859
950
  css: _ControlContainerCSS,
860
951
  className: unique.footer,
861
952
  ref: footerRef
@@ -874,7 +965,7 @@ const DateRangePicker = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((inProps, refe
874
965
  color: 'info',
875
966
  className: unique.confirm,
876
967
  onClick: onConfirm
877
- }, confirmText));
968
+ }, confirmText)));
878
969
  const leftCalendarComp = jsx("div", {
879
970
  css: generateCalendarCSS(unique, false, false, theme)
880
971
  }, 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 +1120,16 @@ const ControlContainerCSS = ({
1029
1120
  ${justifyEnd};
1030
1121
  margin: ${spacing([0, 4, 4])};
1031
1122
  `;
1123
+ const FooterContainerCSS = () => css`
1124
+ ${displayFlex};
1125
+ ${justifyBetween};
1126
+ `;
1127
+ const DateOptionsCSS = ({
1128
+ spacing
1129
+ }) => css`
1130
+ ${displayFlex};
1131
+ padding-left: ${spacing(4)}px;
1132
+ `;
1032
1133
  const pickerCSS = {
1033
1134
  backGr: ({
1034
1135
  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.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",