Skip to content

Commit

Permalink
feat(pure-cell): resolves #285 (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
NatalyaZ authored Oct 18, 2022
1 parent fa63028 commit 946e1e8
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 119 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-peaches-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alfalab/core-components-comment': minor
---

- Добавлен проп rowLimit для управления количеством строк для отображения
10 changes: 10 additions & 0 deletions .changeset/thick-monkeys-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@alfalab/core-components-pure-cell': major
---

- Для `PureCell.AmountTitle` props были объеденены с `AmountType`, удален проп `amount`
- Для `PureCell.Amount` props были объеденены с `AmountType`, удален проп `amount`, `view` переименован в `textView`
- Добавлен проп rowLimit для управления количеством строк для отображения
- Для `PureCell.Addon` расширено значение пропа `verticalAlign`
- Для `PureCell.Category` добавлен проп `rightAddons`
- В `PureCell.Text` исправлен `render` блока `value`
21 changes: 14 additions & 7 deletions packages/comment/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { Typography } from '@alfalab/core-components-typography';
import styles from './index.module.css';

export type CommentProps = {
/**
* Количество строк
*/
rowLimit?: 2 | 5;
/**
* Сss класс для стилизации общей обёртки
*/
Expand All @@ -22,10 +26,13 @@ export type CommentProps = {
children?: ReactNode;
};

export const Comment: React.FC<CommentProps> = ({ className, dataTestId, children }) => (
<div className={cn(styles.component, className)} data-test-id={dataTestId}>
<Typography.Text tag='div' view='component' className={styles.text} color='primary'>
{children}
</Typography.Text>
</div>
);
export const Comment: React.FC<CommentProps> = ({ className, dataTestId, children, rowLimit }) => {
const textClassName = rowLimit && styles[`rowLimit${rowLimit}`];
return (
<div className={cn(styles.component, className)} data-test-id={dataTestId}>
<Typography.Text tag='div' view='component' className={textClassName} color='primary'>
{children}
</Typography.Text>
</div>
);
};
6 changes: 6 additions & 0 deletions packages/comment/src/component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ describe('comment', () => {

expect(screen.getByTestId('test-children')).toBeInTheDocument();
});

it('should use a rowLimit prop', () => {
render(<Comment dataTestId='test-identifier' rowLimit={2} />);

expect(screen.getByTestId('test-identifier').firstElementChild).toHaveClass('rowLimit2');
});
});
5 changes: 3 additions & 2 deletions packages/comment/src/docs/component.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, Story, Props } from '@storybook/addon-docs';
import { text } from '@storybook/addon-knobs';
import { text, select } from '@storybook/addon-knobs';
import { ComponentHeader, Tabs, CssVars } from 'storybook/blocks';
import { Comment } from '@alfalab/core-components-comment';

Expand All @@ -18,9 +18,10 @@ import styles from '!!raw-loader!../index.module.css';
<Story name='Comment'>
{React.createElement(() => {
const children = text('Текст комментария', 'Comment');
const rowLimit = select('Количество строк', ['', '2', '5'], '');
return (
<div>
<Comment>{children}</Comment>
<Comment rowLimit={rowLimit}>{children}</Comment>
</div>
)
})}
Expand Down
9 changes: 8 additions & 1 deletion packages/comment/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
var(--border-radius-xxl);
}

.text {
.rowLimit2 {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}

.rowLimit5 {
display: -webkit-box;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
overflow: hidden;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions packages/pure-cell/src/components/addon/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
/**
* Вертикальное выравнивание
*/
verticalAlign?: 'center';
verticalAlign?: 'top' | 'center' | 'bottom';

/**
* Горизонтальные отступы
Expand All @@ -30,14 +30,12 @@ type Props = {

export const Addon: React.FC<Props> = ({
children,
verticalAlign,
verticalAlign = 'top',
addonPadding = 'default',
dataTestId,
}) => (
<section
className={cn(styles.component, styles[addonPadding], {
[styles.center]: verticalAlign,
})}
className={cn(styles.component, styles[addonPadding], styles[verticalAlign])}
data-test-id={getDataTestId(dataTestId, 'addon')}
>
{children}
Expand Down
9 changes: 9 additions & 0 deletions packages/pure-cell/src/components/addon/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.component {
display: flex;
flex-direction: column;
align-items: flex-end;

& > * {
justify-content: flex-end;
Expand All @@ -20,7 +21,15 @@
padding-left: var(--gap-m);
}

&.top {
align-self: flex-start;
}

&.center {
align-self: center;
}

&.bottom {
align-self: flex-end;
}
}
31 changes: 12 additions & 19 deletions packages/pure-cell/src/components/amount-title/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,20 @@ import { getDataTestId } from '../../../../utils/getDataTestId';
import styles from './index.module.css';

type Props = {
/**
* Props свойственные для компонента Amount
*/
amount: AmountType;

/**
* Цвет денежного значения
*/
color?: Color;
} & AmountType;

/**
* Идентификатор для систем автоматизированного тестирования
*/
dataTestId?: string;
};

