From 22c58b4d7d864414c599761f92212a5825003950 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sun, 10 May 2020 00:25:31 -0700 Subject: input length check and component splitting --- frontend/public/index.html | 2 +- frontend/src/components/CharLimit.js | 37 +++++++++++++++++++++++++++++++ frontend/src/components/Inputs.js | 43 +++++++++++++++++++++++++----------- frontend/src/components/PasteArea.js | 14 ++++++++++-- frontend/src/css/index.css | 3 ++- 5 files changed, 82 insertions(+), 17 deletions(-) create mode 100644 frontend/src/components/CharLimit.js diff --git a/frontend/public/index.html b/frontend/public/index.html index 1e1d637..46d87ba 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -10,7 +10,7 @@ /> - 📋 ctrl-v + ctrl-v 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 ( + {this.props.maxLength - this.props.content.length}/{this.props.maxLength} + ); + } +} + +export default CharLimit \ No newline at end of file diff --git a/frontend/src/components/Inputs.js b/frontend/src/components/Inputs.js index 777e3c6..d2238af 100644 --- a/frontend/src/components/Inputs.js +++ b/frontend/src/components/Inputs.js @@ -1,15 +1,27 @@ 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 ( - + + + + ); } } @@ -17,12 +29,17 @@ class TitleInput extends React.Component { class PasteInput extends React.Component { render() { return ( -