Skip to content

Commit

Permalink
feat(Datetime): add component
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Aug 21, 2017
1 parent 23ec465 commit d39be38
Show file tree
Hide file tree
Showing 40 changed files with 2,998 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/app/Components/ComponentDoc/ComponentProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Extra.propTypes = {
title: PropTypes.node,
}

const getTagType = tag => (tag.type.type === 'AllLiteral' ? 'any' : tag.type.name)
const getTagType = tag => _.get(tag, 'type.type') === 'AllLiteral' ? 'any' : _.get(tag, 'type.name')

/**
* Displays a table of a Component's PropTypes.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 => {
return date.toLocaleTimeString(locale, { hour12: true }).replace(/:\d+ /, ' ')
}

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

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

const Time24HourExample = () => (
<Datetime
time
icon='time'
date={false}
defaultValue={new Date()}
onChange={(e, {value}) => {
console.log("Time selected: ", value)
}}
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/modules/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='modules/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='modules/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/modules/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='modules/Datetime/States/DatetimeExampleDisabledDays'
/>
<ComponentExample
title='Error'
description='A calendar can show an error state'
examplePath='modules/Datetime/States/DatetimeExampleError'
/>
<ComponentExample
title='Disabled'
description='A calendar can be disabled'
examplePath='modules/Datetime/States/DatetimeExampleDisabled'
/>
</ExampleSection>
)

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

const DateRangeExample = () => (
<Datetime.Range
defaultValue={[]}
dateHandler='native'
name='date_range'
defaultValue={[new Date('2017-02-28'), new Date('2017-03-10')]}
onChange={(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,12 @@
import React from 'react'
import { Datetime } from 'semantic-ui-react'

const DatetimeExampleDateOnly = () => (
<Datetime
time={false}
defaultValue={new Date('2017-04-24')}
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
Loading

0 comments on commit d39be38

Please sign in to comment.