@patternfly/react-core 4.169.3 → 4.170.2

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 (48) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/esm/components/FileUpload/FileUpload.d.ts +11 -3
  3. package/dist/esm/components/FileUpload/FileUpload.d.ts.map +1 -1
  4. package/dist/esm/components/FileUpload/FileUpload.js +28 -5
  5. package/dist/esm/components/FileUpload/FileUpload.js.map +1 -1
  6. package/dist/esm/components/FileUpload/FileUploadField.d.ts +2 -0
  7. package/dist/esm/components/FileUpload/FileUploadField.d.ts.map +1 -1
  8. package/dist/esm/components/FileUpload/FileUploadField.js +2 -1
  9. package/dist/esm/components/FileUpload/FileUploadField.js.map +1 -1
  10. package/dist/esm/components/TextInputGroup/TextInputGroup.d.ts +3 -0
  11. package/dist/esm/components/TextInputGroup/TextInputGroup.d.ts.map +1 -1
  12. package/dist/esm/components/TextInputGroup/TextInputGroup.js +6 -2
  13. package/dist/esm/components/TextInputGroup/TextInputGroup.js.map +1 -1
  14. package/dist/esm/components/TextInputGroup/TextInputGroupMain.d.ts +8 -2
  15. package/dist/esm/components/TextInputGroup/TextInputGroupMain.d.ts.map +1 -1
  16. package/dist/esm/components/TextInputGroup/TextInputGroupMain.js +7 -3
  17. package/dist/esm/components/TextInputGroup/TextInputGroupMain.js.map +1 -1
  18. package/dist/js/components/FileUpload/FileUpload.d.ts +11 -3
  19. package/dist/js/components/FileUpload/FileUpload.d.ts.map +1 -1
  20. package/dist/js/components/FileUpload/FileUpload.js +27 -4
  21. package/dist/js/components/FileUpload/FileUpload.js.map +1 -1
  22. package/dist/js/components/FileUpload/FileUploadField.d.ts +2 -0
  23. package/dist/js/components/FileUpload/FileUploadField.d.ts.map +1 -1
  24. package/dist/js/components/FileUpload/FileUploadField.js +2 -1
  25. package/dist/js/components/FileUpload/FileUploadField.js.map +1 -1
  26. package/dist/js/components/TextInputGroup/TextInputGroup.d.ts +3 -0
  27. package/dist/js/components/TextInputGroup/TextInputGroup.d.ts.map +1 -1
  28. package/dist/js/components/TextInputGroup/TextInputGroup.js +7 -3
  29. package/dist/js/components/TextInputGroup/TextInputGroup.js.map +1 -1
  30. package/dist/js/components/TextInputGroup/TextInputGroupMain.d.ts +8 -2
  31. package/dist/js/components/TextInputGroup/TextInputGroupMain.d.ts.map +1 -1
  32. package/dist/js/components/TextInputGroup/TextInputGroupMain.js +7 -3
  33. package/dist/js/components/TextInputGroup/TextInputGroupMain.js.map +1 -1
  34. package/dist/umd/react-core.css +97 -86
  35. package/dist/umd/react-core.js +1581 -1298
  36. package/dist/umd/react-core.min.css +743 -732
  37. package/dist/umd/react-core.min.js +5 -6
  38. package/package.json +7 -7
  39. package/src/components/FileUpload/FileUpload.tsx +77 -30
  40. package/src/components/FileUpload/FileUploadField.tsx +5 -0
  41. package/src/components/FileUpload/__tests__/__snapshots__/FileUpload.test.tsx.snap +3 -7
  42. package/src/components/FileUpload/examples/FileUpload.md +54 -17
  43. package/src/components/Modal/examples/Modal.md +203 -0
  44. package/src/components/TextInputGroup/TextInputGroup.tsx +12 -3
  45. package/src/components/TextInputGroup/TextInputGroupMain.tsx +51 -20
  46. package/src/components/TextInputGroup/__tests__/TextInputGroup.test.tsx +91 -3
  47. package/src/components/TextInputGroup/__tests__/__snapshots__/TextInputGroup.test.tsx.snap +19 -16
  48. package/src/components/TextInputGroup/examples/TextInputGroup.md +13 -0
