Skip to content

Commit c3e64f9

Browse files
committed
fixing interactive content
1 parent 68ec4a8 commit c3e64f9

File tree

6 files changed

+507
-873
lines changed

6 files changed

+507
-873
lines changed

src/components/section-gallery/SectionGallery.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface SectionGalleryItemData {
2020
/** Path to the item illustration */ // TODO: remove if img method is fine
2121
illustration: string
2222
/** Summary text of the item */
23-
summary: JSX.Element
23+
summary: string
2424
/** Label included in the item footer. Choose from a preset or pass a custom label. */
2525
label?: 'beta' | 'demo' | 'deprecated'
2626
/** Link to the item, relative to the section, e.g. "/{section}/{page}" */
@@ -73,6 +73,7 @@ export const SectionGallery = ({
7373
}))
7474
.sort((item1, item2) => item1.name.localeCompare(item2.name))
7575

76+
console.log(galleryItems)
7677
const nonCharsRegex = /[^A-Z0-9]+/gi
7778
const filteringTerm = searchTerm.replace(nonCharsRegex, '')
7879
const filteredItems: SectionGalleryItem[] = galleryItems.filter((item) =>

src/components/section-gallery/SectionGalleryGridLayout.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react'
12
import {
23
Gallery,
34
GalleryItem,
@@ -11,6 +12,7 @@ import {
1112
} from '@patternfly/react-core'
1213
import { SectionGalleryItem } from './SectionGallery'
1314
import { sentenceCase } from 'change-case'
15+
import { convertToReactComponent } from '@patternfly/ast-helpers'
1416

1517
interface SectionGalleryGridLayoutProps {
1618
/** Section where the gallery is located */
@@ -33,6 +35,15 @@ export const SectionGalleryGridLayout = ({
3335
{galleryItems.map(({ name, img, data }, idx) => {
3436
const itemLink = data.link || `/${section}/${name}`
3537

38+
//TODO: rethink how JSX / enriched content is passed to framework
39+
const summaryNoLinks = data.summary.replace(
40+
/<a[^>]*>([^<]+)<\/a>/gm,
41+
'$1',
42+
)
43+
const { code } = convertToReactComponent(`<>${summaryNoLinks}</>`)
44+
const getSummaryComponent = new Function('React', code)
45+
46+
console.log(img)
3647
return (
3748
<GalleryItem span={4} key={idx}>
3849
<Card id={name} key={idx} isClickable>
@@ -48,12 +59,14 @@ export const SectionGalleryGridLayout = ({
4859
</CardHeader>
4960
{(hasGridImages || hasGridText) && (
5061
<CardBody>
51-
{hasGridImages && data.illustration && (
62+
{hasGridImages && img && (
5263
<img src={img.src} alt={`${name} illustration`} /> // verify whether this img.src approach is correct
5364
)}
5465
{hasGridText && (
5566
<Content isEditorial>
56-
<Content component="p">{data.summary}</Content>
67+
<Content component="p">
68+
{getSummaryComponent(React)}
69+
</Content>
5770
</Content>
5871
)}
5972
</CardBody>

src/components/section-gallery/SectionGalleryListLayout.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react'
12
import {
23
DataList,
34
DataListItem,
@@ -12,6 +13,7 @@ import {
1213
} from '@patternfly/react-core'
1314
import { SectionGalleryItem } from './SectionGallery'
1415
import { sentenceCase } from 'change-case'
16+
import { convertToReactComponent } from '@patternfly/ast-helpers'
1517

1618
interface SectionGalleryListLayoutProps {
1719
/** Section where the gallery is located */
@@ -34,6 +36,14 @@ export const SectionGalleryListLayout = ({
3436
{galleryItems.map(({ name, img, data }, idx) => {
3537
const itemLink = data.link || `/${section}/${name}`
3638

39+
//TODO: rethink how JSX / enriched content is passed to framework
40+
const summaryNoLinks = data.summary.replace(
41+
/<a[^>]*>([^<]+)<\/a>/gm,
42+
'$1',
43+
)
44+
const { code } = convertToReactComponent(`<>${summaryNoLinks}</>`)
45+
const getSummaryComponent = new Function('React', code)
46+
3747
return (
3848
<a href={itemLink} key={idx} className="ws-section-gallery-item">
3949
<DataListItem>
@@ -81,7 +91,9 @@ export const SectionGalleryListLayout = ({
8191
</Split>
8292
{hasListText && (
8393
<Content isEditorial>
84-
<Content component="p">{data.summary}</Content>
94+
<Content component="p">
95+
{getSummaryComponent(React)}
96+
</Content>
8597
</Content>
8698
)}
8799
</DataListCell>,

textContent/AllComponents.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ section: components
55
sortValue: 1
66
---
77

8-
import { componentsData } from './components-data.jsx'
8+
import { componentsData } from './components-data.js'
99

1010
<SectionGallery
1111
section="components"

0 commit comments

Comments
 (0)