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(CardGrid): rename props spaced to padding #7804

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,45 @@
import { Card, CardGrid } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
<React.Fragment>
{/* spaced=false -> padding=false */}
<CardGrid
size="s"
spaced={false}
>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
</CardGrid>
{/* spaced=true -> padding=true */}
<CardGrid
size="s"
spaced={true}
>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
</CardGrid>
{/* spaced -> padding */}
<CardGrid
size="s"
spaced
>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
</CardGrid>
</React.Fragment>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`card-grid transforms correctly 1`] = `
"import { Card, CardGrid } from '@vkontakte/vkui';
import React from 'react';

const App = () => {
return (
(<React.Fragment>
{/* spaced=false -> padding=false */}
<CardGrid
size="s"
padding={false}
>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
</CardGrid>
{/* spaced=true -> padding=true */}
<CardGrid
size="s"
padding={true}
>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
</CardGrid>
{/* spaced -> padding */}
<CardGrid
size="s"
padding
>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
<Card>
<div style={{ paddingBottom: '66%' }} />
</Card>
</CardGrid>
</React.Fragment>)
);
};"
`;
12 changes: 12 additions & 0 deletions packages/codemods/src/transforms/v7/__tests__/card-grid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jest.autoMockOff();

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

const name = 'card-grid';
const fixtures = ['basic'] as const;

describe(name, () => {
fixtures.forEach((test) =>
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`),
);
});
18 changes: 18 additions & 0 deletions packages/codemods/src/transforms/v7/card-grid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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, 'CardGrid', alias);

if (localName) {
renameProp(j, source, localName, { spaced: 'padding' });
}

return source.toSource();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const CardGridPlayground = (props: ComponentPlaygroundProps) => {
propSets={[
{
size: ['s', 'm', 'l'],
spaced: [true, false],
padding: [true, false],
},
]}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
padding: 0;
}

.spaced {
.padding {
padding-block: var(--vkui--size_base_padding_vertical--regular);
padding-inline: var(--vkui--size_base_padding_horizontal--regular);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vkui/src/components/CardGrid/CardGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export interface CardGridProps extends HTMLAttributesWithRootRef<HTMLDivElement>
/**
* Если true, то вокруг компонента присутствуют стандартные отсупы сверху/снизу и слева/справа
*/
spaced?: boolean;
padding?: boolean;
}

/**
* @see https://vkcom.github.io/VKUI/#/CardGrid
*/
export const CardGrid = ({
size = 's',
spaced = false,
padding = false,
Component = 'ul',
...restProps
}: CardGridProps): React.ReactNode => {
Expand All @@ -43,7 +43,7 @@ export const CardGrid = ({
baseClassName={classNames(
styles.host,
'vkuiInternalCardGrid',
spaced && styles.spaced,
padding && styles.padding,
stylesSize[size],
sizeX !== 'regular' && sizeXClassNames[sizeX],
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/vkui/src/components/CardGrid/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div style={{ paddingBottom: '30%' }} />
</Card>
</CardGrid>
<CardGrid size="l" spaced>
<CardGrid size="l" padding>
<Card>
<div style={{ paddingBottom: '30%' }} />
</Card>
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
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading