@meduza/ui-kit-2 1.4.11-dark.1 → 1.4.12-analytics.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/RelatedCarousel/RelatedCarousel.types.d.ts +1 -0
- package/dist/ui-kit-2.cjs.development.js +38 -10
- package/dist/ui-kit-2.cjs.development.js.map +1 -1
- package/dist/ui-kit-2.cjs.production.min.js +1 -1
- package/dist/ui-kit-2.cjs.production.min.js.map +1 -1
- package/dist/ui-kit-2.esm.js +38 -10
- package/dist/ui-kit-2.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/RelatedBlock/index.tsx +24 -9
- package/src/RelatedBook/index.tsx +9 -0
- package/src/RelatedCarousel/RelatedCarousel.types.ts +1 -0
- package/src/RelatedCarousel/index.tsx +6 -2
- package/src/RelatedRichBlock/index.tsx +9 -0
package/package.json
CHANGED
|
@@ -5,9 +5,16 @@ import { RelatedBlockProps } from './RelatedBlock.types'
|
|
|
5
5
|
import { makeClassName, ClassNames } from '../utils/makeClassName'
|
|
6
6
|
|
|
7
7
|
import makeStyleContext from '../utils/makeStyleContext'
|
|
8
|
+
import postMessage from '../utils/postMessage'
|
|
8
9
|
|
|
9
10
|
import styles from './RelatedBlock.module.css'
|
|
10
11
|
|
|
12
|
+
const handleClick = (event: React.MouseEvent, to: string) => {
|
|
13
|
+
if (event.button <= 1) {
|
|
14
|
+
postMessage('related', to, 'click')
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
export const RelatedBlock: React.FC<RelatedBlockProps> = ({
|
|
12
19
|
block: {
|
|
13
20
|
data: { title, related },
|
|
@@ -28,15 +35,23 @@ export const RelatedBlock: React.FC<RelatedBlockProps> = ({
|
|
|
28
35
|
<div data-testid="related-block" className={makeClassName(classNames)}>
|
|
29
36
|
<h3 className={styles.header}>{title}</h3>
|
|
30
37
|
<ul className={styles.items}>
|
|
31
|
-
{related.map((item, index) =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
{related.map((item, index) => {
|
|
39
|
+
const to = item.full_url || `/${item.url}`
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<li key={item.id || index} className={styles[item.layout]}>
|
|
43
|
+
<Link
|
|
44
|
+
to={to}
|
|
45
|
+
onClick={(event) => handleClick(event, to)}
|
|
46
|
+
onAuxClick={(event) => handleClick(event, to)}
|
|
47
|
+
>
|
|
48
|
+
<span className={styles.first}>{item.title}</span>
|
|
49
|
+
{item.second_title && ' '}
|
|
50
|
+
{item.second_title && <span>{item.second_title}</span>}
|
|
51
|
+
</Link>
|
|
52
|
+
</li>
|
|
53
|
+
)
|
|
54
|
+
})}
|
|
40
55
|
</ul>
|
|
41
56
|
</div>
|
|
42
57
|
)
|
|
@@ -7,6 +7,7 @@ import styles from './RelatedBook.module.css'
|
|
|
7
7
|
import { RenderBlocks } from '../RenderBlocks'
|
|
8
8
|
import { Image } from '../Image'
|
|
9
9
|
import makeStyleContext from '../utils/makeStyleContext'
|
|
10
|
+
import postMessage from '../utils/postMessage'
|
|
10
11
|
|
|
11
12
|
export const RelatedBook: React.FC<RelatedBookProps> = ({
|
|
12
13
|
block,
|
|
@@ -30,9 +31,17 @@ export const RelatedBook: React.FC<RelatedBookProps> = ({
|
|
|
30
31
|
'--bgColor': `rgb(${block.data.theme.background_color || '0, 0, 0'})`
|
|
31
32
|
} as React.CSSProperties
|
|
32
33
|
|
|
34
|
+
const handleClick = (event: React.MouseEvent) => {
|
|
35
|
+
if (event.button <= 1) {
|
|
36
|
+
postMessage('related', `/${block.data.url}`, 'click')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
return (
|
|
34
41
|
<Link
|
|
35
42
|
to={`/${block.data.url}`}
|
|
43
|
+
onClick={handleClick}
|
|
44
|
+
onAuxClick={handleClick}
|
|
36
45
|
className={makeClassName(classNames)}
|
|
37
46
|
style={cssProps}
|
|
38
47
|
>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useState } from 'react'
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
|
2
2
|
import useEmblaCarousel from 'embla-carousel-react'
|
|
3
3
|
|
|
4
4
|
import { RelatedCarouselProps } from './RelatedCarousel.types'
|
|
@@ -63,7 +63,8 @@ const getDotScale = (
|
|
|
63
63
|
|
|
64
64
|
export const RelatedCarousel: React.FC<RelatedCarouselProps> = ({
|
|
65
65
|
children,
|
|
66
|
-
ariaLabel
|
|
66
|
+
ariaLabel,
|
|
67
|
+
onSlideChange
|
|
67
68
|
}) => {
|
|
68
69
|
const [viewportRef, embla] = useEmblaCarousel({
|
|
69
70
|
loop: true,
|
|
@@ -72,6 +73,8 @@ export const RelatedCarousel: React.FC<RelatedCarouselProps> = ({
|
|
|
72
73
|
})
|
|
73
74
|
|
|
74
75
|
const [activeIndex, setActiveIndex] = useState(0)
|
|
76
|
+
const onSlideChangeRef = useRef(onSlideChange)
|
|
77
|
+
onSlideChangeRef.current = onSlideChange
|
|
75
78
|
const [dotsStart, setDotsStart] = useState(0)
|
|
76
79
|
|
|
77
80
|
const slides = React.Children.toArray(children)
|
|
@@ -85,6 +88,7 @@ export const RelatedCarousel: React.FC<RelatedCarouselProps> = ({
|
|
|
85
88
|
const index = embla.selectedScrollSnap()
|
|
86
89
|
|
|
87
90
|
setActiveIndex(index)
|
|
91
|
+
onSlideChangeRef.current?.(index)
|
|
88
92
|
setDotsStart((start) => getDotsStart(index, start, total))
|
|
89
93
|
}, [embla, total])
|
|
90
94
|
|
|
@@ -6,6 +6,7 @@ import { RelatedRichBlockProps } from './RelatedRichBlock.types'
|
|
|
6
6
|
import { makeClassName, ClassNames } from '../utils/makeClassName'
|
|
7
7
|
import makeStyleContext from '../utils/makeStyleContext'
|
|
8
8
|
import { toCapitalize } from '../utils/converCase'
|
|
9
|
+
import postMessage from '../utils/postMessage'
|
|
9
10
|
|
|
10
11
|
import { Tag } from '../Tag'
|
|
11
12
|
import { Image } from '../Image'
|
|
@@ -41,11 +42,19 @@ export const RelatedRichBlock: React.FC<RelatedRichBlockProps> = ({
|
|
|
41
42
|
context = [...styleContext, 'isInMediaBlock', 'richRelated']
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
const handleClick = (event: React.MouseEvent) => {
|
|
46
|
+
if (event.button <= 1) {
|
|
47
|
+
postMessage('related', `/${url}`, 'click')
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
44
51
|
return (
|
|
45
52
|
<Link
|
|
46
53
|
data-testid="related-rich-block"
|
|
47
54
|
className={makeClassName(classNames)}
|
|
48
55
|
to={`/${url}`}
|
|
56
|
+
onClick={handleClick}
|
|
57
|
+
onAuxClick={handleClick}
|
|
49
58
|
>
|
|
50
59
|
<div className={styles.tag}>
|
|
51
60
|
<Tag size="small" theme="inherit" styleContext="richRelated">
|