Skip to content

Hov 100 | Stepper Component Refactor #172

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

Open
wants to merge 6 commits into
base: main
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
91 changes: 83 additions & 8 deletions docs/docs/components/stepper.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ Here's a quick start guide to get started with the Stepper component.

### Importing Component

import { Stepper, StepperStep, Card } from "@hover-design/react";
import { Stepper, StepperStep, Card, Flex } from "@hover-design/react";
import { StepperExample } from "@site/src/components/examples/StepperExample";

export const StepperContainer = ({ children }) => (
<Card variant="shadow">{children}</Card>
<Flex alignItems="center" justifyContent="center">
<Card variant="shadow">{children}</Card>
</Flex>
);

```jsx
Expand All @@ -24,15 +27,26 @@ import { Stepper, StepperStep } from "@hover-design/react";
import { Stepper, StepperStep } from "@hover-design/react";

const Demo = () => {
const [active, setActive] = useState(1);
const nextStep = () =>
setActive((current) => (current < 3 ? current + 1 : current));
const prevStep = () =>
setActive((current) => (current > 0 ? current - 1 : current));
const [activeStep, setActiveStep] = useState(1);

return (
<div>
<Stepper onStepClick={setActive} activeStep={active}>
<Stepper onStepClick={setActiveStep} activeStep={activeStep}>
<StepperStep>
<label>Step 1</label>
</StepperStep>
<StepperStep>
<label>Step 2</label>
</StepperStep>
<StepperStep>
<label>Step 3</label>
</StepperStep>
</Stepper>
<Stepper
onStepClick={setActiveStep}
activeStep={activeStep}
labelOrientation="vertical"
>
<StepperStep>
<label>Step 1</label>
</StepperStep>
Expand All @@ -48,6 +62,67 @@ const Demo = () => {
};
```

<Flex alignItems="center" justifyContent="space-around" >
<StepperContainer>
<StepperExample />
</StepperContainer>

<StepperContainer>
<StepperExample StepperProps={{ labelOrientation: "vertical" }} />
</StepperContainer>
</Flex>

##### Stepper with orientation

```jsx
<div>
<Stepper
onStepClick={setActiveStep}
activeStep={activeStep}
orientation="vertical"
>
<StepperStep>
<label>Step 1</label>
</StepperStep>
<StepperStep>
<label>Step 2</label>
</StepperStep>
<StepperStep>
<label>Step 3</label>
</StepperStep>
</Stepper>

<Stepper
onStepClick={setActiveStep}
activeStep={activeStep}
orientation="vertical"
labelOrientation="vertical"
>
<StepperStep>
<label>Step 1</label>
</StepperStep>
<StepperStep>
<label>Step 2</label>
</StepperStep>
<StepperStep>
<label>Step 3</label>
</StepperStep>
</Stepper>
</div>
```

<Flex alignItems="center" justifyContent="space-around" >
<StepperContainer>
<StepperExample StepperProps={{ orientation: "vertical" }} />
</StepperContainer>

<StepperContainer>
<StepperExample
StepperProps={{ orientation: "vertical", labelOrientation: "vertical" }}
/>
</StepperContainer>
</Flex>

### Stepper Props Reference

| Key | type | Optional? |
Expand Down
30 changes: 30 additions & 0 deletions docs/src/components/examples/StepperExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
IStepperProps,
IStepperStepProps,
Stepper,
StepperStep
} from "@hover-design/react";

import React, { useState } from "react";

const StepperExample = ({
StepperProps,
StepperStepProps
}: {
StepperProps?: Omit<IStepperProps, "ref">;
StepperStepProps?: Omit<IStepperStepProps, "ref">;
}) => {
const [active, setActive] = useState(1);

return (
<div>
<Stepper activeStep={active} onStepClick={setActive} {...StepperProps}>
<StepperStep {...StepperStepProps}>Step 1</StepperStep>
<StepperStep {...StepperStepProps}>Step 2</StepperStep>
<StepperStep {...StepperStepProps}>Step 3</StepperStep>
</Stepper>
</div>
);
};

