Skip to content

Commit

Permalink
Merge pull request #11 from tableflowhq/stepper-component-update-wide…
Browse files Browse the repository at this point in the history
…r--line-space

Update Stepper component to make width dependent on number of items
  • Loading branch information
ciminelli authored Aug 28, 2023
2 parents 9f8c906 + ec49a97 commit 0f77227
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/Stepper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@ import style from "./style/Stepper.module.scss";
import Icon from "../Icon";

export default function Stepper({ steps, current, clickable, setCurrent }: StepperProps) {
return (
<div className={style.stepper}>
{steps.map((step, i) => {
const done = i < current;
return (
<div className={style.stepper}>
{steps.map((step, i) => {
const done = i < current;

const Element = clickable ? "button" : "div";
const Element = clickable ? "button" : "div";

const buttonProps: any = clickable
? {
onClick: () => setCurrent(i),
type: "button",
}
: {};
const buttonProps: any = clickable
? {
onClick: () => setCurrent(i),
type: "button",
}
: {};

return (
<Element key={i} className={classes([style.step, i === current ? style.active : done && style.done])} {...buttonProps}>
<div className={style.badge}>{done ? <Icon icon="check" /> : i + 1}</div>
<div className={style.label}>{step.label}</div>
</Element>
);
})}
</div>
);
return (
<Element
key={i}
className={classes([style.step, i === current ? style.active : done && style.done, steps.length < 4 && style.stepWide])}
{...buttonProps}>
<div className={style.badge}>{done ? <Icon icon="check" /> : i + 1}</div>
<div className={style.label}>{step.label}</div>
</Element>
);
})}
</div>
);
}
8 changes: 8 additions & 0 deletions src/Stepper/style/Stepper.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@
}
}
}

.stepWide {
&:not(:first-of-type) {
&:before {
width: min(120px, 10vw);
}
}
}
}

0 comments on commit 0f77227

Please sign in to comment.