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

feat(datetime): Add component #1240

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2a18437
feat(Datetime): add component
levithomason Aug 21, 2017
6a50791
refactor(Datetime): move to addons
levithomason Aug 21, 2017
2d15bc1
wip: reworking data flow
levithomason Aug 28, 2017
3fb58e6
fix(Datetime): fix callbacks
levithomason Sep 14, 2017
31d4314
refactor(Datetime): properly breakdown components
levithomason Sep 14, 2017
99ce7fe
test(Datetime): add conformance tests
levithomason Sep 14, 2017
d7e0afa
feat(Datetime): stub typings
levithomason Sep 14, 2017
09d7782
test(Datetime): expose subcomponents
levithomason Sep 14, 2017
38f9acb
chore(karma): blackbox node_modules in error stack
levithomason Sep 14, 2017
185585c
test(Datetime): unhandled props, element type, subcomponents
levithomason Sep 14, 2017
c308fc5
test(hasValidTypings): improve error messages
levithomason Sep 14, 2017
5ce1ae0
feat(DatetimeYears): fix typings
levithomason Sep 14, 2017
8fe5337
feat(customPropTypes): make chainable with isRequired
levithomason Sep 26, 2017
d4cb2fa
test(Datetime): add required props in tests
levithomason Sep 26, 2017
3626a5c
test(DatetimeMonths): fix propTypes vs typings
levithomason Sep 26, 2017
88b2629
fix(DatetimeYears): fix value propType
levithomason Sep 26, 2017
508c1fb
fix(customPropTypes): do not throw on date object
levithomason Sep 26, 2017
86b5d0f
fix(DatetimeGrid): use props vs this.props
levithomason Sep 26, 2017
c1eb742
test(Datetime): fix most propType/typings tests
levithomason Sep 26, 2017
86071ea
test(Datetime): fix all but onChange tests
levithomason Sep 30, 2017
26353ef
test(Datetime): pass conformance tests :tada:
levithomason Oct 19, 2017
07f7601
fix(gulp-react-docgen): handle null prop types
levithomason Oct 19, 2017
b8f75e8
fix(Datetime): fix layout styles
levithomason Oct 19, 2017
4d45de1
fix(ComponentDoc): handle null prop types
levithomason Oct 19, 2017
929e260
fix(docs): run lint
levithomason Oct 19, 2017
a7902d2
fix(Datetime): cleanup styles and props
levithomason Oct 19, 2017
ebf33a6
docs(Datetime): cleanup default props and styles
levithomason Oct 19, 2017
f1a8e0d
test(Datetime): fix utils and typings tests
levithomason Oct 19, 2017
6bdd692
merge master, resolve conflicts
levithomason Feb 4, 2018
726aa2b
fix(Datetime): fix props so route renders
levithomason Feb 5, 2018
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 .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"jsx-quotes": [2, "prefer-single"],
"max-len": [2, 120, 4],
"no-console": 2,
"no-mixed-operators": 0,
"no-multi-spaces": [2, { "ignoreEOLComments": true }],
"no-return-assign": [2, "except-parens"],
"no-underscore-dangle": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const rowStyle = {
flexDirection: 'row',
}

const getTagType = tag => (tag.type.type === 'AllLiteral' ? 'any' : tag.type.name)
const getTagType = (tag) => {
if (!tag || !tag.type || tag.type.type === 'any') return 'any'

return tag.type.name
}