@@ -7,16 +7,25 @@ export interface TextInputGroupProps extends React.HTMLProps<HTMLDivElement> {
7
7
  children?: React.ReactNode;
8
8
  /** Additional classes applied to the text input group container */
9
9
  className?: string;
10
+ /** Adds disabled styling and a disabled context value which text input group main hooks into for the input itself */
11
+ isDisabled?: boolean;
10
12
  }
11
13
 
14
+ export const TextInputGroupContext = React.createContext<Partial<TextInputGroupProps>>({
15
+ isDisabled: false
16
+ });
17
+
12
18
  export const TextInputGroup: React.FunctionComponent<TextInputGroupProps> = ({
13
19
  children,
14
20
  className,
21
+ isDisabled,
15
22
  ...props
16
23
  }: TextInputGroupProps) => (
17
- <div className={css(styles.textInputGroup, className)} {...props}>
18
- {children}
19
- </div>
24
+ <TextInputGroupContext.Provider value={{ isDisabled }}>
25
+ <div className={css(styles.textInputGroup, isDisabled && styles.modifiers.disabled, className)} {...props}>
26
+ {children}
27
+ </div>
28
+ </TextInputGroupContext.Provider>
20
29
  );
21
30
 
22
31
  TextInputGroup.displayName = 'TextInputGroup';
@@ -1,16 +1,34 @@
1
1
  import * as React from 'react';
2
2
  import styles from '@patternfly/react-styles/css/components/TextInputGroup/text-input-group';
3
3
  import { css } from '@patternfly/react-styles';
4
+ import { TextInputGroupContext } from './TextInputGroup';
4
5
 
5
- export interface TextInputGroupMainProps extends React.HTMLProps<HTMLDivElement> {
6
+ export interface TextInputGroupMainProps extends Omit<React.HTMLProps<HTMLDivElement>, 'onChange'> {
6
7
  /** Content rendered inside the text input group main div */
7
8
  children?: React.ReactNode;
8
9
  /** Additional classes applied to the text input group main container */
9
10
  className?: string;
10
11
  /** Icon to be shown on the left side of the text input group main container */
11
12
  icon?: React.ReactNode;
13
+ /** Type that the input accepts. */
14
+ type?:
15
+ | 'text'
16
+ | 'date'
17
+ | 'datetime-local'
18
+ | 'email'
19
+ | 'month'
20
+ | 'number'
21
+ | 'password'
22
+ | 'search'
23
+ | 'tel'
24
+ | 'time'
25
+ | 'url';
12
26
  /** Callback for when there is a change in the input field*/
13
- onChange?: () => void;
27
+ onChange?: (value: string, event: React.FormEvent<HTMLInputElement>) => void;
28
+ /** Callback for when the input field is focused*/
29
+ onFocus?: (event?: any) => void;
30
+ /** Callback for when focus is lost on the input field*/
31
+ onBlur?: (event?: any) => void;
14
32
  /** Accessibility label for the input */
15
33
  'aria-label'?: string;
16
34
  }
@@ -19,25 +37,38 @@ export const TextInputGroupMain: React.FunctionComponent<TextInputGroupMainProps
19
37
  children,
20
38
  className,
21
39
  icon,
22
- onChange,
23
- 'aria-label': ariaLabel,
40
+ type = 'text',
41
+ onChange = (): any => undefined,
42
+ onFocus,
43
+ onBlur,
44
+ 'aria-label': ariaLabel = 'Type to filter',
24
45
  value: inputValue,
25
46
  ...props
26
- }: TextInputGroupMainProps) => (
27
- <div className={css(styles.textInputGroupMain, icon && styles.modifiers.icon, className)} {...props}>
28
- {children}
29
- <span className={css(styles.textInputGroupText)}>
30
- {icon && <span className={css(styles.textInputGroupIcon)}>{icon}</span>}
31
- <input
32
- type="text"
33
- className={css(styles.textInputGroupTextInput)}
34
- aria-label={ariaLabel}
35
- onChange={onChange}
36
- value={inputValue}
37
- />
38
- </span>
39
- </div>
40
- );
47
+ }: TextInputGroupMainProps) => {
48
+ const { isDisabled } = React.useContext(TextInputGroupContext);
49
+
50
+ const handleChange = (event: React.FormEvent<HTMLInputElement>) => {
51
+ onChange(event.currentTarget.value, event);
52
+ };
53
+
54
+ return (
55
+ <div className={css(styles.textInputGroupMain, icon && styles.modifiers.icon, className)} {...props}>
56
+ {children}
57
+ <span className={css(styles.textInputGroupText)}>
58
+ {icon && <span className={css(styles.textInputGroupIcon)}>{icon}</span>}
59
+ <input
60
+ type={type}
61
+ className={css(styles.textInputGroupTextInput)}
62
+ aria-label={ariaLabel}
63
+ disabled={isDisabled}
64
+ onChange={handleChange}
65
+ onFocus={onFocus}
66
+ onBlur={onBlur}
67
+ value={inputValue}
68
+ />
69
+ </span>
70
+ </div>
71
+ );
72
+ };
41
73
 
