@wonderflow/react-components 16.1.0 → 17.1.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 +21 -10
- package/dist/components/product-card/product-card.d.ts.map +1 -1
- package/dist/components/product-card/product-card.js +16 -29
- package/dist/components/product-card/product-card.module.css +1 -1
- package/dist/components/product-card/product-card.stories.d.ts +11 -8
- package/dist/components/product-card/product-card.stories.d.ts.map +1 -1
- package/dist/components/product-card/product-card.stories.js +80 -79
- package/dist/components/product-card/product-card.test.js +71 -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
|
/**
|
|
@@ -17,7 +16,8 @@ export declare type ProductCardProps = PropsWithClass<PropsWithChildren<{
|
|
|
17
16
|
*/
|
|
18
17
|
highlightOnHover?: boolean;
|
|
19
18
|
/**
|
|
20
|
-
* Set the content to be displayed
|
|
19
|
+
* Set the content to be displayed over the cover (image or colored cover) on hover.
|
|
20
|
+
* Ignored when the card is clickable or loading.
|
|
21
21
|
*/
|
|
22
22
|
overlayActions?: React.ReactNode;
|
|
23
23
|
/**
|
|
@@ -28,20 +28,31 @@ export declare type ProductCardProps = PropsWithClass<PropsWithChildren<{
|
|
|
28
28
|
* Set the loading state showing a skeleton.
|
|
29
29
|
*/
|
|
30
30
|
isLoading?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Shows a colored cover with the first two letters of the title.
|
|
33
|
-
*/
|
|
34
|
-
hasColoredCover?: boolean;
|
|
35
31
|
/**
|
|
36
32
|
* Set an action to be performed when clicked.
|
|
37
33
|
*/
|
|
38
34
|
onClick?: () => void;
|
|
39
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Set the name of the marketplace the product comes from.
|
|
37
|
+
* The top bar is rendered only when this is set.
|
|
38
|
+
*/
|
|
39
|
+
sourceLabel?: ProductCardTopBarProps['sourceLabel'];
|
|
40
|
+
/**
|
|
41
|
+
* Set the logo of the marketplace, displayed before the `sourceLabel`.
|
|
42
|
+
*/
|
|
43
|
+
sourceIcon?: ProductCardTopBarProps['sourceIcon'];
|
|
44
|
+
/**
|
|
45
|
+
* Set a label (e.g. "New") displayed as a badge over the top-right corner of the cover.
|
|
46
|
+
* It is not displayed while loading.
|
|
47
|
+
*/
|
|
48
|
+
badge?: string;
|
|
49
|
+
}>> & 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
50
|
export declare type ProductCardComponent = React.ForwardRefExoticComponent<ProductCardProps> & {
|
|
41
51
|
Media: ProductCardMediaComponent;
|
|
42
52
|
Kpis: ProductCardKpisComponent;
|
|
43
53
|
Header: ProductCardHeaderComponent;
|
|
44
54
|
Footer: ProductCardFooterComponent;
|
|
55
|
+
TopBar: ProductCardTopBarComponent;
|
|
45
56
|
};
|
|
46
57
|
export declare const ProductCard: ProductCardComponent;
|
|
47
58
|
//# 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;AAa7D,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;;;OAGG;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,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,sBAsLE,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 { AspectRatio, Chip, Elevator, Separator, Skeleton, 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,23 @@ 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, 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
|
-
|
|
42
|
-
|
|
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 hasMedia = !!source?.length;
|
|
35
|
+
const hasKpis = kpiItems !== 0;
|
|
36
|
+
const hasFooterSeparator = !!footer || isLoading;
|
|
37
|
+
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: [hasTopBar && (_jsxs(_Fragment, { children: [_jsx(ProductCard.TopBar, { "data-inner-element": "ProductCard-TopBar", sourceLabel: sourceLabel, sourceIcon: sourceIcon, isLoading: isLoading }), _jsx(Separator, {})] })), _jsxs("div", { className: styles.Cover, "data-inner-element": "ProductCard-Cover", children: [hasMedia
|
|
38
|
+
? (_jsx(ProductCard.Media, { source: source, isLoading: isLoading, ratio: ratio, "data-inner-element": "ProductCard-Media" }))
|
|
39
|
+
: (_jsx(AspectRatio, { ratio: ratio ?? '1', children: isLoading
|
|
40
|
+
? (_jsx(Skeleton, { style: { borderRadius: '0', lineHeight: '2rem' }, width: "inherit", height: "inherit" }))
|
|
41
|
+
: (_jsx(Stack, { className: styles.ColoredCard, style: { backgroundColor: getColorFromString(title ?? '') }, hAlign: "center", vAlign: "center", fill: false, "data-inner-element": "ProductCard-ColoredCover", children: _jsx(Text, { variant: "heading-1", textAlign: "center", style: { color: '#fff' }, children: title?.slice(0, 2) }) })) })), badge && !isLoading && (_jsx(Chip, { color: "yellow", className: styles.Badge, "data-inner-element": "ProductCard-Badge", children: badge })), hasOverlay && (_jsx(Stack, { direction: "row", hPadding: 24, vAlign: "center", hAlign: "center", className: styles.OverlayActions, "data-inner-element": "ProductCard-OverlayActions", children: _jsx(Stack, { children: overlayActions }) }))] }), _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
42
|
});
|
|
57
43
|
ProductCard.displayName = 'ProductCard';
|
|
58
44
|
ProductCard.Media = ProductCardMedia;
|
|
59
45
|
ProductCard.Header = ProductCardHeader;
|
|
60
46
|
ProductCard.Kpis = ProductCardKpis;
|
|
61
47
|
ProductCard.Footer = ProductCardFooter;
|
|
48
|
+
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{overflow:hidden;position:relative}.Badge{position:absolute;right:1rem;top:10px}.Bottom{margin-top:auto}.OverlayActions{background-color:var(--global-background);inset:0;opacity:0;position:absolute;transition:opacity .3s;z-index:1}.OverlayActions:hover{opacity:1}.ColoredCard{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
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
6
|
+
export declare const Loading: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
7
|
+
export declare const WithMultipleImages: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
8
|
+
export declare const WithBrokenImage: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
9
|
+
export declare const WithColoredCover: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
10
|
+
export declare const WithoutTopBar: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
11
|
+
export declare const WithSourceLabelOnly: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
12
|
+
export declare const WithFewKpis: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
13
|
+
export declare const WithDescription: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
14
|
+
export declare const Clickable: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
15
|
+
export declare const WithOverlayActions: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
16
|
+
export declare const WithOverlayActionsOnColoredCover: 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;AAoC7C,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,WAAW,CAqD5C,CAAC;AAEF,eAAe,KAAK,CAAC;AAQrB,eAAO,MAAM,OAAO,+DAAoB,CAAC;AAGzC,eAAO,MAAM,OAAO,+DAAoB,CAAC;AAOzC,eAAO,MAAM,kBAAkB,+DAAoB,CAAC;AAKpD,eAAO,MAAM,eAAe,+DAAoB,CAAC;AAKjD,eAAO,MAAM,gBAAgB,+DAAoB,CAAC;AAiBlD,eAAO,MAAM,aAAa,+DAAoB,CAAC;AAO/C,eAAO,MAAM,mBAAmB,+DAAoB,CAAC;AAQrD,eAAO,MAAM,WAAW,+DAAoB,CAAC;AAQ7C,eAAO,MAAM,eAAe,+DAAoB,CAAC;AAgBjD,eAAO,MAAM,SAAS,+DAAoB,CAAC;AAK3C,eAAO,MAAM,kBAAkB,+DAAoB,CAAC;AAKpD,eAAO,MAAM,gCAAgC,+DAAoB,CAAC"}
|
|
@@ -1,24 +1,42 @@
|
|
|
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
|
+
const NoKpis = {
|
|
13
|
+
rating: undefined,
|
|
14
|
+
nps: undefined,
|
|
15
|
+
feedbackCount: undefined,
|
|
16
|
+
votesRating: undefined,
|
|
17
|
+
votesCount: undefined,
|
|
18
|
+
sentiment: undefined,
|
|
19
|
+
tgw: undefined,
|
|
20
|
+
priceMin: undefined,
|
|
21
|
+
priceMax: undefined,
|
|
22
|
+
groups: undefined,
|
|
23
|
+
users: undefined,
|
|
24
|
+
usersCap: undefined,
|
|
25
|
+
skus: undefined,
|
|
26
|
+
skusCap: undefined,
|
|
27
|
+
};
|
|
12
28
|
const story = {
|
|
13
29
|
title: 'Domain Components/Product Card',
|
|
14
30
|
component: ProductCard,
|
|
15
31
|
args: {
|
|
16
|
-
|
|
17
|
-
bordered: false,
|
|
32
|
+
bordered: true,
|
|
18
33
|
highlightOnHover: false,
|
|
19
34
|
title: 'Product Card Title',
|
|
20
35
|
titleRows: 3,
|
|
21
36
|
subtitle: 'subtitle',
|
|
37
|
+
sourceLabel: 'Amazon',
|
|
38
|
+
sourceIcon: SourceLogo,
|
|
39
|
+
badge: 'New',
|
|
22
40
|
rating: 4.3,
|
|
23
41
|
nps: 23,
|
|
24
42
|
feedbackCount: 123,
|
|
@@ -40,17 +58,12 @@ const story = {
|
|
|
40
58
|
isLoading: false,
|
|
41
59
|
ratio: '1',
|
|
42
60
|
overlayActions: undefined,
|
|
43
|
-
menuActions: undefined,
|
|
44
61
|
onClick: undefined,
|
|
45
62
|
children: undefined,
|
|
46
63
|
source: SourceImages.slice(0, 1),
|
|
47
|
-
footer: (_jsx(Text, { variant: "body-
|
|
64
|
+
footer: (_jsx(Text, { variant: "body-3", children: "Apr 2023" })),
|
|
48
65
|
},
|
|
49
66
|
argTypes: {
|
|
50
|
-
direction: {
|
|
51
|
-
options: ['vertical', 'horizontal'],
|
|
52
|
-
control: { type: 'select' },
|
|
53
|
-
},
|
|
54
67
|
currency: {
|
|
55
68
|
options: ['EUR', 'USD', 'GBP', 'JPY', 'CNY'],
|
|
56
69
|
control: { type: 'select' },
|
|
@@ -67,93 +80,81 @@ const story = {
|
|
|
67
80
|
},
|
|
68
81
|
};
|
|
69
82
|
export default story;
|
|
70
|
-
const Template =
|
|
71
|
-
|
|
72
|
-
return (_jsx("div", { style: { maxWidth: direction === 'vertical' ? '250px' : '650px' }, children: _jsx(ProductCard, { ...args }) }));
|
|
73
|
-
};
|
|
83
|
+
const Template = args => (_jsx("div", { style: { width: '272px' }, children: _jsx(ProductCard, { ...args }) }));
|
|
84
|
+
// Base
|
|
74
85
|
export const Default = Template.bind({});
|
|
75
86
|
Default.args = {};
|
|
76
|
-
export const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
nps: undefined,
|
|
80
|
-
feedbackCount: 123,
|
|
81
|
-
votesRating: undefined,
|
|
82
|
-
votesCount: undefined,
|
|
83
|
-
sentiment: 0.54,
|
|
84
|
-
tgw: undefined,
|
|
85
|
-
priceMin: undefined,
|
|
86
|
-
priceMax: undefined,
|
|
87
|
-
groups: undefined,
|
|
88
|
-
users: undefined,
|
|
89
|
-
usersCap: undefined,
|
|
90
|
-
skus: undefined,
|
|
91
|
-
skusCap: undefined,
|
|
92
|
-
};
|
|
93
|
-
export const withOverlayActions = Template.bind({});
|
|
94
|
-
withOverlayActions.args = {
|
|
95
|
-
overlayActions: OverlayButtons,
|
|
96
|
-
};
|
|
97
|
-
export const withMenuActions = Template.bind({});
|
|
98
|
-
withMenuActions.args = {
|
|
99
|
-
menuActions: MenuItems,
|
|
87
|
+
export const Loading = Template.bind({});
|
|
88
|
+
Loading.args = {
|
|
89
|
+
isLoading: true,
|
|
100
90
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
export const withMultipleProducts = Template.bind({});
|
|
106
|
-
withMultipleProducts.args = {
|
|
91
|
+
// Cover
|
|
92
|
+
export const WithMultipleImages = Template.bind({});
|
|
93
|
+
WithMultipleImages.args = {
|
|
107
94
|
source: SourceImages,
|
|
108
95
|
};
|
|
109
|
-
export const
|
|
110
|
-
|
|
96
|
+
export const WithBrokenImage = Template.bind({});
|
|
97
|
+
WithBrokenImage.args = {
|
|
111
98
|
source: [...SourceImages, 'broken'],
|
|
112
99
|
};
|
|
113
|
-
export const
|
|
114
|
-
|
|
100
|
+
export const WithColoredCover = Template.bind({});
|
|
101
|
+
WithColoredCover.args = {
|
|
102
|
+
...NoKpis,
|
|
115
103
|
source: [],
|
|
116
104
|
subtitle: '',
|
|
117
|
-
title: '
|
|
105
|
+
title: 'My first board',
|
|
118
106
|
titleRows: 2,
|
|
119
107
|
kpiItems: 2,
|
|
120
|
-
rating: undefined,
|
|
121
|
-
sentiment: undefined,
|
|
122
|
-
feedbackCount: undefined,
|
|
123
|
-
votesCount: undefined,
|
|
124
|
-
votesRating: undefined,
|
|
125
|
-
nps: undefined,
|
|
126
|
-
groups: undefined,
|
|
127
|
-
tgw: undefined,
|
|
128
|
-
priceMin: undefined,
|
|
129
|
-
priceMax: undefined,
|
|
130
108
|
users: 1789,
|
|
131
109
|
usersCap: 1000,
|
|
132
110
|
skus: 234,
|
|
133
111
|
skusCap: 1000,
|
|
134
112
|
footer: undefined,
|
|
135
113
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
114
|
+
// Top bar
|
|
115
|
+
export const WithoutTopBar = Template.bind({});
|
|
116
|
+
WithoutTopBar.args = {
|
|
117
|
+
sourceLabel: undefined,
|
|
118
|
+
sourceIcon: undefined,
|
|
119
|
+
badge: undefined,
|
|
120
|
+
};
|
|
121
|
+
export const WithSourceLabelOnly = Template.bind({});
|
|
122
|
+
WithSourceLabelOnly.args = {
|
|
123
|
+
sourceIcon: undefined,
|
|
124
|
+
badge: undefined,
|
|
125
|
+
};
|
|
126
|
+
// Content
|
|
127
|
+
export const WithFewKpis = Template.bind({});
|
|
128
|
+
WithFewKpis.args = {
|
|
129
|
+
...NoKpis,
|
|
130
|
+
rating: 4.3,
|
|
131
|
+
feedbackCount: 123,
|
|
132
|
+
sentiment: 0.54,
|
|
133
|
+
};
|
|
134
|
+
export const WithDescription = Template.bind({});
|
|
135
|
+
WithDescription.args = {
|
|
136
|
+
sourceLabel: undefined,
|
|
137
|
+
sourceIcon: undefined,
|
|
138
|
+
badge: undefined,
|
|
139
139
|
subtitle: '',
|
|
140
|
-
title: '
|
|
140
|
+
title: 'Domestic Appliances and Tools',
|
|
141
141
|
titleRows: 2,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
feedbackCount: undefined,
|
|
146
|
-
votesCount: undefined,
|
|
147
|
-
votesRating: undefined,
|
|
148
|
-
nps: undefined,
|
|
149
|
-
groups: undefined,
|
|
150
|
-
tgw: undefined,
|
|
151
|
-
priceMin: undefined,
|
|
152
|
-
priceMax: undefined,
|
|
153
|
-
users: 1789,
|
|
154
|
-
usersCap: 1000,
|
|
155
|
-
skus: 234,
|
|
156
|
-
skusCap: 1000,
|
|
142
|
+
description: 'Appliances and tools for everyday cooking, cleaning, and home maintenance.',
|
|
143
|
+
descriptionRows: 3,
|
|
144
|
+
kpiItems: 0,
|
|
157
145
|
footer: undefined,
|
|
158
|
-
|
|
146
|
+
};
|
|
147
|
+
// Interactions
|
|
148
|
+
export const Clickable = Template.bind({});
|
|
149
|
+
Clickable.args = {
|
|
150
|
+
onClick: () => console.log('pressed'),
|
|
151
|
+
};
|
|
152
|
+
export const WithOverlayActions = Template.bind({});
|
|
153
|
+
WithOverlayActions.args = {
|
|
154
|
+
overlayActions: OverlayButtons,
|
|
155
|
+
};
|
|
156
|
+
export const WithOverlayActionsOnColoredCover = Template.bind({});
|
|
157
|
+
WithOverlayActionsOnColoredCover.args = {
|
|
158
|
+
...WithColoredCover.args,
|
|
159
|
+
overlayActions: OverlayButtons,
|
|
159
160
|
};
|
|
@@ -13,32 +13,93 @@ 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 }));
|
|
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 over the 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", 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", isLoading: true }));
|
|
57
|
+
expect(badge()).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
test('it should render the media or the colored cover, with overlay actions only inside the cover', () => {
|
|
60
|
+
const { container, rerender } = render(_jsx(ProductCard, { title: "title", source: SourceImages, overlayActions: _jsx("button", { type: "button", children: "Action" }) }));
|
|
61
|
+
const cover = () => container.querySelector('[data-inner-element="ProductCard-Cover"]');
|
|
62
|
+
const media = () => container.querySelector('[data-inner-element="ProductCard-Media"]');
|
|
63
|
+
const coloredCover = () => container.querySelector('[data-inner-element="ProductCard-ColoredCover"]');
|
|
64
|
+
const overlay = () => container.querySelector('[data-inner-element="ProductCard-OverlayActions"]');
|
|
65
|
+
expect(media()).not.toBeNull();
|
|
66
|
+
expect(coloredCover()).toBeNull();
|
|
67
|
+
expect(cover()?.contains(overlay())).toBe(true);
|
|
68
|
+
expect(screen.getByText('Action')).toBeDefined();
|
|
69
|
+
rerender(_jsx(ProductCard, { title: "title", overlayActions: _jsx("button", { type: "button", children: "Action" }) }));
|
|
70
|
+
expect(media()).toBeNull();
|
|
71
|
+
expect(coloredCover()).not.toBeNull();
|
|
72
|
+
expect(screen.getByText('ti')).toBeDefined();
|
|
73
|
+
expect(cover()?.contains(overlay())).toBe(true);
|
|
74
|
+
rerender(_jsx(ProductCard, { title: "title", overlayActions: _jsx("button", { type: "button", children: "Action" }), onClick: jest.fn() }));
|
|
75
|
+
expect(overlay()).toBeNull();
|
|
76
|
+
rerender(_jsx(ProductCard, { title: "title", overlayActions: _jsx("button", { type: "button", children: "Action" }), isLoading: true }));
|
|
77
|
+
expect(overlay()).toBeNull();
|
|
78
|
+
expect(cover()).not.toBeNull();
|
|
79
|
+
expect(coloredCover()).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
test('it should render the footer separator only with a footer or while loading', () => {
|
|
82
|
+
const { container, rerender } = render(_jsx(ProductCard, { title: "title" }));
|
|
83
|
+
expect(container.querySelectorAll('hr')).toHaveLength(0);
|
|
84
|
+
rerender(_jsx(ProductCard, { title: "title", footer: "Apr 2023" }));
|
|
85
|
+
expect(container.querySelectorAll('hr')).toHaveLength(1);
|
|
86
|
+
rerender(_jsx(ProductCard, { title: "title", isLoading: true }));
|
|
87
|
+
expect(container.querySelectorAll('hr')).toHaveLength(1);
|
|
88
|
+
rerender(_jsx(ProductCard, { title: "title", sourceLabel: "Amazon", footer: "Apr 2023" }));
|
|
89
|
+
expect(container.querySelectorAll('hr')).toHaveLength(2);
|
|
90
|
+
});
|
|
91
|
+
test('it should render the description and hide the KPIs block when kpiItems is 0', () => {
|
|
92
|
+
const { rerender } = render(_jsx(ProductCard, { title: "title", rating: 4.3 }));
|
|
93
|
+
expect(screen.queryByText('A description')).toBeNull();
|
|
94
|
+
expect(screen.getByText('4.3')).toBeDefined();
|
|
95
|
+
rerender(_jsx(ProductCard, { title: "title", description: "A description", rating: 4.3, kpiItems: 0 }));
|
|
96
|
+
expect(screen.getByText('A description')).toBeDefined();
|
|
97
|
+
expect(screen.queryByText('4.3')).toBeNull();
|
|
98
|
+
});
|
|
99
|
+
test('it should be bordered by default', () => {
|
|
100
|
+
const { container, rerender } = render(_jsx(ProductCard, { title: "title" }));
|
|
101
|
+
expect(container.querySelector('[data-card-bordered="true"]')).not.toBeNull();
|
|
102
|
+
rerender(_jsx(ProductCard, { title: "title", bordered: false }));
|
|
103
|
+
expect(container.querySelector('[data-card-bordered="false"]')).not.toBeNull();
|
|
104
|
+
});
|
|
44
105
|
});
|
|
@@ -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.1.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.1.0",
|
|
85
|
+
"@wonderflow/tokens": "17.1.0",
|
|
86
|
+
"@wonderflow/charts": "17.1.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)}}
|