@patternfly/chatbot 6.3.0-prerelease.21 → 6.3.0-prerelease.22

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.
@@ -1,5 +1,5 @@
1
1
  import type { FunctionComponent } from 'react';
2
- import { CardProps } from '@patternfly/react-core';
2
+ import { ButtonProps, CardProps } from '@patternfly/react-core';
3
3
  export interface SourcesCardProps extends CardProps {
4
4
  /** Additional classes for the pagination navigation container. */
5
5
  className?: string;
@@ -11,11 +11,20 @@ export interface SourcesCardProps extends CardProps {
11
11
  paginationAriaLabel?: string;
12
12
  /** Content rendered inside the paginated card */
13
13
  sources: {
14
+ /** Title of sources card */
14
15
  title?: string;
16
+ /** Link to source */
15
17
  link: string;
18
+ /** Body of sources card */
16
19
  body?: React.ReactNode | string;
20
+ /** Whether link is external */
17
21
  isExternal?: boolean;
22
+ /** Whether sources card is expandable */
18
23
  hasShowMore?: boolean;
24
+ /** onClick event applied to the title of the Sources card */
25
+ onClick?: React.MouseEventHandler<HTMLButtonElement>;
26
+ /** Any additional props applied to the title of the Sources card */
27
+ titleProps?: ButtonProps;
19
28
  }[];
20
29
  /** Label for the English word "source" */
21
30
  sourceWord?: string;
@@ -17,6 +17,7 @@ const react_1 = require("react");
17
17
  const react_core_1 = require("@patternfly/react-core");
18
18
  const react_icons_1 = require("@patternfly/react-icons");
19
19
  const SourcesCard = (_a) => {
20
+ var _b;
20
21
  var { className, isDisabled, paginationAriaLabel = 'Pagination', sources, sourceWord = 'source', sourceWordPlural = 'sources', toNextPageAriaLabel = 'Go to next page', toPreviousPageAriaLabel = 'Go to previous page', onNextClick, onPreviousClick, onSetPage, showMoreWords = 'show more', showLessWords = 'show less', isCompact } = _a, props = __rest(_a, ["className", "isDisabled", "paginationAriaLabel", "sources", "sourceWord", "sourceWordPlural", "toNextPageAriaLabel", "toPreviousPageAriaLabel", "onNextClick", "onPreviousClick", "onSetPage", "showMoreWords", "showLessWords", "isCompact"]);
21
22
  const [page, setPage] = (0, react_1.useState)(1);
22
23
  const [isExpanded, setIsExpanded] = (0, react_1.useState)(false);
@@ -33,7 +34,7 @@ const SourcesCard = (_a) => {
33
34
  }
34
35
  return `Source ${page}`;
35
36
  };
36
- return ((0, jsx_runtime_1.jsxs)("div", { className: "pf-chatbot__source", children: [(0, jsx_runtime_1.jsx)("span", { children: (0, react_core_1.pluralize)(sources.length, sourceWord, sourceWordPlural) }), (0, jsx_runtime_1.jsxs)(react_core_1.Card, Object.assign({ isCompact: isCompact, className: "pf-chatbot__sources-card" }, props, { children: [(0, jsx_runtime_1.jsx)(react_core_1.CardTitle, { className: "pf-chatbot__sources-card-title", children: (0, jsx_runtime_1.jsx)(react_core_1.Button, { component: "a", variant: react_core_1.ButtonVariant.link, href: sources[page - 1].link, icon: sources[page - 1].isExternal ? (0, jsx_runtime_1.jsx)(react_icons_1.ExternalLinkSquareAltIcon, {}) : undefined, iconPosition: "end", isInline: true, rel: sources[page - 1].isExternal ? 'noreferrer' : undefined, target: sources[page - 1].isExternal ? '_blank' : undefined, children: renderTitle(sources[page - 1].title) }) }), sources[page - 1].body && ((0, jsx_runtime_1.jsx)(react_core_1.CardBody, { className: `pf-chatbot__sources-card-body`, children: sources[page - 1].hasShowMore ? (
37
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "pf-chatbot__source", children: [(0, jsx_runtime_1.jsx)("span", { children: (0, react_core_1.pluralize)(sources.length, sourceWord, sourceWordPlural) }), (0, jsx_runtime_1.jsxs)(react_core_1.Card, Object.assign({ isCompact: isCompact, className: "pf-chatbot__sources-card" }, props, { children: [(0, jsx_runtime_1.jsx)(react_core_1.CardTitle, { className: "pf-chatbot__sources-card-title", children: (0, jsx_runtime_1.jsx)(react_core_1.Button, Object.assign({ component: "a", variant: react_core_1.ButtonVariant.link, href: sources[page - 1].link, icon: sources[page - 1].isExternal ? (0, jsx_runtime_1.jsx)(react_icons_1.ExternalLinkSquareAltIcon, {}) : undefined, iconPosition: "end", isInline: true, rel: sources[page - 1].isExternal ? 'noreferrer' : undefined, target: sources[page - 1].isExternal ? '_blank' : undefined, onClick: (_b = sources[page - 1].onClick) !== null && _b !== void 0 ? _b : undefined }, sources[page - 1].titleProps, { children: renderTitle(sources[page - 1].title) })) }), sources[page - 1].body && ((0, jsx_runtime_1.jsx)(react_core_1.CardBody, { className: `pf-chatbot__sources-card-body`, children: sources[page - 1].hasShowMore ? (
37
38
  // prevents extra VO announcements of button text - parent Message has aria-live
38
39
  (0, jsx_runtime_1.jsx)("div", { "aria-live": "off", children: (0, jsx_runtime_1.jsx)(react_core_1.ExpandableSection, { variant: react_core_1.ExpandableSectionVariant.truncate, toggleText: isExpanded ? showLessWords : showMoreWords, onToggle: onToggle, isExpanded: isExpanded, truncateMaxLines: 2, children: sources[page - 1].body }) })) : ((0, jsx_runtime_1.jsx)("div", { className: "pf-chatbot__sources-card-body-text", children: sources[page - 1].body })) })), sources.length > 1 && ((0, jsx_runtime_1.jsx)(react_core_1.CardFooter, { className: "pf-chatbot__sources-card-footer-container", children: (0, jsx_runtime_1.jsx)("div", { className: "pf-chatbot__sources-card-footer", children: (0, jsx_runtime_1.jsxs)("nav", { className: `pf-chatbot__sources-card-footer-buttons ${className}`, "aria-label": paginationAriaLabel, children: [(0, jsx_runtime_1.jsx)(react_core_1.Button, { variant: react_core_1.ButtonVariant.plain, isDisabled: isDisabled || page === 1, "data-action": "previous", onClick: (event) => {
39
40
  const newPage = page >= 1 ? page - 1 : 1;
@@ -174,4 +174,14 @@ describe('SourcesCard', () => {
174
174
  ] }));
175
175
  expect(react_1.screen.getByRole('region')).toHaveAttribute('class', 'pf-v6-c-expandable-section__content');
176
176
  }));
177
+ it('should call onClick appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
178
+ const spy = jest.fn();
179
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCard_1.default, { sources: [{ title: 'How to make an apple pie', link: '', onClick: spy }] }));
180
+ yield user_event_1.default.click(react_1.screen.getByRole('link', { name: /How to make an apple pie/i }));
181
+ expect(spy).toHaveBeenCalled();
182
+ }));
183
+ it('should apply titleProps appropriately', () => {
184
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(SourcesCard_1.default, { sources: [{ title: 'How to make an apple pie', link: '', titleProps: { className: 'test' } }] }));
185
+ expect(react_1.screen.getByRole('link', { name: /How to make an apple pie/i })).toHaveClass('test');
186
+ });
177
187
  });
@@ -1,5 +1,5 @@
1
1
  import type { FunctionComponent } from 'react';
2
- import { CardProps } from '@patternfly/react-core';
2
+ import { ButtonProps, CardProps } from '@patternfly/react-core';
3
3
  export interface SourcesCardProps extends CardProps {
4
4
  /** Additional classes for the pagination navigation container. */
5
5
  className?: string;
@@ -11,11 +11,20 @@ export interface SourcesCardProps extends CardProps {
11
11
  paginationAriaLabel?: string;
12
12
  /** Content rendered inside the paginated card */
13
13
  sources: {
14
+ /** Title of sources card */
14
15
  title?: string;
16
+ /** Link to source */
15
17
  link: string;
18
+ /** Body of sources card */
16
19
  body?: React.ReactNode | string;
20
+ /** Whether link is external */
17
21
  isExternal?: boolean;
22
+ /** Whether sources card is expandable */
18
23
  hasShowMore?: boolean;
24
+ /** onClick event applied to the title of the Sources card */
25
+ onClick?: React.MouseEventHandler<HTMLButtonElement>;
26
+ /** Any additional props applied to the title of the Sources card */
27
+ titleProps?: ButtonProps;
19
28
  }[];
20
29
  /** Label for the English word "source" */
21
30
  sourceWord?: string;
@@ -15,6 +15,7 @@ import { useState } from 'react';
15
15
  import { Button, ButtonVariant, Card, CardBody, CardFooter, CardTitle, ExpandableSection, ExpandableSectionVariant, Icon, pluralize, Truncate } from '@patternfly/react-core';
16
16
  import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons';
17
17
  const SourcesCard = (_a) => {
18
+ var _b;
18
19
  var { className, isDisabled, paginationAriaLabel = 'Pagination', sources, sourceWord = 'source', sourceWordPlural = 'sources', toNextPageAriaLabel = 'Go to next page', toPreviousPageAriaLabel = 'Go to previous page', onNextClick, onPreviousClick, onSetPage, showMoreWords = 'show more', showLessWords = 'show less', isCompact } = _a, props = __rest(_a, ["className", "isDisabled", "paginationAriaLabel", "sources", "sourceWord", "sourceWordPlural", "toNextPageAriaLabel", "toPreviousPageAriaLabel", "onNextClick", "onPreviousClick", "onSetPage", "showMoreWords", "showLessWords", "isCompact"]);
19
20
  const [page, setPage] = useState(1);
20
21
  const [isExpanded, setIsExpanded] = useState(false);
@@ -31,7 +32,7 @@ const SourcesCard = (_a) => {
31
32
  }
32
33
  return `Source ${page}`;
33
34
  };
34
- return (_jsxs("div", { className: "pf-chatbot__source", children: [_jsx("span", { children: pluralize(sources.length, sourceWord, sourceWordPlural) }), _jsxs(Card, Object.assign({ isCompact: isCompact, className: "pf-chatbot__sources-card" }, props, { children: [_jsx(CardTitle, { className: "pf-chatbot__sources-card-title", children: _jsx(Button, { component: "a", variant: ButtonVariant.link, href: sources[page - 1].link, icon: sources[page - 1].isExternal ? _jsx(ExternalLinkSquareAltIcon, {}) : undefined, iconPosition: "end", isInline: true, rel: sources[page - 1].isExternal ? 'noreferrer' : undefined, target: sources[page - 1].isExternal ? '_blank' : undefined, children: renderTitle(sources[page - 1].title) }) }), sources[page - 1].body && (_jsx(CardBody, { className: `pf-chatbot__sources-card-body`, children: sources[page - 1].hasShowMore ? (
35
+ return (_jsxs("div", { className: "pf-chatbot__source", children: [_jsx("span", { children: pluralize(sources.length, sourceWord, sourceWordPlural) }), _jsxs(Card, Object.assign({ isCompact: isCompact, className: "pf-chatbot__sources-card" }, props, { children: [_jsx(CardTitle, { className: "pf-chatbot__sources-card-title", children: _jsx(Button, Object.assign({ component: "a", variant: ButtonVariant.link, href: sources[page - 1].link, icon: sources[page - 1].isExternal ? _jsx(ExternalLinkSquareAltIcon, {}) : undefined, iconPosition: "end", isInline: true, rel: sources[page - 1].isExternal ? 'noreferrer' : undefined, target: sources[page - 1].isExternal ? '_blank' : undefined, onClick: (_b = sources[page - 1].onClick) !== null && _b !== void 0 ? _b : undefined }, sources[page - 1].titleProps, { children: renderTitle(sources[page - 1].title) })) }), sources[page - 1].body && (_jsx(CardBody, { className: `pf-chatbot__sources-card-body`, children: sources[page - 1].hasShowMore ? (
35
36
  // prevents extra VO announcements of button text - parent Message has aria-live
36
37
  _jsx("div", { "aria-live": "off", children: _jsx(ExpandableSection, { variant: ExpandableSectionVariant.truncate, toggleText: isExpanded ? showLessWords : showMoreWords, onToggle: onToggle, isExpanded: isExpanded, truncateMaxLines: 2, children: sources[page - 1].body }) })) : (_jsx("div", { className: "pf-chatbot__sources-card-body-text", children: sources[page - 1].body })) })), sources.length > 1 && (_jsx(CardFooter, { className: "pf-chatbot__sources-card-footer-container", children: _jsx("div", { className: "pf-chatbot__sources-card-footer", children: _jsxs("nav", { className: `pf-chatbot__sources-card-footer-buttons ${className}`, "aria-label": paginationAriaLabel, children: [_jsx(Button, { variant: ButtonVariant.plain, isDisabled: isDisabled || page === 1, "data-action": "previous", onClick: (event) => {
37
38
  const newPage = page >= 1 ? page - 1 : 1;
@@ -169,4 +169,14 @@ describe('SourcesCard', () => {
169
169
  ] }));
170
170
  expect(screen.getByRole('region')).toHaveAttribute('class', 'pf-v6-c-expandable-section__content');
171
171
  }));
172
+ it('should call onClick appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
173
+ const spy = jest.fn();
174
+ render(_jsx(SourcesCard, { sources: [{ title: 'How to make an apple pie', link: '', onClick: spy }] }));
175
+ yield userEvent.click(screen.getByRole('link', { name: /How to make an apple pie/i }));
176
+ expect(spy).toHaveBeenCalled();
177
+ }));
178
+ it('should apply titleProps appropriately', () => {
179
+ render(_jsx(SourcesCard, { sources: [{ title: 'How to make an apple pie', link: '', titleProps: { className: 'test' } }] }));
180
+ expect(screen.getByRole('link', { name: /How to make an apple pie/i })).toHaveClass('test');
181
+ });
172
182
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/chatbot",
3
- "version": "6.3.0-prerelease.21",
3
+ "version": "6.3.0-prerelease.22",
4
4
  "description": "This library provides React components based on PatternFly 6 that can be used to build chatbots.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -242,4 +242,18 @@ describe('SourcesCard', () => {
242
242
  );
243
243
  expect(screen.getByRole('region')).toHaveAttribute('class', 'pf-v6-c-expandable-section__content');
244
244
  });
245
+
246
+ it('should call onClick appropriately', async () => {
247
+ const spy = jest.fn();
248
+ render(<SourcesCard sources={[{ title: 'How to make an apple pie', link: '', onClick: spy }]} />);
249
+ await userEvent.click(screen.getByRole('link', { name: /How to make an apple pie/i }));
250
+ expect(spy).toHaveBeenCalled();
251
+ });
252
+
253
+ it('should apply titleProps appropriately', () => {
254
+ render(
255
+ <SourcesCard sources={[{ title: 'How to make an apple pie', link: '', titleProps: { className: 'test' } }]} />
256
+ );
257
+ expect(screen.getByRole('link', { name: /How to make an apple pie/i })).toHaveClass('test');
258
+ });
245
259
  });
@@ -6,6 +6,7 @@ import { useState } from 'react';
6
6
  // Import PatternFly components
7
7
  import {
8
8
  Button,
9
+ ButtonProps,
9
10
  ButtonVariant,
10
11
  Card,
11
12
  CardBody,
@@ -31,11 +32,20 @@ export interface SourcesCardProps extends CardProps {
31
32
  paginationAriaLabel?: string;
32
33
  /** Content rendered inside the paginated card */
33
34
  sources: {
35
+ /** Title of sources card */
34
36
  title?: string;
37
+ /** Link to source */
35
38
  link: string;
39
+ /** Body of sources card */
36
40
  body?: React.ReactNode | string;
41
+ /** Whether link is external */
37
42
  isExternal?: boolean;
43
+ /** Whether sources card is expandable */
38
44
  hasShowMore?: boolean;
45
+ /** onClick event applied to the title of the Sources card */
46
+ onClick?: React.MouseEventHandler<HTMLButtonElement>;
47
+ /** Any additional props applied to the title of the Sources card */
48
+ titleProps?: ButtonProps;
39
49
  }[];
40
50
  /** Label for the English word "source" */
41
51
  sourceWord?: string;
@@ -107,6 +117,8 @@ const SourcesCard: FunctionComponent<SourcesCardProps> = ({
107
117
  isInline
108
118
  rel={sources[page - 1].isExternal ? 'noreferrer' : undefined}
109
119
  target={sources[page - 1].isExternal ? '_blank' : undefined}
120
+ onClick={sources[page - 1].onClick ?? undefined}
121
+ {...sources[page - 1].titleProps}
110
122
  >
111
123
  {renderTitle(sources[page - 1].title)}
112
124
  </Button>