@ncds/ui-admin 0.0.16 → 0.0.17

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.
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RangeDatePicker = void 0;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _react = require("react");
9
+ var _lodash = require("lodash");
10
+ var _moment = _interopRequireDefault(require("moment"));
11
+ var _DatePicker = require("./DatePicker");
12
+ var _utils = require("./utils");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ var __assign = void 0 && (void 0).__assign || function () {
15
+ __assign = Object.assign || function (t) {
16
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
17
+ s = arguments[i];
18
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
19
+ }
20
+ return t;
21
+ };
22
+ return __assign.apply(this, arguments);
23
+ };
24
+ var RangeDatePicker = function (_a) {
25
+ var startDateOptions = _a.startDateOptions,
26
+ endDateOptions = _a.endDateOptions,
27
+ validationOption = _a.validationOption,
28
+ onDateValidation = _a.onDateValidation;
29
+ var resetDateAndAlert = (0, _react.useCallback)(function (type) {
30
+ var _a, _b;
31
+ var newDate = type === 'start' ? ((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.startDate) || '' : ((_b = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _b === void 0 ? void 0 : _b.endDate) || '';
32
+ if (type === 'start') {
33
+ startDateOptions.onChangeDate(newDate);
34
+ } else {
35
+ endDateOptions.onChangeDate(newDate);
36
+ }
37
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
38
+ type: 'end',
39
+ errorType: 'reset',
40
+ newDate: newDate,
41
+ currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
42
+ });
43
+ }, [startDateOptions, endDateOptions, validationOption, onDateValidation]);
44
+ var changeSettingDateAndAlert = (0, _react.useCallback)(function (type, isOverPeriod) {
45
+ if (isOverPeriod === void 0) {
46
+ isOverPeriod = false;
47
+ }
48
+ var _a = validationOption.setting,
49
+ unit = _a.unit,
50
+ period = _a.period;
51
+ var newDate = '';
52
+ if (type === 'start') {
53
+ newDate = (0, _utils.getDateFormat)((0, _moment.default)(startDateOptions.currentDate).add(period, unit).toDate());
54
+ } else {
55
+ newDate = (0, _utils.getDateFormat)((0, _moment.default)(endDateOptions.currentDate).subtract(period, unit).toDate());
56
+ }
57
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
58
+ type: type,
59
+ errorType: isOverPeriod ? 'period' : 'overlap',
60
+ newDate: newDate,
61
+ currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
62
+ });
63
+ }, [startDateOptions, endDateOptions, validationOption, onDateValidation]);
64
+ var validateDateType = function (date) {
65
+ return !isNaN(Date.parse(date));
66
+ };
67
+ (0, _react.useEffect)(function () {
68
+ var _a;
69
+ var needResetDate = validateDateType(startDateOptions.currentDate) && !(0, _lodash.isNil)((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.startDate) && (0, _moment.default)(startDateOptions.currentDate).isAfter(endDateOptions.currentDate);
70
+ if (needResetDate) {
71
+ resetDateAndAlert('start');
72
+ return;
73
+ }
74
+ if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting)) {
75
+ return;
76
+ }
77
+ var isOverDate = (0, _moment.default)(startDateOptions.currentDate).isAfter(endDateOptions.currentDate);
78
+ var _b = validationOption.setting,
79
+ unit = _b.unit,
80
+ period = _b.period;
81
+ var isValidPeriod = (0, _moment.default)(startDateOptions.currentDate).isSameOrAfter((0, _moment.default)(endDateOptions.currentDate).subtract(period, unit));
82
+ if (isOverDate) {
83
+ changeSettingDateAndAlert('start');
84
+ }
85
+ if (!isValidPeriod) {
86
+ changeSettingDateAndAlert('start', !isValidPeriod);
87
+ }
88
+ }, [startDateOptions.currentDate]);
89
+ (0, _react.useEffect)(function () {
90
+ var _a;
91
+ var needResetDate = validateDateType(endDateOptions.currentDate) && !(0, _lodash.isNil)((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.endDate) && (0, _moment.default)(endDateOptions.currentDate).isBefore(startDateOptions.currentDate);
92
+ if (needResetDate) {
93
+ resetDateAndAlert('end');
94
+ return;
95
+ }
96
+ var isNotTodayEndDate = endDateOptions.currentDate !== (0, _utils.getDateFormat)();
97
+ if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting) || !isNotTodayEndDate) {
98
+ return;
99
+ }
100
+ var isOverDate = (0, _moment.default)(startDateOptions.currentDate).isAfter(endDateOptions.currentDate);
101
+ var _b = validationOption.setting,
102
+ unit = _b.unit,
103
+ period = _b.period;
104
+ var isValidPeriod = (0, _moment.default)(endDateOptions.currentDate).isSameOrBefore((0, _moment.default)(startDateOptions.currentDate).add(period, unit));
105
+ if (isOverDate) {
106
+ changeSettingDateAndAlert('end');
107
+ }
108
+ if (!isValidPeriod) {
109
+ changeSettingDateAndAlert('end', !isValidPeriod);
110
+ }
111
+ }, [endDateOptions.currentDate]);
112
+ return (0, _jsxRuntime.jsxs)("div", __assign({
113
+ className: "ncua-range-date-picker"
114
+ }, {
115
+ children: [(0, _jsxRuntime.jsx)(_DatePicker.DatePicker, __assign({}, startDateOptions)), "-", (0, _jsxRuntime.jsx)(_DatePicker.DatePicker, __assign({}, endDateOptions))]
116
+ }));
117
+ };
118
+ exports.RangeDatePicker = RangeDatePicker;
@@ -13,4 +13,26 @@ Object.keys(_DatePicker).forEach(function (key) {
13
13
  return _DatePicker[key];
14
14
  }
15
15
  });
