Skip to content

Commit

Permalink
feat(Calendar): rename onClose prop to onDoneButtonClick
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarMuhamethanov committed Nov 1, 2024
1 parent ebb46a5 commit e95e660
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Calendar } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
const callback = () => {}
return (
<React.Fragment>
<Calendar
onChange={() => {}}
enableTime={true}
disablePast={true}
disableFuture={true}
onClose={() => {}}
/>

<Calendar
onChange={() => {}}
enableTime={true}
disablePast={true}
disableFuture={true}
onClose={callback}
/>
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`calendar transforms correctly 1`] = `
"import { Calendar } from '@vkontakte/vkui';
import React from 'react';
const App = () => {
const callback = () => {}
return (
(<React.Fragment>
<Calendar
onChange={() => {}}
enableTime={true}
disablePast={true}
disableFuture={true}
onDoneButtonClick={() => {}}
/>
<Calendar
onChange={() => {}}
enableTime={true}
disablePast={true}
disableFuture={true}
onDoneButtonClick={callback}
/>
</React.Fragment>)
);
};"
`;
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/v7/__tests__/calendar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper';

const name = 'calendar';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
20 changes: 20 additions & 0 deletions packages/codemods/src/transforms/v7/calendar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { API, FileInfo } from 'jscodeshift';
import { getImportInfo, renameProp } from '../../codemod-helpers';
import { JSCodeShiftOptions } from '../../types';

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, 'Calendar', alias);

if (!localName) {
return source.toSource();
}

renameProp(j, source, localName, { onClose: 'onDoneButtonClick' });

return source.toSource();
}
6 changes: 3 additions & 3 deletions packages/vkui/src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface CalendarProps
* Позволяет запретить выбор даты.
*/
shouldDisableDate?: (value: Date) => boolean;
onClose?: () => void;
onDoneButtonClick?: () => void;
/**
* Дата отображаемого месяца.
* При использовании обновление даты должно происходить вне компонента.
Expand Down Expand Up @@ -87,7 +87,7 @@ export const Calendar = ({
disablePast,
disableFuture,
shouldDisableDate,
onClose,
onDoneButtonClick,
enableTime = false,
doneButtonText,
weekStartsOn = 1,
Expand Down Expand Up @@ -231,7 +231,7 @@ export const Calendar = ({
<CalendarTime
value={value}
onChange={onChange}
onClose={onClose}
onDoneButtonClick={onDoneButtonClick}
doneButtonText={doneButtonText}
changeHoursLabel={changeHoursLabel}
changeMinutesLabel={changeMinutesLabel}
Expand Down
6 changes: 3 additions & 3 deletions packages/vkui/src/components/CalendarTime/CalendarTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface CalendarTimeProps {
changeHoursLabel?: string;
changeMinutesLabel?: string;
onChange?: (value: Date) => void;
onClose?: () => void;
onDoneButtonClick?: () => void;
isDayDisabled?: (day: Date, withTime?: boolean) => boolean;
}

Expand All @@ -37,7 +37,7 @@ export const CalendarTime = ({
value,
doneButtonText = 'Готово',
onChange,
onClose,
onDoneButtonClick,
changeHoursLabel,
changeMinutesLabel,
isDayDisabled,
Expand Down Expand Up @@ -90,7 +90,7 @@ export const CalendarTime = ({
</div>
<div className={styles.button}>
<AdaptivityProvider sizeY="compact">
<Button mode="secondary" onClick={onClose} size="l">
<Button mode="secondary" onClick={onDoneButtonClick} size="l">
{doneButtonText}
</Button>
</AdaptivityProvider>
Expand Down
2 changes: 1 addition & 1 deletion packages/vkui/src/components/DateInput/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export const DateInput = ({
disablePast={disablePast}
disableFuture={disableFuture}
shouldDisableDate={shouldDisableDate}
onClose={removeFocusFromField}
onDoneButtonClick={removeFocusFromField}
getRootRef={calendarRef}
doneButtonText={doneButtonText}
disablePickers={disablePickers}
Expand Down

0 comments on commit e95e660

Please sign in to comment.