diff --git a/packages/react-core/src/components/Compass/CompassMainFooter.tsx b/packages/react-core/src/components/Compass/CompassMainFooter.tsx new file mode 100644 index 00000000000..cbbd60f663f --- /dev/null +++ b/packages/react-core/src/components/Compass/CompassMainFooter.tsx @@ -0,0 +1,24 @@ +import styles from '@patternfly/react-styles/css/components/Compass/compass'; +import { css } from '@patternfly/react-styles'; + +interface CompassMainFooterProps extends Omit, 'title'> { + /** Additional classes added to the main footer */ + className?: string; + /** Main footer content */ + children?: React.ReactNode; + /** Indicates if the main footer is expanded */ + isExpanded?: boolean; +} + +export const CompassMainFooter: React.FunctionComponent = ({ + className, + children, + isExpanded = true, + ...props +}) => ( +
+ {children} +
+); + +CompassMainFooter.displayName = 'CompassMainFooter'; diff --git a/packages/react-core/src/components/Compass/__tests__/CompassMainFooter.test.tsx b/packages/react-core/src/components/Compass/__tests__/CompassMainFooter.test.tsx new file mode 100644 index 00000000000..25b955ba77c --- /dev/null +++ b/packages/react-core/src/components/Compass/__tests__/CompassMainFooter.test.tsx @@ -0,0 +1,52 @@ +import { render, screen } from '@testing-library/react'; +import { CompassMainFooter } from '../CompassMainFooter'; +import styles from '@patternfly/react-styles/css/components/Compass/compass'; + +test('Renders without children', () => { + render( +
+ +
+ ); + expect(screen.getByTestId('test-main-footer').firstChild).toBeVisible(); +}); + +test('Renders with children', () => { + render(Custom content); + expect(screen.getByText('Custom content')).toBeVisible(); +}); + +test('Renders with custom class name when className prop is provided', () => { + render(Test); + expect(screen.getByText('Test')).toHaveClass('custom-class'); +}); + +test(`Renders with default ${styles.compassMainFooter} class`, () => { + render(Test); + expect(screen.getByText('Test')).toHaveClass(styles.compassMainFooter); +}); + +test(`Renders with pf-m-expanded class by default`, () => { + render(Test); + expect(screen.getByText('Test')).toHaveClass('pf-m-expanded'); +}); + +test(`Renders with pf-m-expanded class when isExpanded is true`, () => { + render(Test); + expect(screen.getByText('Test')).toHaveClass('pf-m-expanded'); +}); + +test(`Renders without pf-m-expanded class when isExpanded is false`, () => { + render(Test); + expect(screen.getByText('Test')).not.toHaveClass('pf-m-expanded'); +}); + +test('Renders with additional props spread to the component', () => { + render(Test); + expect(screen.getByText('Test')).toHaveAccessibleName('Test label'); +}); + +test('Matches the snapshot', () => { + const { asFragment } = render(Custom children content); + expect(asFragment()).toMatchSnapshot(); +}); diff --git a/packages/react-core/src/components/Compass/__tests__/__snapshots__/CompassMainFooter.test.tsx.snap b/packages/react-core/src/components/Compass/__tests__/__snapshots__/CompassMainFooter.test.tsx.snap new file mode 100644 index 00000000000..160ef4650a2 --- /dev/null +++ b/packages/react-core/src/components/Compass/__tests__/__snapshots__/CompassMainFooter.test.tsx.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Matches the snapshot 1`] = ` + + + +`; diff --git a/packages/react-core/src/components/Compass/examples/Compass.md b/packages/react-core/src/components/Compass/examples/Compass.md index af4df67604f..b24170a3eea 100644 --- a/packages/react-core/src/components/Compass/examples/Compass.md +++ b/packages/react-core/src/components/Compass/examples/Compass.md @@ -16,13 +16,14 @@ propComponents: ] --- -import './compass.css'; import { useRef, useState } from 'react'; import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon'; import OutlinedPlusSquare from '@patternfly/react-icons/dist/esm/icons/outlined-plus-square-icon'; import OutlinedCopy from '@patternfly/react-icons/dist/esm/icons/outlined-copy-icon'; import OutlinedQuestionCircleIcon from '@patternfly/react-icons/dist/esm/icons/outlined-question-circle-icon'; +import './compass.css'; + ## Examples ### Basic @@ -41,6 +42,14 @@ The background image of the `Compass` and `CompassHero` may be customized by usi ``` +### With alternate footer + +When `footer` is used, its content will take up the width of the screen. However, if content inside of the footer grows, then the two sidebars' heights and placement will adjust to allow for the change. If this is not the desired behavior, then using a `CompassMainFooter` inside of the of the `main` section provides an alterate way to render footer content without interfering with the sidebars, by rendering content at the bottom of the page between the two sidebars opposed to the whole bottom of the page. + +```ts file="CompassMainFooterDemo.tsx" + +``` + ### Demo ```ts isFullscreen file="CompassDemo.tsx" diff --git a/packages/react-core/src/components/Compass/examples/CompassBasic.tsx b/packages/react-core/src/components/Compass/examples/CompassBasic.tsx index c00a2302414..fd3cd1a57cb 100644 --- a/packages/react-core/src/components/Compass/examples/CompassBasic.tsx +++ b/packages/react-core/src/components/Compass/examples/CompassBasic.tsx @@ -40,6 +40,7 @@ export const CompassBasic: React.FunctionComponent = () => { main={mainContent} sidebarEnd={sidebarEndContent} footer={footerContent} + style={{ height: '600px' }} /> ); }; diff --git a/packages/react-core/src/components/Compass/examples/CompassMainFooterDemo.tsx b/packages/react-core/src/components/Compass/examples/CompassMainFooterDemo.tsx new file mode 100644 index 00000000000..4846f6f07aa --- /dev/null +++ b/packages/react-core/src/components/Compass/examples/CompassMainFooterDemo.tsx @@ -0,0 +1,43 @@ +import { + Compass, + CompassHeader, + CompassHero, + CompassContent, + CompassMainHeader, + CompassMainFooter +} from '@patternfly/react-core'; +import './compass.css'; + +export const CompassMainFooterDemo: React.FunctionComponent = () => { + const headerContent = Logo} nav={
Nav
} profile={
Profile
} />; + const sidebarStartContent =
Sidebar start
; + // TODO: simplify mainContent to only a div string + const mainContent = ( + <> + +
Hero
+
+ + +
Content title
+
+
Content
+
+ +
Footer
+
+ + ); + const sidebarEndContent =
Sidebar end
; + + return ( + + ); +}; diff --git a/packages/react-core/src/components/Compass/examples/compass.css b/packages/react-core/src/components/Compass/examples/compass.css index 46c3b19746b..75aef0a3a59 100644 --- a/packages/react-core/src/components/Compass/examples/compass.css +++ b/packages/react-core/src/components/Compass/examples/compass.css @@ -1,8 +1,20 @@ -#ws-react-c-compass-basic [class*="pf-v6-c-compass"] { +#ws-react-p-compass-basic [class*="pf-v6-c-compass"] { position: relative; } -#ws-react-c-compass-basic [class*="pf-v6-c-compass"]::after { +#ws-react-p-compass-basic [class*="pf-v6-c-compass"]::after { + content: ""; + position: absolute; + inset: 0; + border: var(--pf-t--global--border--width--regular) dashed var(--pf-t--global--border--color--default); + pointer-events: none; +} + +#ws-react-p-compass-with-alternate-footer [class*="pf-v6-c-compass"] { + position: relative; +} + +#ws-react-p-compass-with-alternate-footer [class*="pf-v6-c-compass"]:not([class*="footer"])::after { content: ""; position: absolute; inset: 0; diff --git a/packages/react-core/src/components/Compass/index.ts b/packages/react-core/src/components/Compass/index.ts index aabf250facb..af1b6b562dd 100644 --- a/packages/react-core/src/components/Compass/index.ts +++ b/packages/react-core/src/components/Compass/index.ts @@ -6,5 +6,6 @@ export * from './CompassMainHeader'; export * from './CompassMainHeaderContent'; export * from './CompassMainHeaderTitle'; export * from './CompassMainHeaderToolbar'; +export * from './CompassMainFooter'; export * from './CompassMessageBar'; export * from './CompassPanel';