Skip to content

Commit

Permalink
fix(input): removed card type (#1231)
Browse files Browse the repository at this point in the history
Co-authored-by: Валерия Чуричева <valeriacuriceva@MacBook-Pro-Valeria.local>
  • Loading branch information
Valeri8888 and Валерия Чуричева committed Jun 28, 2024
1 parent 831f220 commit ea953eb
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 1 deletion.
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

0 comments on commit ea953eb

Please sign in to comment.