@patternfly/patternfly-doc-core 1.4.0 → 1.6.0

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 (75) hide show
  1. package/.astro/collections/examples.schema.json +40 -0
  2. package/.astro/content-modules.mjs +4 -1
  3. package/.astro/content.d.ts +20 -1
  4. package/.vscode/launch.json +31 -10
  5. package/astro.config.mjs +2 -2
  6. package/declarations.d.ts +2 -0
  7. package/dist/client/_astro/LiveExample.B7IM_dLQ.css +1 -0
  8. package/dist/client/_astro/LiveExample.Df-EUsee.js +40 -0
  9. package/dist/client/_astro/Navigation.CabjIYg4.js +1 -0
  10. package/dist/client/_astro/PageContext.D1pNBMhh.js +9 -0
  11. package/dist/client/_astro/PageSidebarBody.Y-7d6zQM.js +1 -0
  12. package/dist/client/_astro/PageToggle.CbfM9bJB.js +1 -0
  13. package/dist/client/_astro/PageToggleButton.CZ3xPbcc.js +1 -0
  14. package/dist/client/_astro/Toolbar.9-YSFh3P.js +1 -0
  15. package/dist/client/_astro/ToolbarContent.BXdFKbs9.js +1 -0
  16. package/dist/client/_astro/_page_.B8cBYNKa.css +1 -0
  17. package/dist/client/_astro/_page_.CtheD08_.css +1 -0
  18. package/dist/client/_astro/_tab_.DxJDkZPc.css +1 -0
  19. package/dist/client/_astro/_tab_.YrfmckTJ.css +1 -0
  20. package/dist/client/_astro/client.CTJTt880.js +1 -0
  21. package/dist/client/_astro/divider.DjbDHO_6.js +1 -0
  22. package/dist/client/_astro/index.Dhi-S4Ah.js +24 -0
  23. package/dist/client/_astro/index.Dkaqzkgy.js +9 -0
  24. package/dist/client/_astro/page.CDtWFZb5.js +1 -0
  25. package/dist/client/components/accordion/index.html +85 -0
  26. package/dist/client/design-foundations/typography/index.html +24 -22
  27. package/dist/client/design-foundations/usage-and-behavior/index.html +24 -22
  28. package/dist/client/get-started/contribute/index.html +24 -22
  29. package/dist/client/index.html +19 -17
  30. package/dist/server/_@astrojs-ssr-adapter.mjs +1 -1
  31. package/dist/server/chunks/{PropsTables_D_v4KAMn.mjs → PropsTables_IgCNCQTX.mjs} +147 -213
  32. package/dist/server/chunks/{_@astrojs-ssr-adapter_ByVMUK8O.mjs → _@astrojs-ssr-adapter_CbICuCdt.mjs} +2 -2
  33. package/dist/server/chunks/{_astro_assets_CLOMnm-3.mjs → _astro_assets_DaYumpRZ.mjs} +2 -2
  34. package/dist/server/chunks/_astro_data-layer-content_Ni7IDnLe.mjs +1 -0
  35. package/dist/server/chunks/{angle-down-icon_BNJvzYv-.mjs → angle-down-icon_C5YQ7k8s.mjs} +163 -213
  36. package/dist/server/chunks/astro/{server_D4f31GMD.mjs → server_Cl9jPh4p.mjs} +179 -89
  37. package/dist/server/chunks/{astro-designed-error-pages_CpHpbfhr.mjs → astro-designed-error-pages_BFveJFnQ.mjs} +1 -1
  38. package/dist/server/chunks/content-modules_BzUEG69n.mjs +1 -0
  39. package/dist/server/chunks/{sharp_BYpUyJGL.mjs → sharp_CbOL3WDk.mjs} +2 -2
  40. package/dist/server/entry.mjs +3 -3
  41. package/dist/server/{manifest_CBenwYiZ.mjs → manifest_DoNTQyvZ.mjs} +3 -3
  42. package/dist/server/pages/_image.astro.mjs +1 -1
  43. package/dist/server/renderers.mjs +63 -14
  44. package/package.json +5 -2
  45. package/src/components/Content.tsx +61 -0
  46. package/src/components/ExampleToolbar.tsx +296 -0
  47. package/src/components/LiveExample.astro +7 -0
  48. package/src/components/LiveExample.tsx +42 -0
  49. package/src/components/Masthead.astro +1 -1
  50. package/src/components/NavEntry.tsx +0 -2
  51. package/src/components/NavSection.tsx +3 -23
  52. package/src/components/Navigation.astro +52 -7
  53. package/src/components/Navigation.tsx +13 -43
  54. package/src/content.ts +2 -1
  55. package/src/pages/[section]/[page]/[...tab].astro +97 -39
  56. package/textContent/examples/Accordion/Accordion.mdx +45 -0
  57. package/textContent/examples/Accordion/AccordionBordered.tsx +141 -0
  58. package/textContent/examples/Accordion/AccordionDefinitionList.tsx +102 -0
  59. package/textContent/examples/Accordion/AccordionFixedWithMultipleExpandBehavior.tsx +128 -0
  60. package/textContent/examples/Accordion/AccordionSingleExpandBehavior.tsx +118 -0
  61. package/textContent/examples/Accordion/AccordionToggleIconAtStart.tsx +118 -0
  62. package/dist/client/_astro/Button.C3_jB5tC.js +0 -9
  63. package/dist/client/_astro/Navigation.75VF_8AW.js +0 -1
  64. package/dist/client/_astro/PageContext.C7BqCh9N.js +0 -1
  65. package/dist/client/_astro/PageToggle.DDEjruql.js +0 -1
  66. package/dist/client/_astro/Toolbar.TAdHxLSQ.js +0 -1
  67. package/dist/client/_astro/_page_.CXyz_BEo.css +0 -1
  68. package/dist/client/_astro/_page_.DVvr_Mfl.css +0 -1
  69. package/dist/client/_astro/_page_.SnUmZn2y.css +0 -1
  70. package/dist/client/_astro/client.CeeiqVaE.js +0 -1
  71. package/dist/client/_astro/divider.BSD-oFoh.js +0 -1
  72. package/dist/client/_astro/index.CTH3fVMn.js +0 -32
  73. package/dist/client/_astro/page.B65lVdBS.js +0 -1
  74. /package/dist/server/chunks/{_astro_data-layer-content_DDGBHvtb.mjs → Accordion_CGgMUho2.mjs} +0 -0
  75. /package/dist/server/chunks/{content-modules_Dz-S_Wwv.mjs → Accordion_DlM2LvlF.mjs} +0 -0
