@meduza/ui-kit-2 1.3.1 → 1.4.1

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.
@@ -0,0 +1,118 @@
1
+ .root {
2
+ position: relative;
3
+ }
4
+
5
+ .track {
6
+ display: flex;
7
+ gap: 20px;
8
+
9
+ margin: 0 -20px;
10
+ padding: 0 20px;
11
+
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;
22
+ }
23
+
24
+ .track::-webkit-scrollbar {
25
+ display: none;
26
+ }
27
+
28
+ .slide {
29
+ position: relative;
30
+
31
+ flex: 0 0 85%;
32
+ min-width: 0;
33
+
34
+ overflow: hidden;
35
+
36
+ scroll-snap-align: start;
37
+ scroll-snap-stop: always;
38
+ }
39
+
40
+ .dots {
41
+ --dotStep: 7px;
42
+
43
+ width: calc(var(--dotsVisible) * var(--dotStep));
44
+ margin: 28px auto 0;
45
+
46
+ overflow: hidden;
47
+ }
48
+
49
+ .dotsTrack {
50
+ display: flex;
51
+
52
+ transform: translateX(calc(var(--dotsStart) * var(--dotStep) * -1));
53
+
54
+ transition: transform 0.25s ease;
55
+ }
56
+
57
+ .dotCell {
58
+ display: flex;
59
+ flex: 0 0 auto;
60
+ align-items: center;
61
+ justify-content: center;
62
+
63
+ width: var(--dotStep);
64
+ height: var(--dotStep);
65
+ }
66
+
67
+ .dot {
68
+ width: 4px;
69
+ height: 4px;
70
+
71
+ background-color: #d4d4d4;
72
+
73
+ border-radius: 50%;
74
+
75
+ transition: width 0.25s ease, height 0.25s ease, background-color 0.2s;
76
+ }
77
+
78
+ .isSmall {
79
+ width: 2px;
80
+ height: 2px;
81
+ }
82
+
83
+ .isTiny {
84
+ width: 1px;
85
+ height: 1px;
86
+ }
87
+
88
+ .isActive {
89
+ background-color: #000;
90
+ }
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
+ }
@@ -0,0 +1,53 @@
1
+ .root {
2
+ display: block;
3
+
4
+ max-width: 375px;
5
+ margin: 0 auto;
6
+ padding: 0 20px;
7
+ }
8
+
9
+ .block {
10
+ margin: 16px -20px;
11
+ padding: 8px 20px 20px;
12
+
13
+ background-color: #f7f7f7;
14
+ border-top: 4px solid #b88b58;
15
+
16
+ box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.1);
17
+ }
18
+
19
+ .header {
20
+ margin: 0 0 25px;
21
+
22
+ letter-spacing: 1px;
23
+ text-transform: uppercase;
24
+
25
+ color: #7f7f7f;
26
+
27
+ font-size: 12px;
28
+ font-weight: 600;
29
+ line-height: 17px;
30
+ }
31
+
32
+ .card {
33
+ background-color: #fff;
34
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
35
+ }
36
+
37
+ .cover {
38
+ display: block;
39
+
40
+ width: 100%;
41
+ aspect-ratio: 3 / 2;
42
+
43
+ background-color: #d5d5d5;
44
+ }
45
+
46
+ .title {
47
+ margin: 0;
48
+ padding: 10px 12px 14px;
49
+
50
+ font-size: 18px;
51
+ font-weight: 700;
52
+ line-height: 130%;
53
+ }
@@ -0,0 +1,48 @@
1
+ import React from 'react'
2
+ import { RelatedCarousel } from './'
3
+ import { PreviewWrapper } from '../_storybook/PreviewWrapper'
4
+
5
+ import styles from './RelatedCarousel.stories.module.css'
6
+ import mock from './mock.json'
7
+
8
+ export default {
9
+ title: 'Main / RelatedCarousel',
10
+ component: RelatedCarousel,
11
+ parameters: {
12
+ themeWrapperSideBySide: true
13
+ }
14
+ }
15
+
16
+ interface CardProps {
17
+ title: string
18
+ }
19
+
20
+ const Card: React.FC<CardProps> = ({ title }) => (
21
+ <div className={styles.card}>
22
+ <span className={styles.cover} />
23
+ <p className={styles.title}>{title}</p>
24
+ </div>
25
+ )
26
+
27
+ const Example: React.FC = () => {
28
+ return (
29
+ <div className={styles.root}>
30
+ <div className={styles.block}>
31
+ <h3 className={styles.header}>{mock.title}</h3>
32
+ <RelatedCarousel ariaLabel={mock.title}>
33
+ {mock.related.map((item) => (
34
+ <Card key={item.id} title={item.title} />
35
+ ))}
36
+ </RelatedCarousel>
37
+ </div>
38
+ </div>
39
+ )
40
+ }
41
+
42
+ export const Default: React.FC = () => (
43
+ <>
44
+ <PreviewWrapper theme="light">
45
+ <Example />
46
+ </PreviewWrapper>
47
+ </>
48
+ )
@@ -0,0 +1,27 @@
1
+ import React from 'react'
2
+ import { render } from '@testing-library/react'
3
+ import { RelatedCarousel } from './'
4
+
5
+ import styles from './RelatedCarousel.module.css'
6
+
7
+ describe('Related Carousel', () => {
8
+ const renderComponent = () =>
9
+ render(
10
+ <RelatedCarousel>
11
+ <div>Первая</div>
12
+ <div>Вторая</div>
13
+ </RelatedCarousel>
14
+ )
15
+
16
+ it('should have root style', () => {
17
+ const { getByTestId } = renderComponent()
18
+
19
+ expect(getByTestId('related-carousel')).toHaveClass(styles.root)
20
+ })
21
+
22
+ it('should render a dot per slide', () => {
23
+ const { getAllByRole } = renderComponent()
24
+
25
+ expect(getAllByRole('button')).toHaveLength(2)
26
+ })
27
+ })
@@ -0,0 +1,6 @@
1
+ import React from 'react'
2
+
3
+ export interface RelatedCarouselProps {
4
+ children: React.ReactNode
5
+ ariaLabel?: string
6
+ }
@@ -0,0 +1,167 @@
1
+ import React, { useEffect, useRef, useState } from 'react'
2
+
3
+ import { RelatedCarouselProps } from './RelatedCarousel.types'
4
+ import makeClassName from '../utils/makeClassName'
5
+
6
+ import styles from './RelatedCarousel.module.css'
7
+
8
+ const VISIBLE_DOTS = 6
9
+ const EDGE_DOTS = 2
10
+
11
+ type DotsStyle = React.CSSProperties & Record<string, number>
12
+
13
+ const getDotsStart = (
14
+ activeIndex: number,
15
+ currentStart: number,
16
+ total: number
17
+ ): number => {
18
+ if (total <= VISIBLE_DOTS) {
19
+ return 0
20
+ }
21
+
22
+ let start = currentStart
23
+
24
+ if (activeIndex < start + EDGE_DOTS) {
25
+ start = activeIndex - EDGE_DOTS
26
+ }
27
+
28
+ if (activeIndex > start + VISIBLE_DOTS - 1 - EDGE_DOTS) {
29
+ start = activeIndex - VISIBLE_DOTS + 1 + EDGE_DOTS
30
+ }
31
+
32
+ return Math.max(0, Math.min(start, total - VISIBLE_DOTS))
33
+ }
34
+
35
+ const getDotScale = (
36
+ index: number,
37
+ start: number,
38
+ total: number
39
+ ): 'full' | 'small' | 'tiny' => {
40
+ const position = index - start
41
+ const hasBefore = start > 0
42
+ const hasAfter = start + VISIBLE_DOTS < total
43
+
44
+ if (hasBefore && position === 0) {
45
+ return 'tiny'
46
+ }
47
+
48
+ if (hasBefore && position === 1) {
49
+ return 'small'
50
+ }
51
+
52
+ if (hasAfter && position === VISIBLE_DOTS - 1) {
53
+ return 'tiny'
54
+ }
55
+
56
+ if (hasAfter && position === VISIBLE_DOTS - 2) {
57
+ return 'small'
58
+ }
59
+
60
+ return 'full'
61
+ }
62
+
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
+ export const RelatedCarousel: React.FC<RelatedCarouselProps> = ({
78
+ children,
79
+ ariaLabel
80
+ }) => {
81
+ const trackRef = useRef<HTMLUListElement>(null)
82
+ const frameRef = useRef(0)
83
+ const [activeIndex, setActiveIndex] = useState(0)
84
+ const [dotsStart, setDotsStart] = useState(0)
85
+
86
+ const slides = React.Children.toArray(children)
87
+ const lastIndex = slides.length - 1
88
+ const total = slides.length
89
+
90
+ useEffect(() => {
91
+ const track = trackRef.current
92
+
93
+ if (!track) {
94
+ return undefined
95
+ }
96
+
97
+ const handleScroll = () => {
98
+ cancelAnimationFrame(frameRef.current)
99
+
100
+ frameRef.current = requestAnimationFrame(() => {
101
+ const step = getSlideStep(track)
102
+
103
+ if (!step) {
104
+ return
105
+ }
106
+
107
+ const index = Math.max(
108
+ 0,
109
+ Math.min(lastIndex, Math.round(track.scrollLeft / step))
110
+ )
111
+
112
+ setActiveIndex(index)
113
+ setDotsStart((start) => getDotsStart(index, start, lastIndex + 1))
114
+ })
115
+ }
116
+
117
+ track.addEventListener('scroll', handleScroll, { passive: true })
118
+
119
+ return () => {
120
+ cancelAnimationFrame(frameRef.current)
121
+ track.removeEventListener('scroll', handleScroll)
122
+ }
123
+ }, [lastIndex])
124
+
125
+ const dotsStyle: DotsStyle = {
126
+ '--dotsVisible': Math.min(total, VISIBLE_DOTS),
127
+ '--dotsStart': dotsStart
128
+ }
129
+
130
+ return (
131
+ <div
132
+ data-testid="related-carousel"
133
+ className={makeClassName([[styles.root, true]])}
134
+ role="group"
135
+ aria-label={ariaLabel}
136
+ >
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>
144
+ <div aria-hidden="true" className={styles.dots} style={dotsStyle}>
145
+ <div className={styles.dotsTrack}>
146
+ {slides.map((_slide, index) => {
147
+ const isActive = index === activeIndex
148
+ const scale = getDotScale(index, dotsStart, total)
149
+
150
+ return (
151
+ <span key={index} className={styles.dotCell}>
152
+ <span
153
+ className={makeClassName([
154
+ [styles.dot, true],
155
+ [styles.isActive, isActive],
156
+ [styles.isSmall, scale === 'small'],
157
+ [styles.isTiny, scale === 'tiny']
158
+ ])}
159
+ />
160
+ </span>
161
+ )
162
+ })}
163
+ </div>
164
+ </div>
165
+ </div>
166
+ )
167
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "title": "Читайте также",
3
+ "related": [
4
+ {
5
+ "id": "0",
6
+ "title": "На российскую больницу впервые подали в суд за отказ в посещении умирающего в реанимации родственника"
7
+ },
8
+ {
9
+ "id": "1",
10
+ "title": "Мосгорсуд присудил компенсацию семье, которую не пустили в реанимацию к умирающей"
11
+ },
12
+ {
13
+ "id": "2",
14
+ "title": "«Реанимация должна быть открытой». Интервью с врачом о том, почему в России до сих пор не пускают к родственникам"
15
+ }
16
+ ]
17
+ }
@@ -2,13 +2,21 @@
2
2
  position: relative;
