@wonderflow/react-components 14.0.8 → 14.2.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 +4 -0
- package/dist/components/product-card/product-card.d.ts.map +1 -1
- package/dist/components/product-card/product-card.js +28 -3
- package/dist/components/product-card/product-card.module.css +1 -1
- package/dist/components/product-card/product-card.stories.d.ts +1 -0
- package/dist/components/product-card/product-card.stories.d.ts.map +1 -1
- package/dist/components/product-card/product-card.stories.js +24 -0
- package/dist/components/product-card/product-card.test.js +7 -1
- package/package.json +4 -4
|
@@ -28,6 +28,10 @@ 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;
|
|
31
35
|
/**
|
|
32
36
|
* Set an action to be performed when clicked.
|
|
33
37
|
*/
|
|
@@ -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,EACA,iBAAiB,EAE9B,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,EACA,iBAAiB,EAE9B,MAAM,OAAO,CAAC;AASf,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,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jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useDebounce } from 'ahooks';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import { forwardRef, useRef, } from 'react';
|
|
5
|
-
import { Elevator, Stack, } from '../..';
|
|
5
|
+
import { Elevator, 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';
|
|
9
9
|
import { ProductCardKpis } from './product-card-kpis/product-card-kpis';
|
|
10
10
|
import { ProductCardMedia } from './product-card-media/product-card-media';
|
|
11
|
-
|
|
11
|
+
const getColorFromString = (input) => {
|
|
12
|
+
// Generate a hash from the input string
|
|
13
|
+
let hash = 0;
|
|
14
|
+
let color = '#';
|
|
15
|
+
const rgb = [];
|
|
16
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
17
|
+
// eslint-disable-next-line no-bitwise
|
|
18
|
+
hash = input.charCodeAt(i) + ((hash << 5) - hash);
|
|
19
|
+
}
|
|
20
|
+
for (let i = 0; i < 3; i += 1) {
|
|
21
|
+
// eslint-disable-next-line no-bitwise
|
|
22
|
+
const value = (hash >> (i * 8)) & 0xFF;
|
|
23
|
+
rgb.push(value);
|
|
24
|
+
color += (`00${value.toString(16)}`).slice(-2);
|
|
25
|
+
}
|
|
26
|
+
// Calculate luminance to check if the color is too light
|
|
27
|
+
const [r, g, b] = rgb.map(v => v / 255);
|
|
28
|
+
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
29
|
+
if (luminance > 0.8) {
|
|
30
|
+
const darkenedRgb = rgb.map(v => Math.floor(v * 0.6));
|
|
31
|
+
color = darkenedRgb.map(value => (`00${value.toString(16)}`).slice(-2)).join('');
|
|
32
|
+
color = `#${color}`;
|
|
33
|
+
}
|
|
34
|
+
return color;
|
|
35
|
+
};
|
|
36
|
+
export const ProductCard = forwardRef(({ direction = 'vertical', bordered = false, highlightOnHover = false, title, titleRows = 3, subtitle, menuActions, rating, feedbackCount, votesCount, votesRating, sentiment, nps, groups, tgw, priceMin, priceMax, currency, currencyDecimals, users, usersCap, skus, skusCap, kpiItems, kpisRowGap, ratio, source, footer, overlayActions, onClick, isLoading = false, hasColoredCover = false, className, style, children, ...otherProps }, forwardedRef) => {
|
|
12
37
|
const hasOverlay = !!(overlayActions && !menuActions && !onClick && !isLoading);
|
|
13
38
|
const hasMenu = !!(menuActions && !overlayActions && !onClick);
|
|
14
39
|
const hasHighlight = !!(onClick ?? highlightOnHover);
|
|
@@ -34,7 +59,7 @@ export const ProductCard = forwardRef(({ direction = 'vertical', bordered = fals
|
|
|
34
59
|
return ({});
|
|
35
60
|
};
|
|
36
61
|
const deboucedStyle = useDebounce(mediaSizeStyle(direction), { wait: 500 });
|
|
37
|
-
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: [_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 })] })] })] }) }) }));
|
|
62
|
+
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) }) })), _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 })] })] })] }) }) }));
|
|
38
63
|
});
|
|
39
64
|
ProductCard.displayName = 'ProductCard';
|
|
40
65
|
ProductCard.Media = ProductCardMedia;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
@layer components{.Card{background-color:var(--global-background);border-radius:.5rem;overflow:hidden;padding:0;position:relative}.Card[data-card-bordered=true]{border:1px solid var(--dimmed-1)}.Card[data-card-clickable=true]{cursor:pointer}.Row{height:100%;position:relative}.Content{flex-grow:1}.OverlayActions{background-color:var(--global-background);height:100%;opacity:0;position:absolute;transition:opacity .3s;width:100%;z-index:1}.OverlayActions:hover{opacity:1}}
|
|
1
|
+
@layer components{.Card{background-color:var(--global-background);border-radius:.5rem;overflow:hidden;padding:0;position:relative}.Card[data-card-bordered=true]{border:1px solid var(--dimmed-1)}.Card[data-card-clickable=true]{cursor:pointer}.Row{height:100%;position:relative}.Content{flex-grow:1}.OverlayActions{background-color:var(--global-background);height:100%;opacity:0;position:absolute;transition:opacity .3s;width:100%;z-index:1}.OverlayActions:hover{opacity:1}.ColoredCard{height:125px;width:100%}}
|
|
@@ -10,4 +10,5 @@ export declare const clickable: ComponentStory<import("./product-card").ProductC
|
|
|
10
10
|
export declare const withMultipleProducts: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
11
11
|
export declare const withBrokenImage: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
12
12
|
export declare const withNoMedia: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
13
|
+
export declare const withColoredCover: ComponentStory<import("./product-card").ProductCardComponent>;
|
|
13
14
|
//# 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;AAQjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA4C7C,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,WAAW,CAwD5C,CAAC;AAEF,eAAe,KAAK,CAAC;AAQrB,eAAO,MAAM,OAAO,+DAAoB,CAAC;AAGzC,eAAO,MAAM,WAAW,+DAAoB,CAAC;AAkB7C,eAAO,MAAM,kBAAkB,+DAAoB,CAAC;AAKpD,eAAO,MAAM,eAAe,+DAAoB,CAAC;AAKjD,eAAO,MAAM,SAAS,+DAAoB,CAAC;AAK3C,eAAO,MAAM,oBAAoB,+DAAoB,CAAC;AAKtD,eAAO,MAAM,eAAe,+DAAoB,CAAC;AAKjD,eAAO,MAAM,WAAW,+DAAoB,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;AAQjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA4C7C,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,WAAW,CAwD5C,CAAC;AAEF,eAAe,KAAK,CAAC;AAQrB,eAAO,MAAM,OAAO,+DAAoB,CAAC;AAGzC,eAAO,MAAM,WAAW,+DAAoB,CAAC;AAkB7C,eAAO,MAAM,kBAAkB,+DAAoB,CAAC;AAKpD,eAAO,MAAM,eAAe,+DAAoB,CAAC;AAKjD,eAAO,MAAM,SAAS,+DAAoB,CAAC;AAK3C,eAAO,MAAM,oBAAoB,+DAAoB,CAAC;AAKtD,eAAO,MAAM,eAAe,+DAAoB,CAAC;AAKjD,eAAO,MAAM,WAAW,+DAAoB,CAAC;AAwB7C,eAAO,MAAM,gBAAgB,+DAAoB,CAAC"}
|
|
@@ -133,3 +133,27 @@ withNoMedia.args = {
|
|
|
133
133
|
skusCap: 1000,
|
|
134
134
|
footer: undefined,
|
|
135
135
|
};
|
|
136
|
+
export const withColoredCover = Template.bind({});
|
|
137
|
+
withColoredCover.args = {
|
|
138
|
+
source: [],
|
|
139
|
+
subtitle: '',
|
|
140
|
+
title: 'My first board',
|
|
141
|
+
titleRows: 2,
|
|
142
|
+
kpiItems: 2,
|
|
143
|
+
rating: undefined,
|
|
144
|
+
sentiment: undefined,
|
|
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,
|
|
157
|
+
footer: undefined,
|
|
158
|
+
hasColoredCover: true,
|
|
159
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { ProductCard } from './product-card';
|
|
4
4
|
describe('<ProductCard>', () => {
|
|
5
5
|
const SourceImages = [
|
|
@@ -35,4 +35,10 @@ describe('<ProductCard>', () => {
|
|
|
35
35
|
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", source: SourceImages, direction: "horizontal", rating: 1.2, feedbackCount: 1.2, votesCount: 1.2, onClick: spyOnClick, footer: _jsx("div", { children: "some content" }), children: _jsx("div", { children: "some content" }) }));
|
|
36
36
|
expect(container).not.toBeNull();
|
|
37
37
|
});
|
|
38
|
+
test('it should render properly with colored cover', () => {
|
|
39
|
+
const { container } = render(_jsx(ProductCard, { title: "title", subtitle: "subtitle", direction: "horizontal", rating: 1.2, feedbackCount: 1.2, votesCount: 1.2, votesRating: 1.2, sentiment: 1.2, nps: 1.2, groups: 1.2, priceMin: 1.2, priceMax: 1.2, users: 1.2, skus: 1.2, kpiItems: 2, kpisRowGap: 16, bordered: true, highlightOnHover: true, hasColoredCover: true }));
|
|
40
|
+
expect(container).not.toBeNull();
|
|
41
|
+
const coverText = screen.getByText('ti');
|
|
42
|
+
expect(coverText).toBeDefined();
|
|
43
|
+
});
|
|
38
44
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wonderflow/react-components",
|
|
3
|
-
"version": "14.0
|
|
3
|
+
"version": "14.2.0",
|
|
4
4
|
"description": "UI components from Wonderflow's Wanda design system",
|
|
5
5
|
"author": "Wonderflow",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -82,9 +82,9 @@
|
|
|
82
82
|
"@types/react-dom": "17.0.14",
|
|
83
83
|
"@types/react-table": "7.7.20",
|
|
84
84
|
"@types/react-test-renderer": "18.0.7",
|
|
85
|
-
"@wonderflow/config": "14.0
|
|
86
|
-
"@wonderflow/tokens": "14.0
|
|
87
|
-
"@wonderflow/charts": "14.0
|
|
85
|
+
"@wonderflow/config": "14.2.0",
|
|
86
|
+
"@wonderflow/tokens": "14.2.0",
|
|
87
|
+
"@wonderflow/charts": "14.2.0",
|
|
88
88
|
"@types/uuid": "9.0.8",
|
|
89
89
|
"babel-loader": "8.2.5",
|
|
90
90
|
"cpy-cli": "3.1.1",
|