1- import { useCallback , useEffect } from "react" ;
1+ import { useCallback , useEffect , useState } from "react" ;
22import { Tabs } from "antd" ;
33
44import {
@@ -13,8 +13,15 @@ import {
1313import Dropdown from "../Dropdown" ;
1414import JSONViewer from "../JSONViewer" ;
1515import RecipeForm from "../RecipeForm" ;
16- import { ExpandableText } from "../ExpandableDescription " ;
16+ import ExpandableText from "../ExpandableText " ;
1717import "./style.css" ;
18+ import { useSiderHeight } from "../../hooks/useSiderHeight" ;
19+ import {
20+ DEFAULT_DESCRIPTION_HEIGHT ,
21+ SELECT_HEIGHT ,
22+ TABS_HEADER_HEIGHT ,
23+ TEXT_BOTTOM_MARGIN ,
24+ } from "../../constants" ;
1825
1926interface PackingInputProps {
2027 startPacking : (
@@ -34,6 +41,20 @@ const PackingInput = (props: PackingInputProps): JSX.Element => {
3441 const loadAllRecipes = useLoadAllRecipes ( ) ;
3542 const selectRecipe = useSelectRecipe ( ) ;
3643 const storeStartPacking = useStartPacking ( ) ;
44+ const siderHeight = useSiderHeight ( ) ;
45+
46+ const [ descriptionHeight , setDescriptionHeight ] = useState < number > (
47+ DEFAULT_DESCRIPTION_HEIGHT + TEXT_BOTTOM_MARGIN
48+ ) ;
49+ const [ availableRecipeHeight , setAvailableRecipeHeight ] = useState < number > (
50+ siderHeight - descriptionHeight - SELECT_HEIGHT
51+ ) ;
52+
53+ useEffect ( ( ) => {
54+ const newAvailableHeight =
55+ siderHeight - descriptionHeight - SELECT_HEIGHT ;
56+ setAvailableRecipeHeight ( newAvailableHeight ) ;
57+ } , [ siderHeight , descriptionHeight ] ) ;
3758
3859 const preFetchInputsAndRecipes = useCallback ( async ( ) => {
3960 await loadInputOptions ( ) ;
@@ -73,14 +94,30 @@ const PackingInput = (props: PackingInputProps): JSX.Element => {
7394 ) : (
7495 < >
7596 { recipeObj . description && (
76- < ExpandableText text = { recipeObj . description } />
97+ < div className = "recipe-description" >
98+ < ExpandableText
99+ text = { recipeObj . description }
100+ setCurrentHeight = { setDescriptionHeight }
101+ />
102+ </ div >
77103 ) }
78104 < Tabs defaultActiveKey = "1" className = "recipe-content" >
79105 < Tabs . TabPane tab = "Editable fields" key = "1" >
80- < RecipeForm onStartPacking = { handleStartPacking } />
106+ < RecipeForm
107+ onStartPacking = { handleStartPacking }
108+ availableHeight = {
109+ availableRecipeHeight - TABS_HEADER_HEIGHT
110+ }
111+ />
81112 </ Tabs . TabPane >
82113 < Tabs . TabPane tab = "Full Recipe" key = "2" >
83- < JSONViewer title = "Recipe" content = { recipeObj } />
114+ < JSONViewer
115+ title = "Recipe"
116+ content = { recipeObj }
117+ availableHeight = {
118+ availableRecipeHeight - TABS_HEADER_HEIGHT
119+ }
120+ />
84121 </ Tabs . TabPane >
85122 </ Tabs >
86123 </ >
0 commit comments