Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
feat: add locale prop for locale string of DatePicker
Browse files Browse the repository at this point in the history
  • Loading branch information
oh3vci authored and JeffGuKang committed Sep 16, 2020
1 parent 39c3a05 commit 6f452bc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions main/DatePicker/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -134,6 +135,7 @@ function Calendar(props: Props): React.ReactElement {
width: props.calendarWidth,
height: 22,
}}
locale={props.locale}
weekdayFormat={props.weekdayFormat}
/>
<FlatList
Expand Down
3 changes: 2 additions & 1 deletion main/DatePicker/Calendar/CalendarWeekDays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const DayTitle = styled.Text`
interface Props {
style?: ViewStyle;
calendarWidth: number;
locale?: string;
weekdayFormat?: 'narrow' | 'short';
}

Expand All @@ -39,7 +40,7 @@ function CalendarWeekDays(props: Props): React.ReactElement {

for (let idx = 0; idx <= 6; idx++) {
const matchMonth = new Date(2020, 8, 6 + idx);
const weekDay = matchMonth.toLocaleString('default', {
const weekDay = matchMonth.toLocaleString(props.locale, {
weekday: props.weekdayFormat || 'narrow', // 'narrow',
});

Expand Down
4 changes: 3 additions & 1 deletion main/DatePicker/PickerCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Props {
selectedDate?: Date;
onSelectDate: (date: Date) => void;
containerStyle?: ViewStyle;
locale?: string;
onBackdropPress?: () => void;
calendarWidth?: number;
weekdayFormat?: 'narrow' | 'short';
Expand All @@ -36,7 +37,7 @@ interface Props {
}

const PickerCalendar: FC<Props> = (props) => {
const { calendarWidth = 300 } = props;
const { calendarWidth = 300, locale = 'default' } = props;

return (
<Modal visible={props.visible} transparent={true} animationType={'fade'}>
Expand Down Expand Up @@ -70,6 +71,7 @@ const PickerCalendar: FC<Props> = (props) => {
containerStyle={{
overflow: 'hidden',
}}
locale={locale}
renderDay={({
date,
isCurrentMonth,
Expand Down
1 change: 1 addition & 0 deletions main/DatePicker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 2 additions & 0 deletions main/DatePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Props {
style?: ViewStyle;
label?: string;
labelTextStyle?: TextStyle;
locale?: string;
errorText?: string;
errorTextStyle?: TextStyle;
dateTextStyle?: TextStyle;
Expand Down Expand Up @@ -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}
/>
Expand Down
6 changes: 4 additions & 2 deletions main/__tests__/DatePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const standardDate = new Date('2020-09-13');

describe('[DatePicker] render', () => {
it('should render without crashing', () => {
const rendered = render(<DatePicker selectedDate={standardDate} />).asJSON();
const rendered = render(<DatePicker selectedDate={standardDate} locale={'en'} />).asJSON();

// expect(rendered).toMatchSnapshot();
expect(rendered).toBeTruthy();
Expand Down Expand Up @@ -67,6 +67,7 @@ describe('[PickerCalendar] render', () => {
visible={false}
onSelectDate={(): void => {}}
selectedDate={standardDate}
locale={'en'}
weekdayFormat={'narrow'} />,
).asJSON();

Expand All @@ -82,6 +83,7 @@ describe('[Calendar]', () => {
initDate={standardDate}
renderDay={() => <CalendarDate date={standardDate} isToday={false} />}
calendarWidth={300}
locale={'en'}
/>,
).asJSON();

Expand Down Expand Up @@ -144,7 +146,7 @@ describe('[CalendarMonth] render', () => {
describe('[CalendarWeekDays] render', () => {
it('should render without crashing', () => {
const rendered = render(
<CalendarWeekDays calendarWidth={300} weekdayFormat={'narrow'} />,
<CalendarWeekDays calendarWidth={300} weekdayFormat={'narrow'} locale={'en'} />,
).asJSON();

// expect(rendered).toMatchSnapshot();
Expand Down

0 comments on commit 6f452bc

Please sign in to comment.