From bd77d7516293a867aa33113afc9d0d18ff279f6f Mon Sep 17 00:00:00 2001 From: nicolethoen Date: Mon, 1 Jul 2024 15:08:27 -0400 Subject: [PATCH] fix(Wizard): add className and spread props when possible --- .../src/components/Wizard/WizardBody.tsx | 11 +++- .../src/components/Wizard/WizardFooter.tsx | 20 ++++--- .../src/components/Wizard/WizardHeader.tsx | 10 +++- .../src/components/Wizard/WizardNav.tsx | 13 +++-- .../src/components/Wizard/WizardNavItem.tsx | 14 ++++- .../Wizard/__tests__/WizardBody.test.tsx | 33 ++++++++--- .../Wizard/__tests__/WizardFooter.test.tsx | 9 +++ .../Wizard/__tests__/WizardHeader.test.tsx | 51 +++++++++++++++++ .../Wizard/__tests__/WizardNav.test.tsx | 46 ++++++++++++++++ .../Wizard/__tests__/WizardNavItem.test.tsx | 55 +++++++++++++++++++ 10 files changed, 234 insertions(+), 28 deletions(-) create mode 100644 packages/react-core/src/components/Wizard/__tests__/WizardHeader.test.tsx create mode 100644 packages/react-core/src/components/Wizard/__tests__/WizardNav.test.tsx create mode 100644 packages/react-core/src/components/Wizard/__tests__/WizardNavItem.test.tsx diff --git a/packages/react-core/src/components/Wizard/WizardBody.tsx b/packages/react-core/src/components/Wizard/WizardBody.tsx index 56688070a7c..b0c3e9153ad 100644 --- a/packages/react-core/src/components/Wizard/WizardBody.tsx +++ b/packages/react-core/src/components/Wizard/WizardBody.tsx @@ -10,9 +10,11 @@ import { getResizeObserver } from '../../helpers/resizeObserver'; * Used as a wrapper for WizardStep content, where the wrapping element is customizable. */ -export interface WizardBodyProps { +export interface WizardBodyProps extends React.HTMLProps { /** Anything that can be rendered in the Wizard body */ children: React.ReactNode; + /** Additional classes spread to the wizard body */ + className?: string; /** Flag to remove the default body padding */ hasNoPadding?: boolean; /** Adds an accessible name to the wrapper element when the content overflows and renders @@ -29,10 +31,12 @@ export interface WizardBodyProps { export const WizardBody = ({ children, + className, hasNoPadding = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, - component = 'div' + component = 'div', + ...props }: WizardBodyProps) => { const [hasScrollbar, setHasScrollbar] = React.useState(false); const [previousWidth, setPreviousWidth] = React.useState(undefined); @@ -74,7 +78,8 @@ export const WizardBody = ({ {...(shouldFocusContent && { tabIndex: -1 })} {...(component === 'div' && hasScrollbar && { role: 'region' })} {...(hasScrollbar && { 'aria-label': defaultAriaLabel, 'aria-labelledby': ariaLabelledBy, tabIndex: 0 })} - className={css(styles.wizardMain)} + className={css(styles.wizardMain, className)} + {...props} >
{children}
diff --git a/packages/react-core/src/components/Wizard/WizardFooter.tsx b/packages/react-core/src/components/Wizard/WizardFooter.tsx index bd4596dc477..05ce38d53fb 100644 --- a/packages/react-core/src/components/Wizard/WizardFooter.tsx +++ b/packages/react-core/src/components/Wizard/WizardFooter.tsx @@ -5,12 +5,11 @@ import styles from '@patternfly/react-styles/css/components/Wizard/wizard'; import { Button, ButtonVariant } from '../Button'; import { isCustomWizardFooter, WizardFooterButtonProps, WizardStepType } from './types'; - /** * Hosts the standard structure of a footer with ties to the active step so that text for buttons can vary from step to step. */ -export interface WizardFooterProps { +export interface WizardFooterProps extends React.HTMLProps { /** The active step */ activeStep: WizardStepType; /** Next button callback */ @@ -39,18 +38,23 @@ export interface WizardFooterProps { backButtonProps?: Omit; /** Additional props for the Cancel button. */ cancelButtonProps?: WizardFooterButtonProps; + /** Additional classes spread to the wizard footer */ + className?: string; } /** * Applies default wizard footer styling any number of child elements. */ -interface WizardFooterWrapperProps { +interface WizardFooterWrapperProps extends React.HTMLProps { children: React.ReactNode; + className?: string; } -export const WizardFooterWrapper = ({ children }: WizardFooterWrapperProps) => ( -
{children}
+export const WizardFooterWrapper = ({ children, className, ...props }: WizardFooterWrapperProps) => ( +
+ {children} +
); export const WizardFooter = ({ activeStep, ...internalProps }: WizardFooterProps) => { @@ -71,9 +75,11 @@ const InternalWizardFooter = ({ cancelButtonText = 'Cancel', nextButtonProps, backButtonProps, - cancelButtonProps + cancelButtonProps, + className, + ...props }: Omit) => ( - + {!isBackHidden && (