Skip to content

Commit

Permalink
chore(Calendar): add stories (#3711)
Browse files Browse the repository at this point in the history
* chore(Calendar): add stories

* fix: texts and format

* fix: flaky tests

* fix: slight change to default dates
  • Loading branch information
OleksandrNechai authored and sashuk committed Jul 11, 2023
1 parent 7ec7c1a commit 9944a6e
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/picasso/src/Calendar/story/Default.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import type { DateOrDateRangeType } from '@toptal/picasso'
import { Calendar } from '@toptal/picasso'

const DefaultExample = () => {
const [value, setValue] = useState<DateOrDateRangeType>(new Date())
const [value, setValue] = useState<DateOrDateRangeType>(
new Date('2021-07-09')
)

return <Calendar value={value} onChange={setValue} />
}
Expand Down
15 changes: 15 additions & 0 deletions packages/picasso/src/Calendar/story/Range.example.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import { Calendar } from '@toptal/picasso'
import { noop } from '@toptal/picasso/utils'

const RangeExample = () => {
return (
<Calendar
value={[new Date('2021-07-11'), new Date('2021-07-18')]}
range
onChange={noop}
/>
)
}

export default RangeExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { Calendar, Tooltip } from '@toptal/picasso'
import { noop } from '@toptal/picasso/utils'

const WithCustomDayRenderingExample = () => {
return (
<Calendar
value={new Date('2021-07-11')}
onChange={noop}
renderDay={({ children }) => {
return <Tooltip content='Message in tooltip'>{children}</Tooltip>
}}
/>
)
}

export default WithCustomDayRenderingExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import { Calendar } from '@toptal/picasso'
import { noop } from '@toptal/picasso/utils'

const WithDisabledIntervalsExample = () => {
return (
<Calendar
activeMonth={new Date('2021-07-05')}
onChange={noop}
disabledIntervals={[
{ start: new Date('2021-07-11'), end: new Date('2021-07-14') },
{ start: new Date('2021-07-28'), end: new Date('2021-07-30') },
]}
/>
)
}

export default WithDisabledIntervalsExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import { Calendar } from '@toptal/picasso'
import { noop } from '@toptal/picasso/utils'

const WithIndicatedIntervalsExample = () => {
return (
<Calendar
activeMonth={new Date('2021-07-05')}
onChange={noop}
indicatedIntervals={[
{ start: new Date('2021-07-11'), end: new Date('2021-07-14') },
{ start: new Date('2021-07-28'), end: new Date('2021-07-30') },
]}
/>
)
}

export default WithIndicatedIntervalsExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { useState } from 'react'
import type { DateOrDateRangeType } from '@toptal/picasso'
import { Calendar } from '@toptal/picasso'

const WithSelectableDaysLimitExample = () => {
const [value, setValue] = useState<DateOrDateRangeType>(
new Date('2021-07-09')
)

return (
<Calendar
value={value}
onChange={setValue}
minDate={new Date('2021-07-08')}
maxDate={new Date('2021-07-15')}
/>
)
}

export default WithSelectableDaysLimitExample
9 changes: 9 additions & 0 deletions packages/picasso/src/Calendar/story/WithTwoMonths.example.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import { Calendar } from '@toptal/picasso'
import { noop } from '@toptal/picasso/utils'

const WithTwoMonthsExample = () => {
return <Calendar onChange={noop} range numberOfMonths={2} />
}

export default WithTwoMonthsExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import { Calendar } from '@toptal/picasso'
import { noop } from '@toptal/picasso/utils'

const WithWeekStartsOnSundayExample = () => {
return <Calendar onChange={noop} weekStartsOn={0} />
}

export default WithWeekStartsOnSundayExample
28 changes: 27 additions & 1 deletion packages/picasso/src/Calendar/story/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,30 @@ page.createTabChapter('Props').addComponentDocs({
name: 'Calendar',
})

page.createChapter().addExample('Calendar/story/Default.example.tsx', 'Default')
page
.createChapter()
.addExample('Calendar/story/Default.example.tsx', 'Default')
.addExample(
'Calendar/story/WithSelectableDaysLimit.example.tsx',
'With selectable days limit'
)
.addExample('Calendar/story/Range.example.tsx', 'Range')
.addExample('Calendar/story/WithCustomDayRendering.example.tsx', {
title: 'With custom day rendering',
description: 'Hover over the days to see a tooltip',
takeScreenshot: false,
})
.addExample(
'Calendar/story/WithDisabledIntervals.example.tsx',
'With disabled intervals'
)
.addExample(
'Calendar/story/WithIndicatedIntervals.example.tsx',
'With indicated intervals'
)
.addExample('Calendar/story/WithTwoMonths.example.tsx', 'With two months')
.addExample('Calendar/story/WithWeekStartsOnSunday.example.tsx', {
title: 'With week starts on Sunday',
description:
'Calendars that start on Sunday, which you’ll more often see in the US, use an old-fashioned notation based on Christianity. Which makes the day that Christians go to church the first day of the week.',
})

0 comments on commit 9944a6e

Please sign in to comment.