@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.
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ interface IProps {
3
+ date: Date;
4
+ onChange: (e: Date) => void;
5
+ fromDate: Date;
6
+ toDate: Date;
7
+ }
8
+ declare const YearMonthForm: React.FC<IProps>;
9
+ export default YearMonthForm;
10
+ //# sourceMappingURL=YearMonthForm.d.ts.map
@@ -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;
@@ -31,8 +31,6 @@ interface IProps {
31
31
  to?: string;
32
32
  from?: string;
33
33
  };
34
- /** With month and year selects, defaults to true */
35
- withYearMonthForm?: boolean;
36
34
  /** On change callback, returns date */
37
35
  onChange: (value: {
38
36
  to?: Date;
@@ -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;AAwBjD,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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B,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 FocusTrap from 'focus-trap-react';
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 = 400
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 minDateAvailable = new Date(currentYear - 100, 0);
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 = useMemo(() => ({
42
+ const modifiers = {
57
43
  start: dates.from,
58
44
  end: dates.to
59
- }), [dates.from, dates.to]);
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 _jsx(FocusTrap, {
97
- active: true,
98
- focusTrapOptions: {
99
- initialFocus: false,
100
- allowOutsideClick: true,
101
- clickOutsideDeactivates: true
102
- },
103
- children: _jsxs(Wrapper, {
104
- css: () => [styles.wrapper(maxWidth, minWidth), css && css],
105
- children: [_jsxs(Input, {
106
- title: disabled?.from && disabledTitle?.from ? disabledTitle?.from : undefined,
107
- css: theme => [styles.default(theme), validation && styles.validation, invalidMessage && styles.invalid(theme)],
108
- children: [label?.from && _jsx(Label, {
109
- children: label.from
110
- }), _jsx(DayPickerInput, {
111
- ref: fromPickerRef,
112
- keepFocus: false,
113
- format: FORMAT,
114
- formatDate: formatDate,
115
- parseDate: (date, format, locale) => parseDate(date, format, locale, undefined, maxDateAvailable),
116
- onDayChange: handleChange('from'),
117
- dayPickerProps: { ...pickerPropsDefault('from'),
118
- disabledDays: {
119
- after: dates.to
120
- },
121
- toMonth: dates.to,
122
- onDayClick: () => toPickerRef.current?.getInput().focus()
123
- },
124
- placeholder: 'dd.mm.åååå',
125
- onDayPickerHide: onBlur,
126
- value: value?.from,
127
- inputProps: {
128
- disabled: disabled?.from
129
- }
130
- }), invalidMessage?.from && _jsx(IconErrorOutline, {
131
- size: "16px"
132
- }), invalidMessage && _jsx(ErrorMessage, {
133
- children: invalidMessage.from
134
- })]
135
- }), _jsx(DividerLine, {
136
- children: "-"
137
- }), _jsxs(Input, {
138
- css: theme => [styles.default(theme), validation && styles.validation, invalidMessage && styles.invalid(theme)],
139
- title: disabled?.to && disabledTitle?.to ? disabledTitle.to : undefined,
140
- children: [label?.to && _jsx(Label, {
141
- children: label.to
142
- }), _jsx(DayPickerInput, {
143
- ref: toPickerRef,
144
- format: FORMAT,
145
- formatDate: formatDate,
146
- parseDate: (date, format, locale) => parseDate(date, format, locale, undefined, maxDate),
147
- onDayChange: handleChange('to'),
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;AAEjD,eAAO,MAAM,OAAO;;;yGAAe,CAAA;AAEnC,eAAO,MAAM,KAAK;;;yGAAe,CAAA;AAEjC,eAAO,MAAM,KAAK;;;2GAAgB,CAAA;AAElC,eAAO,MAAM,WAAW;;;2GAIvB,CAAA;AAED,eAAO,MAAM,YAAY;;;2GAOxB,CAAA;AAED,eAAO,MAAM,MAAM;wBACG,MAAM,YAAY,MAAM;qBAS3B,SAAS;;qBAiET,SAAS;CAqB3B,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"}