From 9abba2202be5db5248a3a561da2fd173f3fdaba6 Mon Sep 17 00:00:00 2001 From: oh3vci Date: Mon, 14 Sep 2020 22:01:44 +0900 Subject: [PATCH] feat: add locale prop for locale string of DatePicker --- main/DatePicker/Calendar/Calendar.tsx | 2 ++ main/DatePicker/Calendar/CalendarWeekDays.tsx | 3 ++- main/DatePicker/PickerCalendar.tsx | 4 +++- main/DatePicker/README.md | 1 + main/DatePicker/index.tsx | 2 ++ main/__tests__/DatePicker.test.tsx | 6 ++++-- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/main/DatePicker/Calendar/Calendar.tsx b/main/DatePicker/Calendar/Calendar.tsx index 4235a74c9..e83c1f227 100644 --- a/main/DatePicker/Calendar/Calendar.tsx +++ b/main/DatePicker/Calendar/Calendar.tsx @@ -48,6 +48,7 @@ interface Props { pastRange?: number; // Number of past months displayed on the calendar futureRange?: number; // Number of future months displayed on the calendar calendarWidth: number; // calendar width + locale?: string; titleContent?: (monthFirst: Date) => React.ReactElement; weekdayFormat?: 'narrow' | 'short'; } @@ -134,6 +135,7 @@ function Calendar(props: Props): React.ReactElement { width: props.calendarWidth, height: 22, }} + locale={props.locale} weekdayFormat={props.weekdayFormat} /> void; containerStyle?: ViewStyle; + locale?: string; onBackdropPress?: () => void; calendarWidth?: number; weekdayFormat?: 'narrow' | 'short'; @@ -36,7 +37,7 @@ interface Props { } const PickerCalendar: FC = (props) => { - const { calendarWidth = 300 } = props; + const { calendarWidth = 300, locale = 'default' } = props; return ( @@ -70,6 +71,7 @@ const PickerCalendar: FC = (props) => { containerStyle={{ overflow: 'hidden', }} + locale={locale} renderDay={({ date, isCurrentMonth, diff --git a/main/DatePicker/README.md b/main/DatePicker/README.md index 8a8a2ab25..a9655788d 100644 --- a/main/DatePicker/README.md +++ b/main/DatePicker/README.md @@ -16,6 +16,7 @@ | style | | ViewStyle | | | label | | string | `default arrow image` | | labelTextStyle | | TextStyle | `` | +| locale | | string | `default` | | errorText | | string | `Invalid Date` | | errorTextStyle | | TextStyle | `{ color: '#F00', textAlign: 'left' }` | | dateTextStyle | | TextStyle | diff --git a/main/DatePicker/index.tsx b/main/DatePicker/index.tsx index 8bc6eff78..47e835414 100644 --- a/main/DatePicker/index.tsx +++ b/main/DatePicker/index.tsx @@ -17,6 +17,7 @@ interface Props { style?: ViewStyle; label?: string; labelTextStyle?: TextStyle; + locale?: string; errorText?: string; errorTextStyle?: TextStyle; dateTextStyle?: TextStyle; @@ -59,6 +60,7 @@ const DatePicker = (props: Props): React.ReactElement => { setCalendarVisible(false); }} containerStyle={{ width: 300, height: 350 }} + locale={props.locale} weekdayFormat={props.weekdayFormat} titleContent={props.titleContent} /> diff --git a/main/__tests__/DatePicker.test.tsx b/main/__tests__/DatePicker.test.tsx index 8945e0fcc..f73b061aa 100644 --- a/main/__tests__/DatePicker.test.tsx +++ b/main/__tests__/DatePicker.test.tsx @@ -14,7 +14,7 @@ const standardDate = new Date('2020-09-13'); describe('[DatePicker] render', () => { it('should render without crashing', () => { - const rendered = render().asJSON(); + const rendered = render().asJSON(); expect(rendered).toMatchSnapshot(); expect(rendered).toBeTruthy(); @@ -62,6 +62,7 @@ describe('[PickerCalendar] render', () => { visible={false} onSelectDate={(): void => {}} selectedDate={standardDate} + locale={'en'} weekdayFormat={'narrow'} />, ).asJSON(); @@ -77,6 +78,7 @@ describe('[Calendar]', () => { initDate={standardDate} renderDay={() => } calendarWidth={300} + locale={'en'} />, ).asJSON(); @@ -139,7 +141,7 @@ describe('[CalendarMonth] render', () => { describe('[CalendarWeekDays] render', () => { it('should render without crashing', () => { const rendered = render( - , + , ).asJSON(); expect(rendered).toMatchSnapshot();