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(Spacing): remove 3xs size type #7634

Merged
merged 1 commit into from
Sep 20, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Separator, Spacing } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
<Spacing size="3xs">
<Separator/>
</Spacing>

<Spacing size="3xs" />

<Spacing size={"3xs"} />
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`spacing transforms correctly 1`] = `
"import { Separator, Spacing } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
(<React.Fragment>
<Spacing size="2xs">
<Separator/>
</Spacing>
<Spacing size="2xs" />
<Spacing size={"2xs"} />
</React.Fragment>)
);
};"
`;
11 changes: 11 additions & 0 deletions packages/codemods/src/transforms/v7/__tests__/spacing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
jest.autoMockOff();
import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper';

const name = 'spacing';
const fixtures = ['basic'] 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
@@ -1,11 +1,14 @@
import { Collection, JSCodeshift } from 'jscodeshift';
import { API, Collection, JSCodeshift } from 'jscodeshift';
import { report } from '../../../report';

export const remapSizePropValue = ({
j,
source,
sizesMap,
componentName,
api,
}: {
api: API;
j: JSCodeshift;
source: Collection;
sizesMap: Record<string, string>;
Expand All @@ -22,8 +25,23 @@ export const remapSizePropValue = ({
return attributeName === 'size';
})
.forEach((attribute) => {
let nodeToReplaceValue;
if (attribute.node.value?.type === 'JSXExpressionContainer') {
const expression = attribute.node.value.expression;
if (expression.type === 'StringLiteral') {
nodeToReplaceValue = expression;
}
}
if (attribute.node.value?.type === 'StringLiteral') {
attribute.node.value.value = sizesMap[attribute.node.value.value];
nodeToReplaceValue = attribute.node.value;
}
if (nodeToReplaceValue) {
const newValue = sizesMap[nodeToReplaceValue.value];
if (newValue) {
nodeToReplaceValue.value = newValue;
}
} else {
report(api, `Manual changes required for ${componentName}'s "size" prop.`);
}
});
};
1 change: 1 addition & 0 deletions packages/codemods/src/transforms/v7/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function transformer(file: FileInfo, api: API, options: JSCodeShi

remapSizePropValue({
j,
api,
source,
componentName: localName,
sizesMap: {
Expand Down
29 changes: 29 additions & 0 deletions packages/codemods/src/transforms/v7/spacing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { API, FileInfo } from 'jscodeshift';
import { remapSizePropValue } from './common/remapSizePropValue';
import { getImportInfo } 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, 'Spacing', alias);

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

remapSizePropValue({
j,
api,
source,
componentName: localName,
sizesMap: {
'3xs': '2xs',
},
});

return source.toSource();
}
1 change: 1 addition & 0 deletions packages/codemods/src/transforms/v7/spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function transformer(file: FileInfo, api: API, options: JSCodeShi

remapSizePropValue({
j,
api,
source,
componentName: localName,
sizesMap: {
Expand Down
2 changes: 1 addition & 1 deletion packages/vkui/src/components/Header/Header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.Header__before {
align-self: center;
margin-inline-end: var(--vkui--spacing_size_m);
margin-block-start: var(--vkui--spacing_size_3xs);
margin-block-start: var(--vkui--spacing_size_2xs);
}

.Header__before--withSubtitle {
Expand Down
5 changes: 0 additions & 5 deletions packages/vkui/src/components/Spacing/Spacing.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
box-sizing: border-box;
}

.Spacing--3xs {
/* TODO [>=7]: удалить deprecated токен */
--vkui_internal--Spacing_gap: var(--vkui--spacing_size_3xs);
}

.Spacing--2xs {
--vkui_internal--Spacing_gap: var(--vkui--spacing_size_2xs);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/vkui/src/components/Spacing/Spacing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import styles from './Spacing.module.css';
export const CUSTOM_CSS_TOKEN_FOR_USER_GAP = '--vkui_internal--Spacing_gap';

export const sizesClassNames: Record<SpacingSize, string> = {
'3xs': styles['Spacing--3xs'],
'2xs': styles['Spacing--2xs'],
'xs': styles['Spacing--xs'],
's': styles['Spacing--s'],
Expand All @@ -19,7 +18,7 @@ export const sizesClassNames: Record<SpacingSize, string> = {
'4xl': styles['Spacing--4xl'],
};

export type SpacingSize = 's' | 'm' | 'l' | '3xs' | '2xs' | 'xs' | 'xl' | '2xl' | '3xl' | '4xl';
export type SpacingSize = 's' | 'm' | 'l' | '2xs' | 'xs' | 'xl' | '2xl' | '3xl' | '4xl';

export interface SpacingProps extends HTMLAttributesWithRootRef<HTMLDivElement> {
/**
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading