@patternfly/react-core 4.276.4 → 4.276.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.276.4",
3
+ "version": "4.276.5",
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",
@@ -71,5 +71,5 @@
71
71
  "react": "^16.8 || ^17 || ^18",
72
72
  "react-dom": "^16.8 || ^17 || ^18"
73
73
  },
74
- "gitHead": "b914e4945c21e022ab38a900fce7fa7652e0c03d"
74
+ "gitHead": "df6e176375bb8f52dc9b1ef06909e6a7f85d1923"
75
75
  }
@@ -57,8 +57,10 @@ export interface AlertProps extends Omit<React.HTMLProps<HTMLDivElement>, 'actio
57
57
  timeoutAnimation?: number;
58
58
  /** Title of the alert. */
59
59
  title: React.ReactNode;
60
- /** Sets the heading level to use for the alert title. Default is h4. */
60
+ /** @deprecated Sets the heading level to use for the alert title. Default is h4. */
61
61
  titleHeadingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
62
+ /** Sets the element to use as the alert title. Default is h4. */
63
+ component?: keyof JSX.IntrinsicElements;
62
64
  /** Adds accessible text to the alert toggle. */
63
65
  toggleAriaLabel?: string;
64
66
  /** Position of the tooltip which is displayed if text is truncated. */
@@ -99,7 +101,8 @@ export const Alert: React.FunctionComponent<AlertProps> = ({
99
101
  actionClose,
100
102
  actionLinks,
101
103
  title,
102
- titleHeadingLevel: TitleHeadingLevel = 'h4',
104
+ titleHeadingLevel,
105
+ component = 'h4',
103
106
  children = '',
104
107
  className = '',
105
108
  ouiaId,
@@ -126,6 +129,14 @@ export const Alert: React.FunctionComponent<AlertProps> = ({
126
129
  );
127
130
 
128
131
  const titleRef = React.useRef(null);
132
+ const TitleComponent = (titleHeadingLevel || component) as any;
133
+ if (titleHeadingLevel !== undefined) {
134
+ // eslint-disable-next-line no-console
135
+ console.warn(
136
+ 'Alert: titleHeadingLevel is deprecated, please use the newer component prop instead to set the alert title element.'
137
+ );
138
+ }
139
+
129
140
  const divRef = React.useRef<HTMLDivElement>();
130
141
  const [isTooltipVisible, setIsTooltipVisible] = useState(false);
131
142
  React.useEffect(() => {
@@ -145,12 +156,12 @@ export const Alert: React.FunctionComponent<AlertProps> = ({
145
156
  const [containsFocus, setContainsFocus] = useState<boolean | undefined>();
146
157
  const dismissed = timedOut && timedOutAnimation && !isMouseOver && !containsFocus;
147
158
  React.useEffect(() => {
148
- timeout = timeout === true ? 8000 : Number(timeout);
149
- if (timeout > 0) {
150
- const timer = setTimeout(() => setTimedOut(true), timeout);
159
+ const calculatedTimeout = timeout === true ? 8000 : Number(timeout);
160
+ if (calculatedTimeout > 0) {
161
+ const timer = setTimeout(() => setTimedOut(true), calculatedTimeout);
151
162
  return () => clearTimeout(timer);
152
163
  }
153
- }, []);
164
+ }, [timeout]);
154
165
  React.useEffect(() => {
155
166
  const onDocumentFocus = () => {
156
167
  if (divRef.current) {
@@ -172,10 +183,10 @@ export const Alert: React.FunctionComponent<AlertProps> = ({
172
183
  const timer = setTimeout(() => setTimedOutAnimation(true), timeoutAnimation);
173
184
  return () => clearTimeout(timer);
174
185
  }
175
- }, [containsFocus, isMouseOver]);
186
+ }, [containsFocus, isMouseOver, timeoutAnimation]);
176
187
  React.useEffect(() => {
177
188
  dismissed && onTimeout();
178
- }, [dismissed]);
189
+ }, [dismissed, onTimeout]);
179
190
 
180
191
  const [isExpanded, setIsExpanded] = useState(false);
181
192
  const onToggleExpand = () => {
@@ -197,13 +208,13 @@ export const Alert: React.FunctionComponent<AlertProps> = ({
197
208
  return null;
198
209
  }
199
210
  const Title = (
200
- <TitleHeadingLevel
211
+ <TitleComponent
201
212
  {...(isTooltipVisible && { tabIndex: 0 })}
202
213
  ref={titleRef}
203
214
  className={css(styles.alertTitle, truncateTitle && styles.modifiers.truncate)}
204
215
  >
205
216
  {getHeadingContent}
206
- </TitleHeadingLevel>
217
+ </TitleComponent>
207
218
  );
208
219
 
209
220
  return (
@@ -50,8 +50,9 @@ PatternFly supports several properties and variations that can be used to add ex
50
50
 
51
51
  * As demonstrated in the 3rd and 4th variations below, use the `actionClose` property to add an `<AlertActionCloseButton>` component, which can be used to manage and customize alert dismissals. `actionClose` can be used with or without the presence of `actionLinks`.
52
52
 
53
- * As demonstrated in the 5th and 6th variations below, use the `titleHeadingLevel` property to set the heading level of an alert title. Headings should be ordered by their level and heading levels should not be skipped. For example, a heading of an `h2` level should not be followed directly by an `h4`.
54
-
53
+ * As demonstrated in the 5th and 6th variations below, use the `component` property to set the element for an alert title.
54
+ * If the `description` prop is not passed in, then the `component` prop should be set to a non-heading element such as a `span` or `div`.
55
+ * If the `description` prop is passed in, then the `component` prop should be a heading element. Headings should be ordered by their level and heading levels should not be skipped. For example, a heading of an `h2` level should not be followed directly by an `h4`.
55
56
  ```ts
56
57
  import React from 'react';
57
58
  import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core';
@@ -88,8 +89,10 @@ import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/reac
88
89
  }
89
90
  />
90
91
  <Alert variant="success" title="Success alert title" actionClose={<AlertActionCloseButton onClose={() => alert('Clicked the close button')} />} />
91
- <Alert variant="success" title="h1 Success alert title" titleHeadingLevel="h1" />
92
- <Alert variant="success" title="h6 Success alert title" titleHeadingLevel="h6" />
92
+ <Alert variant="success" title="div success alert title" component="div" />
93
+ <Alert variant="success" title="h6 Success alert title" component="h6" >
94
+ <p>Short alert description</p>
95
+ </Alert>
93
96
  </React.Fragment>
94
97
  ```
95
98
  ### Alert timeout