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: product-cover: исправлено название пропса numberOfCards #1489

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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/big-apples-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@alfalab/core-components-product-cover': patch
---

- Исправлено название пропса numberOfCards. Старый пропс (numberOfСards с русской C) оставлен для обратной совместимости, но помечен как деприкейт. При использовании сразу обоих, новый имеет приоритет.
- Микро-оптимизация: импорт кнопки заменён с десктоной на мобильный. (Мобильная сборка имеет приоритет по размеру, поэтому не нужно тащить туда десктопные импорты.)
2 changes: 1 addition & 1 deletion packages/product-cover/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('ProductCover', () => {
secondCard={{
cardNumber: 1234000000001234,
}}
numberOfСards={2}
numberOfCards={2}
dataTestId={dataTestId}
/>,
);
Expand Down
11 changes: 9 additions & 2 deletions packages/product-cover/src/components/image-card/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ export type ImageCardProps = {
height?: number;

/**
* Количество карт
* (Устаревший) Количество карт
* @deprecated Используйте 'numberOfCards'
*/
numberOfСards?: number;

/**
* Количество карт
*/
numberOfCards?: number;
};

export const ImageCard: FC<ImageCardProps> = ({
Expand All @@ -46,6 +52,7 @@ export const ImageCard: FC<ImageCardProps> = ({
width,
height,
numberOfСards,
numberOfCards = numberOfСards,
}) => {
const imagePatternId = useId();

Expand Down Expand Up @@ -106,5 +113,5 @@ export const ImageCard: FC<ImageCardProps> = ({
return null;
};

return height === 16 && numberOfСards ? renderCardMack() : renderImageCard();
return height === 16 && numberOfCards ? renderCardMack() : renderImageCard();
};
23 changes: 15 additions & 8 deletions packages/product-cover/src/components/text/Component.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import cn from 'classnames';

import { ButtonDesktop } from '@alfalab/core-components-button/desktop';
import { ButtonMobile } from '@alfalab/core-components-button/mobile';
import { getDataTestId } from '@alfalab/core-components-shared';
import { Text as TypographyText } from '@alfalab/core-components-typography';
import { EyeMIcon } from '@alfalab/icons-glyph/EyeMIcon';
import { pluralize } from '@alfalab/utils';

import { TYPOGRAPHY_VIEW_FOR_SIZE } from '../../consts';
import { Size } from '../../typings';
import { showNumberOfСards } from '../../utils';
import { showNumberOfCards } from '../../utils';

import styles from './index.module.css';

Expand Down Expand Up @@ -45,10 +45,16 @@ export type TextProps = {
cardNumber?: number;

/**
* Количество карт
* (Устаревший) Количество карт
* @deprecated Используйте 'numberOfCards'
*/
numberOfСards?: number;

/**
* Количество карт
*/
numberOfCards?: number;

/**
* Управление ориентацией стопки карт компонента
*/
Expand All @@ -70,14 +76,15 @@ export const Text: React.FC<TextProps> = ({
cardholderName,
cardNumber,
numberOfСards,
numberOfCards = numberOfСards,
align,
eyeButton,
dataTestId,
size = 164,
onEyeIconClick,
}) => {
const maxSize = size === 164;
const visibleNumberOfСards = showNumberOfСards(size, numberOfСards, align);
const visibleNumberOfCards = showNumberOfCards(size, numberOfCards, align);

return (
<div className={cn(styles.component)} data-test-id={dataTestId}>
Expand All @@ -93,7 +100,7 @@ export const Text: React.FC<TextProps> = ({
</TypographyText>
) : null}

{cardNumber && !visibleNumberOfСards ? (
{cardNumber && !visibleNumberOfCards ? (
<div className={styles.cardNumber}>
<TypographyText
view={TYPOGRAPHY_VIEW_FOR_SIZE[size]}
Expand All @@ -104,20 +111,20 @@ export const Text: React.FC<TextProps> = ({
{String(cardNumber).slice(-4)}
</TypographyText>
{eyeButton && maxSize && (
<ButtonDesktop
<ButtonMobile
view='text'
className={cn(styles.buttonEye)}
dataTestId={getDataTestId(dataTestId, 'eye-btn')}
onClick={onEyeIconClick}
colors='inverted'
>
<EyeMIcon />
</ButtonDesktop>
</ButtonMobile>
)}
</div>
) : null}

{visibleNumberOfСards && (
{visibleNumberOfCards && (
<div className={styles.cardNumber}>
<TypographyText
view={TYPOGRAPHY_VIEW_FOR_SIZE[size]}
Expand Down
14 changes: 7 additions & 7 deletions packages/product-cover/src/docs/description.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ render(() => {

```jsx live
render(() => {
const [numberOfСards, setNumberOfСards] = React.useState('2');
const [numberOfCards, setNumberOfCards] = React.useState('2');
const [sizeAndAlignCard, setSizeAndAlignCard] = React.useState('128-default');

const onChangeNumberOfСards = (_, payload) => {
setNumberOfСards(payload.value);
const onChangeNumberOfCards = (_, payload) => {
setNumberOfCards(payload.value);
};

const onChangeSizeCard = (_, payload) => {
Expand Down Expand Up @@ -185,7 +185,7 @@ render(() => {
};

const secondCard = {
...(numberOfСards === '2' && {
...(numberOfCards === '2' && {
baseUrl: 'https://online.alfabank.ru/cards-images/cards/',
layers: 'BACKGROUND,LOGO,PAYMENT_SYSTEM',
cardId: 'RM',
Expand All @@ -204,7 +204,7 @@ render(() => {
align={alignCard}
firstCard={firstCard}
secondCard={secondCard}
numberOfСards={sizeCard === 16 ? 3 : CARD_COUNT[numberOfСards]}
numberOfCards={sizeCard === 16 ? 3 : CARD_COUNT[numberOfCards]}
/>
</Col>
</Row>
Expand Down Expand Up @@ -240,8 +240,8 @@ render(() => {
<RadioGroup
label='Количество карт'
name='radioGroup'
onChange={onChangeNumberOfСards}
value={numberOfСards}
onChange={onChangeNumberOfCards}
value={numberOfCards}
>
<Radio label='Две' value='2' size='m' />
<Radio label='Больше двух' value='3' size='m' />
Expand Down
7 changes: 4 additions & 3 deletions packages/product-cover/src/single/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const Single: FC<SingleCommonProps> = ({
cardholderNameUppercase,
cardholderName,
numberOfСards,
numberOfCards = numberOfСards,
align,
cardNumber,
className,
Expand All @@ -32,7 +33,7 @@ export const Single: FC<SingleCommonProps> = ({
onEyeIconClick,
dataTestId,
}) => {
const hasContent = Boolean(cardNumber || cardholderName || numberOfСards);
const hasContent = Boolean(cardNumber || cardholderName || numberOfCards);
const showContent = hasContent && size !== 16 && !contentAddons;

return (
Expand Down Expand Up @@ -62,7 +63,7 @@ export const Single: FC<SingleCommonProps> = ({
cardId={cardId}
layers={layers}
baseUrl={baseUrl}
numberOfСards={numberOfСards}
numberOfCards={numberOfCards}
/>

{showContent && (
Expand All @@ -71,7 +72,7 @@ export const Single: FC<SingleCommonProps> = ({
eyeButton={eyeButton}
cardholderNameUppercase={cardholderNameUppercase}
cardholderName={cardholderName}
numberOfСards={numberOfСards}
numberOfCards={numberOfCards}
align={align}
size={size}
onEyeIconClick={onEyeIconClick}
Expand Down
3 changes: 2 additions & 1 deletion packages/product-cover/src/stack/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const Stack: FC<StackProps> = ({
secondCard,
size = 128,
numberOfСards,
numberOfCards = numberOfСards,
className,
align = 'default',
dataTestId,
Expand Down Expand Up @@ -42,7 +43,7 @@ export const Stack: FC<StackProps> = ({
{...secondCard}
size={secondCardSize}
align={align}
numberOfСards={numberOfСards}
numberOfCards={numberOfCards}
dataTestId={getDataTestId(dataTestId, 'second-card')}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe(
secondCard: {
cardNumber: 1234000000001234,
},
numberOfСards: 2,
numberOfCards: 2,
},
}),
],
Expand All @@ -42,7 +42,7 @@ describe(
cardNumber: 1234000000001234,
shadow: '2px 2px 2px 0px rgba(0, 0, 0, 0.20)',
},
numberOfСards: 2,
numberOfCards: 2,
},
}),
],
Expand All @@ -60,7 +60,7 @@ describe(
secondCard: {
cardNumber: 1234000000001234,
},
numberOfСards: 2,
numberOfCards: 2,
},
}),
],
Expand Down
20 changes: 16 additions & 4 deletions packages/product-cover/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ export type SingleCommonProps = {
cardNumber?: number;

/**
* Количество карт
* (Устаревший) Количество карт
* @deprecated Используйте 'numberOfCards'
*/
numberOfСards?: number;

/**
* Количество карт
*/
numberOfCards?: number;

/**
* Управление ориентацией стопки карт компонента
*/
Expand All @@ -124,11 +130,11 @@ export type SingleCommonProps = {
dataTestId?: string;
};

export type SingleProps = Omit<SingleCommonProps, 'numberOfСards' | 'align'>;
export type SingleProps = Omit<SingleCommonProps, 'numberOfСards' | 'numberOfCards' | 'align'>;

export type BankCardImageProps = Omit<
SingleCommonProps,
'size' | 'numberOfСards' | 'className' | 'dataTestId' | 'align'
'size' | 'numberOfСards' | 'numberOfCards' | 'className' | 'dataTestId' | 'align'
>;

export type SizeStack = Exclude<Size, 48 | 96 | 164>;
Expand Down Expand Up @@ -168,10 +174,16 @@ export type StackProps = ConditionalProps & {
secondCard?: BankCardImageProps;

/**
* Количество карт
* (Устаревший) Количество карт
* @deprecated Используйте 'numberOfCards'
*/
numberOfСards?: number;

/**
* Количество карт
*/
numberOfCards?: number;

/**
* Идентификатор для систем автоматизированного тестирования
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/product-cover/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export function getProductCoverStackTestIds(dataTestId: string) {
};
}

export const showNumberOfСards = (sizeCard: number, numberOfСards?: number, align?: string) => {
if (numberOfСards) {
return numberOfСards >= 2 && numberOfСards < 10 && sizeCard === 40 && align === 'default';
export const showNumberOfCards = (sizeCard: number, numberOfCards?: number, align?: string) => {
if (numberOfCards) {
return numberOfCards >= 2 && numberOfCards < 10 && sizeCard === 40 && align === 'default';
}

return false;
Expand Down
Loading