2023-11-30 17:26:17 +08:00
|
|
|
import React, {Component} from "react";
|
2023-12-12 18:21:09 +08:00
|
|
|
import {Tip} from "./Tip";
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
class Line extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
// Initialize the state object with the initial values from the props
|
|
|
|
this.state = {
|
|
|
|
text: props.outvar in props.data ? props.data[props.outvar] : (props.fallback ? props.fallback : "")
|
|
|
|
};
|
|
|
|
// Bind the event handler to this
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
this.props.target.construct(this.props.outvar, this.state.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClick(element) {
|
|
|
|
let text = element.target.value;
|
|
|
|
this.setState({
|
|
|
|
text: text
|
|
|
|
});
|
|
|
|
this.props.target.update(this.props.outvar, text);
|
|
|
|
}
|
|
|
|
|
2024-01-30 17:20:29 +08:00
|
|
|
static getDerivedStateFromProps(props, current_state) {
|
|
|
|
if (current_state.text !== props.data[props.outvar]) {
|
|
|
|
return {
|
|
|
|
text: props.data[props.outvar]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-11-30 17:26:17 +08:00
|
|
|
render() {
|
|
|
|
let key = this.props.id + this.props.outvar;
|
|
|
|
return (
|
|
|
|
<div className="shop-line" key={this.props.id}>
|
|
|
|
<label htmlFor={key} className="form-label">
|
|
|
|
{this.props.icon && <img src={`/images${this.props.icon}`} className="options-icon"/>}
|
|
|
|
{this.props.title}:
|
|
|
|
</label>
|
|
|
|
{this.props.tip && <Tip id={this.props.id + "tooltip"} tip={this.props.tip}/>}
|
|
|
|
<input type="text" className="form-control form-control-sm" id={key} onChange={this.handleClick}
|
|
|
|
value={this.state.text}/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-02 17:24:01 +08:00
|
|
|
export function LineWrapper(target, id, data, {title, fallback, outvar, icon, tip, classes}) {
|
2023-11-30 17:26:17 +08:00
|
|
|
return <Line target={target} title={title} fallback={fallback} outvar={outvar} icon={icon} tip={tip} key={id}
|
2024-02-02 17:24:01 +08:00
|
|
|
id={id} data={data} classes={classes}/>;
|
2023-11-30 17:26:17 +08:00
|
|
|
}
|