@wonderflow/react-components 17.4.0 → 17.5.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-media/product-card-media.module.css +1 -1
- package/dist/components/product-card/product-card.d.ts.map +1 -1
- package/dist/components/product-card/product-card.js +44 -19
- package/dist/components/product-card/product-card.module.css +1 -1
- package/dist/components/product-card/product-card.stories.d.ts.map +1 -1
- package/dist/components/product-card/product-card.stories.js +19 -2
- package/dist/components/product-card/product-card.test.js +27 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
@layer components{.Media{border-bottom:1px solid var(--dimmed-1)}.Image{background-position:50%;background-repeat:no-repeat;background-size:
|
|
1
|
+
@layer components{.Media{border-bottom:1px solid var(--dimmed-1)}.Image{background-position:50%;background-repeat:no-repeat;background-size:contain}}
|
|
@@ -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,EAC9B,MAAM,OAAO,CAAC;AAcf,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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AAW,GAAG,UAAU,GAAG,UAAU,GAAG,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,YAAY,GAAG,aAAa,GAAG,eAAe,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAC/R,kBAAkB,CAAC,CAAA;AA0BnB,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,sBAwRE,CAAC"}
|
|
@@ -33,11 +33,27 @@ export const ProductCard = forwardRef(({ bordered = true, highlightOnHover = fal
|
|
|
33
33
|
const cardRef = useRef(null);
|
|
34
34
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
35
35
|
const [isPeeking, setIsPeeking] = useState(false);
|
|
36
|
+
const [isOverlayOpen, setIsOverlayOpen] = useState(false);
|
|
36
37
|
const [lockedHeight, setLockedHeight] = useState();
|
|
37
38
|
const [isLocked, setIsLocked] = useState(false);
|
|
39
|
+
const hasOverlay = !!(overlayActions && !onClick && !isLoading);
|
|
40
|
+
const hasHighlight = !!(onClick ?? highlightOnHover);
|
|
41
|
+
const isClickable = !!(!isLoading && onClick);
|
|
42
|
+
const hasTopBar = !!sourceLabel;
|
|
43
|
+
const hasMedia = !!source?.length;
|
|
44
|
+
const hasKpis = kpiItems !== 0;
|
|
45
|
+
const hasFooterSeparator = !!footer || isLoading;
|
|
38
46
|
const isKpisExpanded = !!expandable && isExpanded && !isLoading;
|
|
39
47
|
const isShowingAllKpis = isKpisExpanded && !isPeeking;
|
|
40
48
|
const isKpisAvailable = !!expandable && !isLoading;
|
|
49
|
+
// While the overlay actions are open, the KPIs give their space back to the cover.
|
|
50
|
+
const isKpisHidden = hasOverlay && isOverlayOpen && hasKpis;
|
|
51
|
+
const lock = useCallback(() => {
|
|
52
|
+
if (isLocked)
|
|
53
|
+
return;
|
|
54
|
+
setLockedHeight(cardRef.current?.offsetHeight);
|
|
55
|
+
setIsLocked(true);
|
|
56
|
+
}, [isLocked]);
|
|
41
57
|
const unlock = useCallback(() => {
|
|
42
58
|
setIsLocked(false);
|
|
43
59
|
setLockedHeight(undefined);
|
|
@@ -52,38 +68,47 @@ export const ProductCard = forwardRef(({ bordered = true, highlightOnHover = fal
|
|
|
52
68
|
if (!isKpisExpanded)
|
|
53
69
|
setIsPeeking(false);
|
|
54
70
|
}, [isKpisExpanded]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!hasOverlay)
|
|
73
|
+
setIsOverlayOpen(false);
|
|
74
|
+
}, [hasOverlay]);
|
|
55
75
|
// The lock is kept while the collapse animation plays, then released on transition end (or after a fallback delay).
|
|
56
76
|
useEffect(() => {
|
|
57
|
-
if (!isLocked || isKpisExpanded)
|
|
77
|
+
if (!isLocked || isKpisExpanded || isOverlayOpen)
|
|
58
78
|
return undefined;
|
|
59
79
|
const timeout = setTimeout(unlock, LOCK_RELEASE_FALLBACK_MS);
|
|
60
80
|
return () => clearTimeout(timeout);
|
|
61
|
-
}, [isLocked, isKpisExpanded, unlock]);
|
|
81
|
+
}, [isLocked, isKpisExpanded, isOverlayOpen, unlock]);
|
|
62
82
|
const handleExpandedChange = useCallback((expanded) => {
|
|
63
|
-
if (expanded
|
|
64
|
-
|
|
65
|
-
setIsLocked(true);
|
|
66
|
-
}
|
|
83
|
+
if (expanded)
|
|
84
|
+
lock();
|
|
67
85
|
setIsExpanded(expanded);
|
|
68
|
-
}, [
|
|
86
|
+
}, [lock]);
|
|
69
87
|
const handleTransitionEnd = (event) => {
|
|
70
|
-
if (isLocked && !isKpisExpanded && event.propertyName === 'grid-template-rows')
|
|
88
|
+
if (isLocked && !isKpisExpanded && !isOverlayOpen && event.propertyName === 'grid-template-rows')
|
|
71
89
|
unlock();
|
|
72
90
|
};
|
|
73
|
-
const handleCoverMouseEnter =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
91
|
+
const handleCoverMouseEnter = () => {
|
|
92
|
+
if (hasOverlay) {
|
|
93
|
+
if (hasKpis)
|
|
94
|
+
lock();
|
|
95
|
+
setIsOverlayOpen(true);
|
|
96
|
+
}
|
|
97
|
+
else if (isKpisExpanded) {
|
|
98
|
+
setIsPeeking(true);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const handleCoverMouseLeave = () => {
|
|
102
|
+
if (hasOverlay)
|
|
103
|
+
setIsOverlayOpen(false);
|
|
104
|
+
else if (isKpisExpanded)
|
|
105
|
+
setIsPeeking(false);
|
|
106
|
+
};
|
|
107
|
+
return (_jsx(Elevator, { resting: 1, hover: hasHighlight ? 2 : undefined, children: _jsxs(Stack, { ref: mergeRefs([cardRef, forwardedRef]), className: clsx(styles.Card, className), style: { ...style, height: isLocked ? lockedHeight : style?.height }, fill: false, "data-card-bordered": bordered, "data-card-clickable": isClickable, "data-card-expanded": isShowingAllKpis, "data-card-locked": isLocked, "data-card-overlay-open": hasOverlay && isOverlayOpen, onClick: isLoading ? undefined : onClick, onTransitionEnd: handleTransitionEnd, ...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", onMouseEnter: handleCoverMouseEnter, onMouseLeave: handleCoverMouseLeave, children: [hasMedia
|
|
83
108
|
? (_jsx(ProductCard.Media, { source: source, isLoading: isLoading, ratio: ratio, "data-inner-element": "ProductCard-Media" }))
|
|
84
109
|
: (_jsx(AspectRatio, { ratio: ratio ?? '1', children: isLoading
|
|
85
110
|
? (_jsx(Skeleton, { style: { borderRadius: '0', lineHeight: '2rem' }, width: "inherit", height: "inherit" }))
|
|
86
|
-
: (_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, expandable: expandable, expandLabel: expandLabel, collapseLabel: collapseLabel, isExpanded: isShowingAllKpis, onExpandedChange: handleExpandedChange })), 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 })] })] }) }));
|
|
111
|
+
: (_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("div", { className: styles.KpisCollapse, "data-kpis-hidden": isKpisHidden, "aria-hidden": isKpisHidden || undefined, "data-inner-element": "ProductCard-KpisCollapse", children: _jsx("div", { className: styles.KpisCollapseContent, children: _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, expandable: expandable, expandLabel: expandLabel, collapseLabel: collapseLabel, isExpanded: isShowingAllKpis, onExpandedChange: handleExpandedChange }) }) })), 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 })] })] }) }));
|
|
87
112
|
});
|
|
88
113
|
ProductCard.displayName = 'ProductCard';
|
|
89
114
|
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{overflow:hidden;position:relative}.Card[data-card-locked=true]>:not(.Cover){flex-shrink:0}.Card[data-card-locked=true] .Cover{flex:1 1 auto;min-height:0}.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 .
|
|
1
|
+
@layer components{.Card{--kpis-fade:0.075s;--kpis-collapse:0.15s;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}.Card[data-card-locked=true]>:not(.Cover){flex-shrink:0}.Card[data-card-locked=true] .Cover{flex:1 1 auto;min-height:0}.Badge{position:absolute;right:1rem;top:10px}.Bottom{margin-top:auto}.KpisCollapse{display:grid;grid-template-rows:1fr;opacity:1;transition:grid-template-rows var(--kpis-collapse) cubic-bezier(.3,.07,.34,1),opacity var(--kpis-fade) cubic-bezier(.3,.07,.34,1) var(--kpis-collapse),visibility 0s linear;visibility:visible}.KpisCollapse[data-kpis-hidden=true]{grid-template-rows:0fr;opacity:0;transition:grid-template-rows var(--kpis-collapse) cubic-bezier(.3,.07,.34,1) var(--kpis-fade),opacity var(--kpis-fade) cubic-bezier(.3,.07,.34,1),visibility 0s linear calc(var(--kpis-fade) + var(--kpis-collapse));visibility:hidden}@media (prefers-reduced-motion:reduce){.KpisCollapse,.KpisCollapse[data-kpis-hidden=true]{transition:none}}.KpisCollapseContent{min-height:0;overflow:hidden}.OverlayActions{background-color:var(--global-background);inset:0;opacity:0;position:absolute;transition:opacity .2s;z-index:1}.Card[data-card-overlay-open=true] .OverlayActions{opacity:1}.ColoredCard{width:100%}}
|
|
@@ -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;AAWjE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAoC7C,QAAA,MAAM,KAAK,EAAE,aAAa,CAAC,OAAO,WAAW,CAwD5C,CAAC;AAEF,eAAe,KAAK,CAAC;AAQrB,eAAO,MAAM,OAAO,+DAAoB,CAAC;AAKzC,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;AAMlE,eAAO,MAAM,cAAc,+DAAoB,CAAC;AAkBhD,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAAC,OAAO,WAAW,CAmCnE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { Button, Container, Grid, Stack, Text, useBreakpointsConfig, } from '../..';
|
|
3
4
|
import { ProductCard } from './product-card';
|
|
4
5
|
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
6
|
const SourceImages = [
|
|
@@ -169,7 +170,23 @@ ExpandableKpis.args = {
|
|
|
169
170
|
expandable: true,
|
|
170
171
|
overlayActions: OverlayButtons,
|
|
171
172
|
};
|
|
172
|
-
|
|
173
|
+
const GridOverlayButtons = (_jsxs(Stack, { rowGap: 8, children: [_jsx(Button, { children: "Stats" }), _jsx(Button, { kind: "secondary", children: "Compare" }), _jsx(Button, { kind: "secondary", children: "Add to group" }), _jsx(Button, { kind: "secondary", children: "Share" }), _jsx(Button, { kind: "flat", children: "Remove" })] }));
|
|
174
|
+
// Same grid as the Wonderboard catalog (cards view): columns and gutters follow the container width.
|
|
175
|
+
export const ExpandableKpisInGrid = (args) => {
|
|
176
|
+
const containerRef = useRef(null);
|
|
177
|
+
const { value } = useBreakpointsConfig({
|
|
178
|
+
xs: { columns: 1, gutter: 16 },
|
|
179
|
+
sm: { columns: 2, gutter: 16 },
|
|
180
|
+
md: { columns: 3, gutter: 24 },
|
|
181
|
+
lg: { columns: 4, gutter: 24 },
|
|
182
|
+
xl: { columns: 6, gutter: 32 },
|
|
183
|
+
fallback: { columns: 1, gutter: 16 },
|
|
184
|
+
}, containerRef);
|
|
185
|
+
return (_jsx(Container, { children: _jsx(Stack, { vPadding: 32, rowGap: 32, fill: false, ref: containerRef, children: _jsx("div", { style: { paddingTop: '12px' }, children: _jsx(Grid, { rowGap: value.gutter, columnGap: value.gutter, columns: value.columns, filling: false, children: Array.from({ length: 5 }).map((_, i) => (
|
|
186
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
187
|
+
_jsx(Grid.Item, { children: _jsx(ProductCard, { ...args }) }, i))) }) }) }) }));
|
|
188
|
+
};
|
|
173
189
|
ExpandableKpisInGrid.args = {
|
|
174
190
|
...ExpandableKpis.args,
|
|
191
|
+
overlayActions: GridOverlayButtons,
|
|
175
192
|
};
|
|
@@ -78,6 +78,33 @@ describe('<ProductCard>', () => {
|
|
|
78
78
|
expect(cover()).not.toBeNull();
|
|
79
79
|
expect(coloredCover()).toBeNull();
|
|
80
80
|
});
|
|
81
|
+
test('it should hide the KPIs and lock the card while the overlay actions are open, only when the overlay is available', () => {
|
|
82
|
+
const overlayActions = _jsx("button", { type: "button", children: "Action" });
|
|
83
|
+
const { container, rerender } = render(_jsx(ProductCard, { title: "title", rating: 4.3, overlayActions: overlayActions }));
|
|
84
|
+
const card = () => container.querySelector('[data-card-locked]');
|
|
85
|
+
const cover = () => container.querySelector('[data-inner-element="ProductCard-Cover"]');
|
|
86
|
+
const kpis = () => container.querySelector('[data-inner-element="ProductCard-KpisCollapse"]');
|
|
87
|
+
expect(card().getAttribute('data-card-overlay-open')).toBe('false');
|
|
88
|
+
expect(kpis().getAttribute('data-kpis-hidden')).toBe('false');
|
|
89
|
+
fireEvent.mouseEnter(cover());
|
|
90
|
+
expect(card().getAttribute('data-card-overlay-open')).toBe('true');
|
|
91
|
+
expect(card().getAttribute('data-card-locked')).toBe('true');
|
|
92
|
+
expect(kpis().getAttribute('data-kpis-hidden')).toBe('true');
|
|
93
|
+
expect(kpis().getAttribute('aria-hidden')).toBe('true');
|
|
94
|
+
fireEvent.mouseLeave(cover());
|
|
95
|
+
expect(card().getAttribute('data-card-overlay-open')).toBe('false');
|
|
96
|
+
expect(kpis().getAttribute('data-kpis-hidden')).toBe('false');
|
|
97
|
+
expect(card().getAttribute('data-card-locked')).toBe('true');
|
|
98
|
+
const transitionEnd = createEvent.transitionEnd(kpis());
|
|
99
|
+
Object.defineProperty(transitionEnd, 'propertyName', { value: 'grid-template-rows' });
|
|
100
|
+
fireEvent(kpis(), transitionEnd);
|
|
101
|
+
expect(card().getAttribute('data-card-locked')).toBe('false');
|
|
102
|
+
rerender(_jsx(ProductCard, { title: "title", rating: 4.3, overlayActions: overlayActions, onClick: jest.fn() }));
|
|
103
|
+
fireEvent.mouseEnter(cover());
|
|
104
|
+
expect(card().getAttribute('data-card-overlay-open')).toBe('false');
|
|
105
|
+
expect(card().getAttribute('data-card-locked')).toBe('false');
|
|
106
|
+
expect(kpis().getAttribute('data-kpis-hidden')).toBe('false');
|
|
107
|
+
});
|
|
81
108
|
test('it should render the footer separator only with a footer or while loading', () => {
|
|
82
109
|
const { container, rerender } = render(_jsx(ProductCard, { title: "title" }));
|
|
83
110
|
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.5.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.5.0",
|
|
85
|
+
"@wonderflow/tokens": "17.5.0",
|
|
86
|
+
"@wonderflow/charts": "17.5.0",
|
|
87
87
|
"@types/uuid": "9.0.8",
|
|
88
88
|
"babel-loader": "8.2.5",
|
|
89
89
|
"cpy-cli": "3.1.1",
|