@homecode/ui 4.17.0 → 4.17.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.
- package/dist/esm/index.js +2 -0
- package/dist/esm/src/components/Calendar/Calendar.js +1 -1
- package/dist/esm/src/components/DatePicker/DatePicker.helpers.js +12 -1
- package/dist/esm/src/components/DatePicker/DatePicker.js +13 -9
- package/dist/esm/src/components/DatePickerInput/DatePickerInput.js +2 -1
- package/dist/esm/src/components/Popup/Popup.js +3 -2
- package/dist/esm/src/tools/date.js +11 -0
- package/dist/esm/types/src/components/DatePicker/DatePicker.helpers.d.ts +6 -0
- package/dist/esm/types/src/components/DatePicker/DatePicker.types.d.ts +2 -2
- package/dist/esm/types/src/components/DatePickerInput/DatePickerInput.types.d.ts +2 -2
- package/dist/esm/types/src/components/Icon/Icon.example.d.ts +0 -1
- package/dist/esm/types/src/tools/date.d.ts +6 -0
- package/dist/esm/types/src/tools/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -45,6 +45,8 @@ export { env };
|
|
|
45
45
|
export { config } from './src/tools/config.js';
|
|
46
46
|
import * as array from './src/tools/array.js';
|
|
47
47
|
export { array };
|
|
48
|
+
import * as date from './src/tools/date.js';
|
|
49
|
+
export { date };
|
|
48
50
|
import * as string from './src/tools/string.js';
|
|
49
51
|
export { string };
|
|
50
52
|
import * as number from './src/tools/number.js';
|
|
@@ -50,7 +50,7 @@ function Calendar({ className, value, onDayPointerDown, onDayPointerUp, renderDa
|
|
|
50
50
|
// @ts-ignore
|
|
51
51
|
size: size, label: renderYearLabel?.(year) ?? 'Year', value: year,
|
|
52
52
|
// @ts-ignore
|
|
53
|
-
onChange: onYearChange, onBlur: onYearBlur }), jsx(Select, { className: S.month, size: size, label: renderMonthesLabel?.(month) ?? 'Month', options: monthOptions, value: month, onChange: val => setMonth(val) })] }), jsx("div", { className: S.weekDays, children: weekDaysArray.map((day, weekdayIndex) => (jsx("div", { className: cn(S.day, isWeekend(weekdayIndex) && weekendClassName), children: renderWeekDayLabel?.(day) ?? weekDays[day] }, `weekday-${day}`))) }), jsx("div", { className: S.days, children: daysArray.map((day, weekdayIndex) => {
|
|
53
|
+
onChange: onYearChange, onBlur: onYearBlur }), jsx(Select, { className: S.month, size: size, label: renderMonthesLabel?.(month) ?? 'Month', options: monthOptions, value: month, onChange: val => setMonth(val), required: true, hideRequiredStar: true })] }), jsx("div", { className: S.weekDays, children: weekDaysArray.map((day, weekdayIndex) => (jsx("div", { className: cn(S.day, isWeekend(weekdayIndex) && weekendClassName), children: renderWeekDayLabel?.(day) ?? weekDays[day] }, `weekday-${day}`))) }), jsx("div", { className: S.days, children: daysArray.map((day, weekdayIndex) => {
|
|
54
54
|
const className = cn(S.day, day.currentMonth && S.currMonth, isWeekend(weekdayIndex) && weekendClassName, isSameDay(day, value) && S.selected);
|
|
55
55
|
const dayProps = { className };
|
|
56
56
|
if (onDayPointerDown) {
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
function dateToString(date) {
|
|
2
|
+
return `${date.year}-${date.month}-${date.day}`;
|
|
3
|
+
}
|
|
4
|
+
function strigToDate(dateString) {
|
|
5
|
+
const [year, month, day] = dateString.split('-');
|
|
6
|
+
return {
|
|
7
|
+
year: Number(year),
|
|
8
|
+
month: Number(month),
|
|
9
|
+
day: Number(day),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
1
12
|
function isDateEqual(date1, date2) {
|
|
2
13
|
return (date1.year === date2.year &&
|
|
3
14
|
date1.month === date2.month &&
|
|
@@ -17,4 +28,4 @@ function isDateBetween(date, startDate, endDate) {
|
|
|
17
28
|
return isDateAfter(date, startDate) && isDateBefore(date, endDate);
|
|
18
29
|
}
|
|
19
30
|
|
|
20
|
-
export { isDateAfter, isDateBefore, isDateBetween, isDateEqual };
|
|
31
|
+
export { dateToString, isDateAfter, isDateBefore, isDateBetween, isDateEqual, strigToDate };
|
|
@@ -3,7 +3,7 @@ import { useState, useCallback, createElement } from 'react';
|
|
|
3
3
|
import cn from 'classnames';
|
|
4
4
|
import { Calendar } from '../Calendar/Calendar.js';
|
|
5
5
|
import { Button } from '../Button/Button.js';
|
|
6
|
-
import { isDateAfter, isDateBetween, isDateEqual } from './DatePicker.helpers.js';
|
|
6
|
+
import { dateToString, isDateAfter, strigToDate, isDateBetween, isDateEqual } from './DatePicker.helpers.js';
|
|
7
7
|
import S from './DatePicker.styl.js';
|
|
8
8
|
|
|
9
9
|
function DatePicker(props) {
|
|
@@ -11,32 +11,36 @@ function DatePicker(props) {
|
|
|
11
11
|
const isRange = Array.isArray(value);
|
|
12
12
|
const [isPicking, setIsPicking] = useState(false);
|
|
13
13
|
const onFirstDateChange = useCallback((val) => {
|
|
14
|
-
|
|
14
|
+
const valStr = dateToString(val);
|
|
15
|
+
onChange(isRange ? [valStr, value[1]] : valStr);
|
|
15
16
|
}, [value, onChange, isRange]);
|
|
16
17
|
const onPointerDown = () => setIsPicking(true);
|
|
17
18
|
const onPointerUp = () => setIsPicking(false);
|
|
18
19
|
const renderDay = useCallback((val, { className, ...props }) => {
|
|
19
20
|
const { day, year, month } = val;
|
|
21
|
+
const valStr = dateToString(val);
|
|
20
22
|
if (isRange && isPicking) {
|
|
21
23
|
props.onPointerOver = () => {
|
|
22
|
-
const newVal = isDateAfter(value[0], val)
|
|
23
|
-
? [
|
|
24
|
-
: [value[0],
|
|
24
|
+
const newVal = isDateAfter(strigToDate(value[0]), val)
|
|
25
|
+
? [valStr, value[0]]
|
|
26
|
+
: [value[0], valStr];
|
|
25
27
|
onChange(newVal);
|
|
26
28
|
};
|
|
27
29
|
}
|
|
28
30
|
const classes = [className, S.day];
|
|
29
31
|
if (isRange) {
|
|
30
|
-
|
|
32
|
+
const from = strigToDate(value[0]);
|
|
33
|
+
const to = strigToDate(value[1]);
|
|
34
|
+
if (isDateBetween(val, from, to))
|
|
31
35
|
classes.push(S.between);
|
|
32
|
-
if (isDateEqual(val,
|
|
36
|
+
if (isDateEqual(val, from))
|
|
33
37
|
classes.push(S.start);
|
|
34
|
-
if (isDateEqual(val,
|
|
38
|
+
if (isDateEqual(val, to))
|
|
35
39
|
classes.push(S.end);
|
|
36
40
|
}
|
|
37
41
|
return (createElement(Button, { ...props, variant: "clear", className: cn(classes), size: size, key: `${year}-${month}-${day}` }, day));
|
|
38
42
|
}, [size, isPicking, isRange, value, onChange]);
|
|
39
|
-
return (jsxs("div", { className: cn(S.root, props.className), onPointerDown: onPointerDown, onPointerUp: onPointerUp, children: [jsx(Calendar, { size: size, hideOtherMonthDays: isRange, ...calendarProps, renderDay: renderDay, value: isRange ? value[0] : value, onDayPointerDown: onFirstDateChange, onDayPointerUp: undefined }), isRange && (jsx(Calendar, { size: size, hideOtherMonthDays: isRange, ...calendarProps, renderDay: renderDay, value: value[1], onDayPointerDown: val => onChange([value[0], val]), onDayPointerUp: val => onChange([value[0], val]) }))] }));
|
|
43
|
+
return (jsxs("div", { className: cn(S.root, props.className), onPointerDown: onPointerDown, onPointerUp: onPointerUp, children: [jsx(Calendar, { size: size, hideOtherMonthDays: isRange, ...calendarProps, renderDay: renderDay, value: strigToDate(isRange ? value[0] : value), onDayPointerDown: onFirstDateChange, onDayPointerUp: undefined }), isRange && (jsx(Calendar, { size: size, hideOtherMonthDays: isRange, ...calendarProps, renderDay: renderDay, value: strigToDate(value[1]), onDayPointerDown: val => onChange([value[0], dateToString(val)]), onDayPointerUp: val => onChange([value[0], dateToString(val)]) }))] }));
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
export { DatePicker };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import cn from 'classnames';
|
|
3
|
+
import { strToDate } from '../../tools/date.js';
|
|
3
4
|
import { DateTime } from '../DateTime/DateTime.js';
|
|
4
5
|
import { DatePicker } from '../DatePicker/DatePicker.js';
|
|
5
6
|
import { Button } from '../Button/Button.js';
|
|
@@ -9,7 +10,7 @@ import S from './DatePickerInput.styl.js';
|
|
|
9
10
|
function DatePickerInput(props) {
|
|
10
11
|
const { value, variant = 'default', size = 'm', popupProps, displayFormat = 'MMM Do YYYY', } = props;
|
|
11
12
|
const isRange = Array.isArray(value);
|
|
12
|
-
return (jsx(Popup, { size: size, focusControl: true, direction: "bottom-right", ...popupProps, trigger: jsx(Button, { variant: variant, size: size, children: isRange ? (jsxs(Fragment, { children: [jsx(DateTime, { value:
|
|
13
|
+
return (jsx(Popup, { size: size, focusControl: true, direction: "bottom-right", ...popupProps, trigger: jsx(Button, { variant: variant, size: size, children: isRange ? (jsxs(Fragment, { children: [jsx(DateTime, { value: strToDate(value[0]), format: displayFormat }), ' - ', jsx(DateTime, { value: strToDate(value[1]), format: displayFormat })] })) : (jsx(DateTime, { value: strToDate(value), format: displayFormat })) }), contentProps: {
|
|
13
14
|
className: cn(S.popupContent, isRange && S.range, S[`size-${size}`]),
|
|
14
15
|
}, content: jsx(DatePicker, { ...props, className: S.content, calendarProps: { className: S.calendar } }) }));
|
|
15
16
|
}
|
|
@@ -242,7 +242,8 @@ class Popup extends Component {
|
|
|
242
242
|
return;
|
|
243
243
|
}
|
|
244
244
|
// if scrolling outside this popup - close it
|
|
245
|
-
if (!this.isPointerOver(e.target, S.content)
|
|
245
|
+
if (!this.isPointerOver(e.target, S.content) &&
|
|
246
|
+
!childs[this.id]?.length) {
|
|
246
247
|
this.needDropOffset = true;
|
|
247
248
|
this.close();
|
|
248
249
|
}
|
|
@@ -280,7 +281,7 @@ class Popup extends Component {
|
|
|
280
281
|
this.focused = false;
|
|
281
282
|
this.props.triggerProps?.onBlur?.(e);
|
|
282
283
|
// give time to fire clicks inside popup
|
|
283
|
-
this.timers.after(
|
|
284
|
+
this.timers.after(60, () => {
|
|
284
285
|
if (!this.isLastClickInside())
|
|
285
286
|
this.close();
|
|
286
287
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert ISO 8601 format ("YYYY-MM-DD") to Date object
|
|
3
|
+
* @param str
|
|
4
|
+
* @returns Date
|
|
5
|
+
*/
|
|
6
|
+
const strToDate = (str) => {
|
|
7
|
+
const [year, month, day] = str.split('-').map(Number);
|
|
8
|
+
return new Date(year, month - 1, day);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { strToDate };
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { Date } from 'uilib/types';
|
|
2
|
+
export declare function dateToString(date: Date): string;
|
|
3
|
+
export declare function strigToDate(dateString: string): {
|
|
4
|
+
year: number;
|
|
5
|
+
month: number;
|
|
6
|
+
day: number;
|
|
7
|
+
};
|
|
2
8
|
export declare function isDateEqual(date1: Date, date2: Date): boolean;
|
|
3
9
|
export declare function isDateBefore(date1: Date, date2: Date): boolean;
|
|
4
10
|
export declare function isDateAfter(date1: Date, date2: Date): boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Size
|
|
1
|
+
import type { Size } from 'uilib/types';
|
|
2
2
|
import type { Props as CalendarProps } from 'uilib/components/Calendar/Calendar.types';
|
|
3
|
-
export type Value =
|
|
3
|
+
export type Value = string | [string, string];
|
|
4
4
|
export type Props = {
|
|
5
5
|
className?: string;
|
|
6
6
|
value: Value;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Size, Variant } from 'uilib/types';
|
|
2
2
|
import type { Props as PopupProps } from 'uilib/components/Popup/Popup.types';
|
|
3
|
-
export type Value =
|
|
3
|
+
export type Value = string | [string, string];
|
|
4
4
|
export type Props = {
|
|
5
5
|
className?: string;
|
|
6
6
|
size?: Size;
|