@patternfly/react-core 4.224.3 → 4.224.6

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/esm/components/NumberInput/NumberInput.d.ts.map +1 -1
  3. package/dist/esm/components/NumberInput/NumberInput.js +10 -1
  4. package/dist/esm/components/NumberInput/NumberInput.js.map +1 -1
  5. package/dist/js/components/NumberInput/NumberInput.d.ts.map +1 -1
  6. package/dist/js/components/NumberInput/NumberInput.js +10 -1
  7. package/dist/js/components/NumberInput/NumberInput.js.map +1 -1
  8. package/dist/umd/react-core.js +10 -1
  9. package/dist/umd/react-core.min.js +1 -1
  10. package/package.json +5 -5
  11. package/src/components/Modal/examples/Modal.md +22 -804
  12. package/src/components/Modal/examples/ModalBasic.tsx +37 -0
  13. package/src/components/Modal/examples/ModalCustomHeaderFooter.tsx +56 -0
  14. package/src/components/Modal/examples/ModalCustomTitleIcon.tsx +46 -0
  15. package/src/components/Modal/examples/ModalCustomWidth.tsx +38 -0
  16. package/src/components/Modal/examples/ModalLarge.tsx +38 -0
  17. package/src/components/Modal/examples/ModalMedium.tsx +38 -0
  18. package/src/components/Modal/examples/ModalNoHeaderFooter.tsx +37 -0
  19. package/src/components/Modal/examples/ModalSmall.tsx +38 -0
  20. package/src/components/Modal/examples/ModalTitleIcon.tsx +45 -0
  21. package/src/components/Modal/examples/ModalTopAligned.tsx +38 -0
  22. package/src/components/Modal/examples/ModalWithDescription.tsx +38 -0
  23. package/src/components/Modal/examples/ModalWithDropdown.tsx +97 -0
  24. package/src/components/Modal/examples/ModalWithForm.tsx +4 -12
  25. package/src/components/Modal/examples/ModalWithHelp.tsx +54 -0
  26. package/src/components/Modal/examples/ModalWithWizard.tsx +45 -0
  27. package/src/components/NotificationBadge/examples/NotificationBadge.md +4 -72
  28. package/src/components/NotificationBadge/examples/NotificationBadgeBasic.tsx +30 -0
  29. package/src/components/NotificationBadge/examples/NotificationBadgeWithCount.tsx +36 -0
  30. package/src/components/NumberInput/NumberInput.tsx +11 -1
  31. package/src/components/NumberInput/__tests__/NumberInput.test.tsx +94 -1
  32. package/src/components/NumberInput/examples/NumberInput.md +0 -1
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { Modal, ModalVariant, Button, Wizard } from '@patternfly/react-core';
3
+
4
+ export const ModalWithWizard: React.FunctionComponent = () => {
5
+ const [isModalOpen, setIsModalOpen] = React.useState(false);
6
+
7
+ const handleModalToggle = () => {
8
+ setIsModalOpen(!isModalOpen);
9
+ };
10
+
11
+ const steps = [
12
+ { name: 'Step 1', component: <p>Step 1</p> },
13
+ { name: 'Step 2', component: <p>Step 2</p> },
14
+ { name: 'Step 3', component: <p>Step 3</p> },
15
+ { name: 'Step 4', component: <p>Step 4</p> },
16
+ { name: 'Review', component: <p>Review Step</p>, nextButtonText: 'Finish' }
17
+ ];
18
+
19
+ return (
20
+ <React.Fragment>
21
+ <Button variant="primary" onClick={handleModalToggle}>
22
+ Show wizard modal
23
+ </Button>
24
+ <Modal
25
+ variant={ModalVariant.large}
26
+ showClose={false}
27
+ isOpen={isModalOpen}
28
+ aria-labelledby="modal-wizard-label"
29
+ aria-describedby="modal-wizard-description"
30
+ onClose={handleModalToggle}
31
+ hasNoBodyWrapper
32
+ >
33
+ <Wizard
34
+ titleId="modal-wizard-label"
35
+ descriptionId="modal-wizard-description"
36
+ title="Wizard modal"
37
+ description="This is a wizard inside of a modal."
38
+ steps={steps}
39
+ onClose={handleModalToggle}
40
+ height={400}
41
+ />
42
+ </Modal>
43
+ </React.Fragment>
44
+ );
45
+ };
@@ -8,79 +8,11 @@ import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
8
8
  import './notificationBadge.css';
9
9
 
10
10
  ## Examples