42
- TextInputGroupMain.defaultProps = { 'aria-label': 'Type to filter' };
43
74
  TextInputGroupMain.displayName = 'TextInputGroupMain';
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { mount } from 'enzyme';
3
- import { TextInputGroup } from '../TextInputGroup';
3
+ import { TextInputGroup, TextInputGroupContext } from '../TextInputGroup';
4
4
  import { TextInputGroupMain } from '../TextInputGroupMain';
5
5
  import { TextInputGroupUtilities } from '../TextInputGroupUtilities';
6
6
  import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
@@ -26,15 +26,45 @@ describe('TextInputGroup', () => {
26
26
  expect(view).toMatchSnapshot();
27
27
  });
28
28
 
29
- test('renders with the proper stying for an icon on the left side of the component', () => {
29
+ test('renders with the proper stying when disabled', () => {
30
30
  const view = mount(
31
- <TextInputGroup>
31
+ <TextInputGroup isDisabled>
32
32
  <TextInputGroupMain>Foo</TextInputGroupMain>
33
33
  <TextInputGroupUtilities />
34
34
  </TextInputGroup>
35
35
  );
36
36
  expect(view).toMatchSnapshot();
37
37
  });
38
+
39
+ test('passes isDisabled=false to children via a context when isDisabled prop is not passed', () => {
40
+ const TestComponent: React.FunctionComponent = () => {
41
+ const context = React.useContext(TextInputGroupContext);
42
+
43
+ return <div>{context.isDisabled ? 'is disabled' : 'not disabled'}</div>;
44
+ };
45
+
46
+ const view = mount(
47
+ <TextInputGroup>
48
+ <TestComponent />
49
+ </TextInputGroup>
50
+ );
51
+ expect(view.text()).toBe('not disabled');
52
+ });
53
+
54
+ test('passes isDisabled=true to children via a context when isDisabled prop is passed', () => {
55
+ const TestComponent: React.FunctionComponent = () => {
56
+ const context = React.useContext(TextInputGroupContext);
57
+
58
+ return <div>{context.isDisabled ? 'is disabled' : 'not disabled'}</div>;
59
+ };
60
+
61
+ const view = mount(
62
+ <TextInputGroup isDisabled>
63
+ <TestComponent />
64
+ </TextInputGroup>
65
+ );
66
+ expect(view.text()).toBe('is disabled');
67
+ });
38
68
  });
39
69
 
