Skip to content

Commit e55d09c

Browse files
committed
Replaced List components, updated toggletext
1 parent addcd49 commit e55d09c

File tree

6 files changed

+12
-106
lines changed

6 files changed

+12
-106
lines changed

packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithSources.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ export const MessageWithSourcesExample: FunctionComponent = () => {
253253
title: 'Getting started with Red Hat OpenShift',
254254
link: '#',
255255
body: 'Red Hat OpenShift on IBM Cloud is a managed offering to create your own cluster of compute hosts where you can deploy and manage containerized apps on IBM Cloud.',
256-
isExternal: true
256+
isExternal: true,
257+
hasShowMore: true
257258
},
258259
{
259260
title: 'Azure Red Hat OpenShift documentation',

packages/module/src/SourcesCard/SourcesCard.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
}
2020

2121
.pf-chatbot__sources-card-base.pf-m-wrap {
22-
.pf-v6-c-list {
22+
.pf-chatbot__sources-list {
2323
display: flex;
2424
flex-wrap: wrap;
25+
list-style: none;
2526
gap: var(--pf-t--global--spacer--xs);
2627
}
2728
}

packages/module/src/SourcesCard/SourcesCard.test.tsx

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,4 @@ describe('SourcesCard', () => {
4444
expect(screen.queryByRole('navigation')).not.toBeInTheDocument();
4545
expect(screen.queryByText('1/3')).not.toBeInTheDocument();
4646
});
47-
48-
it('should pass listProps to SourcesCardBase when using wrap layout', () => {
49-
render(
50-
<SourcesCard
51-
layout="wrap"
52-
sources={[
53-
{ title: 'How to make an apple pie', link: '' },
54-
{ title: 'How to make cookies', link: '' }
55-
]}
56-
listProps={{ className: 'custom-list-class' }}
57-
/>
58-
);
59-
const listElement = screen.getByRole('list');
60-
expect(listElement).toHaveClass('custom-list-class');
61-
});
62-
63-
it('should pass listItemProps to SourcesCardBase when using wrap layout', () => {
64-
render(
65-
<SourcesCard
66-
layout="wrap"
67-
sources={[
68-
{ title: 'How to make an apple pie', link: '' },
69-
{ title: 'How to make cookies', link: '' }
70-
]}
71-
listItemProps={{ className: 'custom-list-item-class' }}
72-
/>
73-
);
74-
const listItemElements = screen.getAllByRole('listitem');
75-
listItemElements.forEach((listItem) => {
76-
expect(listItem).toHaveClass('custom-list-item-class');
77-
});
78-
});
7947
});

packages/module/src/SourcesCard/SourcesCard.tsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import {
88
CardFooterProps,
99
CardProps,
1010
CardTitleProps,
11-
ListProps,
12-
ListItemProps,
1311
pluralize,
1412
TruncateProps
1513
} from '@patternfly/react-core';
@@ -23,10 +21,6 @@ export interface SourcesCardProps extends CardProps {
2321
layout?: 'paginated' | 'wrap';
2422
/** Max width of a source card when the wrap layout is used. Can be any valid CSS width value. */
2523
cardMaxWidth?: string;
26-
/** Additional props to pass to the list of source cards when the wrap layout is used. */
27-
listProps?: ListProps;
28-
/** Additional props to pass to the list items of source cards when the wrap layout is used. */
29-
listItemProps?: Omit<ListItemProps, 'children'>;
3024
/** Flag indicating if the pagination is disabled. */
3125
isDisabled?: boolean;
3226
/** @deprecated ofWord has been deprecated. Label for the English word "of." */
@@ -88,20 +82,11 @@ const SourcesCard: FunctionComponent<SourcesCardProps> = ({
8882
sourceWordPlural = 'sources',
8983
layout = 'paginated',
9084
cardMaxWidth = '400px',
91-
listProps,
92-
listItemProps,
9385
...props
9486
}: SourcesCardProps) => (
9587
<div className={css('pf-chatbot__source', layout === 'wrap' && 'pf-m-wrap')}>
9688
<span>{pluralize(sources.length, sourceWord, sourceWordPlural)}</span>
97-
<SourcesCardBase
98-
sources={sources}
99-
layout={layout}
100-
listProps={listProps}
101-
listItemProps={listItemProps}
102-
cardMaxWidth={cardMaxWidth}
103-
{...props}
104-
/>
89+
<SourcesCardBase sources={sources} layout={layout} cardMaxWidth={cardMaxWidth} {...props} />
10590
</div>
10691
);
10792

packages/module/src/SourcesCardBase/SourcesCardBase.test.tsx

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -282,36 +282,4 @@ describe('SourcesCardBase', () => {
282282
const firstCard = screen.getByText('How to make an apple pie').closest('.pf-chatbot__sources-card');
283283
expect(firstCard).toHaveStyle({ maxWidth: '500px' });
284284
});
285-
286-
it('should apply listProps when using wrap layout', () => {
287-
render(
288-
<SourcesCardBase
289-
layout="wrap"
290-
sources={[
291-
{ title: 'How to make an apple pie', link: '' },
292-
{ title: 'How to make cookies', link: '' }
293-
]}
294-
listProps={{ className: 'custom-list-class' }}
295-
/>
296-
);
297-
const listElement = screen.getByRole('list');
298-
expect(listElement).toHaveClass('custom-list-class');
299-
});
300-
301-
it('should apply listItemProps when using wrap layout', () => {
302-
render(
303-
<SourcesCardBase
304-
layout="wrap"
305-
sources={[
306-
{ title: 'How to make an apple pie', link: '' },
307-
{ title: 'How to make cookies', link: '' }
308-
]}
309-
listItemProps={{ className: 'custom-list-item-class' }}
310-
/>
311-
);
312-
const listItemElements = screen.getAllByRole('listitem');
313-
listItemElements.forEach((listItem) => {
314-
expect(listItem).toHaveClass('custom-list-item-class');
315-
});
316-
});
317285
});

