diff --git a/packages/clay-date-picker/README.mdx b/packages/clay-date-picker/README.mdx index 76e7b3384b..41cc222cae 100644 --- a/packages/clay-date-picker/README.mdx +++ b/packages/clay-date-picker/README.mdx @@ -61,7 +61,7 @@ To set internationalization of the component, you need to configure the props ac - [`firstDayOfWeek`](#api-firstDayOfWeek) by default the value by default the value is 0 (Sunday) and its values ​​are the days of the week, 1 (Monday), 2 (Tuesday), 3 (Wednesday), 4 (Thursday), 5 (Friday), 6 (Saturday). -- [`dateFormat`](#api-dateFormat) and `timeFormat` is defined according to the **formatting rules of [Moment.js](https://momentjs.com/docs/#/parsing/string-format/)**. +- [`dateFormat`](#api-dateFormat) and `timeFormat` is defined according to the **formatting rules of [date-fns](https://date-fns.org/v2.14.0/docs/format)** which is an implementation of the [unicode technical standards](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table). - [`months`](#api-months) is an `Array` with available months **starting January to December**. - [`weekdaysShort`](#api-weekdaysShort) is an `Array` with the **names of the days of the week in short form**, starting from **Sunday to Saturday**. @@ -86,6 +86,10 @@ To customize the Date Picker content footer you can use the [`footerElement`](#a If you want to expand or close the picker from outside of the component, use the props `expand` and `onExpandChange`. +## Note about Moment.js + +In version 3.4.0, we made the decision to switch to use [date-fns](https://date-fns.org/v2.14.0) instead of Moment.js due to dependency size. Making this changed help reduce the size of @clayui/date-picker by almost 50 KB. + ## API
[APITable "clay-date-picker/src/index.tsx"]
diff --git a/packages/clay-date-picker/docs/index.js b/packages/clay-date-picker/docs/index.js index 78a5832d00..9a6bfd3ec8 100644 --- a/packages/clay-date-picker/docs/index.js +++ b/packages/clay-date-picker/docs/index.js @@ -50,7 +50,7 @@ const DatePickerLocale = () => { return ( = ({ }) => { const memoizedYears: Array = React.useMemo( () => - Helpers.range(years).map((elem) => { + range(years).map((elem) => { return { label: elem, value: elem, @@ -69,7 +68,7 @@ const ClayDatePickerDateNavigation: React.FunctionComponent = ({ * years in the range */ function handleChangeMonth(month: number) { - const date = moment(currentMonth).clone().add(month, 'M').toDate(); + const date = addMonths(currentMonth, month); const year = date.getFullYear(); if (memoizedYears.find((elem) => elem.value === year)) { diff --git a/packages/clay-date-picker/src/DayNumber.tsx b/packages/clay-date-picker/src/DayNumber.tsx index 9c25557c20..ae3819857c 100644 --- a/packages/clay-date-picker/src/DayNumber.tsx +++ b/packages/clay-date-picker/src/DayNumber.tsx @@ -4,10 +4,9 @@ */ import classnames from 'classnames'; -import moment from 'moment'; import React from 'react'; -import {IDay} from './Helpers'; +import {IDay, formatDate, setDate} from './Helpers'; interface IProps { day: IDay; @@ -25,27 +24,25 @@ const ClayDatePickerDayNumber: React.FunctionComponent = ({ const classNames = classnames( 'date-picker-date date-picker-calendar-item', { - active: - moment(day.date).format('YYYY-MM-DD') === - moment(daySelected).format('YYYY-MM-DD'), + active: day.date.toDateString() === daySelected.toDateString(), disabled: day.outside || disabled, } ); - const handleClick = () => onClick(day.date); - return (