40
70
  describe('TextInputGroupMain', () => {
@@ -67,6 +97,64 @@ describe('TextInputGroupMain', () => {
67
97
  view.find('input').simulate('change', { target: { value: 'Foo' } });
68
98
  expect(onChangeMock).toHaveBeenCalledTimes(1);
69
99
  });
100
+
101
+ test('does not call onFocus callback when the input does not get focus', () => {
102
+ const onFocusMock = jest.fn();
103
+
104
+ const view = mount(<TextInputGroupMain onFocus={onFocusMock}>Foo</TextInputGroupMain>);
105
+ expect(onFocusMock).not.toHaveBeenCalled();
106
+ });
107
+
108
+ test('calls the onFocus callback when the input is focused', () => {
109
+ const onFocusMock = jest.fn();
110
+
111
+ const view = mount(<TextInputGroupMain onFocus={onFocusMock}>Foo</TextInputGroupMain>);
112
+ view.find('input').simulate('focus');
113
+ expect(onFocusMock).toHaveBeenCalledTimes(1);
114
+ });
115
+
116
+ test('does not call onBlur callback when the input does not lose focus', () => {
117
+ const onBlurMock = jest.fn();
118
+
119
+ const view = mount(<TextInputGroupMain onBlur={onBlurMock}>Foo</TextInputGroupMain>);
120
+ expect(onBlurMock).not.toHaveBeenCalled();
121
+ });
122
+
123
+ test('calls the onFocus callback when the input loses focus', () => {
124
+ const onBlurMock = jest.fn();
125
+
126
+ const view = mount(<TextInputGroupMain onBlur={onBlurMock}>Foo</TextInputGroupMain>);
127
+ view.find('input').simulate('blur');
128
+ expect(onBlurMock).toHaveBeenCalledTimes(1);
129
+ });
130
+
131
+ test('input type defaults to text', () => {
132
+ const view = mount(<TextInputGroupMain>Foo</TextInputGroupMain>);
133
+ expect(view.find('input').props()['type']).toBe('text');
134
+ });
135
+
136
+ test('input type is updated when a different type is passed', () => {
137
+ const view = mount(<TextInputGroupMain type="search">Foo</TextInputGroupMain>);
138
+ expect(view.find('input').props()['type']).toBe('search');
139
+ });
140
+
141
+ test('input is not disabled when TextInputGroupContext isDisabled is false', () => {
142
+ const view = mount(
143
+ <TextInputGroupContext.Provider value={{ isDisabled: false }}>
144
+ <TextInputGroupMain />
145
+ </TextInputGroupContext.Provider>
146
+ );
147
+ expect(view.find('input').props()['disabled']).toBe(false);
148
+ });
149
+
150
+ test('input is disabled when TextInputGroupContext isDisabled is true', () => {
151
+ const view = mount(
152
+ <TextInputGroupContext.Provider value={{ isDisabled: true }}>
153
+ <TextInputGroupMain />
154
+ </TextInputGroupContext.Provider>
155
+ );
156
+ expect(view.find('input').props()['disabled']).toBe(true);
157
+ });
70
158
  });
71
159
 
