@bbl-digital/snorre 2.4.10 → 2.4.13
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bundle.js +121 -124
- package/esm/core/DatepickerRange/YearMonthForm.js +56 -0
- package/esm/core/DatepickerRange/index.js +75 -105
- package/esm/core/DatepickerRange/styles.js +35 -22
- package/esm/icons/General/IconSliders.js +15 -0
- package/esm/index.js +2 -1
- package/lib/core/Datepicker/yearMonthForm.d.ts.map +1 -1
- package/lib/core/DatepickerRange/YearMonthForm.d.ts +10 -0
- package/lib/core/DatepickerRange/YearMonthForm.d.ts.map +1 -0
- package/lib/core/DatepickerRange/YearMonthForm.js +56 -0
- package/lib/core/DatepickerRange/index.d.ts +0 -2
- package/lib/core/DatepickerRange/index.d.ts.map +1 -1
- package/lib/core/DatepickerRange/index.js +75 -105
- package/lib/core/DatepickerRange/styles.d.ts +8 -0
- package/lib/core/DatepickerRange/styles.d.ts.map +1 -1
- package/lib/core/DatepickerRange/styles.js +35 -22
- package/lib/icons/General/IconSliders.d.ts +4 -0
- package/lib/icons/General/IconSliders.d.ts.map +1 -0
- package/lib/icons/General/IconSliders.js +15 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/package.json +1 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"YearMonthForm.d.ts","sourceRoot":"","sources":["../../../src/packages/core/DatepickerRange/YearMonthForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,UAAU,MAAM;IACd,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,IAAI,CAAA;IAC3B,QAAQ,EAAE,IAAI,CAAA;IACd,MAAM,EAAE,IAAI,CAAA;CACb;AAED,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAmDnC,CAAA;AAED,eAAe,aAAa,CAAA"}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { MONTHS } from '../../utils/dates';
|
3
|
+
import { StyledSelect, Div } from './styles';
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
5
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
6
|
+
|
7
|
+
const YearMonthForm = ({
|
8
|
+
onChange,
|
9
|
+
date,
|
10
|
+
fromDate,
|
11
|
+
toDate
|
12
|
+
}) => {
|
13
|
+
const months = MONTHS;
|
14
|
+
const years = [];
|
15
|
+
|
16
|
+
for (let i = fromDate.getFullYear(); i <= toDate.getFullYear(); i += 1) {
|
17
|
+
years.push(i);
|
18
|
+
}
|
19
|
+
|
20
|
+
const changeMonth = e => {
|
21
|
+
let newDate = date;
|
22
|
+
newDate.setMonth(e.target.value);
|
23
|
+
if (newDate > toDate) newDate = toDate;
|
24
|
+
onChange(newDate);
|
25
|
+
};
|
26
|
+
|
27
|
+
const changeYear = e => {
|
28
|
+
let newDate = date;
|
29
|
+
newDate.setFullYear(e.target.value);
|
30
|
+
if (newDate > toDate) newDate = toDate;
|
31
|
+
onChange(newDate);
|
32
|
+
};
|
33
|
+
|
34
|
+
return /*#__PURE__*/_jsxs(Div, {
|
35
|
+
className: "DayPicker-Caption",
|
36
|
+
children: [/*#__PURE__*/_jsx(StyledSelect, {
|
37
|
+
name: "month",
|
38
|
+
onChange: changeMonth,
|
39
|
+
value: date.getMonth(),
|
40
|
+
children: months.map((month, i) => /*#__PURE__*/_jsx("option", {
|
41
|
+
value: i,
|
42
|
+
children: month
|
43
|
+
}, month))
|
44
|
+
}), /*#__PURE__*/_jsx(StyledSelect, {
|
45
|
+
name: "year",
|
46
|
+
onChange: changeYear,
|
47
|
+
value: date.getFullYear(),
|
48
|
+
children: years.map(year => /*#__PURE__*/_jsx("option", {
|
49
|
+
value: year,
|
50
|
+
children: year
|
51
|
+
}, year))
|
52
|
+
})]
|
53
|
+
});
|
54
|
+
};
|
55
|
+
|
56
|
+
export default YearMonthForm;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/core/DatepickerRange/index.tsx"],"names":[],"mappings":"AAAA,sCAAsC;;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/core/DatepickerRange/index.tsx"],"names":[],"mappings":"AAAA,sCAAsC;;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAsBjD,UAAU,MAAM;IACd,0BAA0B;IAC1B,KAAK,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACtC,6BAA6B;IAC7B,KAAK,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,IAAI,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,CAAA;KAAE,CAAA;IAClC,0BAA0B;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,sBAAsB;IACtB,cAAc,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/C,2BAA2B;IAC3B,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,qBAAqB;IACrB,QAAQ,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;IAC3C,6BAA6B;IAC7B,aAAa,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IAC9C,uCAAuC;IACvC,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,EAAE,CAAC,EAAE,IAAI,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,CAAA;KAAE,KAAK,IAAI,CAAA;IACrD,8BAA8B;IAC9B,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,uCAAuC;IACvC,GAAG,CAAC,EAAE,gBAAgB,CAAA;IACtB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAKD,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAyIrC,CAAA;AAED,eAAe,eAAe,CAAA"}
|
@@ -1,15 +1,14 @@
|
|
1
1
|
/** @jsxImportSource @emotion/react */
|
2
|
-
import
|
3
|
-
import { useRef, useState, useEffect, useMemo } from 'react';
|
2
|
+
import { useRef, useState, useEffect } from 'react';
|
4
3
|
import DayPickerInput from 'react-day-picker/DayPickerInput';
|
5
4
|
import { useIsMobile } from '../..';
|
6
5
|
import IconErrorOutline from '../../icons/General/IconErrorOutline';
|
7
6
|
import { formatDate, MONTHS, parseDate, WEEKDAYS_LONG, WEEKDAYS_SHORT } from '../../utils/dates';
|
8
|
-
import YearMonthForm from '../Datepicker/yearMonthForm';
|
9
7
|
import { Input, Wrapper, styles, Label, ErrorMessage, DividerLine } from './styles';
|
10
8
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
11
9
|
import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
12
10
|
const FORMAT = 'dd.MM.yyyy';
|
11
|
+
const PLACEHOLDER = 'dd.mm.åååå';
|
13
12
|
|
14
13
|
const DatePickerRange = ({
|
15
14
|
value,
|
@@ -19,62 +18,37 @@ const DatePickerRange = ({
|
|
19
18
|
maxDate,
|
20
19
|
disabled,
|
21
20
|
disabledTitle,
|
22
|
-
withYearMonthForm = true,
|
23
21
|
onChange,
|
24
22
|
onBlur,
|
25
23
|
css,
|
26
24
|
maxWidth = 550,
|
27
|
-
minWidth =
|
25
|
+
minWidth = 550
|
28
26
|
}) => {
|
29
27
|
const isMobile = useIsMobile();
|
30
28
|
const fromPickerRef = useRef(null);
|
31
29
|
const toPickerRef = useRef(null);
|
32
30
|
const currentYear = new Date().getFullYear();
|
33
|
-
const
|
34
|
-
const maxDateAvailable = maxDate ? new Date(maxDate) : new Date(currentYear, 11, 31);
|
31
|
+
const maxDateAvailable = maxDate ? new Date(maxDate) : new Date(currentYear + 5, 11, 31);
|
35
32
|
const [dates, setDates] = useState({
|
36
33
|
to: undefined,
|
37
34
|
from: undefined
|
38
35
|
});
|
39
|
-
|
40
|
-
const showFromMonth = () => {
|
41
|
-
if (!dates.from) return;
|
42
|
-
const toMonth = dates.from.getMonth() + 1;
|
43
|
-
const fromMonth = dates.from.getMonth() + 1;
|
44
|
-
|
45
|
-
if (fromMonth - toMonth < 2) {
|
46
|
-
toPickerRef.current?.getDayPicker().showMonth(dates.from);
|
47
|
-
}
|
48
|
-
};
|
49
|
-
|
50
36
|
useEffect(() => {
|
51
37
|
if (isMobile && fromPickerRef) fromPickerRef.current.input.readOnly = true;
|
52
38
|
}, [isMobile, fromPickerRef]);
|
53
39
|
useEffect(() => {
|
54
40
|
if (isMobile && toPickerRef) toPickerRef.current.input.readOnly = true;
|
55
41
|
}, [isMobile, toPickerRef]);
|
56
|
-
const modifiers =
|
42
|
+
const modifiers = {
|
57
43
|
start: dates.from,
|
58
44
|
end: dates.to
|
59
|
-
}
|
60
|
-
|
61
|
-
const pickerPropsDefault = key => ({
|
45
|
+
};
|
46
|
+
const pickerPropsDefault = {
|
62
47
|
locale: 'no',
|
63
48
|
months: MONTHS,
|
64
49
|
weekdaysLong: WEEKDAYS_LONG,
|
65
50
|
weekdaysShort: WEEKDAYS_SHORT,
|
66
51
|
firstDayOfWeek: 1,
|
67
|
-
captionElement: withYearMonthForm ? _jsx(YearMonthForm, {
|
68
|
-
date: dates[key] || new Date(),
|
69
|
-
fromDate: minDateAvailable,
|
70
|
-
toDate: maxDateAvailable,
|
71
|
-
onChange: e => {
|
72
|
-
setDates(prev => ({ ...prev,
|
73
|
-
[key]: e
|
74
|
-
}));
|
75
|
-
showFromMonth();
|
76
|
-
}
|
77
|
-
}) : undefined,
|
78
52
|
// custom
|
79
53
|
modifiers,
|
80
54
|
numberOfMonths: 2,
|
@@ -82,7 +56,21 @@ const DatePickerRange = ({
|
|
82
56
|
from: dates.from,
|
83
57
|
to: dates.to
|
84
58
|
}]
|
85
|
-
}
|
59
|
+
};
|
60
|
+
const toDayProps = { ...pickerPropsDefault,
|
61
|
+
disabledDays: {
|
62
|
+
before: dates.from
|
63
|
+
},
|
64
|
+
month: dates.from,
|
65
|
+
fromMonth: dates.from
|
66
|
+
};
|
67
|
+
const fromDayProps = { ...pickerPropsDefault,
|
68
|
+
disabledDays: {
|
69
|
+
after: dates.to
|
70
|
+
},
|
71
|
+
toMonth: dates.to,
|
72
|
+
onDayClick: () => toPickerRef.current?.getInput().focus()
|
73
|
+
};
|
86
74
|
|
87
75
|
const handleChange = key => date => {
|
88
76
|
setDates(prev => ({ ...prev,
|
@@ -93,78 +81,60 @@ const DatePickerRange = ({
|
|
93
81
|
});
|
94
82
|
};
|
95
83
|
|
96
|
-
return
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
dayPickerProps: { ...pickerPropsDefault('to'),
|
149
|
-
disabledDays: {
|
150
|
-
before: dates.from
|
151
|
-
},
|
152
|
-
month: dates.from,
|
153
|
-
fromMonth: dates.from
|
154
|
-
},
|
155
|
-
placeholder: 'dd.mm.åååå',
|
156
|
-
onDayPickerHide: onBlur,
|
157
|
-
value: value?.to,
|
158
|
-
inputProps: {
|
159
|
-
disabled: disabled?.to
|
160
|
-
}
|
161
|
-
}), invalidMessage?.to && _jsx(IconErrorOutline, {
|
162
|
-
size: "16px"
|
163
|
-
}), invalidMessage && _jsx(ErrorMessage, {
|
164
|
-
children: invalidMessage?.to
|
165
|
-
})]
|
84
|
+
return _jsxs(Wrapper, {
|
85
|
+
css: () => [styles.wrapper(maxWidth, minWidth), css && css],
|
86
|
+
children: [_jsxs(Input, {
|
87
|
+
className: "InputFromTo",
|
88
|
+
title: disabled?.from && disabledTitle?.from ? disabledTitle?.from : undefined,
|
89
|
+
css: theme => [styles.default(theme), validation && styles.validation, invalidMessage && styles.invalid(theme)],
|
90
|
+
children: [label?.from && _jsx(Label, {
|
91
|
+
children: label.from
|
92
|
+
}), _jsx(DayPickerInput, {
|
93
|
+
ref: fromPickerRef,
|
94
|
+
keepFocus: false,
|
95
|
+
format: FORMAT,
|
96
|
+
formatDate: formatDate,
|
97
|
+
parseDate: (date, format, locale) => parseDate(date, format, locale, undefined, maxDateAvailable),
|
98
|
+
onDayChange: handleChange('from'),
|
99
|
+
dayPickerProps: fromDayProps,
|
100
|
+
placeholder: PLACEHOLDER,
|
101
|
+
onDayPickerHide: onBlur,
|
102
|
+
value: value?.from,
|
103
|
+
inputProps: {
|
104
|
+
disabled: disabled?.from
|
105
|
+
}
|
106
|
+
}), invalidMessage?.from && _jsx(IconErrorOutline, {
|
107
|
+
size: "16px"
|
108
|
+
}), invalidMessage && _jsx(ErrorMessage, {
|
109
|
+
children: invalidMessage.from
|
110
|
+
})]
|
111
|
+
}), _jsx(DividerLine, {
|
112
|
+
children: "-"
|
113
|
+
}), _jsxs(Input, {
|
114
|
+
className: "InputFromTo-to",
|
115
|
+
css: theme => [styles.default(theme), validation && styles.validation, invalidMessage && styles.invalid(theme)],
|
116
|
+
title: disabled?.to && disabledTitle?.to ? disabledTitle.to : undefined,
|
117
|
+
children: [label?.to && _jsx(Label, {
|
118
|
+
children: label.to
|
119
|
+
}), _jsx(DayPickerInput, {
|
120
|
+
ref: toPickerRef,
|
121
|
+
format: FORMAT,
|
122
|
+
formatDate: formatDate,
|
123
|
+
parseDate: (date, format, locale) => parseDate(date, format, locale, undefined, maxDate),
|
124
|
+
onDayChange: handleChange('to'),
|
125
|
+
dayPickerProps: toDayProps,
|
126
|
+
placeholder: PLACEHOLDER,
|
127
|
+
onDayPickerHide: onBlur,
|
128
|
+
value: value?.to,
|
129
|
+
inputProps: {
|
130
|
+
disabled: disabled?.to
|
131
|
+
}
|
132
|
+
}), invalidMessage?.to && _jsx(IconErrorOutline, {
|
133
|
+
size: "16px"
|
134
|
+
}), invalidMessage && _jsx(ErrorMessage, {
|
135
|
+
children: invalidMessage?.to
|
166
136
|
})]
|
167
|
-
})
|
137
|
+
})]
|
168
138
|
});
|
169
139
|
};
|
170
140
|
|
@@ -12,6 +12,14 @@ export declare const Label: import("@emotion/styled").StyledComponent<{
|
|
12
12
|
theme?: import("@emotion/react").Theme | undefined;
|
13
13
|
as?: import("react").ElementType<any> | undefined;
|
14
14
|
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {}>;
|
15
|
+
export declare const Div: import("@emotion/styled").StyledComponent<{
|
16
|
+
theme?: import("@emotion/react").Theme | undefined;
|
17
|
+
as?: import("react").ElementType<any> | undefined;
|
18
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
19
|
+
export declare const StyledSelect: import("@emotion/styled").StyledComponent<{
|
20
|
+
theme?: import("@emotion/react").Theme | undefined;
|
21
|
+
as?: import("react").ElementType<any> | undefined;
|
22
|
+
}, import("react").DetailedHTMLProps<import("react").SelectHTMLAttributes<HTMLSelectElement>, HTMLSelectElement>, {}>;
|
15
23
|
export declare const DividerLine: import("@emotion/styled").StyledComponent<{
|
16
24
|
theme?: import("@emotion/react").Theme | undefined;
|
17
25
|
as?: import("react").ElementType<any> | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/packages/core/DatepickerRange/styles.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/packages/core/DatepickerRange/styles.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAGjD,eAAO,MAAM,OAAO;;;yGAAe,CAAA;AAEnC,eAAO,MAAM,KAAK;;;yGAAe,CAAA;AAEjC,eAAO,MAAM,KAAK;;;2GAAgB,CAAA;AAElC,eAAO,MAAM,GAAG;;;yGAAe,CAAA;AAE/B,eAAO,MAAM,YAAY;;;qHAKxB,CAAA;AAED,eAAO,MAAM,WAAW;;;2GAQvB,CAAA;AAED,eAAO,MAAM,YAAY;;;2GAOxB,CAAA;AAED,eAAO,MAAM,MAAM;wBACG,MAAM,YAAY,MAAM;qBAuD3B,SAAS;;qBAoET,SAAS;CAqB3B,CAAA"}
|