@@ -0,0 +1,61 @@
1
+ import { Content as PFContent } from '@patternfly/react-core'
2
+ import { ReactNode } from 'react'
3
+
4
+ export const h1 = ({ children }: { children: ReactNode }) => (
5
+ <PFContent component="h1">{children}</PFContent>
6
+ )
7
+ export const h2 = ({ children }: { children: ReactNode }) => (
8
+ <PFContent component="h2">{children}</PFContent>
9
+ )
10
+ export const h3 = ({ children }: { children: ReactNode }) => (
11
+ <PFContent component="h3">{children}</PFContent>
12
+ )
13
+ export const h4 = ({ children }: { children: ReactNode }) => (
14
+ <PFContent component="h4">{children}</PFContent>
15
+ )
16
+ export const h5 = ({ children }: { children: ReactNode }) => (
17
+ <PFContent component="h5">{children}</PFContent>
18
+ )
19
+ export const h6 = ({ children }: { children: ReactNode }) => (
20
+ <PFContent component="h6">{children}</PFContent>
21
+ )
22
+
23
+ export const p = ({ children }: { children: ReactNode }) => (
24
+ <PFContent component="p">{children}</PFContent>
25
+ )
26
+ export const a = ({ children }: { children: ReactNode }) => (
27
+ <PFContent component="a">{children}</PFContent>
28
+ )
29
+ export const small = ({ children }: { children: ReactNode }) => (
30
+ <PFContent component="small">{children}</PFContent>
31
+ )
32
+
33
+ export const blockquote = ({ children }: { children: ReactNode }) => (
34
+ <PFContent component="blockquote">{children}</PFContent>
35
+ )
36
+ export const pre = ({ children }: { children: ReactNode }) => (
37
+ <PFContent component="pre">{children}</PFContent>
38
+ )
39
+ export const hr = ({ children }: { children: ReactNode }) => (
40
+ <PFContent component="hr">{children}</PFContent>
41
+ )
42
+
43
+ export const ul = ({ children }: { children: ReactNode }) => (
44
+ <PFContent component="ul">{children}</PFContent>
45
+ )
46
+ export const ol = ({ children }: { children: ReactNode }) => (
47
+ <PFContent component="ol">{children}</PFContent>
48
+ )
49
+ export const dl = ({ children }: { children: ReactNode }) => (
50
+ <PFContent component="dl">{children}</PFContent>
51
+ )
52
+ export const li = ({ children }: { children: ReactNode }) => (
53
+ <PFContent component="li">{children}</PFContent>
54
+ )
55
+
56
+ export const dt = ({ children }: { children: ReactNode }) => (
57
+ <PFContent component="dt">{children}</PFContent>
58
+ )
59
+ export const dd = ({ children }: { children: ReactNode }) => (
60
+ <PFContent component="dd">{children}</PFContent>
61
+ )
@@ -0,0 +1,296 @@
1
+ // TODO remove this component it is not good and I don't like that I have to add it
2
+
3
+ import React from 'react'
4
+ import { Button, Form, Tooltip } from '@patternfly/react-core'
5
+ import {
6
+ CodeEditor,
7
+ CodeEditorControl,
8
+ Language,
9
+ } from '@patternfly/react-code-editor'
10
+ import { convertToJSX } from '@patternfly/ast-helpers'
11
+ import ExternalLinkAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon'
12
+ import CodepenIcon from '@patternfly/react-icons/dist/esm/icons/codepen-icon'
13
+ import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon'
14
+ import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon'
15
+ import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-double-right-icon'
16
+ import ReplyAllIcon from '@patternfly/react-icons/dist/esm/icons/reply-all-icon'
17
+
18
+ const copy = (textToCopy: string) => {
19
+ navigator.clipboard.writeText(textToCopy)
20
+ }
21
+
22
+ interface TrackEventValue {
23
+ event_category: string
24
+ event_label: string
25
+ value?: number
26
+ }
27
+
28
+ interface WindowWithGtag extends Window {
29
+ gtag?: (type: string, name: string, value: TrackEventValue) => void
30
+ }
31
+ const _window = window as WindowWithGtag
32
+ /**
33
+ * Sends network call using Google Analytic's gtag function
34
+ * https://developers.google.com/analytics/devguides/collection/gtagjs/events#send_events
35
+ *
36
+ * @param name {string} - The value that will appear as the event action in Google Analytics Event reports.
37
+ * @param eventCategory {string} - The category of the event.
38
+ * @param eventLabel {string} - The label of the event.
39
+ * @param [value] {number} - An optional non-negative integer that will appear as the event value.
40
+ */
41
+ const trackEvent = (
42
+ name: string,
43
+ eventCategory: string,
44
+ eventLabel: string,
45
+ value?: number,
46
+ ) => {
47
+ value ||= 0
48
+ if (_window?.gtag) {
49
+ _window?.gtag('event', name, {
50
+ // eslint-disable-next-line camelcase
51
+ event_category: eventCategory,
52
+ // eslint-disable-next-line camelcase
53
+ event_label: eventLabel,
54
+ // Optional non-negative integer
55
+ ...(value >= 0 && { value }),
56
+ })
57
+ }
58
+ }
59
+
60
+ function getLanguage(lang: string) {
61
+ if (lang === 'js') {
62
+ return Language.javascript
63
+ } else if (lang === 'ts') {
64
+ return Language.typescript
65
+ }
66
+
67
+ return lang as Language
68
+ }
69
+
70
+ interface ExampleToolbarProps {
71
+ fullscreenLink?: string
72
+ codeBoxParams?: any
73
+ lang: string
74
+ isFullscreen?: boolean
75
+ originalCode: string
76
+ code: string
77
+ setCode: (code: string) => void
78
+ exampleTitle?: string
79
+ }
80
+
81
+ export const ExampleToolbar = ({
82
+ // Link to fullscreen example page (each example has one)
83
+ fullscreenLink,
84
+ // Params to pass to codesandbox
85
+ codeBoxParams,
86
+ // Language of code
87
+ lang,
88
+ // Whether the example is fullscreen only
89
+ isFullscreen,
90
+ // Original version of the code
91
+ originalCode,
92
+ // Current code in editor
93
+ code,
94
+ // Callback to set code in parent component
95
+ setCode,
96
+ // Title of example used in creating unique labels
97
+ exampleTitle,
98
+ }: ExampleToolbarProps) => {
99
+ const [isEditorOpen, setIsEditorOpen] = React.useState(false)
100
+ const [isCopied, setCopied] = React.useState(false)
101
+
102
+ const copyLabel = 'Copy code to clipboard'
103
+ const languageLabel = `Toggle ${lang.toUpperCase()} code`
104
+ const codesandboxLabel = 'Open example in CodeSandbox'
105
+ const fullscreenLabel = 'Open example in new window'
106
+ const convertLabel = 'Convert example from Typescript to JavaScript'
107
+ const undoAllLabel = 'Undo all changes'
108
+
109
+ const copyAriaLabel = `Copy ${exampleTitle} example code to clipboard`
110
+ const languageAriaLabel = `Toggle ${lang.toUpperCase()} code in ${exampleTitle} example`
111
+ const codesandboxAriaLabel = `Open ${exampleTitle} example in CodeSandbox`
112
+ const fullscreenAriaLabel = `Open ${exampleTitle} example in new window`
113
+ const convertAriaLabel = `Convert ${exampleTitle} example from Typescript to JavaScript`
114
+ const undoAllAriaLabel = `Undo all changes to ${exampleTitle}`
115
+
116
+ const editorControlProps = {
117
+ className: 'ws-code-editor-control',
118
+ }
119
+
120
+ const commonTooltipProps = {
121
+ exitDelay: 300,
122
+ maxWidth: 'var(--ws-code-editor--tooltip--MaxWidth)',
123
+ }
124
+
125
+ const copyCode = () => {
126
+ copy(code)
127
+ setCopied(true)
128
+ }
129
+
130
+ const customControls = (
131
+ <React.Fragment>
132
+ <CodeEditorControl
133
+ icon={
134
+ <React.Fragment>
135
+ <CodeIcon />
136
+ {' ' + lang.toUpperCase()}
137
+ </React.Fragment>
138
+ }
139
+ onClick={() => {
140
+ setIsEditorOpen(!isEditorOpen)
141
+ // 1 === expand code, 0 === collapse code
142
+ trackEvent(
143
+ 'code_editor_control_click',
144
+ 'click_event',
145
+ 'TOGGLE_CODE',
146
+ isEditorOpen ? 0 : 1,
147
+ )
148
+ }}
149
+ tooltipProps={{
150
+ content: languageLabel,
151
+ ...commonTooltipProps,
152
+ }}
153
+ aria-label={languageAriaLabel}
154
+ aria-expanded={isEditorOpen}
155
+ {...editorControlProps}
156
+ />
157
+ <Tooltip
158
+ content={<div>{isCopied ? 'Code copied' : copyLabel}</div>}
159
+ maxWidth={(editorControlProps as any)?.maxWidth}
160
+ exitDelay={isCopied ? 300 : 1600}
161
+ onTooltipHidden={() => setCopied(false)}
162
+ >
163
+ <Button
164
+ onClick={() => {
165
+ copyCode()
166
+ trackEvent('code_editor_control_click', 'click_event', 'COPY_CODE')
167
+ }}
168
+ variant="plain"
169
+ aria-label={copyAriaLabel}
170
+ className={editorControlProps.className}
171
+ >
172
+ <CopyIcon />
173
+ </Button>
174
+ </Tooltip>
175
+ {codeBoxParams && (
176
+ <Form
177
+ aria-label={`${codesandboxAriaLabel} form`}
178
+ action="https://codesandbox.io/api/v1/sandboxes/define"
179
+ method="POST"
180
+ target="_blank"
181
+ style={{ display: 'inline-block' }}
182
+ >
183
+ <Tooltip
184
+ content={codesandboxLabel}
185
+ maxWidth={(editorControlProps as any).maxWidth}
186
+ >
187
+ <Button
188
+ aria-label={codesandboxAriaLabel}
189
+ variant="plain"
190
+ type="submit"
191
+ onClick={() => {
192
+ trackEvent(
193
+ 'code_editor_control_click',
194
+ 'click_event',
195
+ 'CODESANDBOX_LINK',
196
+ )
197
+ }}
198
+ className={editorControlProps.className}
199
+ >
200
+ <CodepenIcon />
201
+ </Button>
202
+ </Tooltip>
203
+ <input type="hidden" name="parameters" value={codeBoxParams} />
204
+ </Form>
205
+ )}
206
+ {fullscreenLink && (
207
+ <CodeEditorControl
208
+ component="a"
209
+ icon={<ExternalLinkAltIcon />}
210
+ href={fullscreenLink}
211
+ target="_blank"
212
+ rel="noopener noreferrer"
213
+ aria-label={fullscreenAriaLabel}
214
+ tooltipProps={{
215
+ content: fullscreenLabel,
216
+ ...commonTooltipProps,
217
+ }}
218
+ onClick={() => {
219
+ trackEvent(
220
+ 'code_editor_control_click',
221
+ 'click_event',
222
+ 'FULLSCREEN_LINK',
223
+ )
224
+ }}
225
+ {...editorControlProps}
226
+ />
227
+ )}
228
+ {isEditorOpen && lang === 'ts' && (
229
+ <CodeEditorControl
230
+ icon={
231
+ <React.Fragment>
232
+ {'TS '}
233
+ <AngleDoubleRightIcon />
234
+ {' JS'}
235
+ </React.Fragment>
236
+ }
237
+ aria-label={convertAriaLabel}
238
+ tooltipProps={{
239
+ content: convertLabel,
240
+ ...commonTooltipProps,
241
+ }}
242
+ onClick={() => {
243
+ setCode(convertToJSX(code).code)
244
+ trackEvent('code_editor_control_click', 'click_event', 'TS_TO_JS')
245
+ }}
246
+ {...editorControlProps}
247
+ />
248
+ )}
249
+ {code !== originalCode && (
250
+ <CodeEditorControl
251
+ icon={<ReplyAllIcon />}
252
+ aria-label={undoAllAriaLabel}
253
+ tooltipProps={{
254
+ content: undoAllLabel,
255
+ ...commonTooltipProps,
256
+ }}
257
+ onClick={() => {
258
+ setCode(originalCode)
259
+ trackEvent('code_editor_control_click', 'click_event', 'RESET_CODE')
260
+ }}
261
+ {...editorControlProps}
262
+ />
263
+ )}
264
+ </React.Fragment>
265
+ )
266
+
267
+ // TODO: check if worth adding react, patternfly, and example types
268
+ // https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.typescript.languageservicedefaults.html#addextralib
269
+ const onEditorDidMount = (_editor: any, monaco: any) => {
270
+ monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
271
+ jsx: true,
272
+ ...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(),
273
+ })
274
+ monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
275
+ noSemanticValidation: true,
276
+ noSyntaxValidation: true,
277
+ noSuggestionDiagnostics: true,
278
+ onlyVisible: true,
279
+ })
280
+ }
281
+
282
+ return (
283
+ <CodeEditor
284
+ customControls={customControls}
285
+ showEditor={isEditorOpen}
286
+ language={getLanguage(lang)}
287
+ height="400px"
288
+ code={code}
289
+ onChange={(newCode) => setCode(newCode)}
290
+ onEditorDidMount={onEditorDidMount}
291
+ isReadOnly={isFullscreen}
292
+ className={`${isEditorOpen ? 'ws-example-code-expanded ' : ''}ws-code-editor`}
293
+ isHeaderPlain
294
+ />
295
+ )
296
+ }
@@ -0,0 +1,7 @@
1
+ ---
2
+ import { LiveExample as LiveExampleBase } from './LiveExample'
3
+
4
+ const { src } = Astro.props
5
+ ---
6
+
7
+ <LiveExampleBase src={src} client:only="react" />
@@ -0,0 +1,42 @@
1
+ import React, { useState } from 'react'
2
+ import { convertToReactComponent } from '@patternfly/ast-helpers'
3
+ import * as reactCoreModule from '@patternfly/react-core'
4
+ import { ExampleToolbar } from './ExampleToolbar'
5
+ interface LiveExampleProps {
6
+ src: string
7
+ }
8
+
9
+ function getLivePreview(editorCode: string) {
10
+ const scope = { ...reactCoreModule, ...{ useState } }
11
+ const { code: transformedCode } = convertToReactComponent(editorCode)
12
+
13
+ const componentNames = Object.keys(scope)
14
+ const componentValues = Object.values(scope)
15
+
16
+ const getPreviewComponent = new Function(
17
+ 'React',
18
+ ...componentNames,
19
+ transformedCode,
20
+ )
21
+ const PreviewComponent = getPreviewComponent(React, ...componentValues)
22
+
23
+ return <PreviewComponent />
24
+ }
25
+
26
+ export const LiveExample = ({ src }: LiveExampleProps) => {
27
+ const [code, setCode] = useState(src)
28
+ const livePreview = getLivePreview(code)
29
+
30
+ return (
31
+ <>
32
+ {livePreview}
33
+ <ExampleToolbar
34
+ originalCode={src}
35
+ code={code}
36
+ setCode={setCode}
37
+ lang="ts"
38
+ isFullscreen={false}
39
+ />
40
+ </>
41
+ )
42
+ }
@@ -16,7 +16,7 @@ import { PageToggle } from './PageToggle'
16
16
  <PFMasthead>