export const AmountTitle: React.FC<Props> = ({ amount, color = 'primary', dataTestId }) => {
const { value, currency, minority, minorUnits, rightAddons, showPlus, className } = amount;
export const AmountTitle: React.FC<Props> = ({
minority,
minorUnits = 100,
className,
color = 'primary',
dataTestId,
...restProps
}) => {
return (
<Typography.Title
tag='h4'
Expand All @@ -37,14 +33,11 @@ export const AmountTitle: React.FC<Props> = ({ amount, color = 'primary', dataTe
color={color}
>
<CoreAmount
minority={minority === undefined ? minorUnits : minority}
value={value}
rightAddons={rightAddons}
showPlus={showPlus}
minority={minority || minorUnits}
className={cn(styles.weight, className)}
currency={currency}
dataTestId={getDataTestId(dataTestId, 'core-amount-title')}
view='withZeroMinorPart'
{...restProps}
bold='none'
/>
</Typography.Title>
);
Expand Down
38 changes: 9 additions & 29 deletions packages/pure-cell/src/components/amount/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import { getDataTestId } from '../../../../utils/getDataTestId';
import styles from './index.module.css';

type Props = {
/**
* Props свойственные для компонента Amount
*/
amount: AmountType;

/**
* Начертание шрифта денежного значения
*/
Expand All @@ -23,7 +18,7 @@ type Props = {
/**
* Размер денежного значения
*/
view?: 'component' | 'primary-small';
textView?: 'component' | 'primary-small';

/**
* Цвет денежного значения
Expand All @@ -34,44 +29,29 @@ type Props = {
* Идентификатор для систем автоматизированного тестирования
*/
dataTestId?: string;
};
} & AmountType;

export const Amount: React.FC<Props> = ({
amount,
weight = 'normal',
view = 'component',
textView = 'component',
color = 'primary',
minority,
minorUnits = 100,
dataTestId,
...restProps
}) => {
const {
value,
currency,
minority,
minorUnits,
rightAddons,
showPlus,
className,
transparentMinor,
view: viewAmount,
} = amount;
return (
<Typography.Text
view={view}
view={textView}
dataTestId={getDataTestId(dataTestId, 'amount-text')}
className={cn(styles.component)}
color={color}
>
<CoreAmount
minority={minority === undefined ? minorUnits : minority}
value={value}
transparentMinor={transparentMinor}
minority={minority || minorUnits}
bold={weight === 'bold' ? 'full' : 'none'}
rightAddons={rightAddons}
showPlus={showPlus}
className={className}
currency={currency}
dataTestId={getDataTestId(dataTestId, 'amount')}
view={viewAmount}
{...restProps}
/>
</Typography.Text>
);
Expand Down
22 changes: 20 additions & 2 deletions packages/pure-cell/src/components/category/component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ReactNode } from 'react';

import { Typography } from '@alfalab/core-components-typography';
import { getDataTestId } from '../../../../utils/getDataTestId';
Expand All @@ -16,13 +16,23 @@ type Props = {
*/
categoryPercent?: number;

/**
* Слот справа
*/
rightAddons?: ReactNode;

/**
* Идентификатор для систем автоматизированного тестирования
*/
dataTestId?: string;
};

export const Category: React.FC<Props> = ({ categoryName, categoryPercent, dataTestId }) => (
export const Category: React.FC<Props> = ({
categoryName,
categoryPercent,
rightAddons,
dataTestId,
}) => (
<div className={styles.component} data-test-id='cell-pure-category'>
<Typography.Text
view='primary-small'
Expand All @@ -43,5 +53,13 @@ export const Category: React.FC<Props> = ({ categoryName, categoryPercent, dataT
{categoryPercent}%
</Typography.Text>
)}
{rightAddons !== undefined && (
<div
className={styles.rightAddon}
data-test-id={getDataTestId(dataTestId, 'category-right-addon')}
>
{rightAddons}
</div>
)}
</div>
);
5 changes: 5 additions & 0 deletions packages/pure-cell/src/components/category/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-all;
}

.categoryPercent {
Expand All @@ -19,3 +20,7 @@
border-radius: var(--border-radius-xl);
margin-left: var(--gap-2xs);
}

.rightAddon {
margin-left: var(--gap-2xs);
}
30 changes: 16 additions & 14 deletions packages/pure-cell/src/components/text/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,22 @@ export const Text: React.FC<Props> = ({
children
)}
</span>
<span>
{typeof value === 'string' ? (
<Typography.Text
view={view}
color={valueColor}
className={className}
data-test-id={getDataTestId(dataTestId, 'text')}
>
{value}
</Typography.Text>
) : (
value
)}
</span>
{value !== undefined && (
<span className={styles.value}>
{typeof value === 'string' ? (
<Typography.Text
view={view}
color={valueColor}
className={className}
data-test-id={getDataTestId(dataTestId, 'text')}
>
{value}
</Typography.Text>
) : (
value
)}
</span>
)}
</div>
);
};
Loading

0 comments on commit 946e1e8

Please sign in to comment.