@npm_leadtech/legal-lib-components 4.1.20 → 4.1.22

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,4 @@
1
+ import { type FC } from 'react';
2
+ import { type DatePickerCustomProps } from './DatePickerCustomProps.types';
3
+ declare const DatePickerCustom: FC<DatePickerCustomProps>;
4
+ export default DatePickerCustom;
@@ -0,0 +1,79 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import DatePicker, { registerLocale } from 'react-datepicker';
3
+ import { useState } from 'react';
4
+ import { de } from 'date-fns/locale';
5
+ // import './DatePickerCustom.scss'
6
+ // import './DatepickerPlugin.scss'
7
+ registerLocale('de', de);
8
+ const DatePickerCustom = ({ class: className, dateFormat = 'MM/dd/yyyy', isStartDate = false, isValidGroup = false, label, locale = 'en', name, onChange, relatedDate, tooltip, type, validate = false, value }) => {
9
+ const [date, setDate] = useState(() => {
10
+ return typeof value === 'string' && value !== '' ? new Date(value) : null;
11
+ });
12
+ const returnYears = (currentYear) => {
13
+ const years = [];
14
+ const minYear = new Date().getFullYear() - 100;
15
+ const maxYear = new Date().getFullYear() + 500;
16
+ for (let i = minYear; i <= maxYear; i++) {
17
+ years.push(_jsx("option", { value: i, defaultValue: currentYear, children: i }, i));
18
+ }
19
+ return years;
20
+ };
21
+ const handleChange = (date) => {
22
+ setDate(date);
23
+ if (onChange != null) {
24
+ const dateObject = {
25
+ target: {
26
+ name,
27
+ value: date
28
+ }
29
+ };
30
+ onChange(dateObject);
31
+ }
32
+ };
33
+ const addDays = (date, days) => {
34
+ const result = new Date(date);
35
+ result.setDate(result.getDate() + days);
36
+ return result;
37
+ };
38
+ const classStyle = `${validate ? 'e-datepicker' : 'e-datepicker is-invalid'} ${className ?? ''} e-${type} ${!isValidGroup ? '--group-invalid' : ''}\``;
39
+ let minDate;
40
+ let maxDate;
41
+ if (relatedDate != null) {
42
+ if (isStartDate) {
43
+ maxDate = relatedDate;
44
+ maxDate = addDays(maxDate, -1);
45
+ }
46
+ else {
47
+ minDate = relatedDate;
48
+ minDate = addDays(minDate, 1);
49
+ }
50
+ }
51
+ const TooltipObject = tooltip !== undefined ? _jsx("p", { className: 'tooltip-form sans-serif --small', children: tooltip }) : '';
52
+ const actualYear = new Date().getFullYear();
53
+ const intlForMonths = new Intl.DateTimeFormat(locale, { month: 'long' });
54
+ const months = [...Array(12).keys()].map((monthIndex) => {
55
+ const monthName = intlForMonths.format(new Date(actualYear, monthIndex));
56
+ return {
57
+ monthName
58
+ };
59
+ });
60
+ return (_jsxs("div", { className: classStyle, "data-qa": name, children: [TooltipObject, _jsx(DatePicker, { locale: locale, dateFormat: dateFormat, renderCustomHeader: ({ date, changeYear, changeMonth, decreaseMonth, increaseMonth, prevMonthButtonDisabled, nextMonthButtonDisabled }) => (_jsxs("div", { style: {
61
+ margin: 10,
62
+ display: 'flex',
63
+ justifyContent: 'center'
64
+ }, children: [_jsx("button", { className: 'DayPickerNavigation_leftButton', onClick: decreaseMonth, disabled: prevMonthButtonDisabled, children: '<' }), _jsx("select", { className: 'CalendarYear', value: date.getFullYear(), onChange: ({ target: { value } }) => {
65
+ changeYear(Number(value));
66
+ }, children: returnYears(date.getFullYear()) }), _jsx("select", { className: 'CalendarMonth', value: date.getMonth(), onChange: ({ target: { value } }) => {
67
+ changeMonth(Number(value));
68
+ }, children: months.map(({ monthName }, value) => (_jsx("option", { value: value, defaultValue: date.getMonth(), children: monthName }, monthName))) }), _jsx("button", { className: 'DayPickerNavigation_rightButton', onClick: increaseMonth, disabled: nextMonthButtonDisabled, children: '>' })] })), selected: date, minDate: minDate, maxDate: maxDate, onChange: (date) => {
69
+ handleChange(date);
70
+ }, popperPlacement: 'bottom', popperModifiers: [
71
+ {
72
+ name: 'flip',
73
+ options: {
74
+ fallbackPlacements: ['bottom']
75
+ }
76
+ }
77
+ ] }), _jsx("div", { className: 'e-datepicker__inner', children: _jsx("label", { className: 'e-datepicker__label', children: label }) })] }));
78
+ };
79
+ export default DatePickerCustom;
@@ -0,0 +1,116 @@
1
+ @import '../../../globalStyles/variables.scss';
2
+ @import '../../../globalStyles/mediaqueries.scss';
3
+
4
+ .e-datepicker {
5
+ max-width: 55%;
6
+ width: 100%;
7
+ display: flex;
8
+ flex-flow: column-reverse;
9
+ margin-bottom: 2rem;
10
+ &__inner {
11
+ margin-bottom: 0.5rem;
12
+ }
13
+ &__label {
14
+ font-weight: bold;
15
+ }
16
+
17
+ ul li {
18
+ margin: 0;
19
+
20
+ &::before {
21
+ background-color: transparent;
22
+ }
23
+ }
24
+
25
+ .react-datepicker {
26
+ border: 0.5px solid get-color(neutral, neutral-4);
27
+ }
28
+
29
+ .react-datepicker__input-container input {
30
+ color: get-color(neutral, main);
31
+ border-radius: 4px;
32
+ font-size: 1rem;
33
+ background-color: get-color(neutral, neutral-4);
34
+ height: 40px;
35
+ width: 100%;
36
+ padding: 0.75rem 0 0.75rem 0.75rem;
37
+ background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIHdpZHRoPSIyNHB4IiBoZWlnaHQ9IjI0cHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj48IS0tR2VuZXJhdG9yOiBza2V0Y2h0b29sIDYwICgxMDEwMTApIC0gaHR0cHM6Ly9za2V0Y2guY29tLS0+PHRpdGxlPjNEODAzNjU0LUI3NjEtNEZEQy05MThDLTc1QzUwMjdEODcyMDwvdGl0bGU+PGRlc2M+Q3JlYXRlZCB3aXRoIHNrZXRjaHRvb2wuPC9kZXNjPjxkZWZzPjxwYXRoIGQ9Ik0yMiwzIEwxOSwzIEwxOSwxIEwxNywxIEwxNywzIEw3LDMgTDcsMSBMNSwxIEw1LDMgTDIsMyBMMiwyMyBMMjIsMjMgTDIyLDMgWiBNMjAsMjEgTDQsMjEgTDQsOCBMMjAsOCBMMjAsMjEgWiIgaWQ9InBhdGgtMSIvPjwvZGVmcz48ZyBpZD0iQXNzZXQtQXJ0Ym9hcmQtUGFnZSIgc3Ryb2tlPSJub25lIiBzdHJva2Utd2lkdGg9IjEiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+PGcgaWQ9Imljb24vbmF2aWdhdGlvbi9leHBhbmRfbW9yZV8yNHB4LWljb24vYWN0aW9uL2NhbGVuZGFyX3RvZGF5XzI0cHgiPjxtYXNrIGlkPSJtYXNrLTIiIGZpbGw9IndoaXRlIj48dXNlIHhsaW5rOmhyZWY9IiNwYXRoLTEiLz48L21hc2s+PGcgaWQ9Imljb24vYWN0aW9uL2NhbGVuZGFyX3RvZGF5XzI0cHgiIGZpbGwtcnVsZT0ibm9uemVybyIvPjxnIGlkPSLihrMtQ29sb3ItY29sb3ItLy1JY29ucy0vLUJsYWNrLS8tSW5hY3RpdmUiIG1hc2s9InVybCgjbWFzay0yKSIgZmlsbD0iIzQzNDM0MyI+PHJlY3QgaWQ9IlJlY3RhbmdsZSIgeD0iMCIgeT0iMCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0Ii8+PC9nPjwvZz48L2c+PC9zdmc+);
38
+ background-position: 95% 50%;
39
+ background-repeat: no-repeat;
40
+ transition: box-shadow 0.3s ease;
41
+ box-shadow: 0 0 0 0 get-color(primary, main-light-4);
42
+ margin: 0.0005em;
43
+ border: none;
44
+
45
+ &:focus {
46
+ outline: none;
47
+ box-shadow: 0 0 0 2px get-color(primary, main-light-1);
48
+ }
49
+ }
50
+
51
+ .react-datepicker__day {
52
+ font-size: 14px;
53
+ text-align: center;
54
+ border: 0.5px solid get-color(neutral, neutral-4);
55
+ width: 39px;
56
+ height: 38px;
57
+ border-collapse: collapse;
58
+ vertical-align: middle;
59
+ display: table-cell;
60
+ line-height: 1.7rem;
61
+ }
62
+
63
+ .react-datepicker-popper[data-placement^='bottom'] .react-datepicker__triangle::after {
64
+ border-bottom-color: get-color(others, white);
65
+ }
66
+
67
+ .react-datepicker__day--selected {
68
+ background-color: get-color(primary, main-light-2);
69
+ border: 1px double get-color(primary, main-light-2);
70
+
71
+ &:hover {
72
+ background-color: get-color(primary, main-light-2);
73
+ }
74
+ }
75
+
76
+ .react-datepicker__day--keyboard-selected {
77
+ background-color: inherit;
78
+ color: inherit;
79
+
80
+ &:hover {
81
+ border-radius: 0.3rem;
82
+ background-color: #f0f0f0;
83
+ }
84
+ }
85
+
86
+ .react-datepicker__month-container {
87
+ padding: 0 15px 15px;
88
+ }
89
+
90
+ .react-datepicker__month {
91
+ margin: 0;
92
+ }
93
+
94
+ .react-datepicker__header {
95
+ background-color: inherit;
96
+ border: none;
97
+
98
+ button {
99
+ border: 0.5px solid get-color(neutral, neutral-4);
100
+ }
101
+
102
+ select {
103
+ -webkit-appearance: menulist-button;
104
+ background-color: get-color(others, white);
105
+ }
106
+ }
107
+
108
+ .react-datepicker__day-name {
109
+ width: 33px;
110
+ }
111
+
112
+ .react-datepicker__day--outside-month {
113
+ color: get-color(neutral, neutral-3);
114
+ pointer-events: none;
115
+ }
116
+ }
@@ -0,0 +1,178 @@
1
+ import DatePicker, { registerLocale } from 'react-datepicker'
2
+ import React, { type FC, useState } from 'react'
3
+ import { de } from 'date-fns/locale'
4
+
5
+ import { type DatePickerCustomProps } from './DatePickerCustomProps.types'
6
+ // import './DatePickerCustom.scss'
7
+ // import './DatepickerPlugin.scss'
8
+
9
+ registerLocale('de', de)
10
+
11
+ const DatePickerCustom: FC<DatePickerCustomProps> = ({
12
+ class: className,
13
+ dateFormat = 'MM/dd/yyyy',
14
+ isStartDate = false,
15
+ isValidGroup = false,
16
+ label,
17
+ locale = 'en',
18
+ name,
19
+ onChange,
20
+ relatedDate,
21
+ tooltip,
22
+ type,
23
+ validate = false,
24
+ value
25
+ }): React.JSX.Element => {
26
+ const [date, setDate] = useState(() => {
27
+ return typeof value === 'string' && value !== '' ? new Date(value) : null
28
+ })
29
+
30
+ const returnYears = (currentYear: number): React.JSX.Element[] => {
31
+ const years: React.JSX.Element[] = []
32
+ const minYear = new Date().getFullYear() - 100
33
+ const maxYear = new Date().getFullYear() + 500
34
+
35
+ for (let i = minYear; i <= maxYear; i++) {
36
+ years.push(
37
+ <option key={i} value={i} defaultValue={currentYear}>
38
+ {i}
39
+ </option>
40
+ )
41
+ }
42
+
43
+ return years
44
+ }
45
+
46
+ const handleChange = (date: Date | null): void => {
47
+ setDate(date)
48
+ if (onChange != null) {
49
+ const dateObject = {
50
+ target: {
51
+ name,
52
+ value: date
53
+ }
54
+ }
55
+ onChange(dateObject)
56
+ }
57
+ }
58
+
59
+ const addDays = (date, days): Date => {
60
+ const result = new Date(date)
61
+ result.setDate(result.getDate() + days)
62
+ return result
63
+ }
64
+
65
+ const classStyle = `${validate ? 'e-datepicker' : 'e-datepicker is-invalid'} ${className ?? ''} e-${type} ${
66
+ !isValidGroup ? '--group-invalid' : ''
67
+ }\``
68
+
69
+ let minDate
70
+ let maxDate
71
+ if (relatedDate != null) {
72
+ if (isStartDate) {
73
+ maxDate = relatedDate
74
+ maxDate = addDays(maxDate, -1)
75
+ } else {
76
+ minDate = relatedDate
77
+ minDate = addDays(minDate, 1)
78
+ }
79
+ }
80
+
81
+ const TooltipObject = tooltip !== undefined ? <p className='tooltip-form sans-serif --small'>{tooltip}</p> : ''
82
+
83
+ const actualYear = new Date().getFullYear()
84
+
85
+ const intlForMonths = new Intl.DateTimeFormat(locale, { month: 'long' })
86
+ const months = [...Array(12).keys()].map((monthIndex) => {
87
+ const monthName = intlForMonths.format(new Date(actualYear, monthIndex))
88
+ return {
89
+ monthName
90
+ }
91
+ })
92
+
93
+ return (
94
+ <div className={classStyle} data-qa={name}>
95
+ {TooltipObject}
96
+ <DatePicker
97
+ locale={locale}
98
+ dateFormat={dateFormat}
99
+ renderCustomHeader={({
100
+ date,
101
+ changeYear,
102
+ changeMonth,
103
+ decreaseMonth,
104
+ increaseMonth,
105
+ prevMonthButtonDisabled,
106
+ nextMonthButtonDisabled
107
+ }) => (
108
+ <div
109
+ style={{
110
+ margin: 10,
111
+ display: 'flex',
112
+ justifyContent: 'center'
113
+ }}
114
+ >
115
+ <button
116
+ className='DayPickerNavigation_leftButton'
117
+ onClick={decreaseMonth}
118
+ disabled={prevMonthButtonDisabled}
119
+ >
120
+ {'<'}
121
+ </button>
122
+ <select
123
+ className='CalendarYear'
124
+ value={date.getFullYear()}
125
+ onChange={({ target: { value } }) => {
126
+ changeYear(Number(value))
127
+ }}
128
+ >
129
+ {returnYears(date.getFullYear())}
130
+ </select>
131
+
132
+ <select
133
+ className='CalendarMonth'
134
+ value={date.getMonth()}
135
+ onChange={({ target: { value } }) => {
136
+ changeMonth(Number(value))
137
+ }}
138
+ >
139
+ {months.map(({ monthName }, value) => (
140
+ <option key={monthName} value={value} defaultValue={date.getMonth()}>
141
+ {monthName}
142
+ </option>
143
+ ))}
144
+ </select>
145
+
146
+ <button
147
+ className='DayPickerNavigation_rightButton'
148
+ onClick={increaseMonth}
149
+ disabled={nextMonthButtonDisabled}
150
+ >
151
+ {'>'}
152
+ </button>
153
+ </div>
154
+ )}
155
+ selected={date}
156
+ minDate={minDate}
157
+ maxDate={maxDate}
158
+ onChange={(date: Date | null) => {
159
+ handleChange(date)
160
+ }}
161
+ popperPlacement='bottom'
162
+ popperModifiers={[
163
+ {
164
+ name: 'flip',
165
+ options: {
166
+ fallbackPlacements: ['bottom']
167
+ }
168
+ }
169
+ ]}
170
+ />
171
+ <div className={'e-datepicker__inner'}>
172
+ <label className={'e-datepicker__label'}>{label}</label>
173
+ </div>
174
+ </div>
175
+ )
176
+ }
177
+
178
+ export default DatePickerCustom
@@ -0,0 +1,17 @@
1
+ export interface DatePickerCustomProps {
2
+ id?: string;
3
+ name?: string;
4
+ class?: string;
5
+ value?: string;
6
+ focused?: boolean;
7
+ validate?: boolean;
8
+ tooltip?: string;
9
+ isValidGroup?: boolean;
10
+ label?: string;
11
+ locale: string;
12
+ isStartDate?: boolean;
13
+ relatedDate?: Date;
14
+ type?: string;
15
+ dateFormat?: string;
16
+ onChange?: (dateObject: any) => void;
17
+ }
@@ -0,0 +1,17 @@
1
+ export interface DatePickerCustomProps {
2
+ id?: string
3
+ name?: string
4
+ class?: string
5
+ value?: string
6
+ focused?: boolean
7
+ validate?: boolean
8
+ tooltip?: string
9
+ isValidGroup?: boolean
10
+ label?: string
11
+ locale: string
12
+ isStartDate?: boolean
13
+ relatedDate?: Date
14
+ type?: string
15
+ dateFormat?: string
16
+ onChange?: (dateObject: any) => void
17
+ }