Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CardGrid): rename props spaced to padding
Browse files Browse the repository at this point in the history
EldarMuhamethanov committed Oct 21, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
miri64 Martine Lenders
1 parent 1d408a5 commit daec1b4
Showing 18 changed files with 150 additions and 26 deletions.
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
@@ -24,7 +24,7 @@ export const CardGridPlayground = (props: ComponentPlaygroundProps) => {
propSets={[
{
size: ['s', 'm', 'l'],
spaced: [true, false],
padding: [true, false],
},
]}
>
2 changes: 1 addition & 1 deletion packages/vkui/src/components/CardGrid/CardGrid.module.css
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 3 additions & 3 deletions packages/vkui/src/components/CardGrid/CardGrid.tsx
Original file line number Diff line number Diff line change
@@ -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 => {
@@ -43,7 +43,7 @@ export const CardGrid = ({
baseClassName={classNames(
styles.host,
'vkuiInternalCardGrid',
spaced && styles.spaced,
padding && styles.padding,
stylesSize[size],
sizeX !== 'regular' && sizeXClassNames[sizeX],
)}
2 changes: 1 addition & 1 deletion packages/vkui/src/components/CardGrid/Readme.md
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@
<div style={{ paddingBottom: '30%' }} />
</Card>
</CardGrid>
<CardGrid size="l" spaced>
<CardGrid size="l" padding>
<Card>
<div style={{ paddingBottom: '30%' }} />
</Card>
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.

0 comments on commit daec1b4

Please sign in to comment.