-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a87cb3
commit 7048dcc
Showing
18 changed files
with
175 additions
and
61 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
|
||
export { DateInputBox } from './DateInputBox'; | ||
export { DateInputBoxProps } from './DateInputBox.types'; | ||
export { DateInputBox } from './DateInputBox'; | ||
export type { | ||
DateInputBoxProps, | ||
DateSegmentsState, | ||
} from './DateInputBox.types'; |
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 was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
packages/date-picker/src/DatePicker/DatePickerInput/DatePickerInput.spec.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,11 @@ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import { DatePickerInput } from '.'; | ||
|
||
describe('packages/date-picker-input', () => { | ||
test('condition', () => { | ||
|
||
}) | ||
}) |
84 changes: 84 additions & 0 deletions
84
packages/date-picker/src/DatePicker/DatePickerInput/DatePickerInput.stories.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,84 @@ | ||
/* eslint-disable react/prop-types */ | ||
import React, { useEffect, useState } from 'react'; | ||
import { StoryFn } from '@storybook/react'; | ||
import { isValid } from 'date-fns'; | ||
|
||
import LeafyGreenProvider from '@leafygreen-ui/leafygreen-provider'; | ||
import { StoryMetaType } from '@leafygreen-ui/lib'; | ||
|
||
import { | ||
DatePickerContextProps, | ||
DatePickerProvider, | ||
} from '../../DatePickerContext'; | ||
|
||
import { DatePickerInput } from './DatePickerInput'; | ||
|
||
const ProviderWrapper = (Story: StoryFn, ctx?: { args: any }) => ( | ||
<LeafyGreenProvider darkMode={ctx?.args.darkMode}> | ||
<DatePickerProvider | ||
value={{ | ||
...ctx?.args, | ||
}} | ||
> | ||
<Story /> | ||
</DatePickerProvider> | ||
</LeafyGreenProvider> | ||
); | ||
|
||
const meta: StoryMetaType<typeof DatePickerInput, DatePickerContextProps> = { | ||
title: 'Components/DatePicker/DatePickerInput', | ||
component: DatePickerInput, | ||
decorators: [ProviderWrapper], | ||
parameters: { | ||
default: null, | ||
generate: { | ||
combineArgs: { | ||
darkMode: [false, true], | ||
value: [null, new Date('1993-12-26')], | ||
dateFormat: ['iso8601', 'en-US', 'en-UK', 'de-DE'], | ||
timeZone: ['UTC', 'Europe/London', 'America/New_York', 'Asia/Seoul'], | ||
}, | ||
excludeCombinations: [ | ||
{ | ||
timeZone: ['Europe/London', 'America/New_York', 'Asia/Seoul'], | ||
value: null, | ||
}, | ||
], | ||
decorator: ProviderWrapper, | ||
}, | ||
}, | ||
args: { | ||
label: 'Label', | ||
dateFormat: 'en-UK', | ||
timeZone: 'Europe/London', | ||
}, | ||
argTypes: { | ||
value: { control: 'date' }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Basic: StoryFn<typeof DatePickerInput> = props => { | ||
const [date, setDate] = useState<Date | null>(null); | ||
|
||
useEffect(() => { | ||
if (props.value && isValid(new Date(props.value))) { | ||
setDate(new Date(props.value)); | ||
} | ||
}, [props.value]); | ||
|
||
const updateDate = (date: Date | null) => { | ||
setDate(date); | ||
}; | ||
|
||
return ( | ||
<> | ||
<DatePickerInput {...props} value={date} setValue={updateDate} /> | ||
<b>Current date</b> | ||
<span>{date?.toISOString()}</span> | ||
</> | ||
); | ||
}; | ||
|
||
export const Generated = () => {}; |
4 changes: 4 additions & 0 deletions
4
packages/date-picker/src/DatePicker/DatePickerInput/DatePickerInput.styles.ts
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,4 @@ | ||
|
||
import { css } from '@leafygreen-ui/emotion'; | ||
|
||
export const baseStyles = css``; |
9 changes: 9 additions & 0 deletions
9
packages/date-picker/src/DatePicker/DatePickerInput/DatePickerInput.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,9 @@ | ||
import React from 'react'; | ||
import { DatePickerInputProps } from './DatePickerInput.types'; | ||
|
||
// TODO: forwardRef | ||
export function DatePickerInput({}: DatePickerInputProps) { | ||
return <div>your content here</div>; | ||
} | ||
|
||
DatePickerInput.displayName = 'DatePickerInput'; |
1 change: 1 addition & 0 deletions
1
packages/date-picker/src/DatePicker/DatePickerInput/DatePickerInput.types.ts
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 @@ | ||
export interface DatePickerInputProps {} |
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,3 @@ | ||
|
||
export { DatePickerInput } from './DatePickerInput'; | ||
export { DatePickerInputProps } from './DatePickerInput.types'; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...date-picker/src/utils/isValidDate.spec.ts → ...src/utils/isValidDate/isValidDate.spec.ts
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...te-picker/src/utils/isValidLocale.spec.ts → ...utils/isValidLocale/isValidLocale.spec.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { isUndefined } from 'lodash'; | ||
|
||
import { DateSegmentValue } from '../../DateInputSegment'; | ||
|
||
/** | ||
* Returns whether a given value is a valid segment value | ||
*/ | ||
export const isValidSegment = (segment?: DateSegmentValue): segment is number => | ||
!isUndefined(segment) && !isNaN(Number(segment)); |
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,3 @@ | ||
/** Returns whether the provided value is some form of zero value */ | ||
export const isZeroLike = (val: any) => | ||
!val || isNaN(val) || ['', '0', '00', 0].includes(val); |
19 changes: 19 additions & 0 deletions
19
packages/date-picker/src/utils/newDateFromSegments/index.ts
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,19 @@ | ||
import { DateSegmentsState } from '../../DateInputBox'; | ||
import { isValidSegment } from '../isValidSegment'; | ||
|
||
/** Constructs a date object from day, month, year segments */ | ||
export const newDateFromSegments = ( | ||
segments: DateSegmentsState, | ||
): Date | undefined => { | ||
if (segments && Object.values(segments).every(isValidSegment)) { | ||
const { day, month, year } = segments; | ||
return new Date( | ||
year as number, | ||
(month as number) - 1, | ||
day as number, | ||
0, | ||
0, | ||
0, | ||
); | ||
} | ||
}; |
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,22 @@ | ||
import { utcToZonedTime, zonedTimeToUtc } from 'date-fns-tz'; | ||
|
||
/** | ||
* Converts a date in the client's time zone to | ||
*/ | ||
export const toTimeZone = (clientDate: Date | string, timeZone: string) => { | ||
const clientTz = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
const utc = zonedTimeToUtc(clientDate, clientTz); | ||
const tz = utcToZonedTime(utc, timeZone); | ||
return tz; | ||
}; | ||
|
||
/** Converts a date from a given time zone to the client's time zone */ | ||
export const toClientTimeZone = ( | ||
sourceDate: Date | string, | ||
sourceTimeZone: string, | ||
) => { | ||
const clientTz = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
const utc = zonedTimeToUtc(sourceDate, sourceTimeZone); | ||
const client = utcToZonedTime(utc, clientTz); | ||
return client; | ||
}; |