diff --git a/package.json b/package.json index b1b0865..c3cdbed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cadolabs/sphere-ui", - "version": "5.1.0", + "version": "5.1.1", "main": "dist/index.js", "license": "MIT", "repository": "https://github.com/Cado-Labs/sphere-ui", diff --git a/src/components/DatePicker/index.js b/src/components/DatePicker/index.js index 26f1290..2382e83 100644 --- a/src/components/DatePicker/index.js +++ b/src/components/DatePicker/index.js @@ -2,7 +2,7 @@ import React, { useMemo, useState } from "react" import { Calendar } from "primereact/calendar" import { locale as primeLocale } from "primereact/api" -import { getPartsOfTime, filterTooltipOptions, pickDataAttributes } from "../../utils" +import { getYearRange, filterTooltipOptions, pickDataAttributes } from "../../utils" import { withRange } from "./withRange" import { MONTHS, START_DATE } from "./constants" @@ -65,7 +65,7 @@ export const DatePicker = React.forwardRef(({ onChange, dateFormat, placeholder, - yearRange: getYearRange(), + yearRange: yearRange || getYearRange({ startCalendarDate, startRangeOfYears }), locale: primeLocale().locale, disabled, monthNavigator, @@ -114,13 +114,6 @@ export const DatePicker = React.forwardRef(({ setViewDate(e.value) } - const getYearRange = () => { - const { year } = getPartsOfTime() - const startYear = startCalendarDate ? startCalendarDate.getFullYear() : startRangeOfYears - - return yearRange || `${startYear}:${year}` - } - const renderDateRangePicker = () => { const RangePicker = useMemo(() => withRange(Calendar), []) diff --git a/src/components/DateTimePicker/index.js b/src/components/DateTimePicker/index.js index a10ea51..22ecf08 100644 --- a/src/components/DateTimePicker/index.js +++ b/src/components/DateTimePicker/index.js @@ -1,7 +1,7 @@ import React from "react" import { Calendar } from "primereact/calendar" -import { getPartsOfTime, filterTooltipOptions, pickDataAttributes } from "../../utils" +import { getYearRange, filterTooltipOptions, pickDataAttributes } from "../../utils" import { START_DATE } from "../DatePicker/constants" @@ -55,13 +55,6 @@ export const DateTimePicker = React.forwardRef(({ onVisibleChange, ...props }, ref) => { - const getYearRange = () => { - const { year } = getPartsOfTime() - const startYear = startCalendarDate ? startCalendarDate.getFullYear() : startRangeOfYears - - return yearRange || `${startYear}:${year}` - } - const renderFooter = () => { if (!showUTC || !value) return null @@ -135,7 +128,7 @@ export const DateTimePicker = React.forwardRef(({ showTime monthNavigator={monthNavigator} yearNavigator={yearNavigator} - yearRange={getYearRange()} + yearRange={yearRange || getYearRange({ startCalendarDate, startRangeOfYears })} footerTemplate={renderFooter} tooltip={tooltip} tooltipOptions={filteredTooltipOptions} diff --git a/src/utils/getDate.js b/src/utils/date.js similarity index 50% rename from src/utils/getDate.js rename to src/utils/date.js index 07c8b0d..5669969 100644 --- a/src/utils/getDate.js +++ b/src/utils/date.js @@ -6,6 +6,14 @@ const getPartsOfTime = () => { return { month: currentMonth, day: currentDay, year: currentYear } } +const getYearRange = ({ startCalendarDate, startRangeOfYears }) => { + const startYear = startCalendarDate ? startCalendarDate.getFullYear() : startRangeOfYears + const endYear = getPartsOfTime().year + 1 + + return `${startYear}:${endYear}` +} + export { getPartsOfTime, + getYearRange, } diff --git a/src/utils/index.js b/src/utils/index.js index 3f10412..7430e56 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,4 +1,4 @@ -export { getPartsOfTime } from "./getDate" +export { getPartsOfTime, getYearRange } from "./date" export { filterTooltipOptions } from "./filterTooltipOptions" export { filterOptions } from "./filterOptions" export { pickDataAttributes } from "./pickDataAttributes" diff --git a/storybook/stories/form/DatePicker/datePicker.js b/storybook/stories/form/DatePicker/datePicker.js index d5b77c5..3ecd92f 100644 --- a/storybook/stories/form/DatePicker/datePicker.js +++ b/storybook/stories/form/DatePicker/datePicker.js @@ -15,9 +15,8 @@ function DatePickerExample () { const minDate = new Date() const month = new Date().getMonth() - const nextMonth = (month === 11) ? 0 : month + 1 const maxDate = new Date() - maxDate.setMonth(nextMonth) + maxDate.setMonth(maxDate.getMonth() + 1) const minDate2 = new Date() minDate2.setYear(minDate2.getFullYear() - 1) diff --git a/storybook/stories/form/DateTimePicker/dateTimePicker.js b/storybook/stories/form/DateTimePicker/dateTimePicker.js index 41c7da4..f4e088b 100644 --- a/storybook/stories/form/DateTimePicker/dateTimePicker.js +++ b/storybook/stories/form/DateTimePicker/dateTimePicker.js @@ -16,9 +16,8 @@ function DateTimePickerExample () { const minDate = new Date() const month = new Date().getMonth() - const nextMonth = (month === 11) ? 0 : month + 1 const maxDate = new Date() - maxDate.setMonth(nextMonth) + maxDate.setMonth(maxDate.getMonth() + 1) const onChange = event => { const target = event.target