@meduza/ui-kit-2 1.4.1 → 1.4.3

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.
@@ -6728,27 +6728,18 @@ ul.VersesBlock-module_root__CrgSZ:first-child {
6728
6728
  position: relative;
6729
6729
  }
6730
6730
 
6731
- .RelatedCarousel-module_track__UVQ2n {
6732
- display: flex;
6733
- gap: 20px;
6734
-
6731
+ .RelatedCarousel-module_viewport__HCzJi {
6735
6732
  margin: 0 -20px;
6736
6733
  padding: 0 20px;
6737
6734
 
6738
- overflow-x: auto;
6739
-
6740
- list-style: none;
6741
- overscroll-behavior-x: contain;
6742
-
6743
- scroll-snap-type: x mandatory;
6744
- scroll-padding-left: 20px;
6745
- -webkit-overflow-scrolling: touch;
6746
-
6747
- scrollbar-width: none;
6735
+ overflow: hidden;
6748
6736
  }
6749
6737
 
6750
- .RelatedCarousel-module_track__UVQ2n::-webkit-scrollbar {
6751
- display: none;
6738
+ .RelatedCarousel-module_track__UVQ2n {
6739
+ display: flex;
6740
+ gap: 20px;
6741
+
6742
+ touch-action: pan-y pinch-zoom;
6752
6743
  }
6753
6744
 
6754
6745
  .RelatedCarousel-module_slide__MI9tF {
@@ -6758,9 +6749,6 @@ ul.VersesBlock-module_root__CrgSZ:first-child {
6758
6749
  min-width: 0;
6759
6750
 
6760
6751
  overflow: hidden;
6761
-
6762
- scroll-snap-align: start;
6763
- scroll-snap-stop: always;
6764
6752
  }
6765
6753
 
6766
6754
  .RelatedCarousel-module_dots__mOSIC {
@@ -6815,34 +6803,6 @@ ul.VersesBlock-module_root__CrgSZ:first-child {
6815
6803
  background-color: #000;
6816
6804
  }
6817
6805
 
6818
- @media only screen and (min-width: 32em) {
6819
- .RelatedCarousel-module_dots__mOSIC {
6820
- display: none;
6821
- }
6822
-
6823
- .RelatedCarousel-module_track__UVQ2n {
6824
- display: flex;
6825
- flex-direction: column;
6826
- gap: 30px;
6827
-
6828
- margin: 0;
6829
- padding: 0;
6830
-
6831
- overflow: visible;
6832
-
6833
- scroll-snap-type: none;
6834
- scroll-padding-left: 0;
6835
- }
6836
-
6837
- .RelatedCarousel-module_slide__MI9tF {
6838
- flex: none;
6839
-
6840
- width: 100%;
6841
-
6842
- scroll-snap-align: none;
6843
- }
6844
- }
6845
-
6846
6806
  .ToolbarButton-module_root__upsEH {
6847
6807
  display: block;
6848
6808
 
package/dist/ui-kit.css CHANGED
@@ -6728,27 +6728,18 @@ ul.VersesBlock-module_root__CrgSZ:first-child {
6728
6728
  position: relative;
6729
6729
  }
6730
6730
 
6731
- .RelatedCarousel-module_track__UVQ2n {
6732
- display: flex;
6733
- gap: 20px;
6734
-
6731
+ .RelatedCarousel-module_viewport__HCzJi {
6735
6732
  margin: 0 -20px;
6736
6733
  padding: 0 20px;
6737
6734
 
6738
- overflow-x: auto;
6739
-
6740
- list-style: none;
6741
- overscroll-behavior-x: contain;
6742
-
6743
- scroll-snap-type: x mandatory;
6744
- scroll-padding-left: 20px;
6745
- -webkit-overflow-scrolling: touch;
6746
-
6747
- scrollbar-width: none;
6735
+ overflow: hidden;
6748
6736
  }
6749
6737
 
6750
- .RelatedCarousel-module_track__UVQ2n::-webkit-scrollbar {
6751
- display: none;
6738
+ .RelatedCarousel-module_track__UVQ2n {
6739
+ display: flex;
6740
+ gap: 20px;
6741
+
6742
+ touch-action: pan-y pinch-zoom;
6752
6743
  }
6753
6744
 
6754
6745
  .RelatedCarousel-module_slide__MI9tF {
@@ -6758,9 +6749,6 @@ ul.VersesBlock-module_root__CrgSZ:first-child {
6758
6749
  min-width: 0;
6759
6750
 
6760
6751
  overflow: hidden;
6761
-
6762
- scroll-snap-align: start;
6763
- scroll-snap-stop: always;
6764
6752
  }
6765
6753
 
6766
6754
  .RelatedCarousel-module_dots__mOSIC {
@@ -6815,34 +6803,6 @@ ul.VersesBlock-module_root__CrgSZ:first-child {
6815
6803
  background-color: #000;
6816
6804
  }
6817
6805
 
6818
- @media only screen and (min-width: 32em) {
6819
- .RelatedCarousel-module_dots__mOSIC {
6820
- display: none;
6821
- }
6822
-
6823
- .RelatedCarousel-module_track__UVQ2n {
6824
- display: flex;
6825
- flex-direction: column;
6826
- gap: 30px;
6827
-
6828
- margin: 0;
6829
- padding: 0;
6830
-
6831
- overflow: visible;
6832
-
6833
- scroll-snap-type: none;
6834
- scroll-padding-left: 0;
6835
- }
6836
-
6837
- .RelatedCarousel-module_slide__MI9tF {
6838
- flex: none;
6839
-
6840
- width: 100%;
6841
-
6842
- scroll-snap-align: none;
6843
- }
6844
- }
6845
-
6846
6806
  .ToolbarButton-module_root__upsEH {
6847
6807
  display: block;
6848
6808
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.1",
2
+ "version": "1.4.3",
3
3
  "license": "MIT",
4
4
  "description": "UIKit for Meduza",
5
5
  "repository": "https://github.com/meduza-corp/ui-kit-2.git",
@@ -125,5 +125,8 @@
125
125
  "typescript": "^5.1.6",
126
126
  "typescript-plugin-css-modules": "^5.0.1",
127
127
  "utils": "^0.3.1"
128
+ },
129
+ "dependencies": {
130
+ "embla-carousel-react": "^8.6.0"
128
131
  }
129
132
  }
@@ -2,27 +2,18 @@
2
2
  position: relative;
3
3
  }
4
4
 
5
- .track {
6
- display: flex;
7
- gap: 20px;
8
-
5
+ .viewport {
9
6
  margin: 0 -20px;
10
7
  padding: 0 20px;
11
8
 
12
- overflow-x: auto;
13
-
14
- list-style: none;
15
- overscroll-behavior-x: contain;
16
-
17
- scroll-snap-type: x mandatory;
18
- scroll-padding-left: 20px;
19
- -webkit-overflow-scrolling: touch;
20
-
21
- scrollbar-width: none;
9
+ overflow: hidden;
22
10
  }
23
11
 
24
- .track::-webkit-scrollbar {
25
- display: none;
12
+ .track {
13
+ display: flex;
14
+ gap: 20px;
15
+
16
+ touch-action: pan-y pinch-zoom;
26
17
  }
27
18
 
28
19
  .slide {
@@ -32,9 +23,6 @@
32
23
  min-width: 0;
33
24
 
34
25
  overflow: hidden;
35
-
36
- scroll-snap-align: start;
37
- scroll-snap-stop: always;
38
26
  }
39
27
 
40
28
  .dots {
@@ -88,31 +76,3 @@
88
76
  .isActive {
89
77
  background-color: #000;
90
78
  }
91
-
92
- @media $mobile {
93
- .dots {
94
- display: none;
95
- }
96
-
97
- .track {
98
- display: flex;
99
- flex-direction: column;
100
- gap: 30px;
101
-
102
- margin: 0;
103
- padding: 0;
104
-
105
- overflow: visible;
106
-
107
- scroll-snap-type: none;
108
- scroll-padding-left: 0;
109
- }
110
-
111
- .slide {
112
- flex: none;
113
-
114
- width: 100%;
115
-
116
- scroll-snap-align: none;
117
- }
118
- }
@@ -19,9 +19,13 @@ describe('Related Carousel', () => {
19
19
  expect(getByTestId('related-carousel')).toHaveClass(styles.root)
20
20
  })
21
21
 
22
- it('should render a dot per slide', () => {
23
- const { getAllByRole } = renderComponent()
22
+ it('should render a slide and a dot per child', () => {
23
+ const { getByTestId, getByText } = renderComponent()
24
24
 
25
- expect(getAllByRole('button')).toHaveLength(2)
25
+ const carousel = getByTestId('related-carousel')
26
+
27
+ expect(getByText('Первая')).toBeInTheDocument()
28
+ expect(carousel.querySelectorAll(`.${styles.slide}`)).toHaveLength(2)
29
+ expect(carousel.querySelectorAll(`.${styles.dot}`)).toHaveLength(2)
26
30
  })
27
31
  })
@@ -1,4 +1,5 @@
1
- import React, { useEffect, useRef, useState } from 'react'
1
+ import React, { useCallback, useEffect, useState } from 'react'
2
+ import useEmblaCarousel from 'embla-carousel-react'
2
3
 
3
4
  import { RelatedCarouselProps } from './RelatedCarousel.types'
4
5
  import makeClassName from '../utils/makeClassName'
@@ -60,67 +61,47 @@ const getDotScale = (
60
61
  return 'full'
61
62
  }
62
63
 
63
- const getSlideStep = (track: HTMLElement | null): number => {
64
- if (!track) {
65
- return 0
66
- }
67
-
68
- const [first, second] = Array.from(track.children) as HTMLElement[]
69
-
70
- if (!first) {
71
- return 0
72
- }
73
-
74
- return second ? second.offsetLeft - first.offsetLeft : first.offsetWidth
75
- }
76
-
77
64
  export const RelatedCarousel: React.FC<RelatedCarouselProps> = ({
78
65
  children,
79
66
  ariaLabel
80
67
  }) => {
81
- const trackRef = useRef<HTMLUListElement>(null)
82
- const frameRef = useRef(0)
68
+ const [viewportRef, embla] = useEmblaCarousel({
69
+ loop: true,
70
+ align: 'start',
71
+ containScroll: false
72
+ })
73
+
83
74
  const [activeIndex, setActiveIndex] = useState(0)
84
75
  const [dotsStart, setDotsStart] = useState(0)
85
76
 
86
77
  const slides = React.Children.toArray(children)
87
- const lastIndex = slides.length - 1
88
78
  const total = slides.length
89
79
 
90
- useEffect(() => {
91
- const track = trackRef.current
92
-
93
- if (!track) {
94
- return undefined
80
+ const handleSelect = useCallback(() => {
81
+ if (!embla) {
82
+ return
95
83
  }
96
84
 
97
- const handleScroll = () => {
98
- cancelAnimationFrame(frameRef.current)
99
-
100
- frameRef.current = requestAnimationFrame(() => {
101
- const step = getSlideStep(track)
102
-
103
- if (!step) {
104
- return
105
- }
85
+ const index = embla.selectedScrollSnap()
106
86
 
107
- const index = Math.max(
108
- 0,
109
- Math.min(lastIndex, Math.round(track.scrollLeft / step))
110
- )
87
+ setActiveIndex(index)
88
+ setDotsStart((start) => getDotsStart(index, start, total))
89
+ }, [embla, total])
111
90
 
112
- setActiveIndex(index)
113
- setDotsStart((start) => getDotsStart(index, start, lastIndex + 1))
114
- })
91
+ useEffect(() => {
92
+ if (!embla) {
93
+ return undefined
115
94
  }
116
95
 
117
- track.addEventListener('scroll', handleScroll, { passive: true })
96
+ handleSelect()
97
+ embla.on('select', handleSelect)
98
+ embla.on('reInit', handleSelect)
118
99
 
119
100
  return () => {
120
- cancelAnimationFrame(frameRef.current)
121
- track.removeEventListener('scroll', handleScroll)
101
+ embla.off('select', handleSelect)
102
+ embla.off('reInit', handleSelect)
122
103
  }
123
- }, [lastIndex])
104
+ }, [embla, handleSelect])
124
105
 
125
106
  const dotsStyle: DotsStyle = {
126
107
  '--dotsVisible': Math.min(total, VISIBLE_DOTS),
@@ -134,13 +115,15 @@ export const RelatedCarousel: React.FC<RelatedCarouselProps> = ({
134
115
  role="group"
135
116
  aria-label={ariaLabel}
136
117
  >
137
- <ul className={styles.track} ref={trackRef}>
138
- {slides.map((slide, index) => (
139
- <li className={styles.slide} key={index}>
140
- {slide}
141
- </li>
142
- ))}
143
- </ul>
118
+ <div className={styles.viewport} ref={viewportRef}>
119
+ <div className={styles.track}>
120
+ {slides.map((slide, index) => (
121
+ <div className={styles.slide} key={index}>
122
+ {slide}
123
+ </div>
124
+ ))}
125
+ </div>
126
+ </div>
144
127
  <div aria-hidden="true" className={styles.dots} style={dotsStyle}>
145
128
  <div className={styles.dotsTrack}>
146
129
  {slides.map((_slide, index) => {