@punch-in/buffet-modern-core 3.3.11
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/README.md +50 -0
- package/babel.config.js +18 -0
- package/build/bundle.development.js +850 -0
- package/build/bundle.production.js +1 -0
- package/build/esm/components/AttributeIcon/Div.js +51 -0
- package/build/esm/components/AttributeIcon/index.js +53 -0
- package/build/esm/components/Button/index.js +75 -0
- package/build/esm/components/Checkbox/index.js +78 -0
- package/build/esm/components/Count/Wrapper.js +32 -0
- package/build/esm/components/Count/index.js +27 -0
- package/build/esm/components/DatePicker/index.js +206 -0
- package/build/esm/components/DatePicker/reducer.js +42 -0
- package/build/esm/components/Enumeration/index.js +54 -0
- package/build/esm/components/Error/index.js +137 -0
- package/build/esm/components/Error/reducer.js +23 -0
- package/build/esm/components/Flex/index.js +29 -0
- package/build/esm/components/HeaderActions/index.js +41 -0
- package/build/esm/components/HeaderTitle/index.js +45 -0
- package/build/esm/components/Icon/index.js +26 -0
- package/build/esm/components/IconLinks/index.js +36 -0
- package/build/esm/components/InputNumber/index.js +70 -0
- package/build/esm/components/InputText/PrefixIcon.js +32 -0
- package/build/esm/components/InputText/index.js +89 -0
- package/build/esm/components/Label/index.js +40 -0
- package/build/esm/components/List/index.js +50 -0
- package/build/esm/components/ListHeader/BaselineAlignement.js +5 -0
- package/build/esm/components/ListHeader/index.js +52 -0
- package/build/esm/components/ListRow/index.js +30 -0
- package/build/esm/components/ListRow/tests/index.tests.js +21 -0
- package/build/esm/components/NavTabs/index.js +38 -0
- package/build/esm/components/Option/RemoveButton.js +5 -0
- package/build/esm/components/Option/index.js +32 -0
- package/build/esm/components/Padded/index.js +56 -0
- package/build/esm/components/Paging/index.js +57 -0
- package/build/esm/components/Picker/PickerButton.js +61 -0
- package/build/esm/components/Picker/PickerSection.js +48 -0
- package/build/esm/components/Picker/PickerWrapper.js +5 -0
- package/build/esm/components/Picker/index.js +50 -0
- package/build/esm/components/PrefixIcon/index.js +7 -0
- package/build/esm/components/Select/index.js +82 -0
- package/build/esm/components/Separator/index.js +44 -0
- package/build/esm/components/Table/ActionCollapse.js +40 -0
- package/build/esm/components/Table/index.js +140 -0
- package/build/esm/components/Table/tests/index.js +130 -0
- package/build/esm/components/TableHeader/index.js +88 -0
- package/build/esm/components/TableRow/index.js +93 -0
- package/build/esm/components/Text/index.js +67 -0
- package/build/esm/components/Textarea/index.js +16 -0
- package/build/esm/components/TimePicker/index.js +288 -0
- package/build/esm/components/Toggle/index.js +72 -0
- package/build/esm/components/UnknownInput/index.js +19 -0
- package/build/esm/index.js +33 -0
- package/build/esm/theme/colors.js +48 -0
- package/build/index.js +8 -0
- package/package.json +123 -0
- package/src/components/AttributeIcon/Div.js +63 -0
- package/src/components/AttributeIcon/index.js +72 -0
- package/src/components/Button/index.js +95 -0
- package/src/components/Checkbox/index.js +86 -0
- package/src/components/Checkbox/tests/Checkbox.test.js +49 -0
- package/src/components/Count/Wrapper.js +36 -0
- package/src/components/Count/index.js +30 -0
- package/src/components/DatePicker/index.js +213 -0
- package/src/components/DatePicker/reducer.js +27 -0
- package/src/components/DatePicker/tests/__snapshots__/index.test.js.snap +301 -0
- package/src/components/DatePicker/tests/index.test.js +111 -0
- package/src/components/Enumeration/index.js +71 -0
- package/src/components/Enumeration/tests/index.test.js +41 -0
- package/src/components/Error/index.js +118 -0
- package/src/components/Error/reducer.js +14 -0
- package/src/components/Flex/index.js +25 -0
- package/src/components/Flex/tests/__snapshots__/index.test.js.snap +28 -0
- package/src/components/Flex/tests/index.test.js +11 -0
- package/src/components/HeaderActions/index.js +52 -0
- package/src/components/HeaderActions/tests/index.test.js +15 -0
- package/src/components/HeaderTitle/index.js +59 -0
- package/src/components/HeaderTitle/tests/index.test.js +15 -0
- package/src/components/Icon/index.js +50 -0
- package/src/components/Icon/tests/Icon.test.js +33 -0
- package/src/components/IconLinks/index.js +39 -0
- package/src/components/IconLinks/tests/index.test.js +27 -0
- package/src/components/InputNumber/index.js +74 -0
- package/src/components/InputText/PrefixIcon.js +38 -0
- package/src/components/InputText/index.js +88 -0
- package/src/components/Label/index.js +53 -0
- package/src/components/Label/tests/Label.test.js +38 -0
- package/src/components/List/index.js +56 -0
- package/src/components/List/tests/index.test.js +19 -0
- package/src/components/ListHeader/BaselineAlignement.js +7 -0
- package/src/components/ListHeader/index.js +58 -0
- package/src/components/ListHeader/tests/index.test.js +11 -0
- package/src/components/ListRow/index.js +34 -0
- package/src/components/ListRow/tests/index.tests.js +32 -0
- package/src/components/NavTabs/index.js +51 -0
- package/src/components/Option/RemoveButton.js +18 -0
- package/src/components/Option/index.js +32 -0
- package/src/components/Padded/index.js +47 -0
- package/src/components/Padded/tests/__snapshots__/index.test.js.snap +8 -0
- package/src/components/Padded/tests/index.test.js +11 -0
- package/src/components/Paging/index.js +66 -0
- package/src/components/Picker/PickerButton.js +84 -0
- package/src/components/Picker/PickerSection.js +41 -0
- package/src/components/Picker/PickerWrapper.js +7 -0
- package/src/components/Picker/index.js +44 -0
- package/src/components/Picker/tests/__snapshots__/pickerButton.test.js.snap +54 -0
- package/src/components/Picker/tests/__snapshots__/pickerSection.test.js.snap +20 -0
- package/src/components/Picker/tests/pickerButton.test.js +11 -0
- package/src/components/Picker/tests/pickerSection.test.js +11 -0
- package/src/components/PrefixIcon/index.js +11 -0
- package/src/components/Select/index.js +110 -0
- package/src/components/Select/tests/index.test.js +85 -0
- package/src/components/Separator/index.js +49 -0
- package/src/components/Table/ActionCollapse.js +53 -0
- package/src/components/Table/index.js +172 -0
- package/src/components/Table/tests/index.js +146 -0
- package/src/components/TableHeader/index.js +103 -0
- package/src/components/TableHeader/tests/index.test.js +85 -0
- package/src/components/TableRow/index.js +116 -0
- package/src/components/TableRow/tests/index.test.js +89 -0
- package/src/components/Text/index.js +62 -0
- package/src/components/Text/tests/__snapshots__/index.test.js.snap +19 -0
- package/src/components/Text/tests/index.test.js +11 -0
- package/src/components/Textarea/index.js +19 -0
- package/src/components/Textarea/tests/index.test.js +23 -0
- package/src/components/TimePicker/index.js +328 -0
- package/src/components/TimePicker/tests/index.test.js +95 -0
- package/src/components/Toggle/index.js +83 -0
- package/src/components/Toggle/tests/index.test.js +40 -0
- package/src/components/UnknownInput/index.js +20 -0
- package/src/index.js +33 -0
- package/src/theme/colors.js +48 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Datepicker
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, { useEffect, useReducer } from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
|
|
10
|
+
import moment from 'moment';
|
|
11
|
+
import momentPropTypes from 'react-moment-proptypes';
|
|
12
|
+
import 'react-dates/initialize';
|
|
13
|
+
import { DayPickerSingleDateController } from 'react-dates';
|
|
14
|
+
import { faCalendarAlt } from '@fortawesome/free-regular-svg-icons';
|
|
15
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
16
|
+
|
|
17
|
+
import { DatePicker as StyledDatepicker } from '@punch-in/buffet-modern';
|
|
18
|
+
|
|
19
|
+
import reducer, { initialState } from './reducer';
|
|
20
|
+
|
|
21
|
+
import Input from '../InputText';
|
|
22
|
+
|
|
23
|
+
function Datepicker({
|
|
24
|
+
className,
|
|
25
|
+
value,
|
|
26
|
+
withDefaultValue,
|
|
27
|
+
disabled,
|
|
28
|
+
displayFormat,
|
|
29
|
+
id,
|
|
30
|
+
name,
|
|
31
|
+
onChange,
|
|
32
|
+
readOnly,
|
|
33
|
+
tabIndex,
|
|
34
|
+
wait,
|
|
35
|
+
}) {
|
|
36
|
+
const [state, dispatch] = useReducer(reducer, initialState);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
let date = null;
|
|
40
|
+
let displayedDate = '';
|
|
41
|
+
|
|
42
|
+
if (withDefaultValue && !value) {
|
|
43
|
+
date = moment();
|
|
44
|
+
displayedDate = date.format('MM/DD/YYYY');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!!value && moment(value).isValid()) {
|
|
48
|
+
date = value._isAMomentObject === true ? value : moment(value);
|
|
49
|
+
displayedDate = date.format('MM/DD/YYYY');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
dispatch({
|
|
53
|
+
type: 'SET_DATE',
|
|
54
|
+
date,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
dispatch({
|
|
58
|
+
type: 'SET_DISPLAYED_DATE',
|
|
59
|
+
displayedDate,
|
|
60
|
+
});
|
|
61
|
+
}, [value, withDefaultValue]);
|
|
62
|
+
|
|
63
|
+
let timer = null;
|
|
64
|
+
const { date, displayedDate, isFocused, isVisible } = state;
|
|
65
|
+
|
|
66
|
+
const getDateValue = () => {
|
|
67
|
+
let dateValue = date ? date.format(displayFormat) : '';
|
|
68
|
+
|
|
69
|
+
if (isVisible) {
|
|
70
|
+
dateValue = displayedDate;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return dateValue;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleChange = ({ target }) => {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
|
|
79
|
+
dispatch({
|
|
80
|
+
type: 'SET_IS_FOCUSED',
|
|
81
|
+
isFocused: false,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
dispatch({
|
|
85
|
+
type: 'SET_DISPLAYED_DATE',
|
|
86
|
+
displayedDate: target.value,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
timer = setTimeout(() => {
|
|
90
|
+
// Clearing the input
|
|
91
|
+
if (!target.value) {
|
|
92
|
+
onChange({ target: { name, type: 'date', value: null } });
|
|
93
|
+
|
|
94
|
+
dispatch({
|
|
95
|
+
type: 'SET_DATE',
|
|
96
|
+
date: null,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
dispatch({
|
|
100
|
+
type: 'SET_DISPLAYED_DATE',
|
|
101
|
+
displayedDate: '',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
handleDateChange(moment(target.value, 'MM/DD/YYYY'));
|
|
108
|
+
}, wait);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const handleDateChange = dateValue => {
|
|
112
|
+
if (moment(dateValue).isValid()) {
|
|
113
|
+
onChange({ target: { name, type: 'date', value: dateValue } });
|
|
114
|
+
|
|
115
|
+
dispatch({
|
|
116
|
+
type: 'SET_DATE',
|
|
117
|
+
date: dateValue,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
dispatch({
|
|
121
|
+
type: 'SET_DISPLAYED_DATE',
|
|
122
|
+
displayedDate: dateValue.format('MM/DD/YYYY'),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const handleDateClick = dateValue => {
|
|
128
|
+
handleDateChange(dateValue);
|
|
129
|
+
|
|
130
|
+
toggleDatepicker(false);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const handleTabClick = ({ keyCode, which }) => {
|
|
134
|
+
const code = keyCode || which;
|
|
135
|
+
|
|
136
|
+
if (code === 9) {
|
|
137
|
+
toggleDatepicker(false);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const toggleDatepicker = shown => {
|
|
142
|
+
dispatch({
|
|
143
|
+
type: 'SET_IS_VISIBLE',
|
|
144
|
+
isVisible: shown,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
dispatch({
|
|
148
|
+
type: 'SET_IS_FOCUSED',
|
|
149
|
+
isFocused: shown,
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<StyledDatepicker isOpen={isVisible} className={className}>
|
|
155
|
+
<div>
|
|
156
|
+
<Input
|
|
157
|
+
disabled={disabled}
|
|
158
|
+
type="text"
|
|
159
|
+
name="start_date"
|
|
160
|
+
id={id || name}
|
|
161
|
+
value={getDateValue()}
|
|
162
|
+
readOnly={readOnly}
|
|
163
|
+
onChange={handleChange}
|
|
164
|
+
icon={<FontAwesomeIcon icon={faCalendarAlt} />}
|
|
165
|
+
onFocus={() => toggleDatepicker(true)}
|
|
166
|
+
onClick={() => toggleDatepicker(true)}
|
|
167
|
+
onKeyDown={handleTabClick}
|
|
168
|
+
tabIndex={tabIndex}
|
|
169
|
+
/>
|
|
170
|
+
</div>
|
|
171
|
+
{isFocused && (
|
|
172
|
+
<DayPickerSingleDateController
|
|
173
|
+
date={date}
|
|
174
|
+
focused
|
|
175
|
+
numberOfMonths={1}
|
|
176
|
+
onDateChange={handleDateClick}
|
|
177
|
+
onOutsideClick={() => toggleDatepicker(false)}
|
|
178
|
+
daySize={37}
|
|
179
|
+
transitionDuration={0}
|
|
180
|
+
/>
|
|
181
|
+
)}
|
|
182
|
+
</StyledDatepicker>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
Datepicker.defaultProps = {
|
|
187
|
+
className: null,
|
|
188
|
+
disabled: false,
|
|
189
|
+
displayFormat: 'MMMM DD, YYYY',
|
|
190
|
+
id: 'date',
|
|
191
|
+
onChange: () => {},
|
|
192
|
+
readOnly: false,
|
|
193
|
+
tabIndex: '0',
|
|
194
|
+
value: null,
|
|
195
|
+
wait: 600,
|
|
196
|
+
withDefaultValue: false,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
Datepicker.propTypes = {
|
|
200
|
+
className: PropTypes.string,
|
|
201
|
+
disabled: PropTypes.bool,
|
|
202
|
+
displayFormat: PropTypes.string,
|
|
203
|
+
id: PropTypes.string,
|
|
204
|
+
name: PropTypes.string.isRequired,
|
|
205
|
+
onChange: PropTypes.func,
|
|
206
|
+
readOnly: PropTypes.bool,
|
|
207
|
+
tabIndex: PropTypes.string,
|
|
208
|
+
value: PropTypes.oneOfType([momentPropTypes.momentObj, PropTypes.string]),
|
|
209
|
+
wait: PropTypes.number,
|
|
210
|
+
withDefaultValue: PropTypes.bool,
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export default Datepicker;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const initialState = {
|
|
2
|
+
date: null,
|
|
3
|
+
displayedDate: '',
|
|
4
|
+
isFocused: false,
|
|
5
|
+
isVisible: false,
|
|
6
|
+
visibleDate: '',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function reducer(state, action) {
|
|
10
|
+
const { date, displayedDate, isFocused, isVisible, type } = action;
|
|
11
|
+
|
|
12
|
+
switch (type) {
|
|
13
|
+
case 'SET_DATE':
|
|
14
|
+
return { ...state, date };
|
|
15
|
+
case 'SET_DISPLAYED_DATE':
|
|
16
|
+
return { ...state, displayedDate };
|
|
17
|
+
case 'SET_IS_FOCUSED':
|
|
18
|
+
return { ...state, isFocused };
|
|
19
|
+
case 'SET_IS_VISIBLE':
|
|
20
|
+
return { ...state, isVisible };
|
|
21
|
+
default:
|
|
22
|
+
return state;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default reducer;
|
|
27
|
+
export { initialState };
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`<DatePicker /> should match snapshot 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
.c0 {
|
|
6
|
+
position: relative;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.c0 * {
|
|
10
|
+
font-family: 'Lato';
|
|
11
|
+
outline: 0;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.c0 .DateInput {
|
|
16
|
+
width: 100%;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.c0 svg.fa-calendar-alt {
|
|
20
|
+
font-size: 14px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.c0 input {
|
|
24
|
+
font-weight: 400;
|
|
25
|
+
position: relative;
|
|
26
|
+
z-index: 1;
|
|
27
|
+
width: 100%;
|
|
28
|
+
height: 3.4rem;
|
|
29
|
+
padding: 0 1rem;
|
|
30
|
+
font-size: 1.3rem;
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
border: 1px solid #E3E9F3;
|
|
33
|
+
border-radius: 2px;
|
|
34
|
+
color: #000000;
|
|
35
|
+
background-color: transparent;
|
|
36
|
+
padding-left: 42px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.c0 input::-webkit-input-placeholder {
|
|
40
|
+
color: #919BAE;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.c0 input:disabled {
|
|
44
|
+
background-color: transparent;
|
|
45
|
+
cursor: not-allowed;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.c0 .SingleDatePicker,
|
|
49
|
+
.c0 .SingleDatePickerInput__withBorder {
|
|
50
|
+
width: 100%;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.c0 .SingleDatePickerInput__withBorder {
|
|
54
|
+
border: 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.c0 .DateInput_input__focused {
|
|
58
|
+
border-color: #78caff;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.c0 .DayPicker_weekHeader {
|
|
62
|
+
color: #000000;
|
|
63
|
+
border-top: 1px solid #f9f9f9;
|
|
64
|
+
margin-top: -10px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.c0 .DayPicker_weekHeader li {
|
|
68
|
+
padding-top: 7px;
|
|
69
|
+
padding-bottom: 5px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.c0 .DayPicker_weekHeader li small {
|
|
73
|
+
font-size: 1.3rem;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.c0 .DayPicker__withBorder {
|
|
77
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
78
|
+
border: 1px solid #f9f9f9;
|
|
79
|
+
background: white;
|
|
80
|
+
position: absolute;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.c0 .DateInput_fang {
|
|
84
|
+
display: none;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.c0 .CalendarMonth_caption {
|
|
88
|
+
font-size: 1.3rem;
|
|
89
|
+
padding-bottom: 45px;
|
|
90
|
+
padding-top: 23px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.c0 .DayPicker_transitionContainer {
|
|
94
|
+
padding: 4px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.c0 .DayPickerKeyboardShortcuts_show {
|
|
98
|
+
display: none;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.c0 .DayPickerNavigation div[role='button'] {
|
|
102
|
+
font-size: 21px;
|
|
103
|
+
width: 35px;
|
|
104
|
+
height: 33px;
|
|
105
|
+
color: #000000;
|
|
106
|
+
border-radius: 0;
|
|
107
|
+
text-align: center;
|
|
108
|
+
top: 20px;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.c0 .DayPickerNavigation div[role='button'],
|
|
112
|
+
.c0 .DayPickerNavigation div[role='button']:hover {
|
|
113
|
+
border: 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.c0 .DayPickerNavigation div[role='button'].DayPickerNavigation_leftButton__horizontalDefault::before {
|
|
117
|
+
content: '‹';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.c0 .DayPickerNavigation div[role='button'].DayPickerNavigation_rightButton__horizontalDefault::before {
|
|
121
|
+
content: '›';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.c0 .DayPickerNavigation div[role='button'] svg {
|
|
125
|
+
display: none;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.c0 .DayPickerNavigation div[role='button']:hover {
|
|
129
|
+
background: #eee;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.c0 td {
|
|
133
|
+
position: relative;
|
|
134
|
+
cursor: pointer;
|
|
135
|
+
width: 34px;
|
|
136
|
+
height: 18px;
|
|
137
|
+
font-size: 1.3rem;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.c0 td,
|
|
141
|
+
.c0 td.CalendarDay__selected,
|
|
142
|
+
.c0 td.CalendarDay__selected:active,
|
|
143
|
+
.c0 td.CalendarDay__selected:hover,
|
|
144
|
+
.c0 td.CalendarDay__default:hover {
|
|
145
|
+
border: 0;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.c0 td.CalendarDay__today::before {
|
|
149
|
+
content: '';
|
|
150
|
+
display: inline-block;
|
|
151
|
+
border-left: 7px solid transparent;
|
|
152
|
+
border-bottom: 7px solid #005fea;
|
|
153
|
+
border-top-color: rgba(0,0,0,0.2);
|
|
154
|
+
position: absolute;
|
|
155
|
+
bottom: 4px;
|
|
156
|
+
right: 4px;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.c0 td.CalendarDay__selected {
|
|
160
|
+
background-color: #007eff;
|
|
161
|
+
color: #fff;
|
|
162
|
+
text-shadow: 0 -1px 0 rgba(0,0,0,0.25);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.c0 td.CalendarDay__selected.CalendarDay__today::before {
|
|
166
|
+
border-bottom: 7px solid white;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.c2 {
|
|
170
|
+
width: calc(3.4rem - 2px);
|
|
171
|
+
height: calc(3.4rem - 2px);
|
|
172
|
+
color: #B3B5B9;
|
|
173
|
+
position: absolute;
|
|
174
|
+
left: 1px;
|
|
175
|
+
top: 1px;
|
|
176
|
+
background-color: #FAFAFB;
|
|
177
|
+
display: -webkit-box;
|
|
178
|
+
display: -webkit-flex;
|
|
179
|
+
display: -ms-flexbox;
|
|
180
|
+
display: flex;
|
|
181
|
+
-webkit-align-items: center;
|
|
182
|
+
-webkit-box-align: center;
|
|
183
|
+
-ms-flex-align: center;
|
|
184
|
+
align-items: center;
|
|
185
|
+
-webkit-box-pack: center;
|
|
186
|
+
-webkit-justify-content: center;
|
|
187
|
+
-ms-flex-pack: center;
|
|
188
|
+
justify-content: center;
|
|
189
|
+
font-size: 13px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.c3 {
|
|
193
|
+
width: 100%;
|
|
194
|
+
height: 3.4rem;
|
|
195
|
+
padding: 0 1rem;
|
|
196
|
+
font-weight: 400;
|
|
197
|
+
font-size: 1.3rem;
|
|
198
|
+
cursor: text;
|
|
199
|
+
outline: 0;
|
|
200
|
+
border: 1px solid #E3E9F3;
|
|
201
|
+
border-radius: 2px;
|
|
202
|
+
color: #333740;
|
|
203
|
+
background-color: transparent;
|
|
204
|
+
padding-left: calc(3.4rem + 1rem);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.c3::-webkit-input-placeholder {
|
|
208
|
+
color: #919BAE;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.c3:focus {
|
|
212
|
+
border-color: #78caff;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.c3:disabled {
|
|
216
|
+
background-color: #FAFAFB;
|
|
217
|
+
cursor: not-allowed;
|
|
218
|
+
color: #9ea7b8;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.c1 {
|
|
222
|
+
position: relative;
|
|
223
|
+
background-color: #ffffff;
|
|
224
|
+
border-radius: 2px;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.c1 button[type='button'] {
|
|
228
|
+
width: 3.4rem;
|
|
229
|
+
height: 3.4rem;
|
|
230
|
+
position: absolute;
|
|
231
|
+
top: 0;
|
|
232
|
+
right: 0;
|
|
233
|
+
z-index: 2;
|
|
234
|
+
cursor: pointer;
|
|
235
|
+
outline: 0;
|
|
236
|
+
border: 0;
|
|
237
|
+
background: transparent;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.c1 button[type='button']:hover span::before {
|
|
241
|
+
color: #000000;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.c1 button[type='button'].shown span::before {
|
|
245
|
+
color: #000000;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.c1 button[type='button'].shown + input[type='text'] {
|
|
249
|
+
padding-right: calc(3.4rem + 1rem);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.c1 span {
|
|
253
|
+
border-top-left-radius: 2px;
|
|
254
|
+
border-bottom-left-radius: 2px;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.c1 input {
|
|
258
|
+
position: relative;
|
|
259
|
+
z-index: 1;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
<div
|
|
263
|
+
class="c0"
|
|
264
|
+
>
|
|
265
|
+
<div>
|
|
266
|
+
<div
|
|
267
|
+
class="c1"
|
|
268
|
+
>
|
|
269
|
+
<span
|
|
270
|
+
class="c2"
|
|
271
|
+
>
|
|
272
|
+
<svg
|
|
273
|
+
aria-hidden="true"
|
|
274
|
+
class="svg-inline--fa fa-calendar-alt fa-w-14 "
|
|
275
|
+
data-icon="calendar-alt"
|
|
276
|
+
data-prefix="far"
|
|
277
|
+
focusable="false"
|
|
278
|
+
role="img"
|
|
279
|
+
viewBox="0 0 448 512"
|
|
280
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
281
|
+
>
|
|
282
|
+
<path
|
|
283
|
+
d="M148 288h-40c-6.6 0-12-5.4-12-12v-40c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12zm108-12v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm96 0v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm-96 96v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm-96 0v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm192 0v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm96-260v352c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V112c0-26.5 21.5-48 48-48h48V12c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h128V12c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h48c26.5 0 48 21.5 48 48zm-48 346V160H48v298c0 3.3 2.7 6 6 6h340c3.3 0 6-2.7 6-6z"
|
|
284
|
+
fill="currentColor"
|
|
285
|
+
/>
|
|
286
|
+
</svg>
|
|
287
|
+
</span>
|
|
288
|
+
<input
|
|
289
|
+
autocomplete="off"
|
|
290
|
+
class="c3"
|
|
291
|
+
id="date"
|
|
292
|
+
name="start_date"
|
|
293
|
+
tabindex="0"
|
|
294
|
+
type="text"
|
|
295
|
+
value=""
|
|
296
|
+
/>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
</DocumentFragment>
|
|
301
|
+
`;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { mount } from 'enzyme';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import { DayPickerSingleDateController } from 'react-dates';
|
|
5
|
+
import { act, cleanup, render } from '@testing-library/react';
|
|
6
|
+
|
|
7
|
+
import InputText from '../../InputText';
|
|
8
|
+
import DatePicker from '../index';
|
|
9
|
+
|
|
10
|
+
jest.useFakeTimers();
|
|
11
|
+
|
|
12
|
+
const defaultProps = {
|
|
13
|
+
type: 'date',
|
|
14
|
+
name: 'date',
|
|
15
|
+
onChange: jest.fn(),
|
|
16
|
+
};
|
|
17
|
+
const renderComponent = (props = defaultProps) =>
|
|
18
|
+
mount(<DatePicker {...props} />);
|
|
19
|
+
|
|
20
|
+
describe('<DatePicker />', () => {
|
|
21
|
+
afterEach(cleanup);
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line jest/expect-expect
|
|
24
|
+
it('should not crash', () => {
|
|
25
|
+
renderComponent();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should match snapshot', () => {
|
|
29
|
+
const { asFragment } = render(<DatePicker {...defaultProps} />);
|
|
30
|
+
|
|
31
|
+
expect(asFragment()).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should render an input text', () => {
|
|
35
|
+
const wrapper = renderComponent();
|
|
36
|
+
|
|
37
|
+
const input = wrapper.find(InputText);
|
|
38
|
+
expect(input).toHaveLength(1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should render a date picker on input text click', () => {
|
|
42
|
+
const onChange = jest.fn();
|
|
43
|
+
|
|
44
|
+
const props = {
|
|
45
|
+
...defaultProps,
|
|
46
|
+
onChange,
|
|
47
|
+
value: moment(new Date(), 'YYYY-MM-DD'),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const wrapper = renderComponent(props);
|
|
51
|
+
const input = wrapper.find('input');
|
|
52
|
+
|
|
53
|
+
input.simulate('click');
|
|
54
|
+
|
|
55
|
+
const datePicker = wrapper.find(DayPickerSingleDateController);
|
|
56
|
+
|
|
57
|
+
expect(datePicker).toHaveLength(1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should render onChange props on datepicker select', () => {
|
|
61
|
+
const onChange = jest.fn();
|
|
62
|
+
|
|
63
|
+
const props = {
|
|
64
|
+
...defaultProps,
|
|
65
|
+
onChange,
|
|
66
|
+
value: moment(new Date(), 'YYYY-MM-DD'),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const wrapper = renderComponent(props);
|
|
70
|
+
const input = wrapper.find('input');
|
|
71
|
+
|
|
72
|
+
input.simulate('click');
|
|
73
|
+
|
|
74
|
+
const datePicker = wrapper.find(DayPickerSingleDateController);
|
|
75
|
+
|
|
76
|
+
act(() => {
|
|
77
|
+
datePicker.props().onDateChange(moment('1993-07-05', 'YYYY-MM-DD'));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
81
|
+
target: {
|
|
82
|
+
name: 'date',
|
|
83
|
+
type: 'date',
|
|
84
|
+
value: moment('1993-07-05', 'YYYY-MM-DD'),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should display the date value in a human readable format', () => {
|
|
90
|
+
const onChange = jest.fn();
|
|
91
|
+
|
|
92
|
+
const props = {
|
|
93
|
+
...defaultProps,
|
|
94
|
+
onChange,
|
|
95
|
+
value: moment('1993-07-05', 'YYYY-MM-DD'),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const wrapper = renderComponent(props);
|
|
99
|
+
const input = wrapper.find('input');
|
|
100
|
+
|
|
101
|
+
expect(input.props().value).toBe('July 05, 1993');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should use the defaultProps', () => {
|
|
105
|
+
const {
|
|
106
|
+
defaultProps: { onChange },
|
|
107
|
+
} = DatePicker;
|
|
108
|
+
|
|
109
|
+
expect(onChange).toBeDefined();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Enumeration
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import {
|
|
10
|
+
Enumeration as StyledEnumeration,
|
|
11
|
+
EnumerationWrapper,
|
|
12
|
+
} from '@punch-in/buffet-modern';
|
|
13
|
+
|
|
14
|
+
import Label from '../Label';
|
|
15
|
+
|
|
16
|
+
function Enumeration({
|
|
17
|
+
disabled,
|
|
18
|
+
id,
|
|
19
|
+
className,
|
|
20
|
+
name,
|
|
21
|
+
onChange,
|
|
22
|
+
options,
|
|
23
|
+
value,
|
|
24
|
+
}) {
|
|
25
|
+
return (
|
|
26
|
+
<EnumerationWrapper className={className}>
|
|
27
|
+
{options.map(option => (
|
|
28
|
+
<Label key={option.value} htmlFor={id || name}>
|
|
29
|
+
<StyledEnumeration
|
|
30
|
+
disabled={disabled}
|
|
31
|
+
checked={option.value === value}
|
|
32
|
+
name={id || name}
|
|
33
|
+
onChange={onChange}
|
|
34
|
+
value={option.value}
|
|
35
|
+
/>
|
|
36
|
+
<span>{option.label}</span>
|
|
37
|
+
</Label>
|
|
38
|
+
))}
|
|
39
|
+
</EnumerationWrapper>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Enumeration.defaultProps = {
|
|
44
|
+
className: null,
|
|
45
|
+
disabled: false,
|
|
46
|
+
id: null,
|
|
47
|
+
onChange: () => {},
|
|
48
|
+
options: [],
|
|
49
|
+
value: null,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
Enumeration.propTypes = {
|
|
53
|
+
className: PropTypes.string,
|
|
54
|
+
disabled: PropTypes.bool,
|
|
55
|
+
id: PropTypes.string,
|
|
56
|
+
name: PropTypes.string.isRequired,
|
|
57
|
+
onChange: PropTypes.func,
|
|
58
|
+
options: PropTypes.arrayOf(
|
|
59
|
+
PropTypes.shape({
|
|
60
|
+
label: PropTypes.string,
|
|
61
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
62
|
+
})
|
|
63
|
+
),
|
|
64
|
+
value: PropTypes.oneOfType([
|
|
65
|
+
PropTypes.string,
|
|
66
|
+
PropTypes.bool,
|
|
67
|
+
PropTypes.object,
|
|
68
|
+
]),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default Enumeration;
|