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
1 change: 1 addition & 0 deletions packages/wizard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"dependencies": {
"@leafygreen-ui/button": "workspace:^",
"@leafygreen-ui/compound-component": "workspace:^",
"@leafygreen-ui/descendants": "workspace:^",
"@leafygreen-ui/emotion": "workspace:^",
"@leafygreen-ui/form-footer": "workspace:^",
Expand Down
49 changes: 25 additions & 24 deletions packages/wizard/src/Wizard/Wizard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import React, { useCallback } from 'react';

import {
CompoundComponent,
findChild,
findChildren,
} from '@leafygreen-ui/compound-component';
import { Direction } from '@leafygreen-ui/descendants';
import { findChild, findChildren } from '@leafygreen-ui/lib';
import { useControlled } from '@leafygreen-ui/hooks';

import { WizardSubComponentProperties } from '../constants';
import { CompoundComponent } from '../utils/CompoundComponent';
import { useWizardControlledValue } from '../utils/useWizardControlledValue/useWizardControlledValue';
import { WizardProvider } from '../WizardContext/WizardContext';
import { WizardFooter } from '../WizardFooter';
import { WizardStep } from '../WizardStep';
Expand All @@ -30,11 +33,8 @@ export const Wizard = CompoundComponent(
);

// Controlled/Uncontrolled activeStep value
const {
isControlled,
value: activeStep,
setValue: setActiveStep,
} = useWizardControlledValue<number>(activeStepProp, undefined, 0);
const { value: activeStep, updateValue: setActiveStep } =
useControlled<number>(activeStepProp, onStepChange, 0);

if (
activeStepProp &&
Expand All @@ -47,22 +47,23 @@ export const Wizard = CompoundComponent(
);
}

const updateStep = (direction: Direction) => {
const getNextStep = (curr: number) => {
switch (direction) {
case Direction.Next:
return Math.min(curr + 1, stepChildren.length - 1);
case Direction.Prev:
return Math.max(curr - 1, 0);
}
};
const updateStep = useCallback(
(direction: Direction) => {
const getNextStep = (curr: number) => {
switch (direction) {
case Direction.Next:
return Math.min(curr + 1, stepChildren.length - 1);
case Direction.Prev:
return Math.max(curr - 1, 0);
}
};

if (!isControlled) {
setActiveStep(getNextStep);
}

onStepChange?.(getNextStep(activeStep));
};
// TODO pass getNextStep into setter as callback https://jira.mongodb.org/browse/LG-5607
const nextStep = getNextStep(activeStep);
setActiveStep(nextStep);
},
[activeStep, setActiveStep, stepChildren.length],
);

// Get the current step to render
const currentStep = stepChildren[activeStep] || null;
Expand Down
2 changes: 1 addition & 1 deletion packages/wizard/src/WizardFooter/WizardFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { MouseEventHandler } from 'react';

import { CompoundSubComponent } from '@leafygreen-ui/compound-component';
import { Direction } from '@leafygreen-ui/descendants';
import { FormFooter } from '@leafygreen-ui/form-footer';
import { consoleOnce } from '@leafygreen-ui/lib';

import { WizardSubComponentProperties } from '../constants';
import { CompoundSubComponent } from '../utils/CompoundSubComponent';
Comment on lines +3 to -8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { useWizardContext } from '../WizardContext';

import { WizardFooterProps } from './WizardFooter.types';
Expand Down
2 changes: 1 addition & 1 deletion packages/wizard/src/WizardStep/WizardStep.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';

import { CompoundSubComponent } from '@leafygreen-ui/compound-component';
import { cx } from '@leafygreen-ui/emotion';
import { consoleOnce } from '@leafygreen-ui/lib';
import { Description, H3 } from '@leafygreen-ui/typography';

import { WizardSubComponentProperties } from '../constants';
import { CompoundSubComponent } from '../utils/CompoundSubComponent';
import { useWizardContext } from '../WizardContext';

import { TextNode } from './TextNode';
Expand Down
27 changes: 0 additions & 27 deletions packages/wizard/src/utils/CompoundComponent.tsx

This file was deleted.

41 changes: 0 additions & 41 deletions packages/wizard/src/utils/CompoundSubComponent.tsx

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 6 additions & 0 deletions packages/wizard/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"include": ["src/**/*"],
"exclude": ["**/*.spec.*", "**/*.stories.*"],
"references": [
{
"path": "../button"
},
{
"path": "../compound-component"
},
{
"path": "../button"
},
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading