@patternfly/documentation-framework 6.0.0-alpha.99 → 6.0.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.
package/templates/mdx.js CHANGED
@@ -1,21 +1,37 @@
1
1
  import React from 'react';
2
- import { PageSection, Title, Tooltip, PageSectionVariants, Button, BackToTop, Flex, FlexItem, PageGroup, Page, Content, Label, Stack, StackItem } from '@patternfly/react-core';
2
+ import {
3
+ PageSection,
4
+ Title,
5
+ Tooltip,
6
+ PageSectionVariants,
7
+ Button,
8
+ BackToTop,
9
+ Flex,
10
+ FlexItem,
11
+ PageGroup,
12
+ Page,
13
+ Content,
14
+ Label,
15
+ Stack,
16
+ StackItem,
17
+ } from '@patternfly/react-core';
3
18
  import { css } from '@patternfly/react-styles';
4
19
  import ExternalLinkAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon';
5
20
  import { Router, useLocation } from '@reach/router';
6
- import { CSSVariables, PropsTable, TableOfContents, Link, AutoLinkHeader, InlineAlert } from '../components';
21
+ import {
22
+ CSSVariables,
23
+ PropsTable,
24
+ TableOfContents,
25
+ Link,
26
+ AutoLinkHeader,
27
+ InlineAlert,
28
+ } from '../components';
7
29
  import { capitalize, getTitle, slugger, trackEvent } from '../helpers';
8
30
  import './mdx.css';
9
31
  import { convertToReactComponent } from '@patternfly/ast-helpers';
10
32
  import { FunctionsTable } from '../components/functionsTable/functionsTable';
11
33
 