11
- ### Basic
12
- ```js
13
- import React from 'react';
14
- import { NotificationBadge } from '@patternfly/react-core';
15
- import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
16
-
17
- class SimpleNotificationBadge extends React.Component {
18
- constructor(props) {
19
- super(props);
20
- this.state = {
21
- unreadVariant: 'unread',
22
- attentionVariant: 'attention'
23
- };
24
- this.onFirstClick = () => {
25
- this.setState({
26
- unreadVariant: 'read'
27
- });
28
- };
29
- this.onSecondClick = () => {
30
- this.setState({
31
- attentionVariant: 'read'
32
- });
33
- };
34
- }
35
11
 
36
- render() {
37
- const { unreadVariant, attentionVariant } = this.state;
38
- return (
39
- <div className="pf-t-dark">
40
- <NotificationBadge variant={unreadVariant} onClick={this.onFirstClick} aria-label="First notifications" />
41
- <NotificationBadge variant={attentionVariant} onClick={this.onSecondClick} aria-label="Second notifications" />
42
- </div>
43
- );
44
- }
45
- }
12
+ ### Basic
13
+ ```ts file='./NotificationBadgeBasic.tsx'
46
14
  ```
47
15
 
48
- ## Examples
49
16
  ### With count
50
- ```js
51
- import React from 'react';
52
- import { NotificationBadge } from '@patternfly/react-core';
53
- import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
54
-
55
- class NotificationBadgeWithCount extends React.Component {
56
- constructor(props) {
57
- super(props);
58
- this.state = {
59
- firstVariant: 'unread',
60
- firstCount: 30,
61
- secondVariant: 'attention',
62
- secondCount: 30
63
- };
64
- this.onFirstClick = () => {
65
- this.setState({
66
- firstVariant: 'read',
67
- });
68
- };
69
- this.onSecondClick = () => {
70
- this.setState({
71
- secondVariant: 'read'
72
- });
73
- };
74
- }
75
-
76
- render() {
77
- const { firstVariant, firstCount, secondVariant, secondCount } = this.state;
78
- return (
79
- <div className="pf-t-dark">
80
- <NotificationBadge variant={firstVariant} onClick={this.onFirstClick} aria-label="First notifications" count={firstCount} />
81
- <NotificationBadge variant={secondVariant} onClick={this.onSecondClick} aria-label="Second notifications" count={secondCount} />
82
- </div>
83
- );
84
- }
85
- }
86
- ```
17
+ ```ts file='./NotificationBadgeWithCount.tsx'
18
+ ```
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import { NotificationBadge, NotificationBadgeVariant } from '@patternfly/react-core';
3
+
4
+ export const SimpleNotificationBadge: React.FunctionComponent = () => {
5
+ const [unreadVariant, setUnreadVariant] = React.useState(NotificationBadgeVariant.unread);
6
+ const [attentionVariant, setAttentionVariant] = React.useState(NotificationBadgeVariant.attention);
7
+
8
+ const onFirstClick = (value: NotificationBadgeVariant) => {
9
+ setUnreadVariant(value);
10
+ };
11
+
12
+ const onSecondClick = (value: NotificationBadgeVariant) => {
13
+ setAttentionVariant(value);
14
+ };
15
+
16
+ return (
17
+ <div className="pf-t-dark">
18
+ <NotificationBadge
19
+ variant={unreadVariant}
20
+ onClick={() => onFirstClick(NotificationBadgeVariant.read)}
21
+ aria-label="First notifications"
22
+ />
23
+ <NotificationBadge
24
+ variant={attentionVariant}
25
+ onClick={() => onSecondClick(NotificationBadgeVariant.read)}
26
+ aria-label="Second notifications"
27
+ />
28
+ </div>
29
+ );
30
+ };
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { NotificationBadge, NotificationBadgeVariant } from '@patternfly/react-core';
3
+
4
+ export const NotificationBadgeWithCount: React.FunctionComponent = () => {
5
+ const [firstVariant, setFirstVariant] = React.useState(NotificationBadgeVariant.unread);
6
+ const [firstVariantCount, setFirstVariantCount] = React.useState(30);
7
+ const [secondVariant, setSecondVariant] = React.useState(NotificationBadgeVariant.attention);
8
+ const [secondVariantCount, setSecondVariantCount] = React.useState(30);
9
+
10
+ const onFirstClick = (value: NotificationBadgeVariant) => {
11
+ setFirstVariant(value);
12
+ setFirstVariantCount(10);
13
+ };
14
+
15
+ const onSecondClick = (value: NotificationBadgeVariant) => {
16
+ setSecondVariant(value);
17
+ setSecondVariantCount(10);
18
+ };
19
+
20
+ return (
21
+ <div className="pf-t-dark">
22
+ <NotificationBadge
23
+ variant={firstVariant}
24
+ onClick={() => onFirstClick(NotificationBadgeVariant.read)}
25
+ aria-label="First notifications"
26
+ count={firstVariantCount}
27
+ />
28
+ <NotificationBadge
29
+ variant={secondVariant}
30
+ onClick={() => onSecondClick(NotificationBadgeVariant.read)}
31
+ aria-label="Second notifications"
32
+ count={secondVariantCount}
33
+ />
34
+ </div>
35
+ );
36
+ };
@@ -87,6 +87,16 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
87
87
  const keyDownHandler =
88
88
  inputProps && inputProps.onKeyDown ? inputProps.onKeyDown : defaultKeyDownHandler({ inputName, onMinus, onPlus });
89
89
 
90
+ const handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {
91
+ event.target.value = Number(event.target.value).toString();
92
+ if (onChange) {
93
+ onChange(event);
94
+ }
95
+ if (onBlur) {
96
+ onBlur(event);
97
+ }
98
+ };
99
+
90
100
  return (
91
101
  <div
92
102
  className={css(styles.numberInput, className)}
@@ -119,7 +129,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
119
129
  aria-label={inputAriaLabel}
120
130
  {...(isDisabled && { disabled: isDisabled })}
121
131
  {...(onChange && { onChange })}
122
- {...(onBlur && { onBlur })}
132
+ onBlur={handleBlur}
123
133
  {...(!onChange && { readOnly: true })}
124
134
  {...inputProps}
125
135
  onKeyDown={keyDownHandler}
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import { NumberInput } from '../NumberInput';
4
+ import userEvent from '@testing-library/user-event';
4
5
 
5
6
  describe('numberInput', () => {
6
7
  test('renders defaults & extra props', () => {
@@ -60,4 +61,96 @@ describe('numberInput', () => {
60
61
  );
61
62
  expect(asFragment()).toMatchSnapshot();
62
63
  });
64
+
65
+ test('renders negative value', () => {
66
+ render(<NumberInput value={-999} />);
67
+ expect(screen.getByDisplayValue('-999')).toBeInTheDocument();
68
+ });
69
+
70
+ test('renders decimal value', () => {
71
+ render(<NumberInput value={5.5} />);
72
+ expect(screen.getByDisplayValue('5.5')).toBeInTheDocument();
73
+ });
74
+
75
+ test('renders negative decimal value', () => {
76
+ render(<NumberInput value={-5.2} />);
77
+ expect(screen.getByDisplayValue('-5.2')).toBeInTheDocument();
78
+ });
79
+
80
+ test('does not call onChange callback when the input does not change', () => {
81
+ const onChangeMock = jest.fn();
82
+
83
+ render(<NumberInput onChange={onChangeMock}>5</NumberInput>);
84
+
85
+ expect(onChangeMock).not.toHaveBeenCalled();
86
+ });
87
+
88
+ test('calls onChange callback when input changes', () => {
89
+ const onChangeMock = jest.fn();
90
+ render(<NumberInput onChange={onChangeMock}>55</NumberInput>);
91
+
92
+ const input = screen.getByRole('spinbutton');
93
+ userEvent.type(input, '55');
94
+
95
+ expect(onChangeMock).toHaveBeenCalledTimes(2);
96
+ });
97
+
98
+ test('does not call onBlur callback when input does not lose focus', () => {
99
+ const onBlurMock = jest.fn();
100
+
101
+ render(<NumberInput onBlur={onBlurMock}>5</NumberInput>);
102
+
103
+ const input = screen.getByRole('spinbutton');
104
+ userEvent.click(input);
105
+
106
+ expect(onBlurMock).not.toHaveBeenCalled();
107
+ });
108
+
109
+ test('calls onBlur callback when input loses focus', () => {
110
+ const onBlurMock = jest.fn();
111
+
112
+ render(<NumberInput onBlur={onBlurMock}>5</NumberInput>);
113
+
114
+ const input = screen.getByRole('spinbutton');
115
+ userEvent.click(input);
116
+ userEvent.click(document.body);
117
+
118
+ expect(onBlurMock).toHaveBeenCalledTimes(1);
119
+ });
120
+
121
+ test('removes leading zeros from a positive whole number', () => {
122
+ render(<NumberInput value={10} onChange={() => {}} />);
123
+
124
+ const input = screen.getByRole('spinbutton');
125
+ userEvent.type(input, '{arrowleft}{arrowleft}0');
126
+ expect(input).toHaveDisplayValue('010');
127
+
128
+ userEvent.click(document.body);
129
+
130
+ expect(input).toHaveDisplayValue('10');
131
+ });
132
+
133
+ test('removes leading zeros from a negative whole number', () => {
134
+ render(<NumberInput value={-18} onChange={() => {}} />);
135
+
136
+ const input = screen.getByRole('spinbutton');
137
+ userEvent.type(input, '{arrowleft}{arrowleft}0');
138
+ expect(input).toHaveDisplayValue('-018');
139
+
140
+ userEvent.click(document.body);
141
+
142
+ expect(input).toHaveDisplayValue('-18');
143
+ });
144
+
145
+ test('removes leading zeros from a decimal number', () => {
146
+ render(<NumberInput value={47.01} onChange={() => {}} />);
147
+
148
+ const input = screen.getByRole('spinbutton');
149
+ userEvent.type(input, '{arrowleft}{arrowleft}{arrowleft}{arrowleft}{arrowleft}0');
150
+ expect(input).toHaveDisplayValue('047.01');
151
+
152
+ userEvent.click(document.body);
153
+
154
+ expect(input).toHaveDisplayValue('47.01');
155
+ });
63
156
  });
@@ -96,7 +96,6 @@ class UnitNumberInput extends React.Component {
96
96
  };
97
97
 
98
98
  this.onChange2 = event => {
99
- console.log(event.target.value);
100
99
  this.setState({
101
100
  value2: event.target.value
102
101
  });