Skip to content

Commit

Permalink
Update stepper storybook example and extend div props on MdStep (#197)
Browse files Browse the repository at this point in the history
* Update stepper storybook example and extend div props on MdStep

* avoid passing completedCOntent to the dom element

* undo changes ti stepper.css
  • Loading branch information
aurorascharff authored Nov 14, 2024
1 parent aa8e5f1 commit eb50eec
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
10 changes: 7 additions & 3 deletions packages/react/src/stepper/MdStep.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from 'react';

export interface MdStepProps {
export interface MdStepProps extends React.HTMLAttributes<HTMLDivElement> {
title: string;
children: React.ReactNode;
completedContent?: React.ReactNode;
}

const MdStep: React.FunctionComponent<MdStepProps> = ({ children }: MdStepProps) => {
return <div>{children}</div>;
const MdStep: React.FunctionComponent<MdStepProps> = ({ children, ...otherProps }: MdStepProps) => {
// Destructure the title and completedContent props from the otherProps object
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { title, completedContent, ...rest } = otherProps;

return <div {...rest}>{children}</div>;
};

export default MdStep;
62 changes: 42 additions & 20 deletions stories/Stepper.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Title, Subtitle, Description, Controls, Primary, Markdown } from '@storybook/addon-docs';
import { useArgs } from '@storybook/client-api';
import React from 'react';

import Readme from '../packages/css/src/stepper/README.md';
import MdButton from '../packages/react/src/button/MdButton';
import MdChevronIcon from '../packages/react/src/icons/MdChevronIcon';
import MdStep from '../packages/react/src/stepper/MdStep';
import MdStepper from '../packages/react/src/stepper/MdStepper';
import type { Args, StoryFn } from '@storybook/react';
Expand Down Expand Up @@ -97,44 +97,66 @@ export const Stepper: StoryFn<typeof MdStepper> = (args: Args) => {
updateArgs({ activeStep: args.activeStep - 1 });
};

const stepContentStyle: React.CSSProperties = {
display: 'flex',
flexDirection: 'column',
gap: '0.5rem',
};

const buttonStyle: React.CSSProperties = {
display: 'flex',
flexDirection: 'row',
gap: '1rem',
};

const fontStyle: React.CSSProperties = {
fontFamily: 'Open sans',
};

return (
<>
<MdStepper activeStep={args.activeStep}>
<MdStep
style={fontStyle}
title="Step 1"
completedContent={
<>
<div style={fontStyle}>
This is a completed step, which can be shown differently if the &quot;completedContent&quot; prop is
provided
</>
provided.
</div>
}
>
<div>
This is a step
<MdButton onClick={nextStep} small>
Next
<div style={stepContentStyle}>
This is a step.
<MdButton rightIcon={<MdChevronIcon />} onClick={nextStep}>
Go to step 2
</MdButton>
</div>
</MdStep>
<MdStep
title="Step 2"
completedContent={<>This is what Step 2 looks like when completed, this is completely customizable!</>}
style={fontStyle}
completedContent={
<div style={fontStyle}>This is what Step 2 looks like when completed, this is completely customizable!</div>
}
>
<div>
<div style={stepContentStyle}>
This is the content of a MdStep. It can contain anything you want, text or HTML.
<p>Here is a paragraph!</p>
<MdButton onClick={nextStep} small>
Next
</MdButton>
<MdButton onClick={prevStep} theme="secondary" small>
Previous
</MdButton>
<div style={buttonStyle}>
<MdButton onClick={prevStep} theme="secondary">
Previous
</MdButton>
<MdButton rightIcon={<MdChevronIcon />} onClick={nextStep}>
Go to step 3
</MdButton>
</div>
</div>
</MdStep>
<MdStep title="Step 3">
<div>
This is the last step in this example
<MdButton onClick={prevStep} theme="secondary" small>
<MdStep style={fontStyle} title="Step 3">
<div style={stepContentStyle}>
This is the last step in this example.
<MdButton onClick={prevStep} theme="secondary">
Previous
</MdButton>
</div>
Expand Down

0 comments on commit eb50eec

Please sign in to comment.