diff --git a/packages/codemods/src/transforms/v7/common/warnSelectOnChange.ts b/packages/codemods/src/transforms/v7/common/warnSelectOnChange.ts new file mode 100644 index 0000000000..3840180ddc --- /dev/null +++ b/packages/codemods/src/transforms/v7/common/warnSelectOnChange.ts @@ -0,0 +1,16 @@ +import { API, Collection } from 'jscodeshift'; +import { report } from '../../../report'; + +export const warnSelectOnChange = (api: API, source: Collection, componentName: string) => { + const j = api.jscodeshift; + source + .find(j.JSXOpeningElement, { name: { name: componentName } }) + .find(j.JSXAttribute) + .filter((attr) => attr.node.name.name === 'onChange') + .forEach(() => { + report( + api, + `Manual changes required for ${componentName}'s "onChange" prop: need to change event argument to select value`, + ); + }); +}; diff --git a/packages/codemods/src/transforms/v7/custom-select.ts b/packages/codemods/src/transforms/v7/custom-select.ts index 6a34a10823..da8beb446d 100644 --- a/packages/codemods/src/transforms/v7/custom-select.ts +++ b/packages/codemods/src/transforms/v7/custom-select.ts @@ -1,6 +1,7 @@ import { API, FileInfo } from 'jscodeshift'; import { getImportInfo, removeProps } from '../../codemod-helpers'; import { JSCodeShiftOptions } from '../../types'; +import { warnSelectOnChange } from './common/warnSelectOnChange'; export const parser = 'tsx'; @@ -19,6 +20,7 @@ export default function transformer(file: FileInfo, api: API, options: JSCodeShi removeProps(j, api, source, localName, PROPS_TO_REMOVE, () => { return `need to remove props ${PROPS_TO_REMOVE.join(', ')}`; }); + warnSelectOnChange(api, source, localName); return source.toSource(); } diff --git a/packages/codemods/src/transforms/v7/native-select.ts b/packages/codemods/src/transforms/v7/native-select.ts new file mode 100644 index 0000000000..56ff172599 --- /dev/null +++ b/packages/codemods/src/transforms/v7/native-select.ts @@ -0,0 +1,21 @@ +import { API, FileInfo } from 'jscodeshift'; +import { getImportInfo } from '../../codemod-helpers'; +import { JSCodeShiftOptions } from '../../types'; +import { warnSelectOnChange } from './common/warnSelectOnChange'; + +export const parser = 'tsx'; + +export default function transformer(file: FileInfo, api: API, options: JSCodeShiftOptions) { + const { alias } = options; + const j = api.jscodeshift; + const source = j(file.source); + const { localName } = getImportInfo(j, file, 'NativeSelect', alias); + + if (!localName) { + return source.toSource(); + } + + warnSelectOnChange(api, source, localName); + + return source.toSource(); +} diff --git a/packages/codemods/src/transforms/v7/select.ts b/packages/codemods/src/transforms/v7/select.ts index de1d59af25..1fcb3bef5f 100644 --- a/packages/codemods/src/transforms/v7/select.ts +++ b/packages/codemods/src/transforms/v7/select.ts @@ -1,6 +1,7 @@ import { API, FileInfo } from 'jscodeshift'; import { getImportInfo, removeProps } from '../../codemod-helpers'; import { JSCodeShiftOptions } from '../../types'; +import { warnSelectOnChange } from './common/warnSelectOnChange'; export const parser = 'tsx'; @@ -19,6 +20,7 @@ export default function transformer(file: FileInfo, api: API, options: JSCodeShi removeProps(j, api, source, localName, PROPS_TO_REMOVE, () => { return `need to remove props ${PROPS_TO_REMOVE.join(', ')}`; }); + warnSelectOnChange(api, source, localName); return source.toSource(); } diff --git a/packages/vkui/src/components/Avatar/Readme.md b/packages/vkui/src/components/Avatar/Readme.md index f16b90476f..e90a25c16d 100644 --- a/packages/vkui/src/components/Avatar/Readme.md +++ b/packages/vkui/src/components/Avatar/Readme.md @@ -173,7 +173,7 @@ const AvatarPropsForm = ({ { label: 'blue', value: 'blue' }, ]} value={gradientColor} - onChange={(e) => setGradientColor(e.target.value)} + onChange={setGradientColor} /> @@ -196,7 +196,7 @@ const AvatarPropsForm = ({ { label: 'preset="online-mobile"', value: 'online-mobile' }, ]} value={badge} - onChange={(e) => setBadge(e.target.value)} + onChange={setBadge} /> @@ -208,7 +208,7 @@ const AvatarPropsForm = ({ ]} value={badgeBackground} disabled={badge !== 'children'} - onChange={(e) => setBadgeBackground(e.target.value)} + onChange={setBadgeBackground} /> @@ -231,7 +231,7 @@ const AvatarPropsForm = ({ ]} value={overlayTheme} disabled={!overlay} - onChange={(e) => setOverlayTheme(e.target.value)} + onChange={setOverlayTheme} /> @@ -243,7 +243,7 @@ const AvatarPropsForm = ({ ]} value={overlayVisibility} disabled={!overlay} - onChange={(e) => setOverlayVisibility(e.target.value)} + onChange={setOverlayVisibility} /> diff --git a/packages/vkui/src/components/Button/Readme.md b/packages/vkui/src/components/Button/Readme.md index 3188f5d5fc..0c03463f64 100644 --- a/packages/vkui/src/components/Button/Readme.md +++ b/packages/vkui/src/components/Button/Readme.md @@ -71,7 +71,7 @@ const Example = () => { setSize(e.target.value)} + onChange={setSize} options={[ { label: 's', value: 's' }, { label: 'm', value: 'm' }, @@ -96,7 +96,7 @@ const Example = () => { setSizeY(e.target.value)} + onChange={setSizeY} options={[ { label: 'compact', value: 'compact' }, { diff --git a/packages/vkui/src/components/ButtonGroup/Readme.md b/packages/vkui/src/components/ButtonGroup/Readme.md index 04ef8cd919..619937b0d2 100644 --- a/packages/vkui/src/components/ButtonGroup/Readme.md +++ b/packages/vkui/src/components/ButtonGroup/Readme.md @@ -32,7 +32,7 @@ const ButtonGroupPropsForm = ({ handleChange('gap', e.target.value)} + onChange={(newValue) => handleChange('gap', newValue)} options={[ { label: 'none', value: 'none' }, { label: 'space', value: 'space' }, @@ -55,7 +55,7 @@ const ButtonGroupPropsForm = ({ setSizeY(e.target.value)} + onChange={setSizeY} options={[ { label: 'compact', value: 'compact' }, { label: 'regular', value: 'regular' }, diff --git a/packages/vkui/src/components/Calendar/Readme.md b/packages/vkui/src/components/Calendar/Readme.md index 423f0e6715..0b0ad69404 100644 --- a/packages/vkui/src/components/Calendar/Readme.md +++ b/packages/vkui/src/components/Calendar/Readme.md @@ -60,7 +60,7 @@ const Example = () => { setSize(e.target.value)} + onChange={setSize} options={[ { label: 's', diff --git a/packages/vkui/src/components/CalendarHeader/CalendarHeader.tsx b/packages/vkui/src/components/CalendarHeader/CalendarHeader.tsx index 5d26a0dc45..29d0e67426 100644 --- a/packages/vkui/src/components/CalendarHeader/CalendarHeader.tsx +++ b/packages/vkui/src/components/CalendarHeader/CalendarHeader.tsx @@ -12,7 +12,7 @@ import { DEFAULT_MAX_YEAR, DEFAULT_MIN_YEAR, getMonths, getYears } from '../../l import type { HTMLAttributesWithRootRef } from '../../types'; import { AdaptivityProvider } from '../AdaptivityProvider/AdaptivityProvider'; import { useConfigProvider } from '../ConfigProvider/ConfigProviderContext'; -import { CustomSelect } from '../CustomSelect/CustomSelect'; +import { CustomSelect, type SelectProps } from '../CustomSelect/CustomSelect'; import { RootComponent } from '../RootComponent/RootComponent'; import { Tappable } from '../Tappable/Tappable'; import { Paragraph } from '../Typography/Paragraph/Paragraph'; @@ -80,13 +80,11 @@ export const CalendarHeader = ({ }: CalendarHeaderProps): React.ReactNode => { const { locale } = useConfigProvider(); const onMonthsChange = React.useCallback( - (event: React.ChangeEvent) => - onChange(setMonth(viewDate, Number(event.target.value))), + (newValue: SelectProps['value']) => onChange(setMonth(viewDate, Number(newValue))), [onChange, viewDate], ); const onYearChange = React.useCallback( - (event: React.ChangeEvent) => - onChange(setYear(viewDate, Number(event.target.value))), + (newValue: SelectProps['value']) => onChange(setYear(viewDate, Number(newValue))), [onChange, viewDate], ); diff --git a/packages/vkui/src/components/CalendarRange/Readme.md b/packages/vkui/src/components/CalendarRange/Readme.md index b4c96ce412..4faf95dad3 100644 --- a/packages/vkui/src/components/CalendarRange/Readme.md +++ b/packages/vkui/src/components/CalendarRange/Readme.md @@ -37,7 +37,7 @@ const Example = () => { setLocale(e.target.value)} + onChange={setLocale} options={[ { label: 'ru', diff --git a/packages/vkui/src/components/DateRangeInput/Readme.md b/packages/vkui/src/components/DateRangeInput/Readme.md index 6d21ab56af..fc7d9438f1 100644 --- a/packages/vkui/src/components/DateRangeInput/Readme.md +++ b/packages/vkui/src/components/DateRangeInput/Readme.md @@ -48,7 +48,7 @@ const Example = () => { setGap(e.target.value)} - options={GapSelectValues} - /> + setRowGap(e.target.value)} - options={GapSelectValues} - /> + setColumnGap(e.target.value)} - options={GapSelectValues} - /> + setAlign(e.target.value)} + onChange={setAlign} placeholder="Не выбрано" options={[ { label: 'start', value: 'start' }, @@ -185,7 +173,7 @@ const Example = () => { onSelectChange('purpose', newValue)} value={purpose} name="purpose" required diff --git a/packages/vkui/src/components/Image/Readme.md b/packages/vkui/src/components/Image/Readme.md index a532a70c5b..90699b3421 100644 --- a/packages/vkui/src/components/Image/Readme.md +++ b/packages/vkui/src/components/Image/Readme.md @@ -143,7 +143,7 @@ const ImagePropsForm = ({ onBorderRadiusChange, onBadgeChange, onOverlayChange } { label: 'l', value: 'l' }, ]} value={borderRadius} - onChange={(e) => setBorderRadius(e.target.value)} + onChange={setBorderRadius} /> @@ -162,7 +162,7 @@ const ImagePropsForm = ({ onBorderRadiusChange, onBadgeChange, onOverlayChange } ]} value={badgeBackground} disabled={!badge} - onChange={(e) => setBadgeBackground(e.target.value)} + onChange={setBadgeBackground} /> @@ -185,7 +185,7 @@ const ImagePropsForm = ({ onBorderRadiusChange, onBadgeChange, onOverlayChange } ]} value={overlayTheme} disabled={!overlay} - onChange={(e) => setOverlayTheme(e.target.value)} + onChange={setOverlayTheme} /> @@ -197,7 +197,7 @@ const ImagePropsForm = ({ onBorderRadiusChange, onBadgeChange, onOverlayChange } ]} value={overlayVisibility} disabled={!overlay} - onChange={(e) => setOverlayVisibility(e.target.value)} + onChange={setOverlayVisibility} /> diff --git a/packages/vkui/src/components/Input/Readme.md b/packages/vkui/src/components/Input/Readme.md index ed946911dc..7db9295b5a 100644 --- a/packages/vkui/src/components/Input/Readme.md +++ b/packages/vkui/src/components/Input/Readme.md @@ -12,7 +12,7 @@ const ExampleBase = ({ formItemStatus }) => { setSizeY(e.target.value)} + onChange={setSizeY} options={[ { label: 'compact', value: 'compact' }, { label: 'regular', value: 'regular' }, @@ -116,7 +116,7 @@ const Example = () => { - {placeholder && } + {placeholder && } {children}
diff --git a/packages/vkui/src/components/NativeSelect/Readme.md b/packages/vkui/src/components/NativeSelect/Readme.md index 3a66c1260b..1f0c3424c5 100644 --- a/packages/vkui/src/components/NativeSelect/Readme.md +++ b/packages/vkui/src/components/NativeSelect/Readme.md @@ -1,21 +1,78 @@ Надстройка над ` setSizeY(e.target.value)} + onChange={setSizeY} options={[ { label: 'compact', value: 'compact' }, { label: 'regular', value: 'regular' }, @@ -99,7 +99,7 @@ const Example = () => { setAlign(e.target.value || 'stretch')} + onChange={(newValue) => setAlign(newValue || 'stretch')} placeholder="Не выбрано" options={[ { label: 'start', value: 'start' }, @@ -156,29 +156,17 @@ const Example = () => { {!complexGap && ( - )} {complexGap && ( - )} {complexGap && ( - )}
diff --git a/packages/vkui/src/components/Slider/Readme.md b/packages/vkui/src/components/Slider/Readme.md index fce3f87348..2e39a2e946 100644 --- a/packages/vkui/src/components/Slider/Readme.md +++ b/packages/vkui/src/components/Slider/Readme.md @@ -63,11 +63,7 @@ const Example = () => { />
- Uncontrolled}> diff --git a/packages/vkui/src/components/SubnavigationButton/Readme.md b/packages/vkui/src/components/SubnavigationButton/Readme.md index 61f3a6bfb8..96af7f93b2 100644 --- a/packages/vkui/src/components/SubnavigationButton/Readme.md +++ b/packages/vkui/src/components/SubnavigationButton/Readme.md @@ -46,7 +46,7 @@ const SubnavigationButtonExample = () => { setTextLevel(e.target.value)} + onChange={setTextLevel} options={[ { label: '1', value: '1' }, { label: '2', value: '2' }, @@ -67,7 +67,7 @@ const SubnavigationButtonExample = () => { setSizeY(e.target.value)} + onChange={setSizeY} options={[ { label: 'compact', value: 'compact' }, { diff --git a/packages/vkui/src/components/Tabs/Readme.md b/packages/vkui/src/components/Tabs/Readme.md index 0254ab3247..47117f6ce2 100644 --- a/packages/vkui/src/components/Tabs/Readme.md +++ b/packages/vkui/src/components/Tabs/Readme.md @@ -213,7 +213,7 @@ const Scrollable = () => { value: 'secondary', }, ]} - onChange={(event) => setMode(event.target.value)} + onChange={setMode} /> @@ -233,7 +233,7 @@ const Scrollable = () => { value: 'shrinked', }, ]} - onChange={(event) => setLayoutFillMode(event.target.value)} + onChange={setLayoutFillMode} /> setDisabled((prev) => !prev)}>disabled diff --git a/packages/vkui/src/components/ToolButton/Readme.md b/packages/vkui/src/components/ToolButton/Readme.md index d6d62cca45..06f7744177 100644 --- a/packages/vkui/src/components/ToolButton/Readme.md +++ b/packages/vkui/src/components/ToolButton/Readme.md @@ -44,7 +44,7 @@ const Example = () => { setMode(e.target.value)} + onChange={setMode} options={[ { label: 'primary', value: 'primary' }, { label: 'secondary', value: 'secondary' }, @@ -66,7 +66,7 @@ const Example = () => { setSizeY(e.target.value)} + onChange={setSizeY} options={[ { label: 'compact', value: 'compact' }, {