@semcore/carousel 17.2.2 → 17.2.3-prerelease.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/CHANGELOG.md +7 -0
- package/lib/cjs/Carousel.js +34 -32
- package/lib/cjs/Carousel.js.map +1 -1
- package/lib/cjs/Carousel.types.js.map +1 -1
- package/lib/es6/Carousel.js +34 -32
- package/lib/es6/Carousel.js.map +1 -1
- package/lib/es6/Carousel.types.js.map +1 -1
- package/lib/esm/Carousel.mjs +35 -33
- package/lib/types/Carousel.d.ts +2 -11
- package/lib/types/Carousel.types.d.ts +160 -108
- package/package.json +4 -4
- package/src/Carousel.tsx +37 -33
- package/src/Carousel.types.ts +174 -129
|
@@ -1,110 +1,162 @@
|
|
|
1
1
|
import type { BoxProps } from '@semcore/base-components';
|
|
2
|
-
import type { PropGetterFn, Intergalactic
|
|
2
|
+
import type { PropGetterFn, Intergalactic } from '@semcore/core';
|
|
3
3
|
import type { LocalizedMessages } from './translations/__intergalactic-dynamic-locales';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
4
|
+
declare namespace NSCarousel {
|
|
5
|
+
type Props = BoxProps & {
|
|
6
|
+
/** Index active item */
|
|
7
|
+
index?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Index of the active item selected by default
|
|
10
|
+
* @default 0
|
|
11
|
+
*/
|
|
12
|
+
defaultIndex?: number;
|
|
13
|
+
/** Called when the selection is changed */
|
|
14
|
+
onIndexChange?: (index: number) => void;
|
|
15
|
+
/** Animation duration
|
|
16
|
+
* @default 300 */
|
|
17
|
+
duration?: number;
|
|
18
|
+
/** Disables infinite items change in the carousel
|
|
19
|
+
* @default false */
|
|
20
|
+
bounded?: boolean;
|
|
21
|
+
/** Internal */
|
|
22
|
+
step?: number;
|
|
23
|
+
/** Specifies the locale for i18n support */
|
|
24
|
+
locale?: string;
|
|
25
|
+
/** Enable zoom feature for carousel items */
|
|
26
|
+
zoom?: boolean;
|
|
27
|
+
/** Width for items in zooming modal */
|
|
28
|
+
zoomWidth?: number;
|
|
29
|
+
/** Type of indicators */
|
|
30
|
+
indicators?: 'default' | 'hide' | 'preview';
|
|
31
|
+
};
|
|
32
|
+
type DefaultProps = {
|
|
33
|
+
defaultIndex: 0;
|
|
34
|
+
duration: 350;
|
|
35
|
+
step: 100;
|
|
36
|
+
bounded: false;
|
|
37
|
+
i18n: LocalizedMessages;
|
|
38
|
+
locale: 'en';
|
|
39
|
+
indicators: 'default';
|
|
40
|
+
};
|
|
41
|
+
type State = {
|
|
42
|
+
isOpenZoom: boolean;
|
|
43
|
+
selectedIndex: number;
|
|
44
|
+
items: NSCarousel.Item[];
|
|
45
|
+
};
|
|
46
|
+
type Ctx = {
|
|
47
|
+
getContainerProps: PropGetterFn;
|
|
48
|
+
getItemProps: PropGetterFn;
|
|
49
|
+
getPrevProps: PropGetterFn;
|
|
50
|
+
getNextProps: PropGetterFn;
|
|
51
|
+
getIndicatorsProps: PropGetterFn;
|
|
52
|
+
};
|
|
53
|
+
type Handlers = {
|
|
54
|
+
index: [
|
|
55
|
+
null,
|
|
56
|
+
(index: NSCarousel.Props['index']) => void
|
|
57
|
+
];
|
|
58
|
+
};
|
|
59
|
+
type Item = {
|
|
60
|
+
node: HTMLElement;
|
|
61
|
+
};
|
|
62
|
+
namespace Container {
|
|
63
|
+
type Component = Intergalactic.Component<'div', BoxProps>;
|
|
64
|
+
}
|
|
65
|
+
namespace ContentBox {
|
|
66
|
+
type Component = Intergalactic.Component<'div', BoxProps>;
|
|
67
|
+
}
|
|
68
|
+
namespace Indicators {
|
|
69
|
+
type Props = BoxProps & {
|
|
70
|
+
items?: NSCarousel.Item[];
|
|
71
|
+
inverted?: boolean;
|
|
72
|
+
};
|
|
73
|
+
type Component = Intergalactic.Component<'div', Props, State>;
|
|
74
|
+
}
|
|
75
|
+
namespace Indicator {
|
|
76
|
+
type Props = Omit<BoxProps, 'position'> & {
|
|
77
|
+
active?: boolean;
|
|
78
|
+
onClick?: () => void;
|
|
79
|
+
inverted?: boolean;
|
|
80
|
+
};
|
|
81
|
+
type Component = Intergalactic.Component<'div', Props>;
|
|
82
|
+
}
|
|
83
|
+
namespace Item {
|
|
84
|
+
type Props = BoxProps & {
|
|
85
|
+
/** Flag for css cursor
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
zoomIn?: boolean;
|
|
89
|
+
/** Flag for css cursor
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
zoomOut?: boolean;
|
|
93
|
+
/** Function to add item to list in Carousel
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
toggleItem?: (item: NSCarousel.Item, toRemove?: boolean) => void;
|
|
97
|
+
/** Index of item in carousel */
|
|
98
|
+
index?: number;
|
|
99
|
+
uid?: string;
|
|
100
|
+
/** Flag - is current item shown now */
|
|
101
|
+
current?: boolean;
|
|
102
|
+
/** Handler for show item in modal window
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
onToggleZoomModal?: () => void;
|
|
106
|
+
/** Value for transform item
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
transform?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Flag data zoomed
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
isOpenZoom?: boolean;
|
|
115
|
+
};
|
|
116
|
+
type Component = Intergalactic.Component<'div', Props>;
|
|
117
|
+
}
|
|
118
|
+
namespace Prev {
|
|
119
|
+
type Props = BoxProps & {
|
|
120
|
+
label?: string;
|
|
121
|
+
inverted?: boolean;
|
|
122
|
+
tabIndex?: number;
|
|
123
|
+
};
|
|
124
|
+
type Component = Intergalactic.Component<'div', Props>;
|
|
125
|
+
}
|
|
126
|
+
namespace Next {
|
|
127
|
+
type Props = BoxProps & {
|
|
128
|
+
label?: string;
|
|
129
|
+
inverted?: boolean;
|
|
130
|
+
tabIndex?: number;
|
|
131
|
+
};
|
|
132
|
+
type Component = Intergalactic.Component<'div', Props>;
|
|
133
|
+
}
|
|
134
|
+
type Component = Intergalactic.Component<'div', Props, Ctx & State> & {
|
|
135
|
+
Container: Container.Component;
|
|
136
|
+
ContentBox: ContentBox.Component;
|
|
137
|
+
Indicators: Indicators.Component;
|
|
138
|
+
Indicator: Indicator.Component;
|
|
139
|
+
Item: Item.Component;
|
|
140
|
+
Prev: Prev.Component;
|
|
141
|
+
Next: Next.Component;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** @deprecated It will be removed in v18. */
|
|
145
|
+
export type CarouselProps = NSCarousel.Props;
|
|
146
|
+
/** @deprecated It will be removed in v18. */
|
|
147
|
+
export type CarouselDefaultProps = NSCarousel.DefaultProps;
|
|
148
|
+
/** @deprecated It will be removed in v18. */
|
|
149
|
+
export type CarouselContext = NSCarousel.Ctx;
|
|
150
|
+
/** @deprecated It will be removed in v18. */
|
|
151
|
+
export type CarouselItem = NSCarousel.Item;
|
|
152
|
+
/** @deprecated It will be removed in v18. */
|
|
153
|
+
export type CarouselItemProps = NSCarousel.Item.Props;
|
|
154
|
+
/** @deprecated It will be removed in v18. */
|
|
155
|
+
export type CarouselState = NSCarousel.State;
|
|
156
|
+
/** @deprecated It will be removed in v18. */
|
|
157
|
+
export type CarouselButtonProps = NSCarousel.Prev.Props;
|
|
158
|
+
/** @deprecated It will be removed in v18. */
|
|
159
|
+
export type CarouselIndicatorsProps = NSCarousel.Indicators.Props;
|
|
160
|
+
/** @deprecated It will be removed in v18. */
|
|
161
|
+
export type CarouselIndicatorProps = NSCarousel.Indicator.Props;
|
|
162
|
+
export type { NSCarousel };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/carousel",
|
|
3
3
|
"description": "Semrush Carousel Component",
|
|
4
|
-
"version": "17.2.
|
|
4
|
+
"version": "17.2.3-prerelease.0",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es6/index.js",
|
|
7
7
|
"typings": "lib/types/index.d.ts",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"directory": "semcore/carousel"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@semcore/base-components": "17.2.1",
|
|
31
30
|
"@semcore/core": "17.2.1",
|
|
32
|
-
"@semcore/
|
|
33
|
-
"@semcore/testing-utils": "1.0.0"
|
|
31
|
+
"@semcore/base-components": "17.2.1",
|
|
32
|
+
"@semcore/testing-utils": "1.0.0",
|
|
33
|
+
"@semcore/icon": "17.2.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm semcore-builder --source=js,ts && pnpm vite build"
|
package/src/Carousel.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createBreakpoints, Box, Flex } from '@semcore/base-components';
|
|
2
2
|
import type { BoxProps } from '@semcore/base-components';
|
|
3
3
|
import Button from '@semcore/button';
|
|
4
|
+
import type { Intergalactic } from '@semcore/core';
|
|
4
5
|
import { createComponent, Component, sstyled, Root } from '@semcore/core';
|
|
5
6
|
import type { WithI18nEnhanceProps } from '@semcore/core/lib/utils/enhances/i18nEnhance';
|
|
6
7
|
import i18nEnhance from '@semcore/core/lib/utils/enhances/i18nEnhance';
|
|
@@ -13,18 +14,7 @@ import ChevronRight from '@semcore/icon/ChevronRight/l';
|
|
|
13
14
|
import Modal from '@semcore/modal';
|
|
14
15
|
import React from 'react';
|
|
15
16
|
|
|
16
|
-
import type
|
|
17
|
-
import type {
|
|
18
|
-
CarouselProps,
|
|
19
|
-
CarouselState,
|
|
20
|
-
CarouselContext,
|
|
21
|
-
CarouselItem,
|
|
22
|
-
CarouselItemProps,
|
|
23
|
-
CarouselButtonProps,
|
|
24
|
-
CarouselIndicatorsProps,
|
|
25
|
-
CarouselIndicatorProps,
|
|
26
|
-
CarouselDefaultProps,
|
|
27
|
-
} from './Carousel.types';
|
|
17
|
+
import type { NSCarousel } from './Carousel.types';
|
|
28
18
|
import style from './style/carousel.shadow.css';
|
|
29
19
|
import { localizedMessages } from './translations/__intergalactic-dynamic-locales';
|
|
30
20
|
|
|
@@ -39,12 +29,12 @@ const BreakPoints = createBreakpoints(media);
|
|
|
39
29
|
const isSmallScreen = (index?: number) => index === 1;
|
|
40
30
|
|
|
41
31
|
class CarouselRoot extends Component<
|
|
42
|
-
|
|
32
|
+
Intergalactic.InternalTypings.InferComponentProps<NSCarousel.Component>,
|
|
43
33
|
typeof enhance,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
NSCarousel.Handlers,
|
|
35
|
+
WithI18nEnhanceProps,
|
|
36
|
+
NSCarousel.State,
|
|
37
|
+
NSCarousel.DefaultProps
|
|
48
38
|
> {
|
|
49
39
|
static displayName = 'Carousel';
|
|
50
40
|
static defaultProps = {
|
|
@@ -66,7 +56,7 @@ class CarouselRoot extends Component<
|
|
|
66
56
|
refModalContainer = React.createRef<HTMLElement>();
|
|
67
57
|
_touchStartCoord = -1;
|
|
68
58
|
|
|
69
|
-
constructor(props:
|
|
59
|
+
constructor(props: NSCarousel.Props) {
|
|
70
60
|
super(props);
|
|
71
61
|
this.isControlled = props.index !== undefined;
|
|
72
62
|
this.state = {
|
|
@@ -76,11 +66,11 @@ class CarouselRoot extends Component<
|
|
|
76
66
|
};
|
|
77
67
|
}
|
|
78
68
|
|
|
79
|
-
uncontrolledProps() {
|
|
69
|
+
uncontrolledProps(): NSCarousel.Handlers {
|
|
80
70
|
return {
|
|
81
71
|
index: [
|
|
82
72
|
null,
|
|
83
|
-
(
|
|
73
|
+
() => {
|
|
84
74
|
this.refCarousel.current?.blur();
|
|
85
75
|
setTimeout(() => {
|
|
86
76
|
this.refCarousel.current?.focus();
|
|
@@ -119,7 +109,7 @@ class CarouselRoot extends Component<
|
|
|
119
109
|
);
|
|
120
110
|
}
|
|
121
111
|
|
|
122
|
-
componentDidUpdate(prevProps:
|
|
112
|
+
componentDidUpdate(prevProps: typeof this.asProps) {
|
|
123
113
|
const { index } = this.asProps;
|
|
124
114
|
if (prevProps.index !== index && this.isControlled && index !== undefined) {
|
|
125
115
|
this.setState({ selectedIndex: index }, () => this.transformContainer());
|
|
@@ -169,7 +159,7 @@ class CarouselRoot extends Component<
|
|
|
169
159
|
}
|
|
170
160
|
};
|
|
171
161
|
|
|
172
|
-
toggleItem = (item:
|
|
162
|
+
toggleItem = (item: NSCarousel.Item, removeItem = false) => {
|
|
173
163
|
this.setState((prevState) => {
|
|
174
164
|
const newItems = removeItem
|
|
175
165
|
? prevState.items.filter((element) => element.node !== item.node)
|
|
@@ -331,7 +321,7 @@ class CarouselRoot extends Component<
|
|
|
331
321
|
};
|
|
332
322
|
}
|
|
333
323
|
|
|
334
|
-
getItemProps(_props:
|
|
324
|
+
getItemProps(_props: NSCarousel.Item.Props, index: number) {
|
|
335
325
|
const { zoom } = this.asProps;
|
|
336
326
|
const isCurrent = this.isSelected(index);
|
|
337
327
|
|
|
@@ -609,7 +599,9 @@ class CarouselRoot extends Component<
|
|
|
609
599
|
}
|
|
610
600
|
}
|
|
611
601
|
|
|
612
|
-
function Container(
|
|
602
|
+
function Container(
|
|
603
|
+
props: Intergalactic.InternalTypings.InferChildComponentProps<NSCarousel.Container.Component, typeof CarouselRoot, 'Container'>,
|
|
604
|
+
) {
|
|
613
605
|
const SContainer = Root;
|
|
614
606
|
const { styles, duration } = props;
|
|
615
607
|
|
|
@@ -618,14 +610,16 @@ function Container(props: BoxProps & { duration?: number }) {
|
|
|
618
610
|
);
|
|
619
611
|
}
|
|
620
612
|
|
|
621
|
-
function ContentBox(props:
|
|
613
|
+
function ContentBox(props: Intergalactic.InternalTypings.InferComponentProps<NSCarousel.ContentBox.Component>) {
|
|
622
614
|
const SContentBox = Root;
|
|
623
615
|
const { styles } = props;
|
|
624
616
|
|
|
625
617
|
return sstyled(styles)(<SContentBox render={Box} />);
|
|
626
618
|
}
|
|
627
619
|
|
|
628
|
-
class Item extends Component<
|
|
620
|
+
class Item extends Component<
|
|
621
|
+
Intergalactic.InternalTypings.InferChildComponentProps<NSCarousel.Item.Component, typeof CarouselRoot, 'Item'>
|
|
622
|
+
> {
|
|
629
623
|
refItem = React.createRef<HTMLElement>();
|
|
630
624
|
|
|
631
625
|
componentDidMount() {
|
|
@@ -650,7 +644,7 @@ class Item extends Component<CarouselItemProps> {
|
|
|
650
644
|
}
|
|
651
645
|
}
|
|
652
646
|
|
|
653
|
-
componentDidUpdate(prevProps:
|
|
647
|
+
componentDidUpdate(prevProps: typeof this.asProps) {
|
|
654
648
|
const transform = this.props.transform;
|
|
655
649
|
const refItem = this.refItem.current;
|
|
656
650
|
|
|
@@ -679,7 +673,9 @@ class Item extends Component<CarouselItemProps> {
|
|
|
679
673
|
}
|
|
680
674
|
}
|
|
681
675
|
|
|
682
|
-
function Prev(
|
|
676
|
+
function Prev(
|
|
677
|
+
props: Intergalactic.InternalTypings.InferChildComponentProps<NSCarousel.Prev.Component, typeof CarouselRoot, 'Prev'>,
|
|
678
|
+
) {
|
|
683
679
|
const { styles, children, Children, label, top = 0, inverted } = props;
|
|
684
680
|
const SPrev = Root;
|
|
685
681
|
const SPrevButton = Button;
|
|
@@ -704,7 +700,9 @@ function Prev(props: CarouselButtonProps) {
|
|
|
704
700
|
);
|
|
705
701
|
};
|
|
706
702
|
|
|
707
|
-
function Next(
|
|
703
|
+
function Next(
|
|
704
|
+
props: Intergalactic.InternalTypings.InferChildComponentProps<NSCarousel.Next.Component, typeof CarouselRoot, 'Next'>,
|
|
705
|
+
) {
|
|
708
706
|
const { styles, children, Children, label, top = 0, inverted } = props;
|
|
709
707
|
const SNext = Root;
|
|
710
708
|
const SNextButton = Button;
|
|
@@ -729,7 +727,10 @@ function Next(props: CarouselButtonProps) {
|
|
|
729
727
|
);
|
|
730
728
|
};
|
|
731
729
|
|
|
732
|
-
function Indicators(
|
|
730
|
+
function Indicators(
|
|
731
|
+
props: Intergalactic.InternalTypings.InferChildComponentProps<NSCarousel.Indicators.Component, typeof CarouselRoot, 'Indicators'>,
|
|
732
|
+
) {
|
|
733
|
+
const { items, styles, Children, inverted } = props;
|
|
733
734
|
const SIndicators = Root;
|
|
734
735
|
if (Children.origin) {
|
|
735
736
|
return sstyled(styles)(
|
|
@@ -740,14 +741,17 @@ function Indicators({ items, styles, Children, inverted }: CarouselIndicatorsPro
|
|
|
740
741
|
}
|
|
741
742
|
return sstyled(styles)(
|
|
742
743
|
<SIndicators render={Box} invertOutline={inverted}>
|
|
743
|
-
{items?.map((item:
|
|
744
|
+
{items?.map((item: NSCarousel.Item, index: number) => (
|
|
744
745
|
<Carousel.Indicator key={index} {...item} inverted={inverted} />
|
|
745
746
|
))}
|
|
746
747
|
</SIndicators>,
|
|
747
748
|
);
|
|
748
749
|
};
|
|
749
750
|
|
|
750
|
-
function Indicator(
|
|
751
|
+
function Indicator(
|
|
752
|
+
props: Intergalactic.InternalTypings.InferChildComponentProps<NSCarousel.Indicator.Component, typeof CarouselRoot, 'Indicator'>,
|
|
753
|
+
) {
|
|
754
|
+
const { styles, Children } = props;
|
|
751
755
|
const SIndicator = Root;
|
|
752
756
|
return sstyled(styles)(
|
|
753
757
|
<SIndicator render={Box}>
|
|
@@ -762,7 +766,7 @@ function Indicator({ styles, Children }: CarouselIndicatorProps) {
|
|
|
762
766
|
* {@link https://developer.semrush.com/intergalactic/components/carousel/carousel-api/|API} | {@link https://developer.semrush.com/intergalactic/components/carousel/carousel-code/|Examples}
|
|
763
767
|
*/
|
|
764
768
|
const Carousel = createComponent<
|
|
765
|
-
|
|
769
|
+
NSCarousel.Component,
|
|
766
770
|
typeof CarouselRoot
|
|
767
771
|
>(CarouselRoot, {
|
|
768
772
|
Container,
|