packages/module/src/SourcesCardBase/SourcesCardBase.tsx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ import {
1919
ExpandableSection,
2020
ExpandableSectionVariant,
2121
Icon,
22-
List,
23-
ListProps,
24-
ListItem,
25-
ListItemProps,
26-
ListVariant,
2722
Truncate,
2823
TruncateProps
2924
} from '@patternfly/react-core';
@@ -42,10 +37,6 @@ export interface SourcesCardBaseProps extends CardProps {
4237
paginationAriaLabel?: string;
4338
/** Max width of a source card when the wrap layout is used. Can be any valid CSS width value. */
4439
cardMaxWidth?: string;
45-
/** Additional props to pass to the list of source cards when the wrap layout is used. */
46-
listProps?: ListProps;
47-
/** Additional props to pass to the list items of source cards when the wrap layout is used. */
48-
listItemProps?: Omit<ListItemProps, 'children'>;
4940
/** Content rendered inside the paginated card */
5041
sources: {
5142
/** Title of sources card */
@@ -109,8 +100,6 @@ const SourcesCardBase: FunctionComponent<SourcesCardBaseProps> = ({
109100
cardFooterProps,
110101
layout = 'paginated',
111102
cardMaxWidth = '400px',
112-
listProps,
113-
listItemProps,
114103
...props
115104
}: SourcesCardBaseProps) => {
116105
const [page, setPage] = useState(1);
@@ -133,14 +122,8 @@ const SourcesCardBase: FunctionComponent<SourcesCardBaseProps> = ({
133122
};
134123

135124
const renderUncontrolledSourceCard = (source: SourcesCardBaseProps['sources'][0], index: number) => (
136-
<ListItem key={index} className="pf-chatbot__sources-list-item" {...listItemProps}>
137-
<Card
138-
isCompact={isCompact}
139-
className="pf-chatbot__sources-card"
140-
style={{ maxWidth: cardMaxWidth }}
141-
component="span"
142-
{...props}
143-
>
125+
<li key={index} className="pf-chatbot__sources-list-item">
126+
<Card isCompact={isCompact} className="pf-chatbot__sources-card" style={{ maxWidth: cardMaxWidth }} {...props}>
144127
<CardTitle className="pf-chatbot__sources-card-title" {...cardTitleProps}>
145128
<div className="pf-chatbot__sources-card-title-container">
146129
<Button
@@ -170,8 +153,8 @@ const SourcesCardBase: FunctionComponent<SourcesCardBaseProps> = ({
170153
<div aria-live="off">
171154
<ExpandableSection
172155
variant={ExpandableSectionVariant.truncate}
173-
toggleTextCollapsed={showLessWords}
174-
toggleTextExpanded={showMoreWords}
156+
toggleTextCollapsed={showMoreWords}
157+
toggleTextExpanded={showLessWords}
175158
truncateMaxLines={2}
176159
>
177160
{source.body}
@@ -188,15 +171,15 @@ const SourcesCardBase: FunctionComponent<SourcesCardBaseProps> = ({
188171
</CardFooter>
189172
)}
190173
</Card>
191-
</ListItem>
174+
</li>
192175
);
193176

194177
if (layout === 'wrap') {
195178
return (
196179
<div className="pf-chatbot__sources-card-base pf-m-wrap">
197-
<List isPlain variant={ListVariant.inline} className="pf-chatbot__sources-list" {...listProps}>
180+
<ul className="pf-chatbot__sources-list" role="list">
198181
{sources.map((source, index) => renderUncontrolledSourceCard(source, index))}
199-
</List>
182+
</ul>
200183
</div>
201184
);
202185
}

0 commit comments

Comments
 (0)