Skip to content

Commit

Permalink
Merge pull request #70 from BinaryStudioAcademy/task/OV-61-add-stepper
Browse files Browse the repository at this point in the history
OV-61: Add Stepper
  • Loading branch information
sofiia-trokhymchuk authored Sep 26, 2024
2 parents bba47a0 + 71139ec commit 243ce54
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 1 deletion.
6 changes: 6 additions & 0 deletions frontend/src/bundles/common/components/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export { ProtectedRoute } from './protected-route/protected-route.js';
export { RouterProvider } from './router-provider/router-provider.js';
export { Select } from './select/select.js';
export { Sidebar } from './sidebar/sidebar.js';
export { Stepper } from './stepper/stepper.js';
export { Textarea } from './textarea/textarea.js';
export { UploadVideo } from './upload-video/upload-video.js';
export { VideoModal } from './video-modal/video-modal.js';
Expand Down Expand Up @@ -51,6 +52,7 @@ export {
Input as LibraryInput,
Link as LibraryLink,
Modal as LibraryModal,
Stepper as LibraryStepper,
ListItem,
Menu,
MenuButton,
Expand All @@ -61,6 +63,7 @@ export {
ModalCloseButton,
ModalContent,
ModalOverlay,
Progress,
SimpleGrid,
Slider,
SliderFilledTrack,
Expand All @@ -69,6 +72,9 @@ export {
Spacer,
Spinner,
Stack,
Step,
StepIndicator,
StepStatus,
Tab,
TabList,
TabPanel,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/bundles/common/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Header: React.FC<Properties> = ({ left, center, right }) => {
</Box>
)}
<Box className={styles['center']}>{center}</Box>
<Box className={styles['right']}>{right}</Box>
{right && <Box className={styles['right']}>{right}</Box>};
</Flex>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { StepStatus } from './step-status/step-status.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { type ValueOf } from 'shared';

import { Box, Icon } from '~/bundles/common/components/components.js';
import { StepStatus as StepStatusEnum } from '~/bundles/common/components/stepper/enums/enums.js';
import { IconName } from '~/bundles/common/icons/icons.js';

import styles from './styles.module.css';

type Properties = {
step: ValueOf<typeof StepStatusEnum>;
};

const StepStatus: React.FC<Properties> = ({ step }) => {
switch (step) {
case StepStatusEnum.COMPLETE: {
return (
<Box className={styles['complete']}>
<Icon as={IconName.CHECK_CIRCLE} boxSize={3} />
</Box>
);
}

case StepStatusEnum.ACTIVE: {
return (
<Box className={styles['active']}>
<Icon as={IconName.CIRCLE} boxSize={3} />
</Box>
);
}

case StepStatusEnum.INCOMPLETE: {
return (
<Box className={styles['incomplete']}>
<Icon as={IconName.CIRCLE} boxSize={3} />
</Box>
);
}
}
};

export { StepStatus };
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.complete {
background-color: var(--chakra-colors-background-900);
display: inline-flex;
}

.active {
display: inline-flex;
justify-content: center;
align-items: center;
padding: 4px;
color: white;
border: 2px solid;
border-color: var(--chakra-colors-background-600);
border-radius: 50%;
background-color: var(--chakra-colors-background-900);
}

.incomplete {
color: var(--chakra-colors-background-600);
display: inline-flex;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { StepStatus } from './step-status.enum.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const StepStatus = {
COMPLETE: 'complete',
ACTIVE: 'active',
INCOMPLETE: 'incomplete',
} as const;

export { StepStatus };
91 changes: 91 additions & 0 deletions frontend/src/bundles/common/components/stepper/stepper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {
Box,
Header,
Icon,
IconButton,
LibraryStepper,
Progress,
Step,
StepIndicator,
StepStatus,
Text,
} from '~/bundles/common/components/components.js';
import { IconName } from '~/bundles/common/icons/icons.js';

import { StepStatus as StepIcon } from './components/components.js';
import { StepStatus as StepStatusEnum } from './enums/enums.js';
import styles from './styles.module.css';

type Properties = {
steps: string[];
currentStep: string;
};

const Stepper: React.FC<Properties> = ({ steps, currentStep }) => {
const activeStepIndex = steps.indexOf(currentStep);
const progressPercent = (activeStepIndex / (steps.length - 1)) * 100;

const backButton = (
<IconButton
variant="ghostIcon"
aria-label="back"
icon={<Icon as={IconName.ARROW_BACK} boxSize={4} />}
/>
);

const stepProgressBar = (
<Box className={styles['stepperWrapper']}>
<Box className={styles['innerStepper']}>
<LibraryStepper size="sm" index={activeStepIndex} gap="0">
{steps.map((step, index) => (
<Step key={index}>
<StepIndicator
bg="white"
height="12px"
width="12px"
>
<StepStatus
complete={
<StepIcon
step={StepStatusEnum.COMPLETE}
/>
}
active={
<StepIcon
step={StepStatusEnum.ACTIVE}
/>
}
incomplete={
<StepIcon
step={StepStatusEnum.INCOMPLETE}
/>
}
/>
<Text
variant="body1"
color={
index <= activeStepIndex
? 'white'
: 'background.600'
}
position="absolute"
top="20px"
>
{step}
</Text>
</StepIndicator>
</Step>
))}
</LibraryStepper>
<Progress
variant="stepper"
value={progressPercent}
className={styles['progressBar']}
/>
</Box>
</Box>
);
return <Header left={backButton} center={stepProgressBar} />;
};

export { Stepper };
21 changes: 21 additions & 0 deletions frontend/src/bundles/common/components/stepper/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.stepperWrapper {
position: relative;
max-width: 340px;
min-width: 300px;
height: 100%;
}

.innerStepper {
position: absolute;
bottom: 20px;
width: 100%;
height: 100%;
}

.progressBar {
position: absolute;
height: 3px;
width: 100%;
top: 5px;
z-index: -1;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
faBackwardStep,
faCircle,
faCircleUser,
faCloudArrowDown,
faCloudArrowUp,
Expand Down Expand Up @@ -45,9 +46,11 @@ const VolumeOff = convertIcon(faVolumeOff);
const Stop = convertIcon(faStop);
const VideoCamera = convertIcon(faVideoCamera);
const Image = convertIcon(faImage);
const Circle = convertIcon(faCircle);

export {
BackwardStep,
Circle,
CircleUser,
CloudArrowDown,
CloudArrowUp,
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/bundles/common/icons/icon-name.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
AddIcon,
ArrowBackIcon,
ArrowLeftIcon,
ArrowRightIcon,
CheckCircleIcon,
Expand All @@ -15,6 +16,7 @@ import {
import { Logo, LogoText, OpenAi } from './custom-icons/custom-icons.js';
import {
BackwardStep,
Circle,
CircleUser,
CloudArrowDown,
CloudArrowUp,
Expand Down Expand Up @@ -73,6 +75,8 @@ const IconName = {
WARNING: WarningIcon,
VIDEO_CAMERA: VideoCamera,
IMAGE: Image,
CIRCLE: Circle,
ARROW_BACK: ArrowBackIcon,
} as const;

export { IconName };
12 changes: 12 additions & 0 deletions frontend/src/framework/theme/styles/components.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ const components = {
},
},
},
Progress: {
variants: {
stepper: {
filledTrack: {
bg: colors.white,
},
track: {
bg: colors.background[600],
},
},
},
},
};

export { components };

0 comments on commit 243ce54

Please sign in to comment.