|
| 1 | +# Migrate from v2 to v3 |
| 2 | + |
| 3 | +#### Change node-sass to sass |
| 4 | + |
| 5 | +Since |
| 6 | +[node-sass has been deprecated](https://github.com/sass/node-sass#node-sass) and |
| 7 | +[a new module system has been introduced](https://sass-lang.com/blog/the-module-system-is-launched) |
| 8 | +users must switch from `node-sass` to `sass` to use the latest features within |
| 9 | +`react-md`. |
| 10 | + |
| 11 | +```sh |
| 12 | +npm update react-md |
| 13 | +npm uninstall node-sass |
| 14 | +npm install sass |
| 15 | +``` |
| 16 | + |
| 17 | +or with `yarn` |
| 18 | + |
| 19 | +```sh |
| 20 | +yarn add react-md |
| 21 | +yarn remove node-sass |
| 22 | +yarn add sass |
| 23 | +``` |
| 24 | + |
| 25 | +#### Rename InteractionModeListener to UserInteractionModeListener |
| 26 | + |
| 27 | +The `InteractionModeListener` was an alias for `UserInteractionModeListener` and |
| 28 | +has been removed. |
| 29 | + |
| 30 | +#### Remove ResizeObserver |
| 31 | + |
| 32 | +The `ResizeObserver` component has been removed in favor of using the |
| 33 | +`useResizeObserver` hook. |
| 34 | + |
| 35 | +#### Update useResizeObserver to use the new API |
| 36 | + |
| 37 | +```diff |
| 38 | +-const ref = useRef() |
| 39 | +-useResizeObserver({ |
| 40 | +- target: ref, |
| 41 | +- onResize({ height, width, scrollHeight, scrollWidth, element }) { |
| 42 | +- // Do something |
| 43 | +- } |
| 44 | +- disableHeight: true, |
| 45 | +- disableWidth: true |
| 46 | +-}); |
| 47 | ++const [ref] = useResizeObserver((resizeEvent) => { |
| 48 | ++ const { height, width, scrollHeight, scrollWidth, element } = resizeEvent |
| 49 | ++ // do something |
| 50 | ++}, { disableHeight: true, disableWidth: true }); |
| 51 | + |
| 52 | + return ( |
| 53 | + <div ref={ref}> |
| 54 | + {children} |
| 55 | + </div> |
| 56 | + ); |
| 57 | +``` |
| 58 | + |
| 59 | +#### Remove deprecated props from Tooltipped component |
| 60 | + |
| 61 | +Since the `Tooltip` components now use the `HoverModeProvider`, the following |
| 62 | +props should be removed from the `Tooltipped` component: |
| 63 | + |
| 64 | +- `onHide` |
| 65 | +- `onShow` |
| 66 | +- `tooltipId` |
| 67 | +- `hoverDelay` |
| 68 | +- `focusDelay` |
| 69 | +- `touchTimeout` |
| 70 | +- `positionThreshold` |
| 71 | + |
| 72 | +#### Remove TooltipHoverModeConfig |
| 73 | + |
| 74 | +This component has been removed since the `Tooltip` uses the |
| 75 | +`HoverModeProvider`. |
| 76 | + |
| 77 | +#### Update useIndeterminateChecked to use an object as the second argument |
| 78 | + |
| 79 | +```diff |
| 80 | + const { |
| 81 | + getProps, |
| 82 | + rootProps, |
| 83 | + // checkedValues, |
| 84 | + // setCheckedValues, |
| 85 | +-} = useIndeterminateChecked(condiments, ["Sprouts"], customOnChange); |
| 86 | ++} = useIndeterminateChecked(condiments, { |
| 87 | ++ onChange: customOnChange, |
| 88 | ++ defaultCheckedValues: ["Sprouts"], |
| 89 | + }); |
| 90 | +``` |
| 91 | + |
| 92 | +#### Improve build performance by using the new react-md sass file |
| 93 | + |
| 94 | +Part of the v3.0.0 release was to create a |
| 95 | +[new Sass import](https://github.com/mlaursen/react-md/blob/a9995e084480006a77f9123b95ce7275998fb406/packages/react-md/package.json#L9) |
| 96 | +that |
| 97 | +[merges all the .scss files into one](https://github.com/mlaursen/react-md/blob/3e738b4ab14fd7b4aab4f104b0d4120d226b7747/packages/dev-utils/src/utils/styles/combineAllFiles.ts#L105-L109) |
| 98 | +for two reasons: |
| 99 | + |
| 100 | +1. This simplifies importing things from react-md into a single `@use` statement |
| 101 | + instead of multiple lines |
| 102 | +2. Drastically improves build performance in large projects because only one |
| 103 | + `.scss` file needs to be resolved. |
| 104 | + |
| 105 | +`sass-loader` with `webpack` does not maintain context of other `.scss` files in |
| 106 | +your app so each time you `import './path/to/my.scss';` or |
| 107 | +`import styles from './path/to/my.module.scss';`, `sass-loader` will need to |
| 108 | +resolve every `@import` or `@use` statement found in that file recursively. The |
| 109 | +IO required for this is the whole reason build times can get slow in larger |
| 110 | +projects since there are about 200 `.scss` files within react-md that would need |
| 111 | +to be resolved. Combining all the files as a build step within react-md removes |
| 112 | +this issue and drastically increases build performance. |
| 113 | + |
| 114 | +To get started, update your main `.scss` file that imports all the packages |
| 115 | +within `react-md` and generates the styles: |
| 116 | + |
| 117 | +```diff |
| 118 | +-@import '~@react-md/alert/dist/mixins'; |
| 119 | +-@import '~@react-md/app-bar/dist/mixins'; |
| 120 | +-@import '~@react-md/avatar/dist/mixins'; |
| 121 | +-@import '~@react-md/badge/dist/mixins'; |
| 122 | +-@import '~@react-md/button/dist/mixins'; |
| 123 | +-@import '~@react-md/card/dist/mixins'; |
| 124 | +-@import '~@react-md/chip/dist/mixins'; |
| 125 | +-@import '~@react-md/dialog/dist/mixins'; |
| 126 | +-@import '~@react-md/divider/dist/mixins'; |
| 127 | +-@import '~@react-md/elevation/dist/mixins'; |
| 128 | +-@import '~@react-md/expansion-panel/dist/mixins'; |
| 129 | +-@import '~@react-md/form/dist/mixins'; |
| 130 | +-@import '~@react-md/icon/dist/mixins'; |
| 131 | +-@import '~@react-md/layout/dist/mixins'; |
| 132 | +-@import '~@react-md/link/dist/mixins'; |
| 133 | +-@import '~@react-md/list/dist/mixins'; |
| 134 | +-@import '~@react-md/media/dist/mixins'; |
| 135 | +-@import '~@react-md/menu/dist/mixins'; |
| 136 | +-@import '~@react-md/overlay/dist/mixins'; |
| 137 | +-@import '~@react-md/progress/dist/mixins'; |
| 138 | +-@import '~@react-md/sheet/dist/mixins'; |
| 139 | +-@import '~@react-md/states/dist/mixins'; |
| 140 | +-@import '~@react-md/table/dist/mixins'; |
| 141 | +-@import '~@react-md/tabs/dist/mixins'; |
| 142 | +-@import '~@react-md/theme/dist/mixins'; |
| 143 | +-@import '~@react-md/tooltip/dist/mixins'; |
| 144 | +-@import '~@react-md/transition/dist/mixins'; |
| 145 | +-@import '~@react-md/tree/dist/mixins'; |
| 146 | +-@import '~@react-md/typography/dist/mixins'; |
| 147 | +-@import '~@react-md/utils/dist/mixins'; |
| 148 | ++@use 'react-md' as *; |
| 149 | + |
| 150 | + @include react-md-utils; |
| 151 | +``` |
| 152 | + |
| 153 | +Once the main styles have been generated, update the remaining `.scss` files in |
| 154 | +your app replacing `@import` statements of `react-md` packages to be |
| 155 | +`@use 'react-md' as *;`. |
| 156 | + |
| 157 | +#### Overriding react-md Sass variables with the new module system |
| 158 | + |
| 159 | +Check out the new #customizing-your-theme documentation to see how you can |
| 160 | +override `react-md` Sass variables with the new module system and a recommended |
| 161 | +setup. |
0 commit comments