1+ import { useRef , useLayoutEffect } from 'react'
2+ import cn from 'classnames'
3+ import { use_compacting } from '@shared/hooks'
14import { Button } from '../../common/Button'
25import styles from './ResponsePreviewFooter.module.scss'
36
@@ -14,16 +17,49 @@ export const ResponsePreviewFooter: React.FC<Props> = ({
1417 on_accept,
1518 is_accept_disabled
1619} ) => {
20+ const { container_ref, compact_step, report_width } = use_compacting ( 3 )
21+ const back_ref = useRef < HTMLSpanElement > ( null )
22+ const reject_ref = useRef < HTMLSpanElement > ( null )
23+ const accept_ref = useRef < HTMLSpanElement > ( null )
24+
25+ useLayoutEffect ( ( ) => {
26+ if ( back_ref . current && reject_ref . current && accept_ref . current ) {
27+ // Padding (approx 24px per button) + gap (8px * 2)
28+ const padding_and_gap = 3 * 24 + 2 * 8
29+ const width =
30+ back_ref . current . offsetWidth +
31+ reject_ref . current . offsetWidth +
32+ accept_ref . current . offsetWidth +
33+ padding_and_gap
34+ report_width ( width , compact_step )
35+ }
36+ } , [ compact_step , report_width ] )
37+
1738 return (
18- < div className = { styles . container } >
19- < Button on_click = { on_back } is_secondary >
20- Back
39+ < div className = { styles . container } ref = { container_ref } >
40+ < Button on_click = { on_back } is_secondary title = "Back" >
41+ < span className = { styles [ 'button-content' ] } ref = { back_ref } >
42+ { compact_step < 1 && < span className = { styles . text } > Back</ span > }
43+ { compact_step >= 1 && (
44+ < span className = { cn ( 'codicon' , 'codicon-chevron-left' ) } />
45+ ) }
46+ </ span >
2147 </ Button >
22- < Button on_click = { on_reject } is_danger >
23- Reject
48+ < Button on_click = { on_reject } is_danger title = "Reject" >
49+ < span className = { styles [ 'button-content' ] } ref = { reject_ref } >
50+ { compact_step < 2 && < span className = { styles . text } > Reject</ span > }
51+ { compact_step >= 2 && (
52+ < span className = { cn ( 'codicon' , 'codicon-close' ) } />
53+ ) }
54+ </ span >
2455 </ Button >
25- < Button on_click = { on_accept } disabled = { is_accept_disabled } >
26- Accept
56+ < Button on_click = { on_accept } disabled = { is_accept_disabled } title = "Accept" >
57+ < span className = { styles [ 'button-content' ] } ref = { accept_ref } >
58+ { compact_step < 3 && < span className = { styles . text } > Accept</ span > }
59+ { compact_step >= 3 && (
60+ < span className = { cn ( 'codicon' , 'codicon-check' ) } />
61+ ) }
62+ </ span >
2763 </ Button >
2864 </ div >
2965 )
0 commit comments