Codemods

The American Express Design System provides a unified language for designing American Express websites and experiences. The design system provides design resources that match our coded components and are aligned with the American Express brand. Included are colors, components, icons and glyphs, type styles, and graphic assets to get you up and running quickly.

Back to All Codemods

DateRangePicker Transform

Converts a v6 DateRangePicker component to a v7 DateRangePicker component.

Automatic Changes

  • Adds the new id prop which is required.
  • Renames the canRetainEndDateOnChange prop to shouldRetainEndDateOnChange.
  • Renames the errorMessage prop to statusMessage.
  • Renames the locale prop to lang.
  • If the placeholder prop exists, updates to showPlaceholder={true}. To customize the placeholder text, update the lang prop.
  • Renames the primaryDate prop to circleDate.dateString. Use the circleDate.label prop to customize the label.
  • Renames the secondaryDate prop to squareDate.dateString. Use the squareDate.label prop to customize the label.
  • Renames the labels.previousMonth prop to labelOverrides.previousMonthButtonScreenReaderLabel.
  • Renames the labels.nextMonth prop to labelOverrides.nextMonthButtonScreenReaderLabel.
  • Removes the labels.openCalendar prop, which has been deprecated. Use the labelOverrides.getCalendarButtonScreenReaderLabel instead.
  • Removes the labels.closeCalendar prop, which has been deprecated. Use the labelOverrides.getCalendarButtonScreenReaderLabel instead.
  • Removes the labels.selectedDate prop, which has been deprecated.
  • Removes the labels.accessibleHint prop, which has been deprecated. Use the hint prop instead.
  • Removes the labels.getPrimaryLabel prop, which has been deprecated. Use circleDate.label prop instead.
  • Removes the labels.getSecondaryLabel prop, which has been deprecated. Use squareDate.label prop instead.
  • Removes the ids prop, which has been deprecated. Use the id prop instead.
  • Removes the dates prop, which has been deprecated. See manual changes below.
  • Removes the showLegend prop, which has been deprecated. If the circleDate or squareDate props are provided, then the legend will be shown.
  • Attempts to transform the deprecated theme prop to the className prop. If it cannot, deletes the theme prop.

For example:

import { DateRangePicker } from '@americanexpress/dls-react6';

export default function Page() {

return (

<DateRangePicker

ids={{ start: 'start-id', end: 'end-id' }}

dates={dates}

canRetainEndDateOnChange={true}

errorMessage="Message."

locale="en-US"

placeholder="MM/DD/YYYY"

primaryDate={primaryDate}

secondaryDate={secondaryDate}

labels={{

previousMonth: 'Previous month',

nextMonth: 'Next month',

openCalendar: 'Open calendar',

closeCalendar: 'Close calendar',

selectedDate: 'Selected date',

accessibleHint: 'Please select a date.',

getPrimaryLabel: () => {},

getSecondaryLabel: () => {},

}}

showLegend={true}

onChange={() => {}}

onBlur={() => {}}

weekdays={weekdays}

format={format}

startDayOffset={startDayOffset}

status={status}

theme={{ color: 'red' }}

{...otherProps}

/>

);

}

Transforms into:

import { DateRangePicker } from '@americanexpress/dls-react';

export default function Page() {

return (

<DateRangePicker

shouldRetainEndDateOnChange={true}

statusMessage="Message."

lang="en-US"

showPlaceholder={true}

circleDate={{

dateString: primaryDate,

label: 'Primary Date',

}}

squareDate={{

dateString: secondaryDate,

label: 'Secondary Date',

}}

labelOverrides={{

previousMonthButtonScreenReaderLabel: 'Previous month',

nextMonthButtonScreenReaderLabel: 'Next month',

}}

onChange={() => {}}

onBlur={() => {}}

weekdays={weekdays}

format={format}

startDayOffset={startDayOffset}

status={status}

id="unique-id-for-date-range-picker"

{...otherProps}

/>

);

}

Manual Changes

Updated Date Format for
dateString

The expected format of the dateString (applicable to the new value, onChange, and onBlur props) across the board is now expected to always be in the format YYYY-MM-DD. If you were previously providing dateStrings to the component in a different format, please update your code to always provide and receive any dateStrings in the format YYYY-MM-DD.

Function signature changes

The onChange and onBlur function signatures has been updated. The second argument is now an object of type:

{

start: { dateString: string, dateObject: Date | null },

end: { dateString: string, dateObject: Date | null },

isInvalid: boolean

}

dates prop is deprecated

Move the following v6 props to the corresponding v7 props:

  • dates.start -> value.start
  • dates.end -> value.end
  • dates.min -> minDate
  • dates.max -> maxDate
  • dates.disabled -> disabledDates

Questions?

Connect with the DLS Team on Slack or by email.

Resources

Check out additional resources.