0

I am trying to implement a maximize tool button in ExtReact but I get an

error: "Uncaught TypeError: n.up is not a function". 

Here is my current implementation of this function:

{
    type: 'maximize',
    handler: function(e, target, panelHdr) {
        var panel = panelHdr.up('panel');
        if (!panel.maximized) {
            panel.restoreSize = panel.getSize();
            panel.restorePos = panel.getPosition(true);
            panel.maximized = true;
            var parent = panel.ownerCt,
                container = parent ? parent.getTargetEl() : panel.container,
                newBox = container.getViewSize(false);
            panel.setBox(newBox);
        } else {
            var newBox = panel.restoreSize;
            newBox.x = panel.restorePos[0];
            newBox.y = panel.restorePos[1];
            panel.maximized = false;
            panel.setBox(newBox);
        }
    }
}
Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44

1 Answers1

3

In ExtReact for tool handler the first parameter is

The logical owner of the tool. In a typical usage this will be an Panel (as specified by the toolOwner config) see this handler.

See below example :-

 {
     type: 'maximize',

     /* @param  {Ext.Component} owner The logical owner of the tool. In a typical usage this will be an Panel (as specified by the toolOwner config).
      * @param {Ext.Tool} tool The tool that is calling.
      * @param {Ext.event.Event} event The click event.
      */
     handler: function(owner, tool, event) {

     }
 }

You can see screenshot here for minimize and maximize.

CODE SNIPPET

import React, {
    Component
} from 'react';
import {
    Container,
    Panel,
    Button
} from '@extjs/ext-react';

Ext.require('Ext.Toast');

function toolHandler(panel, tool) {
    Ext.toast(`You clicked ${tool.config.type}`);
    if (tool.config.type=="maximize") {
        panel.setHeight(window.innerHeight).setWidth(window.innerWidth)
    }else{
         panel.setHeight(panel.initialConfig.height).setWidth(panel.initialConfig.width)
    }
}

export default class PanelExample extends Component {

    render() {
        return (
            <Container>
                <Panel
                    shadow
                    title="Panel"
                    height={300}
                    width={500}
                   // collapsible={{ dynamic: true }}
                    tools={[
                        {type: 'minimize', handler: toolHandler },
                        {type: 'maximize',handler: toolHandler  }
                    ]}
                >
                    <p>Panel Body</p>
                </Panel>
            </Container>
        )
    }
}
Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44