@trafilea/afrodita-components 6.2.0 → 6.3.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/build/index.d.ts CHANGED
@@ -72,7 +72,7 @@ declare type IconProps$1 = {
72
72
  className?: string;
73
73
  } & StyledIconProps;
74
74
 
75
- declare const Icon$1: React__default.FC<IconProps$1>;
75
+ declare const Icon$1: React__default.NamedExoticComponent<IconProps$1>;
76
76
 
77
77
  declare type Props$1 = Omit<IconProps$1, 'name'>;
78
78
  declare type IconComponent = React__default.FC<Props$1>;
@@ -3338,13 +3338,18 @@ declare const Spinner: React.FC<SpinnerProps>;
3338
3338
 
3339
3339
  declare const useOnClickOutside: <T extends HTMLElement = HTMLElement>(ref: RefObject<T>, handler: (event: Event) => void) => void;
3340
3340
 
3341
- declare const useWindowDimensions: (breakpoints: ThemeBreakpoints) => {
3341
+ declare type Viewport = 'mobile' | 'tablet' | 'desktop';
3342
+ declare type UseWindowDimensions = (breakpoints: ThemeBreakpoints, shouldListenChanges?: boolean) => {
3343
+ viewport: Viewport;
3342
3344
  isMobile: boolean;
3345
+ isTablet: boolean;
3346
+ isDesktop: boolean;
3343
3347
  windowDimensions: {
3344
3348
  width: number;
3345
3349
  height: number;
3346
3350
  };
3347
- };
3351
+ };
3352
+ declare const useWindowDimensions: UseWindowDimensions;
3348
3353
 
