Skip to content

Commit

Permalink
fix: make #date-picker support for en-US locale
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Nov 11, 2020
1 parent 0501b9a commit 744d143
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
10 changes: 0 additions & 10 deletions packages/dnb-ui-lib/src/components/date-picker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,6 @@ export default class DatePicker extends React.PureComponent {
_listenForPropChanges: true
}

const separators = props.mask_order.match(/[^mdy]/g)
this.maskList = props.mask_order.split(/[^mdy]/).reduce((acc, cur) => {
acc.push(cur)
if (separators.length > 0) {
acc.push(separators.shift())
}
return acc
}, [])
console.log('this.maskList', this.maskList)

if (props.end_date && !isTrue(props.range)) {
warn(
`The DatePicker got a "end_date". You have to set range={true} as well!.`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ export default class DatePickerInput extends React.PureComponent {
this.maskList = props.maskOrder
.split(props.separatorRexExp)
.reduce((acc, cur) => {
acc.push(cur)
if (separators.length > 0) {
acc.push(separators.shift())
if (cur) {
acc.push(cur)
if (separators.length > 0) {
acc.push(separators.shift())
}
}
return acc
}, [])

console.log('this.maskList', this.maskList)

this._startDayRef = React.createRef()
this._startMonthRef = React.createRef()
this._startYearRef = React.createRef()
Expand Down
6 changes: 3 additions & 3 deletions packages/dnb-ui-lib/stories/components/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react'
import { Wrapper, Box } from '../helpers'
import styled from '@emotion/styled'

import enLocale from 'date-fns/locale/en-US'
import enLocale from 'date-fns/locale/en-GB'
import startOfMonth from 'date-fns/startOfMonth'
import lastDayOfMonth from 'date-fns/lastDayOfMonth'
import addDays from 'date-fns/addDays'
Expand Down Expand Up @@ -51,14 +51,14 @@ const ChangeLocale = () => {

// React.useEffect(() => {
// setTimeout(() => {
// setLocale('en-US')
// setLocale('en-GB')
// }, 2e3)
// }, [])

return (
<Dropdown
value={locale}
data={{ 'en-US': 'English', 'nb-NO': 'Norsk' }}
data={{ 'en-GB': 'English', 'nb-NO': 'Norsk' }}
on_change={({ data: { value } }) => {
setLocale(value)
}}
Expand Down

0 comments on commit 744d143

Please sign in to comment.