Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(datetimepicker.tsx and dropdown.tsx): multiple languages, onClick
Browse files Browse the repository at this point in the history
Added support for multiple languages (supported by the UI at the time of writing) for
DateTimePicker. Added story to demonstrate new languages. Also added support for onClick in
dropdown.)

fix #324
  • Loading branch information
Vignesh Durai committed May 25, 2020
1 parent 9215903 commit ab390db
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/components/DateTimePicker/DateTimePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { enUS, ptBR } from 'date-fns/locale'
import { enUS, ptBR, arDZ, de, es, fr, it, ja, ru, zhCN } from 'date-fns/locale'
import React, { ReactNode } from 'react'
import InputGroup from 'react-bootstrap/InputGroup'
import DatePicker, { registerLocale, setDefaultLocale } from 'react-datepicker'
Expand All @@ -8,6 +8,14 @@ import 'react-datepicker/dist/react-datepicker.css'

registerLocale('enUS', enUS)
registerLocale('ptBR', ptBR)
registerLocale('ar', arDZ)
registerLocale('de', de)
registerLocale('es', es)
registerLocale('fr', fr)
registerLocale('it', it)
registerLocale('ja', ja)
registerLocale('ru', ru)
registerLocale('zr', zhCN)

setDefaultLocale('enUS')

Expand Down
3 changes: 3 additions & 0 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ interface Props {
const Dropdown = (props: Props) => {
const { text, size, id, items, direction, variant, style, alignRight } = props

const noop = () => {}

const getDropdownItem = (item: Item, i: number) => (
<DropdownRB.Item
style={item.style}
key={item.key || `dropdown-item-${i.toString()}`}
eventKey={item.eventKey || `dropdown-event-${i.toString()}`}
onClick={item.onClick || noop}
>
{item.text}
</DropdownRB.Item>
Expand Down
81 changes: 80 additions & 1 deletion stories/datetimepicker.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { storiesOf } from '@storybook/react'
import React, { useState } from 'react'

import { DateTimePicker } from '../src'
import { DateTimePicker, Dropdown } from '../src'

storiesOf('DateTimePickers', module)
.addParameters({
Expand Down Expand Up @@ -289,3 +289,82 @@ storiesOf('DateTimePickers', module)
</div>
)
})
.add('Supported languages', () => {
const [startDate, setStartDate] = useState(new Date())
const [language, setLanguage] = useState('enUS')

return (
<div>
<Dropdown
text={language}
items={[
{
text: 'enUS',
onClick: () => {
setLanguage('enUS')
},
},
{
text: 'ptBR',
onClick: () => {
setLanguage('ptBR')
},
},
{
text: 'de',
onClick: () => {
setLanguage('de')
},
},
{
text: 'ar',
onClick: () => {
setLanguage('ar')
},
},
{
text: 'es',
onClick: () => {
setLanguage('es')
},
},
{
text: 'fr',
onClick: () => {
setLanguage('fr')
},
},
{
text: 'it',
onClick: () => {
setLanguage('it')
},
},
{
text: 'ja',
onClick: () => {
setLanguage('ja')
},
},
{
text: 'ru',
onClick: () => {
setLanguage('ru')
},
},
{
text: 'zr',
onClick: () => {
setLanguage('zr')
},
},
]}
/>
<DateTimePicker
locale={language}
selected={startDate}
onChange={(date) => setStartDate(date)}
/>
</div>
)
})

0 comments on commit ab390db

Please sign in to comment.