Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HT3 #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

HT3 #27

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"prop-types": "^15.5.10",
"react": "^15.5.0",
"react-day-picker": "^6.0.2",
"react-dom": "^15.5.0",
"react-select": "^1.0.0-rc.5",
"react-transition-group": "^1.2.0"
Expand Down
3 changes: 3 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import PropTypes from 'prop-types'
import ArticleList from './ArticleList'
import ArticlesChart from './ArticlesChart'
import UserForm from './UserForm'
import CustomDayPicker from './CustomDayPicker'

import Select from 'react-select'
import 'react-select/dist/react-select.css'

Expand All @@ -24,6 +26,7 @@ class App extends Component {

return (
<div>
<CustomDayPicker />
<UserForm />
<Select options = {options} value = {this.state.selection} onChange = {this.changeSelection} multi />
<ArticleList articles = {articles} defaultOpenId = {articles[0].id}/>
Expand Down
8 changes: 8 additions & 0 deletions src/components/CommentForm.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.comment-invalid {
border: 4px solid red;
}

.username-invalid {
border: 4px solid red;
}

56 changes: 56 additions & 0 deletions src/components/CommentForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react'
import PropTypes from 'prop-types'
import './CommentForm.css'

export default class CommentForm extends React.Component {
state = {
username: '',
comment: '',
usernameValid: true,
commentValid: true
}

handleUsernameChange = ev => {
ev.preventDefault();

const {value} = ev.target
const {length} = ev.target.value

this.setState({
username: value,
usernameValid: (length >= 5 && length <= 15),
})
}

handleCommentChange = ev => {
ev.preventDefault();

const {value} = ev.target
const {length} = ev.target.value

this.setState({
comment: value,
commentValid: (length >= 20 && length <= 50),
})
}

render() {
return (
<form>
<input
type="text"
value = {this.state.username}
onChange = {this.handleUsernameChange}
className = {this.state.usernameValid ? 'username-valid' : 'username-invalid'}
/>
<textarea
value = {this.state.comment}
cols="20"
rows="4"
onChange = {this.handleCommentChange}
className = {this.state.commentValid ? 'comment-valid' : 'comment-invalid'}
/>
</form>
)
}
}
2 changes: 2 additions & 0 deletions src/components/CommentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import React, {Component} from 'react'
import PropTypes from 'prop-types'
import Comment from './Comment'
import toggleOpen from '../decorators/toggleOpen'
import CommentForm from './CommentForm'

function CommentList({comments = [], isOpen, toggleOpen}) {
const text = isOpen ? 'hide comments' : 'show comments'
return (
<div>
<button onClick={toggleOpen}>{text}</button>
{getBody({comments, isOpen})}
<CommentForm />
</div>
)
}
Expand Down
49 changes: 49 additions & 0 deletions src/components/CustomDayPicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react'
import PropTypes from 'prop-types'

import DayPicker, {DateUtils} from 'react-day-picker'
import 'react-day-picker/lib/style.css'

export default class CustomDayPicker extends React.Component {
constructor(props) {
super(props)

this.state = { from: null, to: null }
}

handleDayClick = day => {
const range = DateUtils.addDayToRange(day, this.state)
this.setState(range)
}

handleResetClick = e => {
e.preventDefault()
this.setState({
from: null,
to: null
})
}

render() {
const { from, to } = this.state

return (
<div className="RangeExample">
{!from && !to && <p>Please select the <strong>first day</strong>.</p>}
{from && !to && <p>Please select the <strong>last day</strong>.</p>}
{from &&
to &&
<p>
{`You chose from ${from.toLocaleString('ru')} to ${to.toLocaleString('ru')}.`}
{' '}<a href="." onClick={this.handleResetClick}>Reset</a>
</p>}
<DayPicker
numberOfMonths={2}
selectedDays={[from, { from, to }]}
onDayClick={this.handleDayClick}
fixedWeeks
/>
</div>
)
}
}