This commit is contained in:
bakhirev 2024-08-15 14:52:27 +03:00
parent 780ff751df
commit 886c258357
6 changed files with 97 additions and 25 deletions

View file

@ -3,6 +3,7 @@ import React from 'react';
import { IColumn } from 'ts/components/Table/interfaces/Column'; import { IColumn } from 'ts/components/Table/interfaces/Column';
import Line from './Line'; import Line from './Line';
import LineWithTemplate from './LineWithTemplate';
import Title from './Title'; import Title from './Title';
import style from '../styles/index.module.scss'; import style from '../styles/index.module.scss';
@ -19,6 +20,7 @@ function Card({
className, className,
customStyle, customStyle,
}: ICardProps) { }: ICardProps) {
let alreadySetHeader = false;
const parts = lines.map((line: IColumn, columnIndex: number) => { const parts = lines.map((line: IColumn, columnIndex: number) => {
const value = line.properties const value = line.properties
? item[line.properties] ? item[line.properties]
@ -28,13 +30,13 @@ function Card({
? line.formatter(value) ? line.formatter(value)
: value; : value;
if (typeof line.template === 'function') { const hasTemplate = typeof line.template === 'function';
return line.template(formattedValue, item); const content = hasTemplate // @ts-ignore
} ? line.template(formattedValue, item)
: `${line.prefixes ?? ''}${formattedValue ?? ''}${line.suffixes ?? ''}`;
const content = `${line.prefixes ?? ''}${formattedValue ?? ''}${line.suffixes ?? ''}`; if (!alreadySetHeader && line.title) {
alreadySetHeader = true;
if (!columnIndex) {
return ( return (
<Title <Title
key={`${line.title}_${columnIndex}`} key={`${line.title}_${columnIndex}`}
@ -45,6 +47,17 @@ function Card({
); );
} }
if (hasTemplate && (!line.width || (line.width && line.width > 110))) {
return (
<LineWithTemplate
key={`${line.title}_${columnIndex}`}
item={item}
column={line}
value={content}
/>
);
}
return ( return (
<Line <Line
key={`${line.title}_${columnIndex}`} key={`${line.title}_${columnIndex}`}

View file

@ -17,17 +17,21 @@ function Line({
item, item,
value, value,
className, className,
}: ILineProps): JSX.Element { }: ILineProps): JSX.Element | null {
const { t } = useTranslation(); const { t } = useTranslation();
const columnClassName = typeof column.className === 'function' const columnClassName = typeof column.className === 'function'
? column.className('body', item) ? column.className('body', item)
: column.className; : column.className;
const type = typeof value;
if (!column.title
|| type === 'undefined'
|| value === ''
|| (type === 'number' && isNaN(value as number))
|| (type === 'object' && !value)) return null;
return ( return (
<div <div className={`${style.card_line} ${className || ''} ${columnClassName || ''}`}>
key={column.title}
className={`${style.card_line} ${className || ''} ${columnClassName || ''}`}
>
<div className={style.card_line_title}> <div className={style.card_line_title}>
{t(column.title || '')} {t(column.title || '')}
</div> </div>

View file

@ -8,9 +8,13 @@ function getCardConfigs(
column: IColumn, column: IColumn,
index: number, index: number,
) => { ) => {
if (index === 0) {
acc.text.push(column);
return acc;
}
const nextColumn = dirtyColumns[index + 1]; const nextColumn = dirtyColumns[index + 1];
if (column.template === ColumnTypesEnum.SHORT_NUMBER if (column.template === ColumnTypesEnum.SHORT_NUMBER && typeof nextColumn?.template === 'function') {
&& typeof nextColumn?.template === 'function') {
acc.text.push({ acc.text.push({
...column, ...column,
title: nextColumn?.title, title: nextColumn?.title,

View file

@ -1,15 +1,18 @@
@import 'src/styles/variables'; @import 'src/styles/variables';
.card { .card {
position: relative;
display: inline-block; display: inline-block;
width: 100%; width: 100%;
padding: var(--space-s); padding: var(--space-xxl) var(--space-s) var(--space-s);
margin: 0 var(--space-xxl) var(--space-xxl) 0; margin: 0 var(--space-xxl) var(--space-xxl) 0;
border-radius: var(--border-radius-m);
border: 1px solid var(--color-border);
page-break-inside: avoid; page-break-inside: avoid;
box-sizing: border-box; box-sizing: border-box;
vertical-align: top; vertical-align: top;
border-radius: var(--border-radius-m);
border: 1px solid var(--color-border);
background-color: var(--color-white); background-color: var(--color-white);
&_wrapper { &_wrapper {
@ -18,21 +21,36 @@
} }
&_title { &_title {
position: absolute;
top: -13px;
left: 20%;
right: 20%;
font-size: var(--font-m); font-size: var(--font-m);
font-weight: bold; font-weight: bold;
display: block; display: inline-block;
padding: var(--space-xxs) var(--space-s);
margin: 0 0 var(--space-l); margin: 0 0 var(--space-l);
line-height: 1.3; line-height: 1.3;
white-space: normal; white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
text-align: center; text-align: center;
border-radius: var(--border-radius-s);
border: 1px solid var(--color-border);
background-color: var(--color-white);
} }
&_line { &_line {
display: block; display: flex;
justify-content: space-between;
align-items: center;
padding: var(--space-xxs) var(--space-xxs) var(--space-xxxs);
white-space: nowrap; white-space: nowrap;
padding: var(--space-xxs);
box-sizing: border-box; box-sizing: border-box;
border: none; border: none;
@ -40,26 +58,52 @@
&_value { &_value {
font-size: var(--font-s); font-size: var(--font-s);
position: relative; position: relative;
display: inline-block; display: inline-block;
width: max-content;
line-height: 1.3; line-height: 1.3;
white-space: normal; white-space: normal;
text-overflow: ellipsis; text-overflow: ellipsis;
vertical-align: top; vertical-align: top;
box-sizing: border-box; box-sizing: border-box;
text-align: left; text-align: left;
}
&_title { color: var(--color-42);
width: 60%;
} }
&_value { &_value {
width: 40%;
text-align: right; text-align: right;
} }
} }
&_line_with_template {
display: block;
text-align: center;
margin-top: var(--space-xxs);
border-top: 2px dotted var(--color-border);
&_title {
font-size: var(--font-s);
display: block;
padding: var(--space-xxs) var(--space-xxs) var(--space-xxs);
line-height: 1.3;
white-space: normal;
text-overflow: ellipsis;
vertical-align: top;
box-sizing: border-box;
color: var(--color-42);
}
}
} }
.card_line + .card_line { .card_line + .card_line {
border-top: 1px solid var(--color-border); border-top: 1px solid var(--color-border);
} }
.card_line_with_template > .line_chart {
margin-top: 0;
}

View file

@ -13,6 +13,7 @@ function UiKitTags({
}: IUiKitTagsProps) { }: IUiKitTagsProps) {
const values = Array.isArray(value) ? value : [value]; const values = Array.isArray(value) ? value : [value];
const formattedValues = values.filter((v) => v); const formattedValues = values.filter((v) => v);
if (!formattedValues?.length) return null;
const items = formattedValues const items = formattedValues
.map((tagValue: any) => ( .map((tagValue: any) => (
@ -22,6 +23,8 @@ function UiKitTags({
/> />
)); ));
if (!items?.length) return null;
return ( return (
<div className={style.ui_kit_tags}> <div className={style.ui_kit_tags}>
{items} {items}

View file

@ -7,7 +7,7 @@
&_item { &_item {
display: inline-block; display: inline-block;
padding: var(--space-xxxs) var(--space-xs); padding: var(--space-xxxs) var(--space-xs);
margin: 0 var(--space-xs) var(--space-xs) 0; margin: 0 0 var(--space-xs) 0;
font-size: var(--font-s); font-size: var(--font-s);
font-weight: 100; font-weight: 100;
@ -25,3 +25,7 @@
color: var(--color-black); color: var(--color-black);
} }
} }
.ui_kit_tags_item + .ui_kit_tags_item {
margin-right: var(--space-xs);
}