diff --git a/src/components/DateTimePicker/DateTimePicker.tsx b/src/components/DateTimePicker/DateTimePicker.tsx index ad418cd8..089c62ba 100644 --- a/src/components/DateTimePicker/DateTimePicker.tsx +++ b/src/components/DateTimePicker/DateTimePicker.tsx @@ -1,4 +1,4 @@ -import { enUS, ptBR } from 'date-fns/locale' +import * as locales from 'date-fns/locale' import React, { ReactNode, CSSProperties } from 'react' import InputGroup from 'react-bootstrap/InputGroup' import DatePicker, { registerLocale, setDefaultLocale } from 'react-datepicker' @@ -6,8 +6,14 @@ import DatePicker, { registerLocale, setDefaultLocale } from 'react-datepicker' import { Icon } from '../Icon' import 'react-datepicker/dist/react-datepicker.css' -registerLocale('enUS', enUS) -registerLocale('ptBR', ptBR) +// Generic way to register all available locales +Object.entries(locales).forEach(([key, locale]) => { + registerLocale(key, locale) +}) + +// Additional locales required for the frontend +registerLocale('ar', locales.arDZ) +registerLocale('zr', locales.zhCN) setDefaultLocale('enUS') diff --git a/src/components/Dropdown/Dropdown.tsx b/src/components/Dropdown/Dropdown.tsx index 236350f5..8bf818a6 100644 --- a/src/components/Dropdown/Dropdown.tsx +++ b/src/components/Dropdown/Dropdown.tsx @@ -40,6 +40,7 @@ const Dropdown = (props: Props) => { style={item.style} key={item.key || `dropdown-item-${i.toString()}`} eventKey={item.eventKey || `dropdown-event-${i.toString()}`} + onClick={item.onClick} > {item.text} diff --git a/stories/datetimepicker.stories.tsx b/stories/datetimepicker.stories.tsx index de87429b..3debd3c2 100644 --- a/stories/datetimepicker.stories.tsx +++ b/stories/datetimepicker.stories.tsx @@ -1,7 +1,8 @@ import { storiesOf } from '@storybook/react' +import * as locales from 'date-fns/locale' import React, { useState } from 'react' -import { DateTimePicker } from '../src' +import { DateTimePicker, Dropdown } from '../src' storiesOf('DateTimePickers', module) .addParameters({ @@ -289,3 +290,38 @@ storiesOf('DateTimePickers', module) ) }) + .add('Supported languages', () => { + const [startDate, setStartDate] = useState(new Date()) + const [language, setLanguage] = useState('enUS') + const items = Object.keys(locales).map((locale) => ({ + text: locale, + onClick: () => { + setLanguage(locale) + }, + })) + const ar = { + text: 'ar', + onClick: () => { + setLanguage('ar') + }, + } + const zr = { + text: 'zr', + onClick: () => { + setLanguage('zr') + }, + } + items.push(ar) + items.push(zr) + + return ( +
+ + setStartDate(date)} + /> +
+ ) + })