16
+ });
17
+ var _RangeDatePicker = require("./RangeDatePicker");
18
+ Object.keys(_RangeDatePicker).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _RangeDatePicker[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _RangeDatePicker[key];
25
+ }
26
+ });
27
+ });
28
+ var _utils = require("./utils");
29
+ Object.keys(_utils).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _utils[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _utils[key];
36
+ }
37
+ });
16
38
  });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDateFormat = getDateFormat;
7
+ exports.getToday = getToday;
8
+ var _moment = _interopRequireDefault(require("moment"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function getToday() {
11
+ return (0, _moment.default)().toDate();
12
+ }
13
+ function getDateFormat(date) {
14
+ if (date === void 0) {
15
+ date = getToday();
16
+ }
17
+ return (0, _moment.default)(date).format('YYYY-MM-DD');
18
+ }
@@ -0,0 +1,110 @@
1
+ var __assign = this && this.__assign || function () {
2
+ __assign = Object.assign || function (t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
+ }
7
+ return t;
8
+ };
9
+ return __assign.apply(this, arguments);
10
+ };
11
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ import { useCallback, useEffect } from 'react';
13
+ import { isNil } from 'lodash';
14
+ import moment from 'moment';
15
+ import { DatePicker } from './DatePicker';
16
+ import { getDateFormat } from './utils';
17
+ export var RangeDatePicker = function (_a) {
18
+ var startDateOptions = _a.startDateOptions,
19
+ endDateOptions = _a.endDateOptions,
20
+ validationOption = _a.validationOption,
21
+ onDateValidation = _a.onDateValidation;
22
+ var resetDateAndAlert = useCallback(function (type) {
23
+ var _a, _b;
24
+ var newDate = type === 'start' ? ((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.startDate) || '' : ((_b = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _b === void 0 ? void 0 : _b.endDate) || '';
25
+ if (type === 'start') {
26
+ startDateOptions.onChangeDate(newDate);
27
+ } else {
28
+ endDateOptions.onChangeDate(newDate);
29
+ }
30
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
31
+ type: 'end',
32
+ errorType: 'reset',
33
+ newDate: newDate,
34
+ currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
35
+ });
36
+ }, [startDateOptions, endDateOptions, validationOption, onDateValidation]);
37
+ var changeSettingDateAndAlert = useCallback(function (type, isOverPeriod) {
38
+ if (isOverPeriod === void 0) {
39
+ isOverPeriod = false;
40
+ }
41
+ var _a = validationOption.setting,
42
+ unit = _a.unit,
43
+ period = _a.period;
44
+ var newDate = '';
45
+ if (type === 'start') {
46
+ newDate = getDateFormat(moment(startDateOptions.currentDate).add(period, unit).toDate());
47
+ } else {
48
+ newDate = getDateFormat(moment(endDateOptions.currentDate).subtract(period, unit).toDate());
49
+ }
50
+ onDateValidation === null || onDateValidation === void 0 ? void 0 : onDateValidation({
51
+ type: type,
52
+ errorType: isOverPeriod ? 'period' : 'overlap',
53
+ newDate: newDate,
54
+ currentDate: type === 'start' ? startDateOptions.currentDate : endDateOptions.currentDate
55
+ });
56
+ }, [startDateOptions, endDateOptions, validationOption, onDateValidation]);
57
+ var validateDateType = function (date) {
58
+ return !isNaN(Date.parse(date));
59
+ };
60
+ useEffect(function () {
61
+ var _a;
62
+ var needResetDate = validateDateType(startDateOptions.currentDate) && !isNil((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.startDate) && moment(startDateOptions.currentDate).isAfter(endDateOptions.currentDate);
63
+ if (needResetDate) {
64
+ resetDateAndAlert('start');
65
+ return;
66
+ }
67
+ if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting)) {
68
+ return;
69
+ }
70
+ var isOverDate = moment(startDateOptions.currentDate).isAfter(endDateOptions.currentDate);
71
+ var _b = validationOption.setting,
72
+ unit = _b.unit,
73
+ period = _b.period;
74
+ var isValidPeriod = moment(startDateOptions.currentDate).isSameOrAfter(moment(endDateOptions.currentDate).subtract(period, unit));
75
+ if (isOverDate) {
76
+ changeSettingDateAndAlert('start');
77
+ }
78
+ if (!isValidPeriod) {
79
+ changeSettingDateAndAlert('start', !isValidPeriod);
80
+ }
81
+ }, [startDateOptions.currentDate]);
82
+ useEffect(function () {
83
+ var _a;
84
+ var needResetDate = validateDateType(endDateOptions.currentDate) && !isNil((_a = validationOption === null || validationOption === void 0 ? void 0 : validationOption.initDate) === null || _a === void 0 ? void 0 : _a.endDate) && moment(endDateOptions.currentDate).isBefore(startDateOptions.currentDate);
85
+ if (needResetDate) {
86
+ resetDateAndAlert('end');
87
+ return;
88
+ }
89
+ var isNotTodayEndDate = endDateOptions.currentDate !== getDateFormat();
90
+ if (!(validationOption === null || validationOption === void 0 ? void 0 : validationOption.setting) || !isNotTodayEndDate) {
91
+ return;
92
+ }
93
+ var isOverDate = moment(startDateOptions.currentDate).isAfter(endDateOptions.currentDate);
94
+ var _b = validationOption.setting,
95
+ unit = _b.unit,
96
+ period = _b.period;
97
+ var isValidPeriod = moment(endDateOptions.currentDate).isSameOrBefore(moment(startDateOptions.currentDate).add(period, unit));
98
+ if (isOverDate) {
99
+ changeSettingDateAndAlert('end');
100
+ }
101
+ if (!isValidPeriod) {
102
+ changeSettingDateAndAlert('end', !isValidPeriod);
103
+ }
104
+ }, [endDateOptions.currentDate]);
105
+ return _jsxs("div", __assign({
106
+ className: "ncua-range-date-picker"
107
+ }, {
108
+ children: [_jsx(DatePicker, __assign({}, startDateOptions)), "-", _jsx(DatePicker, __assign({}, endDateOptions))]
109
+ }));
110
+ };
@@ -1 +1,3 @@
1
- export * from './DatePicker';
1
+ export * from './DatePicker';
2
+ export * from './RangeDatePicker';
3
+ export * from './utils';
@@ -0,0 +1,10 @@
1
+ import moment from 'moment';
2
+ export function getToday() {
3
+ return moment().toDate();
4
+ }
5
+ export function getDateFormat(date) {
6
+ if (date === void 0) {
7
+ date = getToday();
8
+ }
9
+ return moment(date).format('YYYY-MM-DD');
10
+ }
@@ -0,0 +1,24 @@
1
+ import { unitOfTime } from 'moment';
2
+ import { DatePickerProps } from './DatePicker';
3
+ export type RangeDatePickerProps = {
4
+ startDateOptions: DatePickerProps;
5
+ endDateOptions: DatePickerProps;
6
+ validationOption?: {
7
+ initDate?: {
8
+ startDate?: string;
9
+ endDate?: string;
10
+ };
11
+ setting?: {
12
+ unit: unitOfTime.Diff;
13
+ period: number;
14
+ };
15
+ };
16
+ onDateValidation?: (params: {
17
+ type: 'start' | 'end';
18
+ errorType: 'reset' | 'period' | 'overlap';
19
+ newDate: string;
20
+ currentDate: string;
21
+ }) => void;
22
+ };
23
+ export declare const RangeDatePicker: ({ startDateOptions, endDateOptions, validationOption, onDateValidation, }: RangeDatePickerProps) => import("react/jsx-runtime").JSX.Element;
24
+ //# sourceMappingURL=RangeDatePicker.d.ts.map
@@ -1,2 +1,4 @@
1
1
  export * from './DatePicker';
2
+ export * from './RangeDatePicker';
3
+ export * from './utils';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export declare function getToday(): Date;
2
+ export declare function getDateFormat(date?: Date | string): string;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -1616,6 +1616,7 @@ button {
1616
1616
 
1617
1617
  .ncua-date-picker {
1618
1618
  position: relative;
1619
+ display: inline-block;
1619
1620
  }
1620
1621
  .ncua-date-picker .flatpickr-wrapper {
1621
1622
  border: 1px solid var(--gray-200);
@@ -1785,6 +1786,12 @@ button {
1785
1786
  color: var(--gray-300);
1786
1787
  }
1787
1788
 
1789
+ .ncua-range-date-picker {
1790
+ display: inline-flex;
1791
+ align-items: center;
1792
+ gap: 8px;
1793
+ }
1794
+
1788
1795
  .ncua-carousel-number-group {
1789
1796
  display: inline-flex;
1790
1797
  align-items: center;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ncds/ui-admin",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "nhn-commerce의 어드민 디자인 시스템입니다.",
5
5
  "scripts": {
6
6
  "barrel": "node barrel.js",