Skip to content

Commit

Permalink
migrated ProgressIndicator files to .tsx and updated screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
recondesigns committed Mar 6, 2024
1 parent cb7da78 commit 0fa81ac
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`UpdateProfileForm > should render with required props 1`] = `
Professional Details
</h3>
<div
className="flex flex-col my-6 mx-0 items-center"
className="flex flex-col items-center mx-0 my-6"
>
<label
htmlFor="steps-indicator"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import { number } from 'prop-types';

export const developmentErrors = {
currentStepTooLow: '"currentStep" cannot be negative',
currentStepTooHigh: '"currentStep" cannot be greater than "totalSteps"',
totalStepsTooLow: '"totalSteps" must be greater than zero',
};

const throwDevelopmentException = (expression, message) => {
const throwDevelopmentException = (expression: boolean, message: string) => {
if (process.env.NODE_ENV !== 'production' && expression) {
throw new Error(message);
}
};

ProgressIndicator.propTypes = {
stepNumber: number,
totalSteps: number,
};

ProgressIndicator.defaultProps = {
stepNumber: 0,
totalSteps: 1,
export type ProgressIndicatorPropsType = {
/**
* Sets the current step number.
*/
stepNumber: number;
/**
* Sets the total number of steps.
*/
totalSteps: number;
};

export default function ProgressIndicator({ stepNumber, totalSteps }) {
export default function ProgressIndicator({
stepNumber = 0,
totalSteps = 1,
}: ProgressIndicatorPropsType) {
throwDevelopmentException(totalSteps < 1, developmentErrors.totalStepsTooLow);
throwDevelopmentException(stepNumber < 0, developmentErrors.currentStepTooLow);
throwDevelopmentException(stepNumber > totalSteps, developmentErrors.currentStepTooHigh);

const percentageCompleted = (stepNumber / totalSteps) * 100;

return (
<div className="flex flex-col my-6 mx-0 items-center">
<div className="flex flex-col items-center mx-0 my-6">
<label htmlFor="steps-indicator">
{stepNumber}/{totalSteps} Complete
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Meta, StoryObj } from '@storybook/react';
import {
Title,
ArgTypes,
Expand All @@ -9,28 +10,10 @@ import {
} from '@storybook/blocks';
import ProgressIndicator from '../ProgressIndicator';

export const Default = {
render: args => <ProgressIndicator {...args} />,
};

export const TotalSteps = {
render: args => <ProgressIndicator {...args} />,
args: {
stepNumber: 0,
totalSteps: 100,
},
};

export const StepNumber = {
render: args => <ProgressIndicator {...args} />,
args: {
stepNumber: 40,
totalSteps: 100,
},
};
type ProgressIndicatorStoryType = StoryObj<typeof ProgressIndicator>;

const meta = {
title: 'Progress Indicator',
const meta: Meta<typeof ProgressIndicator> = {
title: 'ProgressIndicator',
component: ProgressIndicator,
argTypes: {
stepNumber: {
Expand Down Expand Up @@ -90,3 +73,23 @@ const meta = {
};

export default meta;

export const Default: ProgressIndicatorStoryType = {
render: args => <ProgressIndicator {...args} />,
};

export const TotalSteps: ProgressIndicatorStoryType = {
...Default,
args: {
stepNumber: 0,
totalSteps: 100,
},
};

export const StepNumber: ProgressIndicatorStoryType = {
...Default,
args: {
stepNumber: 40,
totalSteps: 100,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`ProgressIndicator > should render with required props 1`] = `
<div
className="flex flex-col my-6 mx-0 items-center"
className="flex flex-col items-center mx-0 my-6"
>
<label
htmlFor="steps-indicator"
Expand Down

0 comments on commit 0fa81ac

Please sign in to comment.