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

[BREAKING CHANGE] feat: rename appearance to colorScheme #7728

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

- platform: 'android'
- browserName: 'chromium'
- appearance: 'light'
- colorScheme: 'light'

```tsx
test('Example', async ({ expectScreenshotClippedToContent }) => {
Expand Down
47 changes: 47 additions & 0 deletions packages/codemods/src/codemod-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,53 @@ export function getImportInfo(
return { localName: localImportName };
}

export function renameImportName(
j: JSCodeshift,
source: Collection,
componentName: string,
newName: string,
alias: string,
renameOnlyImportedName: boolean,
) {
source
.find(j.ImportDeclaration, { source: { value: alias } })
.find(j.ImportSpecifier, { local: { name: componentName } })
.forEach((path) => {
const newSpecifier = j.importSpecifier(
j.identifier(newName),
renameOnlyImportedName ? j.identifier(componentName) : j.identifier(newName),
);
(newSpecifier as any).importKind = (path.value as any).importKind;
j(path).replaceWith(newSpecifier);
});
}

export function renameIdentifier(
j: JSCodeshift,
source: Collection,
oldName: string,
newName: string,
) {
source.find(j.Identifier, { name: oldName }).forEach((path) => {
j(path).replaceWith(j.identifier(newName));
});
}

export function renameTypeIdentifier(
j: JSCodeshift,
source: Collection,
oldName: string,
newName: string,
) {
source
.find(j.TSTypeReference, { typeName: { type: 'Identifier', name: oldName } })
.forEach((path) => {
if (path.node.typeName.type === 'Identifier') {
path.node.typeName.name = newName;
}
});
}

export function renameProp(
j: JSCodeshift,
source: Collection,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AppearanceProvider as AppearanceProviderAlias, type AppearanceProviderProps as AppearanceProviderPropsAlias, Snackbar } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
const props: AppearanceProviderPropsAlias = {
value: 'dark',
children: (<Snackbar action="Поделиться">Поделиться</Snackbar>)
};

return (
<React.Fragment>
<AppearanceProviderAlias {...props} />
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AppearanceProvider, type AppearanceProviderProps, Snackbar } from '@vkontakte/vkui';
import React from 'react';

type Props = AppearanceProviderProps & {
additionalProp: string,
}

const App = () => {
const props: AppearanceProviderProps = {
value: 'dark',
children: (<Snackbar action="Поделиться">Поделиться</Snackbar>)
};

const getAdditionalProvider = () => (
<AppearanceProvider value={"light"}>
<Snackbar action="Поделиться">Поделиться</Snackbar>
</AppearanceProvider>
)

return (
<React.Fragment>
<AppearanceProvider {...props} />
{getAdditionalProvider()}
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Appearance as AppearanceAlias, type AppearanceType as AppearanceTypeAlias } from '@vkontakte/vkui';
import React from 'react';

const Component: React.FC<{
appearance: AppearanceTypeAlias;
}> = () => {
return (
<div></div>
)
}

const App = () => {
const appearance: AppearanceTypeAlias = AppearanceAlias.LIGHT;

return (
<React.Fragment>
<Component appearance={AppearanceAlias.DARK} />
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Appearance, type AppearanceType, useAppearance } from '@vkontakte/vkui';
import React from 'react';

const Component: React.FC<{
appearance: AppearanceType;
}> = ({
appearance,
}) => {
return (
<div></div>
)
}

const App = () => {
const appearance: AppearanceType = Appearance.LIGHT;

const fromHookAppearance = useAppearance();

return (
<React.Fragment>
<Component appearance={Appearance.DARK} />
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ConfigProvider, ConfigProviderContext } from '@vkontakte/vkui';
import React, {createContext} from 'react';

const OtherContext = createContext({});


const App = () => {
const contextValue = {}
return (
<>
<ConfigProvider
appearance={"dark"}
{...contextValue}
>
<div></div>
</ConfigProvider>

<ConfigProviderContext.Provider value={{
appearance: 'light',
...contextValue
}}>
<div></div>
</ConfigProviderContext.Provider>

<OtherContext.Provider value={{
appearance: 'light',
...contextValue
}}>
<div></div>
</OtherContext.Provider>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`appearance-provider transforms correctly 1`] = `
"import { ColorSchemeProvider, type ColorSchemeProviderProps, Snackbar } from '@vkontakte/vkui';
import React from 'react';

type Props = ColorSchemeProviderProps & {
additionalProp: string,
}

const App = () => {
const props: ColorSchemeProviderProps = {
value: 'dark',
children: (<Snackbar action="Поделиться">Поделиться</Snackbar>)
};

const getAdditionalProvider = () => (
<ColorSchemeProvider value={"light"}>
<Snackbar action="Поделиться">Поделиться</Snackbar>
</ColorSchemeProvider>
)

return (
(<React.Fragment>
<ColorSchemeProvider {...props} />
{getAdditionalProvider()}
</React.Fragment>)
);
};"
`;

exports[`appearance-provider transforms correctly 2`] = `
"import { ColorSchemeProvider as AppearanceProviderAlias, type ColorSchemeProviderProps as AppearanceProviderPropsAlias, Snackbar } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
const props: AppearanceProviderPropsAlias = {
value: 'dark',
children: (<Snackbar action="Поделиться">Поделиться</Snackbar>)
};

return (
<React.Fragment>
<AppearanceProviderAlias {...props} />
</React.Fragment>
);
};"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`appearance transforms correctly 1`] = `
"import { ColorScheme, type ColorSchemeType, useColorScheme } from '@vkontakte/vkui';
import React from 'react';

const Component: React.FC<{
appearance: ColorSchemeType;
}> = ({
appearance,
}) => {
return (
<div></div>
)
}

const App = () => {
const appearance: ColorSchemeType = ColorScheme.LIGHT;

const fromHookAppearance = useColorScheme();

return (
(<React.Fragment>
<Component appearance={ColorScheme.DARK} />
</React.Fragment>)
);
};"
`;

exports[`appearance transforms correctly 2`] = `
"import { ColorScheme as AppearanceAlias, type ColorSchemeType as AppearanceTypeAlias } from '@vkontakte/vkui';
import React from 'react';

const Component: React.FC<{
appearance: AppearanceTypeAlias;
}> = () => {
return (
<div></div>
)
}

const App = () => {
const appearance: AppearanceTypeAlias = AppearanceAlias.LIGHT;

return (
<React.Fragment>
<Component appearance={AppearanceAlias.DARK} />
</React.Fragment>
);
};"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`config-provider transforms correctly 1`] = `
"import { ConfigProvider, ConfigProviderContext } from '@vkontakte/vkui';
import React, {createContext} from 'react';

const OtherContext = createContext({});


const App = () => {
const contextValue = {}
return (<>
<ConfigProvider
colorScheme={"dark"}
{...contextValue}
>
<div></div>
</ConfigProvider>
<ConfigProviderContext.Provider value={{
colorScheme: 'light',
...contextValue
}}>
<div></div>
</ConfigProviderContext.Provider>
<OtherContext.Provider value={{
appearance: 'light',
...contextValue
}}>
<div></div>
</OtherContext.Provider>
</>);
};"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'appearance-provider';
const fixtures = ['basic', 'alias'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/v7/__tests__/appearance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'appearance';
const fixtures = ['basic', 'alias'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'config-provider';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
Loading
Loading