@patternfly/react-core 4.189.5 → 4.190.0
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/CHANGELOG.md +11 -0
- package/dist/esm/components/TimePicker/TimePicker.d.ts +6 -4
- package/dist/esm/components/TimePicker/TimePicker.d.ts.map +1 -1
- package/dist/esm/components/TimePicker/TimePicker.js +37 -26
- package/dist/esm/components/TimePicker/TimePicker.js.map +1 -1
- package/dist/esm/components/TimePicker/TimePickerUtils.d.ts +3 -2
- package/dist/esm/components/TimePicker/TimePickerUtils.d.ts.map +1 -1
- package/dist/esm/components/TimePicker/TimePickerUtils.js +57 -42
- package/dist/esm/components/TimePicker/TimePickerUtils.js.map +1 -1
- package/dist/js/components/TimePicker/TimePicker.d.ts +6 -4
- package/dist/js/components/TimePicker/TimePicker.d.ts.map +1 -1
- package/dist/js/components/TimePicker/TimePicker.js +36 -25
- package/dist/js/components/TimePicker/TimePicker.js.map +1 -1
- package/dist/js/components/TimePicker/TimePickerUtils.d.ts +3 -2
- package/dist/js/components/TimePicker/TimePickerUtils.d.ts.map +1 -1
- package/dist/js/components/TimePicker/TimePickerUtils.js +59 -43
- package/dist/js/components/TimePicker/TimePickerUtils.js.map +1 -1
- package/dist/umd/react-core.js +93 -67
- package/dist/umd/react-core.min.css +252 -252
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +5 -5
- package/src/components/TimePicker/TimePicker.tsx +54 -31
- package/src/components/TimePicker/TimePickerUtils.tsx +76 -39
- package/src/components/TimePicker/__tests__/TimePicker.test.tsx +49 -11
- package/src/components/TimePicker/examples/TimePicker.md +19 -2
package/dist/umd/react-core.js
CHANGED
|
@@ -17821,7 +17821,7 @@
|
|
|
17821
17821
|
.getMinutes()
|
|
17822
17822
|
.toString()
|
|
17823
17823
|
.padStart(2, '0');
|
|
17824
|
-
const timeOption = hour
|
|
17824
|
+
const timeOption = `${hour}${delimiter}${minutes}${hour12 ? suffix : ''}`;
|
|
17825
17825
|
// time option is valid if within min/max constraints
|
|
17826
17826
|
if (isWithinMinMax(minTime, maxTime, timeOption, delimiter)) {
|
|
17827
17827
|
res.push(timeOption);
|
|
@@ -17830,7 +17830,7 @@
|
|
|
17830
17830
|
}
|
|
17831
17831
|
return res;
|
|
17832
17832
|
};
|
|
17833
|
-
const parseTime = (time, timeRegex, delimiter, is12Hour) => {
|
|
17833
|
+
const parseTime = (time, timeRegex, delimiter, is12Hour, includeSeconds) => {
|
|
17834
17834
|
const date = new Date(time);
|
|
17835
17835
|
// if default time is a ISO 8601 formatted date string, we parse it to hh:mm(am/pm) format
|
|
17836
17836
|
if (!isNaN(date.getDate()) && (time instanceof Date || time.includes('T'))) {
|
|
@@ -17838,6 +17838,8 @@
|
|
|
17838
17838
|
? `${date.getHours() > 12 ? date.getHours() - 12 : date.getHours()}`
|
|
17839
17839
|
: `${date.getHours()}`.padStart(2, '0');
|
|
17840
17840
|
const minutes = `${date.getMinutes()}`.padStart(2, '0');
|
|
17841
|
+
const seconds = includeSeconds ? `${date.getSeconds()}`.padStart(2, '0') : '';
|
|
17842
|
+
const secondsWithDelimiter = seconds ? `${delimiter}${seconds}` : '';
|
|
17841
17843
|
let ampm = '';
|
|
17842
17844
|
if (is12Hour && date.getHours() > 11) {
|
|
17843
17845
|
ampm = pmSuffix;
|
|
@@ -17845,27 +17847,30 @@
|
|
|
17845
17847
|
else if (is12Hour) {
|
|
17846
17848
|
ampm = amSuffix;
|
|
17847
17849
|
}
|
|
17848
|
-
return `${hours}${delimiter}${minutes}${ampm}`;
|
|
17850
|
+
return `${hours}${delimiter}${minutes}${secondsWithDelimiter}${ampm}`;
|
|
17849
17851
|
}
|
|
17850
17852
|
else if (typeof time === 'string') {
|
|
17851
17853
|
time = time.trim();
|
|
17852
|
-
if (
|
|
17853
|
-
const [, hours, minutes, suffix = ''] = timeRegex.exec(time);
|
|
17854
|
-
const
|
|
17855
|
-
// Format AM/PM according to design
|
|
17854
|
+
if (time !== '' && validateTime(time, timeRegex, delimiter, is12Hour)) {
|
|
17855
|
+
const [, hours, minutes, seconds, suffix = ''] = timeRegex.exec(time);
|
|
17856
|
+
const secondsWithDelimiter = includeSeconds ? `${delimiter}${seconds !== null && seconds !== void 0 ? seconds : '00'}` : '';
|
|
17856
17857
|
let ampm = '';
|
|
17857
|
-
|
|
17858
|
-
|
|
17859
|
-
|
|
17860
|
-
|
|
17861
|
-
|
|
17862
|
-
|
|
17863
|
-
|
|
17864
|
-
|
|
17865
|
-
|
|
17866
|
-
|
|
17858
|
+
// Format AM/PM according to design
|
|
17859
|
+
if (is12Hour) {
|
|
17860
|
+
const uppercaseSuffix = suffix.toUpperCase();
|
|
17861
|
+
if (uppercaseSuffix === amSuffix.toUpperCase().trim()) {
|
|
17862
|
+
ampm = amSuffix;
|
|
17863
|
+
}
|
|
17864
|
+
else if (uppercaseSuffix === pmSuffix.toUpperCase().trim()) {
|
|
17865
|
+
ampm = pmSuffix;
|
|
17866
|
+
}
|
|
17867
|
+
else {
|
|
17868
|
+
// if this 12 hour time is missing am/pm but otherwise valid,
|
|
17869
|
+
// append am/pm depending on time of day
|
|
17870
|
+
ampm = new Date().getHours() > 11 ? pmSuffix : amSuffix;
|
|
17871
|
+
}
|
|
17867
17872
|
}
|
|
17868
|
-
return `${hours}${delimiter}${minutes}${ampm}`;
|
|
17873
|
+
return `${hours}${delimiter}${minutes}${secondsWithDelimiter}${ampm}`;
|
|
17869
17874
|
}
|
|
17870
17875
|
}
|
|
17871
17876
|
return time.toString();
|
|
@@ -17886,10 +17891,10 @@
|
|
|
17886
17891
|
const getHours = (time, timeRegex) => {
|
|
17887
17892
|
const parts = time.match(timeRegex);
|
|
17888
17893
|
if (parts && parts.length) {
|
|
17889
|
-
if (/pm/i.test(parts[
|
|
17894
|
+
if (/pm/i.test(parts[4])) {
|
|
17890
17895
|
return parseInt(parts[1]) === 12 ? parseInt(parts[1]) : parseInt(parts[1]) + 12;
|
|
17891
17896
|
}
|
|
17892
|
-
if (/am/i.test(parts[
|
|
17897
|
+
if (/am/i.test(parts[4])) {
|
|
17893
17898
|
return parseInt(parts[1]) === 12 ? 0 : parseInt(parts[1]);
|
|
17894
17899
|
}
|
|
17895
17900
|
return parseInt(parts[1]);
|
|
@@ -17900,34 +17905,44 @@
|
|
|
17900
17905
|
const parts = time.match(timeRegex);
|
|
17901
17906
|
return parts && parts.length ? parseInt(parts[2]) : null;
|
|
17902
17907
|
};
|
|
17903
|
-
const
|
|
17908
|
+
const getSeconds = (time, timeRegex) => {
|
|
17909
|
+
var _a;
|
|
17910
|
+
const seconds = (_a = time.match(timeRegex)) === null || _a === void 0 ? void 0 : _a[3];
|
|
17911
|
+
return seconds ? parseInt(seconds) : null;
|
|
17912
|
+
};
|
|
17913
|
+
const isWithinMinMax = (minTime, maxTime, time, delimiter, includeSeconds) => {
|
|
17904
17914
|
// do not throw error if empty string
|
|
17905
17915
|
if (time.trim() === '') {
|
|
17906
17916
|
return true;
|
|
17907
17917
|
}
|
|
17908
|
-
const convertTo24Hour = (time) => {
|
|
17909
|
-
const timeReg = new RegExp(`^\\s*(\\d\\d?)${delimiter}([0-5]\\d)\\s*([AaPp][Mm])?\\s*$`);
|
|
17910
|
-
const regMatches = timeReg.exec(time);
|
|
17911
|
-
if (!regMatches || !regMatches.length) {
|
|
17912
|
-
return;
|
|
17913
|
-
}
|
|
17914
|
-
let hours = regMatches[1].padStart(2, '0');
|
|
17915
|
-
const minutes = regMatches[2];
|
|
17916
|
-
const suffix = regMatches[3] || '';
|
|
17917
|
-
if (suffix.toUpperCase() === 'PM' && hours !== '12') {
|
|
17918
|
-
hours = `${parseInt(hours) + 12}`;
|
|
17919
|
-
}
|
|
17920
|
-
else if (suffix.toUpperCase() === 'AM' && hours === '12') {
|
|
17921
|
-
hours = '00';
|
|
17922
|
-
}
|
|
17923
|
-
return `${hours}${delimiter}${minutes}`;
|
|
17924
|
-
};
|
|
17925
17918
|
// correctly format as 24hr times (12:30AM => 00:30, 1:15 => 01:15)
|
|
17926
|
-
|
|
17927
|
-
|
|
17928
|
-
|
|
17919
|
+
const min24HourTime = convertTo24Hour(minTime, delimiter, includeSeconds);
|
|
17920
|
+
const selected24HourTime = convertTo24Hour(time, delimiter, includeSeconds);
|
|
17921
|
+
const max24HourTime = convertTo24Hour(maxTime, delimiter, includeSeconds);
|
|
17929
17922
|
// simple string comparison for 24hr times
|
|
17930
|
-
return
|
|
17923
|
+
return min24HourTime <= selected24HourTime && selected24HourTime <= max24HourTime;
|
|
17924
|
+
};
|
|
17925
|
+
const convertTo24Hour = (time, delimiter, includeSeconds) => {
|
|
17926
|
+
const timeReg = new RegExp(`^\\s*(\\d\\d?)${delimiter}([0-5]\\d)${delimiter}?([0-5]\\d)?\\s*([AaPp][Mm])?\\s*$`);
|
|
17927
|
+
const regMatches = timeReg.exec(time);
|
|
17928
|
+
if (!regMatches || !regMatches.length) {
|
|
17929
|
+
return;
|
|
17930
|
+
}
|
|
17931
|
+
let hours = regMatches[1].padStart(2, '0');
|
|
17932
|
+
const minutes = regMatches[2];
|
|
17933
|
+
let seconds = regMatches[3] ? `${delimiter}${regMatches[3]}` : '';
|
|
17934
|
+
// When seconds is empty and 'includeSeconds' is enabled, append 0 seconds.
|
|
17935
|
+
if (!seconds && includeSeconds) {
|
|
17936
|
+
seconds = `${delimiter}00`;
|
|
17937
|
+
}
|
|
17938
|
+
const suffix = regMatches[4] || '';
|
|
17939
|
+
if (suffix.toUpperCase() === 'PM' && hours !== '12') {
|
|
17940
|
+
hours = `${parseInt(hours) + 12}`;
|
|
17941
|
+
}
|
|
17942
|
+
else if (suffix.toUpperCase() === 'AM' && hours === '12') {
|
|
17943
|
+
hours = '00';
|
|
17944
|
+
}
|
|
17945
|
+
return `${hours}${delimiter}${minutes}${seconds}`;
|
|
17931
17946
|
};
|
|
17932
17947
|
|
|
17933
17948
|
class TimePicker extends React__namespace.Component {
|
|
@@ -18049,29 +18064,34 @@
|
|
|
18049
18064
|
scrollIndex
|
|
18050
18065
|
});
|
|
18051
18066
|
};
|
|
18052
|
-
this.getRegExp = () =>
|
|
18053
|
-
|
|
18054
|
-
|
|
18067
|
+
this.getRegExp = (includeSeconds = true) => {
|
|
18068
|
+
const { is24Hour, delimiter } = this.props;
|
|
18069
|
+
let baseRegex = `\\s*(\\d\\d?)${delimiter}([0-5]\\d)`;
|
|
18070
|
+
if (includeSeconds) {
|
|
18071
|
+
baseRegex += `${delimiter}?([0-5]\\d)?`;
|
|
18072
|
+
}
|
|
18073
|
+
return new RegExp(`^${baseRegex}${is24Hour ? '' : '\\s*([AaPp][Mm])?'}\\s*$`);
|
|
18074
|
+
};
|
|
18055
18075
|
this.getOptions = () => (this.menuRef && this.menuRef.current ? Array.from(this.menuRef.current.children) : []);
|
|
18056
18076
|
this.isValidFormat = (time) => {
|
|
18057
18077
|
if (this.props.validateTime) {
|
|
18058
18078
|
return this.props.validateTime(time);
|
|
18059
18079
|
}
|
|
18060
|
-
const { delimiter, is24Hour } = this.props;
|
|
18061
|
-
return validateTime(time, this.
|
|
18080
|
+
const { delimiter, is24Hour, includeSeconds } = this.props;
|
|
18081
|
+
return validateTime(time, this.getRegExp(includeSeconds), delimiter, !is24Hour);
|
|
18062
18082
|
};
|
|
18063
18083
|
this.isValidTime = (time) => {
|
|
18064
|
-
const { delimiter } = this.props;
|
|
18084
|
+
const { delimiter, includeSeconds } = this.props;
|
|
18065
18085
|
const { minTimeState, maxTimeState } = this.state;
|
|
18066
|
-
return isWithinMinMax(minTimeState, maxTimeState, time, delimiter);
|
|
18086
|
+
return isWithinMinMax(minTimeState, maxTimeState, time, delimiter, includeSeconds);
|
|
18067
18087
|
};
|
|
18068
18088
|
this.isValid = (time) => this.isValidFormat(time) && this.isValidTime(time);
|
|
18069
18089
|
this.onToggle = (isOpen) => {
|
|
18070
18090
|
// on close, parse and validate input
|
|
18071
18091
|
this.setState(prevState => {
|
|
18072
18092
|
const { timeRegex, isInvalid } = prevState;
|
|
18073
|
-
const { delimiter, is24Hour } = this.props;
|
|
18074
|
-
const time = parseTime(prevState.timeState, timeRegex, delimiter, !is24Hour);
|
|
18093
|
+
const { delimiter, is24Hour, includeSeconds } = this.props;
|
|
18094
|
+
const time = parseTime(prevState.timeState, timeRegex, delimiter, !is24Hour, includeSeconds);
|
|
18075
18095
|
return {
|
|
18076
18096
|
isOpen,
|
|
18077
18097
|
timeState: time,
|
|
@@ -18081,8 +18101,8 @@
|
|
|
18081
18101
|
};
|
|
18082
18102
|
this.onSelect = (selection) => {
|
|
18083
18103
|
const { timeRegex, timeState } = this.state;
|
|
18084
|
-
const { delimiter, is24Hour } = this.props;
|
|
18085
|
-
const time = parseTime(selection, timeRegex, delimiter, !is24Hour);
|
|
18104
|
+
const { delimiter, is24Hour, includeSeconds } = this.props;
|
|
18105
|
+
const time = parseTime(selection, timeRegex, delimiter, !is24Hour, includeSeconds);
|
|
18086
18106
|
if (time !== timeState) {
|
|
18087
18107
|
this.onInputChange(time);
|
|
18088
18108
|
}
|
|
@@ -18097,8 +18117,10 @@
|
|
|
18097
18117
|
e.stopPropagation();
|
|
18098
18118
|
};
|
|
18099
18119
|
this.onInputChange = (newTime) => {
|
|
18100
|
-
|
|
18101
|
-
|
|
18120
|
+
const { onChange } = this.props;
|
|
18121
|
+
const { timeRegex } = this.state;
|
|
18122
|
+
if (onChange) {
|
|
18123
|
+
onChange(newTime, getHours(newTime, timeRegex), getMinutes(newTime, timeRegex), getSeconds(newTime, timeRegex), this.isValid(newTime));
|
|
18102
18124
|
}
|
|
18103
18125
|
this.scrollToSelection(newTime);
|
|
18104
18126
|
this.setState({
|
|
@@ -18108,30 +18130,32 @@
|
|
|
18108
18130
|
};
|
|
18109
18131
|
this.onBlur = (event) => {
|
|
18110
18132
|
const { timeRegex } = this.state;
|
|
18111
|
-
const { delimiter, is24Hour } = this.props;
|
|
18112
|
-
const time = parseTime(event.currentTarget.value, timeRegex, delimiter, !is24Hour);
|
|
18133
|
+
const { delimiter, is24Hour, includeSeconds } = this.props;
|
|
18134
|
+
const time = parseTime(event.currentTarget.value, timeRegex, delimiter, !is24Hour, includeSeconds);
|
|
18113
18135
|
this.setState({
|
|
18114
18136
|
isInvalid: !this.isValid(time)
|
|
18115
18137
|
});
|
|
18116
18138
|
};
|
|
18117
|
-
const { is24Hour, delimiter, time } = this.props;
|
|
18139
|
+
const { is24Hour, delimiter, time, includeSeconds } = this.props;
|
|
18118
18140
|
let { minTime, maxTime } = this.props;
|
|
18119
18141
|
if (minTime === '') {
|
|
18120
|
-
|
|
18142
|
+
const minSeconds = includeSeconds ? `${delimiter}00` : '';
|
|
18143
|
+
minTime = is24Hour ? `00${delimiter}00${minSeconds}` : `12${delimiter}00${minSeconds} AM`;
|
|
18121
18144
|
}
|
|
18122
18145
|
if (maxTime === '') {
|
|
18123
|
-
|
|
18146
|
+
const maxSeconds = includeSeconds ? `${delimiter}59` : '';
|
|
18147
|
+
maxTime = is24Hour ? `23${delimiter}59${maxSeconds}` : `11${delimiter}59${maxSeconds} PM`;
|
|
18124
18148
|
}
|
|
18125
18149
|
const timeRegex = this.getRegExp();
|
|
18126
18150
|
this.state = {
|
|
18127
18151
|
isInvalid: false,
|
|
18128
18152
|
isOpen: false,
|
|
18129
|
-
timeState: parseTime(time, timeRegex, delimiter, !is24Hour),
|
|
18153
|
+
timeState: parseTime(time, timeRegex, delimiter, !is24Hour, includeSeconds),
|
|
18130
18154
|
focusedIndex: null,
|
|
18131
18155
|
scrollIndex: 0,
|
|
18132
18156
|
timeRegex,
|
|
18133
|
-
minTimeState: parseTime(minTime, timeRegex, delimiter, !is24Hour),
|
|
18134
|
-
maxTimeState: parseTime(maxTime, timeRegex, delimiter, !is24Hour)
|
|
18157
|
+
minTimeState: parseTime(minTime, timeRegex, delimiter, !is24Hour, includeSeconds),
|
|
18158
|
+
maxTimeState: parseTime(maxTime, timeRegex, delimiter, !is24Hour, includeSeconds)
|
|
18135
18159
|
};
|
|
18136
18160
|
}
|
|
18137
18161
|
componentDidMount() {
|
|
@@ -18146,7 +18170,7 @@
|
|
|
18146
18170
|
}
|
|
18147
18171
|
componentDidUpdate(prevProps, prevState) {
|
|
18148
18172
|
const { timeState, isOpen, isInvalid, timeRegex } = this.state;
|
|
18149
|
-
const { time, is24Hour, delimiter } = this.props;
|
|
18173
|
+
const { time, is24Hour, delimiter, includeSeconds } = this.props;
|
|
18150
18174
|
if (isOpen && !prevState.isOpen && timeState && !isInvalid) {
|
|
18151
18175
|
this.scrollToSelection(timeState);
|
|
18152
18176
|
}
|
|
@@ -18157,14 +18181,16 @@
|
|
|
18157
18181
|
}
|
|
18158
18182
|
if (time !== '' && time !== prevProps.time) {
|
|
18159
18183
|
this.setState({
|
|
18160
|
-
timeState: parseTime(time, timeRegex, delimiter, !is24Hour)
|
|
18184
|
+
timeState: parseTime(time, timeRegex, delimiter, !is24Hour, includeSeconds)
|
|
18161
18185
|
});
|
|
18162
18186
|
}
|
|
18163
18187
|
}
|
|
18164
18188
|
render() {
|
|
18165
|
-
const _a = this.props, { 'aria-label': ariaLabel, isDisabled, className, placeholder, id, menuAppendTo, is24Hour, invalidFormatErrorMessage, invalidMinMaxErrorMessage, direction, stepMinutes, width, delimiter,
|
|
18189
|
+
const _a = this.props, { 'aria-label': ariaLabel, isDisabled, className, placeholder, id, menuAppendTo, is24Hour, invalidFormatErrorMessage, invalidMinMaxErrorMessage, direction, stepMinutes, width, delimiter, inputProps,
|
|
18166
18190
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
18167
|
-
onChange, time, validateTime,
|
|
18191
|
+
onChange, time, validateTime, minTime, maxTime, includeSeconds } = _a,
|
|
18192
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
18193
|
+
props = __rest$1(_a, ['aria-label', "isDisabled", "className", "placeholder", "id", "menuAppendTo", "is24Hour", "invalidFormatErrorMessage", "invalidMinMaxErrorMessage", "direction", "stepMinutes", "width", "delimiter", "inputProps", "onChange", "time", "validateTime", "minTime", "maxTime", "includeSeconds"]);
|
|
18168
18194
|
const { timeState, isOpen, isInvalid, focusedIndex, minTimeState, maxTimeState } = this.state;
|
|
18169
18195
|
const style = { '--pf-c-date-picker__input--c-form-control--Width': width };
|
|
18170
18196
|
const options = makeTimeOptions(stepMinutes, !is24Hour, delimiter, minTimeState, maxTimeState);
|