Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-ui-codemod): add codemod for react-ui 5.0 #3477

Merged
merged 8 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/react-ui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ yarn react-ui-codemod CODEMOD [JSCODESHIFT_OPTIONS] [CODEMOD_OPTIONS]

## Список кодмодов

### react-ui-5.0/renameThemeVars

Переименовывает переменные темы в соответствии с изменениями в [3459](https://github.com/skbkontur/retail-ui/pull/3459)
zhzz marked this conversation as resolved.
Show resolved Hide resolved

```
npx react-ui-codemod react-ui-5.0/renameThemeVars.ts FILES_PATH
```

### react-ui-4.0/transformLabelToCaption

Для компонента `Switcher` переименовывает проп `label` на `caption`. Подробнее здесь [2121#discussion_r488456100](https://github.com/skbkontur/retail-ui/pull/2121#discussion_r488456100).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,39 @@ defineInlineTest(
{},
`
const THEME = ThemeFactory.create({
blue: '#0000ff',
btnLinkLineBorderBottomStyle: 'solid',
linkLineBorderBottomWidth: '2px',
}, DEFAULT_THEME);
blue: '#0000ff',
btnLinkLineBorderBottomStyle: 'solid',
linkLineBorderBottomWidth: '2px',
pagingForwardIconMarginTop: '5px',
tokenMarginY: '20px',
tokenInputLineHeight: '5px',
btnIconGapSmall: '5px',
menuItemIconWidth: '5px',
toggleFontSize: '5px',
checkboxFontSize: '5px',
textareaFontSize: '5px',
radioSize: '5px',
tabFontSize: '5px',
fileUploaderFontSize: '5px',
}, DEFAULT_THEME);
`,
`
const THEME = ThemeFactory.create({
blue: '#0000ff',
btnLinkTextDecorationStyle: 'solid',
linkTextDecorationThickness: '2px',
pagingForwardIconMarginTop: '5px',
tokenMarginYSmall: '20px',
tokenInputLineHeightSmall: '5px',
btnIconGapSmallLeft: '5px',
menuItemIconWidthSmall: '5px',
toggleFontSizeSmall: '5px',
checkboxFontSizeSmall: '5px',
textareaFontSizeSmall: '5px',
radioSizeSmall: '5px',
tabFontSizeLarge: '5px',
fileUploaderFontSizeSmall: '5px',
}, DEFAULT_THEME);
`,
`
const THEME = ThemeFactory.create({
blue: '#0000ff',
btnLinkTextDecorationStyle: 'solid',
linkTextDecorationThickness: '2px',
}, DEFAULT_THEME);
`,
`rename theme variables`,
);
60 changes: 59 additions & 1 deletion packages/react-ui-codemod/react-ui-5.0/renameThemeVars.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { API, FileInfo } from 'jscodeshift';

const RENAMED_VARS: Record<string, string> = {
Expand All @@ -12,6 +11,65 @@ const RENAMED_VARS: Record<string, string> = {
btnLinkHoverLineBorderBottomStyle: 'btnLinkHoverTextDecorationStyle',
btnLinkLineBorderBottomWidth: 'btnLinkTextDecorationThickness',
btnLinkLineBorderBottomOpacity: 'btnLinkTextUnderlineOpacity',
tokenMarginY: 'tokenMarginYSmall',
tokenMarginX: 'tokenMarginXSmall',
tokenFontSize: 'tokenFontSizeSmall',
tokenLineHeight: 'tokenLineHeightSmall',
tokenPaddingY: 'tokenPaddingYSmall',
tokenPaddingX: 'tokenPaddingXSmall',
tokenInputLineHeight: 'tokenInputLineHeightSmall',
tokenInputPaddingY: 'tokenInputPaddingYSmall',
tokenInputPaddingX: 'tokenInputPaddingXSmall',
btnIconGapSmall: 'btnIconGapSmallLeft',
btnIconGapMedium: 'btnIconGapMediumLeft',
btnIconGapLarge: 'btnIconGapLargeLeft',
menuItemIconWidth: 'menuItemIconWidthSmall',
menuItemPaddingForIcon: 'menuItemPaddingForIconSmall',
menuItemLineHeight: 'menuItemLineHeightSmall',
menuItemFontSize: 'menuItemFontSizeSmall',
menuItemPaddingX: 'menuItemPaddingXSmall',
menuMessageLineHeight: 'menuMessageLineHeightSmall',
menuMessageFontSize: 'menuMessageFontSizeSmall',
menuHeaderLineHeight: 'menuHeaderLineHeightSmall',
menuHeaderFontSize: 'menuHeaderFontSizeSmall',
menuHeaderPaddingX: 'menuHeaderPaddingXSmall',
menuHeaderPaddingTop: 'menuHeaderPaddingTopSmall',
menuHeaderPaddingBottom: 'menuHeaderPaddingBottomSmall',
menuLegacyPaddingY: 'menuScrollContainerContentWrapperPaddingY',
toggleFontSize: 'toggleFontSizeSmall',
toggleLineHeight: 'toggleLineHeightSmall',
toggleHandleBorderRadius: 'toggleHandleBorderRadiusSmall',
toggleHeight: 'toggleHeightSmall',
toggleWidth: 'toggleWidthSmall',
toggleBorderRadius: 'toggleBorderRadiusSmall',
toggleBg: 'toggleHandleBg',
toggleHandleSize: 'toggleHandleSizeSmall',
toggleHandleBoxShadowOld: 'toggleHandleBoxShadow',
checkboxFontSize: 'checkboxFontSizeSmall',
checkboxLineHeight: 'checkboxLineHeightSmall',
checkboxBoxSize: 'checkboxBoxSizeSmall',
checkboxPaddingY: 'checkboxPaddingYSmall',
textareaFontSize: 'textareaFontSizeSmall',
textareaLineHeight: 'textareaLineHeightSmall',
textareaMinHeight: 'textareaMinHeightSmall',
textareaPaddingX: 'textareaPaddingXSmall',
textareaPaddingY: 'textareaPaddingYSmall',
radioSize: 'radioSizeSmall',
radioFontSize: 'radioFontSizeSmall',
radioLineHeight: 'radioLineHeightSmall',
radioPaddingY: 'radioPaddingYSmall',
radioBulletSize: 'radioBulletSizeSmall',
tabFontSize: 'tabFontSizeLarge',
tabLineHeight: 'tabLineHeightLarge',
tabPaddingX: 'tabPaddingXLarge',
tabsMarginX: 'tabPaddingXLarge',
tabPaddingY: 'tabPaddingYLarge',
dropdownMenuSelectedBg: 'menuItemSelectedBg',
dropdownMenuHoverBg: 'menuItemHoverBg',
fileUploaderFontSize:'fileUploaderFontSizeSmall',
fileUploaderLineHeight:'fileUploaderLineHeightSmall',
fileUploaderPaddingX:'fileUploaderPaddingXSmall',
fileUploaderPaddingY:'fileUploaderPaddingYSmall'
};

export default function transform(file: FileInfo, api: API) {
Expand Down