Skip to content

Commit

Permalink
Add report component (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
vesnushka authored Dec 19, 2024
1 parent f63914d commit 60ba397
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 1 deletion.
74 changes: 74 additions & 0 deletions src/components/Report/Report.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Meta, StoryObj } from '@storybook/react';

import { withColorSchemeDecorator } from 'src/storybook/decorators';

import { Report, ReportLabel, ReportProps } from './index';
import { InfoCircleOutlined } from '@ant-design/icons';
import styled from 'styled-components';

const args: ReportProps = {
items: [
{
title: 'Title 1',
value: 'Value 1',
},
{
title: 'Title 2',
value: 0,
},
],
};

const meta: Meta<typeof Report> = {
title: 'components / Report',
component: Report,
decorators: [withColorSchemeDecorator],
args,
};

export default meta;

type Story = StoryObj<ReportProps>;

export const Default: Story = {};

const S = {
Label: styled.div`
display: flex;
gap: 0 4px;
color: ${({ theme }) => theme.neutralPalette.gray_7};
svg {
font-size: 14px;
}
`,
};

export const FullWidth: Story = {
args: {
fullWidth: true,
items: [
{
title: 'Title 1',
value: 'Value 1',
},
{
title: 'Title 2',
value: 0,
},
{
title: (
<S.Label>
<ReportLabel>Title 3</ReportLabel>
<InfoCircleOutlined />
</S.Label>
),
value: 'Value 3',
},
{
title: 'Title 4',
value: 'Value 4',
},
],
},
};
48 changes: 48 additions & 0 deletions src/components/Report/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import { S } from './styles';
import _ from 'lodash';

export interface ReportProps {
items: Array<{
title: React.ReactNode;
value?: React.ReactNode;
}>;
fullWidth?: boolean;
style?: React.CSSProperties;
className?: string;
}

export function Report(props: ReportProps) {
const { className, style, items, fullWidth = false } = props;

return (
<S.Container className={className} style={style} $fullWidth={fullWidth}>
{items.map(({ title, value }, index) => (
<S.Item key={`report-${index}`}>
{_.isString(title) ? <ReportLabel>{title}</ReportLabel> : title}
{_.isString(value) || _.isNumber(value) || _.isUndefined(value) || _.isNull(value) ? (
<ReportValue>{value}</ReportValue>
) : (
value
)}
</S.Item>
))}
</S.Container>
);
}

interface ReportLabelProps {
children: React.ReactNode;
}

export function ReportLabel(props: ReportLabelProps) {
const { children } = props;

return <S.Label>{children}</S.Label>;
}

export function ReportValue(props: ReportLabelProps) {
const { children } = props;

return <S.Value>{children ?? '-'}</S.Value>;
}
35 changes: 35 additions & 0 deletions src/components/Report/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import styled, { css } from 'styled-components';
import { Text } from '../Typography';

export const S = {
Container: styled.div<{ $fullWidth?: boolean }>`
display: flex;
justify-content: flex-start;
gap: 16px 40px;
padding: 16px;
border: 1px solid ${({ theme }) => theme.neutralPalette.gray_4};
border-radius: 10px;
background-color: ${({ theme }) => theme.neutralPalette.gray_1};
width: fit-content;
${({ $fullWidth }) =>
$fullWidth &&
css`
width: auto;
justify-content: space-between;
`}
`,
Item: styled.div`
display: flex;
flex-direction: column;
gap: 4px 0;
`,
Label: styled(Text)`
font-size: 12px;
line-height: 20px;
color: ${({ theme }) => theme.neutralPalette.gray_7};
`,
Value: styled(Text)`
font-weight: 700;
`,
};
3 changes: 2 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export * from './Spinner';
export * from './Table';
export * from './TextWithMacroFill';
export * from './TimePicker';
export * from './Typography';
export * from './Typography';
export * from './Report';

0 comments on commit 60ba397

Please sign in to comment.