Skip to content

Commit

Permalink
geosolutions-it#10158: refactor more buttons to use tooltip enhancer
Browse files Browse the repository at this point in the history
Use accessible tooltip enhancer in Locate, Redo, Undo, Zoom and Toggle button components

On Behalf of DB Systel
  • Loading branch information
Florian Kellner committed Apr 4, 2024
1 parent 0463e49 commit 53867bf
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 198 deletions.
3 changes: 1 addition & 2 deletions web/client/components/buttons/FullScreenButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import PropTypes from 'prop-types';
import React from 'react';

import ToggleButton from './ToggleButton';
import { Tooltip } from 'react-bootstrap';
import Message from '../I18N/Message';

/**
Expand Down Expand Up @@ -86,7 +85,7 @@ class FullScreenButton extends React.Component {
};

render() {
return (<ToggleButton {...this.getButtonProperties()} pressed={this.props.active} tooltip={<Tooltip id="full-screen-button-tip"><Message msgId={this.props.active ? this.props.activeTooltip : this.props.notActiveTooltip}/></Tooltip>} />);
return (<ToggleButton {...this.getButtonProperties()} pressed={this.props.active} tooltip={<Message msgId={this.props.active ? this.props.activeTooltip : this.props.notActiveTooltip}/>} />);
}
}

Expand Down
3 changes: 1 addition & 2 deletions web/client/components/buttons/GlobeViewSwitcherButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import React from 'react';
import PropTypes from 'prop-types';

import ToggleButton from './ToggleButton';
import { Tooltip } from 'react-bootstrap';
import Message from '../I18N/Message';

/**
Expand Down Expand Up @@ -85,7 +84,7 @@ class GlobeViewSwitcherButton extends React.Component {
};

render() {
return <ToggleButton {...this.getButtonProperties()} pressed={this.props.active} tooltip={<Tooltip id="globeViewSwitcher-tooltip"><Message msgId={this.props.active ? this.props.activeTooltip : this.props.notActiveTooltip}/></Tooltip>} />;
return <ToggleButton {...this.getButtonProperties()} pressed={this.props.active} tooltip={<Message msgId={this.props.active ? this.props.activeTooltip : this.props.notActiveTooltip}/>} />;
}
}

Expand Down
37 changes: 24 additions & 13 deletions web/client/components/buttons/ToggleButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Glyphicon } from 'react-bootstrap';
import OverlayTrigger from '../misc/OverlayTrigger';
import Button from '../misc/Button';
import {ButtonWithTooltip} from '../misc/Button';
import ImageButton from './ImageButton';
import tooltip from "../misc/enhancers/tooltip";
/**
* Toggle button with tooltip and icons or image support.
* @memberof components.buttons
Expand Down Expand Up @@ -70,18 +71,36 @@ class ToggleButton extends React.Component {

renderNormalButton = () => {
return (
<Button id={this.props.id} {...this.props.btnConfig} onClick={this.onClick} bsStyle={this.props.pressed ? this.props.pressedStyle : this.props.defaultStyle} style={this.props.style}>
<ButtonWithTooltip
id={this.props.id}
{...this.props.btnConfig}
onClick={this.onClick}
bsStyle={this.props.pressed ? this.props.pressedStyle : this.props.defaultStyle}
style={this.props.style}
tooltip={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
{this.props.glyphicon ? <Glyphicon glyph={this.props.glyphicon}/> : null}
{this.props.glyphicon && this.props.text && !React.isValidElement(this.props.text) ? "\u00A0" : null}
{this.props.text}
{this.props.help}
</Button>
</ButtonWithTooltip>
);
};

renderImageButton = () => {
const ImageButtonT = tooltip(ImageButton);
return (
<ImageButton id={this.props.id} image={this.props.image} onClick={this.onClick} style={this.props.style}/>
<ImageButtonT
id={this.props.id}
image={this.props.image}
onClick={this.onClick}
style={this.props.style}
tooltip={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
/>
);
};

Expand All @@ -94,15 +113,7 @@ class ToggleButton extends React.Component {
};

render() {
var retval;
var btn = this.props.btnType === 'normal' ? this.renderNormalButton() : this.renderImageButton();
if (this.props.tooltip) {
retval = this.addTooltip(btn);
} else {
retval = btn;
}
return retval;

return this.props.btnType === 'normal' ? this.renderNormalButton() : this.renderImageButton();
}
}

Expand Down
48 changes: 18 additions & 30 deletions web/client/components/buttons/ZoomButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import PropTypes from 'prop-types';
import React from 'react';

import Button from '../misc/Button';
import { Glyphicon, Tooltip } from 'react-bootstrap';
import OverlayTrigger from '../misc/OverlayTrigger';
import { ButtonWithTooltip } from '../misc/Button';
import { Glyphicon } from 'react-bootstrap';

class ZoomButton extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -49,34 +48,23 @@ class ZoomButton extends React.Component {
};

render() {
return this.addTooltip(
<Button
id={this.props.id}
style={this.props.style}
onClick={() => this.props.onZoom(this.props.currentZoom + this.props.step)}
className={this.props.className}
disabled={this.props.currentZoom + this.props.step > this.props.maxZoom || this.props.currentZoom + this.props.step < this.props.minZoom}
bsStyle={this.props.bsStyle}
>
{this.props.glyphicon ? <Glyphicon glyph={this.props.glyphicon}/> : null}
{this.props.glyphicon && this.props.text ? "\u00A0" : null}
{this.props.text}
{this.props.help}
</Button>
);
return (<ButtonWithTooltip
id={this.props.id}
style={this.props.style}
onClick={() => this.props.onZoom(this.props.currentZoom + this.props.step)}
className={this.props.className}
disabled={this.props.currentZoom + this.props.step > this.props.maxZoom || this.props.currentZoom + this.props.step < this.props.minZoom}
bsStyle={this.props.bsStyle}
tooltip={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
{this.props.glyphicon ? <Glyphicon glyph={this.props.glyphicon}/> : null}
{this.props.glyphicon && this.props.text ? "\u00A0" : null}
{this.props.text}
{this.props.help}
</ButtonWithTooltip>);
}

addTooltip = (btn) => {
if (!this.props.tooltip) {
return btn;
}
let tooltip = <Tooltip id="locate-tooltip">{this.props.tooltip}</Tooltip>;
return (
<OverlayTrigger placement={this.props.tooltipPlace} key={"overlay-trigger." + this.props.id} overlay={tooltip}>
{btn}
</OverlayTrigger>
);
};
}

export default ZoomButton;
52 changes: 26 additions & 26 deletions web/client/components/mapcontrols/locate/LocateBtn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@

import PropTypes from 'prop-types';
import React from 'react';
import {Glyphicon, Tooltip} from 'react-bootstrap';
import {Glyphicon} from 'react-bootstrap';

import Message from '../../I18N/Message';
import OverlayTrigger from '../../misc/OverlayTrigger';
import defaultIcon from '../../misc/spinners/InlineSpinner/img/spinner.gif';
import Button from '../../misc/Button';
import {ButtonWithTooltip} from '../../misc/Button';
import('./css/locate.css');

let checkingGeoLocation = false;
Expand Down Expand Up @@ -74,9 +72,19 @@ class LocateBtn extends React.Component {
renderButton = () => {
const geoLocationDisabled = this.props.locate === "PERMISSION_DENIED";
return (
<Button id={this.props.id} disabled={geoLocationDisabled} {...this.props.btnConfig} onClick={this.onClick} bsStyle={this.getBtnStyle()} style={this.props.style}>
<ButtonWithTooltip
id={this.props.id}
disabled={geoLocationDisabled}
{...this.props.btnConfig}
onClick={this.onClick}
bsStyle={this.getBtnStyle()}
style={this.props.style}
tooltipId={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
<Glyphicon glyph={this.props.glyph}/>{this.props.text}{this.props.help}
</Button>
</ButtonWithTooltip>
);
};

Expand All @@ -91,18 +99,18 @@ class LocateBtn extends React.Component {
}} alt="..." />)
;
return (
<Button id={this.props.id} onClick={this.onClick} {...this.props.btnConfig} bsStyle={this.getBtnStyle()} style={this.props.style}>
<ButtonWithTooltip
id={this.props.id}
onClick={this.onClick}
{...this.props.btnConfig}
bsStyle={this.getBtnStyle()}
style={this.props.style}
tooltipId={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
{img}
</Button>
);
};

addTooltip = (btn) => {
const tooltip = <Tooltip id="locate-tooltip"><Message msgId={this.props.tooltip} /></Tooltip>;
return (
<OverlayTrigger placement={this.props.tooltipPlace} key={`{overlay-trigger.${this.props.id}-${this.props.tooltip}}`} overlay={tooltip}>
{btn}
</OverlayTrigger>
</ButtonWithTooltip>
);
};

Expand Down Expand Up @@ -130,15 +138,7 @@ class LocateBtn extends React.Component {
}

render() {
var retval;
var btn = this.props.locate === "LOCATING" ? this.renderLoadingButton() : this.renderButton();
if (this.props.tooltip) {
retval = this.addTooltip(btn);
} else {
retval = btn;
}
return retval;

return this.props.locate === "LOCATING" ? this.renderLoadingButton() : this.renderButton();
}

getBtnStyle = () => {
Expand Down
52 changes: 17 additions & 35 deletions web/client/components/mapcontrols/navigationhistory/RedoButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

import React from 'react';
import PropTypes from 'prop-types';
import { Glyphicon, Tooltip } from 'react-bootstrap';

import OverlayTrigger from '../../misc/OverlayTrigger';
import Button from '../../misc/Button';
import { Glyphicon } from 'react-bootstrap';
import {ButtonWithTooltip} from '../../misc/Button';

class RedoBtn extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -40,44 +38,28 @@ class RedoBtn extends React.Component {
}
};

onClick = () => {
this.props.onClick();
};

shouldComponentUpdate(nextProps) {
return this.props.disabled !== nextProps.disabled;
}

renderButton = () => {
return (
<Button id={this.props.id} disabled={this.props.disabled} {...this.props.btnConfig} onClick={this.onClick} bsStyle={this.props.buttonStyle} style={this.props.style}>
<Glyphicon glyph={this.props.glyph}/>{this.props.text}{this.props.help}
</Button>
);
};

addTooltip = (btn) => {
let tooltip = <Tooltip id="redo-btn-tooltip">{this.props.tooltip}</Tooltip>;
return (
<OverlayTrigger placement={this.props.tooltipPlace} key={"overlay-trigger." + this.props.id} overlay={tooltip}>
{btn}
</OverlayTrigger>
);
onClick = () => {
this.props.onClick();
};

UNSAFE_componentWillMount() {
// none
}

render() {
var retval;
var btn = this.renderButton();
if (this.props.tooltip) {
retval = this.addTooltip(btn);
} else {
retval = btn;
}
return retval;
return (<ButtonWithTooltip
id={this.props.id}
disabled={this.props.disabled}
{...this.props.btnConfig}
onClick={this.onClick}
bsStyle={this.props.buttonStyle}
style={this.props.style}
tooltip={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
<Glyphicon glyph={this.props.glyph}/>{this.props.text}{this.props.help}
</ButtonWithTooltip>);

}
}
Expand Down
51 changes: 18 additions & 33 deletions web/client/components/mapcontrols/navigationhistory/UndoButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import React from 'react';
import PropTypes from 'prop-types';

import { Glyphicon, Tooltip } from 'react-bootstrap';
import OverlayTrigger from '../../misc/OverlayTrigger';
import Button from '../../misc/Button';
import { Glyphicon } from 'react-bootstrap';
import {ButtonWithTooltip} from '../../misc/Button';

class UndoBtn extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -40,44 +39,30 @@ class UndoBtn extends React.Component {
}
};

onClick = () => {
this.props.onClick();
};

shouldComponentUpdate(nextProps) {
return this.props.disabled !== nextProps.disabled;
}

renderButton = () => {
return (
<Button id={this.props.id} disabled={this.props.disabled} {...this.props.btnConfig} onClick={this.onClick} bsStyle={this.props.buttonStyle} style={this.props.style}>
<Glyphicon glyph={this.props.glyph}/>{this.props.text}{this.props.help}
</Button>
);
onClick = () => {
this.props.onClick();
};

addTooltip = (btn) => {
let tooltip = <Tooltip id="undo-btn-tooltip">{this.props.tooltip}</Tooltip>;
render() {
return (
<OverlayTrigger placement={this.props.tooltipPlace} key={"overlay-trigger." + this.props.id} overlay={tooltip}>
{btn}
</OverlayTrigger>
<ButtonWithTooltip
id={this.props.id}
disabled={this.props.disabled}
{...this.props.btnConfig}
onClick={this.onClick}
bsStyle={this.props.buttonStyle}
style={this.props.style}
tooltip={this.props.tooltip}
tooltipPosition={this.props.tooltipPlace}
keyProp={"overlay-trigger." + this.props.id}
>
<Glyphicon glyph={this.props.glyph}/>{this.props.text}{this.props.help}
</ButtonWithTooltip>
);
};

UNSAFE_componentWillMount() {
// none
}

render() {
var retval;
var btn = this.renderButton();
if (this.props.tooltip) {
retval = this.addTooltip(btn);
} else {
retval = btn;
}
return retval;

}
}
Expand Down
Loading

0 comments on commit 53867bf

Please sign in to comment.