import Input from './Input' import React from 'react' let inputStyle = { width: '300px', } let spanStyle = { fontSize: '14px', color: 'rgba(0, 0, 0, 0.65)', display: 'inline-block', width: '80px', } let formItmeStyle = { marginBottom: '10px', } class Link extends React.Component { state = { text: '', link: '', title: '', newTab: false, showTips: false, } hasProtocol = link => { if (link.match(/^http:|https:/) || link.match(/^\/\//)) { return true } return false } generateHtml = () => { let {text, link, title, newTab} = this.state if (link) { let html = '' if (!this.hasProtocol(link)) { link = 'http://' + link } html += `${text || link}` return html } } changeConfig = (e, type) => { let value = e.target.value let boolType = ['newTab'] if (boolType.indexOf(type) !== -1) { value = !!value } if (type == 'link') { if (!this.hasProtocol(value)) { this.setState({ showTips: true, }) } else { this.setState({ showTips: false, }) } } if (type == 'newTab') { return this.setState({newTab: !this.state.newTab}) } this.setState({[type]: value}, () => { this.props.onChange && this.props.onChange(this.generateHtml()) }) } render() { let {text, link, title, newTab, showTips} = this.state return (
) } } export default Link