@ncds/ui-admin 0.0.16 → 0.0.18

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,15 @@ 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
+ });
16
27
  });
@@ -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
+ }
@@ -45,20 +45,23 @@ var Tooltip = function (_a) {
45
45
  iconType = _c === void 0 ? 'stroke' : _c,
46
46
  _d = _a.position,
47
47
  position = _d === void 0 ? 'top' : _d,
48
+ _e = _a.size,
49
+ size = _e === void 0 ? 'sm' : _e,
48
50
  title = _a.title,
49
51
  content = _a.content,
50
- _e = _a.hideArrow,
51
- hideArrow = _e === void 0 ? false : _e;
52
+ _f = _a.hideArrow,
53
+ hideArrow = _f === void 0 ? false : _f;
54
+ var iconSize = size === 'sm' ? 14 : 16;
52
55
  return (0, _jsxRuntime.jsxs)("span", __assign({
53
- className: (0, _classnames.default)('ncua-tooltip', "".concat(hideArrow ? 'ncua-tooltip--hidden-arrow' : ''), "".concat(iconType === 'stroke' ? 'ncua-tooltip--stroke' : ''))
56
+ className: (0, _classnames.default)('ncua-tooltip', "ncua-tooltip--".concat(size), "".concat(hideArrow ? 'ncua-tooltip--hidden-arrow' : ''), "".concat(iconType === 'stroke' ? 'ncua-tooltip--stroke' : ''))
54
57
  }, {
55
58
  children: [iconType === 'stroke' ? (0, _jsxRuntime.jsx)(_uiAdminIcon.HelpCircle, {
56
- width: 16,
57
- height: 16,
59
+ width: iconSize,
60
+ height: iconSize,
58
61
  color: "var(--gray-300"
59
62
  }) : (0, _jsxRuntime.jsx)(_uiAdminIcon.HelpCircleFill, {
60
- width: 16,
61
- height: 16,
63
+ width: iconSize,
64
+ height: iconSize,
62
65
  color: "var(--gray-300)"
63
66
  }), tooltipContent({
64
67
  tooltipType: tooltipType,
@@ -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,2 @@
1
- export * from './DatePicker';
1
+ export * from './DatePicker';
2
+ export * from './RangeDatePicker';
@@ -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
+ }
@@ -38,20 +38,23 @@ export var Tooltip = function (_a) {
38
38
  iconType = _c === void 0 ? 'stroke' : _c,
39
39
  _d = _a.position,
40
40
  position = _d === void 0 ? 'top' : _d,
41
+ _e = _a.size,
42
+ size = _e === void 0 ? 'sm' : _e,
41
43
  title = _a.title,
42
44
  content = _a.content,
43
- _e = _a.hideArrow,
44
- hideArrow = _e === void 0 ? false : _e;
45
+ _f = _a.hideArrow,
46
+ hideArrow = _f === void 0 ? false : _f;
47
+ var iconSize = size === 'sm' ? 14 : 16;
45
48
  return _jsxs("span", __assign({
46
- className: classNames('ncua-tooltip', "".concat(hideArrow ? 'ncua-tooltip--hidden-arrow' : ''), "".concat(iconType === 'stroke' ? 'ncua-tooltip--stroke' : ''))
49
+ className: classNames('ncua-tooltip', "ncua-tooltip--".concat(size), "".concat(hideArrow ? 'ncua-tooltip--hidden-arrow' : ''), "".concat(iconType === 'stroke' ? 'ncua-tooltip--stroke' : ''))
47
50
  }, {
48
51
  children: [iconType === 'stroke' ? _jsx(HelpCircle, {
49
- width: 16,
50
- height: 16,
52
+ width: iconSize,
53
+ height: iconSize,
51
54
  color: "var(--gray-300"
52
55
  }) : _jsx(HelpCircleFill, {
53
- width: 16,
54
- height: 16,
56
+ width: iconSize,
57
+ height: iconSize,
55
58
  color: "var(--gray-300)"
56
59
  }), tooltipContent({
57
60
  tooltipType: tooltipType,
@@ -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,3 @@
1
1
  export * from './DatePicker';
2
+ export * from './RangeDatePicker';
2
3
  //# 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
@@ -2,10 +2,11 @@ interface TooltipProps {
2
2
  tooltipType?: 'white' | 'black';
3
3
  iconType?: 'stroke' | 'fill';
4
4
  position?: 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
5
+ size?: 'sm' | 'md';
5
6
  hideArrow?: boolean;
6
7
  title?: string;
7
8
  content?: string;
8
9
  }
9
- export declare const Tooltip: ({ tooltipType, iconType, position, title, content, hideArrow, }: TooltipProps) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const Tooltip: ({ tooltipType, iconType, position, size, title, content, hideArrow, }: TooltipProps) => import("react/jsx-runtime").JSX.Element;
10
11
  export {};
11
12
  //# sourceMappingURL=Tooltip.d.ts.map
@@ -1088,15 +1088,15 @@ button {
1088
1088
 
1089
1089
  .ncua-tooltip {
1090
1090
  position: relative;
1091
- font-size: 11px;
1091
+ font-size: 12px;
1092
1092
  }
1093
1093
  .ncua-tooltip svg {
1094
1094
  cursor: pointer;
1095
1095
  }
1096
1096
  .ncua-tooltip__bg {
1097
1097
  position: absolute;
1098
- padding: 12px;
1099
1098
  border-radius: 4px;
1099
+ padding: 8px 12px;
1100
1100
  display: flex;
1101
1101
  flex-direction: column;
1102
1102
  gap: 4px;
@@ -1225,6 +1225,9 @@ button {
1225
1225
  .ncua-tooltip:not(:hover) .ncua-tooltip__bg {
1226
1226
  display: none;
1227
1227
  }
1228
+ .ncua-tooltip:has(.ncua-tooltip__title) .ncua-tooltip__bg {
1229
+ padding: 12px;
1230
+ }
1228
1231
 
1229
1232
  :root {
1230
1233
  --select-height-xs: 28px;
@@ -1616,6 +1619,7 @@ button {
1616
1619
 
1617
1620
  .ncua-date-picker {
1618
1621
  position: relative;
1622
+ display: inline-block;
1619
1623
  }
1620
1624
  .ncua-date-picker .flatpickr-wrapper {
1621
1625
  border: 1px solid var(--gray-200);
@@ -1785,6 +1789,12 @@ button {
1785
1789
  color: var(--gray-300);
1786
1790
  }
1787
1791
 
1792
+ .ncua-range-date-picker {
1793
+ display: inline-flex;
1794
+ align-items: center;
1795
+ gap: 8px;
1796
+ }
1797
+
1788
1798
  .ncua-carousel-number-group {
1789
1799
  display: inline-flex;
1790
1800
  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.18",
4
4
  "description": "nhn-commerce의 어드민 디자인 시스템입니다.",
5
5
  "scripts": {
6
6
  "barrel": "node barrel.js",