72
160
  describe('TextInputGroupUtilities', () => {
@@ -9,9 +9,7 @@ exports[`TextInputGroup gets custom class and id 1`] = `
9
9
  className="pf-c-text-input-group custom-class"
10
10
  id="test-id"
11
11
  >
12
- <TextInputGroupMain
13
- aria-label="Type to filter"
14
- >
12
+ <TextInputGroupMain>
15
13
  <div
16
14
  className="pf-c-text-input-group__main"
17
15
  >
@@ -22,6 +20,7 @@ exports[`TextInputGroup gets custom class and id 1`] = `
22
20
  <input
23
21
  aria-label="Type to filter"
24
22
  className="pf-c-text-input-group__text-input"
23
+ onChange={[Function]}
25
24
  type="text"
26
25
  />
27
26
  </span>
@@ -41,9 +40,7 @@ exports[`TextInputGroup renders content 1`] = `
41
40
  <div
42
41
  className="pf-c-text-input-group"
43
42
  >
44
- <TextInputGroupMain
45
- aria-label="Type to filter"
46
- >
43
+ <TextInputGroupMain>
47
44
  <div
48
45
  className="pf-c-text-input-group__main"
49
46
  >
@@ -54,6 +51,7 @@ exports[`TextInputGroup renders content 1`] = `
54
51
  <input
55
52
  aria-label="Type to filter"
56
53
  className="pf-c-text-input-group__text-input"
54
+ onChange={[Function]}
57
55
  type="text"
58
56
  />
59
57
  </span>
@@ -68,14 +66,14 @@ exports[`TextInputGroup renders content 1`] = `
68
66
  </TextInputGroup>
69
67
  `;
70
68
 
71
- exports[`TextInputGroup renders with the proper stying for an icon on the left side of the component 1`] = `
72
- <TextInputGroup>
69
+ exports[`TextInputGroup renders with the proper stying when disabled 1`] = `
70
+ <TextInputGroup
71
+ isDisabled={true}
72
+ >
73
73
  <div
74
- className="pf-c-text-input-group"
74
+ className="pf-c-text-input-group pf-m-disabled"
75
75
  >
76
- <TextInputGroupMain
77
- aria-label="Type to filter"
78
- >
76
+ <TextInputGroupMain>
79
77
  <div
80
78
  className="pf-c-text-input-group__main"
81
79
  >
@@ -86,6 +84,8 @@ exports[`TextInputGroup renders with the proper stying for an icon on the left s
86
84
  <input
87
85
  aria-label="Type to filter"
88
86
  className="pf-c-text-input-group__text-input"
87
+ disabled={true}
88
+ onChange={[Function]}
89
89
  type="text"
90
90
  />
91
91
  </span>
@@ -101,9 +101,7 @@ exports[`TextInputGroup renders with the proper stying for an icon on the left s
101
101
  `;
102
102
 
103
103
  exports[`TextInputGroupMain renders content 1`] = `
104
- <TextInputGroupMain
105
- aria-label="Type to filter"
106
- >
104
+ <TextInputGroupMain>
107
105
  <div
108
106
  className="pf-c-text-input-group__main"
109
107
  >
@@ -114,6 +112,8 @@ exports[`TextInputGroupMain renders content 1`] = `
114
112
  <input
115
113
  aria-label="Type to filter"
116
114
  className="pf-c-text-input-group__text-input"
115
+ disabled={false}
116
+ onChange={[Function]}
117
117
  type="text"
118
118
  />
119
119
  </span>
@@ -123,7 +123,6 @@ exports[`TextInputGroupMain renders content 1`] = `
123
123
 
124
124
  exports[`TextInputGroupMain renders given input icon props 1`] = `
125
125
  <TextInputGroupMain
126
- aria-label="Type to filter"
127
126
  icon={
128
127
  <SearchIcon
129
128
  color="currentColor"
@@ -170,6 +169,8 @@ exports[`TextInputGroupMain renders given input icon props 1`] = `
170
169
  <input
171
170
  aria-label="Type to filter"
172
171
  className="pf-c-text-input-group__text-input"
172
+ disabled={false}
173
+ onChange={[Function]}
173
174
  type="text"
174
175
  />
175
176
  </span>
@@ -191,6 +192,8 @@ exports[`TextInputGroupMain renders the input with custom aria label when given
191
192
  <input
192
193
  aria-label="Foo"
193
194
  className="pf-c-text-input-group__text-input"
195
+ disabled={false}
196
+ onChange={[Function]}
194
197
  type="text"
195
198
  />
196
199
  </span>
@@ -24,6 +24,19 @@ const BasicTextInputGroup = () => (
24
24
  );
25
25
  ```
26
26
 
27
+ ### Disabled
28
+
29
+ ```js
30
+ import React from 'react';
31
+ import { TextInputGroup, TextInputGroupMain } from '@patternfly/react-core';
32
+
33
+ const DisabledTextInputGroup = () => (
34
+ <TextInputGroup isDisabled>
35
+ <TextInputGroupMain value="Disabled" type="text" aria-label="Disabled text input group example input" />
36
+ </TextInputGroup>
37
+ );
38
+ ```
39
+
27
40
  ### Utilities and icon
28
41
 
29
42
  ```js