myshell-react-lib 0.1.4 → 0.1.6

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.
Files changed (147) hide show
  1. package/dist/index.cjs +52 -3
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +8 -2
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -2
  8. package/src/common/assets/audio-playing.json +0 -3657
  9. package/src/common/constants/constants.ts +0 -24
  10. package/src/common/constants/types/common.ts +0 -10
  11. package/src/common/hooks/useAudioPlayer.tsx +0 -198
  12. package/src/common/hooks/useDevice.ts +0 -26
  13. package/src/common/hooks/useNativeBridge.ts +0 -42
  14. package/src/common/hooks/useNotification.tsx +0 -179
  15. package/src/common/hooks/useWindowWidth.ts +0 -19
  16. package/src/common/utils/common-helper.ts +0 -81
  17. package/src/components/ItemDemo.tsx +0 -15
  18. package/src/components/accordion.tsx +0 -126
  19. package/src/components/alert-dialog.tsx +0 -148
  20. package/src/components/alert.tsx +0 -65
  21. package/src/components/aspect-ratio.tsx +0 -7
  22. package/src/components/audio-player.tsx +0 -60
  23. package/src/components/audio-playing.tsx +0 -33
  24. package/src/components/avatar.tsx +0 -133
  25. package/src/components/badge.tsx +0 -67
  26. package/src/components/button/button.styles.ts +0 -258
  27. package/src/components/button/button.tsx +0 -215
  28. package/src/components/button/icon-button.styles.ts +0 -101
  29. package/src/components/button/icon-button.tsx +0 -100
  30. package/src/components/button/index.tsx +0 -3
  31. package/src/components/button/link-button.tsx +0 -184
  32. package/src/components/cascader.tsx +0 -175
  33. package/src/components/checkbox.tsx +0 -135
  34. package/src/components/command.tsx +0 -155
  35. package/src/components/context-menu.tsx +0 -198
  36. package/src/components/count-down.tsx +0 -83
  37. package/src/components/custom-notification.tsx +0 -95
  38. package/src/components/dialog.tsx +0 -158
  39. package/src/components/drawer.tsx +0 -116
  40. package/src/components/dropdown-menu.tsx +0 -196
  41. package/src/components/energy-progress.tsx +0 -55
  42. package/src/components/form.tsx +0 -201
  43. package/src/components/group.tsx +0 -9
  44. package/src/components/guide.tsx +0 -243
  45. package/src/components/icon.tsx +0 -96
  46. package/src/components/icons/index.tsx +0 -13
  47. package/src/components/icons/outline/ArrowLeftIcon.tsx +0 -28
  48. package/src/components/icons/outline/ArrowUpTrayIcon.tsx +0 -28
  49. package/src/components/icons/outline/CheckCircleIcon.tsx +0 -27
  50. package/src/components/icons/outline/ConfigIcon.tsx +0 -42
  51. package/src/components/icons/outline/DownIcon.tsx +0 -18
  52. package/src/components/icons/outline/FilterIcon.tsx +0 -20
  53. package/src/components/icons/outline/PencilSquareIcon.tsx +0 -28
  54. package/src/components/icons/outline/WindowIcon.tsx +0 -26
  55. package/src/components/icons/solid/CaretDownIcon.tsx +0 -22
  56. package/src/components/icons/solid/CodeIcon.tsx +0 -25
  57. package/src/components/icons/solid/DragIcon.tsx +0 -24
  58. package/src/components/icons/solid/PhoneIcon.tsx +0 -29
  59. package/src/components/icons/solid/RectangleGroupIcon.tsx +0 -26
  60. package/src/components/image.tsx +0 -151
  61. package/src/components/input.tsx +0 -118
  62. package/src/components/label.tsx +0 -26
  63. package/src/components/link.tsx +0 -123
  64. package/src/components/marquee/index.css +0 -15
  65. package/src/components/marquee/marquee.tsx +0 -220
  66. package/src/components/masonry.tsx +0 -138
  67. package/src/components/menubar.tsx +0 -234
  68. package/src/components/mobile/m-tooltip.tsx +0 -34
  69. package/src/components/modal.tsx +0 -561
  70. package/src/components/navigation-bar.tsx +0 -100
  71. package/src/components/number-input.tsx +0 -143
  72. package/src/components/page-content.tsx +0 -16
  73. package/src/components/popover.tsx +0 -191
  74. package/src/components/progress.tsx +0 -80
  75. package/src/components/radio-group.tsx +0 -44
  76. package/src/components/scroll-area.tsx +0 -49
  77. package/src/components/search-bar.tsx +0 -140
  78. package/src/components/secondary-navigation-bar.tsx +0 -328
  79. package/src/components/select.tsx +0 -273
  80. package/src/components/separator.tsx +0 -31
  81. package/src/components/sheet.tsx +0 -143
  82. package/src/components/skeleton.tsx +0 -20
  83. package/src/components/slider.tsx +0 -160
  84. package/src/components/spinner.tsx +0 -50
  85. package/src/components/swiper/index.module.scss +0 -88
  86. package/src/components/swiper/index.tsx +0 -319
  87. package/src/components/switch.tsx +0 -67
  88. package/src/components/tabs.tsx +0 -325
  89. package/src/components/textarea.tsx +0 -71
  90. package/src/components/toast/toast.tsx +0 -182
  91. package/src/components/toast/toaster.tsx +0 -160
  92. package/src/components/toast/use-toast.tsx +0 -248
  93. package/src/components/toggle-group.tsx +0 -64
  94. package/src/components/toggle.tsx +0 -46
  95. package/src/components/tooltip.tsx +0 -283
  96. package/src/components/typography.tsx +0 -437
  97. package/src/index.ts +0 -70
  98. package/src/lib/utils.ts +0 -62
  99. package/src/stories/Accordion.stories.tsx +0 -64
  100. package/src/stories/AccordionItem.stories.tsx +0 -48
  101. package/src/stories/Avatar.stories.ts +0 -58
  102. package/src/stories/Badge.stories.tsx +0 -40
  103. package/src/stories/BannerSwiper.stories.tsx +0 -102
  104. package/src/stories/Button.stories.tsx +0 -543
  105. package/src/stories/Checkbox.stories.tsx +0 -161
  106. package/src/stories/Configure.mdx +0 -341
  107. package/src/stories/CssProperties.mdx +0 -30
  108. package/src/stories/Description.stories.ts +0 -70
  109. package/src/stories/Display.stories.ts +0 -64
  110. package/src/stories/FeaturedSwiper.stories.tsx +0 -6978
  111. package/src/stories/GridSwiper.stories.tsx +0 -1407
  112. package/src/stories/Guide.stories.tsx +0 -247
  113. package/src/stories/Heading.stories.ts +0 -89
  114. package/src/stories/Icon.stories.ts +0 -77
  115. package/src/stories/IconButton.stories.tsx +0 -301
  116. package/src/stories/IconTextButton.stories.ts +0 -59
  117. package/src/stories/Image.stories.ts +0 -55
  118. package/src/stories/Input.stories.tsx +0 -203
  119. package/src/stories/Modal.stories.tsx +0 -144
  120. package/src/stories/NavigationBar.stories.tsx +0 -81
  121. package/src/stories/Notification.stories.tsx +0 -276
  122. package/src/stories/Popover.stories.tsx +0 -100
  123. package/src/stories/SearchBar.stories.ts +0 -43
  124. package/src/stories/SecondaryNavigationBar.stories.tsx +0 -199
  125. package/src/stories/Select.stories.tsx +0 -107
  126. package/src/stories/Separator.stories.tsx +0 -49
  127. package/src/stories/Spinner.stories.tsx +0 -48
  128. package/src/stories/SubHeading.stories.ts +0 -64
  129. package/src/stories/Swich.stories.tsx +0 -69
  130. package/src/stories/Tabs.stories.tsx +0 -90
  131. package/src/stories/Text.stories.ts +0 -78
  132. package/src/stories/Textarea.stories.tsx +0 -155
  133. package/src/stories/Toast.stories.tsx +0 -424
  134. package/src/stories/Tooltip.stories.tsx +0 -244
  135. package/src/stories/ViewAutoSwiper.stories.tsx +0 -1408
  136. package/src/styles/components-dark.scss +0 -212
  137. package/src/styles/components-light.scss +0 -210
  138. package/src/styles/design-dark.scss +0 -330
  139. package/src/styles/design-light.scss +0 -345
  140. package/src/styles/design2-dark.scss +0 -319
  141. package/src/styles/design2-light.scss +0 -364
  142. package/src/styles/font.css +0 -19
  143. package/src/styles/global.scss +0 -251
  144. package/src/styles/md-viewer.scss +0 -155
  145. package/src/styles/new-tokens.scss +0 -255
  146. package/src/styles/tokens.scss +0 -401
  147. package/src/types/scss.d.ts +0 -24