const ComponentPropFunctionSignature = ({ name, tags }) => {
const params = _.filter(tags, { title: 'param' })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

// IE or standard language
const locale = navigator.userLanguage || navigator.language

// Locale formatted date
const dateFormatter = date => date.toLocaleDateString(locale)

// Locale formatted 12-hour time with seconds removed
const timeFormatter = date => date.toLocaleTimeString(locale, { hour12: true }).replace(/:\d+ /, ' ')

const DatetimeExampleFormatters = () => (
<Datetime
time
dateFormatter={dateFormatter}
timeFormatter={timeFormatter}
/>
)

export default DatetimeExampleFormatters
20 changes: 20 additions & 0 deletions docs/app/Examples/addons/Datetime/Content/Time24HourExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

const Time24HourExample = () => (
<Datetime
time
icon='time'
date={false}
hourFormatter={(date) => {
const options = { hour12: false }
return date.toLocaleTimeString('en-US', options).substr(0, 5)
}}
timeFormatter={(date) => {
const options = { hour12: false }
return date.toLocaleTimeString('en-US', options).substr(0, 5)
}}
/>
)

export default Time24HourExample
20 changes: 20 additions & 0 deletions docs/app/Examples/addons/Datetime/Content/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'

const DatetimeContentExamples = () => (
<ExampleSection title='Content'>
<ComponentExample
title='Using custom Date and Time formatters'
description='A date time component can use custom date and time formatting functions.'
examplePath='addons/Datetime/Content/DatetimeExampleFormatters'
/>
<ComponentExample
title='Time only with forced 24H format'
description='A full Time selector, where the time display is set to US locale but forced into a 24 hour clock'
examplePath='addons/Datetime/Content/Time24HourExample'
/>
</ExampleSection>
)

export default DatetimeContentExamples
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

const DatetimeExampleDisabled = () => (
<Datetime time={false} placeholder='Disabled Date' disabled />
)

export default DatetimeExampleDisabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

function yesterday() {
const _date = new Date()
_date.setDate(_date.getDate() - 1)
return _date
}

function tomorrow() {
const _date = new Date()
_date.setDate(_date.getDate() + 1)
return _date
}

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

export default DatetimeExampleDisabledDays
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

const DatetimeExampleError = () => (
<Datetime time={false} placeholder='Select Date' error />
)

export default DatetimeExampleError
28 changes: 28 additions & 0 deletions docs/app/Examples/addons/Datetime/States/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'

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.',
].join(' ')}
examplePath='addons/Datetime/States/DatetimeExampleDisabledDays'
/>
<ComponentExample
title='Error'
description='A calendar can show an error state'
examplePath='addons/Datetime/States/DatetimeExampleError'
/>
<ComponentExample
title='Disabled'
description='A calendar can be disabled'
examplePath='addons/Datetime/States/DatetimeExampleDisabled'
/>
</ExampleSection>
)

export default DatetimeStatesExamples
19 changes: 19 additions & 0 deletions docs/app/Examples/addons/Datetime/Types/DateRangeExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

const DateRangeExample = () => <Datetime />

// TODO
// const DateRangeExample = () => (
// <Datetime.Range
// defaultValue={[]}
// dateHandler='native'
// name='date_range'
// defaultValue={[new Date('2017-02-28'), new Date('2017-03-10')]}
// onDateChange={(e, {rangeId, name, value}) => {
// console.log("Date selected: ", name, rangeId, value)
// }}
// />
// )

export default DateRangeExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

const DatetimeExampleDateOnly = () => (
<Datetime time={false} placeholder='Select Date' />
)

export default DatetimeExampleDateOnly
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

const DatetimeExampleStartSunday = () => (
<div className='ui two column grid'>
<div className='column'>
<Datetime time={false} placeholder='Week starts Sunday' firstDayOfWeek={0} />
</div>
<div className='column'>
<Datetime time={false} placeholder='Week starts Monday' />
</div>
</div>
)

export default DatetimeExampleStartSunday
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

const DatetimeExampleFull = () => <Datetime time />

export default DatetimeExampleFull
8 changes: 8 additions & 0 deletions docs/app/Examples/addons/Datetime/Types/TimeExampleFull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

const TimeExampleFull = () => (
<Datetime time date={false} />
)

export default TimeExampleFull
35 changes: 35 additions & 0 deletions docs/app/Examples/addons/Datetime/Types/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react'
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'

