Skip to content

Commit

Permalink
rewrite DialogButton
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Dec 2, 2024
1 parent ad19db1 commit ec0e77e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
28 changes: 12 additions & 16 deletions viewer/components/DialogButton.jsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
import React from 'react';
import PropTypes from 'prop-types';
import GuiHelper from '../util/GuiHelpers.js';
import {useKeyEventHandlerPlain} from '../util/GuiHelpers.js';
import KeyHandler from '../util/keyhandler';

class DialogButton extends React.Component {
constructor(props){
super(props);
KeyHandler.registerDialogComponent("dialogButton");
GuiHelper.keyEventHandler(this,(component,action)=>{
if (this.props.onClick && ! this.props.disabled && this.props.visible !== false) this.props.onClick();
},"dialogButton",this.props.name);
}
render() {
let {icon,style,disabled,visible,...forward}=this.props;
const COMPONENT="dialogButton";
const DialogButton=(props)=>{
KeyHandler.registerDialogComponent(COMPONENT);
useKeyEventHandlerPlain(props.name,COMPONENT,()=>{
if (props.onClick && ! props.disabled && props.visible !== false) props.onClick();
});
let {icon,style,disabled,visible,name,className,toggle,children,...forward}=props;
if (visible === false) return null;
let className = this.props.className || "";
className += " dialogButton " + this.props.name;
if (className === undefined) className="";
className += " dialogButton " + name;
let spanStyle={};
if (icon !== undefined) {
className+=" icon";
spanStyle.backgroundImage = "url(" + icon + ")";
}
className+=this.props.toggle?" active":" inactive";
className+=toggle?" active":" inactive";
let add = {};
if (disabled) {
add.disabled = true;
}
return (
<button {...forward} {...add} className={className}>
<span style={spanStyle}/>
{this.props.children}
{children}
</button>
);
}
}

DialogButton.propTypes={
onClick: PropTypes.func,
Expand Down
3 changes: 3 additions & 0 deletions viewer/util/GuiHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ export const useKeyEventHandler=(props,component,opt_callback)=>{
}
},[])
}
export const useKeyEventHandlerPlain=(name,component,callback)=>{
return useKeyEventHandler({name:name},component,callback);
}

//from https://stackoverflow.com/questions/487073/how-to-check-if-element-is-visible-after-scrolling
//returns:
Expand Down
1 change: 0 additions & 1 deletion viewer/util/keys.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ let keys={
propertySequence:K,
propertiesLoaded: K,
hasActiveInputs: K,
currentDialog: K, //holds the data for the currently visible dialog - if any
windowDimensions: K,
layoutEditing:K,
layoutSequence: K, //updated on layout load
Expand Down

0 comments on commit ec0e77e

Please sign in to comment.