@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.
@@ -1,110 +1,162 @@
1
1
  import type { BoxProps } from '@semcore/base-components';
2
- import type { PropGetterFn, Intergalactic, IRootComponentProps } from '@semcore/core';
2
+ import type { PropGetterFn, Intergalactic } from '@semcore/core';
3
3
  import type { LocalizedMessages } from './translations/__intergalactic-dynamic-locales';
4
- export type CarouselProps = BoxProps & {
5
- /** Index active item */
6
- index?: number;
7
- /**
8
- * Index of the active item selected by default
9
- * @default 0
10
- */
11
- defaultIndex?: number;
12
- /** Called when the selection is changed */
13
- onIndexChange?: (index: number) => void;
14
- /** Animation duration
15
- * @default 300 */
16
- duration?: number;
17
- /** Disables infinite items change in the carousel
18
- * @default false */
19
- bounded?: boolean;
20
- /** Internal */
21
- step?: number;
22
- /** Specifies the locale for i18n support */
23
- locale?: string;
24
- /** Enable zoom feature for carousel items */
25
- zoom?: boolean;
26
- /** Width for items in zooming modal */
27
- zoomWidth?: number;
28
- /** Type of indicators */
29
- indicators?: 'default' | 'hide' | 'preview';
30
- };
31
- export type CarouselDefaultProps = {
32
- defaultIndex: 0;
33
- duration: 350;
34
- step: 100;
35
- bounded: false;
36
- i18n: LocalizedMessages;
37
- locale: 'en';
38
- indicators: 'default';
39
- };
40
- export type CarouselContext = {
41
- getContainerProps: PropGetterFn;
42
- getItemProps: PropGetterFn;
43
- getPrevProps: PropGetterFn;
44
- getNextProps: PropGetterFn;
45
- getIndicatorsProps: PropGetterFn;
46
- };
47
- export type CarouselItem = {
48
- node: HTMLElement;
49
- };
50
- export type CarouselItemProps = BoxProps & {
51
- /** Flag for css cursor
52
- * @private
53
- */
54
- zoomIn?: boolean;
55
- /** Flag for css cursor
56
- * @private
57
- */
58
- zoomOut?: boolean;
59
- /** Function to add item to list in Carousel
60
- * @private
61
- */
62
- toggleItem?: (item: CarouselItem, toRemove?: boolean) => void;
63
- /** Index of item in carousel */
64
- index?: number;
65
- uid?: string;
66
- /** Flag - is current item shown now */
67
- current?: boolean;
68
- /** Handler for show item in modal window
69
- * @private
70
- */
71
- onToggleZoomModal?: () => void;
72
- /** Value for transform item
73
- * @private
74
- */
75
- transform?: number;
76
- /**
77
- * Flag data zoomed
78
- * @private
79
- */
80
- isOpenZoom?: boolean;
81
- };
82
- export type CarouselState = {
83
- isOpenZoom: boolean;
84
- selectedIndex: number;
85
- items: CarouselItem[];
86
- };
87
- export type CarouselButtonProps = IRootComponentProps & BoxProps & {
88
- label?: string;
89
- inverted?: boolean;
90
- tabIndex?: number;
91
- };
92
- export type CarouselIndicatorsProps = IRootComponentProps & BoxProps & {
93
- items?: CarouselItem[];
94
- inverted?: boolean;
95
- };
96
- export type CarouselIndicatorProps = IRootComponentProps & Omit<BoxProps, 'position'> & {
97
- active?: boolean;
98
- onClick?: () => void;
99
- inverted?: boolean;
100
- } & CarouselItem;
101
- declare const CarouselType: Intergalactic.Component<'div', CarouselProps, CarouselContext & CarouselState> & {
102
- Container: Intergalactic.Component<'div', BoxProps>;
103
- ContentBox: Intergalactic.Component<'div', BoxProps>;
104
- Indicators: Intergalactic.Component<'div', CarouselIndicatorsProps, CarouselState>;
105
- Indicator: Intergalactic.Component<'div', CarouselIndicatorProps>;
106
- Item: Intergalactic.Component<'div', CarouselItemProps>;
107
- Prev: Intergalactic.Component<'div', CarouselButtonProps>;
108
- Next: Intergalactic.Component<'div', CarouselButtonProps>;
109
- };
110
- export default CarouselType;
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.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/icon": "17.2.0",
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 CarouselType from './Carousel.types';
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
- CarouselProps,
32
+ Intergalactic.InternalTypings.InferComponentProps<NSCarousel.Component>,
43
33
  typeof enhance,
44
- { index: any },
45
- CarouselContext & WithI18nEnhanceProps,
46
- CarouselState,
47
- CarouselDefaultProps
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: CarouselProps) {
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
- (_index: number) => {
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: CarouselProps) {
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: CarouselItem, removeItem = false) => {
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: CarouselItemProps, index: number) {
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(props: BoxProps & { duration?: number }) {
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: BoxProps) {
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<CarouselItemProps> {
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: CarouselItemProps) {
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(props: CarouselButtonProps) {
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(props: CarouselButtonProps) {
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({ items, styles, Children, inverted }: CarouselIndicatorsProps) {
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: CarouselItem, index: number) => (
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({ styles, Children }: CarouselIndicatorProps) {
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
- typeof CarouselType,
769
+ NSCarousel.Component,
766
770
  typeof CarouselRoot
767
771
  >(CarouselRoot, {
768
772
  Container,