Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ const widgetMapping: WidgetMapping = {
defaults: { w: 2, h: 3, maxH: 6, minH: 2 },
config: {
title: 'Example Widget',
icon: <CubeIcon />
icon: <CubeIcon />,
// Optional: header info icon (popover by default; use variant: 'modal' for longer content)
info: {
title: 'About this widget',
content: <p>Short help text explaining what this widget shows.</p>
}
},
renderWidget: (id) => <div>Widget content goes here</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ const widgetMapping: WidgetMapping = {
headerLink: {
title: 'View full report',
href: '#'
},
// Longer help content — opens in a modal
info: {
title: 'About Recent Activity',
content: (
<>
<p>This widget lists recent deployments and infrastructure changes.</p>
<p>Entries are ordered newest first. Use the footer link to open the full activity report.</p>
</>
),
variant: 'modal',
}
},
renderWidget: () => <ActivityWidget />
Expand All @@ -130,7 +141,12 @@ const widgetMapping: WidgetMapping = {
defaults: { w: 1, h: 3, maxH: 6, minH: 2 },
config: {
title: 'Notifications',
icon: <BellIcon />
icon: <BellIcon />,
// Short help content — opens in a popover (default)
info: {
title: 'About Notifications',
content: <p>Shows alerts, maintenance windows, and available patches that need attention.</p>,
}
},
renderWidget: () => <NotificationsWidget />
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ const widgetMapping: WidgetMapping = {
config: {
title: 'Notifications',
icon: <BellIcon />,
info: {
title: 'About Notifications',
content: <p>Shows alerts, maintenance windows, and available patches that need attention.</p>,
},
},
renderWidget: () => <NotificationsWidget />,
},
Expand Down
31 changes: 31 additions & 0 deletions packages/module/patternfly-docs/content/examples/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,34 @@ const widgetMapping: WidgetMapping = {
headerLink: {
title: 'View details',
href: '/details'
},
// Optional header info icon — popover by default
info: {
title: 'About this widget',
content: <p>Short help text explaining what this widget shows.</p>
}
},
renderWidget: (id) => <MyWidgetContent />
},
'detailed-widget': {
defaults: { w: 2, h: 4, maxH: 8, minH: 3 },
config: {
title: 'Detailed Widget',
// Use variant: 'modal' when the help content is long
info: {
title: 'Detailed information',
content: <p>Longer help content that needs more space…</p>,
variant: 'modal',
ariaLabel: 'Detailed widget help'
}
},
renderWidget: (id) => <DetailedWidgetContent />
}
};
```

When `config.info` is set, an info icon appears in the widget header actions. Clicking it opens a **popover** by default, or a **modal** when `variant: 'modal'` is set.

### Widget configuration options

| Property | Type | Description |
Expand All @@ -112,8 +133,18 @@ const widgetMapping: WidgetMapping = {
| `config.title` | `string` | Widget title displayed in the header |
| `config.icon` | `ReactNode` | Icon displayed next to the title |
| `config.headerLink` | `{ title: string, href: string }` | Optional link displayed in the widget header |
| `config.info` | `WidgetInfo` | Optional header info icon; see below |
| `renderWidget` | `(id: string) => ReactNode` | Function that renders the widget content |

### Widget info (`config.info`)

| Property | Type | Description |
|----------|------|-------------|
| `content` | `ReactNode` | Body content shown in the popover or modal (required) |
| `title` | `ReactNode` | Optional header/title for the popover or modal |
| `variant` | `'popover' \| 'modal'` | Presentation style. Defaults to `'popover'`. Use `'modal'` for longer content |
| `ariaLabel` | `string` | Accessible label for the info icon button. Defaults to `"More information"` |

## Template configuration

Define your initial layout using the `ExtendedTemplateConfig` type:
Expand Down
68 changes: 61 additions & 7 deletions packages/module/src/WidgetLayout/GridTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ import {
Icon,
MenuToggle,
MenuToggleElement,
Modal,
ModalBody,
ModalHeader,
Popover,
Skeleton,
Tooltip,
} from '@patternfly/react-core';
import CompressIcon from '@patternfly/react-icons/dist/esm/icons/compress-icon';
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
import ExpandIcon from '@patternfly/react-icons/dist/esm/icons/expand-icon';
import GripVerticalIcon from '@patternfly/react-icons/dist/esm/icons/grip-vertical-icon';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';
import LockIcon from '@patternfly/react-icons/dist/esm/icons/lock-icon';
import MinusCircleIcon from '@patternfly/react-icons/dist/esm/icons/minus-circle-icon';
import UnlockIcon from '@patternfly/react-icons/dist/esm/icons/unlock-icon';
import React, { useMemo, useState } from 'react';
import clsx from 'clsx';
import type { LayoutItem } from 'react-grid-layout';
import { ExtendedLayoutItem, WidgetConfiguration, AnalyticsTracker } from './types';
import { ExtendedLayoutItem, WidgetConfiguration, WidgetInfo, AnalyticsTracker } from './types';

export type SetWidgetAttribute = <T extends string | number | boolean>(id: string, attributeName: keyof ExtendedLayoutItem, value: T) => void;

Expand All @@ -46,6 +51,53 @@ export type GridTileProps = React.PropsWithChildren<{
analytics?: AnalyticsTracker;
}>;

const WidgetInfoAction = ({ info }: { info: WidgetInfo }) => {
const [isModalOpen, setIsModalOpen] = useState(false);
const ariaLabel = info.ariaLabel ?? 'More information';
const accessibleName = typeof info.title === 'string' ? info.title : ariaLabel;
const isModal = info.variant === 'modal';

const trigger = (
<Button
className="pf-v6-widget-grid-tile__info-button"
variant="plain"
aria-label={ariaLabel}
onClick={isModal ? () => setIsModalOpen(true) : undefined}
>
<InfoCircleIcon aria-hidden="true" />
</Button>
);

if (isModal) {
return (
<>
{trigger}
<Modal
isOpen={isModalOpen}
onClose={() => setIsModalOpen(false)}
variant="medium"
aria-label={accessibleName}
>
{info.title != null && <ModalHeader title={info.title} />}
<ModalBody>{info.content}</ModalBody>
</Modal>
</>
);
}

return (
<Popover
triggerAction="click"
headerContent={info.title}
bodyContent={info.content}
appendTo={() => document.body}
aria-label={accessibleName}
>
{trigger}
</Popover>
);
};

const GridTile = ({
widgetType,
isDragging,
Expand All @@ -58,8 +110,8 @@ const GridTile = ({
analytics,
}: GridTileProps) => {
const [isOpen, setIsOpen] = useState(false);
const { headerLink } = widgetConfig.config || {};
const hasHeader = headerLink && headerLink.href && headerLink.title;
const { headerLink, info } = widgetConfig.config || {};
const hasHeader = headerLink?.href && headerLink?.title;

const [linkHref, linkTarget] = useMemo(() => {
if (!headerLink?.href) {
Expand Down Expand Up @@ -133,6 +185,7 @@ const GridTile = ({

const headerActions = (
<>
{info ? <WidgetInfoAction info={info} /> : null}
<Dropdown
ouiaId={`${widgetType}-widget`}
popperProps={{
Expand All @@ -158,7 +211,10 @@ const GridTile = ({
<DropdownList>{dropdownItems}</DropdownList>
</Dropdown>
<Tooltip content={<p>{widgetConfig.static ? 'Widget locked' : 'Move'}</p>}>
<Icon
<Button
component="span"
variant="plain"
icon={<GripVerticalIcon aria-hidden="true" />}
onMouseDown={() => {
setIsDragging(true);
analytics?.('widget-layout.widget-move', { widgetType });
Expand All @@ -167,9 +223,7 @@ const GridTile = ({
className={clsx('pf-v6-widget-drag-handle', {
'pf-v6-widget-drag-handle--dragging': isDragging,
})}
>
<GripVerticalIcon />
</Icon>
/>
</Tooltip>
</>
);
Expand Down
81 changes: 81 additions & 0 deletions packages/module/src/WidgetLayout/__tests__/GridTile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,84 @@ describe('GridTile - header link', () => {
expect(screen.getByText('test-widget')).toBeInTheDocument();
});
});

describe('GridTile - info action', () => {
it('does not render info button when info is not configured', () => {
render(<GridTile {...createProps()} />);
expect(screen.queryByRole('button', { name: 'More information' })).not.toBeInTheDocument();
});

it('opens a popover with content on click by default', async () => {
const user = userEvent.setup();
render(
<GridTile
{...createProps({
widgetConfig: {
...createProps().widgetConfig,
config: {
title: 'Test Widget',
info: {
title: 'About this widget',
content: <p>Short help text</p>,
},
},
},
})}
/>
);

await user.click(screen.getByRole('button', { name: 'More information' }));
expect(await screen.findByText('Short help text')).toBeInTheDocument();
expect(screen.getByText('About this widget')).toBeInTheDocument();
});

it('opens a modal with content when variant is modal', async () => {
const user = userEvent.setup();
render(
<GridTile
{...createProps({
widgetConfig: {
...createProps().widgetConfig,
config: {
title: 'Test Widget',
info: {
title: 'Detailed info',
content: <p>Long form help content</p>,
variant: 'modal',
},
},
},
})}
/>
);

expect(screen.queryByText('Long form help content')).not.toBeInTheDocument();
await user.click(screen.getByRole('button', { name: 'More information' }));
expect(await screen.findByText('Long form help content')).toBeInTheDocument();
expect(screen.getByText('Detailed info')).toBeInTheDocument();

await user.click(screen.getByRole('button', { name: 'Close' }));
expect(screen.queryByText('Long form help content')).not.toBeInTheDocument();
});

it('applies a custom ariaLabel to the info button', () => {
render(
<GridTile
{...createProps({
widgetConfig: {
...createProps().widgetConfig,
config: {
info: {
content: <p>Help</p>,
ariaLabel: 'Widget help details',
},
},
},
})}
/>
);

expect(screen.getByRole('button', { name: 'Widget help details' })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'More information' })).not.toBeInTheDocument();
});
});
14 changes: 13 additions & 1 deletion packages/module/src/WidgetLayout/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,24 @@ export interface WidgetHeaderLink {
href?: string;
}

export interface WidgetInfo {
/** Body content shown in the popover or modal */
content: React.ReactNode;
/** Optional header/title for the popover or modal */
title?: React.ReactNode;
/** Defaults to 'popover'. Use 'modal' for longer content. */
variant?: 'popover' | 'modal';
/** Accessible label for the info icon button (default: "More information") */
ariaLabel?: string;
}

export interface WidgetConfiguration {
icon?: React.ReactNode;
headerLink?: WidgetHeaderLink;
title?: string;
wrapperProps?: Omit<CardProps, 'children'>;
cardBodyProps?: Omit<CardBodyProps, 'children'>;
info?: WidgetInfo;
}

/**
Expand All @@ -63,7 +75,7 @@ export interface WidgetDefinition {
widgetType: string;
/** Default dimensions for the widget */
defaults: WidgetDefaults;
/** Widget configuration (title, icon, header link) */
/** Widget configuration (title, icon, header link, info) */
config?: WidgetConfiguration;
/** Function that renders the widget content */
renderWidget: (widgetId: string) => React.ReactNode;
Expand Down
16 changes: 16 additions & 0 deletions packages/module/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@
cursor: grab;
}

.pf-v6-widget-grid-tile .pf-v6-widget-grid-tile__info-button,
.pf-v6-widget-grid-tile .pf-v6-widget-grid-tile__menu-toggle,
.pf-v6-widget-grid-tile .pf-v6-widget-drag-handle {
inline-size: var(--pf-t--global--spacer--lg);
block-size: var(--pf-t--global--spacer--lg);
min-inline-size: var(--pf-t--global--spacer--lg);
min-block-size: var(--pf-t--global--spacer--lg);
padding: 0;
align-items: center;
line-height: 0;
}

.pf-v6-widget-grid-tile .pf-v6-c-card__actions {
--pf-v6-c-card__actions--Gap: var(--pf-t--global--spacer--gap--action-to-action--plain);
}

.pf-v6-widget-grid-tile .pf-v6-widget-drag-handle.pf-v6-widget-drag-handle--dragging {
cursor: grabbing;
}
Expand Down