@wonderflow/react-components 16.0.0 → 17.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/product-card/product-card-footer/product-card-footer.d.ts.map +1 -1
- package/dist/components/product-card/product-card-footer/product-card-footer.js +2 -2
- package/dist/components/product-card/product-card-header/product-card-header.d.ts +1 -4
- package/dist/components/product-card/product-card-header/product-card-header.d.ts.map +1 -1
- package/dist/components/product-card/product-card-header/product-card-header.js +9 -13
- package/dist/components/product-card/product-card-header/product-card-header.test.js +1 -1
- package/dist/components/product-card/product-card-kpis/product-card-kpis.d.ts +2 -1
- package/dist/components/product-card/product-card-kpis/product-card-kpis.d.ts.map +1 -1
- package/dist/components/product-card/product-card-kpis/product-card-kpis.js +19 -18
- package/dist/components/product-card/product-card-kpis/product-card-kpis.module.css +1 -1
- package/dist/components/product-card/product-card-kpis/product-card.kpis.test.js +14 -0
- package/dist/components/product-card/product-card-media/product-card-media.module.css +1 -1
- package/dist/components/product-card/product-card-top-bar/product-card-top-bar.d.ts +18 -0
- package/dist/components/product-card/product-card-top-bar/product-card-top-bar.d.ts.map +1 -0
- package/dist/components/product-card/product-card-top-bar/product-card-top-bar.js +24 -0
- package/dist/components/product-card/product-card-top-bar/product-card-top-bar.module.css +1 -0
- package/dist/components/product-card/product-card-top-bar/product-card-top-bar.test.d.ts +2 -0
- package/dist/components/product-card/product-card-top-bar/product-card-top-bar.test.d.ts.map +1 -0
- package/dist/components/product-card/product-card-top-bar/product-card-top-bar.test.js +14 -0
- package/dist/components/product-card/product-card.d.ts +19 -5
- package/dist/components/product-card/product-card.d.ts.map +1 -1
- package/dist/components/product-card/product-card.js +14 -29
- package/dist/components/product-card/product-card.module.css +1 -1
- package/dist/components/product-card/product-card.stories.d.ts +4 -1
- package/dist/components/product-card/product-card.stories.d.ts.map +1 -1
- package/dist/components/product-card/product-card.stories.js +37 -18
- package/dist/components/product-card/product-card.test.js +49 -10
- package/dist/components/table/to-tanstack-columns.d.ts.map +1 -1
- package/dist/components/table/to-tanstack-columns.js +3 -1
- package/dist/examples/shell.stories.d.ts.map +1 -1
- package/dist/examples/shell.stories.js +1 -1
- package/dist/utils/formatting.d.ts +4 -0
- package/dist/utils/formatting.d.ts.map +1 -1
- package/dist/utils/formatting.js +5 -2
- package/dist/utils/formatting.test.js +8 -0
- package/package.json +4 -4
- package/dist/components/product-card/product-card-header/product-card-header.module.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-card-footer.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-footer/product-card-footer.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAc,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAMtD,oBAAY,sBAAsB,GAAG,iBAAiB,CAAC;IACrD;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,CAAA;AAEF,oBAAY,0BAA0B,GAAG,KAAK,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAC;AAEjG,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"product-card-footer.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-footer/product-card-footer.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAc,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAMtD,oBAAY,sBAAsB,GAAG,iBAAiB,CAAC;IACrD;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,CAAA;AAEF,oBAAY,0BAA0B,GAAG,KAAK,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAC;AAEjG,eAAO,MAAM,iBAAiB,4BAYE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright 2023 Wonderflow Design Team
|
|
3
|
+
* Copyright 2023-2026 Wonderflow Design Team
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -16,5 +16,5 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
16
16
|
*/
|
|
17
17
|
import { forwardRef } from 'react';
|
|
18
18
|
import { Skeleton, Stack, } from '../../..';
|
|
19
|
-
export const ProductCardFooter = forwardRef(({ isLoading = false, children, ...otherProps }, forwardedRef) => (_jsx(Stack, {
|
|
19
|
+
export const ProductCardFooter = forwardRef(({ isLoading = false, children, ...otherProps }, forwardedRef) => (_jsx(Stack, { style: { padding: children || isLoading ? '16px' : '0 16px 16px' }, ...otherProps, ref: forwardedRef, children: isLoading ? _jsx(Skeleton, { height: "24px", style: { lineHeight: '1.5rem' } }) : children })));
|
|
20
20
|
ProductCardFooter.displayName = 'ProductCardFooter';
|
|
@@ -10,6 +10,7 @@ export declare type ProductCardHeaderProps = {
|
|
|
10
10
|
title?: string;
|
|
11
11
|
/**
|
|
12
12
|
* Define how many lines the title should be clamped to.
|
|
13
|
+
* The title area is always at least 2 rows tall (or `titleRows` if lower).
|
|
13
14
|
*/
|
|
14
15
|
titleRows?: number;
|
|
15
16
|
/**
|
|
@@ -20,10 +21,6 @@ export declare type ProductCardHeaderProps = {
|
|
|
20
21
|
* Define how many lines the description should be clamped to.
|
|
21
22
|
*/
|
|
22
23
|
descriptionRows?: number;
|
|
23
|
-
/**
|
|
24
|
-
* Set the content to be displayed in the header menu.
|
|
25
|
-
*/
|
|
26
|
-
menuActions?: React.ReactNode;
|
|
27
24
|
/**
|
|
28
25
|
* Set the loading state showing a skeleton.
|
|
29
26
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-card-header.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-header/product-card-header.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"product-card-header.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-header/product-card-header.tsx"],"names":[],"mappings":";AA0BA,oBAAY,sBAAsB,GAAG;IACnC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAA;AAED,oBAAY,0BAA0B,GAAG,KAAK,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAC;AAEjG,eAAO,MAAM,iBAAiB,4BA6CE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright 2023 Wonderflow Design Team
|
|
3
|
+
* Copyright 2023-2026 Wonderflow Design Team
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -15,18 +15,14 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { forwardRef } from 'react';
|
|
18
|
-
import { ClampText,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const dynamicStyle = {
|
|
24
|
-
'--header-title-height': `${(titleRows ?? 0) * titleRem}rem`,
|
|
25
|
-
'--header-description-height': `${(descriptionRows ?? 0) * descriptionRem}rem`,
|
|
26
|
-
};
|
|
18
|
+
import { ClampText, Skeleton, Stack, Text, } from '../../..';
|
|
19
|
+
// `heading-6` line height (1.75rem) and the rows the title always occupies, to keep KPIs aligned across cards.
|
|
20
|
+
const TITLE_LINE_HEIGHT_REM = 1.75;
|
|
21
|
+
const TITLE_MIN_ROWS = 2;
|
|
22
|
+
export const ProductCardHeader = forwardRef(({ subtitle, title, titleRows = 3, description, descriptionRows = 3, isLoading = false, }, forwardedRef) => {
|
|
27
23
|
if (isLoading) {
|
|
28
|
-
return (_jsxs(Stack, {
|
|
24
|
+
return (_jsxs(Stack, { rowGap: 8, style: { padding: '16px 16px 8px' }, children: [_jsxs("div", { children: [subtitle && _jsx(Skeleton, { count: 1, width: "50%" }), title && _jsx("div", { children: _jsx(Skeleton, { count: 1, height: "28px", width: "60%" }) })] }), description && _jsx("div", { children: _jsx(Skeleton, { count: 1, width: "80%" }) })] }));
|
|
29
25
|
}
|
|
30
|
-
return (_jsxs(Stack, {
|
|
26
|
+
return (_jsxs(Stack, { rowGap: 8, ref: forwardedRef, style: { padding: '16px 16px 8px' }, children: [_jsxs("div", { children: [subtitle && _jsx(Text, { variant: "subtitle-2", children: subtitle }), title && (_jsx("div", { style: { minHeight: `${Math.min(titleRows, TITLE_MIN_ROWS) * TITLE_LINE_HEIGHT_REM}rem` }, children: _jsx(ClampText, { rows: titleRows, children: _jsx(Text, { variant: "heading-6", children: title }) }) }))] }), description && (_jsx(ClampText, { rows: descriptionRows, children: _jsx(Text, { variant: "body-2", children: description }) }))] }));
|
|
31
27
|
});
|
|
32
28
|
ProductCardHeader.displayName = 'ProductCardHeader';
|
|
@@ -11,7 +11,7 @@ describe('<ProductCardHeader>', () => {
|
|
|
11
11
|
expect(container).not.toBeNull();
|
|
12
12
|
});
|
|
13
13
|
test('it should render properly with skeleton', () => {
|
|
14
|
-
const { container } = render(_jsx(ProductCardHeader, { title: "title", subtitle: "subtitle", description: "description",
|
|
14
|
+
const { container } = render(_jsx(ProductCardHeader, { title: "title", subtitle: "subtitle", description: "description", isLoading: true }));
|
|
15
15
|
expect(container).not.toBeNull();
|
|
16
16
|
});
|
|
17
17
|
});
|
|
@@ -67,7 +67,8 @@ export declare type ProductCardKpisProps = PropsWithClass<{
|
|
|
67
67
|
*/
|
|
68
68
|
skusCap?: number;
|
|
69
69
|
/**
|
|
70
|
-
* Set the number of Kpis items to be displayed.
|
|
70
|
+
* Set the maximum number of Kpis items to be displayed (and the skeleton rows while loading).
|
|
71
|
+
* When used through `ProductCard`, `0` hides the KPIs block (and its spacing) entirely.
|
|
71
72
|
*/
|
|
72
73
|
kpiItems?: number;
|
|
73
74
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-card-kpis.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-kpis/product-card-kpis.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"product-card-kpis.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-kpis/product-card-kpis.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAe/D,oBAAY,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAE7J,oBAAY,oBAAoB,GAAG,cAAc,CAAC;IAChD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;MAEE;IACF,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;MAEE;IACF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;MAEE;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;MAEE;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;MAEE;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;MAEE;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAClC;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,CAAA;AAEF,oBAAY,wBAAwB,GAAG,KAAK,CAAC,yBAAyB,CAAC,oBAAoB,CAAC,CAAC;AAS7F,eAAO,MAAM,eAAe,0BAsIE,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import tkns from '@wonderflow/tokens/platforms/web/tokens.json';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
-
import { forwardRef, useMemo
|
|
4
|
+
import { forwardRef, useMemo } from 'react';
|
|
5
5
|
import { Skeleton, Stack, Symbol, Text, } from '../../..';
|
|
6
6
|
import { formatKpiValue, formatPriceRangeValues, isGreaterThan, isValueOverCap, } from '../../../utils/formatting';
|
|
7
7
|
import * as styles from './product-card-kpis.module.css';
|
|
@@ -9,7 +9,7 @@ export const ProductCardKpis = forwardRef(({ rating, feedbackCount, votesCount,
|
|
|
9
9
|
const config = useMemo(() => ([
|
|
10
10
|
{
|
|
11
11
|
property: 'feedback-rating',
|
|
12
|
-
value: formatKpiValue(rating, { decimal:
|
|
12
|
+
value: formatKpiValue(rating, { decimal: 1, minRange: 0, maxRange: 5 }),
|
|
13
13
|
icon: 'feedback-rating',
|
|
14
14
|
iconColor: isGreaterThan(3.99, rating) ? `hsl(${tkns.color.yellow['30']})` : undefined,
|
|
15
15
|
},
|
|
@@ -20,29 +20,29 @@ export const ProductCardKpis = forwardRef(({ rating, feedbackCount, votesCount,
|
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
property: 'feedback-count',
|
|
23
|
-
value: formatKpiValue(feedbackCount),
|
|
23
|
+
value: formatKpiValue(feedbackCount, { decimal: 0, minRange: 0, compact: true }),
|
|
24
24
|
icon: 'message',
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
property: 'votes-rating',
|
|
28
|
-
value: formatKpiValue(votesRating, { decimal:
|
|
28
|
+
value: formatKpiValue(votesRating, { decimal: 1, minRange: 0, maxRange: 5 }),
|
|
29
29
|
icon: 'star',
|
|
30
30
|
iconColor: isGreaterThan(3.99, votesRating) ? `hsl(${tkns.color.yellow['20']})` : undefined,
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
property: 'votes-count',
|
|
34
|
-
value: formatKpiValue(votesCount),
|
|
34
|
+
value: formatKpiValue(votesCount, { decimal: 0, minRange: 0, compact: true }),
|
|
35
35
|
icon: 'votes-count',
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
property: 'sentiment',
|
|
39
|
-
value: formatKpiValue(sentiment, { decimal:
|
|
39
|
+
value: formatKpiValue(sentiment, { decimal: 1, minRange: -1, maxRange: 1 }),
|
|
40
40
|
icon: 'hearts-suit',
|
|
41
41
|
iconColor: isGreaterThan(0.5, sentiment) ? 'var(--highlight-red-foreground)' : undefined,
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
property: 'tgw',
|
|
45
|
-
value: formatKpiValue(tgw, { decimal:
|
|
45
|
+
value: formatKpiValue(tgw, { decimal: 1, minRange: 0 }),
|
|
46
46
|
icon: 'frown',
|
|
47
47
|
},
|
|
48
48
|
{
|
|
@@ -52,18 +52,22 @@ export const ProductCardKpis = forwardRef(({ rating, feedbackCount, votesCount,
|
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
property: 'groups',
|
|
55
|
-
value: formatKpiValue(groups),
|
|
55
|
+
value: formatKpiValue(groups, { decimal: 0, minRange: 0, compact: true }),
|
|
56
56
|
icon: 'grid',
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
property: 'users',
|
|
60
|
-
value: formatKpiValue(users, {
|
|
60
|
+
value: formatKpiValue(users, {
|
|
61
|
+
decimal: 0, minRange: 0, cap: usersCap, compact: true,
|
|
62
|
+
}),
|
|
61
63
|
icon: 'users',
|
|
62
64
|
iconColor: isValueOverCap(users, usersCap) ? 'var(--highlight-red-foreground)' : undefined,
|
|
63
65
|
},
|
|
64
66
|
{
|
|
65
67
|
property: 'skus',
|
|
66
|
-
value: formatKpiValue(skus, {
|
|
68
|
+
value: formatKpiValue(skus, {
|
|
69
|
+
decimal: 0, minRange: 0, cap: skusCap, compact: true,
|
|
70
|
+
}),
|
|
67
71
|
icon: 'rectangle-barcode',
|
|
68
72
|
iconColor: isValueOverCap(skus, skusCap) ? 'var(--highlight-red-foreground)' : undefined,
|
|
69
73
|
},
|
|
@@ -85,14 +89,11 @@ export const ProductCardKpis = forwardRef(({ rating, feedbackCount, votesCount,
|
|
|
85
89
|
skus,
|
|
86
90
|
skusCap
|
|
87
91
|
]);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
return (_jsx("div", { className: clsx(styles.Kpis, className), style: { ...dynamicStyle, ...style }, ref: forwardedRef, children: isLoading
|
|
93
|
-
? (_jsx(Stack, { hPadding: 24, children: _jsx(Skeleton, { height: "20px", width: "50%", count: kpiItems }) }))
|
|
94
|
-
: (_jsx(Stack, { rowGap: kpisRowGap, hPadding: 24, children: config
|
|
92
|
+
return (_jsx("div", { className: clsx(styles.Kpis, className), style: style, ref: forwardedRef, children: isLoading
|
|
93
|
+
? (_jsx(Stack, { children: _jsx(Skeleton, { height: "20px", width: "50%", count: kpiItems }) }))
|
|
94
|
+
: (_jsx(Stack, { rowGap: kpisRowGap, children: config
|
|
95
95
|
.filter(el => el.value)
|
|
96
|
-
.
|
|
96
|
+
.slice(0, kpiItems)
|
|
97
|
+
.map(el => (_jsx(Text, { className: styles.Kpi, variant: "body-2", decoratorStart: _jsx(Symbol, { source: el.icon, color: el.iconColor, weight: "solid" }), decoratorSize: "medium", children: el.value }, el.property))) })) }));
|
|
97
98
|
});
|
|
98
99
|
ProductCardKpis.displayName = 'ProductCardKpis';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
@layer components{.Kpis{
|
|
1
|
+
@layer components{.Kpis{padding:.5rem 1rem 1rem}.Kpis .Kpi[data-text-decorator=true]{color:var(--dimmed-7);gap:6px}}
|
|
@@ -19,4 +19,18 @@ describe('<ProductCardKpis>', () => {
|
|
|
19
19
|
expect(container).not.toBeNull();
|
|
20
20
|
expect(container.textContent).toContain('R$');
|
|
21
21
|
});
|
|
22
|
+
test('it should format decimals with one digit and counts in compact notation', () => {
|
|
23
|
+
const { container } = render(_jsx(ProductCardKpis, { rating: 4.26, sentiment: 0.54, feedbackCount: 1234, votesCount: 234000, users: 1789, usersCap: 1000, skus: 12, kpiItems: 11 }));
|
|
24
|
+
const text = container.textContent;
|
|
25
|
+
expect(text).toContain('4.3');
|
|
26
|
+
expect(text).toContain('0.5');
|
|
27
|
+
expect(text).toContain('1.2K');
|
|
28
|
+
expect(text).toContain('234K');
|
|
29
|
+
expect(text).toContain('1.8K / 1K');
|
|
30
|
+
expect(text).toContain('12');
|
|
31
|
+
});
|
|
32
|
+
test('it should render at most kpiItems rows', () => {
|
|
33
|
+
const { container } = render(_jsx(ProductCardKpis, { rating: 4, feedbackCount: 10, votesCount: 20, kpiItems: 2 }));
|
|
34
|
+
expect(container.querySelectorAll('p')).toHaveLength(2);
|
|
35
|
+
});
|
|
22
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
@layer components{.Image{background-position:50%;background-repeat:no-repeat;background-size:
|
|
1
|
+
@layer components{.Image{background-position:50%;background-repeat:no-repeat;background-size:cover;border:1px solid var(--dimmed-1)}}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type ProductCardTopBarProps = PropsWithClass<{
|
|
3
|
+
/**
|
|
4
|
+
* Set the name of the marketplace the product comes from.
|
|
5
|
+
*/
|
|
6
|
+
sourceLabel?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Set the logo of the marketplace, displayed in a 16px slot before the label.
|
|
9
|
+
*/
|
|
10
|
+
sourceIcon?: React.ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* Set the loading state showing a skeleton.
|
|
13
|
+
*/
|
|
14
|
+
isLoading?: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
export declare type ProductCardTopBarComponent = React.ForwardRefExoticComponent<ProductCardTopBarProps>;
|
|
17
|
+
export declare const ProductCardTopBar: ProductCardTopBarComponent;
|
|
18
|
+
//# sourceMappingURL=product-card-top-bar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-card-top-bar.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-top-bar/product-card-top-bar.tsx"],"names":[],"mappings":";AAuBA,oBAAY,sBAAsB,GAAG,cAAc,CAAC;IAClD;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,CAAA;AAEF,oBAAY,0BAA0B,GAAG,KAAK,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAC;AAEjG,eAAO,MAAM,iBAAiB,4BA6BE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 Wonderflow Design Team
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import clsx from 'clsx';
|
|
18
|
+
import { forwardRef } from 'react';
|
|
19
|
+
import { Skeleton, Text } from '../../..';
|
|
20
|
+
import * as styles from './product-card-top-bar.module.css';
|
|
21
|
+
export const ProductCardTopBar = forwardRef(({ sourceLabel, sourceIcon, isLoading = false, className, style, ...otherProps }, forwardedRef) => (_jsxs("div", { ref: forwardedRef, className: clsx(styles.TopBar, className), style: style, ...otherProps, children: [_jsxs("div", { className: styles.Dots, "aria-hidden": "true", children: [_jsx("span", { className: styles.Dot }), _jsx("span", { className: styles.Dot }), _jsx("span", { className: styles.Dot })] }), isLoading
|
|
22
|
+
? _jsx(Skeleton, { width: "96px", height: "23px", borderRadius: 8 })
|
|
23
|
+
: (_jsxs("div", { className: styles.Pill, children: [sourceIcon && _jsx("span", { className: styles.Icon, children: sourceIcon }), _jsx(Text, { variant: "body-3", children: sourceLabel })] }))] })));
|
|
24
|
+
ProductCardTopBar.displayName = 'ProductCardTopBar';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@layer components{.TopBar{align-items:center;display:flex;gap:.5rem;padding:.5rem 1rem}.Dots{display:flex;gap:.25rem}.Dot{block-size:10px;border-radius:50%;inline-size:10px;opacity:.2}.Dot:first-child{background-color:var(--dimmed-4)}.Dot:nth-child(2){background-color:var(--dimmed-3)}.Dot:nth-child(3){background-color:var(--dimmed-2)}.Pill{background-color:var(--dimmed-0);block-size:23px;border-radius:6px;display:flex;gap:.25rem;padding:0 .25rem}.Icon,.Pill{align-items:center}.Icon{block-size:16px;display:inline-flex;flex-shrink:0;inline-size:16px;justify-content:center;overflow:hidden}.Icon>*{block-size:100%;inline-size:100%;object-fit:contain}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-card-top-bar.test.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-top-bar/product-card-top-bar.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ProductCardTopBar } from './product-card-top-bar';
|
|
4
|
+
describe('<ProductCardTopBar>', () => {
|
|
5
|
+
test('it should render the label and the icon', () => {
|
|
6
|
+
render(_jsx(ProductCardTopBar, { sourceLabel: "Amazon", sourceIcon: _jsx("img", { alt: "logo", src: "logo.png" }) }));
|
|
7
|
+
expect(screen.getByText('Amazon')).toBeDefined();
|
|
8
|
+
expect(screen.getByAltText('logo')).toBeDefined();
|
|
9
|
+
});
|
|
10
|
+
test('it should hide the label while loading', () => {
|
|
11
|
+
render(_jsx(ProductCardTopBar, { sourceLabel: "Amazon", isLoading: true }));
|
|
12
|
+
expect(screen.queryByText('Amazon')).toBeNull();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -3,13 +3,12 @@ import { ProductCardFooterComponent } from './product-card-footer/product-card-f
|
|
|
3
3
|
import { ProductCardHeaderComponent, ProductCardHeaderProps } from './product-card-header/product-card-header';
|
|
4
4
|
import { ProductCardKpisComponent, ProductCardKpisProps } from './product-card-kpis/product-card-kpis';
|
|
5
5
|
import { ProductCardMediaComponent, ProductCardMediaProps } from './product-card-media/product-card-media';
|
|
6
|
+
import { ProductCardTopBarComponent, ProductCardTopBarProps } from './product-card-top-bar/product-card-top-bar';
|
|
6
7
|
export declare type ProductCardProps = PropsWithClass<PropsWithChildren<{
|
|
7
|
-
/**
|
|
8
|
-
* Change the product card layout.
|
|
9
|
-
*/
|
|
10
|
-
direction?: 'vertical' | 'horizontal';
|
|
11
8
|
/**
|
|
12
9
|
* Add a border to the card to increase its visual weight and contrast.
|
|
10
|
+
*
|
|
11
|
+
* @default true
|
|
13
12
|
*/
|
|
14
13
|
bordered?: boolean;
|
|
15
14
|
/**
|
|
@@ -36,12 +35,27 @@ export declare type ProductCardProps = PropsWithClass<PropsWithChildren<{
|
|
|
36
35
|
* Set an action to be performed when clicked.
|
|
37
36
|
*/
|
|
38
37
|
onClick?: () => void;
|
|
39
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Set the name of the marketplace the product comes from.
|
|
40
|
+
* The top bar is rendered only when this is set.
|
|
41
|
+
*/
|
|
42
|
+
sourceLabel?: ProductCardTopBarProps['sourceLabel'];
|
|
43
|
+
/**
|
|
44
|
+
* Set the logo of the marketplace, displayed before the `sourceLabel`.
|
|
45
|
+
*/
|
|
46
|
+
sourceIcon?: ProductCardTopBarProps['sourceIcon'];
|
|
47
|
+
/**
|
|
48
|
+
* Set a label (e.g. "New") displayed as a badge over the top-right corner of the cover.
|
|
49
|
+
* It is not displayed while loading or when the card has no cover.
|
|
50
|
+
*/
|
|
51
|
+
badge?: string;
|
|
52
|
+
}>> & Pick<ProductCardMediaProps, 'ratio' | 'source'> & Pick<ProductCardHeaderProps, 'title' | 'titleRows' | 'subtitle' | 'description' | 'descriptionRows'> & Pick<ProductCardKpisProps, 'rating' | 'feedbackCount' | 'votesCount' | 'votesRating' | 'users' | 'skus' | 'sentiment' | 'priceMin' | 'priceMax' | 'nps' | 'kpisRowGap' | 'kpiItems' | 'groups' | 'tgw' | 'skusCap' | 'usersCap' | 'currency' | 'currencyDecimals'>;
|
|
40
53
|
export declare type ProductCardComponent = React.ForwardRefExoticComponent<ProductCardProps> & {
|
|
41
54
|
Media: ProductCardMediaComponent;
|
|
42
55
|
Kpis: ProductCardKpisComponent;
|
|
43
56
|
Header: ProductCardHeaderComponent;
|
|
44
57
|
Footer: ProductCardFooterComponent;
|
|
58
|
+
TopBar: ProductCardTopBarComponent;
|
|
45
59
|
};
|
|
46
60
|
export declare const ProductCard: ProductCardComponent;
|
|
47
61
|
//# sourceMappingURL=product-card.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-card.d.ts","sourceRoot":"","sources":["../../../src/components/product-card/product-card.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"product-card.d.ts","sourceRoot":"","sources":["../../../src/components/product-card/product-card.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAc,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAW7D,OAAO,EAAqB,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAC1G,OAAO,EAAqB,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AAClI,OAAO,EAAmB,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AACxH,OAAO,EAAoB,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAC7H,OAAO,EAAqB,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AAEpI,oBAAY,gBAAgB,GAAG,cAAc,CAAC,iBAAiB,CAAC;IAC9D;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACjC;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,sBAAsB,CAAC,aAAa,CAAC,CAAC;IACpD;;OAEG;IACH,UAAU,CAAC,EAAE,sBAAsB,CAAC,YAAY,CAAC,CAAC;IAClD;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC,GACD,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,QAAQ,CAAC,GAC/C,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,WAAW,GAAG,UAAU,GAAG,aAAa,GAAG,iBAAiB,CAAC,GACpG,IAAI,CAAC,oBAAoB,EAAE,QAAQ,GAAG,eAAe,GAAG,YAAY,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAC9O,kBAAkB,CAAC,CAAA;AAuBnB,oBAAY,oBAAoB,GAAG,KAAK,CAAC,yBAAyB,CAAC,gBAAgB,CAAC,GAAG;IACrF,KAAK,EAAE,yBAAyB,CAAC;IACjC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,MAAM,EAAE,0BAA0B,CAAC;IACnC,MAAM,EAAE,0BAA0B,CAAC;IACnC,MAAM,EAAE,0BAA0B,CAAC;CACpC,CAAC;AAEF,eAAO,MAAM,WAAW,sBA8KE,CAAC"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import tkns from '@wonderflow/tokens/platforms/web/tokens.json';
|
|
3
|
-
import { useDebounce } from 'ahooks';
|
|
4
3
|
import clsx from 'clsx';
|
|
5
|
-
import { forwardRef
|
|
6
|
-
import { Elevator, Stack, Text, } from '../..';
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import { Chip, Elevator, Separator, Stack, Text, } from '../..';
|
|
7
6
|
import * as styles from './product-card.module.css';
|
|
8
7
|
import { ProductCardFooter } from './product-card-footer/product-card-footer';
|
|
9
8
|
import { ProductCardHeader } from './product-card-header/product-card-header';
|
|
10
9
|
import { ProductCardKpis } from './product-card-kpis/product-card-kpis';
|
|
11
10
|
import { ProductCardMedia } from './product-card-media/product-card-media';
|
|
11
|
+
import { ProductCardTopBar } from './product-card-top-bar/product-card-top-bar';
|
|
12
12
|
const getColorFromString = (input) => {
|
|
13
13
|
const colorPalette = tkns.color;
|
|
14
14
|
// Generate a hash from the input string
|
|
@@ -26,36 +26,21 @@ const getColorFromString = (input) => {
|
|
|
26
26
|
const firstShade = Object.values(shades)[5];
|
|
27
27
|
return `hsl(${firstShade})`;
|
|
28
28
|
};
|
|
29
|
-
export const ProductCard = forwardRef(({
|
|
30
|
-
const hasOverlay = !!(overlayActions && !
|
|
31
|
-
const hasMenu = !!(menuActions && !overlayActions && !onClick);
|
|
29
|
+
export const ProductCard = forwardRef(({ bordered = true, highlightOnHover = false, title, titleRows = 3, subtitle, description, descriptionRows, rating, feedbackCount, votesCount, votesRating, sentiment, nps, groups, tgw, priceMin, priceMax, currency, currencyDecimals, users, usersCap, skus, skusCap, kpiItems, kpisRowGap, ratio, source, footer, overlayActions, onClick, sourceLabel, sourceIcon, badge, isLoading = false, hasColoredCover = false, className, style, children, ...otherProps }, forwardedRef) => {
|
|
30
|
+
const hasOverlay = !!(overlayActions && !onClick && !isLoading);
|
|
32
31
|
const hasHighlight = !!(onClick ?? highlightOnHover);
|
|
33
32
|
const isClickable = !!(!isLoading && onClick);
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
flexGrow: 0,
|
|
42
|
-
height: 'auto',
|
|
43
|
-
width: '100%',
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return ({
|
|
47
|
-
flexGrow: 0,
|
|
48
|
-
width: `${Math.min(width, height)}px`,
|
|
49
|
-
height: 'auto',
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return ({});
|
|
53
|
-
};
|
|
54
|
-
const deboucedStyle = useDebounce(mediaSizeStyle(direction), { wait: 500 });
|
|
55
|
-
return (_jsx(Elevator, { resting: 1, hover: hasHighlight ? 2 : undefined, children: _jsx(Stack, { ref: forwardedRef, className: clsx(styles.Card, className), style: { ...style }, "data-card-bordered": bordered, "data-card-clickable": isClickable, onClick: isLoading ? undefined : onClick, ...otherProps, children: _jsxs(Stack, { "data-inner-element": "ProductCard-Container", direction: "row", className: styles.Row, fill: false, ref: containerRef, children: [hasOverlay && (_jsx(Stack, { direction: "row", hPadding: 24, vAlign: "center", hAlign: "center", className: styles.OverlayActions, "data-inner-element": "ProductCard-OverlayActions", children: _jsx(Stack, { children: overlayActions }) })), _jsxs(Stack, { "data-inner-element": "ProductCard-Group", direction: (direction === 'vertical') ? 'column' : 'row', className: styles.Content, children: [hasColoredCover && !source?.length && (_jsx(Stack, { className: styles.ColoredCard, style: { backgroundColor: `${getColorFromString(title ?? '')}` }, hAlign: "center", vAlign: "center", fill: false, children: _jsx(Text, { variant: "heading-1", textAlign: "center", style: { color: '#fff' }, children: title?.slice(0, 2) }) })), !hasColoredCover && source && (_jsx(ProductCard.Media, { source: source, isLoading: isLoading, ratio: ratio, "data-inner-element": "ProductCard-Media", style: deboucedStyle })), _jsxs(Stack, { direction: "column", children: [_jsx(ProductCard.Header, { "data-inner-element": "ProductCard-Header", title: title, titleRows: titleRows, subtitle: subtitle, isLoading: isLoading, menuActions: hasMenu && menuActions }), _jsx(ProductCardKpis, { "data-inner-element": "ProductCard-Kpis", rating: rating, feedbackCount: feedbackCount, votesCount: votesCount, votesRating: votesRating, sentiment: sentiment, nps: nps, groups: groups, tgw: tgw, priceMin: priceMin, priceMax: priceMax, currency: currency, currencyDecimals: currencyDecimals, users: users, usersCap: usersCap, skus: skus, skusCap: skusCap, isLoading: isLoading, kpiItems: kpiItems, kpisRowGap: kpisRowGap }), children && !isLoading && (_jsx(Stack, { hPadding: 24, "data-inner-element": "ProductCard-Children", children: children })), _jsx(ProductCard.Footer, { isLoading: isLoading, "data-inner-element": "ProductCard-Footer", children: footer })] })] })] }) }) }));
|
|
33
|
+
const hasTopBar = !!sourceLabel;
|
|
34
|
+
const hasColoredCard = hasColoredCover && !source?.length;
|
|
35
|
+
const hasMedia = !hasColoredCover && !!source?.length;
|
|
36
|
+
const hasCover = hasColoredCard || hasMedia;
|
|
37
|
+
const hasKpis = kpiItems !== 0;
|
|
38
|
+
const hasFooterSeparator = !!footer || isLoading;
|
|
39
|
+
return (_jsx(Elevator, { resting: 1, hover: hasHighlight ? 2 : undefined, children: _jsxs(Stack, { ref: forwardedRef, className: clsx(styles.Card, className), style: { ...style }, fill: false, "data-card-bordered": bordered, "data-card-clickable": isClickable, onClick: isLoading ? undefined : onClick, ...otherProps, children: [hasOverlay && (_jsx(Stack, { direction: "row", hPadding: 24, vAlign: "center", hAlign: "center", className: styles.OverlayActions, "data-inner-element": "ProductCard-OverlayActions", children: _jsx(Stack, { children: overlayActions }) })), hasTopBar && (_jsxs(_Fragment, { children: [_jsx(ProductCard.TopBar, { "data-inner-element": "ProductCard-TopBar", sourceLabel: sourceLabel, sourceIcon: sourceIcon, isLoading: isLoading }), _jsx(Separator, {})] })), hasCover && (_jsxs("div", { className: styles.Cover, children: [hasColoredCard && (_jsx(Stack, { className: styles.ColoredCard, style: { backgroundColor: `${getColorFromString(title ?? '')}` }, hAlign: "center", vAlign: "center", fill: false, children: _jsx(Text, { variant: "heading-1", textAlign: "center", style: { color: '#fff' }, children: title?.slice(0, 2) }) })), hasMedia && (_jsx(ProductCard.Media, { source: source, isLoading: isLoading, ratio: ratio, "data-inner-element": "ProductCard-Media" })), badge && !isLoading && (_jsx(Chip, { color: "yellow", className: styles.Badge, "data-inner-element": "ProductCard-Badge", children: badge }))] })), _jsx(ProductCard.Header, { "data-inner-element": "ProductCard-Header", title: title, titleRows: titleRows, subtitle: subtitle, description: description, descriptionRows: descriptionRows, isLoading: isLoading }), hasKpis && (_jsx(ProductCardKpis, { "data-inner-element": "ProductCard-Kpis", rating: rating, feedbackCount: feedbackCount, votesCount: votesCount, votesRating: votesRating, sentiment: sentiment, nps: nps, groups: groups, tgw: tgw, priceMin: priceMin, priceMax: priceMax, currency: currency, currencyDecimals: currencyDecimals, users: users, usersCap: usersCap, skus: skus, skusCap: skusCap, isLoading: isLoading, kpiItems: kpiItems, kpisRowGap: kpisRowGap })), children && !isLoading && (_jsx(Stack, { hPadding: 16, "data-inner-element": "ProductCard-Children", children: children })), _jsxs("div", { className: styles.Bottom, children: [hasFooterSeparator && _jsx(Separator, {}), _jsx(ProductCard.Footer, { isLoading: isLoading, "data-inner-element": "ProductCard-Footer", children: footer })] })] }) }));
|
|
56
40
|
});
|
|
57
41
|
ProductCard.displayName = 'ProductCard';
|
|
58
42
|
ProductCard.Media = ProductCardMedia;
|
|
59
43
|
ProductCard.Header = ProductCardHeader;
|
|
60
44
|
ProductCard.Kpis = ProductCardKpis;
|
|
61
45
|
ProductCard.Footer = ProductCardFooter;
|
|
46
|
+
ProductCard.TopBar = ProductCardTopBar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
@layer components{.Card{background-color:var(--global-background);border-radius
|
|
1
|
+
@layer components{.Card{background-color:var(--global-background);border-radius:12px;overflow:hidden;padding:0;position:relative}.Card[data-card-bordered=true]{border:1px solid var(--dimmed-1)}.Card[data-card-clickable=true]{cursor:pointer}.Cover{position:relative}.Badge{position:absolute;right:1rem;top:10px}.Bottom{margin-top:auto}.OverlayActions{background-color:var(--global-background);height:100%;opacity:0;position:absolute;transition:opacity .3s;width:100%;z-index:1}.OverlayActions:hover{opacity:1}.ColoredCard{height:125px;max-height:125px;width:100%}}
|
|
@@ -3,12 +3,15 @@ import { ProductCard } from './product-card';
|
|
|
3
3
|
declare const story: ComponentMeta<typeof ProductCard>;
|
|
4
4
|
export default story;
|
|
5
5
|
export declare const Default: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
6
|
+
export declare const withoutTopBar: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
7
|
+
export declare const withSourceLabelOnly: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
8
|
+
export declare const loading: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
6
9
|
export declare const withFewKpis: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
7
10
|
export declare const withOverlayActions: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
8
|
-
export declare const withMenuActions: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
9
11
|
export declare const clickable: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
10
12
|
export declare const withMultipleProducts: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
11
13
|
export declare const withBrokenImage: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
12
14
|
export declare const withNoMedia: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
15
|
+
export declare const withDescription: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
13
16
|
export declare const withColoredCover: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
14
17
|
//# sourceMappingURL=product-card.stories.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-card.stories.d.ts","sourceRoot":"","sources":["../../../src/components/product-card/product-card.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"product-card.stories.d.ts","sourceRoot":"","sources":["../../../src/components/product-card/product-card.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAmB7C,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,WAAW,CAqD5C,CAAC;AAEF,eAAe,KAAK,CAAC;AAMrB,eAAO,MAAM,OAAO,+DAAoB,CAAC;AAGzC,eAAO,MAAM,aAAa,+DAAoB,CAAC;AAO/C,eAAO,MAAM,mBAAmB,+DAAoB,CAAC;AAMrD,eAAO,MAAM,OAAO,+DAAoB,CAAC;AAKzC,eAAO,MAAM,WAAW,+DAAoB,CAAC;AAkB7C,eAAO,MAAM,kBAAkB,+DAAoB,CAAC;AAKpD,eAAO,MAAM,SAAS,+DAAoB,CAAC;AAK3C,eAAO,MAAM,oBAAoB,+DAAoB,CAAC;AAKtD,eAAO,MAAM,eAAe,+DAAoB,CAAC;AAKjD,eAAO,MAAM,WAAW,+DAAoB,CAAC;AAwB7C,eAAO,MAAM,eAAe,+DAAoB,CAAC;AAcjD,eAAO,MAAM,gBAAgB,+DAAoB,CAAC"}
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button,
|
|
2
|
+
import { Button, Stack, Text, } from '../..';
|
|
3
3
|
import { ProductCard } from './product-card';
|
|
4
4
|
const OverlayButtons = (_jsxs(Stack, { rowGap: 16, children: [_jsx(Button, { children: "Stats" }), _jsx(Button, { kind: "secondary", children: "Compare" }), _jsx(Button, { kind: "secondary", children: "Add to group" })] }));
|
|
5
|
-
const MenuItems = (_jsxs(Menu, { children: [_jsx(Menu.Item, { autoFocus: true, icon: "news", value: "1", children: "Stats" }), _jsx(Menu.Item, { icon: "theater", value: "1", children: "Compare" }), _jsx(Menu.Item, { icon: "grid", value: "1", placement: "right-start", description: "add product to group", children: "Add to group" })] }));
|
|
6
5
|
const SourceImages = [
|
|
7
6
|
'https://products.gumlet.io/image-1675779605803.jpeg',
|
|
8
7
|
'https://storage.googleapis.com/wonderflow-product-images/KITCHENAID%205KSM15%20SERIES.png',
|
|
9
8
|
'https://storage.googleapis.com/wonderflow-product-images/CLASSIC%204.5%20QT.png',
|
|
10
9
|
// 'https://storage.googleapis.com/wonderflow-product-images/delonghi_coffee_MC%20NESPRESSO%20INISSIA.png',
|
|
11
10
|
];
|
|
11
|
+
const SourceLogo = _jsx("img", { src: "/amazon-logo.png", alt: "Amazon" });
|
|
12
12
|
const story = {
|
|
13
13
|
title: 'Domain Components/Product Card',
|
|
14
14
|
component: ProductCard,
|
|
15
15
|
args: {
|
|
16
|
-
|
|
17
|
-
bordered: false,
|
|
16
|
+
bordered: true,
|
|
18
17
|
highlightOnHover: false,
|
|
19
18
|
title: 'Product Card Title',
|
|
20
19
|
titleRows: 3,
|
|
21
20
|
subtitle: 'subtitle',
|
|
21
|
+
sourceLabel: 'Amazon',
|
|
22
|
+
sourceIcon: SourceLogo,
|
|
23
|
+
badge: 'New',
|
|
22
24
|
rating: 4.3,
|
|
23
25
|
nps: 23,
|
|
24
26
|
feedbackCount: 123,
|
|
@@ -40,17 +42,12 @@ const story = {
|
|
|
40
42
|
isLoading: false,
|
|
41
43
|
ratio: '1',
|
|
42
44
|
overlayActions: undefined,
|
|
43
|
-
menuActions: undefined,
|
|
44
45
|
onClick: undefined,
|
|
45
46
|
children: undefined,
|
|
46
47
|
source: SourceImages.slice(0, 1),
|
|
47
|
-
footer: (_jsx(Text, { variant: "body-
|
|
48
|
+
footer: (_jsx(Text, { variant: "body-3", children: "Apr 2023" })),
|
|
48
49
|
},
|
|
49
50
|
argTypes: {
|
|
50
|
-
direction: {
|
|
51
|
-
options: ['vertical', 'horizontal'],
|
|
52
|
-
control: { type: 'select' },
|
|
53
|
-
},
|
|
54
51
|
currency: {
|
|
55
52
|
options: ['EUR', 'USD', 'GBP', 'JPY', 'CNY'],
|
|
56
53
|
control: { type: 'select' },
|
|
@@ -67,12 +64,24 @@ const story = {
|
|
|
67
64
|
},
|
|
68
65
|
};
|
|
69
66
|
export default story;
|
|
70
|
-
const Template =
|
|
71
|
-
const { direction } = args;
|
|
72
|
-
return (_jsx("div", { style: { maxWidth: direction === 'vertical' ? '250px' : '650px' }, children: _jsx(ProductCard, { ...args }) }));
|
|
73
|
-
};
|
|
67
|
+
const Template = args => (_jsx("div", { style: { width: '272px' }, children: _jsx(ProductCard, { ...args }) }));
|
|
74
68
|
export const Default = Template.bind({});
|
|
75
69
|
Default.args = {};
|
|
70
|
+
export const withoutTopBar = Template.bind({});
|
|
71
|
+
withoutTopBar.args = {
|
|
72
|
+
sourceLabel: undefined,
|
|
73
|
+
sourceIcon: undefined,
|
|
74
|
+
badge: undefined,
|
|
75
|
+
};
|
|
76
|
+
export const withSourceLabelOnly = Template.bind({});
|
|
77
|
+
withSourceLabelOnly.args = {
|
|
78
|
+
sourceIcon: undefined,
|
|
79
|
+
badge: undefined,
|
|
80
|
+
};
|
|
81
|
+
export const loading = Template.bind({});
|
|
82
|
+
loading.args = {
|
|
83
|
+
isLoading: true,
|
|
84
|
+
};
|
|
76
85
|
export const withFewKpis = Template.bind({});
|
|
77
86
|
withFewKpis.args = {
|
|
78
87
|
rating: 4.3,
|
|
@@ -94,10 +103,6 @@ export const withOverlayActions = Template.bind({});
|
|
|
94
103
|
withOverlayActions.args = {
|
|
95
104
|
overlayActions: OverlayButtons,
|
|
96
105
|
};
|
|
97
|
-
export const withMenuActions = Template.bind({});
|
|
98
|
-
withMenuActions.args = {
|
|
99
|
-
menuActions: MenuItems,
|
|
100
|
-
};
|
|
101
106
|
export const clickable = Template.bind({});
|
|
102
107
|
clickable.args = {
|
|
103
108
|
onClick: () => console.log('pressed'),
|
|
@@ -133,8 +138,22 @@ withNoMedia.args = {
|
|
|
133
138
|
skusCap: 1000,
|
|
134
139
|
footer: undefined,
|
|
135
140
|
};
|
|
141
|
+
export const withDescription = Template.bind({});
|
|
142
|
+
withDescription.args = {
|
|
143
|
+
sourceLabel: undefined,
|
|
144
|
+
sourceIcon: undefined,
|
|
145
|
+
badge: undefined,
|
|
146
|
+
subtitle: '',
|
|
147
|
+
title: 'Domestic Appliances and Tools',
|
|
148
|
+
titleRows: 2,
|
|
149
|
+
description: 'Appliances and tools for everyday cooking, cleaning, and home maintenance.',
|
|
150
|
+
descriptionRows: 3,
|
|
151
|
+
kpiItems: 0,
|
|
152
|
+
footer: undefined,
|
|
153
|
+
};
|
|
136
154
|
export const withColoredCover = Template.bind({});
|
|
137
155
|
withColoredCover.args = {
|
|
156
|
+
badge: 'New',
|
|
138
157
|
source: [],
|
|
139
158
|
subtitle: '',
|
|
140
159
|
title: 'My first board',
|
|
@@ -13,32 +13,71 @@ describe('<ProductCard>', () => {
|
|
|
13
13
|
expect(container).not.toBeNull();
|
|
14
14
|
});
|
|
15
15
|
test('it should render properly with props', () => {
|
|
16
|
-
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: SourceImages,
|
|
17
|
-
expect(container).not.toBeNull();
|
|
18
|
-
});
|
|
19
|
-
test('it should render properly with menu actions', () => {
|
|
20
|
-
const s = SourceImages.slice(0, 3);
|
|
21
|
-
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: s, direction: "horizontal", rating: 1.2, feedbackCount: 1.2, votesCount: 1.2, menuActions: _jsx("div", { children: "some content" }) }));
|
|
16
|
+
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: SourceImages, rating: 1.2, feedbackCount: 1.2, votesCount: 1.2, votesRating: 1.2, sentiment: 1.2, nps: 1.2, groups: 1.2, priceMin: 1.2, priceMax: 1.2, users: 1.2, skus: 1.2, kpiItems: 2, kpisRowGap: 16, bordered: true, highlightOnHover: true, ratio: "1/1" }));
|
|
22
17
|
expect(container).not.toBeNull();
|
|
23
18
|
});
|
|
24
19
|
test('it should render properly with overlay actions', () => {
|
|
25
|
-
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: SourceImages,
|
|
20
|
+
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: SourceImages, rating: 1.2, feedbackCount: 1.2, votesCount: 1.2, overlayActions: _jsx("div", { children: "some content" }) }));
|
|
26
21
|
expect(container).not.toBeNull();
|
|
27
22
|
});
|
|
28
23
|
test('it should render properly with on click', () => {
|
|
29
24
|
const spyOnClick = jest.fn();
|
|
30
|
-
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: SourceImages,
|
|
25
|
+
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: SourceImages, rating: 1.2, feedbackCount: 1.2, votesCount: 1.2, onClick: spyOnClick }));
|
|
31
26
|
expect(container).not.toBeNull();
|
|
32
27
|
});
|
|
33
28
|
test('it should render properly with children', () => {
|
|
34
29
|
const spyOnClick = jest.fn();
|
|
35
|
-
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: SourceImages,
|
|
30
|
+
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: SourceImages, rating: 1.2, feedbackCount: 1.2, votesCount: 1.2, onClick: spyOnClick, footer: _jsx("div", { children: "some content" }), children: _jsx("div", { children: "some content" }) }));
|
|
36
31
|
expect(container).not.toBeNull();
|
|
37
32
|
});
|
|
38
33
|
test('it should render properly with colored cover', () => {
|
|
39
|
-
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle",
|
|
34
|
+
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", rating: 1.2, feedbackCount: 1.2, votesCount: 1.2, votesRating: 1.2, sentiment: 1.2, nps: 1.2, groups: 1.2, priceMin: 1.2, priceMax: 1.2, users: 1.2, skus: 1.2, kpiItems: 2, kpisRowGap: 16, bordered: true, highlightOnHover: true, hasColoredCover: true }));
|
|
40
35
|
expect(container).not.toBeNull();
|
|
41
36
|
const coverText = screen.getByText('ti');
|
|
42
37
|
expect(coverText).toBeDefined();
|
|
43
38
|
});
|
|
39
|
+
test('it should render the top bar only when sourceLabel is set', () => {
|
|
40
|
+
const { container, rerender } = render(_jsx(ProductCard, { title: "title" }));
|
|
41
|
+
expect(container.querySelector('[data-inner-element="ProductCard-TopBar"]')).toBeNull();
|
|
42
|
+
rerender(_jsx(ProductCard, { title: "title", sourceLabel: "Amazon", sourceIcon: _jsx("img", { alt: "logo", src: "logo.png" }) }));
|
|
43
|
+
expect(container.querySelector('[data-inner-element="ProductCard-TopBar"]')).not.toBeNull();
|
|
44
|
+
expect(screen.getByText('Amazon')).toBeDefined();
|
|
45
|
+
expect(screen.getByAltText('logo')).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
test('it should render the badge only over a cover and not while loading', () => {
|
|
48
|
+
const { container, rerender } = render(_jsx(ProductCard, { title: "title", source: SourceImages, badge: "New" }));
|
|
49
|
+
const badge = () => container.querySelector('[data-inner-element="ProductCard-Badge"]');
|
|
50
|
+
expect(badge()).not.toBeNull();
|
|
51
|
+
expect(screen.getByText('New')).toBeDefined();
|
|
52
|
+
rerender(_jsx(ProductCard, { title: "title", hasColoredCover: true, badge: "New" }));
|
|
53
|
+
expect(badge()).not.toBeNull();
|
|
54
|
+
rerender(_jsx(ProductCard, { title: "title", source: SourceImages, badge: "New", isLoading: true }));
|
|
55
|
+
expect(badge()).toBeNull();
|
|
56
|
+
rerender(_jsx(ProductCard, { title: "title", badge: "New" }));
|
|
57
|
+
expect(badge()).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
test('it should render the footer separator only with a footer or while loading', () => {
|
|
60
|
+
const { container, rerender } = render(_jsx(ProductCard, { title: "title" }));
|
|
61
|
+
expect(container.querySelectorAll('hr')).toHaveLength(0);
|
|
62
|
+
rerender(_jsx(ProductCard, { title: "title", footer: "Apr 2023" }));
|
|
63
|
+
expect(container.querySelectorAll('hr')).toHaveLength(1);
|
|
64
|
+
rerender(_jsx(ProductCard, { title: "title", isLoading: true }));
|
|
65
|
+
expect(container.querySelectorAll('hr')).toHaveLength(1);
|
|
66
|
+
rerender(_jsx(ProductCard, { title: "title", sourceLabel: "Amazon", footer: "Apr 2023" }));
|
|
67
|
+
expect(container.querySelectorAll('hr')).toHaveLength(2);
|
|
68
|
+
});
|
|
69
|
+
test('it should render the description and hide the KPIs block when kpiItems is 0', () => {
|
|
70
|
+
const { rerender } = render(_jsx(ProductCard, { title: "title", rating: 4.3 }));
|
|
71
|
+
expect(screen.queryByText('A description')).toBeNull();
|
|
72
|
+
expect(screen.getByText('4.3')).toBeDefined();
|
|
73
|
+
rerender(_jsx(ProductCard, { title: "title", description: "A description", rating: 4.3, kpiItems: 0 }));
|
|
74
|
+
expect(screen.getByText('A description')).toBeDefined();
|
|
75
|
+
expect(screen.queryByText('4.3')).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
test('it should be bordered by default', () => {
|
|
78
|
+
const { container, rerender } = render(_jsx(ProductCard, { title: "title" }));
|
|
79
|
+
expect(container.querySelector('[data-card-bordered="true"]')).not.toBeNull();
|
|
80
|
+
rerender(_jsx(ProductCard, { title: "title", bordered: false }));
|
|
81
|
+
expect(container.querySelector('[data-card-bordered="false"]')).not.toBeNull();
|
|
82
|
+
});
|
|
44
83
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-tanstack-columns.d.ts","sourceRoot":"","sources":["../../../src/components/table/to-tanstack-columns.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,EACL,iBAAiB,EAClB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"to-tanstack-columns.d.ts","sourceRoot":"","sources":["../../../src/components/table/to-tanstack-columns.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,EACL,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAiEjB,eAAO,MAAM,iBAAiB,+FAE2C,CAAC"}
|
|
@@ -33,7 +33,9 @@ const toTanStackColumn = (column) => {
|
|
|
33
33
|
: Header);
|
|
34
34
|
const cell = Cell
|
|
35
35
|
? ctx => Cell({ row: ctx.row, value: ctx.getValue() })
|
|
36
|
-
|
|
36
|
+
// `flexRender` mounts function cells as React components, and React 17
|
|
37
|
+
// throws if a component returns `undefined` (e.g. accessor on a missing key).
|
|
38
|
+
: ctx => (ctx.getValue() ?? null);
|
|
37
39
|
const shared = {
|
|
38
40
|
id,
|
|
39
41
|
header,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell.stories.d.ts","sourceRoot":"","sources":["../../src/examples/shell.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQjE,OAAO,EAEL,SAAS,EAOV,MAAM,cAAc,CAAC;AAItB,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,SAAS,CAG1C,CAAC;AAEF,eAAe,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"shell.stories.d.ts","sourceRoot":"","sources":["../../src/examples/shell.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQjE,OAAO,EAEL,SAAS,EAOV,MAAM,cAAc,CAAC;AAItB,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,SAAS,CAG1C,CAAC;AAEF,eAAe,KAAK,CAAC;AA0JrB,eAAO,MAAM,KAAK,kHAAoB,CAAC"}
|
|
@@ -35,6 +35,6 @@ const Template = () => {
|
|
|
35
35
|
}, [isBrowser]);
|
|
36
36
|
return (_jsx(Container, { dimension: "full", padding: false, className: style.MainContainer, children: _jsxs(Stack, { direction: "row", children: [_jsxs(Stack, { id: "LeftMenu", rowGap: 16, className: style.LeftMenu, "data-is-open": isLeftOpen, children: [_jsx("div", { className: style.LeftMenuInner, "data-is-open": isLeftOpen }), isLeftOpen
|
|
37
37
|
? (_jsx("div", { children: linkIcons.map((e, i) => (_jsx(Menu.Item, { disabled: true, value: `${e}`, icon: linkIcons[i], children: e }, seed(`linkMenu${i}`)))) }))
|
|
38
|
-
: (_jsx(Stack, { inline: true, hAlign: "center", rowGap: 8, children: linkIcons.map((e, i) => (_jsx(IconButton, { disabled: true, icon: linkIcons[i], kind: "flat" }, `${e} ${seed(`icons${i}`)}`))) }))] }), _jsxs(Stack, { children: [_jsxs(Stack, { id: "MainMenu", direction: "row", vAlign: "center", hAlign: "space-between", columnGap: 16, className: style.MainMenu, children: [_jsx(Stack, { inline: true, children: _jsx(Button, { kind: "secondary", dimension: "regular", fullWidth: false, onClick: () => setIsLeftOpen(!isLeftOpen), children: "Menu" }) }), _jsx(Stack, { inline: true, children: _jsx(Button, { kind: "secondary", dimension: "regular", fullWidth: false, onClick: () => setIsRightOpen(!isRightOpen), children: "Filters" }) })] }), _jsx(Container, { ref: ref, dimension: containerValue.dimension, className: clsx(style.Container, 'ContainerEx'), children: _jsxs(Stack, { rowGap: 32, vPadding: 32, children: [_jsxs(Snackbar, { title: "Product Card Container", children: [_jsx(Text, { as: "span", variant: "body-2", children: `Window Width: ${size}px - Breakpoints Match: ${matches.toUpperCase()}` }), _jsx(Text, { as: "span", variant: "body-2", children: `Container Width: ${containerSize}px - Grid Columns: ${containerValue.col} - Grid Gutter: ${containerValue.gutter}px` }), _jsx(Text, { as: "span", variant: "body-2", children: `useBreakpointsConfig.value: ${JSON.stringify(containerValue)} - useBreakpointsConfig.matches: ${containerMatches.toUpperCase()}` })] }), _jsx(Grid, { colMinWidth: "1rem", columns: containerValue.col, rowGap: containerValue.gutter, columnGap: containerValue.gutter, filling: false, children: Array(12).fill('Card').map((e, i) => (_jsx(Grid.Item, { children: _jsx(ProductCard, { source: ['https://storage.googleapis.com/wonderflow-product-images/KITCHENAID%20CLASSIC%20SERIES.png'], subtitle: "brand name", title: `Product-${e} ${i + 1}`, sentiment: 0.51, rating: 4.51, feedbackCount: 3251, footer: "01 Aug 2023",
|
|
38
|
+
: (_jsx(Stack, { inline: true, hAlign: "center", rowGap: 8, children: linkIcons.map((e, i) => (_jsx(IconButton, { disabled: true, icon: linkIcons[i], kind: "flat" }, `${e} ${seed(`icons${i}`)}`))) }))] }), _jsxs(Stack, { children: [_jsxs(Stack, { id: "MainMenu", direction: "row", vAlign: "center", hAlign: "space-between", columnGap: 16, className: style.MainMenu, children: [_jsx(Stack, { inline: true, children: _jsx(Button, { kind: "secondary", dimension: "regular", fullWidth: false, onClick: () => setIsLeftOpen(!isLeftOpen), children: "Menu" }) }), _jsx(Stack, { inline: true, children: _jsx(Button, { kind: "secondary", dimension: "regular", fullWidth: false, onClick: () => setIsRightOpen(!isRightOpen), children: "Filters" }) })] }), _jsx(Container, { ref: ref, dimension: containerValue.dimension, className: clsx(style.Container, 'ContainerEx'), children: _jsxs(Stack, { rowGap: 32, vPadding: 32, children: [_jsxs(Snackbar, { title: "Product Card Container", children: [_jsx(Text, { as: "span", variant: "body-2", children: `Window Width: ${size}px - Breakpoints Match: ${matches.toUpperCase()}` }), _jsx(Text, { as: "span", variant: "body-2", children: `Container Width: ${containerSize}px - Grid Columns: ${containerValue.col} - Grid Gutter: ${containerValue.gutter}px` }), _jsx(Text, { as: "span", variant: "body-2", children: `useBreakpointsConfig.value: ${JSON.stringify(containerValue)} - useBreakpointsConfig.matches: ${containerMatches.toUpperCase()}` })] }), _jsx(Grid, { colMinWidth: "1rem", columns: containerValue.col, rowGap: containerValue.gutter, columnGap: containerValue.gutter, filling: false, children: Array(12).fill('Card').map((e, i) => (_jsx(Grid.Item, { children: _jsx(ProductCard, { source: ['https://storage.googleapis.com/wonderflow-product-images/KITCHENAID%20CLASSIC%20SERIES.png'], subtitle: "brand name", title: `Product-${e} ${i + 1}`, sentiment: 0.51, rating: 4.51, feedbackCount: 3251, footer: "01 Aug 2023", highlightOnHover: true }) }, seed(`cards${i}`)))) })] }) })] }), _jsxs(Stack, { id: "RightMenu", className: style.RightMenu, "data-is-open": isRightOpen, children: [_jsx("div", { className: style.RightMenuInner }), _jsx("div", { className: style.Filter, children: Array(10).fill('Filter').map((e, i) => (_jsxs(Disclosure, { summary: `${e} ${String.fromCharCode(i + 65)}`, children: [_jsx(Menu.Item, { value: "1", subtext: "Hint Text", children: "Menu Item 1" }), _jsx(Menu.Item, { value: "2", subtext: "Hint Text", children: "Menu Item 2" }), _jsx(Menu.Item, { value: "3", subtext: "Hint Text", children: "Menu Item 3" }), _jsx(Menu.Item, { value: "4", subtext: "Hint Text", children: "Menu Item 4" })] }, seed(`filters${i}`)))) })] })] }) }));
|
|
39
39
|
};
|
|
40
40
|
export const Shell = Template.bind({});
|
|
@@ -10,6 +10,10 @@ export declare const formatKpiValue: (value?: number, option?: {
|
|
|
10
10
|
minRange?: number;
|
|
11
11
|
maxRange?: number;
|
|
12
12
|
cap?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Use the compact notation (e.g. `1.2K`). When `true`, `decimal` is ignored.
|
|
15
|
+
*/
|
|
16
|
+
compact?: boolean;
|
|
13
17
|
}) => string;
|
|
14
18
|
export declare const isValueOverCap: (value?: number, cap?: number) => boolean;
|
|
15
19
|
export declare const isGreaterThan: (threashold: number, value?: number) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/utils/formatting.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,QAAQ,EAAE,MAAM,gEAAgE,CAAC;AAE1F,eAAO,MAAM,WAAW,cAAe,QAAQ,wHAuC9C,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAC5B,MAAM,OACN,MAAM,WACH;IACN,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,uBAkBF,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,MAAM,aAAa,MAAM,aAAa,MAAM,WAU7E,CAAC;
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/utils/formatting.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,QAAQ,EAAE,MAAM,gEAAgE,CAAC;AAE1F,eAAO,MAAM,WAAW,cAAe,QAAQ,wHAuC9C,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAC5B,MAAM,OACN,MAAM,WACH;IACN,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,uBAkBF,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,MAAM,aAAa,MAAM,aAAa,MAAM,WAU7E,CAAC;AAIF,eAAO,MAAM,cAAc,WACjB,MAAM,WACN;IACN,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,WAuBF,CAAC;AAEF,eAAO,MAAM,cAAc,WAAY,MAAM,QAAQ,MAAM,YAAuF,CAAC;AAEnJ,eAAO,MAAM,aAAa,eAAgB,MAAM,UAAU,MAAM,YAAsD,CAAC"}
|
package/dist/utils/formatting.js
CHANGED
|
@@ -83,14 +83,17 @@ export const clampValue = (value, minRange, maxRange) => {
|
|
|
83
83
|
return newMax;
|
|
84
84
|
return value;
|
|
85
85
|
};
|
|
86
|
+
const compactFormatter = new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1 });
|
|
86
87
|
export const formatKpiValue = (value, option = { decimal: 0, minRange: 0 }) => {
|
|
87
88
|
const { decimal, minRange, maxRange, cap, } = option;
|
|
89
|
+
const isCompact = option.compact ?? false;
|
|
88
90
|
const hasValue = typeof value === 'number';
|
|
89
91
|
const d = typeof decimal === 'number' && decimal > 0 ? decimal : 0;
|
|
90
92
|
if (hasValue) {
|
|
91
|
-
const
|
|
93
|
+
const format = (n) => (isCompact ? compactFormatter.format(n) : n.toFixed(d));
|
|
94
|
+
const res = format(clampValue(value, minRange, maxRange));
|
|
92
95
|
if (typeof cap === 'number' && cap > 0) {
|
|
93
|
-
const c = clampValue(cap, minRange, maxRange)
|
|
96
|
+
const c = format(clampValue(cap, minRange, maxRange));
|
|
94
97
|
return `${res} / ${c}`;
|
|
95
98
|
}
|
|
96
99
|
return res;
|
|
@@ -92,6 +92,14 @@ describe('formatKpiValue()', () => {
|
|
|
92
92
|
const res = formatKpiValue(10, { decimal: 0, cap: 100 });
|
|
93
93
|
expect(res).toBe('10 / 100');
|
|
94
94
|
});
|
|
95
|
+
it('should return the compact format for value and cap', () => {
|
|
96
|
+
expect(formatKpiValue(999, { decimal: 0, compact: true })).toBe('999');
|
|
97
|
+
expect(formatKpiValue(1234, { decimal: 0, compact: true })).toBe('1.2K');
|
|
98
|
+
expect(formatKpiValue(234000, { decimal: 0, compact: true })).toBe('234K');
|
|
99
|
+
expect(formatKpiValue(1789, { decimal: 0, compact: true, cap: 1000 })).toBe('1.8K / 1K');
|
|
100
|
+
expect(formatKpiValue(-5, { decimal: 0, compact: true, minRange: 0 })).toBe('0');
|
|
101
|
+
expect(formatKpiValue(undefined, { decimal: 0, compact: true })).toBe('');
|
|
102
|
+
});
|
|
95
103
|
});
|
|
96
104
|
describe('isValueOverCap()', () => {
|
|
97
105
|
it('should return true when value > cap', () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wonderflow/react-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"description": "UI components from Wonderflow's Wanda design system",
|
|
5
5
|
"author": "Wonderflow",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -81,9 +81,9 @@
|
|
|
81
81
|
"@types/react": "17.0.43",
|
|
82
82
|
"@types/react-dom": "17.0.14",
|
|
83
83
|
"@types/react-test-renderer": "18.0.7",
|
|
84
|
-
"@wonderflow/config": "
|
|
85
|
-
"@wonderflow/tokens": "
|
|
86
|
-
"@wonderflow/charts": "
|
|
84
|
+
"@wonderflow/config": "17.0.0",
|
|
85
|
+
"@wonderflow/tokens": "17.0.0",
|
|
86
|
+
"@wonderflow/charts": "17.0.0",
|
|
87
87
|
"@types/uuid": "9.0.8",
|
|
88
88
|
"babel-loader": "8.2.5",
|
|
89
89
|
"cpy-cli": "3.1.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer components{.Subtitle{text-transform:uppercase}.Title{height:var(--header-title-height)}.Description{height:var(--header-descriotion-height)}}
|