diff options
| author | Ryan Mehri <[email protected]> | 2020-05-10 10:06:17 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-05-10 10:06:17 -0600 |
| commit | b63c59506439652354d2ae93796732039156dc32 (patch) | |
| tree | be456f581edcf40a4d95337346313fed26b3b8b9 /frontend/src/components | |
| parent | Merge pull request #7 from jackyzha0/react (diff) | |
| parent | input length check and component splitting (diff) | |
| download | ctrl-v-b63c59506439652354d2ae93796732039156dc32.tar.xz ctrl-v-b63c59506439652354d2ae93796732039156dc32.zip | |
Merge pull request #8 from jackyzha0/react
more react changes
Diffstat (limited to 'frontend/src/components')
| -rw-r--r-- | frontend/src/components/CharLimit.js | 37 | ||||
| -rw-r--r-- | frontend/src/components/Header.js | 2 | ||||
| -rw-r--r-- | frontend/src/components/Inputs.js | 47 | ||||
| -rw-r--r-- | frontend/src/components/PasteArea.js | 34 |
4 files changed, 113 insertions, 7 deletions
diff --git a/frontend/src/components/CharLimit.js b/frontend/src/components/CharLimit.js new file mode 100644 index 0000000..623b378 --- /dev/null +++ b/frontend/src/components/CharLimit.js @@ -0,0 +1,37 @@ +import React from 'react'; +import styled, { css } from 'styled-components' + +// show char limit if length > half of max +const Chars = styled.p` + color: #11111100; + font-family: 'Roboto Mono', monospace; + position: absolute; + font-size: 0.8em; + writing-mode: vertical-rl; + top: 50%; + transform: translate(5em, -50%); + right: 0; + transition: all 0.5s cubic-bezier(.25,.8,.25,1); + + ${props => + ((props.content.length / props.maxLength) > 0.5) && + css` + color: #111111; + `}; + + ${props => + ((props.content.length / props.maxLength) > 1) && + css` + color: #ee1111; + `}; +`; + +class CharLimit extends React.Component { + render() { + return ( + <Chars {...this.props} >{this.props.maxLength - this.props.content.length}/{this.props.maxLength}</Chars> + ); + } +} + +export default CharLimit
\ No newline at end of file diff --git a/frontend/src/components/Header.js b/frontend/src/components/Header.js index 1f1f99f..a0c5ee8 100644 --- a/frontend/src/components/Header.js +++ b/frontend/src/components/Header.js @@ -12,7 +12,7 @@ const Header = () => { <span role="img" aria-label="clipboard">📋 </span> ctrl-v </h1> - <h3>pastebin but less ass.</h3> + <h3>a modern, <a href="https://github.com/jackyzha0/ctrl-v" target="_blank" rel="noopener noreferrer">open-source</a> pastebin with latex and markdown rendering support</h3> </SpacedTitle> ); } diff --git a/frontend/src/components/Inputs.js b/frontend/src/components/Inputs.js new file mode 100644 index 0000000..d2238af --- /dev/null +++ b/frontend/src/components/Inputs.js @@ -0,0 +1,47 @@ +import React from 'react'; +import CharLimit from './CharLimit' +import styled from 'styled-components' + +const CharLimitContainer = styled.div` + position: relative; +` + +class TitleInput extends React.Component { + render() { + return ( + <CharLimitContainer> + <input + name="title" + className="lt-shadow" + placeholder="Title" + type="text" + autoComplete="off" + onChange={this.props.onChange} + value={this.props.value} /> + <CharLimit + content={this.props.value} + maxLength={this.props.maxLength} /> + </CharLimitContainer> + ); + } +} + +class PasteInput extends React.Component { + render() { + return ( + <CharLimitContainer> + <textarea + name="content" + placeholder="Paste your text here" + value={this.props.content} + onChange={this.props.onChange} + className="lt-shadow" /> + <CharLimit + content={this.props.content} + maxLength={this.props.maxLength} /> + </CharLimitContainer> + ); + } +} + +export { TitleInput, PasteInput }
\ No newline at end of file diff --git a/frontend/src/components/PasteArea.js b/frontend/src/components/PasteArea.js index f7c060c..f026ef9 100644 --- a/frontend/src/components/PasteArea.js +++ b/frontend/src/components/PasteArea.js @@ -1,31 +1,53 @@ import React from 'react'; +import { TitleInput, PasteInput } from './Inputs' class PasteArea extends React.Component { constructor(props) { super(props); this.state = { - value: '' + title: '', + content: '', }; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); } + componentDidUpdate() { + if (this.state.title === "") { + document.title = `ctrl-v`; + } else { + document.title = `ctrl-v | ${this.state.title}`; + } + } + handleChange(event) { - this.setState({ value: event.target.value }); + const target = event.target; + const name = target.name; + + this.setState({ + [name]: target.value + }); } handleSubmit(event) { - alert('paste content: ' + this.state.value); + console.log(`title: ${this.state.title}`) + console.log(`content: ${this.state.content}`) event.preventDefault(); } render() { return ( <form onSubmit={this.handleSubmit}> - <textarea placeholder="Paste your text here" - value={this.state.value} onChange={this.handleChange} className="lt-shadow"/> - <br></br> + <TitleInput + onChange={this.handleChange} + value={this.state.title} + maxLength="100" /> + <PasteInput + onChange={this.handleChange} + content={this.state.content} + maxLength="100000" /> + <br /> <input className="lt-button lt-shadow lt-hover" type="submit" value="new paste" /> </form> ); |