# @toptal/picasso-codemod [![Picasso NPM package](https://img.shields.io/npm/v/@toptal/picasso-codemod?color=green&logo=toptal)](https://www.npmjs.com/package/@toptal/picasso-codemod) > Codemod scripts for Picasso This repository contains a collection of codemod scripts based for use with [JSCodeshift](https://github.com/facebook/jscodeshift) that help update Picasso APIs. ## Usage: ```shell npx @toptal/picasso-codemod [] [options] ``` @toptal/picasso-codemod can detect what type of repository you use and select files automatically for you. For `monorepo` it looks through following paths: ```shell *libs/*/src/**/*.tsx *hosts/*/src/**/*.tsx *apps/*/src/**/*.tsx *namespaces/*/libs/*/src/**/*.tsx *namespaces/*/apps/*/src/**/*.tsx ``` and for `SPA` it checks: ```shell src/**/*.tsx ``` If your repository follows a different structure, you can **specify path to your files as a second parameter** (`files`) shown in the usage command. ## Limitations Codemods do not guarantee the code format preservation. Therefore be sure to run `prettier` and `eslint` on your repo after applying a codemod. Take a look [here](https://github.com/benjamn/recast/issues/140) to learn more about the issue. ## Included Scripts ### v40.0.0 Replaces spacing property values of `Container` and `Dropdown` components with BASE-aligned property values according to the https://github.com/toptal/picasso/blob/master/docs/decisions/18-spacings.md. Property values that do not have BASE counterpart or are complex expressions have to be updated manually (non-BASE values have to be replaced with BASE ones after consulting with Design Team), codemod outputs the list of such cases for convenience. Run linter or prettier to align updated code with project code style ```sh npx @toptal/picasso-codemod v40.0.0@latest ``` ### v36.0.0 Replaces all imports of RichTextEditor related components to `@toptal/picasso-rich-text-editor` and updates package.json with a new version of `@toptal/picasso`, `@toptal/picasso-rich-text-editor` and `@toptal/picasso-forms` ```sh npx @toptal/picasso-codemod v36.0.0 --run-in-band ``` ### v52.2.0 Replaces compound `Form` with `FormNonCompound` and adjusts all the compound components to be directly imported from `picasso-forms`. #### `non-compound-forms` ```diff -
- - - - - + + + + + + ```
Command ```sh npx @toptal/picasso-codemod v52.2.0/non-compound-forms src/**/*.tsx ```
### v24.0.0 Replaces imports and components from `Sidebar` to `Page.Sidebar` #### `page-sidebar` ```diff - - Foo - - - - + + Foo + + + + ```
Command ```sh npx @toptal/picasso-codemod v24.0.0/page-sidebar ```
### v20.0.0 #### `remove-tooltip-variant` Removes tooltip variant ```diff - + - + ```
Command ```sh npx @toptal/picasso-codemod v20.0.0/remove-tooltip-variant ```
#### `replace-error` Replaces `error` prop with `status` prop for input components that supports `error` prop: `Input`, `NumberInput`, `Autocomplete`, `PasswordInput`, `DatePicker`, `TimePicker`, `Select` and `TagSelector` ```diff - + - + - + ```
Command ```sh npx @toptal/picasso-codemod v20.0.0/replace-error ```
#### `overlay-badge` Rename the removed `OverlayBadge` to `Badge`, `Badge` now has functionality from both components. We also add an prop `size` as `medium` in previous `OverlayBadge`s if `size` is missing, this is because the default for `Badge` is actually `large` ```diff -import { OverlayBadge } from '@toptal/picasso' +import { Badge } from '@toptal/picasso' const foo = () => ( - - - + + + ) ``` ### v19.0.0 #### `rename-rating-stars` Transforms old `Rating` and `Form.Ratings` to their new names, `Rating.Stars` and `Form.Rating.Stars` ```diff - + - + ```
Command ```sh npx @toptal/picasso-codemod v19.0.0/rename-rating-stars ```
### v18.0.0 #### `picasso-lab` Merges `picasso-lab` imports into `picasso` and replaces `picasso-lab` reference with `picasso`. > Note: Some edge cases are not covered. > > If imports cannot be resolved, user will be shown with the warning - which > files cannot be updated and needs manual inspection. Here's how the diff should look like: ```diff -import { Component1, Component2 } from '@toptal/picasso-lab' +import { Component1, Component2 } from '@toptal/picasso' -import * as NamespaceImport from '@toptal/picasso-lab' +import * as NamespaceImport from '@toptal/picasso' -import { Component1 } from '@toptal/picasso' -import { Component2 } from '@toptal/picasso-lab' +import { Component1, Component2 } from '@toptal/picasso' -import { Component1 } from '@toptal/picasso' -// unresolved import -import { Component2 } from '@toptal/picasso-lab' +import { Component1 } from '@toptal/picasso' +// unresolved import +import { Component2 } from '@toptal/picasso' ```
Command ```sh npx @toptal/picasso-codemod v18.0.0/picasso-lab ```
### v17.0.0 #### `typography-sizes` Transforms `Typography`, `TypographyOverflow` and `Amount` size prop from `'small' | 'xsmall'` to `'xsmall' | 'xxsmall'`. This change only applies to variant `body` (which is default) > **Remember to run this codemod only once in your structure!** > > Because in first run: `small --> xsmall` > > but in second run: `xsmall --> xxsmall` > > If you need to run it again, revert/checkout previous changes Here's how the diff should look like: ```diff -Text +Text -Text +Text -Text +Text -Text +Text -Text +Text -Text +Text -Text +Text -Text +Text -Text +Text ```
Command ```sh npx @toptal/picasso-codemod v17.0.0/typography-sizes ```
#### In case you use wrapper components for `Typography` codemod by default checks only `Typography`, `TypographyOverflow` and `Amount` components. If you want to include other components, you need to: 1. create a json file and put your components in it: ```json { "includeComponents": ["Foo", "Bar"] } ``` 2. run command with `--parser-config` param: ```shell npx @toptal/picasso-codemod v17.0.0/typography-sizes --parser-config=path/to/your/config.json ``` #### `container-borders` Removes `bordered` prop from `Container` components with all colored variants. Here's how the diff should look like: ```diff -text +text -text +text -text +text -text +text -text +text ```
Command ```sh npx @toptal/picasso-codemod v17.0.0/container-borders ```
### v16.0.0 #### `revert-colors` Transforms props with `ColorType` for the `Tag.Rectangular`, `Tag` and `Indicator` from `'dark' | 'positive' | 'light' | 'negative' | 'warning' | 'primary'` to `'red' | 'yellow' | 'dark-grey' | 'light-grey' | 'green' | 'blue'`. The diff should look like this: ```diff -Label -Label -Label -Label -Label +Label +Label +Label +Label +Label -Label -Label -Label -Label -Label +Label +Label +Label +Label +Label - - - - - + + + + + ```
Command ```sh npx @toptal/picasso-codemod v16.0.0/revert-colors ```
### v5.0.0 #### `prompt-modal-variants` Updates the PromptModal variant prop from `red | green | blue` to `positive | negative`. The diff should look like this: ```diff - - - + + + ```
Command ```sh npx @toptal/picasso-codemod v5.0.0/prompt-modal-variants ```
#### `label-tag` Renames occurrences of `Label` to `Tag`. ```diff - import { Label } from '@toptal/picasso' + import { Tag } from '@toptal/picasso' const Example = () => ( - + - + Angular JS - + React JS - + Ember JS - + Vue JS - + ) ```
Command ```sh npx @toptal/picasso-codemod v5.0.0/label-tag ```
#### `accordion-borders` Updates the Accordion prop `bordered?: boolean` to `borders: 'all' | 'none'`. The diff should look like this: ```diff -Summary -Summary -Summary -Summary +Summary +Summary +Summary +Summary ```
Command ```sh npx @toptal/picasso-codemod v5.0.0/accordion-borders ```
#### `subheader-pagehead` Renames occurrences of `Subheader` to `PageHead`. ```diff - import { Subheader } from '@toptal/picasso' + import { PageHead } from '@toptal/picasso' const Example = () => ( - + - + - Title + Title - + - + ) ```
Command ```sh npx @toptal/picasso-codemod v5.0.0/subheader-pagehead ```
#### `header-topbar` Renames occurrences of `Page.Header` to `Page.TopBar`. ````diff import { Page } from '@toptal/picasso' const Example = () => ( - + Content - +
Command ```sh npx @toptal/picasso-codemod v5.0.0/header-topbar ````
#### `button-variants` Renames variants of button to new values, replaced circular button with `Button.Circular`. ```diff const Example = () => ( - + ) ```
Command ```sh npx @toptal/picasso-codemod v5.0.0/button-variants ```