-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(HorizontalCell): add custom width support (#7807)
* feat(HorizontalCell): add custom width support * fix: fix codemod error * feat(HorizontalCellShowMore): change size values feat(ScrollArrow): change size values
- Loading branch information
1 parent
1d4b706
commit 90ea9e0
Showing
60 changed files
with
363 additions
and
197 deletions.
There are no files selected for viewing
17 changes: 4 additions & 13 deletions
17
...ges/codemods/src/transforms/v7/__testfixtures__/horizontal-cell-show-more/basic.input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
import { HorizontalCellShowMore, HorizontalScroll } from '@vkontakte/vkui'; | ||
import { HorizontalCellShowMore } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
import '@vkontakte/vkui/dist/vkui.css'; | ||
|
||
const App = () => { | ||
return ( | ||
<React.Fragment> | ||
<HorizontalScroll> | ||
<div /> | ||
<div /> | ||
<div /> | ||
<HorizontalCellShowMore onClick={() => {}} compensateLastCellIndent size="m" height={88} /> | ||
</HorizontalScroll> | ||
<HorizontalScroll> | ||
<div /> | ||
<div /> | ||
<div /> | ||
<HorizontalCellShowMore onClick={() => {}} compensateLastCellIndent={true} size="m" height={88} /> | ||
</HorizontalScroll> | ||
<HorizontalCellShowMore compensateLastCellIndent size="m" height={88} /> | ||
<HorizontalCellShowMore compensateLastCellIndent={true} size="l" height={88} /> | ||
<HorizontalCellShowMore compensateLastCellIndent={false} size="s" height={88} /> | ||
</React.Fragment> | ||
); | ||
}; |
15 changes: 15 additions & 0 deletions
15
packages/codemods/src/transforms/v7/__testfixtures__/scroll-arrow/basic.input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Gallery, HorizontalScroll, ScrollArrow } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<React.Fragment> | ||
<ScrollArrow direction='down' size='m' /> | ||
<ScrollArrow direction='left' size='l' /> | ||
<HorizontalScroll arrowSize='m' /> | ||
<HorizontalScroll arrowSize='l' /> | ||
<Gallery arrowSize='m' /> | ||
<Gallery arrowSize='l' /> | ||
</React.Fragment> | ||
); | ||
}; |
17 changes: 4 additions & 13 deletions
17
...ages/codemods/src/transforms/v7/__tests__/__snapshots__/horizontal-cell-show-more.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/codemods/src/transforms/v7/__tests__/__snapshots__/scroll-arrow.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`scroll-arrow transforms correctly 1`] = ` | ||
"import { Gallery, HorizontalScroll, ScrollArrow } from '@vkontakte/vkui'; | ||
import React from 'react'; | ||
const App = () => { | ||
return ( | ||
(<React.Fragment> | ||
<ScrollArrow direction='down' size="s" /> | ||
<ScrollArrow direction='left' size="m" /> | ||
<HorizontalScroll arrowSize="s" /> | ||
<HorizontalScroll arrowSize="m" /> | ||
<Gallery arrowSize="s" /> | ||
<Gallery arrowSize="m" /> | ||
</React.Fragment>) | ||
); | ||
};" | ||
`; |
12 changes: 12 additions & 0 deletions
12
packages/codemods/src/transforms/v7/__tests__/scroll-arrow.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
jest.autoMockOff(); | ||
|
||
import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper'; | ||
|
||
const name = 'scroll-arrow'; | ||
const fixtures = ['basic'] as const; | ||
|
||
describe(name, () => { | ||
fixtures.forEach((test) => | ||
defineSnapshotTestFromFixture(__dirname, name, global.TRANSFORM_OPTIONS, `${name}/${test}`), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { API, ASTPath, FileInfo, JSXAttribute } from 'jscodeshift'; | ||
import { getImportInfo } from '../../codemod-helpers'; | ||
import { report } from '../../report'; | ||
import { JSCodeShiftOptions } from '../../types'; | ||
|
||
export const parser = 'tsx'; | ||
|
||
const componentName = 'ScrollArrow'; | ||
const affectedComponents = ['HorizontalScroll', 'Gallery']; | ||
|
||
function arrowSizeManipulator(api: API, attribute: ASTPath<JSXAttribute>) { | ||
const node = attribute.node; | ||
|
||
if (node.value?.type === 'StringLiteral') { | ||
const oldValue = node.value.value; | ||
const newValue = oldValue === 'm' ? 's' : oldValue === 'l' ? 'm' : undefined; | ||
if (newValue) { | ||
node.value = api.jscodeshift.stringLiteral(newValue); | ||
} | ||
} else { | ||
report( | ||
api, | ||
`Manual changes required for ${componentName}'s "size" prop. Use "s" or "m" value only.`, | ||
); | ||
} | ||
} | ||
|
||
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, componentName, alias); | ||
const { localName: horizontalScrollLocalName } = getImportInfo( | ||
j, | ||
file, | ||
affectedComponents[0], | ||
alias, | ||
); | ||
const { localName: galleryLocalName } = getImportInfo(j, file, affectedComponents[1], alias); | ||
|
||
if (!localName) { | ||
return source.toSource(); | ||
} | ||
|
||
source | ||
.find(j.JSXOpeningElement) | ||
.filter( | ||
(path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName, | ||
) | ||
.find(j.JSXAttribute, { name: { name: 'size' } }) | ||
.forEach((attribute) => { | ||
arrowSizeManipulator(api, attribute); | ||
}); | ||
|
||
source | ||
.find(j.JSXOpeningElement) | ||
.filter( | ||
(path) => | ||
path.value.name.type === 'JSXIdentifier' && | ||
[horizontalScrollLocalName, galleryLocalName].includes(path.value.name.name), | ||
) | ||
.find(j.JSXAttribute, { name: { name: 'arrowSize' } }) | ||
.forEach((attribute) => { | ||
arrowSizeManipulator(api, attribute); | ||
}); | ||
|
||
return source.toSource(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.