|
| 1 | +# Migrating from [`n-ui-foundations`](https://github.com/financial-times/n-ui-foundations) to [`dotcom-ui-base-styles`](https://github.com/Financial-Times/dotcom-page-kit/tree/main/packages/dotcom-ui-base-styles) |
| 2 | + |
| 3 | +[`n-ui-foundations`](https://github.com/financial-times/n-ui-foundations) was a package containing default styles for FT.com apps and components. It's been replaced by [`dotcom-ui-base-styles`](https://github.com/Financial-Times/dotcom-page-kit/tree/main/packages/dotcom-ui-base-styles), which is part of Page Kit. |
| 4 | + |
| 5 | +## Migrating the Javascript utilities |
| 6 | + |
| 7 | +`n-ui-foundations`'s Javascript utilities are deprecated and haven't been moved to `dotcom-ui-base-styles`. There are three utilities still in use in FT.com repos, which have web-native replacements: |
| 8 | + |
| 9 | +<table> |
| 10 | +<tr><th><code>n-ui-foundations</code> utility</th><th>replacement</th></tr> |
| 11 | +<tr> |
| 12 | +<td><code>$</code></td><td> |
| 13 | + |
| 14 | +`document.querySelector`/`element.querySelector` |
| 15 | + |
| 16 | +</td></tr><tr> |
| 17 | +<td><code>$$</code></td><td> |
| 18 | + |
| 19 | +`document.querySelectorAll`/`element.querySelectorAll` |
| 20 | + |
| 21 | +</td></tr><tr> |
| 22 | +<td><code>broadcast</code></td><td> |
| 23 | + |
| 24 | +```javascript |
| 25 | +target.dispatchEvent( |
| 26 | + new CustomEvent( |
| 27 | + EVENT_NAME, |
| 28 | + { bubbles: true, cancelable: true, detail: EVENT_DATA } |
| 29 | + ) |
| 30 | +) |
| 31 | +``` |
| 32 | + |
| 33 | +_**nb**: `broadcast` sets `bubbles` and `cancelable` to `true`, but that might not be required, depending on your use case._ |
| 34 | + |
| 35 | +</td></tr></table> |
| 36 | + |
| 37 | +## Migrating Sass |
| 38 | + |
| 39 | +### For apps |
| 40 | + |
| 41 | +1. Your app likely already depends on `dotcom-ui-base-styles`. If it doesn't have a direct dependency on it, install it with `npm install @financial-times/dotcom-ui-base-styles`. |
| 42 | +2. Replace any Sass `@import` for `n-ui-foundations/main` with `@financial-times/dotcom-ui-base-styles/styles`. |
| 43 | +3. Replace any calls to the `n-ui-foundations` Sass mixins with the `dotcom-ui-base-styles` equivalents. The mixins are still available under the old `nUi`-prefixed names, but Sass will print a deprecation warning if you're using them. These are the renamed mixins: |
| 44 | + - `nUiFoundations` → `dotcomUiBaseStyles` |
| 45 | + - `nUiGrid` → `dotcomGrid` |
| 46 | + - `nUiTypography` → `dotcomUiTypography` |
| 47 | + - `nUiUtil` → `dotcomUiUtil` |
| 48 | + |
| 49 | +### For components |
| 50 | + |
| 51 | +Originally, `n-ui-foundations` was intended to make sure the versions of [Origami](https://origami.ft.com/) components used by FT.com components and apps were consistent, ensuring we didn't have duplicate CSS or inconsistent design. Since Origami 2, this requirement is handled by npm peer dependencies. This means `dotcom-ui-base-styles` **no longer needs to support components**. |
| 52 | + |
| 53 | +1. Remove any imports in your component's Sass for `n-ui-foundations`. |
| 54 | +2. Work out which Origami components from `n-ui-foundations` are used by your component. `n-ui-foundations` installs these components: |
| 55 | + - [`o-buttons`](https://github.com/Financial-Times/origami/tree/main/components/o-buttons) |
| 56 | + - [`o-colors`](https://github.com/Financial-Times/origami/tree/main/components/o-colors) |
| 57 | + - [`o-fonts`](https://github.com/Financial-Times/origami/tree/main/components/o-fonts) |
| 58 | + - [`o-grid`](https://github.com/Financial-Times/origami/tree/main/components/o-grid) |
| 59 | + - [`o-icons`](https://github.com/Financial-Times/origami/tree/main/components/o-icons) |
| 60 | + - [`o-normalise`](https://github.com/Financial-Times/origami/tree/main/components/o-normalise) |
| 61 | + - [`o-typography`](https://github.com/Financial-Times/origami/tree/main/components/o-typography) |
| 62 | + - [`o-viewport`](https://github.com/Financial-Times/origami/tree/main/components/o-viewport) |
| 63 | + - [`o-visual-effects`](https://github.com/Financial-Times/origami/tree/main/components/o-visual-effects) |
| 64 | +4. Install the appropriate Origami components as peer dependencies (i.e. with `--save-peer`). |
| 65 | +5. Add Sass `@import`s for these components. |
| 66 | + |
| 67 | +## Remove `n-ui-foundations` as a dependency |
| 68 | + |
| 69 | +Finally, uninstall the `n-ui-foundations` npm package: |
| 70 | + |
| 71 | +```sh |
| 72 | +npm remove n-ui-foundations |
| 73 | +``` |
0 commit comments