@@ -1,118 +0,0 @@
1
- import { cva } from 'class-variance-authority';
2
- import * as React from 'react';
3
-
4
- import { cn } from '@/lib/utils';
5
-
6
- export type InputProps = Omit<
7
- React.InputHTMLAttributes<HTMLInputElement>,
8
- 'size'
9
- > & {
10
- rounded?:
11
- | 'default'
12
- | 'none'
13
- | 'sm'
14
- | 'md'
15
- | 'lg'
16
- | 'xl'
17
- | '2xl'
18
- | '3xl'
19
- | 'full'
20
- | null
21
- | undefined;
22
- size?: 'xs' | 'sm' | 'md' | 'lg' | null | undefined;
23
- isFull?: boolean;
24
- border?: 'none' | 'default' | null | undefined;
25
- shadow?: 'none' | 'default' | null | undefined;
26
- outline?: 'none' | 'default' | null | undefined;
27
- background?: 'none' | 'default' | null | undefined;
28
- };
29
-
30
- const Input = React.forwardRef<HTMLInputElement, InputProps>(
31
- (
32
- {
33
- className,
34
- type,
35
- autoComplete = 'off',
36
- isFull = true,
37
- rounded = 'lg',
38
- size = 'sm',
39
- border = 'default',
40
- outline = 'default',
41
- background = 'default',
42
- shadow = 'default',
43
- ...props
44
- },
45
- ref
46
- ) => {
47
- const { readOnly } = props;
48
-
49
- const inputVariants = cva('', {
50
- variants: {
51
- rounded: {
52
- none: 'rounded-none',
53
- sm: 'rounded-sm',
54
- default: 'rounded',
55
- md: 'rounded-md',
56
- lg: 'rounded-lg',
57
- xl: 'rounded-xl',
58
- '2xl': 'rounded-2xl',
59
- '3xl': 'rounded-3xl',
60
- full: 'rounded-full',
61
- },
62
- size: {
63
- lg: 'h-14',
64
- md: 'h-11',
65
- sm: 'h-10',
66
- xs: 'h-9',
67
- },
68
- border: {
69
- none: 'border-none shadow-none',
70
- default: 'border border-cc-Input-border-default ',
71
- },
72
- outline: {
73
- none: 'outline-none',
74
- default:
75
- 'focus-visible:outline-none aria-[invalid=true]:focus-visible:ring-error focus-visible:ring-2 focus-visible:ring-cc-Focus-Rings-Brand-default focus-visible:ring-offset-0',
76
- },
77
- background: {
78
- none: 'bg-transparent',
79
- default:
80
- 'bg-cc-Input-bg-default hover:bg-cc-Input-bg-hover disabled:bg-cc-Input-bg-disabled',
81
- },
82
- shadow: {
83
- none: 'shadow-none',
84
- default: '',
85
- },
86
- },
87
- defaultVariants: {
88
- rounded: 'lg',
89
- size: 'sm',
90
- border: 'default',
91
- outline: 'default',
92
- background: 'default',
93
- },
94
- });
95
-
96
- return (
97
- <input
98
- type={type}
99
- className={cn(
100
- 'flex space-x-2 p-3 text-base text-Colors-Text-Default placeholder:text-Colors-Text-Subtlest ring-offset-cc-Focus-Rings-Brand-default',
101
- 'aria-[invalid=true]:border-Colors-Border-Critical aria-[invalid=true]:hover:bg-Colors-Background-Critical-Subtle',
102
- 'file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:cursor-not-allowed disabled:opacity-30',
103
- inputVariants({ rounded, size, border, outline, background, shadow }),
104
- readOnly &&
105
- 'focus-visible:ring-offset-0 focus-visible:ring-transparent',
106
- isFull && 'w-full',
107
- className
108
- )}
109
- autoComplete={autoComplete}
110
- ref={ref}
111
- {...props}
112
- />
113
- );
114
- }
115
- );
116
- Input.displayName = 'Input';
117
-
118
- export { Input };
@@ -1,26 +0,0 @@
1
- 'use client';
2
-
3
- import * as LabelPrimitive from '@radix-ui/react-label';
4
- import { cva, type VariantProps } from 'class-variance-authority';
5
- import * as React from 'react';
6
-
7
- import { cn } from '@/lib/utils';
8
-
9
- const labelVariants = cva(
10
- 'text-sm font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-30'
11
- );
12
-
13
- const Label = React.forwardRef<
14
- React.ElementRef<typeof LabelPrimitive.Root>,
15
- React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
16
- VariantProps<typeof labelVariants>
17
- >(({ className, ...props }, ref) => (
18
- <LabelPrimitive.Root
19
- ref={ref}
20
- className={cn(labelVariants(), className)}
21
- {...props}
22
- />
23
- ));
24
- Label.displayName = LabelPrimitive.Root.displayName;
25
-
26
- export { Label };
@@ -1,123 +0,0 @@
1
- import LinkComponent from 'next/link';
2
- import { useMemo } from 'react';
3
-
4
- import { useNativeBridge } from '@/common/hooks/useNativeBridge';
5
- import { isClient, isIosApp } from '@/common/utils/common-helper';
6
-
7
- import { UrlObject } from 'url';
8
- import { useMedia } from 'react-use';
9
-
10
- export interface LinkProps {
11
- /**
12
- * 跳转地址
13
- * '/about'
14
- * {
15
- * pathname: '/about',
16
- query: { name: 'test' },
17
- * }
18
- */
19
- href: string | UrlObject;
20
- /**
21
- * 图像宽度
22
- * string | number
23
- */
24
- scroll?: boolean;
25
-
26
- /**
27
- * 替换url
28
- */
29
- replace?: boolean;
30
- /**
31
- * true:进入视区预先获取herf数据
32
- * false:进入视区不获取,悬浮时获取
33
- */
34
- prefetch?: boolean;
35
- /**
36
- * Forces `Link` to send the `href` property to its child.
37
- *
38
- * @defaultValue `false`
39
- */
40
- passHref?: boolean;
41
- /**
42
- * 样式覆盖
43
- */
44
- className?: string;
45
- /**
46
- * 是否是返回link
47
- */
48
- back?: boolean;
49
- onClick?: (e: any) => void;
50
- children?: React.ReactNode;
51
- [key: string]: any;
52
- }
53
-
54
- export function Link({
55
- className,
56
- href,
57
- scroll = false,
58
- replace = false,
59
- prefetch = true,
60
- back = false,
61
- children,
62
- onClick,
63
- ...props
64
- }: LinkProps) {
65
- const path = typeof href === 'string' ? href : `${href.pathname}`;
66
- // ref:外链添加nofollow,noreferrer,告诉搜索引擎不要抓取以免降低自身站点权重;内链添加dofollow标签,保证权重的传递
67
- const externalLink = /^(https?:\/\/)/.test(path);
68
- const { getIosUrl, nativeGoBack } = useNativeBridge();
69
- const isIos = isClient() && isIosApp();
70
- const isMobile = useMedia('(max-width: 768px)');
71
-
72
- // 通过url是否有platform参数判断是否是ios
73
- const pathname = useMemo(() => {
74
- // 站外链接直接返回
75
- if (externalLink) return path;
76
- // 白名单直接返回
77
- // if (
78
- // NotMatchWhitelist.some((whitelist: string) => path.startsWith(whitelist))
79
- // ) {
80
- // return path;
81
- // }
82
-
83
- let formatPath = path;
84
- // 统一做m&pc路由跳转优化
85
- const isMobPath = path.startsWith('/m/');
86
- if (isMobile) {
87
- formatPath = isMobPath ? path : `/m${path}`;
88
- } else {
89
- formatPath = isMobPath ? path.slice(2) : path;
90
- }
91
-
92
- return isIos ? getIosUrl(formatPath) || formatPath : formatPath;
93
- }, [path]);
94
-
95
- // 此处兼容ios跳转返回后失效问题
96
- const Com = isIos ? 'a' : LinkComponent;
97
-
98
- return (
99
- <Com
100
- href={pathname}
101
- scroll={scroll}
102
- replace={replace}
103
- prefetch={prefetch}
104
- onClick={(e) => {
105
- if (isIos && back) {
106
- e.stopPropagation();
107
- e.preventDefault();
108
- nativeGoBack();
109
- } else {
110
- onClick?.(e);
111
- }
112
- }}
113
- className={className}
114
- rel={externalLink ? 'nofollow,noreferrer' : 'dofollow'}
115
- target={externalLink ? '_blank' : undefined}
116
- {...props}
117
- >
118
- {children}
119
- </Com>
120
- );
121
- }
122
-
123
- export default Link;
@@ -1,15 +0,0 @@
1
- .ms-marquee-pause-hover:hover div{
2
- animation-play-state: paused !important;
3
- }
4
- .ms-marquee-pause-running:hover div{
5
- animation-play-state: running !important;
6
- }
7
-
8
- @keyframes scroll {
9
- 0% {
10
- transform: translateX(0%);
11
- }
12
- 100% {
13
- transform: translateX(-100%);
14
- }
15
- }
@@ -1,220 +0,0 @@
1
- /* eslint-disable import/no-unassigned-import */
2
- import React, {
3
- Fragment,
4
- useEffect,
5
- useState,
6
- useRef,
7
- useCallback,
8
- useMemo,
9
- ReactNode,
10
- CSSProperties,
11
- FC,
12
- forwardRef,
13
- Children,
14
- MutableRefObject,
15
- RefAttributes,
16
- } from 'react';
17
-
18
- import { cn } from '@/lib/utils';
19
-
20
- import './index.css';
21
-
22
- type MarqueeProps = {
23
- style?: CSSProperties;
24
- className?: string;
25
- autoFill?: boolean;
26
- play?: boolean;
27
- pauseOnHover?: boolean;
28
- direction?: 'left' | 'right' | 'up' | 'down';
29
- speed?: number;
30
- delay?: number;
31
- loop?: number;
32
- onFinish?: () => void;
33
- onCycleComplete?: () => void;
34
- children?: ReactNode;
35
- } & RefAttributes<HTMLDivElement>;
36
-
37
- const Marquee: FC<MarqueeProps> = forwardRef(function Marquee(
38
- {
39
- style = {},
40
- className = '',
41
- autoFill = false,
42
- play = true,
43
- pauseOnHover = false,
44
- direction = 'left',
45
- speed = 50,
46
- delay = 0,
47
- loop = 0,
48
- onFinish,
49
- onCycleComplete,
50
- children,
51
- },
52
- ref
53
- ) {
54
- const [containerWidth, setContainerWidth] = useState(0);
55
- const [marqueeWidth, setMarqueeWidth] = useState(0);
56
- const [multiplier, setMultiplier] = useState(1);
57
- const [isMounted, setIsMounted] = useState(false);
58
- const rootRef = useRef<HTMLDivElement>(null);
59
- const containerRef = (ref as MutableRefObject<HTMLDivElement>) || rootRef;
60
- const marqueeRef = useRef<HTMLDivElement>(null);
61
-
62
- const calculateWidth = useCallback(() => {
63
- if (marqueeRef.current && containerRef.current) {
64
- const containerRect = containerRef.current.getBoundingClientRect();
65
- const marqueeRect = marqueeRef.current.getBoundingClientRect();
66
- let containerWidth = containerRect.width;
67
- let marqueeWidth = marqueeRect.width;
68
-
69
- if (direction === 'up' || direction === 'down') {
70
- containerWidth = containerRect.height;
71
- marqueeWidth = marqueeRect.height;
72
- }
73
-
74
- if (autoFill && containerWidth && marqueeWidth) {
75
- setMultiplier(
76
- marqueeWidth < containerWidth
77
- ? Math.ceil(containerWidth / marqueeWidth)
78
- : 1
79
- );
80
- } else {
81
- setMultiplier(1);
82
- }
83
-
84
- setContainerWidth(containerWidth);
85
- setMarqueeWidth(marqueeWidth);
86
- }
87
- }, [autoFill, containerRef, direction]);
88
-
89
- useEffect(() => {
90
- if (!isMounted) return;
91
-
92
- calculateWidth();
93
- if (marqueeRef.current && containerRef.current) {
94
- const resizeObserver = new ResizeObserver(() => calculateWidth());
95
- resizeObserver.observe(containerRef.current);
96
- resizeObserver.observe(marqueeRef.current);
97
-
98
- return () => {
99
- if (!resizeObserver) return;
100
- resizeObserver.disconnect();
101
- };
102
- }
103
- }, [calculateWidth, containerRef, isMounted]);
104
-
105
- useEffect(() => {
106
- calculateWidth();
107
- }, [calculateWidth, children]);
108
-
109
- useEffect(() => {
110
- setIsMounted(true);
111
- }, []);
112
-
113
- // Animation duration
114
- const duration = useMemo(() => {
115
- if (autoFill) {
116
- return (marqueeWidth * multiplier) / speed;
117
- } else {
118
- return marqueeWidth < containerWidth
119
- ? containerWidth / speed
120
- : marqueeWidth / speed;
121
- }
122
- }, [autoFill, containerWidth, marqueeWidth, multiplier, speed]);
123
-
124
- const containerStyle = useMemo(
125
- () => ({
126
- ...style,
127
- width: direction === 'up' || direction === 'down' ? `100vh` : '100%',
128
- transform:
129
- direction === 'up'
130
- ? 'rotate(-90deg)'
131
- : direction === 'down'
132
- ? 'rotate(90deg)'
133
- : 'none',
134
- }),
135
- [style, play, pauseOnHover, direction]
136
- );
137
-
138
- const marqueeStyle = useMemo(
139
- () => ({
140
- flex: '0 0 auto',
141
- animationDuration: `${duration}s`,
142
- animationDirection: direction === 'left' ? 'normal' : 'reverse',
143
- animationDelay: `${delay}s`,
144
- animation: !!loop
145
- ? `scroll ${duration}s linear ${delay}s ${loop}`
146
- : `scroll ${duration}s linear ${delay}s infinite`,
147
- minWidth: autoFill ? `auto` : '100%',
148
- }),
149
- [play, direction, duration, delay, loop, autoFill]
150
- );
151
-
152
- const childStyle = useMemo(
153
- () => ({
154
- transform:
155
- direction === 'up'
156
- ? 'rotate(90deg)'
157
- : direction === 'down'
158
- ? 'rotate(-90deg)'
159
- : 'none',
160
- }),
161
- [direction]
162
- );
163
-
164
- // Render {multiplier} number of children
165
- const multiplyChildren = useCallback(
166
- (multiplier: number) => {
167
- return [
168
- ...Array(
169
- Number.isFinite(multiplier) && multiplier >= 0 ? multiplier : 0
170
- ),
171
- ].map((_, i) => (
172
- <Fragment key={i}>
173
- {Children.map(children, (child) => {
174
- return (
175
- <div key={`children${i}`} style={childStyle} className="ms-child">
176
- {child}
177
- </div>
178
- );
179
- })}
180
- </Fragment>
181
- ));
182
- },
183
- [childStyle, children]
184
- );
185
-
186
- return !isMounted ? null : (
187
- <div
188
- ref={containerRef}
189
- style={containerStyle}
190
- className={cn(
191
- `ms-marquee-container overflow-x-hidden flex flex-row relative${className}`,
192
- !play || pauseOnHover ? 'ms-marquee-pause-hover' : ''
193
- )}
194
- >
195
- <div
196
- className={cn(' z-[1] flex flex-row items-center')}
197
- style={marqueeStyle}
198
- onAnimationIteration={onCycleComplete}
199
- onAnimationEnd={onFinish}
200
- >
201
- <div
202
- className="flex flex-row items-center min-w-[auto]"
203
- ref={marqueeRef}
204
- >
205
- {Children.map(children, (child) => {
206
- return (
207
- <div style={childStyle} className="ms-child">
208
- {child}
209
- </div>
210
- );
211
- })}
212
- </div>
213
- {multiplyChildren(multiplier - 1)}
214
- </div>
215
- <div style={marqueeStyle}>{multiplyChildren(multiplier)}</div>
216
- </div>
217
- );
218
- });
219
-
220
- export { Marquee };
@@ -1,138 +0,0 @@
1
- 'use client';
2
-
3
- import { indexOf, min } from 'lodash-es';
4
- import React, { Children, useEffect, useState } from 'react';
5
-
6
- import { cn } from '@/lib/utils';
7
-
8
- interface BreakpointColsObject {
9
- default: number;
10
- [key: number]: number;
11
- }
12
-
13
- interface MasonryProps {
14
- breakpointCols?: number | BreakpointColsObject;
15
- className?: string;
16
- columnClassName?: string;
17
- children?: React.ReactNode;
18
- columnAttrs?: React.HTMLAttributes<HTMLDivElement>;
19
- heights?: number[];
20
- }
21
-
22
- const Masonry: React.FC<MasonryProps> = ({
23
- breakpointCols = {
24
- default: 0,
25
- 3280: 5,
26
- 1919: 4,
27
- 1439: 3,
28
- 1199: 2,
29
- },
30
- className = '',
31
- columnClassName = '',
32
- children,
33
- columnAttrs = {},
34
- heights,
35
- }) => {
36
- const [columnCount, setColumnCount] = useState<number>(
37
- typeof breakpointCols === 'number' ? breakpointCols : breakpointCols.default
38
- );
39
-
40
- const reCalculateColumnCount = () => {
41
- const windowWidth = window?.innerWidth || Infinity;
42
- let newColumnCount = columnCount;
43
-
44
- if (typeof breakpointCols === 'object') {
45
- let matchedBreakpoint = Infinity;
46
-
47
- for (const breakpoint in breakpointCols) {
48
- const optBreakpoint = parseInt(breakpoint);
49
- const isCurrentBreakpoint =
50
- optBreakpoint > 0 && windowWidth <= optBreakpoint;
51
-
52
- if (isCurrentBreakpoint && optBreakpoint < matchedBreakpoint) {
53
- matchedBreakpoint = optBreakpoint;
54
- newColumnCount = breakpointCols[breakpoint];
55
- }
56
- }
57
-
58
- newColumnCount = Math.max(1, newColumnCount || 1);
59
- }
60
-
61
- if (columnCount !== newColumnCount) {
62
- setColumnCount(newColumnCount);
63
- }
64
- };
65
-
66
- useEffect(() => {
67
- const handleResize = () => {
68
- reCalculateColumnCount();
69
- };
70
-
71
- window.addEventListener('resize', handleResize);
72
-
73
- // Invoke immediately to set the initial column count
74
- handleResize();
75
-
76
- return () => {
77
- window.removeEventListener('resize', handleResize);
78
- };
79
- }, [breakpointCols, columnCount]);
80
-
81
- const itemsInColumns = () => {
82
- const columns = new Array<React.ReactNode[]>(columnCount);
83
- const totals = new Array<number>(columnCount).fill(0);
84
- const items = Children.toArray(children);
85
-
86
- if (heights) {
87
- for (let i = 0; i < items.length; i++) {
88
- const columnIndex = indexOf(totals, min(totals));
89
-
90
- if (!columns[columnIndex]) {
91
- columns[columnIndex] = [];
92
- }
93
- columns[columnIndex].push(items[i]);
94
- totals[columnIndex] += heights[i];
95
- }
96
- } else {
97
- for (let i = 0; i < items.length; i++) {
98
- const columnIndex = i % columnCount;
99
- if (!columns[columnIndex]) {
100
- columns[columnIndex] = [];
101
- }
102
- columns[columnIndex].push(items[i]);
103
- }
104
- }
105
-
106
- return columns;
107
- };
108
-
109
- const renderColumns = () => {
110
- const childrenInColumns = itemsInColumns();
111
- const columnWidth = `${100 / childrenInColumns.length}%`;
112
-
113
- return childrenInColumns.map((items, i) => (
114
- <div
115
- {...columnAttrs}
116
- style={{ ...columnAttrs.style, width: columnWidth }}
117
- className={cn(
118
- 'space-y-2 bg-clip-padding pl-2 md:space-y-5 md:pl-5',
119
- columnClassName
120
- )}
121
- key={i}
122
- >
123
- {items}
124
- </div>
125
- ));
126
- };
127
-
128
- return (
129
- <div
130
- {...columnAttrs}
131
- className={cn('mr-4 flex w-auto md:mr-6', className || 'my-masonry-grid')}
132
- >
133
- {columnCount > 0 && renderColumns()}
134
- </div>
135
- );
136
- };
137
-
138
- export { Masonry };