Skip to content

Commit

Permalink
fix(datetime): fix couple hundred lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Mar 26, 2017
1 parent bcc8350 commit 87d50ed
Show file tree
Hide file tree
Showing 22 changed files with 269 additions and 319 deletions.
1 change: 0 additions & 1 deletion docs/app/Examples/modules/Datetime/Content/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
import ContributionPrompt from 'docs/app/Components/ComponentDoc/ContributionPrompt'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'

const DatetimeContentExamples = () => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'
import {yesterday, tomorrow} from '../../../../../../src/lib/dateUtils'
import { yesterday, tomorrow } from '../../../../../../src/lib/dateUtils'

const today = new Date()
const disabledDates = [
yesterday(today),
today,
tomorrow(today)
yesterday(today),
today,
tomorrow(today),
]
const DateTimeExampleDisabledDays = () => (
<Datetime
time={false}
placeholder='Disabled days'
disabledDates={disabledDates}/>
time={false}
placeholder='Disabled days'
disabledDates={disabledDates}
/>
)

export default DateTimeExampleDisabledDays
7 changes: 5 additions & 2 deletions docs/app/Examples/modules/Datetime/States/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const DatetimeStatesExamples = () => (
<ExampleSection title='States'>
<ComponentExample
title='Calendar with disabled days'
description='A calendar can specify a set of disabled dates. This example has today, yesterday and tomorrow disabled.'
description={[
'A calendar can specify a set of disabled dates.',
'This example has today, yesterday and tomorrow disabled.',
].join(' ')}
examplePath='modules/Datetime/States/DateTimeExampleDisabledDays'
/>
<ComponentExample
Expand All @@ -22,4 +25,4 @@ const DatetimeStatesExamples = () => (
</ExampleSection>
)

export default DatetimeStatesExamples;
export default DatetimeStatesExamples
4 changes: 2 additions & 2 deletions docs/app/Examples/modules/Datetime/Types/DateRangeExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ const DateRangeExample = () => (
)

export default DateRangeExample
//defaultSelectionStart={new Date('2017-02-28')}
//defaultSelectionEnd={new Date('2017-03-10')}/>
// defaultSelectionStart={new Date('2017-02-28')}
// defaultSelectionEnd={new Date('2017-03-10')}/>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Datetime } from 'semantic-ui-react'

const TimeExampleFull = () => (
<Datetime date={false} time={true} defaultValue={new Date()} icon='time' />
<Datetime date={false} time defaultValue={new Date()} icon='time' />
)

export default TimeExampleFull
2 changes: 1 addition & 1 deletion docs/app/Examples/modules/Datetime/Types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ const DatetimeTypesExamples = () => (

)

export default DatetimeTypesExamples;
export default DatetimeTypesExamples
2 changes: 1 addition & 1 deletion docs/app/Examples/modules/Datetime/Variations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const DatetimeVariationsExamples = () => (
</ExampleSection>
)

export default DatetimeVariationsExamples;
export default DatetimeVariationsExamples
2 changes: 1 addition & 1 deletion docs/app/Examples/modules/Datetime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ const DatetimeExamples = () => (
</div>
)

export default DatetimeExamples;
export default DatetimeExamples
8 changes: 4 additions & 4 deletions src/lib/customPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,16 @@ export const deprecate = (help, validator) => {

export const DateValue = (props, propName, componentName) => {
if (props[propName]) {
let value = props[propName];
let value = props[propName]
if (typeof value === 'string') {
return new Date(value) != 'Invalid Date' && !isNaN(new Date(value)) ? null :
new Error(propName + ' in ' + componentName + " cannot be parsed as a date");
new Error(propName + ' in ' + componentName + ' cannot be parsed as a date')
} else if (typeof value === 'object') {
return value.getDate != undefined ? null :
new Error(propName + ' in ' + componentName + " is not a Date or a string parsable date");
new Error(propName + ' in ' + componentName + ' is not a Date or a string parsable date')
}
}

// assume all ok
return null;
return null
}
4 changes: 2 additions & 2 deletions src/lib/dateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Table from '../collections/Table/Table'
* @return {string} Returns the number padded with a zero if below 10
*/
export function zeroPad(n) {
return (n < 10 ? '0' : '') + n;
return (n < 10 ? '0' : '') + n
}
/**
* Return the first date of the month for a given date
Expand Down Expand Up @@ -97,7 +97,7 @@ export function RowWrapper(props) {
*/
export function ItemCell(props) {
const { onClick, name, value, active } = props
const className = cx({ active: active })
const className = cx({ active })
const rest = getUnhandledProps(ItemCell, props)
return (
<Table.Cell {...rest} selectable className={className} onClick={onClick}>
Expand Down
80 changes: 39 additions & 41 deletions src/modules/Datetime/Calendar.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import React, { PropTypes } from 'react'
import cx from 'classnames'
import DayCell from './DayCell'
import CalendarHeader from './CalendarHeader'
import Month from './Month'
import Months from './Months'
import Years from './Years'
import Hours from './Hours'
import Minutes from './Minutes'
import DropDown from '../Dropdown/Dropdown'
import Button from '../../elements/Button'
import * as utils from '../../lib/dateUtils'

import {
AutoControlledComponent as Component,
customPropTypes,
getElementType,
getUnhandledProps,
META,
useKeyOnly,
} from '../../lib'

/**
Expand Down Expand Up @@ -127,40 +119,39 @@ export default class Calendar extends Component {
*/
selectionEnd: customPropTypes.DateValue,
defaultSelectionEnd: customPropTypes.DateValue,
range: PropTypes.bool
range: PropTypes.bool,

// TODO what is this used for and what type is it?
page: PropTypes.any,
}

static defaultProps = {
disabledDates: [],
firstDayOfWeek: 1,
date: true,
time: true,
range: false
range: false,
}

static autoControlledProps = [
'value',
'mode',
'selectionStart',
'selectionEnd'
'selectionEnd',
]

constructor(props) {
super(props)
this.state = {
value: new Date(),
hovering: null,
mode: this.getInitialMode(props)
mode: this.getInitialMode(props),
}
}

getInitialMode(props) {
const {date, time} = props
if (!date && time) {
return 'HOUR'
} else {
return 'DAY'
}
const { date, time } = props
return !date && time ? 'HOUR' : 'DAY'
}

/**
Expand Down Expand Up @@ -204,16 +195,17 @@ export default class Calendar extends Component {
*/
setMonth = (e, props) => {
e.stopPropagation()
let { value, page } = props
const { value, page } = props
const nextMode = 'DAY'
const date = new Date(this.state.value)
if (!value && page) {
value = date.getMonth() + page
}
date.setMonth(value)
const month = !value && page
? date.getMonth() + page
: value

date.setMonth(month)
this.trySetState({
value: date,
mode: nextMode
mode: nextMode,
})
if (this.props.onChangeMonth) {
this.props.onChangeMonth(date)
Expand All @@ -230,7 +222,7 @@ export default class Calendar extends Component {
date.setYear(year)
this.trySetState({
value: date,
mode: nextMode
mode: nextMode,
})
}

Expand All @@ -240,13 +232,13 @@ export default class Calendar extends Component {
date.setHours(hour)
this.trySetState({
value: date,
mode: nextMode
mode: nextMode,
})
}

setMinute = (e, minute) => {
e.stopPropagation()
const { onDateSelect, time } = this.props
const { onDateSelect } = this.props
const date = new Date(this.state.value)
date.setMinutes(minute)
const extraState = {}
Expand All @@ -255,7 +247,7 @@ export default class Calendar extends Component {
}
this.trySetState({
value: date,
...extraState
...extraState,
})
if (onDateSelect) {
onDateSelect(new Date(date), e)
Expand All @@ -269,18 +261,18 @@ export default class Calendar extends Component {
*/
setDay = (e, day) => {
e.stopPropagation()
const date = new Date(this.state.value);
const date = new Date(this.state.value)
date.setDate(day)
const { onDateSelect, time } = this.props
const nextMode = time ? 'HOUR' : this.state.mode
const rangeState = {}
if (this.props.range) {
if (this.props.range) {
rangeState.selectionStart = date
}
this.trySetState({
value: date,
mode: nextMode,
...rangeState
...rangeState,
})
if (!time && onDateSelect) {
onDateSelect(new Date(date), e)
Expand All @@ -307,6 +299,9 @@ export default class Calendar extends Component {
case 'YEAR':
this.setYear(e, this.getYear() + (direction * 16), mode)
break

default:
break
}
}

Expand All @@ -329,18 +324,20 @@ export default class Calendar extends Component {
const { mode, value, selectionStart, selectionEnd } = this.state
switch (mode) {
case 'DAY':
return (<Month
firstDayOfWeek={firstDayOfWeek}
content={content}
onClick={this.setDay}
date={value}
selectionStart={selectionStart}
selectionEnd={selectionEnd}
disabledDates={disabledDates}
/>)
return (
<Month
firstDayOfWeek={firstDayOfWeek}
content={content}
onClick={this.setDay}
date={value}
selectionStart={selectionStart}
selectionEnd={selectionEnd}
disabledDates={disabledDates}
/>
)

case 'MONTH':
return <Months content={content} onClick={this.setMonth}/>
return <Months content={content} onClick={this.setMonth} />

case 'YEAR':
return <Years year={this.getYear()} onClick={this.setYear} />
Expand All @@ -350,6 +347,7 @@ export default class Calendar extends Component {

case 'MINUTE':
return <Minutes onClick={this.setMinute} hour={this.getHour()} />

default:
return null
}
Expand Down
17 changes: 4 additions & 13 deletions src/modules/Datetime/CalendarHeader.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import _ from 'lodash'
import cx from 'classnames'
import _ from 'lodash/fp'
import React, { Component, PropTypes } from 'react'

import {
childrenUtils,
createShorthand,
customPropTypes,
META,
getElementType,
getUnhandledProps,
useKeyOnly,
} from '../../lib'

import Menu from '../../collections/Menu/Menu'
Expand Down Expand Up @@ -62,21 +56,18 @@ export default class CalendarHeader extends Component {
}

handleClick = (e) => {

e.stopPropagation()
}

render() {
const {
className,
monthName,
month,
year,
onPrevious,
onNext,
onChangeMode,
mode,
date
date,
} = this.props

const items = _.compact([
Expand All @@ -90,12 +81,12 @@ export default class CalendarHeader extends Component {
{year - 8}-{year + 7}
</Menu.Item>
),
['HOUR', 'MINUTE'].indexOf(mode) > -1 && (
_.includes(mode, ['HOUR', 'MINUTE']) && (
<Menu.Item key='month' onClick={onChangeMode.bind(null, 'MONTH')}>
{monthName}&nbsp;{date.getDate()}
</Menu.Item>
),
['DAY', 'MONTH', 'HOUR', 'MINUTE'].indexOf(mode) > -1 && (
_.includes(mode, ['DAY', 'MONTH', 'HOUR', 'MINUTE']) && (
<Menu.Item key='year' onClick={onChangeMode.bind(null, 'YEAR')}>
{year}
</Menu.Item>
Expand Down
Loading

0 comments on commit 87d50ed

Please sign in to comment.