From f8ae1842a3422df1ac5a620a946d4840356f3032 Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 24 Mar 2022 02:55:48 -0400 Subject: [PATCH] Add components --- src/api/utils/DoElementsOverlap.ts | 10 ++++++ src/api/utils/index.ts | 1 + .../layout/LayoutFurniIconImageView.tsx | 35 +++++++++++++++++++ src/common/layout/index.ts | 1 + 4 files changed, 47 insertions(+) create mode 100644 src/api/utils/DoElementsOverlap.ts create mode 100644 src/common/layout/LayoutFurniIconImageView.tsx diff --git a/src/api/utils/DoElementsOverlap.ts b/src/api/utils/DoElementsOverlap.ts new file mode 100644 index 00000000..f28b0c86 --- /dev/null +++ b/src/api/utils/DoElementsOverlap.ts @@ -0,0 +1,10 @@ +export const DoElementsOverlap = (a: HTMLElement, b: HTMLElement) => +{ + const rectA = a.getBoundingClientRect(); + const rectB = b.getBoundingClientRect(); + + const ox = Math.abs(rectA.x - rectB.x) < (rectA.x < rectB.x ? rectB.width : rectA.width); + const oy = Math.abs(rectA.y - rectB.y) < (rectA.y < rectB.y ? rectB.height : rectA.height); + + return (ox && oy); +} diff --git a/src/api/utils/index.ts b/src/api/utils/index.ts index 398758cb..c63244a6 100644 --- a/src/api/utils/index.ts +++ b/src/api/utils/index.ts @@ -1,5 +1,6 @@ export * from './CloneObject'; export * from './ColorUtils'; +export * from './DoElementsOverlap'; export * from './LocalizeBadgeDescription'; export * from './LocalizeBageName'; export * from './LocalizeFormattedNumber'; diff --git a/src/common/layout/LayoutFurniIconImageView.tsx b/src/common/layout/LayoutFurniIconImageView.tsx new file mode 100644 index 00000000..c961d66f --- /dev/null +++ b/src/common/layout/LayoutFurniIconImageView.tsx @@ -0,0 +1,35 @@ +import { FC } from 'react'; +import { LayoutImage, LayoutImageProps } from '.'; +import { GetRoomEngine } from '../../api'; +import { ProductTypeEnum } from '../../components/catalog/common/ProductTypeEnum'; + +interface LayoutFurniIconImageViewProps extends LayoutImageProps +{ + productType: string; + productClassId: number; + extraData?: string; +} + +export const LayoutFurniIconImageView: FC = props => +{ + const { productType = 's', productClassId = -1, extraData = '', ...rest } = props; + + const getImageIconUrl = () => + { + let imageUrl: string = null; + + switch(productType.toLocaleLowerCase()) + { + case ProductTypeEnum.FLOOR: + imageUrl = GetRoomEngine().getFurnitureFloorIconUrl(productClassId); + break; + case ProductTypeEnum.WALL: + imageUrl = GetRoomEngine().getFurnitureWallIconUrl(productClassId, extraData); + break; + } + + return imageUrl; + } + + return ; +} diff --git a/src/common/layout/index.ts b/src/common/layout/index.ts index 1d7beea2..a7bdd15c 100644 --- a/src/common/layout/index.ts +++ b/src/common/layout/index.ts @@ -2,6 +2,7 @@ export * from './LayoutAvatarImageView'; export * from './LayoutBackgroundImage'; export * from './LayoutBadgeImageView'; export * from './LayoutCurrencyIcon'; +export * from './LayoutFurniIconImageView'; export * from './LayoutFurniImageView'; export * from './LayoutGiftTagView'; export * from './LayoutGridItem';