3349
3354
  declare global {
3350
3355
  interface Events {
@@ -3201,19 +3201,26 @@ var fetchWithCache = function (request, saveToCacheFn) {
3201
3201
  var createIconImage = function (_a) {
3202
3202
  var src = _a.src;
3203
3203
  return __awaiter(void 0, void 0, void 0, function () {
3204
- var blob, localUrl_1, cleanup, error_1;
3204
+ var localUrl, error_1;
3205
3205
  return __generator(this, function (_b) {
3206
3206
  switch (_b.label) {
3207
3207
  case 0:
3208
3208
  _b.trys.push([0, 2, , 3]);
3209
- return [4 /*yield*/, fetchWithCache(src, function (response) { return response.blob(); })];
3209
+ return [4 /*yield*/, fetchWithCache(src, function (response) { return __awaiter(void 0, void 0, void 0, function () {
3210
+ var blob;
3211
+ return __generator(this, function (_a) {
3212
+ switch (_a.label) {
3213
+ case 0: return [4 /*yield*/, response.blob()];
3214
+ case 1:
3215
+ blob = _a.sent();
3216
+ return [2 /*return*/, URL.createObjectURL(blob)];
3217
+ }
3218
+ });
3219
+ }); })];
3210
3220
  case 1:
3211
- blob = _b.sent();
3212
- localUrl_1 = URL.createObjectURL(blob);
3213
- cleanup = function () { return URL.revokeObjectURL(localUrl_1); };
3221
+ localUrl = _b.sent();
3214
3222
  return [2 /*return*/, {
3215
- src: localUrl_1,
3216
- cleanup: cleanup,
3223
+ src: localUrl,
3217
3224
  }];
3218
3225
  case 2:
3219
3226
  error_1 = _b.sent();
@@ -3262,11 +3269,10 @@ var IconFromExtSource = function (_a) {
3262
3269
  if (!localSource) {
3263
3270
  fetchIcon();
3264
3271
  }
3265
- return localSource === null || localSource === void 0 ? void 0 : localSource.cleanup;
3266
- }, [iconURL, localSource === null || localSource === void 0 ? void 0 : localSource.cleanup]);
3272
+ }, [iconURL]);
3267
3273
  var imageProperties = __assign$1({ alt: title !== null && title !== void 0 ? title : name, 'data-testid': testId, height: height, width: width }, rest);
3268
3274
  if (error) {
3269
- return jsx$1(StyledImageWrapper, __assign$1({}, imageProperties, rest, { src: iconURL }), void 0);
3275
+ return jsx$1(StyledImageWrapper, __assign$1({}, imageProperties, { src: iconURL }), void 0);
3270
3276
  }
3271
3277
  if (!localSource) {
3272
3278
  return jsx$1(SkeletonBox, { width: width, height: height }, void 0);
@@ -3278,7 +3284,7 @@ var IconFromExtSource = function (_a) {
3278
3284
  };
3279
3285
 
3280
3286
  /* eslint-disable react/forbid-component-props */
3281
- var Icon$1 = function (_a) {
3287
+ var UnmemoIcon = function (_a) {
3282
3288
  var height = _a.height, _b = _a.width, width = _b === void 0 ? 1 : _b, title = _a.title, testId = _a.testId, fill = _a.fill, name = _a.name, svgProps = _a.svgProps, rest = __rest(_a, ["height", "width", "title", "testId", "fill", "name", "svgProps"]);
3283
3289
  var assets = useTheme().assets;
3284
3290
  var newWidth = width && getIconDimension(width);
@@ -3290,7 +3296,8 @@ var Icon$1 = function (_a) {
3290
3296
  return (jsxs$1(StyledSvgWrapper, __assign$1({ "data-testid": testId, fill: fill, height: newHeight, type: "image/svg+xml", width: newWidth }, rest, svgProps, { children: [jsx$1("title", { children: title !== null && title !== void 0 ? title : name }, void 0), jsx$1("use", { xlinkHref: "".concat(iconURL, "#").concat(svgId) }, void 0)] }), void 0));
3291
3297
  }
3292
3298
  return (jsx$1(IconFromExtSource, __assign$1({ svgId: svgId, iconURL: iconURL, testId: testId, fill: fill, height: newHeight, svgProps: svgProps, width: newWidth, name: name, title: title }, rest), void 0));
3293
- };
3299
+ };
3300
+ var Icon$1 = React__default.memo(UnmemoIcon, function (prevProps, nextProps) { return prevProps.name !== nextProps.name; });
3294
3301
 
3295
3302
  var Add = function (props) { return jsx$1(Icon$1, __assign$1({}, props, { name: "actions/add" }), void 0); };
3296
3303
 
@@ -5209,28 +5216,60 @@ var DiscountTag = function (_a) {
5209
5216
  };
5210
5217
  var templateObject_1$1A, templateObject_2$10;
5211
5218
 
5219
+ //TODO Move this to types with ThemeBreakpoints
5220
+ var Viewports = {
5221
+ mobile: 'mobile',
5222
+ tablet: 'tablet',
5223
+ desktop: 'desktop',
5224
+ };
5212
5225
  function getWindowDimensions() {
5226
+ if (typeof window === 'undefined')
5227
+ return { width: 0, height: 0 };
5213
5228
  var width = window.innerWidth, height = window.innerHeight;
5214
5229
  return {
5215
5230
  width: width,
5216
5231
  height: height,
5217
5232
  };
5218
5233
  }
5219
- var useWindowDimensions = function (breakpoints) {
5220
- var _a = useState({ width: 0, height: 0 }), windowDimensions = _a[0], setWindowDimensions = _a[1];
5234
+ var getViewport = function (breakpoints, width) {
5235
+ if (width <= breakpoints.mobile)
5236
+ return Viewports.mobile;
5237
+ if (breakpoints.tablet && width <= breakpoints.tablet) {
5238
+ return Viewports.tablet;
5239
+ }
5240
+ return Viewports.desktop;
5241
+ };
5242
+ var useWindowDimensions = function (breakpoints, shouldListenChanges) {
5243
+ var _a = useState(function () {
5244
+ var dimension = getWindowDimensions();
5245
+ return {
5246
+ windowDimensions: dimension,
5247
+ viewport: getViewport(breakpoints, dimension.width),
5248
+ };
5249
+ }), state = _a[0], setState = _a[1];
5221
5250
  useEffect(function () {
5222
5251
  function handleResize() {
5223
- setWindowDimensions(getWindowDimensions());
5252
+ var newDimension = getWindowDimensions();
5253
+ var newViewport = getViewport(breakpoints, newDimension.width);
5254
+ setState(function (oldState) {
5255
+ if (shouldListenChanges || oldState.viewport !== newViewport) {
5256
+ return {
5257
+ windowDimensions: newDimension,
5258
+ viewport: newViewport,
5259
+ };
5260
+ }
5261
+ return oldState;
5262
+ });
5224
5263
  }
5225
- // calling it here updates the dimensions on first render
5226
5264
  handleResize();
5227
5265
  window.addEventListener('resize', handleResize);
5228
5266
  return function () { return window.removeEventListener('resize', handleResize); };
5229
- }, []);
5230
- return {
5231
- isMobile: windowDimensions.width < breakpoints.desktop,
5232
- windowDimensions: windowDimensions,
5233
- };
5267
+ // eslint-disable-next-line react-hooks/exhaustive-deps
5268
+ }, [shouldListenChanges]);
5269
+ var isMobile = state.viewport === Viewports.mobile;
5270
+ var isTablet = state.viewport === Viewports.tablet;
5271
+ var isDesktop = state.viewport === Viewports.desktop;
5272
+ return __assign$1(__assign$1({}, state), { isMobile: isMobile, isTablet: isTablet, isDesktop: isDesktop });
5234
5273
  };
5235
5274
 
5236
5275
  var getStylesBySize$c = function (size, theme) {
@@ -13701,9 +13740,9 @@ var range = function (limit) { return __spreadArray([], new Array(limit), true).
13701
13740
  var SlideDots = function (_a) {
13702
13741
  var quantity = _a.quantity, selectedIndex = _a.selectedIndex, containerDataTestId = _a.containerDataTestId;
13703
13742
  var theme = useTheme();
13704
- return (jsx$1(Container$u, __assign$1({ "data-testid": containerDataTestId }, { children: range(quantity).map(function (index) { return (jsx$1(Icon.SlideDots.SlideDot, { height: 0.75, width: 0.75, fill: index === selectedIndex
13743
+ return (jsx$1(Container$u, __assign$1({ "data-testid": containerDataTestId }, { children: range(quantity).map(function (index) { return (jsx$1(Icon$1, { name: "navigation/slide_dot".concat(index === selectedIndex ? '_solid' : ''), height: 0.75, width: 0.75, fill: index === selectedIndex
13705
13744
  ? theme.component.slideNavigation.slideDots.selectedDotColor
13706
- : theme.component.slideNavigation.slideDots.unselectedDotColor, opacity: theme.component.slideNavigation.slideDots.dotsOpacity, testId: "slide-dot-".concat(index) }, index)); }) }), void 0));
13745
+ : theme.component.slideNavigation.slideDots.unselectedDotColor, opacity: theme.component.slideNavigation.slideDots.dotsOpacity, testId: "slide-dot-".concat(index) }, "Icon-".concat(index, "-navigation/slide_dot").concat(index === selectedIndex ? '_solid' : ''))); }) }), void 0));
13707
13746
  };
13708
13747
  var templateObject_1$E;
13709
13748
 
@@ -19201,7 +19240,7 @@ var getDefaultCountdown = function () {
19201
19240
  var HurryUp = function (_a) {
19202
19241
  var hurryUpText = _a.hurryUpText, backgroundColor = _a.backgroundColor, _b = _a.iconSize, iconSize = _b === void 0 ? 1.5 : _b, _c = _a.textPosition, textPosition = _c === void 0 ? 'center' : _c, _d = _a.showTimer, showTimer = _d === void 0 ? false : _d, _e = _a.clockPosition, clockPosition = _e === void 0 ? 'left' : _e, _f = _a.countdown, countdown = _f === void 0 ? getDefaultCountdown() : _f, timerProps = __rest(_a, ["hurryUpText", "backgroundColor", "iconSize", "textPosition", "showTimer", "clockPosition", "countdown"]);
19203
19242
  var theme = useTheme();
19204
- return (jsxs$1(TimerContainer, __assign$1({ backgroundColor: backgroundColor || theme.component.card.backgroundColor, textPosition: textPosition, borderRadius: theme.component.hurryUp.borderRadius, "data-testid": "HurryUp" }, { children: [clockPosition === 'left' && (jsxs$1(Fragment$2, { children: [jsx$1(Icon.PDP.Stopwatch, { width: iconSize, height: iconSize, fill: theme.colors.pallete.secondary.color }, void 0), "\u00A0"] }, void 0)), jsx$1(Text$8, __assign$1({ testId: "HurryUpText", variant: "body", size: "small", weight: "demi" }, { children: hurryUpText }), void 0), clockPosition === 'right' && (jsxs$1(Fragment$2, { children: [jsx$1(Icon.PDP.Stopwatch, { width: iconSize, height: iconSize, fill: theme.colors.pallete.secondary.color }, void 0), "\u00A0"] }, void 0)), showTimer && jsx$1(Timer, __assign$1({ countdown: countdown, onTimeUp: function () { } }, timerProps), void 0)] }), void 0));
19243
+ return (jsxs$1(TimerContainer, __assign$1({ backgroundColor: backgroundColor || theme.component.card.backgroundColor, textPosition: textPosition, borderRadius: theme.component.hurryUp.borderRadius, "data-testid": "HurryUp" }, { children: [clockPosition === 'left' && (jsxs$1(Fragment$2, { children: [jsx$1(Icon.PDP.Stopwatch, { width: iconSize, height: iconSize, fill: theme.colors.pallete.secondary.color }, void 0), "\u00A0"] }, void 0)), jsx$1(Text$8, __assign$1({ testId: "HurryUpText", variant: "body", size: "small", weight: "demi" }, { children: hurryUpText }), void 0), "\u00A0", clockPosition === 'right' && (jsxs$1(Fragment$2, { children: [jsx$1(Icon.PDP.Stopwatch, { width: iconSize, height: iconSize, fill: theme.colors.pallete.secondary.color }, void 0), "\u00A0"] }, void 0)), showTimer && jsx$1(Timer, __assign$1({ countdown: countdown, onTimeUp: function () { } }, timerProps), void 0)] }), void 0));
19205
19244
  };
19206
19245
 
19207
19246
  var Container = newStyled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: ", ";\n height: ", ";\n svg {\n vertical-align: unset;\n }\n"], ["\n width: ", ";\n height: ", ";\n svg {\n vertical-align: unset;\n }\n"])), function (_a) {