Skip to content

Commit 9cb52fb

Browse files
committed
moved label render inside bubble component
1 parent 6f7d54f commit 9cb52fb

File tree

5 files changed

+75
-70
lines changed

5 files changed

+75
-70
lines changed

src/bubble/bubble.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { FC } from "react";
22
import type { IBubbleProps } from "./types";
33
import { Elements } from "../constants";
44
import whiteTick from '../assets/white-tick.svg';
5-
import { STEP_STATUSES } from '../constants';
5+
import { STEP_STATUSES, LABEL_POSITION } from '../constants';
66
import styles from './styles.module.scss';
77

88
const Bubble: FC<IBubbleProps> = (props) => {
@@ -13,7 +13,8 @@ const Bubble: FC<IBubbleProps> = (props) => {
1313
currentStepIndex,
1414
handleStepClick = null,
1515
showCursor,
16-
getStyles
16+
getStyles,
17+
labelPosition
1718
} = props;
1819

1920
return (
@@ -45,6 +46,41 @@ const Bubble: FC<IBubbleProps> = (props) => {
4546
|| index + 1}
4647
</>
4748
)}
49+
<div className={`${styles.labelContainer} ${styles[`labelContainer__${labelPosition || LABEL_POSITION.RIGHT}`]}`}>
50+
{step?.label && (
51+
<span
52+
className={`${styles.labelTitle}
53+
${showCursor && styles.cursorPointer}
54+
${index === currentStepIndex && styles.activeLabelTitle}`}
55+
style={{
56+
...((getStyles(Elements.LabelTitle)) || {}),
57+
...((index === currentStepIndex && getStyles(Elements.ActiveLabelTitle)) || {})
58+
}}
59+
onClick={(): void | null => handleStepClick && handleStepClick()}
60+
role="presentation"
61+
id={`stepper-label-${index}`}
62+
>
63+
{step.label}
64+
</span>
65+
)}
66+
{step?.description && (
67+
<span
68+
className={`${styles.labelDescription}
69+
${handleStepClick && styles.cursorPointer}
70+
${index === currentStepIndex && styles.activeLabelDescription}`}
71+
style={{
72+
...((getStyles(Elements.LabelDescription)) || {}),
73+
...((index === currentStepIndex &&
74+
getStyles(Elements.ActiveLabelDescription)) || {})
75+
}}
76+
onClick={(): void | null => handleStepClick && handleStepClick()}
77+
role="presentation"
78+
id={`stepper-desc-${index}`}
79+
>
80+
{step.description}
81+
</span>
82+
)}
83+
</div>
4884
</div>
4985
);
5086
};

src/bubble/styles.module.scss

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
font-weight: 400;
1212
font-size: 12px;
1313
line-height: 16px;
14-
border: 7px solid;
14+
margin: 7px;
15+
position: relative;
1516
}
1617
.activeStepBubble {
1718
border: 7px solid #CBCBEF;
19+
margin: 0;
1820
}
1921
.inactiveStepBubble {
2022
opacity: 0.4;
@@ -26,4 +28,35 @@
2628
}
2729
.cursorPointer {
2830
cursor: pointer;
31+
}
32+
33+
.labelContainer {
34+
position: absolute;
35+
width: max-content;
36+
height: 100%;
37+
display: flex;
38+
flex-direction: column;
39+
justify-content: center;
40+
&__right {
41+
left: 44px;
42+
}
43+
&__left {
44+
right: 44px;
45+
align-items: end;
46+
}
47+
.labelTitle {
48+
color: #4F4F4F;
49+
}
50+
.activeLabelTitle {
51+
font-weight: 700;
52+
}
53+
.labelDescription {
54+
font-weight: 400;
55+
font-size: 12px;
56+
line-height: 21px;
57+
color: #929292;
58+
}
59+
.activeLabelDescription {
60+
color: #676767;
61+
}
2962
}

src/bubble/types.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export type IBubbleProps = {
99
currentStepIndex?: number,
1010
handleStepClick(): void,
1111
showCursor: boolean,
12-
getStyles(element: Elements): object
12+
getStyles(element: Elements): object,
13+
labelPosition: 'left' | 'right'
1314
}

src/stepper-component/stepperComponent.tsx

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,8 @@ const Stepper: FC<IStepperProps> = (props) => {
3535
showCursor={!!onStepClick}
3636
renderAdornment={renderBubble}
3737
getStyles={(element: Elements): object => getStyles(element, step, stepIndex)}
38+
labelPosition={labelPosition}
3839
/>
39-
<div className={`${classes.labelContainer} ${classes[`labelContainer__${labelPosition || LABEL_POSITION.RIGHT}`]}`}>
40-
{step?.label && (
41-
<span
42-
className={`${classes.labelTitle}
43-
${onStepClick && classes.cursorPointer}
44-
${stepIndex === currentStepIndex && classes.activeLabelTitle}`}
45-
style={{
46-
...((getStyles(Elements.LabelTitle, step, stepIndex)) || {}),
47-
...((stepIndex === currentStepIndex && getStyles(Elements.ActiveLabelTitle, step, stepIndex)) || {})
48-
}}
49-
onClick={(): void => onStepClick && onStepClick(step, stepIndex)}
50-
role="presentation"
51-
id={`stepper-label-${stepIndex}`}
52-
>
53-
{step.label}
54-
</span>
55-
)}
56-
{step?.description && (
57-
<span
58-
className={`${classes.labelDescription}
59-
${onStepClick && classes.cursorPointer}
60-
${stepIndex === currentStepIndex && classes.activeLabelDescription}`}
61-
style={{
62-
...((getStyles(Elements.LabelDescription, step, stepIndex)) || {}),
63-
...((stepIndex === currentStepIndex &&
64-
getStyles(Elements.ActiveLabelDescription, step, stepIndex)) || {})
65-
}}
66-
onClick={(): void => onStepClick && onStepClick(step, stepIndex)}
67-
role="presentation"
68-
id={`stepper-desc-${stepIndex}`}
69-
>
70-
{step.description}
71-
</span>
72-
)}
73-
</div>
7440
{stepIndex < steps?.length - 1 && (
7541
<div
7642
className={`${classes.lineSeparator}

src/stepper-component/styles.module.scss

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,6 @@
1515
flex-direction: column;
1616
align-items: center;
1717
width: fit-content;
18-
.labelContainer {
19-
position: absolute;
20-
width: max-content;
21-
height: fit-content;
22-
display: flex;
23-
flex-direction: column;
24-
&__right {
25-
top: 4px;
26-
left: 44px;
27-
}
28-
&__left {
29-
top: 4px;
30-
right: 44px;
31-
align-items: end;
32-
}
33-
.labelTitle {
34-
color: #4F4F4F;
35-
}
36-
.activeLabelTitle {
37-
font-weight: 700;
38-
}
39-
.labelDescription {
40-
font-weight: 400;
41-
font-size: 12px;
42-
line-height: 21px;
43-
color: #929292;
44-
}
45-
.activeLabelDescription {
46-
color: #676767;
47-
}
48-
}
4918
.lineSeparator {
5019
height: 22px;
5120
width: 1px;

0 commit comments

Comments
 (0)