Skip to content

Commit 36535f3

Browse files
authored
Merge pull request #154 from KasperskyLab/feature/publish-hexa-ui-charts-07-15
feat: publish @kaspersky/hexa-ui-charts
2 parents 8343a86 + 1955a65 commit 36535f3

370 files changed

Lines changed: 32355 additions & 16488 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/kaspersky-hexa-ui-charts/.eslintrc.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/kaspersky-hexa-ui-charts/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ dist/
1313
.eslintcache
1414

1515
*storybook.log
16+
17+
playwright-report/
18+
storybook-static/
19+
test-results/

packages/kaspersky-hexa-ui-charts/.storybook/assert-stub.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ module.exports.ok = noop
55
module.exports.strictEqual = noop
66
module.exports.deepEqual = noop
77
module.exports.fail = noop
8-
module.exports.equal = noop
8+
module.exports.equal = noop
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Grid, GridItem } from '@kaspersky/hexa-ui'
2+
import { Space } from '@kaspersky/hexa-ui'
3+
import { Text } from '@kaspersky/hexa-ui'
4+
import React, { FC, useMemo } from 'react'
5+
6+
import { productColors } from '@kaspersky/hexa-ui-core/colors/js'
7+
import { StatusNoThreadOutline, StatusOkOutline } from '@kaspersky/hexa-ui-icons/24'
8+
9+
import { metaDod, MetaDodProps } from './types'
10+
11+
type MetaDodKeys = keyof MetaDodProps['list']
12+
13+
export const MetaDod: FC<MetaDodProps> = ({ list }: MetaDodProps) => {
14+
const metaDodKeys = useMemo(() => Object.keys(metaDod) as MetaDodKeys[], [])
15+
16+
return (
17+
<Grid layout={{ cols: ['repeat(2, 240px)'] }}>
18+
{metaDodKeys.map(key =>
19+
<GridItem key={key}>
20+
<Space size={8}>
21+
{list[key]
22+
? <StatusOkOutline color={productColors.icon.status.statusgrass.light} />
23+
: <StatusNoThreadOutline color={productColors.icon.status.statusneutral.light} />}
24+
<Text>
25+
{metaDod[key]}
26+
</Text>
27+
</Space>
28+
</GridItem>
29+
)}
30+
</Grid>
31+
)
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './withMeta'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export type MetaList = {
2+
dod?: MetaDodProps['list'],
3+
component?: string,
4+
description?: string,
5+
usage?: string,
6+
designLink?: string,
7+
pixsoView?: string
8+
}
9+
10+
export const metaDod = {
11+
designTokens: 'Design tokens',
12+
unitTests: 'Unit tests',
13+
screenshotTests: 'Screenshot tests',
14+
storybook: 'Storybook',
15+
pixsoView: 'Pixso'
16+
}
17+
18+
export type MetaDodProps = {
19+
list: Partial<Record<keyof typeof metaDod, boolean>>
20+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
import { Link, Markdown } from '@kaspersky/hexa-ui'
3+
import { Space } from '@kaspersky/hexa-ui'
4+
import { Heading, Text } from '@kaspersky/hexa-ui'
5+
import React from 'react'
6+
import styled from 'styled-components'
7+
8+
import { MetaDod } from './MetaDod'
9+
import { MetaList } from './types'
10+
11+
const StyledHeading = styled(Heading)`
12+
border: none !important;
13+
padding: 0 !important;
14+
margin: 0 !important;
15+
`
16+
17+
const StyledLink = styled(Link)`
18+
height: 20px !important;
19+
> span {
20+
font-family: inherit !important;
21+
font-size: inherit !important;
22+
}
23+
`
24+
25+
export function withMeta (
26+
list: MetaList,
27+
Component?: React.FC
28+
): React.FC {
29+
const setMeta = (props: any) => {
30+
return (
31+
<Space gap={32} direction="vertical" align="start">
32+
<Space gap={16} direction="vertical" align="start">
33+
<StyledHeading type="H2">{list?.component}</StyledHeading>
34+
{(list?.pixsoView || list?.designLink) && (
35+
<Space gap={16}>
36+
{list?.pixsoView && (
37+
<StyledLink
38+
href={list.pixsoView}
39+
target="_blank"
40+
decoration="icon"
41+
size="medium"
42+
>
43+
Документация в Pixso
44+
</StyledLink>
45+
)}
46+
{list?.designLink && (
47+
<StyledLink
48+
href={list.designLink}
49+
target="_blank"
50+
decoration="icon"
51+
size="medium"
52+
>
53+
Компонент в Pixso
54+
</StyledLink>
55+
)}
56+
</Space>
57+
)}
58+
</Space>
59+
<Space gap={16} direction="vertical" align="start">
60+
<Heading type="H4">Назначение</Heading>
61+
<Markdown value={list?.usage || '-'} />
62+
</Space>
63+
{list?.description && <Space gap={16} direction="vertical" align="start">
64+
<Heading type="H4">Технические особенности</Heading>
65+
<Markdown value={list?.description ?? '-'} />
66+
</Space>}
67+
{list?.dod && <MetaDod list={list.dod} />}
68+
{Component && <Component {...props} />}
69+
</Space>
70+
)
71+
}
72+
return setMeta
73+
}
Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { random } from "lodash"
21
import { add, Duration } from 'date-fns'
32
import { IStackedChartData } from "../src/types/chartData"
43

@@ -14,28 +13,60 @@ const numberFormatter = new Intl.NumberFormat('en-US', {
1413
style: 'percent'
1514
})
1615

17-
export function generateData (total = 1, totalInStack = 5, maxRandomValue = 1000): IStackedChartData {
18-
return Array.from({ length: total }).map((_, idx) => ({
19-
name: numberFormatter.format(idx),
20-
color: colors[idx % colors.length],
21-
data: Array.from({ length: totalInStack }).map((_, idx) => ({ metric: 10 * idx, value: random(0, maxRandomValue), originalPayload: idx.toString() }))
22-
}))
16+
const FIXED_NOW = new Date(Date.UTC(2026, 0, 1, 12, 0, 0));
17+
18+
export const getStableValue = (
19+
maxValue: number,
20+
pointIndex: number,
21+
seriesIndex = 0,
22+
): number => {
23+
if (maxValue <= 0) {
24+
return 0;
25+
}
26+
27+
return (
28+
((pointIndex + 1) * 137 +
29+
(seriesIndex + 1) * 71 +
30+
(pointIndex + 1) * (seriesIndex + 1) * 29) %
31+
(maxValue + 1)
32+
);
33+
};
34+
35+
export function generateData(
36+
total = 1,
37+
totalInStack = 5,
38+
maxRandomValue = 1000,
39+
): IStackedChartData {
40+
return Array.from({ length: total }).map((_, seriesIndex) => ({
41+
name: numberFormatter.format(seriesIndex),
42+
color: colors[seriesIndex % colors.length],
43+
data: Array.from({ length: totalInStack }).map((_, pointIndex) => ({
44+
metric: 10 * pointIndex,
45+
value: getStableValue(maxRandomValue, pointIndex, seriesIndex),
46+
originalPayload: pointIndex.toString(),
47+
})),
48+
}));
2349
}
2450

25-
const now = new Date()
26-
27-
export function generateTimelineData (total = 1, totalInStack = 20, maxRandomValue = 1000, durationType: keyof Duration = 'days', title?: string): IStackedChartData {
28-
return Array.from({ length: total }).map((_, idx) => ({
29-
name: numberFormatter.format(idx),
30-
color: colors[idx % colors.length],
31-
data: Array.from({ length: totalInStack }).map((_, idx) => {
32-
const metric = add(now, { [durationType]: idx })
33-
34-
return ({ metric,
35-
value: random(maxRandomValue),
36-
originalPayload: add(now, { [durationType]: idx }),
37-
title: title && ((metric: string) => `${title}${metric}`) })
38-
})
39-
})
40-
)
51+
export function generateTimelineData(
52+
total = 1,
53+
totalInStack = 20,
54+
maxRandomValue = 1000,
55+
durationType: keyof Duration = 'days',
56+
title?: string,
57+
): IStackedChartData {
58+
return Array.from({ length: total }).map((_, seriesIndex) => ({
59+
name: numberFormatter.format(seriesIndex),
60+
color: colors[seriesIndex % colors.length],
61+
data: Array.from({ length: totalInStack }).map((_, pointIndex) => {
62+
const metric = add(FIXED_NOW, { [durationType]: pointIndex });
63+
64+
return {
65+
metric,
66+
value: getStableValue(maxRandomValue, pointIndex, seriesIndex),
67+
originalPayload: metric,
68+
title: title && ((metric: string) => `${title}${metric}`),
69+
};
70+
}),
71+
}));
4172
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { GlobalStyle } from '@kaspersky/hexa-ui/design-system'
2+
import { ThemeProvider } from '@kaspersky/hexa-ui/design-system'
3+
import { themeColors } from '@kaspersky/hexa-ui/design-system'
4+
import { ThemeKey } from '@kaspersky/hexa-ui/design-system'
5+
import React, { FC, HTMLAttributes } from 'react'
6+
import styled from 'styled-components'
7+
8+
export const withThemeProvider = (Story: FC, context: any) => {
9+
const themeKey = context.globals.theme || ThemeKey.Light
10+
const direction = context.globals.direction || 'ltr'
11+
12+
return (
13+
<ThemeProvider theme={themeKey}>
14+
<GlobalStyle />
15+
<StoryLayoutContainer theme={themeKey} dir={direction}>
16+
<Story {...context} theme={themeKey} />
17+
</StoryLayoutContainer>
18+
</ThemeProvider>
19+
)
20+
}
21+
22+
export const StoryLayoutContainer = styled.div<HTMLAttributes<HTMLDivElement>>(
23+
(props: { theme: ThemeKey, inverted?: boolean }) => ({
24+
display: 'flex',
25+
gap: '16px',
26+
flexWrap: 'wrap',
27+
padding: '1.5rem',
28+
margin: '-1rem',
29+
alignItems: 'flex-start',
30+
minHeight: '100vh',
31+
background: props.inverted ? props.theme === ThemeKey.Light ? '#AB94F1' : '#1DA189' : themeColors.bg.base[props.theme]
32+
})
33+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, { FC } from 'react'
2+
3+
export const withVisualData = (Story: FC, context: any) => {
4+
const visual = context.parameters.visual;
5+
6+
return (
7+
<div
8+
data-visual-root
9+
data-visual-delay-ms={visual?.delayMs ?? 0}
10+
>
11+
<Story {...context} />
12+
</div>
13+
);
14+
};

0 commit comments

Comments
 (0)