-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add human-readable format option to Date range picker display (#…
- Loading branch information
Showing
15 changed files
with
639 additions
and
52 deletions.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
pages/date-range-picker/absolute-format.localization.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React, { useContext, useState } from 'react'; | ||
import { Box, DateRangePicker, DateRangePickerProps, SpaceBetween, Grid } from '~components'; | ||
import { i18nStrings, isValid } from './common'; | ||
import AppContext, { AppContextType } from '../app/app-context'; | ||
|
||
const locales = [ | ||
'ar', | ||
'de', | ||
'en-GB', | ||
'en-US', | ||
'es', | ||
'fr', | ||
'he', | ||
'id', | ||
'it', | ||
'ja', | ||
'ko', | ||
'ms', | ||
'pt-BR', | ||
'th', | ||
'tr', | ||
'vi', | ||
'zh-CN', | ||
'zh-TW', | ||
]; | ||
|
||
const rtlLocales = new Set(['ar', 'he']); | ||
|
||
type DemoContext = React.Context< | ||
AppContextType<{ | ||
absoluteFormat?: DateRangePickerProps.AbsoluteFormat; | ||
dateOnly?: boolean; | ||
hideTimeOffset?: boolean; | ||
timeOffset?: number; | ||
}> | ||
>; | ||
|
||
const initialRange = { | ||
startDate: '2024-12-09T00:00:00+01:00', | ||
endDate: '2024-12-31T23:59:59+01:00', | ||
}; | ||
|
||
export default function DateRangePickerScenario() { | ||
const { urlParams, setUrlParams } = useContext(AppContext as DemoContext); | ||
|
||
const [value, setValue] = useState<DateRangePickerProps['value']>({ | ||
type: 'absolute', | ||
startDate: urlParams.dateOnly ? initialRange.startDate.slice(0, 10) : initialRange.startDate, | ||
endDate: urlParams.dateOnly ? initialRange.endDate.slice(0, 10) : initialRange.endDate, | ||
}); | ||
|
||
return ( | ||
<Box padding="s"> | ||
<SpaceBetween direction="vertical" size="m"> | ||
<h1>Absolute date range picker with custom absolute format</h1> | ||
<SpaceBetween direction="horizontal" size="xxl"> | ||
<label> | ||
Format{' '} | ||
<select | ||
value={urlParams.absoluteFormat} | ||
onChange={event => | ||
setUrlParams({ | ||
absoluteFormat: event.currentTarget.value as DateRangePickerProps.AbsoluteFormat, | ||
}) | ||
} | ||
> | ||
<option value="">(Default)</option> | ||
<option value="long-localized">Localized</option> | ||
</select> | ||
</label> | ||
<label> | ||
<input | ||
type="checkbox" | ||
checked={urlParams.dateOnly} | ||
onChange={event => setUrlParams({ dateOnly: !!event.target.checked })} | ||
/>{' '} | ||
Date only | ||
</label> | ||
<label> | ||
Time offset from UTC in minutes{' '} | ||
<input | ||
type="number" | ||
value={urlParams.timeOffset} | ||
onChange={event => { | ||
const value = parseInt(event.currentTarget.value); | ||
setUrlParams({ timeOffset: isNaN(value) ? 0 : value }); | ||
}} | ||
/> | ||
</label> | ||
<label> | ||
<input | ||
type="checkbox" | ||
checked={urlParams.hideTimeOffset} | ||
onChange={event => setUrlParams({ hideTimeOffset: !!event.target.checked })} | ||
/>{' '} | ||
Hide time offset | ||
</label> | ||
</SpaceBetween> | ||
<hr /> | ||
{locales.map(locale => ( | ||
<div key={`pickers-${locale}`} dir={rtlLocales.has(locale) ? 'rtl' : 'ltr'}> | ||
<Grid gridDefinition={[{ colspan: 1 }, { colspan: 11 }]}> | ||
<div style={{ textAlign: 'right' }}>{locale}</div> | ||
<DateRangePicker | ||
value={value} | ||
locale={locale} | ||
i18nStrings={i18nStrings} | ||
placeholder={'Filter by a date and time range'} | ||
onChange={e => setValue(e.detail.value)} | ||
relativeOptions={[]} | ||
isValidRange={isValid} | ||
rangeSelectorMode={'absolute-only'} | ||
getTimeOffset={urlParams.timeOffset === undefined ? undefined : () => urlParams.timeOffset!} | ||
absoluteFormat={urlParams.absoluteFormat} | ||
dateOnly={urlParams.dateOnly} | ||
hideTimeOffset={urlParams.hideTimeOffset} | ||
/> | ||
</Grid> | ||
</div> | ||
))} | ||
</SpaceBetween> | ||
</Box> | ||
); | ||
} |
67 changes: 67 additions & 0 deletions
67
pages/date-range-picker/absolute-format.permutations.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React from 'react'; | ||
import { Box, DateRangePicker, DateRangePickerProps, SpaceBetween } from '~components'; | ||
import { i18nStrings, isValid } from './common'; | ||
import ScreenshotArea from '../utils/screenshot-area'; | ||
import PermutationsView from '../utils/permutations-view'; | ||
import createPermutations from '../utils/permutations'; | ||
|
||
const permutations = createPermutations< | ||
Pick<DateRangePickerProps, 'absoluteFormat' | 'dateOnly' | 'hideTimeOffset' | 'value'> | ||
>([ | ||
{ | ||
absoluteFormat: ['iso', 'long-localized'], | ||
dateOnly: [true], | ||
value: [ | ||
{ | ||
type: 'absolute', | ||
startDate: '2024-12-30', | ||
endDate: '2024-12-31', | ||
}, | ||
], | ||
}, | ||
{ | ||
absoluteFormat: ['iso', 'long-localized'], | ||
dateOnly: [false], | ||
hideTimeOffset: [true, false], | ||
value: [ | ||
{ | ||
type: 'absolute', | ||
startDate: '2024-12-30T00:00:00+01:00', | ||
endDate: '2024-12-31T23:59:59+01:00', | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
export default function DateRangePickerPermutations() { | ||
return ( | ||
<Box padding="s"> | ||
<SpaceBetween direction="vertical" size="m"> | ||
<h1>Absolute date range picker with custom absolute format</h1> | ||
<hr /> | ||
<ScreenshotArea> | ||
<PermutationsView | ||
permutations={permutations} | ||
render={permutation => ( | ||
<DateRangePicker | ||
value={permutation.value} | ||
absoluteFormat={permutation.absoluteFormat} | ||
dateOnly={permutation.dateOnly} | ||
hideTimeOffset={permutation.hideTimeOffset} | ||
locale="en-US" | ||
i18nStrings={i18nStrings} | ||
placeholder={'Filter by a date and time range'} | ||
relativeOptions={[]} | ||
isValidRange={isValid} | ||
rangeSelectorMode={'absolute-only'} | ||
getTimeOffset={() => 60} | ||
/> | ||
)} | ||
/> | ||
</ScreenshotArea> | ||
</SpaceBetween> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.