export { StepperExample };
15 changes: 7 additions & 8 deletions packages/eslint-config/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ module.exports = {
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
ecmaFeatures: { jsx: true },
ecmaFeatures: { jsx: true }
},
settings: {
react: {
version: "detect",
},
version: "detect"
}
},
env: {
browser: true,
amd: true,
node: true,
node: true
},
extends: [
"plugin:react/recommended",
"plugin:jsx-a11y/recommended",
"./base",
"./base"
],
rules: {
"react/react-in-jsx-scope": OFF,
"jsx-a11y/accessible-emoji": ERROR,
"react/prop-types": OFF,
},
"react/prop-types": OFF
}
};
3 changes: 2 additions & 1 deletion packages/lib/src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export const Divider = ({
: dividerContainerVertical
}`}
>
<hr
<div
role="separator"
className={`${dividerClass} ${className}`}
style={dividerStyles}
{...nativeProps}
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/src/components/Stepper/Stepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ const StepperComponent: ForwardRefRenderFunction<
dividerProps: item.props.dividerProps || dividerProps,
className: item.props.className || className,
style: item.props.style || style,
size: item.props.size || size,
orientation,
labelOrientation,
onClick: () =>
allowClick && typeof onStepClick === "function" && onStepClick(index),
size
allowClick && typeof onStepClick === "function" && onStepClick(index)
})
);
return acc;
Expand Down
133 changes: 93 additions & 40 deletions packages/lib/src/components/Stepper/StepperStep/StepperStep.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,73 @@
import { assignInlineVars } from "@vanilla-extract/dynamic";
import React, { ForwardRefRenderFunction } from "react";
import React, {
ForwardedRef,
ForwardRefRenderFunction,
ReactNode
} from "react";
import { Divider } from "../../Divider";
import { Flex } from "../../Flex";
import { eliminateUndefinedKeys } from "../../../utils/object-utils";
import { eliminateUndefinedKeys, accessDefinedValues } from "../../../utils";
import {
StepperBorderRadius,
StepperChildrenClass,
StepperDividerWrapperClass,
StepperSizes,
StepperStepIconClass,
stepperThemeClass,
stepperThemeVars
} from "../stepper.styles.css";
import { IStepperStepProps } from "../stepper.types";
import { CheckIcon } from "../../_internal/Icons";

const RenderDivider = ({
isLastChild,
StepperDividerWrapperStyle,
stepState,
dividerProps,
orientation
}: Pick<
IStepperStepProps,
"isLastChild" | "stepState" | "dividerProps" | "orientation"
> & { StepperDividerWrapperStyle: string }) => {
if (isLastChild) return <></>;
return (
<div className={StepperDividerWrapperStyle}>
<Divider
size="2px"
color={
stepState === "stepCompleted"
? stepperThemeVars.completedStyles.backgroundColor
: stepperThemeVars.baseStyles.backgroundColor
}
{...dividerProps}
orientation={orientation}
/>
</div>
);
};

const RenderIcon = ({
StepperStepIconStyle,
_Icon,
ref
}: {
StepperStepIconStyle: string;
_Icon: () => ReactNode;
ref: ForwardedRef<HTMLDivElement>;
}) => {
return (
<Flex
display="inline-flex"
alignItems="center"
justifyContent="center"
className={StepperStepIconStyle}
ref={ref}
>
{_Icon()}
</Flex>
);
};

const StepperStepComponent: ForwardRefRenderFunction<
HTMLDivElement,
IStepperStepProps
Expand All @@ -27,6 +83,7 @@ const StepperStepComponent: ForwardRefRenderFunction<
completedStyles,
progressStyles,
dividerProps,
size,
borderRadius,
orientation,
labelOrientation,
Expand All @@ -38,6 +95,14 @@ const StepperStepComponent: ForwardRefRenderFunction<
) => {
const assignVariables = assignInlineVars(
eliminateUndefinedKeys({
[stepperThemeVars.stepperStyleBorderRadius]: accessDefinedValues(
borderRadius,
StepperBorderRadius
),
[stepperThemeVars.stepperStyleSize]: accessDefinedValues(
size,
StepperSizes
),
[stepperThemeVars.baseStyles.backgroundColor]:
baseStyles?.backgroundColor,
[stepperThemeVars.baseStyles.color]: baseStyles?.color,
Expand Down Expand Up @@ -69,38 +134,6 @@ const StepperStepComponent: ForwardRefRenderFunction<
return icon;
};

const renderIcon = () => {
return (
<Flex
display="inline-flex"
alignItems="center"
justifyContent="center"
className={StepperStepIconStyle}
ref={ref}
>
{_Icon()}
</Flex>
);
};

const renderDivider = () => {
if (isLastChild) return null;
return (
<div className={StepperDividerWrapperStyle}>
<Divider
size="2px"
color={
stepState === "stepCompleted"
? stepperThemeVars.completedStyles.backgroundColor
: stepperThemeVars.baseStyles.backgroundColor
}
{...dividerProps}
orientation={orientation}
/>
</div>
);
};

return (
<Flex
display="inline-flex"
Expand All @@ -113,15 +146,25 @@ const StepperStepComponent: ForwardRefRenderFunction<
>
{orientation === labelOrientation ? (
<>
{renderIcon()}
<RenderIcon
StepperStepIconStyle={StepperStepIconStyle}
_Icon={_Icon}
ref={ref}
/>
<Flex
display="flex"
alignItems="center"
alignSelf="stretch"
flexDirection={labelOrientation === "vertical" ? "column" : "row"}
>
<div>{children}</div>
{renderDivider()}
<div className={StepperChildrenClass}>{children}</div>
<RenderDivider
isLastChild={isLastChild}
StepperDividerWrapperStyle={StepperDividerWrapperStyle}
stepState={stepState}
dividerProps={dividerProps}
orientation={orientation}
/>
</Flex>
</>
) : (
Expand All @@ -132,10 +175,20 @@ const StepperStepComponent: ForwardRefRenderFunction<
alignSelf="stretch"
flexDirection={labelOrientation === "vertical" ? "row" : "column"}
>
{renderIcon()}
{renderDivider()}
<RenderIcon
StepperStepIconStyle={StepperStepIconStyle}
_Icon={_Icon}
ref={ref}
/>
<RenderDivider
isLastChild={isLastChild}
StepperDividerWrapperStyle={StepperDividerWrapperStyle}
stepState={stepState}
dividerProps={dividerProps}
orientation={orientation}
/>
</Flex>
<div>{children}</div>
<div className={StepperChildrenClass}>{children}</div>
</>
)}
</Flex>
Expand Down
Loading