const DatetimeTypesExamples = () => (
<ExampleSection title='Types'>
<ComponentExample
title='Date'
description='A date only Date selector'
examplePath='addons/Datetime/Types/DatetimeExampleDateOnly'
/>
<ComponentExample
title='First Day Of Week'
description='Set the first day of the week to either Monday or Sunday'
examplePath='addons/Datetime/Types/DatetimeExampleFirstWeekDay'
/>
<ComponentExample
title='Time'
description='A full Time selector, with initial value of the current time'
examplePath='addons/Datetime/Types/TimeExampleFull'
/>
<ComponentExample
title='Date and Time'
description='A full Date and Time selector, with initial value of the current date and time'
examplePath='addons/Datetime/Types/DatetimeExampleFull'
/>
<ComponentExample
title='Range'
description='A date range selector'
examplePath='addons/Datetime/Types/DateRangeExample'
/>
</ExampleSection>
)

export default DatetimeTypesExamples
9 changes: 9 additions & 0 deletions docs/app/Examples/addons/Datetime/Usage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'

const DatetimeUsageExamples = () => (
<ExampleSection title='Usage' />
)

export default DatetimeUsageExamples
10 changes: 10 additions & 0 deletions docs/app/Examples/addons/Datetime/Variations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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 DatetimeVariationsExamples = () => (
<ExampleSection title='Variations' />
)

export default DatetimeVariationsExamples
17 changes: 17 additions & 0 deletions docs/app/Examples/addons/Datetime/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'

import Content from './Content'
import States from './States'
import Types from './Types'
import Usage from './Usage'
import Variations from './Variations'

const DatetimeExamples = () => (
<div>
<Types />
<States />
<Content />
</div>
)

export default DatetimeExamples
2 changes: 1 addition & 1 deletion gulp/plugins/gulp-react-docgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default (filename) => {
// replace prop `description` strings with a parsed doc block object and updated `type`
_.each(parsed.props, (propDef, propName) => {
const { description, tags } = parseDocBlock(propDef.description)
const { name, value } = parseType(propName, propDef)
const { name, value } = parseType(propName, propDef) || {}

parsed.props[propName] = {
...propDef,
Expand Down
11 changes: 3 additions & 8 deletions gulp/plugins/util/parseType.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,15 @@ const parseUnion = (union) => {
}
}

const parsers = {
enum: parseEnum,
union: parseUnion,
}

export default (propName, { type }) => {
if (type === undefined) {
throw new Error([
`The prop "${propName}" does not contain propType definition. This happens if the property is in the `,
'defaultProps, but it is not in the propTypes',
].join(' '))
}
if (type.name === 'enum') return parseEnum(type)
if (type.name === 'union') return parseUnion(type)

const parser = parsers[type.name]

return parser ? parser(type) : type
return type
}
10 changes: 5 additions & 5 deletions gulp/tasks/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ task('clean:docs', (cb) => {
// ----------------------------------------

task('build:docs:docgen', () => src([
`${config.paths.src()}/addons/**/*.js`,
`${config.paths.src()}/addons/**/[A-Z]*.js`,
`${config.paths.src()}/behaviors/**/*.js`,
`${config.paths.src()}/elements/**/*.js`,
`${config.paths.src()}/collections/**/*.js`,
`${config.paths.src()}/modules/**/*.js`,
`${config.paths.src()}/views/**/*.js`,
`${config.paths.src()}/elements/**/[A-Z]*.js`,
`${config.paths.src()}/collections/**/[A-Z]*.js`,
`${config.paths.src()}/modules/**/[A-Z]*.js`,
`${config.paths.src()}/views/**/[A-Z]*.js`,
'!**/index.js',
])
// do not remove the function keyword
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ process.env.CHROME_BIN = revisionInfo.executablePath

const formatError = (msg) => {
// filter out empty lines and node_modules
if (!msg.trim() || /~/.test(msg)) return ''
if (!msg.trim() || /(~|node_modules)/.test(msg)) return ''

// indent the error beneath the it() message
let newLine = ` ${msg}`
Expand Down
Loading