Migrating to v3
This guide will show you how to upgrade your codebase.
1Package upgrade
1yarn upgrade @defencedigital/react-component-library
And:
1yarn upgrade @defencedigital/design-tokens2yarn upgrade @defencedigital/eslint-config-react3yarn upgrade @defencedigital/fonts4yarn upgrade @defencedigital/icon-library
2Breaking changes
Components
Autocomplete
Use
Autocompleteinstead ofSelectfor behaviour when the user could type and select an item
Avatar
Replace
initialsby usingchildren
Button
Remove use of
colorUse
COMPONENT_SIZEforsizeUse
BUTTON_VARIANT.DANGERforvariantinstead ofcolor={BUTTON_COLOR.DANGER}
Checkbox
Use
checkedinstead ofisCheckedRemove use of
isValid
CheckboxEnhanced
Use
Checkboxinstead ofCheckboxEnhanced
ContextMenu
Remove
positionas component is positioned based on available screen real estateUpdate
onHidecallback parametersUpdate
onShowcallback parameters
DataList
Use the replacement
DescriptionList
DatePicker
Use
Placementfrom@popperjsforplacementUse
initialIsOpeninstead ofisOpenUse
startDateandendDateinstead of valueIf
startDateandendDateare used, these should now be set from the current form state instead of the initial form values. Alternatively, you can useinitialStartDateandinitialEndDateto only set the initial valuesonChangeis now called when an invalid or disabled date is typed. You should ensure these are correctly handled in your form validation logicThe calendar no longer automatically opens when the input is focused. This may affect automated tests
Check presentation as external margins have been removed
Remove use of
isValid
DescriptionList
Use instead of
DataListUse
descriptioninstead oftitleonDescriptionListUse
titleinstead ofdescriptiononDescriptionListItemCheck presentation as external margins have been removed
DismissibleBanner
Rename to
DismissibleBannerfromDismissableBanner
Masthead
Update
onSearchcallback parameters
NumberInput
Remove use of
canClearUse
size={COMPONENT_SIZE.SMALL}instead ofisCondensedUpdate
onChangecallback parametersUse
iconorprefixinstead ofstartAdornmentUse
suffixinstead ofunitUse
prefixorsuffixinstead ofunitPositionCheck presentation as external margins have been removed
Remove use of
isValid
Pagination
Update
onChangecallback parameters
Radio
Use
defaultCheckedinstead ofisCheckedRemove use of
isValid
RadioEnhanced
Use
Radioinstead ofRadioEnhanced
RangeSlider
Some of the behaviours associated with this component have fundamentally changed. Refer to the design specification.
Select
Replace instances with
Autocompletewhere autocomplete/typeahead behaviour is requiredRemove use of
isClearableas the clear button is always presented when an item is selectedSpecify children using
SelectOptionrather than an array of value and label optionsUpdate
onChangecallback parameters to usevalue: string | nullrather thanevent: anyRemove use of
isValid
Sidebar
There is the ability to use the
Sidebarwithin a layout by usingSidebarWrapperAs the component is more composable
navis no longer a prop.
Refer to Storybook for code examples.
Switch
Specify children using
SwitchOptionrather than an array of value and label optionsUse
COMPONENT_SIZEforsizeRemove use of
isValid
TabSet
Use
TabSetIteminstead ofTabUpdate parameters for use of
onChangecallbackA ResizeObserver polyfill is required in older browsers and in Jest. The CRA template has been updated to reflect this
TextArea
Remove use of
footnotein favour of using the component in conjunction withFieldandhintText.Remove use of
isValid
TextInput
Add a
labelRemove use of
placeholderCheck presentation as external margins have been removed
Remove use of
footnotein favour of using the component in conjunction withFieldandhintText.Remove use of
isValid
Timeline
Replace render callback with prop bag in
TimelineDay,TimelineDays,TimelineEvent,TimelineHour,TimelineHours,TimelineMonth,TimelineMonths,TimelineRow,TimelineRows,TimelineTodayMarker,TimelineWeek,TimelineWeeksUse the
hasSideprop instead ofTimelineSideRename use of
renderColumnsto render onTimelineRowsRemove use of
dayWidthanddaysTotalinrendercallback ofTimelineWeeksRemove use of
isAfterEndandisBeforeStartinuseTimelinePositionin favour ofstartsAfterEndandstartsAfterStart
Strict null checks
strictNullChecks has been enabled. Interfaces are now more accurate about whether props accept null or undefined. There are no changes required by consumers.
Root font size
Root font-size breakpoints have been removed so any workarounds to fix this can be safely removed.
To fix a problem with the inconsistent position of bold font compared to other weights, fonts are no longer being loaded from Google CDN. It is worth checking text presentation, in particular where different weights are being used.
Forms
Use Field, Fieldset and SectionDivider to replace withFormik and FormikGroup.
Icons (legacy icons are gone)
Replace dependency on legacy icons with
@defencedigital/icon-libraryequivalent
Legacy icons that have been removed:
BellGraphHouseLogoRightArrowSearchToolsVisibilityVisibilityOff
Design Tokens
Use
ColorGroupinstead ofColourGroup
Eslint config
eslint-config-airbnb has been upgraded. The new version includes official compatibility with ESLint 8, drops support for ESLint 6 and older and adds a few new rules.
List of rule changes:
https://github.com/airbnb/javascript/commit/f3d3a075cda2acc02011e71991c10bb5b4a15278
https://github.com/airbnb/javascript/commit/1bc8cabd447ef9ce69d27ae70e67eb47daeffc21
react/function-component-definition has been turned off.
CSS Framework
There is not a 3.x.x of @defencedigital/css-framework and it is strongly recommended to remove any dependencies on this legacy framework. If a dependency is still required then use 2.x.x of @defencedigital/css-framework.
The root of your application should now be wrapped with a single instance of the provided GlobalStyleProvider context provider. (GlobalStyleProvider applies various global styles, and as such, only one instance of it should be mounted at once.)