3
3
  z-index: 10;
4
4
 
5
- display: block;
5
+ display: flex;
6
+ flex-flow: column nowrap;
7
+ gap: 20px;
8
+
9
+ padding: 10px 20px 20px;
6
10
  overflow: hidden;
7
11
 
8
12
  text-decoration: none;
9
13
 
10
- border-radius: 8px;
14
+ background-color: #f7f7f7;
15
+
16
+ border-top: 2px solid #b78a54;
17
+
11
18
  outline-width: 0;
19
+ box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.1);
12
20
  }
13
21
 
14
22
  .root:hover {
@@ -17,32 +25,7 @@
17
25
  }
18
26
  }
19
27
 
20
- .root::after {
21
- position: absolute;
22
- top: 0;
23
- right: 0;
24
- bottom: 0;
25
- left: 0;
26
- z-index: 20;
27
-
28
- border-radius: 8px;
29
-
30
- content: '';
31
- }
32
-
33
- .root::before {
34
- display: block;
35
-
36
- width: 100%;
37
- }
38
-
39
- .root::after {
40
- box-shadow: inset 0 4px #b88b59, inset 0 5px rgba(0, 0, 0, 0.2),
41
- inset 0 0 0 1px rgba(0, 0, 0, 0.1);
42
- }
43
-
44
- .root,
45
- .wrapper {
28
+ .root {
46
29
  margin: 16px 0;
47
30
 
48
31
  @media $portraitTablet {
@@ -50,180 +33,41 @@
50
33
  }
51
34
  }
52
35
 
53
- .overlay,
54
- .overlayHeader {
55
- position: absolute;
56
- right: 0;
57
- left: 0;
58
- z-index: 10;
59
- }
60
-
61
- .overlay {
62
- bottom: 0;
63
-
64
- height: 295px;
36
+ .content {
37
+ display: flex;
38
+ flex-flow: row nowrap;
39
+ gap: 20px;
65
40
  }
66
41
 
67
- .overlayHeader {
68
- top: 0;
69
-
70
- height: 150px;
42
+ .cover {
43
+ flex-shrink: 0;
44
+ width: 200px;
71
45
  }
72
46
 
73
47
  .body {
74
48
  display: flex;
75
49
  flex-flow: column nowrap;
76
- justify-content: flex-end;
77
-
78
- padding: 12px 15px;
79
-
80
- background-color: #f7f7f7;
81
-
82
- @media $mobile {
83
- position: absolute;
84
- right: 0;
85
- bottom: 0;
86
- left: 0;
87
- z-index: 10;
88
-
89
- min-height: 295px;
90
- padding: 20px;
91
-
92
- background-color: transparent;
93
- }
94
- }
95
-
96
- .isRich {
97
- color: #000;
98
-
99
- @media $mobile {
100
- color: #fff;
101
- }
102
- }
103
-
104
- .isRich.hasGradient .body {
105
- @media $mobile {
106
- position: absolute;
107
- right: 0;
108
- bottom: 0;
109
- left: 0;
110
- z-index: 10;
111
-
112
- min-height: 295px;
113
-
114
- background-color: transparent;
115
- }
116
- }
117
-
118
- .isRich .picture {
119
- position: relative;
120
- }
121
-
122
- .isRich .picture::after {
123
- position: absolute;
124
- right: 1px;
125
- bottom: 0;
126
- left: 1px;
127
- z-index: 10;
128
-
129
- border-bottom: 1px solid rgba(0, 0, 0, 0.1);
130
-
131
- content: '';
132
-
133
- @media $mobile {
134
- content: '';
135
- }
136
- }
137
-
138
- .isCard {
139
- color: #fff;
140
-
141
- background-color: #191919;
142
-
143
- @media $mobile {
144
- min-height: 350px;
145
- }
146
- }
147
-
148
- .isCard .body {
149
- background-color: transparent;
150
-
151
- @media $mobile {
152
- position: absolute;
153
- right: 0;
154
- bottom: 0;
155
- left: 0;
156
- z-index: 10;
157
-
158
- min-height: 295px;
159
- }
160
- }
161
-
162
- .isCard::before {
163
- @media $mobile {
164
- padding-bottom: 66.66%;
165
-
166
- content: '';
167
- }
168
50
  }
169
51
 
170
52
  .isCard .cover {
171
53
  position: relative;
172
54
 
173
- width: 100%;
174
-
175
- @media $mobile {
176
- position: absolute;
177
- top: 0;
178
- bottom: 0;
179
- }
180
- }
181
-
182
- .isCard .cover::before {
183
- display: block;
184
-
185
- padding-bottom: 78.50746269%;
55
+ display: flex;
56
+ align-items: center;
57
+ justify-content: center;
186
58
 
187
- content: '';
59
+ background-color: #191919;
188
60
 
189
- @media $mobile {
190
- content: none;
191
- }
61
+ aspect-ratio: 1 / 1;
192
62
  }
193
63
 
194
- .isCard .picture {
195
- position: absolute;
196
- top: 50%;
197
- left: 50%;
198
-
199
- width: 180px;
200
- height: 180px;
201
-
202
- transform: translate(-50%, -50%);
203
-
204
- @media $mobile {
205
- top: 25%;
206
-
207
- transform: translate(-50%, -25%);
208
- }
64
+ .isCard .cover > div {
65
+ width: 100px;
66
+ height: 100px;
209
67
  }
210
68
 
211
69
  .tag {
212
- position: absolute;
213
- top: 14px;
214
- right: 15px;
215
- left: 15px;
216
- z-index: 10;
217
-
218
- color: rgba(255, 255, 255, 0.7);
219
-
220
- font-size: 12px;
221
-
222
- @media $landscapeTablet {
223
- top: 16px;
224
- right: 20px;
225
- left: 20px;
226
- }
70
+ color: rgba(0, 0, 0, 0.5);
227
71
  }
228
72
 
229
73
  .center {
@@ -233,23 +77,6 @@
233
77
  margin-left: auto;
234
78
  }
235
79
 
236
- /* Themes */
237
-
238
- .isRich.dark {
239
- color: #000;
240
- }
241
-
242
- .isRich.dark .tag {
243
- color: rgba(0, 0, 0, 0.7);
244
- }
245
-
246
- .isRich.light {
247
- @media $mobile {
248
- color: #fff;
249
- text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
250
- }
251
- }
252
-
253
80
  /* Display */
254
81
 
255
82
  .mobile {
@@ -262,6 +89,6 @@
262
89
  display: none;
263
90
 
264
91
  @media $mobile {
265
- display: block;
92
+ display: flex;
266
93
  }
267
94
  }