@wonderflow/react-components 17.0.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.d.ts +3 -6
- package/dist/components/product-card/product-card.d.ts.map +1 -1
- package/dist/components/product-card/product-card.js +8 -6
- package/dist/components/product-card/product-card.module.css +1 -1
- package/dist/components/product-card/product-card.stories.d.ts +11 -11
- package/dist/components/product-card/product-card.stories.d.ts.map +1 -1
- package/dist/components/product-card/product-card.stories.js +63 -81
- package/dist/components/product-card/product-card.test.js +26 -4
- package/package.json +4 -4
|
@@ -16,7 +16,8 @@ export declare type ProductCardProps = PropsWithClass<PropsWithChildren<{
|
|
|
16
16
|
*/
|
|
17
17
|
highlightOnHover?: boolean;
|
|
18
18
|
/**
|
|
19
|
-
* 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.
|
|
20
21
|
*/
|
|
21
22
|
overlayActions?: React.ReactNode;
|
|
22
23
|
/**
|
|
@@ -27,10 +28,6 @@ export declare type ProductCardProps = PropsWithClass<PropsWithChildren<{
|
|
|
27
28
|
* Set the loading state showing a skeleton.
|
|
28
29
|
*/
|
|
29
30
|
isLoading?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Shows a colored cover with the first two letters of the title.
|
|
32
|
-
*/
|
|
33
|
-
hasColoredCover?: boolean;
|
|
34
31
|
/**
|
|
35
32
|
* Set an action to be performed when clicked.
|
|
36
33
|
*/
|
|
@@ -46,7 +43,7 @@ export declare type ProductCardProps = PropsWithClass<PropsWithChildren<{
|
|
|
46
43
|
sourceIcon?: ProductCardTopBarProps['sourceIcon'];
|
|
47
44
|
/**
|
|
48
45
|
* 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
|
|
46
|
+
* It is not displayed while loading.
|
|
50
47
|
*/
|
|
51
48
|
badge?: string;
|
|
52
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'>;
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import tkns from '@wonderflow/tokens/platforms/web/tokens.json';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import { forwardRef } from 'react';
|
|
5
|
-
import { Chip, Elevator, Separator, Stack, Text, } from '../..';
|
|
5
|
+
import { AspectRatio, Chip, Elevator, Separator, Skeleton, Stack, Text, } from '../..';
|
|
6
6
|
import * as styles from './product-card.module.css';
|
|
7
7
|
import { ProductCardFooter } from './product-card-footer/product-card-footer';
|
|
8
8
|
import { ProductCardHeader } from './product-card-header/product-card-header';
|
|
@@ -26,17 +26,19 @@ const getColorFromString = (input) => {
|
|
|
26
26
|
const firstShade = Object.values(shades)[5];
|
|
27
27
|
return `hsl(${firstShade})`;
|
|
28
28
|
};
|
|
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,
|
|
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
30
|
const hasOverlay = !!(overlayActions && !onClick && !isLoading);
|
|
31
31
|
const hasHighlight = !!(onClick ?? highlightOnHover);
|
|
32
32
|
const isClickable = !!(!isLoading && onClick);
|
|
33
33
|
const hasTopBar = !!sourceLabel;
|
|
34
|
-
const
|
|
35
|
-
const hasMedia = !hasColoredCover && !!source?.length;
|
|
36
|
-
const hasCover = hasColoredCard || hasMedia;
|
|
34
|
+
const hasMedia = !!source?.length;
|
|
37
35
|
const hasKpis = kpiItems !== 0;
|
|
38
36
|
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: [
|
|
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 })] })] }) }));
|
|
40
42
|
});
|
|
41
43
|
ProductCard.displayName = 'ProductCard';
|
|
42
44
|
ProductCard.Media = ProductCardMedia;
|
|
@@ -1 +1 @@
|
|
|
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);
|
|
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,15 +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
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
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>;
|
|
17
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;AAOjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,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"}
|
|
@@ -9,6 +9,22 @@ const SourceImages = [
|
|
|
9
9
|
// 'https://storage.googleapis.com/wonderflow-product-images/delonghi_coffee_MC%20NESPRESSO%20INISSIA.png',
|
|
10
10
|
];
|
|
11
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,
|
|
@@ -65,81 +81,58 @@ const story = {
|
|
|
65
81
|
};
|
|
66
82
|
export default story;
|
|
67
83
|
const Template = args => (_jsx("div", { style: { width: '272px' }, children: _jsx(ProductCard, { ...args }) }));
|
|
84
|
+
// Base
|
|
68
85
|
export const Default = Template.bind({});
|
|
69
86
|
Default.args = {};
|
|
70
|
-
export const
|
|
71
|
-
|
|
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 = {
|
|
87
|
+
export const Loading = Template.bind({});
|
|
88
|
+
Loading.args = {
|
|
83
89
|
isLoading: true,
|
|
84
90
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
nps: undefined,
|
|
89
|
-
feedbackCount: 123,
|
|
90
|
-
votesRating: undefined,
|
|
91
|
-
votesCount: undefined,
|
|
92
|
-
sentiment: 0.54,
|
|
93
|
-
tgw: undefined,
|
|
94
|
-
priceMin: undefined,
|
|
95
|
-
priceMax: undefined,
|
|
96
|
-
groups: undefined,
|
|
97
|
-
users: undefined,
|
|
98
|
-
usersCap: undefined,
|
|
99
|
-
skus: undefined,
|
|
100
|
-
skusCap: undefined,
|
|
101
|
-
};
|
|
102
|
-
export const withOverlayActions = Template.bind({});
|
|
103
|
-
withOverlayActions.args = {
|
|
104
|
-
overlayActions: OverlayButtons,
|
|
105
|
-
};
|
|
106
|
-
export const clickable = Template.bind({});
|
|
107
|
-
clickable.args = {
|
|
108
|
-
onClick: () => console.log('pressed'),
|
|
109
|
-
};
|
|
110
|
-
export const withMultipleProducts = Template.bind({});
|
|
111
|
-
withMultipleProducts.args = {
|
|
91
|
+
// Cover
|
|
92
|
+
export const WithMultipleImages = Template.bind({});
|
|
93
|
+
WithMultipleImages.args = {
|
|
112
94
|
source: SourceImages,
|
|
113
95
|
};
|
|
114
|
-
export const
|
|
115
|
-
|
|
96
|
+
export const WithBrokenImage = Template.bind({});
|
|
97
|
+
WithBrokenImage.args = {
|
|
116
98
|
source: [...SourceImages, 'broken'],
|
|
117
99
|
};
|
|
118
|
-
export const
|
|
119
|
-
|
|
100
|
+
export const WithColoredCover = Template.bind({});
|
|
101
|
+
WithColoredCover.args = {
|
|
102
|
+
...NoKpis,
|
|
120
103
|
source: [],
|
|
121
104
|
subtitle: '',
|
|
122
|
-
title: '
|
|
105
|
+
title: 'My first board',
|
|
123
106
|
titleRows: 2,
|
|
124
107
|
kpiItems: 2,
|
|
125
|
-
rating: undefined,
|
|
126
|
-
sentiment: undefined,
|
|
127
|
-
feedbackCount: undefined,
|
|
128
|
-
votesCount: undefined,
|
|
129
|
-
votesRating: undefined,
|
|
130
|
-
nps: undefined,
|
|
131
|
-
groups: undefined,
|
|
132
|
-
tgw: undefined,
|
|
133
|
-
priceMin: undefined,
|
|
134
|
-
priceMax: undefined,
|
|
135
108
|
users: 1789,
|
|
136
109
|
usersCap: 1000,
|
|
137
110
|
skus: 234,
|
|
138
111
|
skusCap: 1000,
|
|
139
112
|
footer: undefined,
|
|
140
113
|
};
|
|
141
|
-
|
|
142
|
-
|
|
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 = {
|
|
143
136
|
sourceLabel: undefined,
|
|
144
137
|
sourceIcon: undefined,
|
|
145
138
|
badge: undefined,
|
|
@@ -151,28 +144,17 @@ withDescription.args = {
|
|
|
151
144
|
kpiItems: 0,
|
|
152
145
|
footer: undefined,
|
|
153
146
|
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
nps: undefined,
|
|
168
|
-
groups: undefined,
|
|
169
|
-
tgw: undefined,
|
|
170
|
-
priceMin: undefined,
|
|
171
|
-
priceMax: undefined,
|
|
172
|
-
users: 1789,
|
|
173
|
-
usersCap: 1000,
|
|
174
|
-
skus: 234,
|
|
175
|
-
skusCap: 1000,
|
|
176
|
-
footer: undefined,
|
|
177
|
-
hasColoredCover: true,
|
|
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,
|
|
178
160
|
};
|
|
@@ -31,7 +31,7 @@ describe('<ProductCard>', () => {
|
|
|
31
31
|
expect(container).not.toBeNull();
|
|
32
32
|
});
|
|
33
33
|
test('it should render properly with colored cover', () => {
|
|
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
|
|
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 }));
|
|
35
35
|
expect(container).not.toBeNull();
|
|
36
36
|
const coverText = screen.getByText('ti');
|
|
37
37
|
expect(coverText).toBeDefined();
|
|
@@ -44,18 +44,40 @@ describe('<ProductCard>', () => {
|
|
|
44
44
|
expect(screen.getByText('Amazon')).toBeDefined();
|
|
45
45
|
expect(screen.getByAltText('logo')).toBeDefined();
|
|
46
46
|
});
|
|
47
|
-
test('it should render the badge
|
|
47
|
+
test('it should render the badge over the cover and not while loading', () => {
|
|
48
48
|
const { container, rerender } = render(_jsx(ProductCard, { title: "title", source: SourceImages, badge: "New" }));
|
|
49
49
|
const badge = () => container.querySelector('[data-inner-element="ProductCard-Badge"]');
|
|
50
50
|
expect(badge()).not.toBeNull();
|
|
51
51
|
expect(screen.getByText('New')).toBeDefined();
|
|
52
|
-
rerender(_jsx(ProductCard, { title: "title",
|
|
52
|
+
rerender(_jsx(ProductCard, { title: "title", badge: "New" }));
|
|
53
53
|
expect(badge()).not.toBeNull();
|
|
54
54
|
rerender(_jsx(ProductCard, { title: "title", source: SourceImages, badge: "New", isLoading: true }));
|
|
55
55
|
expect(badge()).toBeNull();
|
|
56
|
-
rerender(_jsx(ProductCard, { title: "title", badge: "New" }));
|
|
56
|
+
rerender(_jsx(ProductCard, { title: "title", badge: "New", isLoading: true }));
|
|
57
57
|
expect(badge()).toBeNull();
|
|
58
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
|
+
});
|
|
59
81
|
test('it should render the footer separator only with a footer or while loading', () => {
|
|
60
82
|
const { container, rerender } = render(_jsx(ProductCard, { title: "title" }));
|
|
61
83
|
expect(container.querySelectorAll('hr')).toHaveLength(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wonderflow/react-components",
|
|
3
|
-
"version": "17.
|
|
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": "17.
|
|
85
|
-
"@wonderflow/tokens": "17.
|
|
86
|
-
"@wonderflow/charts": "17.
|
|
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",
|