Merge pull request #131 from IBM/date-picker

fix(date-picker): move l10n customization to createCalendar
This commit is contained in:
Eric Liu 2020-02-03 15:42:40 -08:00 committed by GitHub
commit 6b11cbb5c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,13 +3,6 @@ import l10n from 'flatpickr/dist/l10n/index.js';
import rangePlugin from 'flatpickr/dist/plugins/rangePlugin';
import { cx } from '../../lib';
if (l10n.en) {
l10n.en.weekdays.shorthand.forEach((_, index) => {
const shorthand = _.slice(0, 2);
l10n.en.weekdays.shorthand[index] = shorthand === 'Th' ? 'Th' : shorthand.charAt(0);
});
}
function updateClasses(instance) {
const { calendarContainer, days, daysContainer, weekdayContainer, selectedDates } = instance;
@ -48,12 +41,23 @@ function updateMonthNode(instance) {
}
function createCalendar({ options, base, input, dispatch }) {
let locale = options.locale;
if (options.locale === 'en' && l10n && l10n.en) {
l10n.en.weekdays.shorthand.forEach((_, index) => {
const shorthand = _.slice(0, 2);
l10n.en.weekdays.shorthand[index] = shorthand === 'Th' ? 'Th' : shorthand.charAt(0);
});
locale = l10n.en;
}
return new flatpickr(base, {
...options,
allowInput: true,
disableMobile: true,
clickOpens: true,
locale: l10n[options.locale],
locale,
plugins: [options.mode === 'range' && new rangePlugin({ position: 'left', input })].filter(
Boolean
),