@patternfly/react-core 4.189.4 → 4.191.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/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/esm/components/NumberInput/NumberInput.js +13 -1
- package/dist/esm/components/NumberInput/NumberInput.js.map +1 -1
- package/dist/esm/components/Tabs/Tabs.d.ts +2 -0
- package/dist/esm/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/esm/components/Tabs/Tabs.js +24 -18
- package/dist/esm/components/Tabs/Tabs.js.map +1 -1
- 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/esm/helpers/util.d.ts +2 -1
- package/dist/esm/helpers/util.d.ts.map +1 -1
- package/dist/esm/helpers/util.js +5 -4
- package/dist/esm/helpers/util.js.map +1 -1
- package/dist/js/components/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/js/components/NumberInput/NumberInput.js +13 -1
- package/dist/js/components/NumberInput/NumberInput.js.map +1 -1
- package/dist/js/components/Tabs/Tabs.d.ts +2 -0
- package/dist/js/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/js/components/Tabs/Tabs.js +24 -18
- package/dist/js/components/Tabs/Tabs.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/js/helpers/util.d.ts +2 -1
- package/dist/js/helpers/util.d.ts.map +1 -1
- package/dist/js/helpers/util.js +5 -4
- package/dist/js/helpers/util.js.map +1 -1
- package/dist/umd/react-core.css +69 -69
- package/dist/umd/react-core.js +134 -90
- package/dist/umd/react-core.min.css +34 -34
- package/dist/umd/react-core.min.js +2 -2
- package/package.json +5 -5
- package/src/components/NumberInput/NumberInput.tsx +17 -0
- package/src/components/NumberInput/__tests__/__snapshots__/NumberInput.test.tsx.snap +10 -0
- package/src/components/NumberInput/examples/NumberInput.md +43 -0
- package/src/components/Tabs/Tabs.tsx +25 -18
- 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/src/demos/Button.md +67 -0
- package/src/helpers/util.ts +10 -4
|
@@ -4,42 +4,42 @@ import { act } from 'react-dom/test-utils';
|
|
|
4
4
|
import { TimePicker } from '../TimePicker'
|
|
5
5
|
|
|
6
6
|
describe('test timepicker onChange method with valid values', () => {
|
|
7
|
-
const testOnChange = ({
|
|
7
|
+
const testOnChange = ({ inputProps, expects }) => {
|
|
8
8
|
const onChange = jest.fn();
|
|
9
9
|
|
|
10
10
|
const event: any = {
|
|
11
|
-
currentTarget: { value:
|
|
11
|
+
currentTarget: { value: inputProps.value }
|
|
12
12
|
};
|
|
13
|
-
const view = mount(<TimePicker onChange={onChange}
|
|
14
|
-
|
|
13
|
+
const view = mount(<TimePicker onChange={onChange} {...inputProps} aria-label="time picker" />);
|
|
14
|
+
|
|
15
15
|
act(() => {
|
|
16
16
|
view.find('input').prop('onChange')(event);
|
|
17
17
|
})
|
|
18
|
-
expect(onChange).toBeCalledWith(
|
|
18
|
+
expect(onChange).toBeCalledWith(inputProps.value, expects.hour, expects.minutes, expects.seconds, true);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
test('should return the correct value using the AM/PM pattern - midnight', () => {
|
|
22
|
-
testOnChange({
|
|
22
|
+
testOnChange({ inputProps: { value: "12:00 AM", is24Hour: false }, expects: { hour: 0, minutes: 0, seconds: null }})
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
test('should return the correct value using the AM/PM pattern - midday', () => {
|
|
26
|
-
testOnChange({
|
|
26
|
+
testOnChange({ inputProps: { value: "12:35 PM", is24Hour: false }, expects: { hour: 12, minutes: 35, seconds: null }})
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
test('should return the correct value using the AM/PM pattern - last minute of the day', () => {
|
|
30
|
-
testOnChange({
|
|
30
|
+
testOnChange({ inputProps: { value: "11:59 PM", is24Hour: false }, expects: { hour: 23, minutes: 59, seconds: null }})
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
test('should return the correct value using the 24h pattern - midnight', () => {
|
|
34
|
-
testOnChange({
|
|
34
|
+
testOnChange({ inputProps: { value: "00:00:00", is24Hour: true, includeSeconds: true }, expects: { hour: 0, minutes: 0, seconds: 0 }})
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
test('should return the correct value using the 24h pattern - midday', () => {
|
|
38
|
-
testOnChange({
|
|
38
|
+
testOnChange({ inputProps: { value: "12:35", is24Hour: false }, expects: { hour: 12, minutes: 35, seconds: null }})
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
test('should return the correct value using the 24h pattern - last minute of the day', () => {
|
|
42
|
-
testOnChange({
|
|
42
|
+
testOnChange({ inputProps: { value: "23:59", is24Hour: true }, expects: { hour: 23, minutes: 59, seconds: null }})
|
|
43
43
|
})
|
|
44
44
|
})
|
|
45
45
|
|
|
@@ -90,3 +90,41 @@ describe('test isInvalid', () => {
|
|
|
90
90
|
expect(view.find('.pf-m-error')).toHaveLength(1);
|
|
91
91
|
})
|
|
92
92
|
})
|
|
93
|
+
|
|
94
|
+
describe('test includeSeconds', () => {
|
|
95
|
+
const baseProps = {
|
|
96
|
+
"aria-label": "time picker",
|
|
97
|
+
value: "12:00 PM",
|
|
98
|
+
includeSeconds: true
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
it('should be valid still with a max value of "11:59:59 PM" by default', () => {
|
|
102
|
+
const event: any = { currentTarget: { value: "11:59:59 PM" } };
|
|
103
|
+
const view = mount(<TimePicker {...baseProps} />);
|
|
104
|
+
|
|
105
|
+
act(() => view.find('input').prop('onChange')(event));
|
|
106
|
+
view.update();
|
|
107
|
+
|
|
108
|
+
expect(view.find('.pf-m-error')).toHaveLength(0);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should be valid still with a max value of "23:59:59" by default when using 24 hour time', () => {
|
|
112
|
+
const event: any = { currentTarget: { value: "23:59:59" } };
|
|
113
|
+
const view = mount(<TimePicker {...baseProps} value="20:00" is24Hour />);
|
|
114
|
+
|
|
115
|
+
act(() => view.find('input').prop('onChange')(event));
|
|
116
|
+
view.update();
|
|
117
|
+
|
|
118
|
+
expect(view.find('.pf-m-error')).toHaveLength(0);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should be invalid with a max value of "24:00:00" by default', () => {
|
|
122
|
+
const event: any = { currentTarget: { value: "24:00:00" } };
|
|
123
|
+
const view = mount(<TimePicker {...baseProps} value="20:00" is24Hour />);
|
|
124
|
+
|
|
125
|
+
act(() => view.find('input').prop('onChange')(event));
|
|
126
|
+
view.update();
|
|
127
|
+
|
|
128
|
+
expect(view.find('.pf-m-error')).toHaveLength(1);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -15,13 +15,14 @@ import React from 'react';
|
|
|
15
15
|
import { TimePicker } from '@patternfly/react-core';
|
|
16
16
|
|
|
17
17
|
SimpleTimePicker = () => {
|
|
18
|
-
const onChange = (time, hour, minute, isValid) => {
|
|
18
|
+
const onChange = (time, hour, minute, seconds, isValid) => {
|
|
19
19
|
console.log("time", time);
|
|
20
20
|
console.log("hour", hour);
|
|
21
21
|
console.log("minute", minute);
|
|
22
|
+
console.log("seconds", seconds);
|
|
22
23
|
console.log("isValid", isValid);
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
return <TimePicker time="3:35 AM" onChange={onChange}/>;
|
|
26
27
|
}
|
|
27
28
|
```
|
|
@@ -52,3 +53,19 @@ import { TimePicker } from '@patternfly/react-core';
|
|
|
52
53
|
|
|
53
54
|
<TimePicker is24Hour minTime="9:30" maxTime="17:15" placeholder="14:00"/>
|
|
54
55
|
```
|
|
56
|
+
|
|
57
|
+
### With seconds
|
|
58
|
+
```js
|
|
59
|
+
import React from 'react';
|
|
60
|
+
import { TimePicker } from '@patternfly/react-core';
|
|
61
|
+
|
|
62
|
+
SimpleTimePicker = () => <TimePicker time="3:35:20 PM" includeSeconds />;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 24 hours with seconds
|
|
66
|
+
```js
|
|
67
|
+
import React from 'react';
|
|
68
|
+
import { TimePicker } from '@patternfly/react-core';
|
|
69
|
+
|
|
70
|
+
SimpleTimePicker = () => <TimePicker time="12:35:50" includeSeconds is24Hour />;
|
|
71
|
+
```
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Button
|
|
3
|
+
section: components
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
|
|
7
|
+
|
|
8
|
+
## Demos
|
|
9
|
+
|
|
10
|
+
### Progress button
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { Form, FormGroup, ActionGroup, InputGroup, TextInput, Button } from '@patternfly/react-core';
|
|
15
|
+
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
|
|
16
|
+
|
|
17
|
+
const ProgressButton: React.FunctionComponent = () => {
|
|
18
|
+
const [loginState, setLoginState] = React.useState<'notLoggedIn' | 'loading' | 'loggedIn'>('notLoggedIn');
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Form>
|
|
22
|
+
<FormGroup label="Username" isRequired fieldId="progress-button-initial-login">
|
|
23
|
+
<TextInput
|
|
24
|
+
isRequired
|
|
25
|
+
type="text"
|
|
26
|
+
id="progress-button-initial-login"
|
|
27
|
+
name="progress-button-initial-login"
|
|
28
|
+
value="johndoe"
|
|
29
|
+
aria-label="username input"
|
|
30
|
+
/>
|
|
31
|
+
</FormGroup>
|
|
32
|
+
<FormGroup label="Password" isRequired fieldId="progress-button-initial-password">
|
|
33
|
+
<TextInput
|
|
34
|
+
isRequired
|
|
35
|
+
type="password"
|
|
36
|
+
value="p@ssw0rd"
|
|
37
|
+
id="progress-button-initial-password"
|
|
38
|
+
name="progress-button-initial-password"
|
|
39
|
+
aria-label="password input"
|
|
40
|
+
/>
|
|
41
|
+
</FormGroup>
|
|
42
|
+
<ActionGroup>
|
|
43
|
+
<Button
|
|
44
|
+
variant="primary"
|
|
45
|
+
onClick={
|
|
46
|
+
loginState === 'notLoggedIn'
|
|
47
|
+
? () => {
|
|
48
|
+
setLoginState('loading');
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
setLoginState('loggedIn');
|
|
51
|
+
}, 3000);
|
|
52
|
+
}
|
|
53
|
+
: null
|
|
54
|
+
}
|
|
55
|
+
isLoading={loginState === 'loading'}
|
|
56
|
+
icon={loginState === 'loggedIn' ? <CheckCircleIcon /> : null}
|
|
57
|
+
spinnerAriaValueText="Loading..."
|
|
58
|
+
>
|
|
59
|
+
{loginState === 'notLoggedIn' && 'Link account and log in'}
|
|
60
|
+
{loginState === 'loading' && 'Linking account'}
|
|
61
|
+
{loginState === 'loggedIn' && 'Logged in'}
|
|
62
|
+
</Button>
|
|
63
|
+
</ActionGroup>
|
|
64
|
+
</Form>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
```
|
package/src/helpers/util.ts
CHANGED
|
@@ -39,24 +39,30 @@ export function debounce(this: any, func: (...args: any[]) => any, wait: number)
|
|
|
39
39
|
* @param {HTMLElement} container The container to check if the element is in view of.
|
|
40
40
|
* @param {HTMLElement} element The element to check if it is view
|
|
41
41
|
* @param {boolean} partial true if partial view is allowed
|
|
42
|
+
* @param {boolean} strict true if strict mode is set, never consider the container width and element width
|
|
42
43
|
*
|
|
43
44
|
* @returns { boolean } True if the component is in View.
|
|
44
45
|
*/
|
|
45
|
-
export function isElementInView(
|
|
46
|
+
export function isElementInView(
|
|
47
|
+
container: HTMLElement,
|
|
48
|
+
element: HTMLElement,
|
|
49
|
+
partial: boolean,
|
|
50
|
+
strict: boolean = false
|
|
51
|
+
): boolean {
|
|
46
52
|
if (!container || !element) {
|
|
47
53
|
return false;
|
|
48
54
|
}
|
|
49
55
|
const containerBounds = container.getBoundingClientRect();
|
|
50
56
|
const elementBounds = element.getBoundingClientRect();
|
|
51
|
-
const containerBoundsLeft = Math.
|
|
57
|
+
const containerBoundsLeft = Math.ceil(containerBounds.left);
|
|
52
58
|
const containerBoundsRight = Math.floor(containerBounds.right);
|
|
53
|
-
const elementBoundsLeft = Math.
|
|
59
|
+
const elementBoundsLeft = Math.ceil(elementBounds.left);
|
|
54
60
|
const elementBoundsRight = Math.floor(elementBounds.right);
|
|
55
61
|
|
|
56
62
|
// Check if in view
|
|
57
63
|
const isTotallyInView = elementBoundsLeft >= containerBoundsLeft && elementBoundsRight <= containerBoundsRight;
|
|
58
64
|
const isPartiallyInView =
|
|
59
|
-
partial &&
|
|
65
|
+
(partial || (!strict && containerBounds.width < elementBounds.width)) &&
|
|
60
66
|
((elementBoundsLeft < containerBoundsLeft && elementBoundsRight > containerBoundsLeft) ||
|
|
61
67
|
(elementBoundsRight > containerBoundsRight && elementBoundsLeft < containerBoundsRight));
|
|
62
68
|
|