Skip to content

Commit 2df5c1e

Browse files
committed
adds LGIDs
1 parent cbb87fe commit 2df5c1e

File tree

6 files changed

+41
-13
lines changed

6 files changed

+41
-13
lines changed

packages/wizard/src/Wizard/Wizard.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ import {
77
import { useControlled } from '@leafygreen-ui/hooks';
88

99
import { WizardSubComponentProperties } from '../constants';
10+
import { getLgIds } from '../utils/getLgIds';
1011
import { WizardProvider } from '../WizardContext/WizardContext';
1112
import { WizardFooter } from '../WizardFooter';
1213
import { WizardStep } from '../WizardStep';
1314

1415
import { WizardProps } from './Wizard.types';
1516

1617
export const Wizard = CompoundComponent(
17-
({ activeStep: activeStepProp, onStepChange, children }: WizardProps) => {
18+
({
19+
activeStep: activeStepProp,
20+
onStepChange,
21+
children,
22+
'data-lgid': dataLgId,
23+
}: WizardProps) => {
24+
const lgIds = getLgIds(dataLgId);
1825
const stepChildren = findChildren(
1926
children,
2027
WizardSubComponentProperties.Step,
@@ -48,7 +55,11 @@ export const Wizard = CompoundComponent(
4855
);
4956

5057
return (
51-
<WizardProvider activeStep={activeStep} updateStep={updateStep}>
58+
<WizardProvider
59+
activeStep={activeStep}
60+
updateStep={updateStep}
61+
lgIds={lgIds}
62+
>
5263
{stepChildren.map((child, i) => (i === activeStep ? child : null))}
5364
</WizardProvider>
5465
);

packages/wizard/src/Wizard/Wizard.types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ReactNode } from 'react';
22

3-
export interface WizardProps {
3+
import { LgIdProps } from '@leafygreen-ui/lib';
4+
5+
export interface WizardProps extends LgIdProps {
46
/**
57
* The current active step index (0-based).
68
* If provided, the component operates in controlled mode, and any interaction will not update internal state.

packages/wizard/src/WizardContext/WizardContext.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React, { createContext, PropsWithChildren, useContext } from 'react';
22

3+
import { getLgIds } from '../utils/getLgIds';
4+
import { GetLgIdsReturnType } from '../utils/getLgIds';
5+
36
export interface WizardContextData {
47
isWizardContext: boolean;
58
activeStep: number;
@@ -11,12 +14,14 @@ export interface WizardContextData {
1114
* @returns
1215
*/
1316
updateStep: (step: number) => void;
17+
lgIds: GetLgIdsReturnType;
1418
}
1519

1620
export const WizardContext = createContext<WizardContextData>({
1721
isWizardContext: false,
1822
activeStep: 0,
1923
updateStep: () => {},
24+
lgIds: getLgIds('lg-wizard'),
2025
});
2126

2227
interface WizardProviderProps
@@ -26,13 +31,15 @@ export const WizardProvider = ({
2631
children,
2732
activeStep,
2833
updateStep,
34+
lgIds = getLgIds('lg-wizard'),
2935
}: WizardProviderProps) => {
3036
return (
3137
<WizardContext.Provider
3238
value={{
3339
isWizardContext: true,
3440
activeStep,
3541
updateStep,
42+
lgIds,
3643
}}
3744
>
3845
{children}

packages/wizard/src/WizardFooter/WizardFooter.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export const WizardFooter = CompoundSubComponent(
1818
className,
1919
...rest
2020
}: WizardFooterProps) => {
21-
const { isWizardContext, activeStep, updateStep } = useWizardContext();
21+
const { isWizardContext, activeStep, updateStep, lgIds } =
22+
useWizardContext();
2223
const { isAcknowledged, requiresAcknowledgement } = useWizardStepContext();
2324
const isPrimaryButtonDisabled =
2425
(requiresAcknowledgement && !isAcknowledged) ||
@@ -48,6 +49,7 @@ export const WizardFooter = CompoundSubComponent(
4849
<FormFooter
4950
{...rest}
5051
className={className}
52+
data-lgid={lgIds.footer}
5153
backButtonProps={
5254
activeStep > 0
5355
? {

packages/wizard/src/WizardStep/WizardStep.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { WizardStepProvider } from './WizardStepContext';
1717
export const WizardStep = CompoundSubComponent(
1818
({ children, requiresAcknowledgement = false }: WizardStepProps) => {
1919
const stepId = useIdAllocator({ prefix: 'wizard-step' });
20-
const { isWizardContext } = useWizardContext();
20+
const { isWizardContext, lgIds } = useWizardContext();
2121

2222
if (!isWizardContext) {
2323
consoleOnce.error(
@@ -36,13 +36,15 @@ export const WizardStep = CompoundSubComponent(
3636
]);
3737

3838
return (
39-
<WizardStepProvider
40-
stepId={stepId}
41-
requiresAcknowledgement={requiresAcknowledgement}
42-
>
43-
{restChildren}
44-
{footerChild}
45-
</WizardStepProvider>
39+
<div data-lgid={lgIds.step}>
40+
<WizardStepProvider
41+
stepId={stepId}
42+
requiresAcknowledgement={requiresAcknowledgement}
43+
>
44+
{restChildren}
45+
{footerChild}
46+
</WizardStepProvider>
47+
</div>
4648
);
4749
},
4850
{

packages/wizard/src/utils/getLgIds.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ export const DEFAULT_LGID_ROOT = 'lg-wizard';
44

55
export const getLgIds = (root: LgIdString = DEFAULT_LGID_ROOT) => {
66
const ids = {
7-
root,
7+
step: `${root}-step`,
8+
footer: `${root}-footer`,
9+
footerPrimaryButton: `${root}-footer-primary_button`,
10+
footerBackButton: `${root}-footer-back_button`,
11+
footerCancelButton: `${root}-footer-cancel_button`,
812
} as const;
913
return ids;
1014
};

0 commit comments

Comments
 (0)