Skip to content

Commit 38b9c9c

Browse files
Improve Date Range UX for selecting a single day (#1560)
1 parent 64c76c1 commit 38b9c9c

File tree

12 files changed

+192
-75
lines changed

12 files changed

+192
-75
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## UNRELEASED
9+
10+
### Changed
11+
12+
- InputDateRange allows you to specify a single day range by clicking on one of the date range endpoints
13+
814
## [0.9.18]
915

1016
### Added
@@ -24,7 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2430

2531
## [0.9.17] - 2020-10-12
2632

27-
## Added
33+
### Added
2834

2935
- `Combobox` and `ComboboxMulti` `openOnClick` prop
3036
- `ComboboxInput` now supports `freeInput` prop
@@ -35,7 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3541
- `useDialog` - all of the power of `Dialog` in a hook!
3642
- Visual Snapshot test for `MenuItem`, `MenuGroup`, `Status`
3743

38-
## Changed
44+
### Changed
3945

4046
- `Code`, `CodeBlock` & `Paragraph` now explicitly use `theme.colors.text` as default color
4147
- `Dialog`
0 Bytes
Loading
25.7 KB
Loading
23.3 KB
Loading
25.1 KB
Loading
26.1 KB
Loading
21.9 KB
Loading

storybook/src/Forms/DateRange.stories.tsx renamed to packages/components/src/FieldDateRange/FieldDateRange.story.tsx

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,73 +23,50 @@
2323
SOFTWARE.
2424
2525
*/
26-
import React, { FC, useState } from 'react'
27-
import {
28-
Button,
29-
FieldSelect,
30-
Paragraph,
31-
Popover,
32-
PopoverContent,
33-
} from '@looker/components'
34-
import { DateFormat } from '@looker/components/src/DateFormat'
35-
import { FieldDateRange } from '@looker/components/src/FieldDateRange'
36-
import { InputDateRange } from '@looker/components/src/InputDateRange'
37-
import { Locales } from '@looker/components/src/utils/i18n'
26+
import React, { useState } from 'react'
27+
import { Story } from '@storybook/react/types-6-0'
28+
import { Locales } from '../utils/i18n'
29+
import { FieldSelect } from '../Form/Fields/FieldSelect'
30+
import { Paragraph } from '../Text/Paragraph'
31+
import { DateFormat } from '../DateFormat'
32+
import { FieldDateRange, FieldInputDateRangeProps } from '.'
3833

3934
interface DateRange {
4035
from?: Date
4136
to?: Date
4237
}
4338

4439
export default {
45-
title: 'Forms/DateRange',
40+
component: FieldDateRange,
41+
title: 'FieldDateRange',
4642
}
4743

48-
export const Basic = () => <FieldDateRange />
49-
export const Disabled = () => <FieldDateRange disabled />
50-
51-
export const Controlled: FC = () => {
52-
const startDate = new Date()
53-
startDate.setDate(9)
54-
const endDate = new Date()
55-
endDate.setDate(15)
56-
57-
const [controlledDateRange, setControlledDateRange] = useState<any>()
44+
const Template: Story<FieldInputDateRangeProps> = (args) => (
45+
<FieldDateRange {...args} />
46+
)
47+
48+
export const Basic = Template.bind({})
49+
Basic.args = {
50+
defaultValue: {
51+
from: new Date('May 18, 2020'),
52+
to: new Date('May 21, 2020'),
53+
},
54+
label: 'Pick A Date',
55+
}
5856

59-
const handleNextWeekClick = () => {
60-
setControlledDateRange({
61-
from: new Date('03/02/2020'),
62-
to: new Date('03/09/2020'),
63-
})
64-
}
57+
export const Disabled = Template.bind({})
58+
Disabled.args = {
59+
disabled: true,
60+
label: 'Pick A Date',
61+
}
6562

66-
return (
67-
<Popover
68-
content={
69-
<PopoverContent>
70-
<Button onClick={handleNextWeekClick}>Next Week</Button>
71-
<InputDateRange
72-
value={controlledDateRange}
73-
onChange={setControlledDateRange}
74-
/>
75-
</PopoverContent>
76-
}
77-
>
78-
<Button>
79-
{controlledDateRange ? (
80-
<>
81-
<DateFormat>{controlledDateRange.from}</DateFormat> &mdash;
82-
<DateFormat>{controlledDateRange.to}</DateFormat>
83-
</>
84-
) : (
85-
'Select Dates'
86-
)}
87-
</Button>
88-
</Popover>
89-
)
63+
export const Error = Template.bind({})
64+
Error.args = {
65+
label: 'Pick A Date',
66+
validationMessage: { message: 'Field Disabled', type: 'error' },
9067
}
9168

92-
export const Localized: FC = () => {
69+
export const Localized = () => {
9370
const startDate = new Date()
9471
startDate.setDate(9)
9572
const endDate = new Date()
@@ -141,3 +118,7 @@ export const Localized: FC = () => {
141118
</>
142119
)
143120
}
121+
122+
Localized.parameters = {
123+
storyshots: { disable: true },
124+
}

packages/components/src/FieldDateRange/FieldDateRange.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ import {
3838

3939
export interface FieldInputDateRangeProps
4040
extends FieldProps,
41-
InputDateRangeProps {}
41+
InputDateRangeProps {
42+
ref: Ref<HTMLInputElement>
43+
}
4244

4345
const FieldDateRangeComponent = forwardRef(
4446
(props: FieldInputDateRangeProps, ref: Ref<HTMLInputElement>) => {
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2020 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
import React, { useState } from 'react'
27+
import { Story } from '@storybook/react/types-6-0'
28+
import { Button } from '../Button'
29+
import { Popover, PopoverContent } from '../Popover'
30+
import { DateFormat } from '../DateFormat'
31+
import { InputDateRange, InputDateRangeProps } from './'
32+
33+
export default {
34+
component: InputDateRange,
35+
title: 'InputDateRange',
36+
}
37+
38+
const Template: Story<InputDateRangeProps> = (args) => (
39+
<InputDateRange {...args} />
40+
)
41+
42+
export const Basic = Template.bind({})
43+
Basic.args = {
44+
defaultValue: {
45+
from: new Date('July 25, 2020'),
46+
to: new Date('August 5, 2020'),
47+
},
48+
}
49+
export const Disabled = () => <InputDateRange disabled />
50+
51+
export const Controlled = () => {
52+
const startDate = new Date()
53+
startDate.setDate(9)
54+
const endDate = new Date()
55+
endDate.setDate(15)
56+
57+
const [controlledDateRange, setControlledDateRange] = useState<any>()
58+
59+
const handleNextWeekClick = () => {
60+
setControlledDateRange({
61+
from: new Date('03/02/2020'),
62+
to: new Date('03/09/2020'),
63+
})
64+
}
65+
66+
return (
67+
<Popover
68+
content={
69+
<PopoverContent>
70+
<Button onClick={handleNextWeekClick}>Next Week</Button>
71+
<InputDateRange
72+
value={controlledDateRange}
73+
onChange={setControlledDateRange}
74+
/>
75+
</PopoverContent>
76+
}
77+
>
78+
<Button>
79+
{controlledDateRange ? (
80+
<>
81+
<DateFormat>{controlledDateRange.from}</DateFormat> &mdash;
82+
<DateFormat>{controlledDateRange.to}</DateFormat>
83+
</>
84+
) : (
85+
'Select Dates'
86+
)}
87+
</Button>
88+
</Popover>
89+
)
90+
}
91+
92+
Controlled.parameters = {
93+
storyshots: { disable: true },
94+
}

0 commit comments

Comments
 (0)