|
| 1 | +# NAV designsystem Codemods |
| 2 | + |
| 3 | +Collection of Codemods for easier migration between breaking changes. |
| 4 | + |
| 5 | +Highly inspired by both MUI and NEXT |
| 6 | + |
| 7 | +- [NEXT](https://nextjs.org/docs/advanced-features/codemods) |
| 8 | +- [MUI](https://github.com/mui/material-ui/tree/master/packages/mui-codemod) |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +Codemod transformations runs code-transformations programmatically in your project. This helps when migrating lots of breaking changes without spending hours doing it manually. |
| 13 | + |
| 14 | +NOTE: This codemod only supports fairly "default" usage of components. Components used with dynamic imports, styled-components, non-default imports (example `import * as DS from "@navikt/ds-react"` or `from "@navikt/ds-react/cjs"`) will not work as expected. |
| 15 | + |
| 16 | +```javascript |
| 17 | +npx @navikt/ds-codemod <transform> <path> |
| 18 | +``` |
| 19 | + |
| 20 | +transform - name of transform, see available transforms below. |
| 21 | +path - files or directory to transform |
| 22 | +--dry Do a dry-run, no code will be edited |
| 23 | +--print Prints the changed output for comparison |
| 24 | + |
| 25 | +## Beta (0.19.x) -> v1.0.0 |
| 26 | + |
| 27 | +`npx @navikt/ds-codemod v1.0.0/preset src` |
| 28 | + |
| 29 | +### preset |
| 30 | + |
| 31 | +Combines all avaliable codemods for migrating from beta -> v1.0.0. This transform should only be ran once. |
| 32 | + |
| 33 | +Includes these transforms |
| 34 | + |
| 35 | +- v1.0.0/tabs |
| 36 | +- v1.0.0/chat |
| 37 | +- v1.0.0/pagination |
| 38 | + |
| 39 | +### tabs |
| 40 | + |
| 41 | +`npx @navikt/ds-codemod v1.0.0/tabs src` |
| 42 | + |
| 43 | +```diff |
| 44 | +<Tabs |
| 45 | + defaultValue="logg" |
| 46 | + onChange={(x) => console.log(x)} |
| 47 | +- loop |
| 48 | ++ iconPosition="left" |
| 49 | +> |
| 50 | + <Tabs.List |
| 51 | +- loop |
| 52 | + > |
| 53 | + <Tabs.Tab |
| 54 | + value="logg" |
| 55 | + label="logg" |
| 56 | +- iconPosition="left" |
| 57 | + /> |
| 58 | + </Tabs.List> |
| 59 | + <Tabs.Panel value="logg">TabPanel for Logg-tab</Tabs.Panel> |
| 60 | +</Tabs> |
| 61 | +``` |
| 62 | + |
| 63 | +### chat |
| 64 | + |
| 65 | +`npx @navikt/ds-codemodmod v1.0.0/chat src` |
| 66 | + |
| 67 | +```diff |
| 68 | +-<SpeechBubble |
| 69 | ++<Chat |
| 70 | +- illustration={<Illustration />} |
| 71 | +- topText="Ola Normann 01.01.21 14:00" |
| 72 | +- illustrationBgColor="blue" |
| 73 | ++ avatar={<Illustration />} |
| 74 | ++ name="Ola Normann 01.01.21 14:00" |
| 75 | ++ avatarBgColor="blue" |
| 76 | + backgroundColor="red" |
| 77 | +> |
| 78 | +- <SpeechBubble.Bubble> |
| 79 | ++ <Chat.Bubble> |
| 80 | + Aute minim nisi sunt mollit duis sunt nulla minim non proident. |
| 81 | +- </SpeechBubble.Bubble> |
| 82 | ++ </Chat.Bubble> |
| 83 | +-</SpeechBubble> |
| 84 | ++</Chat> |
| 85 | +``` |
| 86 | + |
| 87 | +### pagination |
| 88 | + |
| 89 | +`npx @navikt/ds-codemod v1.0.0/pagination src` |
| 90 | + |
| 91 | +This codemod should only be ran once, since the size-scale will keep decreasing for each subsequent iteration. |
| 92 | + |
| 93 | +```diff |
| 94 | +-<Pagiation /> |
| 95 | ++<Pagiation size="small"/> |
| 96 | + |
| 97 | +-<Pagiation size="medium"/> |
| 98 | ++<Pagiation size="small"/> |
| 99 | + |
| 100 | +-<Pagiation size="small"/> |
| 101 | ++<Pagiation size="xsmall"/> |
| 102 | +``` |
| 103 | + |
| 104 | +## License |
| 105 | + |
| 106 | +[MIT](https://github.com/navikt/Designsystemet/blob/master/LICENCE) |
0 commit comments