@patternfly/react-core 4.181.3 → 4.182.1
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 +41 -0
- package/dist/esm/components/ClipboardCopy/ClipboardCopy.d.ts +1 -0
- package/dist/esm/components/ClipboardCopy/ClipboardCopy.d.ts.map +1 -1
- package/dist/esm/components/ClipboardCopy/ClipboardCopy.js +5 -0
- package/dist/esm/components/ClipboardCopy/ClipboardCopy.js.map +1 -1
- package/dist/esm/components/OverflowMenu/OverflowMenuControl.d.ts.map +1 -1
- package/dist/esm/components/OverflowMenu/OverflowMenuControl.js +8 -4
- package/dist/esm/components/OverflowMenu/OverflowMenuControl.js.map +1 -1
- package/dist/esm/components/OverflowMenu/OverflowMenuGroup.d.ts.map +1 -1
- package/dist/esm/components/OverflowMenu/OverflowMenuGroup.js +5 -1
- package/dist/esm/components/OverflowMenu/OverflowMenuGroup.js.map +1 -1
- package/dist/esm/components/TimePicker/TimePicker.d.ts +13 -0
- package/dist/esm/components/TimePicker/TimePicker.d.ts.map +1 -1
- package/dist/esm/components/TimePicker/TimePicker.js +28 -9
- package/dist/esm/components/TimePicker/TimePicker.js.map +1 -1
- package/dist/esm/components/TimePicker/TimePickerUtils.d.ts +2 -1
- package/dist/esm/components/TimePicker/TimePickerUtils.d.ts.map +1 -1
- package/dist/esm/components/TimePicker/TimePickerUtils.js +45 -19
- package/dist/esm/components/TimePicker/TimePickerUtils.js.map +1 -1
- package/dist/esm/components/Toolbar/Toolbar.d.ts +2 -0
- package/dist/esm/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/esm/components/Toolbar/Toolbar.js +2 -2
- package/dist/esm/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/esm/components/Toolbar/ToolbarChipGroupContent.d.ts +2 -0
- package/dist/esm/components/Toolbar/ToolbarChipGroupContent.d.ts.map +1 -1
- package/dist/esm/components/Toolbar/ToolbarChipGroupContent.js +4 -5
- package/dist/esm/components/Toolbar/ToolbarChipGroupContent.js.map +1 -1
- package/dist/js/components/ClipboardCopy/ClipboardCopy.d.ts +1 -0
- package/dist/js/components/ClipboardCopy/ClipboardCopy.d.ts.map +1 -1
- package/dist/js/components/ClipboardCopy/ClipboardCopy.js +5 -0
- package/dist/js/components/ClipboardCopy/ClipboardCopy.js.map +1 -1
- package/dist/js/components/OverflowMenu/OverflowMenuControl.d.ts.map +1 -1
- package/dist/js/components/OverflowMenu/OverflowMenuControl.js +7 -4
- package/dist/js/components/OverflowMenu/OverflowMenuControl.js.map +1 -1
- package/dist/js/components/OverflowMenu/OverflowMenuGroup.d.ts.map +1 -1
- package/dist/js/components/OverflowMenu/OverflowMenuGroup.js +4 -1
- package/dist/js/components/OverflowMenu/OverflowMenuGroup.js.map +1 -1
- package/dist/js/components/TimePicker/TimePicker.d.ts +13 -0
- package/dist/js/components/TimePicker/TimePicker.d.ts.map +1 -1
- package/dist/js/components/TimePicker/TimePicker.js +27 -8
- package/dist/js/components/TimePicker/TimePicker.js.map +1 -1
- package/dist/js/components/TimePicker/TimePickerUtils.d.ts +2 -1
- package/dist/js/components/TimePicker/TimePickerUtils.d.ts.map +1 -1
- package/dist/js/components/TimePicker/TimePickerUtils.js +47 -20
- package/dist/js/components/TimePicker/TimePickerUtils.js.map +1 -1
- package/dist/js/components/Toolbar/Toolbar.d.ts +2 -0
- package/dist/js/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/js/components/Toolbar/Toolbar.js +2 -2
- package/dist/js/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/js/components/Toolbar/ToolbarChipGroupContent.d.ts +2 -0
- package/dist/js/components/Toolbar/ToolbarChipGroupContent.d.ts.map +1 -1
- package/dist/js/components/Toolbar/ToolbarChipGroupContent.js +4 -5
- package/dist/js/components/Toolbar/ToolbarChipGroupContent.js.map +1 -1
- package/dist/umd/react-core.css +104 -104
- package/dist/umd/react-core.js +94 -39
- package/dist/umd/react-core.min.js +4 -4
- package/package.json +5 -5
- package/src/components/ClipboardCopy/ClipboardCopy.tsx +6 -0
- package/src/components/OverflowMenu/OverflowMenuControl.tsx +6 -2
- package/src/components/OverflowMenu/OverflowMenuGroup.tsx +3 -1
- package/src/components/TimePicker/TimePicker.tsx +48 -9
- package/src/components/TimePicker/TimePickerUtils.tsx +54 -24
- package/src/components/TimePicker/examples/TimePicker.md +11 -0
- package/src/components/Toolbar/Toolbar.tsx +4 -0
- package/src/components/Toolbar/ToolbarChipGroupContent.tsx +6 -2
- package/src/components/Toolbar/__tests__/Generated/__snapshots__/Toolbar.test.tsx.snap +1 -0
- package/src/components/Toolbar/__tests__/__snapshots__/ToolbarToggleGroup.test.tsx.snap +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.182.1",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.
|
|
38
|
-
"@patternfly/react-styles": "^4.
|
|
39
|
-
"@patternfly/react-tokens": "^4.
|
|
37
|
+
"@patternfly/react-icons": "^4.33.1",
|
|
38
|
+
"@patternfly/react-styles": "^4.32.1",
|
|
39
|
+
"@patternfly/react-tokens": "^4.34.1",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
41
|
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "7ef55a0e7fc984b853657c3b86e14e4e0f6ffe1c"
|
|
64
64
|
}
|
|
@@ -111,6 +111,12 @@ export class ClipboardCopy extends React.Component<ClipboardCopyProps, Clipboard
|
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
+
componentWillUnmount = () => {
|
|
115
|
+
if (this.timer) {
|
|
116
|
+
window.clearTimeout(this.timer);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
114
120
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
115
121
|
expandContent = (_event: React.MouseEvent<Element, MouseEvent>) => {
|
|
116
122
|
this.setState(prevState => ({
|
|
@@ -15,12 +15,16 @@ export interface OverflowMenuControlProps extends React.HTMLProps<HTMLDivElement
|
|
|
15
15
|
export const OverflowMenuControl: React.SFC<OverflowMenuControlProps> = ({
|
|
16
16
|
className,
|
|
17
17
|
children,
|
|
18
|
-
hasAdditionalOptions
|
|
18
|
+
hasAdditionalOptions,
|
|
19
|
+
...props
|
|
19
20
|
}: OverflowMenuControlProps) => (
|
|
20
21
|
<OverflowMenuContext.Consumer>
|
|
21
22
|
{value =>
|
|
22
23
|
(value.isBelowBreakpoint || hasAdditionalOptions) && (
|
|
23
|
-
<div className={css(styles.overflowMenuControl, className)}
|
|
24
|
+
<div className={css(styles.overflowMenuControl, className)} {...props}>
|
|
25
|
+
{' '}
|
|
26
|
+
{children}{' '}
|
|
27
|
+
</div>
|
|
24
28
|
)
|
|
25
29
|
}
|
|
26
30
|
</OverflowMenuContext.Consumer>
|
|
@@ -18,7 +18,8 @@ export const OverflowMenuGroup: React.FC<OverflowMenuGroupProps> = ({
|
|
|
18
18
|
className,
|
|
19
19
|
children,
|
|
20
20
|
isPersistent = false,
|
|
21
|
-
groupType
|
|
21
|
+
groupType,
|
|
22
|
+
...props
|
|
22
23
|
}: OverflowMenuGroupProps) => (
|
|
23
24
|
<OverflowMenuContext.Consumer>
|
|
24
25
|
{value =>
|
|
@@ -30,6 +31,7 @@ export const OverflowMenuGroup: React.FC<OverflowMenuGroupProps> = ({
|
|
|
30
31
|
groupType === 'icon' && styles.modifiers.iconButtonGroup,
|
|
31
32
|
className
|
|
32
33
|
)}
|
|
34
|
+
{...props}
|
|
33
35
|
>
|
|
34
36
|
{children}
|
|
35
37
|
</div>
|
|
@@ -9,7 +9,16 @@ import { TimeOption } from './TimeOption';
|
|
|
9
9
|
import { KeyTypes, SelectDirection } from '../Select';
|
|
10
10
|
import { InputGroup } from '../InputGroup';
|
|
11
11
|
import { TextInput, TextInputProps } from '../TextInput';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
parseTime,
|
|
14
|
+
validateTime,
|
|
15
|
+
makeTimeOptions,
|
|
16
|
+
amSuffix,
|
|
17
|
+
pmSuffix,
|
|
18
|
+
getHours,
|
|
19
|
+
getMinutes,
|
|
20
|
+
isWithinMinMax
|
|
21
|
+
} from './TimePickerUtils';
|
|
13
22
|
|
|
14
23
|
export interface TimePickerProps
|
|
15
24
|
extends Omit<React.HTMLProps<HTMLDivElement>, 'onChange' | 'onFocus' | 'onBlur' | 'disabled' | 'ref'> {
|
|
@@ -27,6 +36,8 @@ export interface TimePickerProps
|
|
|
27
36
|
time?: string | Date;
|
|
28
37
|
/** Error message to display when the time is provided in an invalid format. */
|
|
29
38
|
invalidFormatErrorMessage?: string;
|
|
39
|
+
/** Error message to display when the time provided is not within the minTime/maxTime constriants */
|
|
40
|
+
invalidMinMaxErrorMessage?: string;
|
|
30
41
|
/** True if the time is 24 hour time. False if the time is 12 hour time */
|
|
31
42
|
is24Hour?: boolean;
|
|
32
43
|
/** Optional event handler called each time the value in the time picker input changes. */
|
|
@@ -50,6 +61,10 @@ export interface TimePickerProps
|
|
|
50
61
|
stepMinutes?: number;
|
|
51
62
|
/** Additional props for input field */
|
|
52
63
|
inputProps?: TextInputProps;
|
|
64
|
+
/** A time string indicating the minimum value allowed. The format could be an ISO 8601 formatted date string or in 'HH{delimiter}MM' format */
|
|
65
|
+
minTime?: string | Date;
|
|
66
|
+
/** A time string indicating the maximum value allowed. The format could be an ISO 8601 formatted date string or in 'HH{delimiter}MM' format */
|
|
67
|
+
maxTime?: string | Date;
|
|
53
68
|
}
|
|
54
69
|
|
|
55
70
|
interface TimePickerState {
|
|
@@ -59,6 +74,8 @@ interface TimePickerState {
|
|
|
59
74
|
focusedIndex: number;
|
|
60
75
|
scrollIndex: number;
|
|
61
76
|
timeRegex: RegExp;
|
|
77
|
+
minTimeState: string;
|
|
78
|
+
maxTimeState: string;
|
|
62
79
|
}
|
|
63
80
|
|
|
64
81
|
export class TimePicker extends React.Component<TimePickerProps, TimePickerState> {
|
|
@@ -74,6 +91,7 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
|
|
|
74
91
|
time: '',
|
|
75
92
|
is24Hour: false,
|
|
76
93
|
invalidFormatErrorMessage: 'Invalid time format',
|
|
94
|
+
invalidMinMaxErrorMessage: 'Invalid time entered',
|
|
77
95
|
placeholder: 'hh:mm',
|
|
78
96
|
delimiter: ':',
|
|
79
97
|
'aria-label': 'Time picker',
|
|
@@ -81,22 +99,31 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
|
|
|
81
99
|
direction: 'down',
|
|
82
100
|
width: 150,
|
|
83
101
|
stepMinutes: 30,
|
|
84
|
-
inputProps: {}
|
|
102
|
+
inputProps: {},
|
|
103
|
+
minTime: '',
|
|
104
|
+
maxTime: ''
|
|
85
105
|
};
|
|
86
106
|
|
|
87
107
|
constructor(props: TimePickerProps) {
|
|
88
108
|
super(props);
|
|
89
|
-
|
|
90
109
|
const { is24Hour, delimiter, time } = this.props;
|
|
110
|
+
let { minTime, maxTime } = this.props;
|
|
111
|
+
if (minTime === '') {
|
|
112
|
+
minTime = is24Hour ? `00${delimiter}00` : `12${delimiter}00AM`;
|
|
113
|
+
}
|
|
114
|
+
if (maxTime === '') {
|
|
115
|
+
maxTime = is24Hour ? `23${delimiter}59` : `11${delimiter}59PM`;
|
|
116
|
+
}
|
|
91
117
|
const timeRegex = this.getRegExp();
|
|
92
|
-
|
|
93
118
|
this.state = {
|
|
94
119
|
isInvalid: false,
|
|
95
120
|
isOpen: false,
|
|
96
121
|
timeState: parseTime(time, timeRegex, delimiter, !is24Hour),
|
|
97
122
|
focusedIndex: null,
|
|
98
123
|
scrollIndex: 0,
|
|
99
|
-
timeRegex
|
|
124
|
+
timeRegex,
|
|
125
|
+
minTimeState: parseTime(minTime, timeRegex, delimiter, !is24Hour),
|
|
126
|
+
maxTimeState: parseTime(maxTime, timeRegex, delimiter, !is24Hour)
|
|
100
127
|
};
|
|
101
128
|
}
|
|
102
129
|
|
|
@@ -253,7 +280,7 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
|
|
|
253
280
|
getOptions = () =>
|
|
254
281
|
(this.menuRef && this.menuRef.current ? Array.from(this.menuRef.current.children) : []) as HTMLElement[];
|
|
255
282
|
|
|
256
|
-
|
|
283
|
+
isValidFormat = (time: string) => {
|
|
257
284
|
if (this.props.validateTime) {
|
|
258
285
|
return this.props.validateTime(time);
|
|
259
286
|
}
|
|
@@ -261,6 +288,14 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
|
|
|
261
288
|
return validateTime(time, this.state.timeRegex, delimiter, !is24Hour);
|
|
262
289
|
};
|
|
263
290
|
|
|
291
|
+
isValidTime = (time: string) => {
|
|
292
|
+
const { delimiter } = this.props;
|
|
293
|
+
const { minTimeState, maxTimeState } = this.state;
|
|
294
|
+
return isWithinMinMax(minTimeState, maxTimeState, time, delimiter);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
isValid = (time: string) => this.isValidFormat(time) && this.isValidTime(time);
|
|
298
|
+
|
|
264
299
|
onToggle = (isOpen: boolean) => {
|
|
265
300
|
// on close, parse and validate input
|
|
266
301
|
this.setState(prevState => {
|
|
@@ -329,6 +364,7 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
|
|
|
329
364
|
menuAppendTo,
|
|
330
365
|
is24Hour,
|
|
331
366
|
invalidFormatErrorMessage,
|
|
367
|
+
invalidMinMaxErrorMessage,
|
|
332
368
|
direction,
|
|
333
369
|
stepMinutes,
|
|
334
370
|
width,
|
|
@@ -338,11 +374,14 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
|
|
|
338
374
|
time,
|
|
339
375
|
validateTime,
|
|
340
376
|
inputProps,
|
|
377
|
+
minTime,
|
|
378
|
+
maxTime,
|
|
341
379
|
...props
|
|
342
380
|
} = this.props;
|
|
343
|
-
const { timeState, isOpen, isInvalid, focusedIndex } = this.state;
|
|
381
|
+
const { timeState, isOpen, isInvalid, focusedIndex, minTimeState, maxTimeState } = this.state;
|
|
344
382
|
const style = { '--pf-c-date-picker__input--c-form-control--Width': width } as React.CSSProperties;
|
|
345
|
-
const options = makeTimeOptions(stepMinutes, !is24Hour, delimiter);
|
|
383
|
+
const options = makeTimeOptions(stepMinutes, !is24Hour, delimiter, minTimeState, maxTimeState);
|
|
384
|
+
const isValidFormat = this.isValidFormat(timeState);
|
|
346
385
|
const randomId = id || getUniqueId('time-picker');
|
|
347
386
|
|
|
348
387
|
const menuContainer = (
|
|
@@ -408,7 +447,7 @@ export class TimePicker extends React.Component<TimePickerProps, TimePickerState
|
|
|
408
447
|
</InputGroup>
|
|
409
448
|
{isInvalid && (
|
|
410
449
|
<div className={css(datePickerStyles.datePickerHelperText, datePickerStyles.modifiers.error)}>
|
|
411
|
-
{invalidFormatErrorMessage}
|
|
450
|
+
{!isValidFormat ? invalidFormatErrorMessage : invalidMinMaxErrorMessage}
|
|
412
451
|
</div>
|
|
413
452
|
)}
|
|
414
453
|
</div>
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
export const amSuffix = ' AM';
|
|
2
2
|
export const pmSuffix = ' PM';
|
|
3
3
|
|
|
4
|
-
export const makeTimeOptions = (
|
|
4
|
+
export const makeTimeOptions = (
|
|
5
|
+
stepMinutes: number,
|
|
6
|
+
hour12: boolean,
|
|
7
|
+
delimiter: string,
|
|
8
|
+
minTime: string,
|
|
9
|
+
maxTime: string
|
|
10
|
+
) => {
|
|
5
11
|
const res = [];
|
|
6
12
|
const iter = new Date(new Date().setHours(0, 0, 0, 0));
|
|
7
13
|
const iterDay = iter.getDay();
|
|
8
14
|
while (iter.getDay() === iterDay) {
|
|
9
|
-
let hour = iter.getHours();
|
|
15
|
+
let hour: string | number = iter.getHours();
|
|
10
16
|
let suffix = amSuffix;
|
|
11
17
|
if (hour12) {
|
|
12
18
|
if (hour === 0) {
|
|
@@ -18,19 +24,18 @@ export const makeTimeOptions = (stepMinutes: number, hour12: boolean, delimiter:
|
|
|
18
24
|
hour %= 12;
|
|
19
25
|
}
|
|
20
26
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
hour = hour12 ? hour.toString() : hour.toString().padStart(2, '0');
|
|
28
|
+
const minutes = iter
|
|
29
|
+
.getMinutes()
|
|
30
|
+
.toString()
|
|
31
|
+
.padStart(2, '0');
|
|
32
|
+
const timeOption = hour + delimiter + minutes + (hour12 ? suffix : '');
|
|
33
|
+
// time option is valid if within min/max constraints
|
|
34
|
+
if (isWithinMinMax(minTime, maxTime, timeOption, delimiter)) {
|
|
35
|
+
res.push(timeOption);
|
|
36
|
+
}
|
|
31
37
|
iter.setMinutes(iter.getMinutes() + stepMinutes);
|
|
32
38
|
}
|
|
33
|
-
|
|
34
39
|
return res;
|
|
35
40
|
};
|
|
36
41
|
|
|
@@ -53,26 +58,20 @@ export const parseTime = (time: string | Date, timeRegex: RegExp, delimiter: str
|
|
|
53
58
|
} else if (typeof time === 'string') {
|
|
54
59
|
time = time.trim();
|
|
55
60
|
if (is12Hour && time !== '' && validateTime(time, timeRegex, delimiter, is12Hour)) {
|
|
61
|
+
const [, hours, minutes, suffix = ''] = timeRegex.exec(time);
|
|
62
|
+
const uppercaseSuffix = suffix.toUpperCase();
|
|
56
63
|
// Format AM/PM according to design
|
|
57
64
|
let ampm = '';
|
|
58
|
-
if (
|
|
59
|
-
time = time
|
|
60
|
-
.toUpperCase()
|
|
61
|
-
.replace(amSuffix.toUpperCase().trim(), '')
|
|
62
|
-
.trim();
|
|
65
|
+
if (uppercaseSuffix === amSuffix.toUpperCase().trim()) {
|
|
63
66
|
ampm = amSuffix;
|
|
64
|
-
} else if (
|
|
65
|
-
time = time
|
|
66
|
-
.toUpperCase()
|
|
67
|
-
.replace(pmSuffix.toUpperCase().trim(), '')
|
|
68
|
-
.trim();
|
|
67
|
+
} else if (uppercaseSuffix === pmSuffix.toUpperCase().trim()) {
|
|
69
68
|
ampm = pmSuffix;
|
|
70
69
|
} else {
|
|
71
70
|
// if this 12 hour time is missing am/pm but otherwise valid,
|
|
72
71
|
// append am/pm depending on time of day
|
|
73
72
|
ampm = new Date().getHours() > 11 ? pmSuffix : amSuffix;
|
|
74
73
|
}
|
|
75
|
-
return `${
|
|
74
|
+
return `${hours}${delimiter}${minutes}${ampm}`;
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
return time.toString();
|
|
@@ -111,3 +110,34 @@ export const getMinutes = (time: string, timeRegex: RegExp) => {
|
|
|
111
110
|
const parts = time.match(timeRegex);
|
|
112
111
|
return parts && parts.length ? parseInt(parts[2]) : null;
|
|
113
112
|
};
|
|
113
|
+
|
|
114
|
+
export const isWithinMinMax = (minTime: string, maxTime: string, time: string, delimiter: string) => {
|
|
115
|
+
// do not throw error if empty string
|
|
116
|
+
if (time.trim() === '') {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
const convertTo24Hour = (time: string): string => {
|
|
120
|
+
const timeReg = new RegExp(`^\\s*(\\d\\d?)${delimiter}([0-5]\\d)\\s*([AaPp][Mm])?\\s*$`);
|
|
121
|
+
const regMatches = timeReg.exec(time);
|
|
122
|
+
if (!regMatches || !regMatches.length) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
let hours = regMatches[1].padStart(2, '0');
|
|
126
|
+
const minutes = regMatches[2];
|
|
127
|
+
const suffix = regMatches[3] || '';
|
|
128
|
+
if (suffix.toUpperCase() === 'PM' && hours !== '12') {
|
|
129
|
+
hours = `${parseInt(hours) + 12}`;
|
|
130
|
+
} else if (suffix.toUpperCase() === 'AM' && hours === '12') {
|
|
131
|
+
hours = '00';
|
|
132
|
+
}
|
|
133
|
+
return `${hours}${delimiter}${minutes}`;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// correctly format as 24hr times (12:30AM => 00:30, 1:15 => 01:15)
|
|
137
|
+
minTime = convertTo24Hour(minTime);
|
|
138
|
+
time = convertTo24Hour(time);
|
|
139
|
+
maxTime = convertTo24Hour(maxTime);
|
|
140
|
+
|
|
141
|
+
// simple string comparison for 24hr times
|
|
142
|
+
return minTime <= time && time <= maxTime;
|
|
143
|
+
};
|
|
@@ -41,3 +41,14 @@ import { TimePicker } from '@patternfly/react-core';
|
|
|
41
41
|
|
|
42
42
|
<TimePicker is24Hour delimiter="h" placeholder=""/>
|
|
43
43
|
```
|
|
44
|
+
|
|
45
|
+
### Minimum/maximum times
|
|
46
|
+
|
|
47
|
+
The `minTime`/`maxTime` props restrict the options shown for the user to select from as well as trigger the `invalidMinMaxErrorMessage` if the user enters a time outside this range.
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import React from 'react';
|
|
51
|
+
import { TimePicker } from '@patternfly/react-core';
|
|
52
|
+
|
|
53
|
+
<TimePicker is24Hour minTime="9:30" maxTime="17:15" placeholder="14:00"/>
|
|
54
|
+
```
|
|
@@ -41,6 +41,8 @@ export interface ToolbarProps extends React.HTMLProps<HTMLDivElement>, OUIAProps
|
|
|
41
41
|
xl?: 'insetNone' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl';
|
|
42
42
|
'2xl'?: 'insetNone' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl';
|
|
43
43
|
};
|
|
44
|
+
/** Text to display in the total number of applied filters ToolbarFilter */
|
|
45
|
+
numberOfFiltersText?: (numberOfFilters: number) => string;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export interface ToolbarState {
|
|
@@ -125,6 +127,7 @@ export class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
|
|
|
125
127
|
usePageInsets,
|
|
126
128
|
isSticky,
|
|
127
129
|
ouiaId,
|
|
130
|
+
numberOfFiltersText,
|
|
128
131
|
...props
|
|
129
132
|
} = this.props;
|
|
130
133
|
|
|
@@ -171,6 +174,7 @@ export class Toolbar extends React.Component<ToolbarProps, ToolbarState> {
|
|
|
171
174
|
showClearFiltersButton={showClearFiltersButton}
|
|
172
175
|
clearFiltersButtonText={clearFiltersButtonText}
|
|
173
176
|
numberOfFilters={numberOfFilters}
|
|
177
|
+
numberOfFiltersText={numberOfFiltersText}
|
|
174
178
|
collapseListedFiltersBreakpoint={collapseListedFiltersBreakpoint}
|
|
175
179
|
/>
|
|
176
180
|
</ToolbarContext.Provider>
|
|
@@ -25,6 +25,8 @@ export interface ToolbarChipGroupContentProps extends React.HTMLProps<HTMLDivEle
|
|
|
25
25
|
clearFiltersButtonText?: string;
|
|
26
26
|
/** Total number of filters currently being applied across all ToolbarFilter components */
|
|
27
27
|
numberOfFilters: number;
|
|
28
|
+
/** Text to display in the total number of applied filters ToolbarFilter */
|
|
29
|
+
numberOfFiltersText?: (numberOfFilters: number) => string;
|
|
28
30
|
/** The breakpoint at which the listed filters in chip groups are collapsed down to a summary */
|
|
29
31
|
collapseListedFiltersBreakpoint?: 'all' | 'md' | 'lg' | 'xl' | '2xl';
|
|
30
32
|
}
|
|
@@ -33,7 +35,8 @@ export class ToolbarChipGroupContent extends React.Component<ToolbarChipGroupCon
|
|
|
33
35
|
static displayName = 'ToolbarChipGroupContent';
|
|
34
36
|
static defaultProps: PickOptional<ToolbarChipGroupContentProps> = {
|
|
35
37
|
clearFiltersButtonText: 'Clear all filters',
|
|
36
|
-
collapseListedFiltersBreakpoint: 'lg'
|
|
38
|
+
collapseListedFiltersBreakpoint: 'lg',
|
|
39
|
+
numberOfFiltersText: (numberOfFilters: number) => `${numberOfFilters} filters applied`
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
render() {
|
|
@@ -46,6 +49,7 @@ export class ToolbarChipGroupContent extends React.Component<ToolbarChipGroupCon
|
|
|
46
49
|
clearFiltersButtonText,
|
|
47
50
|
collapseListedFiltersBreakpoint,
|
|
48
51
|
numberOfFilters,
|
|
52
|
+
numberOfFiltersText,
|
|
49
53
|
...props
|
|
50
54
|
} = this.props;
|
|
51
55
|
|
|
@@ -79,7 +83,7 @@ export class ToolbarChipGroupContent extends React.Component<ToolbarChipGroupCon
|
|
|
79
83
|
/>
|
|
80
84
|
{collapseListedFilters && numberOfFilters > 0 && !isExpanded && (
|
|
81
85
|
<ToolbarGroup>
|
|
82
|
-
<ToolbarItem>{numberOfFilters}
|
|
86
|
+
<ToolbarItem>{numberOfFiltersText(numberOfFilters)}</ToolbarItem>
|
|
83
87
|
</ToolbarGroup>
|
|
84
88
|
)}
|
|
85
89
|
{showClearFiltersButton && !isExpanded && (
|
|
@@ -119,6 +119,7 @@ exports[`Toolbar should render inset 1`] = `
|
|
|
119
119
|
collapseListedFiltersBreakpoint="lg"
|
|
120
120
|
isExpanded={false}
|
|
121
121
|
numberOfFilters={0}
|
|
122
|
+
numberOfFiltersText={[Function]}
|
|
122
123
|
showClearFiltersButton={false}
|
|
123
124
|
>
|
|
124
125
|
<div
|
|
@@ -255,6 +256,7 @@ exports[`Toolbar should render with page inset flag 1`] = `
|
|
|
255
256
|
collapseListedFiltersBreakpoint="lg"
|
|
256
257
|
isExpanded={false}
|
|
257
258
|
numberOfFilters={0}
|
|
259
|
+
numberOfFiltersText={[Function]}
|
|
258
260
|
showClearFiltersButton={false}
|
|
259
261
|
>
|
|
260
262
|
<div
|