17
17
  <MastheadMain>
18
18
  <MastheadToggle>
19
- <PageToggle client:idle />
19
+ <PageToggle client:idle transition:persist />
20
20
  </MastheadToggle>
21
21
  <MastheadBrand>
22
22
  <MastheadLogo component="a" href="/">
@@ -6,9 +6,7 @@ export interface TextContentEntry {
6
6
  data: {
7
7
  id: string
8
8
  section: string
9
- tab?: string
10
9
  }
11
- collection: string
12
10
  }
13
11
 
14
12
  interface NavEntryProps {
@@ -14,30 +14,10 @@ export const NavSection = ({
14
14
  sectionId,
15
15
  activeItem,
16
16
  }: NavSectionProps) => {
17
- const isExpanded = window.location.pathname.includes(sectionId)
17
+ const isExpanded = window.location.pathname.includes(kebabCase(sectionId))
18
+ const isActive = entries.some((entry) => entry.id === activeItem)
18
19
 
19
- const sortedNavEntries = entries.sort((a, b) =>
20
- a.data.id.localeCompare(b.data.id),
21
- )
22
-
23
- const isActive = sortedNavEntries.some((entry) => entry.id === activeItem)
24
-
25
- let navItems = sortedNavEntries
26
- if (sectionId === 'components' || sectionId === 'layouts') {
27
- // only display unique entry.data.id in the nav list if the section is components
28
- navItems = [
29
- ...sortedNavEntries
30
- .reduce((map, entry) => {
31
- if (!map.has(entry.data.id)) {
32
- map.set(entry.data.id, entry)
33
- }
34
- return map
35
- }, new Map())
36
- .values(),
37
- ]
38
- }
39
-
40
- const items = navItems.map((entry) => (
20
+ const items = entries.map((entry) => (
41
21
  <NavEntry
42
22
  key={entry.id}
43
23
  entry={entry}
@@ -2,6 +2,7 @@
2
2
  import { getCollection } from 'astro:content'
3
3
 
4
4
  import { Navigation as ReactNav } from './Navigation.tsx'
5
+ import { TextContentEntry } from './NavEntry.tsx'
5
6
 
6
7
  import { content } from '../content'
7
8
 
@@ -13,12 +14,56 @@ const collections = await Promise.all(
13
14
  ),
14
15
  )
15
16
 
16
- const navEntries = collections.flat()
17
+ const navDataRaw = collections.flat();
18
+ const uniqueSections = new Set(navDataRaw.map((entry) => entry.data.section));
19
+ const navData: Record<string, TextContentEntry[]> = {};
20
+
21
+ const [orderedSections, unorderedSections] = Array.from(uniqueSections).reduce(
22
+ (acc, section) => {
23
+ if (!config.navSectionOrder) {
24
+ acc[1].push(section)
25
+ return acc
26
+ }
27
+
28
+ const index = config.navSectionOrder.indexOf(section)
29
+ if (index > -1) {
30
+ acc[0][index] = section
31
+ } else {
32
+ acc[1].push(section)
33
+ }
34
+ return acc
35
+ },
36
+ [[], []] as [string[], string[]],
37
+ )
38
+
39
+ const sortedSections = [...orderedSections, ...unorderedSections.sort()]
40
+ sortedSections.map((section) => {
41
+ const entries = navDataRaw
42
+ .filter((entry) => entry.data.section === section)
43
+ .map(entry => ({ id: entry.id, data: { id: entry.data.id, section }} as TextContentEntry))
44
+
45
+ const sortedEntries = entries.sort((a, b) =>
46
+ a.data.id.localeCompare(b.data.id),
47
+ )
48
+
49
+ let navEntries = sortedEntries
50
+ if (section === 'components' || section === 'layouts') {
51
+ // only display unique entry.data.id in the nav list if the section is components
52
+ navEntries = [
53
+ ...sortedEntries
54
+ .reduce((map, entry) => {
55
+ if (!map.has(entry.data.id)) {
56
+ map.set(entry.data.id, entry)
57
+ }
58
+ return map
59
+ }, new Map())
60
+ .values(),
61
+ ]
62
+ }
63
+
64
+ navData[section] = navEntries;
65
+ })
66
+
17
67
  ---
18
68
 
19
- <ReactNav
20
- client:only="react"
21
- navEntries={navEntries}
22
- navSectionOrder={config.navSectionOrder}
23
- transition:animate="fade"
24
- />
69
+ <ReactNav client:only="react" navData={navData} transition:animate="fade" />
@@ -4,19 +4,17 @@ import { NavSection } from './NavSection'
4
4
  import { type TextContentEntry } from './NavEntry'
5
5
 
6
6
  interface NavigationProps {
7
- navEntries: TextContentEntry[]
8
- navSectionOrder?: string[]
7
+ navData: Record<string, TextContentEntry[]>
9
8
  }
10
9
 
11
10
  export const Navigation: React.FunctionComponent<NavigationProps> = ({
12
- navEntries,
13
- navSectionOrder,
11
+ navData,
14
12
  }: NavigationProps) => {
15
13
  const [activeItem, setActiveItem] = useState('')
16
14
 
17
15
  useEffect(() => {
18
16
  // TODO: Needs an alternate solution because of /tab in the path
19
- setActiveItem(window.location.pathname.split('/').reverse()[0])
17
+ setActiveItem(window.location.pathname.split('/').reverse()[0])
20
18
  }, [])
21
19
 
22
20
  const onNavSelect = (
@@ -26,48 +24,20 @@ export const Navigation: React.FunctionComponent<NavigationProps> = ({
26
24
  setActiveItem(selectedItem.itemId.toString())
27
25
  }
28
26
 
29
- const uniqueSections = Array.from(
30
- new Set(navEntries.map((entry) => entry.data.section)),
31
- )
32
-
33
- // We want to list any ordered sections first, followed by any unordered sections sorted alphabetically
34
- const [orderedSections, unorderedSections] = uniqueSections.reduce(
35
- (acc, section) => {
36
- if (!navSectionOrder) {
37
- acc[1].push(section)
38
- return acc
39
- }
40
-
41
- const index = navSectionOrder.indexOf(section)
42
- if (index > -1) {
43
- acc[0][index] = section
44
- } else {
45
- acc[1].push(section)
46
- }
47
- return acc
48
- },
49
- [[], []] as [string[], string[]],
50
- )
51
- const sortedSections = [...orderedSections, ...unorderedSections.sort()]
52
-
53
- const navSections = sortedSections.map((section) => {
54
- const entries = navEntries.filter((entry) => entry.data.section === section)
55
-
56
- return (
57
- <NavSection
58
- key={section}
59
- entries={entries}
60
- sectionId={section}
61
- activeItem={activeItem}
62
- />
63
- )
64
- })
65
-
66
27
  return (
67
28
  // Can possibly add back PageSidebar wrapper when https://github.com/patternfly/patternfly/issues/7377 goes in
68
29
  <PageSidebarBody id="page-sidebar-body">
69
30
  <Nav onSelect={onNavSelect}>
70
- <NavList>{navSections}</NavList>
31
+ <NavList>
32
+ {Object.entries(navData).map(([key, value], index) => (
33
+ <NavSection
34
+ key={index}
35
+ entries={value}
36
+ sectionId={key}
37
+ activeItem={activeItem}
38
+ />
39
+ ))}
40
+ </NavList>
71
41
  </Nav>
72
42
  </PageSidebarBody>
73
43
  )
package/src/content.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export const content = [
2
- { base: 'textContent', pattern: '*.md', name: "textContent" }
2
+ { base: 'textContent', pattern: '*.{md,mdx}', name: 'textContent' },
3
+ { base: 'textContent', pattern: 'examples/*/*.mdx', name: 'examples' },
3
4
  // TODO: Remove. Uncomment for local testing.
4
5
  // {
5
6
  // "packageName":"@patternfly/react-core",