Skip to content

Commit

Permalink
input component (bukinoshita#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita committed Nov 23, 2017
1 parent 3dd6d65 commit d3922be
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 124 deletions.
9 changes: 8 additions & 1 deletion components/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React from 'react'

import { colors, typography } from './../theme'
import { colors, typography, phone } from './../theme'

const Button = ({ children, type, onClick, disabled }) => {
return (
Expand Down Expand Up @@ -37,6 +37,13 @@ const Button = ({ children, type, onClick, disabled }) => {
background-color: ${colors.gray};
cursor: default;
}
@media ${phone} {
button {
display: block;
width: 100%;
}
}
`}</style>
</button>
)
Expand Down
123 changes: 123 additions & 0 deletions components/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
'use strict'

import React from 'react'

import { colors, typography } from './../theme'

const Input = ({
name,
type,
placeholder,
value,
onChange,
autoFocus,
multiline,
customStyle
}) => {
return (
<div>
{multiline ? (
<textarea
name={name}
rows="1"
placeholder={placeholder}
value={value}
onChange={onChange}
autoFocus={autoFocus}
/>
) : (
<input
name={name}
type={type}
placeholder={placeholder}
value={value}
onChange={onChange}
autoFocus={autoFocus}
style={customStyle}
/>
)}

<style jsx>{`
input {
width: 100%;
resize: none;
background-color: transparent;
border: 1px solid ${colors.gray};
padding: 15px;
font-size: ${typography.f12};
color: ${colors.white};
margin-top: 15px;
outline: none;
font-weight: ${typography.semibold};
transition: all 200ms;
max-width: 500px;
}
input::-webkit-input-placeholder {
color: ${colors.gray};
}
input::-moz-placeholder {
color: ${colors.gray};
}
input:-ms-input-placeholder {
color: ${colors.gray};
}
input:-moz-placeholder {
color: ${colors.gray};
}
input:focus {
border-color: ${colors.white};
}
textarea {
width: 100%;
resize: none;
min-height: 100px;
background-color: transparent;
border: 1px solid ${colors.gray};
padding: 15px;
font-size: ${typography.f12};
color: ${colors.white};
outline: none;
font-weight: ${typography.semibold};
transition: all 200ms;
max-width: 500px;
}
textarea::-webkit-input-placeholder {
color: ${colors.gray};
}
textarea::-moz-placeholder {
color: ${colors.gray};
}
textarea:-ms-input-placeholder {
color: ${colors.gray};
}
textarea:-moz-placeholder {
color: ${colors.gray};
}
textarea:focus {
border-color: ${colors.white};
}
`}</style>
</div>
)
}

Input.defaultProps = {
type: 'text',
placeholder: '',
value: '',
multiline: false,
autoFocus: false
}

export default Input
96 changes: 11 additions & 85 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Router from 'next/router'
import Page from './../layouts/page'

import Button from './../components/button'
import Input from './../components/input'

import { colors, typography, phone } from './../theme'

Expand Down Expand Up @@ -63,56 +64,14 @@ class Home extends Component {
render() {
const { message, hasPassphrase, passphrase, requesting } = this.state
const passphraseInput = hasPassphrase ? (
<fieldset>
<input
type="text"
placeholder="Your passphrase"
name="passphrase"
value={passphrase}
onChange={this.onInputChange}
autoFocus={true}
/>

<style jsx>{`
fieldset {
border: 0;
}
input {
width: 100%;
resize: none;
background-color: transparent;
border: 1px solid ${colors.gray};
padding: 15px;
font-size: ${typography.f12};
color: ${colors.white};
margin-top: 15px;
outline: none;
font-weight: ${typography.semibold};
transition: all 200ms;
}
input::-webkit-input-placeholder {
color: ${colors.gray};
}
input::-moz-placeholder {
color: ${colors.gray};
}
input:-ms-input-placeholder {
color: ${colors.gray};
}
input:-moz-placeholder {
color: ${colors.gray};
}
input:focus {
border-color: ${colors.white};
}
`}</style>
</fieldset>
<Input
type="text"
placeholder="Your passphrase"
name="passphrase"
value={passphrase}
onChange={this.onInputChange}
autoFocus={true}
/>
) : (
<span onClick={this.addPassphrase}>
+ add passphrase
Expand All @@ -138,12 +97,13 @@ class Home extends Component {
return (
<Page>
<form onSubmit={this.onSubmit}>
<textarea
<Input
placeholder="Your secret..."
name="message"
value={message}
onChange={this.onInputChange}
autoFocus={true}
multiline={true}
/>

{passphraseInput}
Expand All @@ -162,40 +122,6 @@ class Home extends Component {
text-align: center;
}
textarea {
width: 100%;
resize: none;
min-height: 100px;
background-color: transparent;
border: 1px solid ${colors.gray};
padding: 15px;
font-size: ${typography.f12};
color: ${colors.white};
outline: none;
font-weight: ${typography.semibold};
transition: all 200ms;
}
textarea::-webkit-input-placeholder {
color: ${colors.gray};
}
textarea::-moz-placeholder {
color: ${colors.gray};
}
textarea:-ms-input-placeholder {
color: ${colors.gray};
}
textarea:-moz-placeholder {
color: ${colors.gray};
}
textarea:focus {
border-color: ${colors.white};
}
@media ${phone} {
form {
max-width: 100%;
Expand Down
42 changes: 4 additions & 38 deletions pages/s/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import parser from 'ua-parser-js'
import Page from './../../layouts/page'

import Button from './../../components/button'
import Input from './../../components/input'

import { colors, typography } from './../../theme'

import api from './../../services/api'
Expand Down Expand Up @@ -80,21 +82,20 @@ class S extends Component {

render() {
const { hasPassphrase, passphrase, message, fetched, fetching } = this.state

const styles = this.state.sFetched ? { borderColor: 'red' } : null

const passphraseInput = hasPassphrase ? (
<div>
<p>Shh... we cannot tell you the secret without the passphrase.</p>
<form onSubmit={this.revealSecret}>
<input
<Input
type="text"
placeholder="Your passphrase"
name="passphrase"
value={passphrase}
onChange={this.onInputChange}
style={styles}
autoFocus={true}
customStyle={styles}
/>
<div>
<Button type="submit" disabled={fetching}>
Expand All @@ -109,41 +110,6 @@ class S extends Component {
font-weight: ${typography.semibold};
margin-top: 10px;
}
input {
width: 100%;
resize: none;
background-color: transparent;
border: 1px solid ${colors.gray};
padding: 15px;
font-size: ${typography.f12};
color: ${colors.white};
margin-top: 15px;
outline: none;
font-weight: ${typography.semibold};
transition: all 200ms;
max-width: 500px;
}
input::-webkit-input-placeholder {
color: ${colors.gray};
}
input::-moz-placeholder {
color: ${colors.gray};
}
input:-ms-input-placeholder {
color: ${colors.gray};
}
input:-moz-placeholder {
color: ${colors.gray};
}
input:focus {
border-color: ${colors.white};
}
`}</style>
</div>
) : (
Expand Down

0 comments on commit d3922be

Please sign in to comment.