Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stepper component #1757

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
52 changes: 52 additions & 0 deletions src/components/Stepper/Stepper.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import Stepper from './index';

const meta = {
title: 'Pending Review/Stepper',
component: Stepper,
argTypes: {
children: { control: false },
},
} satisfies Meta<typeof Stepper>;

export default meta;

type Story = StoryObj<typeof meta>;

const steps = [
{ id: 1, label: 'Overview' },
{ id: 2, label: 'Targeting' },
{ id: 3, label: 'Measure' },
];

const DefaultStepper = () => {
const [activeStep, setActiveStep] = React.useState(1);
return (
<Stepper>
{steps.map((step, index) => (
<Stepper.Step
key={step.id}
id={step.id}
label={step.label}
isActive={step.id === activeStep}
stepIndex={index}
onClick={() => setActiveStep(step.id)}
/>
))}
</Stepper>
);
};

export const Default: Story = {
args: {
children: (
<>
<Stepper.Step id={1} />
</>
),
},

render: () => <DefaultStepper />,
};
29 changes: 29 additions & 0 deletions src/components/Stepper/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';

export type StepId = string | number;
export type StepLabel = string | React.ReactNode;

export interface StepperStepProps {
id: StepId;
onClick?: (...args: any[]) => any;
label?: StepLabel;
disabled?: boolean;
isActive?: boolean;
isCompleted?: boolean;
children?: React.ReactNode;
className?: string;
stepIndex?: number;
}

declare const StepperStep: React.FC<StepperStepProps>;

export interface StepperProps {
children: React.ReactNode;
dts?: string;
}

declare const Stepper: React.FC<StepperProps> & {
Step: typeof StepperStep;
};

export default Stepper;
80 changes: 80 additions & 0 deletions src/components/Stepper/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';
import _ from 'lodash';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { expandDts } from '../../utils';
import './styles.css';

const StepperStep = ({

Check warning on line 8 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L8

Added line #L8 was not covered by tests
id,
label = '',

Check warning on line 10 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L10

Added line #L10 was not covered by tests
children,
disabled = false,

Check warning on line 12 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L12

Added line #L12 was not covered by tests
stepIndex,
onClick,

isActive,
isCompleted,
className,
}) => {
const classNames = classnames(

Check warning on line 20 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L19-L20

Added lines #L19 - L20 were not covered by tests
'aui--step',
{
active: isActive,
completed: isCompleted,
disabled: disabled,
},
className
);

return (
<div className={classNames} onClick={() => (disabled ? _.noop : onClick(id))}>
<div className="aui--step-item">{children ? children : stepIndex + 1}</div>
{!!label && <p className="aui--step-label">{label}</p>}

Check warning on line 33 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L30-L33

Added lines #L30 - L33 were not covered by tests
</div>
);
};

StepperStep.propTypes = {

Check warning on line 38 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L38

Added line #L38 was not covered by tests
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
onClick: PropTypes.func,
disabled: PropTypes.bool,
isActive: PropTypes.bool,
isCompleted: PropTypes.bool,
children: PropTypes.node,
className: PropTypes.string,
stepIndex: PropTypes.number,
};

StepperStep.defaultProps = {

Check warning on line 50 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L50

Added line #L50 was not covered by tests
disabled: false,
};

const Stepper = ({ children, dts, size = 'medium' }) => {
return (

Check warning on line 55 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L54-L55

Added lines #L54 - L55 were not covered by tests
<div className={`aui--stepper aui-${size}`} data-testid="stepper-component" {...expandDts(dts)}>
{React.Children.map(children, (child, index) => {
return React.cloneElement(child, {

Check warning on line 58 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L57-L58

Added lines #L57 - L58 were not covered by tests
key: index,
stepIndex: index,
...child.props,
});
})}
</div>
);
};
export const sizes = ['small', 'medium', 'large'];

Check warning on line 67 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L67

Added line #L67 was not covered by tests

Stepper.propTypes = {

Check warning on line 69 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L69

Added line #L69 was not covered by tests
children: PropTypes.node.isRequired,
dts: PropTypes.string,
/**
* Controls the width for the stepper.
*/
size: PropTypes.oneOf(sizes),
};

Stepper.Step = StepperStep;

Check warning on line 78 in src/components/Stepper/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Stepper/index.jsx#L78

Added line #L78 was not covered by tests

export default Stepper;
68 changes: 68 additions & 0 deletions src/components/Stepper/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.aui--stepper {
display: flex;
width: 400px;

/* &.aui-large {
width: 100%;
} */

/*
&.aui-small {
width: calc(100% / 3);
} */
}

.aui--step {
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

/* width: 100%;
*/
flex: 1;
}

.aui--step:not(:first-child)::before {
content: '';
background-color: #cbd5e0;
position: absolute;
width: 100%;
height: 2px;
right: 50%;

/* half of step height */
top: 20px;
transform: translateY(-50%);
}

/* TODO: deal with icon fill color */
.aui--step-item {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
position: relative;
border-radius: 9999px;
font-weight: 600;
color: #1c1d1f;
background-color: #ebeef2;
cursor: pointer;

/* todo: box-shadow */

/* hover? */
}

.active .aui--step-item {
background-color: #1c1d1f;
color: #fff;
}

.completed:not(:first-child)::before,
.active:not(:first-child)::before {
background-color: #0b0c0c;
}
Loading