Skip to content

Commit d1a70a9

Browse files
committed
updating types export, including all exported interfaces in 'React next' doc for Wizard
1 parent 5982c3f commit d1a70a9

11 files changed

Lines changed: 49 additions & 53 deletions

File tree

packages/react-core/src/next/components/Wizard/WizardContext.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
2-
import { Step, SubStep } from './types';
2+
import { WizardControlStep } from './types';
33
import { getActiveStep } from './utils';
44

55
export interface WizardContextProps {
66
/** List of steps */
7-
steps: (Step | SubStep)[];
7+
steps: WizardControlStep[];
88
/** Active step */
9-
activeStep: Step | SubStep;
9+
activeStep: WizardControlStep;
1010
/** Footer element */
1111
footer: React.ReactElement;
1212
/** Navigate to the next step */
@@ -28,16 +28,16 @@ export interface WizardContextProps {
2828
export const WizardContext = React.createContext({} as WizardContextProps);
2929

3030
interface WizardContextRenderProps {
31-
steps: (Step | SubStep)[];
32-
activeStep: Step | SubStep;
31+
steps: WizardControlStep[];
32+
activeStep: WizardControlStep;
3333
footer: React.ReactElement;
3434
onNext(): void;
3535
onBack(): void;
3636
onClose(): void;
3737
}
3838

3939
export interface WizardContextProviderProps {
40-
steps: (Step | SubStep)[];
40+
steps: WizardControlStep[];
4141
currentStepIndex: number;
4242
footer: React.ReactElement;
4343
children: React.ReactElement | ((props: WizardContextRenderProps) => React.ReactElement);

packages/react-core/src/next/components/Wizard/WizardFooter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { css } from '@patternfly/react-styles';
44
import styles from '@patternfly/react-styles/css/components/Wizard/wizard';
55

66
import { Button, ButtonVariant } from '../../../components/Button';
7-
import { Step, SubStep, WizardNavStepFunction } from './types';
7+
import { WizardControlStep, WizardNavStepFunction } from './types';
88

99
/**
1010
* Hosts the standard structure of a footer with ties to the active step so that text for buttons can vary from step to step.
1111
*/
1212

1313
export interface WizardFooterProps {
1414
/** The currently active WizardStep */
15-
activeStep: Step | SubStep;
15+
activeStep: WizardControlStep;
1616
/** Next button callback */
1717
onNext(): WizardNavStepFunction | void;
1818
/** Back button callback */

packages/react-core/src/next/components/Wizard/WizardStep.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React from 'react';
22

3-
import { Step } from './types';
3+
import { WizardControlStep } from './types';
44
import { WizardBody, WizardBodyProps } from './WizardBody';
55

66
/**
77
* Used as a passthrough of step properties for Wizard and all supporting child components.
88
* Also acts as a wrapper for content, with an optional inclusion of WizardBody.
99
*/
1010

11-
export interface WizardStepProps extends Omit<Step, 'parentId' | 'subStepIds' | 'visited'> {
12-
/** Optional for when the Step is used as a parent to sub-steps */
11+
export interface WizardStepProps extends Omit<WizardControlStep, 'parentId' | 'subStepIds' | 'visited'> {
12+
/** Optional for when the step is used as a parent to sub-steps */
1313
children?: React.ReactNode;
1414
/** Props for WizardBody that wraps content by default. Can be set to null for exclusion of WizardBody. */
1515
body?: WizardBodyProps | null;

packages/react-core/src/next/components/Wizard/WizardToggle.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-ico
88
import { KeyTypes } from '../../../helpers/constants';
99
import { WizardNav, WizardNavItem } from '../../../components/Wizard';
1010
import {
11-
Step,
12-
SubStep,
13-
isWizardSubStep,
14-
isCustomWizardNav,
11+
WizardControlStep,
1512
CustomWizardNavFunction,
1613
DefaultWizardNavProps,
1714
isWizardBasicStep,
18-
isWizardParentStep
15+
isWizardParentStep,
16+
isWizardSubStep,
17+
isCustomWizardNav
1918
} from './types';
2019

2120
/**
@@ -24,9 +23,9 @@ import {
2423

2524
export interface WizardToggleProps {
2625
/** List of steps and/or sub-steps */
27-
steps: (Step | SubStep)[];
26+
steps: WizardControlStep[];
2827
/** The currently active WizardStep */
29-
activeStep: Step | SubStep;
28+
activeStep: WizardControlStep;
3029
/** The WizardFooter */
3130
footer: React.ReactElement;
3231
/** Custom WizardNav or callback used to create a default WizardNav */

packages/react-core/src/next/components/Wizard/__tests__/Wizard.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { render, screen } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
55

66
import { WizardNav, WizardNavItem } from '../../../../components/Wizard';
7-
import { DefaultWizardNavProps, Step, SubStep } from '../types';
8-
import { DefaultWizardFooterProps, Wizard, WizardStep } from '..';
7+
import { DefaultWizardNavProps, WizardControlStep, DefaultWizardFooterProps } from '../types';
8+
import { Wizard, WizardStep } from '..';
99

1010
describe('Wizard', () => {
1111
it('renders step when child is of type WizardStep', () => {
@@ -123,8 +123,8 @@ describe('Wizard', () => {
123123
it('renders custom nav', () => {
124124
const nav = (
125125
isOpen: boolean,
126-
steps: (Step | SubStep)[],
127-
activeStep: Step | SubStep,
126+
steps: WizardControlStep[],
127+
activeStep: WizardControlStep,
128128
goToStepByIndex: (index: number) => void
129129
) => (
130130
<WizardNav isOpen={isOpen}>

packages/react-core/src/next/components/Wizard/examples/Wizard.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: Wizard
33
section: components
44
cssPrefix: pf-c-wizard
5-
propComponents: ['Wizard', 'WizardStep', 'WizardFooter', 'WizardToggle', 'WizardStep', 'WizardBody', 'WizardContextProps', 'Step', 'SubStep']
5+
propComponents: ['Wizard', 'WizardStep', 'WizardFooter', 'WizardToggle', 'WizardStep', 'WizardBody', 'WizardContextProps', 'WizardBasicStep', 'WizardParentStep', 'WizardSubStep', 'DefaultWizardNavProps', 'DefaultWizardFooterProps']
66
beta: true
77
---
88

packages/react-core/src/next/components/Wizard/examples/WizardCustomNav.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22
import { WizardNav, WizardNavItem } from '@patternfly/react-core';
3-
import { Wizard, WizardStep, Step, SubStep } from '@patternfly/react-core/next';
3+
import { Wizard, WizardStep, WizardControlStep } from '@patternfly/react-core/next';
44

55
export const WizardCustomNav: React.FunctionComponent = () => {
66
const nav = (
77
isOpen: boolean,
8-
steps: (Step | SubStep)[],
9-
activeStep: Step | SubStep,
8+
steps: WizardControlStep[],
9+
activeStep: WizardControlStep,
1010
goToStepByIndex: (index: number) => void
1111
) => (
1212
<WizardNav isOpen={isOpen}>

packages/react-core/src/next/components/Wizard/examples/WizardKitchenSink.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import {
1616
WizardHeader
1717
} from '@patternfly/react-core';
1818
import {
19-
Step,
2019
Wizard,
2120
WizardStep,
2221
WizardBody,
2322
WizardFooter,
24-
useWizardFooter,
2523
WizardStepProps,
24+
WizardControlStep,
25+
useWizardFooter,
2626
useWizardContext
2727
} from '@patternfly/react-core/next';
2828
import { css } from '@patternfly/react-styles';
@@ -35,7 +35,7 @@ const CustomWizardFooter = () => {
3535

3636
const CustomNavItem = () => {
3737
const { steps, activeStep, goToStepByIndex } = useWizardContext();
38-
const step = (steps.find(step => step.id === 'third-step') || {}) as Step;
38+
const step = (steps.find(step => step.id === 'third-step') || {}) as WizardControlStep;
3939

4040
return (
4141
<WizardNavItem

packages/react-core/src/next/components/Wizard/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@ export * from './WizardFooter';
44
export * from './WizardToggle';
55
export * from './WizardStep';
66
export * from './hooks';
7+
export * from './types';
78
export { useWizardContext } from './WizardContext';
8-
9-
import * as Types from './types';
10-
export type Step = Types.Step;
11-
export type SubStep = Types.SubStep;

packages/react-core/src/next/components/Wizard/types.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
22
import { WizardNavItemProps, WizardNavProps } from '../../../components/Wizard';
33

4-
/** Initially inferred from WizardStep components, these properties represent what is controllable from within WizardContext for a given step. */
5-
6-
export interface Step {
4+
export interface WizardBasicStep {
75
/** Name of the step's nav item */
86
name: React.ReactNode;
97
/** Unique identifier */
@@ -14,8 +12,6 @@ export interface Step {
1412
visited?: boolean;
1513
/** Content shown when the step's nav item is selected. When treated as a parent step, only sub-step content will be shown. */
1614
component?: React.ReactElement;
17-
/** Nested step IDs */
18-
subStepIds?: string[];
1915
/** (Unused if nav is controlled) Custom WizardNavItem */
2016
navItem?: React.ReactElement<WizardNavItemProps>;
2117
/** (Unused if footer is controlled) Can change the Next button text. If nextButtonText is also set for the Wizard, this step specific one overrides it. */
@@ -28,14 +24,18 @@ export interface Step {
2824
hideBackButton?: boolean;
2925
}
3026

31-
/** With the same purpose as Step, SubStep inherits all properties of Step with the exception of subStepIds. */
27+
export interface WizardParentStep extends WizardBasicStep {
28+
/** Nested step IDs */
29+
subStepIds?: string[];
30+
}
3231

33-
export interface SubStep extends Omit<Step, 'subStepIds'> {
32+
export interface WizardSubStep extends WizardBasicStep {
3433
/** Unique identifier of the parent step */
3534
parentId?: string | number;
3635
}
3736

38-
export type WizardNavStepData = Pick<Step | SubStep, 'id' | 'name'>;
37+
export type WizardControlStep = WizardBasicStep | WizardParentStep | WizardSubStep;
38+
export type WizardNavStepData = Pick<WizardControlStep, 'id' | 'name'>;
3939
export type WizardNavStepFunction = (currentStep: WizardNavStepData, previousStep: WizardNavStepData) => void;
4040

4141
export interface DefaultWizardNavProps {
@@ -60,8 +60,8 @@ export interface DefaultWizardFooterProps {
6060

6161
export type CustomWizardNavFunction = (
6262
isOpen: boolean,
63-
steps: (Step | SubStep)[],
64-
activeStep: Step | SubStep,
63+
steps: WizardControlStep[],
64+
activeStep: WizardControlStep,
6565
goToStepByIndex: (index: number) => void
6666
) => React.ReactElement<WizardNavProps>;
6767

@@ -77,14 +77,14 @@ export function isCustomWizardFooter(
7777
return React.isValidElement(footer);
7878
}
7979

80-
export function isWizardBasicStep(step: Step | SubStep): step is Step {
81-
return (step as Step)?.subStepIds === undefined && !isWizardSubStep(step);
80+
export function isWizardBasicStep(step: WizardControlStep): step is WizardBasicStep {
81+
return (step as WizardParentStep)?.subStepIds === undefined && !isWizardSubStep(step);
8282
}
8383

84-
export function isWizardSubStep(step: Step | SubStep): step is SubStep {
85-
return (step as SubStep)?.parentId !== undefined;
84+
export function isWizardSubStep(step: WizardControlStep): step is WizardSubStep {
85+
return (step as WizardSubStep)?.parentId !== undefined;
8686
}
8787

88-
export function isWizardParentStep(step: Step | SubStep): step is Step {
89-
return (step as Step)?.subStepIds !== undefined;
88+
export function isWizardParentStep(step: WizardControlStep): step is WizardParentStep {
89+
return (step as WizardParentStep)?.subStepIds !== undefined;
9090
}

0 commit comments

Comments
 (0)