@cloud-ru/ds-carousel 1.0.5 → 1.0.6-preview-d50a3da1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-ru/ds-carousel",
3
- "version": "1.0.5",
3
+ "version": "1.0.6-preview-d50a3da1.0",
4
4
  "description": "Компонент горизонтальной прокрутки слайдов — стрелки, пагинация, свайп, автопрокрутка, infinite scroll и multi-item отображение.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,10 +35,11 @@
35
35
  "dependencies": {
36
36
  "classnames": "^2.5.1",
37
37
  "merge-refs": "^2.0.0",
38
- "@cloud-ru/ds-button": "^1.0.2",
39
- "@cloud-ru/ds-icons": "^1.2.0",
40
- "@cloud-ru/ds-pagination": "^1.0.5",
41
- "@cloud-ru/ds-utils": "^1.1.0"
38
+ "@cloud-ru/ds-adaptive": "1.0.1",
39
+ "@cloud-ru/ds-button": "1.0.3-preview-d50a3da1.0",
40
+ "@cloud-ru/ds-pagination": "1.0.6-preview-d50a3da1.0",
41
+ "@cloud-ru/ds-utils": "1.1.0",
42
+ "@cloud-ru/ds-icons": "1.2.1-preview-d50a3da1.0"
42
43
  },
43
44
  "publishConfig": {
44
45
  "access": "public"
package/src/Carousel.tsx CHANGED
@@ -1,3 +1,4 @@
1
+ import { LayoutPresets, mergePresets, useLayoutDefaults } from '@cloud-ru/ds-adaptive';
1
2
  import { PaginationSlider } from '@cloud-ru/ds-pagination';
2
3
  import { extractSupportProps, useUncontrolledProp, WithSupportProps } from '@cloud-ru/ds-utils';
3
4
  import cn from 'classnames';
@@ -8,6 +9,9 @@ import { Control, ItemProvider } from './helperComponents';
8
9
  import styles from './styles.module.scss';
9
10
  import { ControlsVisibility } from './types';
10
11
 
12
+ /** Пропы `Carousel`, дефолты которых меняет адаптив (preset-класс). */
13
+ type CarouselLayoutDefaults = Pick<CarouselProps, 'arrows'>;
14
+
11
15
  export type CarouselProps = WithSupportProps<{
12
16
  /**
13
17
  * CSS - класснейм
@@ -47,7 +51,8 @@ export type CarouselProps = WithSupportProps<{
47
51
  */
48
52
  swipeActivateLength?: number;
49
53
  /**
50
- * Использовать стрелки для переключения страниц
54
+ * Использовать стрелки для переключения страниц.
55
+ * На mobile по умолчанию скрыты (`CAROUSEL_LAYOUT_PRESETS`), вернуть — через `layoutPresets`.
51
56
  * @default true
52
57
  */
53
58
  arrows?: boolean;
@@ -78,15 +83,25 @@ export type CarouselProps = WithSupportProps<{
78
83
  * @default 'hover'
79
84
  */
80
85
  controlsVisibility?: ControlsVisibility;
86
+ /**
87
+ * Override mobile-дефолтов адаптива для этого инстанса (deep-merge поверх `CAROUSEL_LAYOUT_PRESETS`).
88
+ * Escape-hatch: обычно не нужен — DS-пресет применяется автоматически по `AdaptiveProvider`.
89
+ */
90
+ layoutPresets?: LayoutPresets<CarouselLayoutDefaults>;
81
91
  }>;
82
92
 
93
+ /** DS-пресет адаптива `Carousel`: на mobile стрелки скрыты, страницы листаются свайпом и пагинацией. */
94
+ export const CAROUSEL_LAYOUT_PRESETS: LayoutPresets<CarouselLayoutDefaults> = {
95
+ mobile: { arrows: false },
96
+ };
97
+
83
98
  export function Carousel({
84
99
  children: items,
85
100
  showItems = 1,
86
101
  scrollBy: scrollByProp,
87
102
  transition = 0.4,
88
103
  swipe = true,
89
- arrows = true,
104
+ arrows,
90
105
  pagination = true,
91
106
  className,
92
107
  gap,
@@ -95,8 +110,15 @@ export function Carousel({
95
110
  swipeActivateLength = 48,
96
111
  autoSwipe,
97
112
  controlsVisibility = CONTROLS_VISIBILITY.hover,
113
+ layoutPresets,
98
114
  ...rest
99
115
  }: CarouselProps) {
116
+ // arrows участвует в пресете — дефолт держим в базе useLayoutDefaults, не в деструктуризации.
117
+ const { arrows: resolvedArrows } = useLayoutDefaults<CarouselLayoutDefaults>(
118
+ { arrows: true },
119
+ mergePresets(CAROUSEL_LAYOUT_PRESETS, layoutPresets),
120
+ { arrows },
121
+ );
100
122
  const timerRef = useRef<NodeJS.Timeout | null>(null);
101
123
 
102
124
  const scrollBy = useMemo(() => scrollByProp ?? Math.trunc(showItems), [showItems, scrollByProp]);
@@ -167,7 +189,7 @@ export function Carousel({
167
189
  {items}
168
190
  </ItemProvider>
169
191
 
170
- {arrows && (
192
+ {resolvedArrows && (
171
193
  <>
172
194
  {(infiniteScroll || page > 0) && (
173
195
  <Control
@@ -4,24 +4,15 @@
4
4
  .control {
5
5
  top: 50%;
6
6
 
7
- :global(.sn-mobile) & {
8
- // TODO: refactoring after https://jira.cloud.ru/browse/FF-8182
9
- display: none;
10
- }
11
-
12
7
  &[data-direction='prev'] {
13
- @include base.composite-var(carousel.$carousel, 'anatomy', 'contentWrapper', 'controlWrapper', 'controlBack');
14
-
15
8
  position: absolute;
16
- left: 0;
9
+ left: calc(#{base.simple-var(carousel.$carousel, 'anatomy', 'contentWrapper', 'controlWrapper', 'controlBack', 'padding-left')} / 2);
17
10
  transform: translateY(-50%) translateX(-50%);
18
11
  }
19
12
 
20
13
  &[data-direction='next'] {
21
- @include base.composite-var(carousel.$carousel, 'anatomy', 'contentWrapper', 'controlWrapper', 'controlForward');
22
-
23
14
  position: absolute;
24
- right: 0;
15
+ right: calc(#{base.simple-var(carousel.$carousel, 'anatomy', 'contentWrapper', 'controlWrapper', 'controlForward', 'padding-right')} / 2);
25
16
  transform: translateY(-50%) translateX(50%);
26
17
  }
27
18
  }