mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-24 18:46:40 +07:00
67 lines
1.4 KiB
TypeScript
67 lines
1.4 KiB
TypeScript
import React from 'react';
|
|
import classnames from 'classnames';
|
|
|
|
interface Props {
|
|
value: string;
|
|
onChange: (text: string) => void;
|
|
onBlur: () => void;
|
|
}
|
|
|
|
type State = {
|
|
text: String;
|
|
}
|
|
|
|
class StickerDesc extends React.PureComponent<Props, State> {
|
|
state = {
|
|
text: this.props.value,
|
|
};
|
|
|
|
setText = e => {
|
|
this.props.onChange(e.target.value);
|
|
};
|
|
|
|
blockMouse = e => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
if (!this.input) {
|
|
return
|
|
}
|
|
|
|
this.input.focus();
|
|
};
|
|
|
|
input: HTMLTextAreaElement | null = null;
|
|
|
|
render() {
|
|
const { value: text } = this.props;
|
|
|
|
return (
|
|
<div
|
|
className={classnames('sticker-desc', { is_empty: !text.trim() })}
|
|
onMouseDownCapture={this.blockMouse}
|
|
onMouseUpCapture={this.blockMouse}
|
|
onDragStartCapture={this.blockMouse}
|
|
onTouchStartCapture={this.blockMouse}
|
|
>
|
|
<div className="sticker-desc-sizer">
|
|
<span
|
|
dangerouslySetInnerHTML={{
|
|
__html: (text.replace(/\n$/, '\n ').replace(/\n/g, '<br />') || ' ')
|
|
}}
|
|
/>
|
|
<textarea
|
|
onChange={this.setText}
|
|
value={text}
|
|
onMouseDown={this.blockMouse}
|
|
onDragStart={this.blockMouse}
|
|
ref={el => { this.input = el; }}
|
|
onBlur={this.props.onBlur}
|
|
/>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
export { StickerDesc };
|