Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Wizard): implement success status on steps / nav items #10714

Merged
merged 4 commits into from
Jul 19, 2024
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
11 changes: 7 additions & 4 deletions packages/react-core/src/components/Wizard/WizardNavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';

import { OUIAProps, useOUIAProps } from '../../helpers';
import { WizardNavItemStatus } from './types';
Expand Down Expand Up @@ -38,7 +39,7 @@ export interface WizardNavItemProps
/** The id for the navigation item */
id?: string | number;
/** Used to determine the icon displayed next to content. Default has no icon. */
status?: 'default' | 'error';
status?: 'default' | 'error' | 'success';
}

export const WizardNavItem = ({
Expand Down Expand Up @@ -96,18 +97,20 @@ export const WizardNavItem = ({
styles.wizardNavLink,
isCurrent && styles.modifiers.current,
isDisabled && styles.modifiers.disabled,
status === WizardNavItemStatus.Error && styles.modifiers.danger
status === WizardNavItemStatus.Error && styles.modifiers.danger,
status === WizardNavItemStatus.Success && styles.modifiers.success
)}
aria-disabled={isDisabled ? true : null}
aria-current={isCurrent && !children ? 'step' : false}
{...(isExpandable && { 'aria-expanded': isExpanded })}
{...ouiaProps}
>
{status === WizardNavItemStatus.Error && (
{status !== WizardNavItemStatus.Default && (
<>
<span className="pf-v6-screen-reader">, {status}</span>
<span className={css(styles.wizardNavLinkStatusIcon)}>
<ExclamationCircleIcon />
{status === WizardNavItemStatus.Error && <ExclamationCircleIcon />}
{status === WizardNavItemStatus.Success && <CheckCircleIcon />}
</span>
</>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/src/components/Wizard/WizardStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface WizardStepProps {
/** Replaces the step's footer. The step's footer takes precedance over the wizard's footer. */
footer?: React.ReactElement | Partial<WizardFooterProps>;
/** Used to determine icon next to the step's navigation item */
status?: 'default' | 'error';
status?: 'default' | 'error' | 'success';
/** Flag to determine whether parent steps can expand or not. Defaults to false. */
isExpandable?: boolean;
}
Expand Down
19 changes: 16 additions & 3 deletions packages/react-core/src/components/Wizard/WizardToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon';
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';

import { KeyTypes } from '../../helpers/constants';
import { WizardStepType, isWizardSubStep } from './types';
Expand Down Expand Up @@ -92,12 +93,24 @@ export const WizardToggle = ({
aria-expanded={isNavExpanded}
>
<span className={css(styles.wizardToggleList)}>
<span className={css(styles.wizardToggleListItem, isActiveStepStatus === 'error' && styles.modifiers.danger)}>
{isActiveStepStatus === 'error' ? (
<span
className={css(
styles.wizardToggleListItem,
isActiveStepStatus === 'error' && styles.modifiers.danger,
isActiveStepStatus === 'success' && styles.modifiers.success
)}
>
{isActiveStepStatus === 'error' && (
<span className={css(styles.wizardToggleStatusIcon)}>
<ExclamationCircleIcon />
</span>
) : (
)}
{isActiveStepStatus === 'success' && (
<span className={css(styles.wizardToggleStatusIcon)}>
<CheckCircleIcon />
</span>
)}
{isActiveStepStatus !== 'success' && isActiveStepStatus !== 'error' && (
<span className={css(styles.wizardToggleNum)}>{wizardToggleIndex}</span>
)}{' '}
{parentStep?.name || activeStep?.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ test(`Renders screen reader text and danger icon when status is error`, () => {
expect(screen.getByRole('button')).toHaveClass(styles.modifiers.danger);
expect(screen.getByText(', error')).toBeInTheDocument();
});

test(`Renders screen reader text and success icon when status is success`, () => {
render(<WizardNavItem status="success" />);
expect(screen.getByRole('button')).toHaveClass(styles.modifiers.success);
expect(screen.getByText(', success')).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ test('updates "navItem" in context when the value changes', () => {
test('updates "status" in context when the value changes', () => {
render(<WizardStep {...testStep} status="error" />);
expect(setStep).toHaveBeenCalledWith({ ...testStepProps, status: 'error', isVisited: true });
render(<WizardStep {...testStep} status="success" />);
expect(setStep).toHaveBeenCalledWith({ ...testStepProps, status: 'success', isVisited: true });
});
4 changes: 2 additions & 2 deletions packages/react-core/src/components/Wizard/examples/Wizard.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ If a `WizardStep` is passed a `body={null}` property, you must manually handle f

```

### Step error status
### Step status

```ts file="./WizardStepErrorStatus.tsx"
```ts file="./WizardStepStatus.tsx"

```

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';

import { Radio, Wizard, WizardStep } from '@patternfly/react-core';

interface SomeContextProps {
errorMessage: string | undefined;
setErrorMessage(error: string | undefined): void;
successMessage: string | undefined;
setSuccessMessage(error: string | undefined): void;
}
type SomeContextRenderProps = Pick<SomeContextProps, 'successMessage', 'errorMessage'>;
interface SomeContextProviderProps {
children: (context: SomeContextRenderProps) => React.ReactElement;
}

const SomeContext: React.Context<SomeContextProps> = React.createContext({} as SomeContextProps);

const SomeContextProvider = ({ children }: SomeContextProviderProps) => {
const [errorMessage, setErrorMessage] = React.useState<string>();
const [successMessage, setSuccessMessage] = React.useState<string>();

return (
<SomeContext.Provider value={{ errorMessage, setErrorMessage, successMessage, setSuccessMessage }}>
{children({ errorMessage, successMessage })}
</SomeContext.Provider>
);
};

const StepContentWithAction = () => {
const { errorMessage, setErrorMessage, successMessage, setSuccessMessage } = React.useContext(SomeContext);

return (
<>
<Radio
label="Give step 1 an error status"
isChecked={!!errorMessage}
onChange={(_event, checked) => {
setErrorMessage(checked ? 'Some error message' : undefined);
setSuccessMessage(!checked ? 'Some error message' : undefined);
}}
id="toggle-error-checkbox"
name="Toggle Status"
/>
<Radio
label="Give step 1 a success status"
isChecked={!!successMessage}
onChange={(_event, checked) => {
setSuccessMessage(checked ? 'Some success message' : undefined);
setErrorMessage(!checked ? 'Some success message' : undefined);
}}
id="toggle-success-checkbox"
name="Toggle Status"
/>
</>
);
};

export const WizardStepStatus: React.FunctionComponent = () => (
<SomeContextProvider>
{({ errorMessage, successMessage }) => {
let status = 'default';
if (errorMessage) {
status = 'error';
} else if (successMessage) {
status = 'success';
}
return (
<Wizard height={400} title="Step status wizard">
<WizardStep status={status} id="status-step-1" name="Step 1">
Step 1 content
</WizardStep>
<WizardStep name="Status step" id="error-status-step-2">
<StepContentWithAction />
</WizardStep>
<WizardStep name="Review" id="status-review-step" footer={{ nextButtonText: 'Finish' }}>
Review step content
</WizardStep>
</Wizard>
);
}}
</SomeContextProvider>
);
5 changes: 3 additions & 2 deletions packages/react-core/src/components/Wizard/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ export interface WizardBasicStep {
/** Replaces the step's footer. The step's footer takes precedance over the wizard's footer. */
footer?: React.ReactElement | Partial<WizardFooterProps>;
/** Used to determine icon next to the step's navItem */
status?: 'default' | 'error';
status?: 'default' | 'error' | 'success';
}

export enum WizardNavItemStatus {
Default = 'default',
Error = 'error'
Error = 'error',
Success = 'success'
}

/** Type for customizing a button (next, back or cancel) in a Wizard footer. It omits some props which either have a default value or are passed directly via WizardFooterProps. */
Expand Down
Loading
Loading