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

fix(input): removed card type #1231

Merged
merged 1 commit into from
Jun 28, 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
6 changes: 6 additions & 0 deletions .changeset/five-waves-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@alfalab/core-components-input": major
---

- Удален тип 'card'
- Добавлен трансформер input-type-card, который заменяет атрибут type со значением 'card' на inputMode со значением 'numeric'
5 changes: 5 additions & 0 deletions .changeset/soft-coats-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alfalab/core-components-codemod": minor
---

Добавлен кодмод, который заменяет атрибут type со значением 'card' на inputMode со значением 'numeric' в компоненте Input
1 change: 1 addition & 0 deletions packages/codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $ npx @alfalab/core-components-codemod --transformers=button-xs,button-views --g
| button-views-45 | Меняет вид кнопки с view `tertiary` на `outlined`, `link` на `transparent`, `ghost` на `text` |
| skeleton-blur | Добавляет свойство `allowBackdropBlur` со значение true к компоненту Skeleton |
| status-soft | Изменяет view компонента Status с `soft` на `muted-alt`|
| input-type-card | Заменяет атрибут type со значением 'card' на inputMode со значением 'numeric' в компоненте Input |

### 42 мажорный релиз

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';

import { Input } from '@alfalab/core-components-input';
import { InputDesktop } from '@alfalab/core-components-input/desktop';
import { InputMobile } from '@alfalab/core-components-input/mobile';

export const Component = () => (
<React.Fragment>
<Input type='number'/>
<Input type='email'/>
<Input type='card' size='56'/>
<Input type='card'/>
<Input type='text'/>
<Input/>
<InputDesktop type='number'/>
<InputDesktop type='email'/>
<InputDesktop type='card' size='56'/>
<InputDesktop type='card'/>
<InputDesktop type='text'/>
<InputDesktop/>
<InputMobile type='number'/>
<InputMobile type='email'/>
<InputMobile type='card' size='56'/>
<InputMobile type='card'/>
<InputMobile type='text'/>
<InputMobile/>
</React.Fragment>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';

import { Input } from '@alfalab/core-components-input';
import { InputDesktop } from '@alfalab/core-components-input/desktop';
import { InputMobile } from '@alfalab/core-components-input/mobile';

export const Component = () => (
<React.Fragment>
<Input type='number'/>
<Input type='email'/>
<Input inputMode='numeric' size='56'/>
<Input inputMode='numeric'/>
<Input type='text'/>
<Input/>
<InputDesktop type='number'/>
<InputDesktop type='email'/>
<InputDesktop inputMode='numeric' size='56'/>
<InputDesktop inputMode='numeric'/>
<InputDesktop type='text'/>
<InputDesktop/>
<InputMobile type='number'/>
<InputMobile type='email'/>
<InputMobile inputMode='numeric' size='56'/>
<InputMobile inputMode='numeric'/>
<InputMobile type='text'/>
<InputMobile/>
</React.Fragment>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// eslint-disable-next-line prefer-destructuring
const defineTest = require('jscodeshift/dist/testUtils').defineTest;

jest.autoMockOff();

defineTest(__dirname, 'transform', null, 'transform', { parser: 'tsx' });
36 changes: 36 additions & 0 deletions packages/codemod/src/input-type-card/transform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable */
import { ASTPath, JSXElement, Transform } from 'jscodeshift';
import { addStringAttribute } from '../utils';

const inputTypeTransform: Transform = (fileInfo, api) => {
const j = api.jscodeshift;
const source = j(fileInfo.source);

const componentsNames = ['Input', 'InputDesktop', 'InputMobile'];

componentsNames.forEach((elementName) => {
source.findJSXElements(elementName).forEach((path) => {
j(path).replaceWith((path: ASTPath<JSXElement>) => {
const { node } = path;

const { openingElement } = node;

j(openingElement)
.find(j.JSXAttribute, {
name: { name: 'type' },
value: { value: 'card' },
})
.replaceWith(() =>
j.jsxAttribute(j.jsxIdentifier('inputMode'), j.stringLiteral('numeric')),
);
return node;
});
});
});
return source.toSource({
quote: 'single',
wrapColumn: 1000,
});
};

export default inputTypeTransform;
2 changes: 1 addition & 1 deletion packages/input/src/components/base-input/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export type BaseInputProps = Omit<
/**
* Атрибут type
*/
type?: 'number' | 'card' | 'email' | 'money' | 'password' | 'tel' | 'text';
type?: 'number' | 'email' | 'money' | 'password' | 'tel' | 'text';

/**
* Ref для обертки input
Expand Down
Loading