carbon-react 106.6.9 → 106.6.10
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/esm/components/date/__internal__/date-picker/date-picker.component.js +24 -11
- package/esm/components/date/__internal__/date-picker/date-picker.d.ts +2 -0
- package/esm/components/date/date.component.js +3 -2
- package/lib/components/date/__internal__/date-picker/date-picker.component.js +24 -11
- package/lib/components/date/__internal__/date-picker/date-picker.d.ts +2 -0
- package/lib/components/date/date.component.js +3 -2
- package/package.json +1 -1
|
@@ -17,7 +17,8 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
|
|
|
17
17
|
disablePortal,
|
|
18
18
|
onDayClick,
|
|
19
19
|
pickerMouseDown,
|
|
20
|
-
pickerProps
|
|
20
|
+
pickerProps,
|
|
21
|
+
open
|
|
21
22
|
}, ref) => {
|
|
22
23
|
const l = useLocale();
|
|
23
24
|
const {
|
|
@@ -27,22 +28,27 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
|
|
|
27
28
|
const {
|
|
28
29
|
weekStartsOn
|
|
29
30
|
} = options;
|
|
30
|
-
const monthsLong = Array.from({
|
|
31
|
+
const monthsLong = useMemo(() => Array.from({
|
|
31
32
|
length: 12
|
|
32
|
-
}).map((_, i) =>
|
|
33
|
-
|
|
33
|
+
}).map((_, i) => {
|
|
34
|
+
const month = localize.month(i);
|
|
35
|
+
return month[0].toUpperCase() + month.slice(1);
|
|
36
|
+
}), [localize]);
|
|
37
|
+
const monthsShort = useMemo(() => Array.from({
|
|
34
38
|
length: 12
|
|
35
39
|
}).map((_, i) => localize.month(i, {
|
|
36
40
|
width: "abbreviated"
|
|
37
|
-
}).substring(0, 3));
|
|
38
|
-
const weekdaysLong = Array.from({
|
|
41
|
+
}).substring(0, 3)), [localize]);
|
|
42
|
+
const weekdaysLong = useMemo(() => Array.from({
|
|
39
43
|
length: 7
|
|
40
|
-
}).map((_, i) => localize.day(i));
|
|
41
|
-
const weekdaysShort = Array.from({
|
|
44
|
+
}).map((_, i) => localize.day(i)), [localize]);
|
|
45
|
+
const weekdaysShort = useMemo(() => Array.from({
|
|
42
46
|
length: 7
|
|
43
|
-
}).map((_, i) => localize.day(i, l.locale()
|
|
47
|
+
}).map((_, i) => localize.day(i, ["de", "pl"].filter(str => l.locale().includes(str)).length ? {
|
|
48
|
+
width: "wide"
|
|
49
|
+
} : {
|
|
44
50
|
width: "abbreviated"
|
|
45
|
-
}).substring(0, 3));
|
|
51
|
+
}).substring(0, 3)), [l, localize]);
|
|
46
52
|
const popoverModifiers = useMemo(() => [{
|
|
47
53
|
name: "offset",
|
|
48
54
|
options: {
|
|
@@ -65,6 +71,10 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
|
|
|
65
71
|
|
|
66
72
|
const formatDay = date => `${weekdaysShort[date.getDay()]} ${date.getDate()} ${monthsShort[date.getMonth()]} ${date.getFullYear()}`;
|
|
67
73
|
|
|
74
|
+
if (!open) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
return /*#__PURE__*/React.createElement(Popover, {
|
|
69
79
|
placement: "bottom-start",
|
|
70
80
|
reference: inputElement,
|
|
@@ -125,6 +135,9 @@ DatePicker.propTypes = {
|
|
|
125
135
|
pickerProps: PropTypes.object,
|
|
126
136
|
|
|
127
137
|
/** Callback to handle mousedown event on picker */
|
|
128
|
-
pickerMouseDown: PropTypes.func
|
|
138
|
+
pickerMouseDown: PropTypes.func,
|
|
139
|
+
|
|
140
|
+
/** Sets whether the picker should be displayed */
|
|
141
|
+
open: PropTypes.bool
|
|
129
142
|
};
|
|
130
143
|
export default DatePicker;
|
|
@@ -16,6 +16,8 @@ export interface DatePickerProps extends Pick<DayPickerProps, "onDayClick"> {
|
|
|
16
16
|
selectedDays?: Date;
|
|
17
17
|
/** Callback to handle mousedown event on picker container */
|
|
18
18
|
pickerMouseDown?: () => void;
|
|
19
|
+
/** Sets whether the picker should be displayed */
|
|
20
|
+
open?: boolean;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
declare function DatePicker(
|
|
@@ -310,7 +310,7 @@ const DateInput = ({
|
|
|
310
310
|
size: size,
|
|
311
311
|
disabled: disabled,
|
|
312
312
|
readOnly: readOnly
|
|
313
|
-
})),
|
|
313
|
+
})), /*#__PURE__*/React.createElement(DatePicker, {
|
|
314
314
|
disablePortal: disablePortal,
|
|
315
315
|
inputElement: parentRef,
|
|
316
316
|
pickerProps: pickerProps,
|
|
@@ -320,7 +320,8 @@ const DateInput = ({
|
|
|
320
320
|
minDate: minDate,
|
|
321
321
|
maxDate: maxDate,
|
|
322
322
|
ref: pickerRef,
|
|
323
|
-
pickerMouseDown: handlePickerMouseDown
|
|
323
|
+
pickerMouseDown: handlePickerMouseDown,
|
|
324
|
+
open: open
|
|
324
325
|
}));
|
|
325
326
|
};
|
|
326
327
|
|
|
@@ -39,7 +39,8 @@ const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
39
39
|
disablePortal,
|
|
40
40
|
onDayClick,
|
|
41
41
|
pickerMouseDown,
|
|
42
|
-
pickerProps
|
|
42
|
+
pickerProps,
|
|
43
|
+
open
|
|
43
44
|
}, ref) => {
|
|
44
45
|
const l = (0, _useLocale.default)();
|
|
45
46
|
const {
|
|
@@ -49,22 +50,27 @@ const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
49
50
|
const {
|
|
50
51
|
weekStartsOn
|
|
51
52
|
} = options;
|
|
52
|
-
const monthsLong = Array.from({
|
|
53
|
+
const monthsLong = (0, _react.useMemo)(() => Array.from({
|
|
53
54
|
length: 12
|
|
54
|
-
}).map((_, i) =>
|
|
55
|
-
|
|
55
|
+
}).map((_, i) => {
|
|
56
|
+
const month = localize.month(i);
|
|
57
|
+
return month[0].toUpperCase() + month.slice(1);
|
|
58
|
+
}), [localize]);
|
|
59
|
+
const monthsShort = (0, _react.useMemo)(() => Array.from({
|
|
56
60
|
length: 12
|
|
57
61
|
}).map((_, i) => localize.month(i, {
|
|
58
62
|
width: "abbreviated"
|
|
59
|
-
}).substring(0, 3));
|
|
60
|
-
const weekdaysLong = Array.from({
|
|
63
|
+
}).substring(0, 3)), [localize]);
|
|
64
|
+
const weekdaysLong = (0, _react.useMemo)(() => Array.from({
|
|
61
65
|
length: 7
|
|
62
|
-
}).map((_, i) => localize.day(i));
|
|
63
|
-
const weekdaysShort = Array.from({
|
|
66
|
+
}).map((_, i) => localize.day(i)), [localize]);
|
|
67
|
+
const weekdaysShort = (0, _react.useMemo)(() => Array.from({
|
|
64
68
|
length: 7
|
|
65
|
-
}).map((_, i) => localize.day(i, l.locale()
|
|
69
|
+
}).map((_, i) => localize.day(i, ["de", "pl"].filter(str => l.locale().includes(str)).length ? {
|
|
70
|
+
width: "wide"
|
|
71
|
+
} : {
|
|
66
72
|
width: "abbreviated"
|
|
67
|
-
}).substring(0, 3));
|
|
73
|
+
}).substring(0, 3)), [l, localize]);
|
|
68
74
|
const popoverModifiers = (0, _react.useMemo)(() => [{
|
|
69
75
|
name: "offset",
|
|
70
76
|
options: {
|
|
@@ -87,6 +93,10 @@ const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
87
93
|
|
|
88
94
|
const formatDay = date => `${weekdaysShort[date.getDay()]} ${date.getDate()} ${monthsShort[date.getMonth()]} ${date.getFullYear()}`;
|
|
89
95
|
|
|
96
|
+
if (!open) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
90
100
|
return /*#__PURE__*/_react.default.createElement(_popover.default, {
|
|
91
101
|
placement: "bottom-start",
|
|
92
102
|
reference: inputElement,
|
|
@@ -148,7 +158,10 @@ DatePicker.propTypes = {
|
|
|
148
158
|
pickerProps: _propTypes.default.object,
|
|
149
159
|
|
|
150
160
|
/** Callback to handle mousedown event on picker */
|
|
151
|
-
pickerMouseDown: _propTypes.default.func
|
|
161
|
+
pickerMouseDown: _propTypes.default.func,
|
|
162
|
+
|
|
163
|
+
/** Sets whether the picker should be displayed */
|
|
164
|
+
open: _propTypes.default.bool
|
|
152
165
|
};
|
|
153
166
|
var _default = DatePicker;
|
|
154
167
|
exports.default = _default;
|
|
@@ -16,6 +16,8 @@ export interface DatePickerProps extends Pick<DayPickerProps, "onDayClick"> {
|
|
|
16
16
|
selectedDays?: Date;
|
|
17
17
|
/** Callback to handle mousedown event on picker container */
|
|
18
18
|
pickerMouseDown?: () => void;
|
|
19
|
+
/** Sets whether the picker should be displayed */
|
|
20
|
+
open?: boolean;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
declare function DatePicker(
|
|
@@ -335,7 +335,7 @@ const DateInput = ({
|
|
|
335
335
|
size: size,
|
|
336
336
|
disabled: disabled,
|
|
337
337
|
readOnly: readOnly
|
|
338
|
-
})),
|
|
338
|
+
})), /*#__PURE__*/_react.default.createElement(_datePicker.default, {
|
|
339
339
|
disablePortal: disablePortal,
|
|
340
340
|
inputElement: parentRef,
|
|
341
341
|
pickerProps: pickerProps,
|
|
@@ -345,7 +345,8 @@ const DateInput = ({
|
|
|
345
345
|
minDate: minDate,
|
|
346
346
|
maxDate: maxDate,
|
|
347
347
|
ref: pickerRef,
|
|
348
|
-
pickerMouseDown: handlePickerMouseDown
|
|
348
|
+
pickerMouseDown: handlePickerMouseDown,
|
|
349
|
+
open: open
|
|
349
350
|
}));
|
|
350
351
|
};
|
|
351
352
|
|