1- import React from "react" ;
1+ import React , { useRef , useLayoutEffect , useState } from "react" ;
22import styled , { css } from "styled-components" ;
33import BulletCircle from "./bullet-circle" ;
44import { h2 , small , mobileStyle } from "../../../styles/common-style" ;
55
66interface IContainer {
77 last ?: boolean ;
88 completed ?: boolean ;
9+ paddingBottom ?: number ;
910}
1011
1112const Container = styled . div < IContainer > `
@@ -14,6 +15,16 @@ const Container = styled.div<IContainer>`
1415 display: flex;
1516 justify-content: center;
1617 align-items: start;
18+ ${ ( { paddingBottom } ) =>
19+ paddingBottom
20+ ? css `
21+ ${ mobileStyle (
22+ ( ) => css `
23+ padding-bottom : ${ paddingBottom } px;
24+ `
25+ ) }
26+ `
27+ : "" }
1728
1829 ${ ( { theme, last, completed } ) =>
1930 last
@@ -93,14 +104,26 @@ const HorizontalBullet: React.FC<HorizontalBulletProps> = ({
93104 last,
94105 completed,
95106 ...props
96- } ) => (
97- < Container { ...{ active, completed, last } } { ...props } >
98- < BulletCircle { ...{ active, completed, index } } />
99- < TextWrapper { ...{ active } } >
100- < h2 > { title } </ h2 >
101- { subitems && subitems . map ( ( item , i ) => < small key = { i } > { item } </ small > ) }
102- </ TextWrapper >
103- </ Container >
104- ) ;
107+ } ) => {
108+ const textRef = useRef < HTMLDivElement > ( null ) ;
109+ const [ paddingBottom , setPaddingBottom ] = useState ( 0 ) ;
110+
111+ useLayoutEffect ( ( ) => {
112+ if ( textRef . current ) {
113+ const totalHeight = textRef . current . clientHeight ;
114+ setPaddingBottom ( totalHeight ) ;
115+ }
116+ } , [ subitems ] ) ;
117+
118+ return (
119+ < Container { ...{ active, completed, last, paddingBottom } } { ...props } >
120+ < BulletCircle { ...{ active, completed, index } } />
121+ < TextWrapper ref = { textRef } { ...{ active } } >
122+ < h2 > { title } </ h2 >
123+ { subitems && subitems . map ( ( item , i ) => < small key = { i } > { item } </ small > ) }
124+ </ TextWrapper >
125+ </ Container >
126+ ) ;
127+ } ;
105128
106129export default HorizontalBullet ;
0 commit comments