12
- const MDXChildTemplate = ({
13
- Component,
14
- source,
15
- toc = [],
16
- index = 0,
17
- id
18
- }) => {
34
+ const MDXChildTemplate = ({ Component, source, toc = [], index = 0, id }) => {
19
35
  const {
20
36
  propComponents = [],
21
37
  sourceLink,
@@ -25,60 +41,107 @@ const MDXChildTemplate = ({
25
41
  deprecated,
26
42
  template,
27
43
  newImplementationLink,
28
- functionDocumentation = []
44
+ functionDocumentation = [],
29
45
  } = Component.getPageData();
30
46
  const cssVarsTitle = cssPrefix.length > 0 && 'CSS variables';
31
47
  const propsTitle = propComponents.length > 0 && 'Props';
32
- if (propsTitle && !toc.find(item => item.text === propsTitle)) {
48
+ if (propsTitle && !toc.find((item) => item.text === propsTitle)) {
33
49
  toc.push({ text: propsTitle });
34
- toc.push(propComponents.map(propComponent => ({ text: propComponent.name })));
50
+ toc.push(
51
+ propComponents.map((propComponent) => ({ text: propComponent.name }))
52
+ );
35
53
  }
36
- if (cssVarsTitle && !toc.find(item => item.text === cssVarsTitle)) {
54
+ if (cssVarsTitle && !toc.find((item) => item.text === cssVarsTitle)) {
37
55
  toc.push({ text: cssVarsTitle });
38
56
  if (cssPrefix.length > 1) {
39
- toc.push(cssPrefix.map(cssPrefix => ({ text: `Prefixed with '${cssPrefix}'` })));
57
+ toc.push(
58
+ cssPrefix.map((cssPrefix) => ({ text: `Prefixed with '${cssPrefix}'` }))
59
+ );
40
60
  }
41
61
  }
42
62
  // We don't add `id`s in anchor-header.js for items where id === slugger(text)
43
63
  // in order to save ~10KB bandwidth.
44
64
  if (toc.length > 1) {
45
- const ensureID = tocItem => {
65
+ const ensureID = (tocItem) => {
46
66
  if (Array.isArray(tocItem)) {
47
67
  tocItem.forEach(ensureID);
68
+ } else if (!tocItem.id) {
69
+ tocItem.id = slugger(tocItem.text);
48
70
  }
49
- else if (!tocItem.id) {
50
- tocItem.id = slugger(tocItem.text)
51
- }
52
- }
71
+ };
53
72
  ensureID(toc);
54
73
  }
55
74
 
56
- const isComponentCodeDocs = ['react', 'react-demos', 'html', 'html-demos', 'react-templates'].includes(source);
75
+ const isComponentCodeDocs = [
76
+ 'react',
77
+ 'react-demos',
78
+ 'html',
79
+ 'html-demos',
80
+ 'react-templates',
81
+ ].includes(source);
57
82
 
58
- const InlineAlerts = (optIn || beta || deprecated || source === 'react-deprecated' || source === 'html-deprecated' || template || source === 'react-template') && (
83
+ const InlineAlerts = (optIn ||
84
+ beta ||
85
+ deprecated ||
86
+ source === 'react-deprecated' ||
87
+ source === 'html-deprecated' ||
88
+ // TODO: remove hardcoded Tile when Core PR merges
89
+ // https://github.com/patternfly/patternfly/pull/7178
90
+ id === 'Tile' ||
91
+ template ||
92
+ source === 'react-template') && (
59
93
  <StackItem>
60
- {optIn && (
61
- <InlineAlert title="Opt-in feature">
62
- {optIn}
63
- </InlineAlert>
64
- )}
94
+ {optIn && <InlineAlert title="Opt-in feature">{optIn}</InlineAlert>}
65
95
  {beta && (
66
96
  <InlineAlert title="Beta feature">
67
- This beta component is currently under review and is still open for further evolution. It is available for use in product. Beta components are considered for promotion on a quarterly basis. Please join in and give us your feedback or submit any questions on the <a href="https://forum.patternfly.org/">PatternFly forum</a> or via <a href="//slack.patternfly.org/" target="_blank" rel="noopener noreferrer">Slack</a>. To learn more about the process, visit our <Link to="/get-started/about-patternfly#beta-components">about page</Link> or our <a href="https://github.com/patternfly/patternfly-org/tree/main/beta-component-promotion">Beta components</a> page on GitHub.
97
+ This beta component is currently under review and is still open for
98
+ further evolution. It is available for use in product. Beta components
99
+ are considered for promotion on a quarterly basis. Please join in and
100
+ give us your feedback or submit any questions on the{' '}
101
+ <a href="https://forum.patternfly.org/">PatternFly forum</a> or via{' '}
102
+ <a
103
+ href="//slack.patternfly.org/"
104
+ target="_blank"
105
+ rel="noopener noreferrer"
106
+ >
107
+ Slack
108
+ </a>
109
+ . To learn more about the process, visit our{' '}
110
+ <Link to="/get-started/about-patternfly#beta-components">
111
+ about page
112
+ </Link>{' '}
113
+ or our{' '}
114
+ <a href="https://github.com/patternfly/patternfly-org/tree/main/beta-component-promotion">
115
+ Beta components
116
+ </a>{' '}
117
+ page on GitHub.
68
118
  </InlineAlert>
69
119
  )}
70
- {(deprecated || source === 'react-deprecated' || source === 'html-deprecated') && (
120
+ {(deprecated ||
121
+ source === 'react-deprecated' ||
122
+ source === 'html-deprecated' ||
123
+ // TODO: remove hardcoded Tile when Core PR merges
124
+ // https://github.com/patternfly/patternfly/pull/7178
125
+ id === 'Tile') && (
71
126
  <InlineAlert title="Deprecated feature" variant="warning">
72
- This component implementation has been deprecated in favor of a newer solution, and is no longer being maintained or enhanced.
127
+ This component implementation has been deprecated in favor of a newer
128
+ solution, and is no longer being maintained or enhanced.
73
129
  {newImplementationLink && (
74
130
  <React.Fragment>
75
- You can find the <Link to={newImplementationLink}>updated implementation here</Link>.
131
+ You can find the{' '}
132
+ <Link to={newImplementationLink}>
133
+ updated implementation here
134
+ </Link>
135
+ .
76
136
  </React.Fragment>
77
- )}
78
- {' '}To learn more about deprecated components, visit <Link to="/get-started/about-patternfly#deprecated-components">about PatternFly.</Link>
137
+ )}{' '}
138
+ To learn more about deprecated components, visit{' '}
139
+ <Link to="/get-started/about-patternfly#deprecated-components">
140
+ about PatternFly.
141
+ </Link>
79
142
  </InlineAlert>
80
143
  )}
81
- {(template || source === 'react-template') && (
144
+ {(template || source === 'react-template') && (
82
145
  <InlineAlert title="Templates" variant="info">
83
146
  {`This page showcases templates for the ${id.toLowerCase()} component. A template combines a component with logic that supports a specific use case, with a streamlined API that offers additional, limited customization.`}
84
147
  </InlineAlert>
@@ -88,107 +151,164 @@ const MDXChildTemplate = ({
88
151
  // Create dynamic component for @reach/router
89
152
  const ChildComponent = () => (
90
153
  <div className={source !== 'landing-pages' ? 'pf-v6-l-flex' : ''}>
91
- {toc.length > 1 && (
92
- <TableOfContents items={toc} />
93
- )}
94
- <Stack hasGutter style={{...(source !== 'landing-pages' && {maxWidth: "825px"})}}>
154
+ {toc.length > 1 && <TableOfContents items={toc} />}
155
+ <Stack
156
+ hasGutter
157
+ style={{ ...(source !== 'landing-pages' && { maxWidth: '825px' }) }}
158
+ >
95
159
  {InlineAlerts}
96
- <Component />
97
- {functionDocumentation.length > 0 && (
98
- <StackItem>
99
- <AutoLinkHeader headingLevel="h2" className="pf-v6-c-content--h2" id="functions">
100
- Functions
101
- </AutoLinkHeader>
102
- <FunctionsTable functionDescriptions={functionDocumentation}/>
103
- </StackItem>
104
- )}
105
- {propsTitle && (
106
- <StackItem>
107
- <AutoLinkHeader headingLevel="h2" className="pf-v6-c-content--h2" id="props">
108
- {propsTitle}
109
- </AutoLinkHeader>
110
- {propComponents.map(component => (
111
- <PropsTable
112
- key={component.name}
113
- title={component.name}
114
- description={component.description}
115
- rows={component.props}
116
- allPropComponents={propComponents}
117
- />
118
- ))}
119
- </StackItem>
120
- )}
121
- {cssPrefix.length > 0 && (
122
- <StackItem>
123
- <AutoLinkHeader headingLevel="h2" className="pf-v6-c-content--h2" id="css-variables">
124
- {cssVarsTitle}
125
- </AutoLinkHeader>
126
- {cssPrefix.map((prefix, index) => (
127
- <CSSVariables key={index} autoLinkHeader={cssPrefix.length > 1} prefix={prefix} />
128
- ))}
129
- </StackItem>
130
- )}
131
- {sourceLink && (
132
- <StackItem>
133
- <br />
134
- <a href={sourceLink} target="_blank" onClick={() => trackEvent('view_source_click', 'click_event', source.toUpperCase())}>View source on GitHub</a>
135
- </StackItem>
136
- )}
160
+ <Component />
161
+ {functionDocumentation.length > 0 && (
162
+ <StackItem>
163
+ <AutoLinkHeader
164
+ headingLevel="h2"
165
+ className="pf-v6-c-content--h2"
166
+ id="functions"
167
+ >
168
+ Functions
169
+ </AutoLinkHeader>
170
+ <FunctionsTable functionDescriptions={functionDocumentation} />
171
+ </StackItem>
172
+ )}
173
+ {propsTitle && (
174
+ <StackItem>
175
+ <AutoLinkHeader
176
+ headingLevel="h2"
177
+ className="pf-v6-c-content--h2"
178
+ id="props"
179
+ >
180
+ {propsTitle}
181
+ </AutoLinkHeader>
182
+ {propComponents.map((component) => (
183
+ <PropsTable
184
+ key={component.name}
185
+ title={component.name}
186
+ description={component.description}
187
+ rows={component.props}
188
+ allPropComponents={propComponents}
189
+ />
190
+ ))}
191
+ </StackItem>
192
+ )}
193
+ {cssPrefix.length > 0 && (
194
+ <StackItem>
195
+ <AutoLinkHeader
196
+ headingLevel="h2"
197
+ className="pf-v6-c-content--h2"
198
+ id="css-variables"
199
+ >
200
+ {cssVarsTitle}
201
+ </AutoLinkHeader>
202
+ {cssPrefix.map((prefix, index) => (
203
+ <CSSVariables
204
+ key={index}
205
+ autoLinkHeader={cssPrefix.length > 1}
206
+ prefix={prefix}
207
+ />
208
+ ))}
209
+ </StackItem>
210
+ )}
211
+ {sourceLink && (
212
+ <StackItem>
213
+ <br />
214
+ <a
215
+ href={sourceLink}
216
+ target="_blank"
217
+ onClick={() =>
218
+ trackEvent(
219
+ 'view_source_click',
220
+ 'click_event',
221
+ source.toUpperCase()
222
+ )
223
+ }
224
+ >
225
+ View source on GitHub
226
+ </a>
227
+ </StackItem>
228
+ )}
137
229
  </Stack>
138
230
  </div>
139
231
  );
140
232
  ChildComponent.displayName = `MDXChildTemplate${Component.displayName}`;
141
233
  return <ChildComponent key={source} path={source} default={index === 0} />;
142
- }
234
+ };
143
235
 
144
236
  export const MDXTemplate = ({
145
237
  title,
146
238
  sources = [],
147
239
  path,
148
240
  id,
149
- componentsData
241
+ componentsData,
150
242
  }) => {
151
- const isDeprecated = sources.some(source => source.source === "react-deprecated" || source.source === "html-deprecated") && !sources.some(source => source.source === "react" || source.source === "html");
152
- const isBeta = sources.some(source => source.beta && source.source !== 'react-next' && source.source !== 'react-templates');
153
- const isDemo = sources.some(source => source.source === "react-demos" || source.source === "html-demos") && !sources.some(source => source.source === "react" || source.source === "html");
243
+ const isDeprecated =
244
+ sources.some(
245
+ (source) =>
246
+ source.source === 'react-deprecated' ||
247
+ source.source === 'html-deprecated'
248
+ ) &&
249
+ !sources.some(
250
+ (source) => source.source === 'react' || source.source === 'html'
251
+ );
252
+ const isBeta = sources.some(
253
+ (source) =>
254
+ source.beta &&
255
+ source.source !== 'react-next' &&
256
+ source.source !== 'react-templates'
257
+ );
258
+ const isDemo =
259
+ sources.some(
260
+ (source) =>
261
+ source.source === 'react-demos' || source.source === 'html-demos'
262
+ ) &&
263
+ !sources.some(
264
+ (source) => source.source === 'react' || source.source === 'html'
265
+ );
154
266
  // Build obj mapping source names to text displayed on tabs
155
267
  const tabNames = sources.reduce((acc, curSrc) => {
156
268
  const { source, tabName } = curSrc;
157
269
  // use tabName for tab name if present, otherwise default to source
158
- const tabLinkText = tabName || capitalize(source.replace('html', 'HTML').replace(/-/g, ' '));
270
+ const tabLinkText =
271
+ tabName || capitalize(source.replace('html', 'HTML').replace(/-/g, ' '));
159
272
  acc[source] = tabLinkText;
160
273
  return acc;
161
274
  }, {});
162
275
  const sourceKeys = Object.keys(tabNames);
163
276
  const isSinglePage = sourceKeys.length === 1;
164
277
 
165
- let isDevResources, isComponent, isExtension, isChart, isPattern, isLayout, isUtility, isUpgrade;
278
+ let isDevResources,
279
+ isComponent,
280
+ isExtension,
281
+ isChart,
282
+ isPattern,
283
+ isLayout,
284
+ isUtility,
285
+ isUpgrade;
166
286
 
167
287
  const getSection = () => {
168
288
  return sources.some((source) => {
169
289
  switch (source.section) {
170
- case "developer-resources":
290
+ case 'developer-resources':
171
291
  isDevResources = true;
172
292
  return;
173
- case "components":
293
+ case 'components':
174
294
  isComponent = true;
175
295
  return;
176
- case "extensions":
296
+ case 'extensions':
177
297
  isExtension = true;
178
298
  return;
179
- case "charts":
299
+ case 'charts':
180
300
  isChart = true;
181
301
  return;
182
- case "patterns":
302
+ case 'patterns':
183
303
  isPattern = true;
184
304
  return;
185
- case "layouts":
305
+ case 'layouts':
186
306
  isLayout = true;
187
307
  return;
188
- case "utilities":
308
+ case 'utilities':
189
309
  isUtility = true;
190
310
  return;
191
- case "get-started":
311
+ case 'get-started':
192
312
  if (source.source.includes('upgrade')) {
193
313
  isUpgrade = true;
194
314
  }
@@ -199,7 +319,7 @@ export const MDXTemplate = ({
199
319
 
200
320
  // hide tab if it doesn't include the strings below
201
321
  const hideTabName = sourceKeys.some(
202
- (e) => e.includes("pages") || e.includes("training")
322
+ (e) => e.includes('pages') || e.includes('training')
203
323
  );
204
324
  const { pathname } = useLocation();
205
325
  let activeSource = pathname.replace(/\/$/, '').split('/').pop();
@@ -225,34 +345,30 @@ export const MDXTemplate = ({
225
345
  getSection();
226
346
  if (isChart || isDevResources || isExtension) {
227
347
  if (isSinglePage) {
228
- return "pf-m-light-100";
348
+ return 'pf-m-light-100';
229
349
  }
230
- return "pf-m-light";
350
+ return 'pf-m-light';
231
351
  } else if (isUtility || isPattern || isLayout || isComponent || isUpgrade) {
232
- return "pf-m-light";
352
+ return 'pf-m-light';
233
353
  }
234
- return "pf-m-light-100";
354
+ return 'pf-m-light-100';
235
355
  };
236
356
 
237
- const showTabs = (
238
- (!isSinglePage && !hideTabName) ||
239
- isComponent ||
240
- isUtility ||
241
- isPattern
242
- );
357
+ const showTabs =
358
+ (!isSinglePage && !hideTabName) || isComponent || isUtility || isPattern;
243
359
 
244
360
  return (
245
361
  <React.Fragment>
246
362
  <PageGroup>
247
363
  <PageSection
248
364
  className={getClassName()}
249
- variant={!isSinglePage ? PageSectionVariants.light : ""}
365
+ variant={!isSinglePage ? PageSectionVariants.light : ''}
250
366
  isWidthLimited
251
367
  >
252
- <Content>
253
- <Flex alignItems={{ default: 'alignItemsCenter'}}>
368
+ <Content isEditorial>
369
+ <Flex alignItems={{ default: 'alignItemsCenter' }}>
254
370
  <FlexItem>
255
- <Title headingLevel='h1' size='4xl' id="ws-page-title">
371
+ <Title headingLevel="h1" size="4xl" id="ws-page-title">
256
372
  {title}
257
373
  </Title>
258
374
  </FlexItem>
@@ -288,11 +404,15 @@ export const MDXTemplate = ({
288
404
  </Flex>
289
405
  </FlexItem>
290
406
  </Flex>
291
- {isComponent && summary && (<SummaryComponent />)}
407
+ {isComponent && summary && <SummaryComponent />}
292
408
  </Content>
293
409
  </PageSection>
294
- { showTabs && (
295
- <PageSection id="ws-sticky-nav-tabs" stickyOnBreakpoint={{'default':'top'}} type="tabs">
410
+ {showTabs && (
411
+ <PageSection
412
+ id="ws-sticky-nav-tabs"
413
+ stickyOnBreakpoint={{ default: 'top' }}
414
+ type="tabs"
415
+ >
296
416
  <div className="pf-v6-c-tabs pf-m-page-insets pf-m-no-border-bottom">
297
417
  <ul className="pf-v6-c-tabs__list">
298
418
  {sourceKeys.map((source, index) => (
@@ -303,9 +423,18 @@ export const MDXTemplate = ({
303
423
  activeSource === source && 'pf-m-current'
304
424
  )}
305
425
  // Send clicked tab name for analytics
306
- onClick={() => trackEvent('tab_click', 'click_event', source.toUpperCase())}
426
+ onClick={() =>
427
+ trackEvent(
428
+ 'tab_click',
429
+ 'click_event',
430
+ source.toUpperCase()
431
+ )
432
+ }
307
433
  >
308
- <Link className="pf-v6-c-tabs__link" to={`${path}${index === 0 ? '' : '/' + source}`}>
434
+ <Link
435
+ className="pf-v6-c-tabs__link"
436
+ to={`${path}${index === 0 ? '' : '/' + source}`}
437
+ >
309
438
  {tabNames[source]}
310
439
  </Link>
311
440
  </li>
@@ -315,7 +444,7 @@ export const MDXTemplate = ({
315
444
  </PageSection>
316
445
  )}
317
446
  <PageSection id="main-content" isFilled className="pf-m-light-100">
318
- {isSinglePage && <MDXChildTemplate {...sources[0]} id={id}/>}
447
+ {isSinglePage && <MDXChildTemplate {...sources[0]} id={id} />}
319
448
  {!isSinglePage && (
320
449
  <Router className="pf-v6-u-h-100" primary={false}>
321
450
  {sources
@@ -327,8 +456,11 @@ export const MDXTemplate = ({
327
456
  </Router>
328
457
  )}
329
458
  </PageSection>
330
- <BackToTop className="ws-back-to-top" scrollableSelector="#ws-page-main" />
459
+ <BackToTop
460
+ className="ws-back-to-top"
461
+ scrollableSelector="#ws-page-main"
462
+ />
331
463
  </PageGroup>
332
464
  </React.Fragment>
333
465
  );
334
- }
466
+ };