Created
July 11, 2018 04:50
-
-
Save asmattic/2fa45a64737bd3086d37c234932d4673 to your computer and use it in GitHub Desktop.
CSV to Markdown Table Converter (React)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import csvToMarkDownTable from 'csv-to-markdown-table'; | |
const style = { | |
markdownTableWrapper: { | |
padding: '0', | |
margin: '0', | |
listStyle: 'none', | |
display: 'flex', | |
flexDirection: 'column', | |
justifyContent: 'spaceAround', | |
alignItems: 'stretch' | |
}, | |
flexItem: { | |
padding: '5px', | |
width: '200px', | |
height: '150px', | |
marginTop: '10px', | |
lineHeight: '20px', | |
fontSize: '3em', | |
} | |
} | |
class MarkdownTableConverter extends Component { | |
state = { | |
markdownTableInput: "", | |
markdownTableOutput: "", | |
} | |
componentDidMount() { | |
console.log('componentDidMount'); | |
} | |
// static propTypes = {} | |
// static defaultProps = {} | |
handleInputChange = (event) => { | |
const markdownTableOutput = csvToMarkDownTable(event.target.value); | |
console.log('markdownTableOutput ', markdownTableOutput); | |
this.setState(prevState => ({ | |
markdownTableInput: event.target.value, | |
markdownTableOutput | |
})); | |
} | |
render() { | |
const { markdownTableOutput, markdownTableInput } = this.state; | |
return ( | |
<div className="markdown-table-wrapper" style={style.markdownTableWrapper}> | |
<textarea type="text" className="flex-item markdown-table-input" style={style.flexItem} onChange={this.handleInputChange} value={markdownTableInput}/> | |
<textarea type="text" className="flex-item markdown-table-output" style={style.flexIte} readOnly value={markdownTableOutput} /> | |
</div> | |
); | |
} | |
} | |
export default MarkdownTableConverter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment