@antscorp/antsomi-ui 1.3.5-beta.576 → 1.3.5-beta.577

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.
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  // Libraries
13
- import React, { memo, useEffect, useMemo, useState } from 'react';
13
+ import React, { memo, useEffect, useMemo, useRef, useState } from 'react';
14
14
  import classNames from 'classnames';
15
15
  // Styled
16
16
  import { BannerWrapper } from './styled';
@@ -18,12 +18,15 @@ import { BannerWrapper } from './styled';
18
18
  import { MobileFrameV2 } from '@antscorp/antsomi-ui/es/components/atoms';
19
19
  // Constants
20
20
  import { DEVICE_TYPE } from '../../constants';
21
+ // Hooks
22
+ import { useForceUpdate } from '@antscorp/antsomi-ui/es/hooks';
21
23
  export const Banner = memo(props => {
22
- const { deviceType, showSkeleton = false, children, height } = props, restOfProps = __rest(props, ["deviceType", "showSkeleton", "children", "height"]);
24
+ var _a;
25
+ const { deviceType, showSkeleton = false, children, height = 700 } = props, restOfProps = __rest(props, ["deviceType", "showSkeleton", "children", "height"]);
26
+ const ref = useRef(null);
27
+ const forceUpdate = useForceUpdate();
23
28
  const isMobile = useMemo(() => deviceType === DEVICE_TYPE.MOBILE.value, [deviceType]);
24
- // States
25
29
  const [shouldAnimate, setShouldAnimate] = useState(false);
26
- // Side effects
27
30
  useEffect(() => {
28
31
  setShouldAnimate(true);
29
32
  const timerId = setTimeout(() => {
@@ -31,7 +34,26 @@ export const Banner = memo(props => {
31
34
  }, 1000);
32
35
  return () => clearTimeout(timerId);
33
36
  }, [children]);
34
- return (React.createElement(BannerWrapper, Object.assign({ "$height": height }, restOfProps),
37
+ useEffect(() => {
38
+ let timeoutAfterChange = null;
39
+ const handleResize = () => {
40
+ if (timeoutAfterChange) {
41
+ clearTimeout(timeoutAfterChange);
42
+ }
43
+ timeoutAfterChange = setTimeout(() => {
44
+ forceUpdate();
45
+ }, 0);
46
+ };
47
+ const resizeObserver = new ResizeObserver(handleResize);
48
+ if (ref === null || ref === void 0 ? void 0 : ref.current)
49
+ resizeObserver.observe(ref === null || ref === void 0 ? void 0 : ref.current);
50
+ return () => {
51
+ if (timeoutAfterChange) {
52
+ clearTimeout(timeoutAfterChange);
53
+ }
54
+ };
55
+ }, [forceUpdate]);
56
+ return (React.createElement(BannerWrapper, Object.assign({ ref: ref, "$height": height, clientHeight: (_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.offsetHeight }, restOfProps),
35
57
  React.createElement("div", { className: `${isMobile ? 'mobile-wrapper animate__animated animate__zoomIn' : 'desktop-wrapper'}` },
36
58
  React.createElement("div", { className: classNames({
37
59
  'content-wrapper': true,
@@ -1,3 +1,4 @@
1
1
  export declare const BannerWrapper: import("styled-components").StyledComponent<"div", any, {
2
- $height?: number | undefined;
2
+ $height: number | string;
3
+ clientHeight?: number | undefined;
3
4
  }, never>;
@@ -1,4 +1,6 @@
1
+ // Libraries
1
2
  import styled, { css } from 'styled-components';
3
+ import { isNumber } from 'lodash';
2
4
  // Images
3
5
  import skeletonBackground from '../../../../../assets/images/background/skeleton-background.png';
4
6
  // Constants
@@ -14,14 +16,21 @@ export const BannerWrapper = styled.div `
14
16
  background-color: ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.colorBgSkeleton};
15
17
  border-radius: ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.borderRadius}px;
16
18
  border: 1px solid ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.blue1_1};
17
- height: ${props => props.$height || 700}px;
19
+ height: ${({ $height }) => (isNumber($height) ? `${$height}px` : $height)};
18
20
 
19
21
  // Calculate scale of mobile frame
20
22
  #banner-mobile {
21
- ${props => {
22
- const height = props.$height || 700;
23
- const smallScale = (height - 10) / (MOBILE_VIEWPORT.MD.height + 36);
24
- const largeScale = (height - 10) / (MOBILE_VIEWPORT.LG.height + 36);
23
+ ${({ clientHeight }) => {
24
+ const [smallScale, largeScale] = (() => {
25
+ if (clientHeight) {
26
+ const bannerPadding = 5;
27
+ const margin = 18;
28
+ const smallScale = (clientHeight - bannerPadding * 2) / (MOBILE_VIEWPORT.MD.height + margin * 2);
29
+ const largeScale = (clientHeight - bannerPadding * 2) / (MOBILE_VIEWPORT.LG.height + margin * 2);
30
+ return [smallScale, largeScale];
31
+ }
32
+ return [1, 1];
33
+ })();
25
34
  return css `
26
35
  @media screen and (max-height: 1000px) {
27
36
  transform: scale(${smallScale});
@@ -34,37 +43,6 @@ export const BannerWrapper = styled.div `
34
43
  }}
35
44
  }
36
45
 
37
- /* ${props => props.$height
38
- ? css `
39
- height: ${props.$height}px;
40
-
41
- .mobile-wrapper {
42
- width: 359px;
43
- height: ${props.$height}px;
44
- }
45
- `
46
- : css `
47
- @media screen and (max-height: 1000px) {
48
- height: 760px;
49
- max-height: 760px;
50
-
51
- .mobile-wrapper {
52
- width: 359px;
53
- height: 722.41px;
54
- }
55
- }
56
-
57
- @media screen and (min-height: 1001px) {
58
- height: 830px;
59
- max-height: 830px;
60
-
61
- .mobile-wrapper {
62
- width: 380px;
63
- height: 800px;
64
- }
65
- }
66
- `} */
67
-
68
46
  .mobile-wrapper {
69
47
  position: relative;
70
48
  border-radius: 80px;
@@ -15,7 +15,8 @@ export interface PreviewTemplateModalProps extends ModalProps {
15
15
  export interface BannerProps extends React.HTMLAttributes<HTMLDivElement> {
16
16
  deviceType?: InformationProps['deviceType'];
17
17
  showSkeleton?: boolean;
18
- height?: number;
18
+ /** Type of height includes: number, px, %, vh */
19
+ height?: number | string;
19
20
  children?: React.ReactNode;
20
21
  }
21
22
  export type ThumbnailProps = Omit<ThumbnailCardProps, 'id' | 'name' | 'thumbnail' | 'onClickWrapper'> & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.576",
3
+ "version": "1.3.5-beta.577",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",