@faststore/ui 1.12.19 → 1.12.23
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 +18 -0
- package/dist/hooks/useSlider/useSlider.d.ts +3 -1
- package/dist/hooks/useSlider/useSlider.js +5 -10
- package/dist/hooks/useSlider/useSlider.js.map +1 -1
- package/dist/molecules/Bullets/Bullets.js +1 -1
- package/dist/molecules/Bullets/Bullets.js.map +1 -1
- package/dist/molecules/Carousel/Carousel.d.ts +40 -2
- package/dist/molecules/Carousel/Carousel.js +115 -56
- package/dist/molecules/Carousel/Carousel.js.map +1 -1
- package/dist/molecules/Carousel/CarouselItem.d.ts +11 -0
- package/dist/molecules/Carousel/CarouselItem.js +18 -0
- package/dist/molecules/Carousel/CarouselItem.js.map +1 -0
- package/package.json +5 -5
- package/src/hooks/useSlider/useSlider.ts +8 -9
- package/src/molecules/Bullets/Bullets.test.tsx +5 -5
- package/src/molecules/Bullets/Bullets.tsx +3 -3
- package/src/molecules/Bullets/stories/Bullets.mdx +2 -2
- package/src/molecules/Carousel/Carousel.test.tsx +55 -52
- package/src/molecules/Carousel/Carousel.tsx +217 -85
- package/src/molecules/Carousel/CarouselItem.tsx +54 -0
- package/src/molecules/Carousel/stories/Carousel.mdx +7 -7
- package/src/molecules/Carousel/stories/Carousel.stories.tsx +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.12.23](https://github.com/vtex/faststore/compare/v1.12.22...v1.12.23) (2022-11-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Revisit `Carousel` component ([#1476](https://github.com/vtex/faststore/issues/1476)) ([5bf8662](https://github.com/vtex/faststore/commit/5bf86628e04fd5cf47c10071e66058de035d8023))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## 1.12.20 (2022-10-26)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Chores
|
|
19
|
+
|
|
20
|
+
* git blame ignore modification by data-fs ([#1494](https://github.com/vtex/faststore/issues/1494)) ([783079e](https://github.com/vtex/faststore/commit/783079e7095b39270bbb60e79063b774056dc5d4))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
## 1.12.19 (2022-10-25)
|
|
7
25
|
|
|
8
26
|
|
|
@@ -52,8 +52,10 @@ export interface UseSliderArgs extends SwipeableProps {
|
|
|
52
52
|
itemsPerPage?: number;
|
|
53
53
|
/** Whether or not the slider is infinite. */
|
|
54
54
|
infiniteMode?: boolean;
|
|
55
|
+
/** Whether or not slide after swiping left/right. */
|
|
56
|
+
shouldSlideOnSwipe?: boolean;
|
|
55
57
|
}
|
|
56
|
-
export default function useSlider({ totalItems, itemsPerPage, infiniteMode, ...swipeableConfigOverrides }: UseSliderArgs): {
|
|
58
|
+
export default function useSlider({ totalItems, itemsPerPage, infiniteMode, shouldSlideOnSwipe, ...swipeableConfigOverrides }: UseSliderArgs): {
|
|
57
59
|
handlers: import("react-swipeable").SwipeableHandlers;
|
|
58
60
|
slide: (page: number | SlideDirection, dispatch: Dispatch<Action>) => void;
|
|
59
61
|
sliderState: SliderState;
|
|
@@ -70,14 +70,10 @@ const defaultSliderState = (totalItems, itemsPerPage, infinite) => ({
|
|
|
70
70
|
});
|
|
71
71
|
const slide = (page, dispatch) => {
|
|
72
72
|
if (page === 'next') {
|
|
73
|
-
dispatch({
|
|
74
|
-
type: 'NEXT_PAGE',
|
|
75
|
-
});
|
|
73
|
+
dispatch({ type: 'NEXT_PAGE' });
|
|
76
74
|
}
|
|
77
75
|
if (page === 'previous') {
|
|
78
|
-
dispatch({
|
|
79
|
-
type: 'PREVIOUS_PAGE',
|
|
80
|
-
});
|
|
76
|
+
dispatch({ type: 'PREVIOUS_PAGE' });
|
|
81
77
|
}
|
|
82
78
|
if (typeof page === 'number') {
|
|
83
79
|
dispatch({
|
|
@@ -89,12 +85,11 @@ const slide = (page, dispatch) => {
|
|
|
89
85
|
});
|
|
90
86
|
}
|
|
91
87
|
};
|
|
92
|
-
export default function useSlider({ totalItems, itemsPerPage = 1, infiniteMode = false, ...swipeableConfigOverrides }) {
|
|
88
|
+
export default function useSlider({ totalItems, itemsPerPage = 1, infiniteMode = false, shouldSlideOnSwipe = true, ...swipeableConfigOverrides }) {
|
|
93
89
|
const [sliderState, sliderDispatch] = useReducer(reducer, undefined, () => defaultSliderState(totalItems, itemsPerPage, infiniteMode));
|
|
94
90
|
const handlers = useSwipeable({
|
|
95
|
-
onSwipedRight: () => slide('previous', sliderDispatch),
|
|
96
|
-
onSwipedLeft: () => slide('next', sliderDispatch),
|
|
97
|
-
preventDefaultTouchmoveEvent: true,
|
|
91
|
+
onSwipedRight: () => shouldSlideOnSwipe && slide('previous', sliderDispatch),
|
|
92
|
+
onSwipedLeft: () => shouldSlideOnSwipe && slide('next', sliderDispatch),
|
|
98
93
|
trackMouse: true,
|
|
99
94
|
...swipeableConfigOverrides,
|
|
100
95
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlider.js","sourceRoot":"","sources":["../../../src/hooks/useSlider/useSlider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAyD9C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,KAAa,EAAE,EAAE,CACzD,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,KAAa,EAAE,EAAE,CAC7D,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,OAAO,GAAG,CAAC,CAAC,GAAG,KAAK,CA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CAAA;AACH,CAAC"}
|
|
@@ -5,7 +5,7 @@ const Bullets = forwardRef(function Bullets({ totalQuantity, activeBullet, onCli
|
|
|
5
5
|
const bulletIndexes = useMemo(() => Array(totalQuantity).fill(0), [totalQuantity]);
|
|
6
6
|
return (React.createElement("div", Object.assign({ ref: ref, "data-fs-bullets": true, "data-testid": testId, role: "tablist" }, otherProps), bulletIndexes.map((_, idx) => {
|
|
7
7
|
const isActive = activeBullet === idx;
|
|
8
|
-
return (React.createElement(Button, {
|
|
8
|
+
return (React.createElement(Button, { key: idx, role: "tab", tabIndex: -1, "data-fs-bullet": true, testId: `${testId}-bullet`, onClick: (e) => onClick(e, idx), "aria-label": ariaLabelGenerator(idx, isActive), "aria-controls": ariaControlsGenerator?.(idx), "aria-selected": isActive }));
|
|
9
9
|
})));
|
|
10
10
|
});
|
|
11
11
|
export default Bullets;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bullets.js","sourceRoot":"","sources":["../../../src/molecules/Bullets/Bullets.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAElD,OAAO,MAAM,MAAM,oBAAoB,CAAA;AAmCvC,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,QAAiB,EAAE,EAAE,CAC1D,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,cAAc,GAAG,GAAG,CAAC,EAAE,CAAA;AAErD,MAAM,OAAO,GAAG,UAAU,CAA+B,SAAS,OAAO,CACvE,EACE,aAAa,EACb,YAAY,EACZ,OAAO,EACP,MAAM,GAAG,eAAe,EACxB,kBAAkB,GAAG,gBAAgB,EACrC,qBAAqB,EACrB,GAAG,UAAU,EACd,EACD,GAAG;IAEH,MAAM,aAAa,GAAG,OAAO,CAC3B,GAAG,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAClC,CAAC,aAA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V,QAAQ,EAAE,CAAC,CAAC,0BAEZ,MAAM,EAAE,GAAG,MAAM,SAAS,EAC1B,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,gBACnB,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,mBAC9B,qBAAqB,EAAE,CAAC,GAAG,CAAC,mBAC5B,QAAQ,GACvB,CACH,CAAA;IACH,CAAC,CAAC,CACE,CACP,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,eAAe,OAAO,CAAA"}
|
|
@@ -1,16 +1,54 @@
|
|
|
1
|
-
import type { PropsWithChildren } from 'react';
|
|
1
|
+
import type { ReactNode, PropsWithChildren } from 'react';
|
|
2
2
|
import type { SwipeableProps } from 'react-swipeable';
|
|
3
3
|
export interface CarouselProps extends SwipeableProps {
|
|
4
|
+
/**
|
|
5
|
+
* ID of the current instance of the component.
|
|
6
|
+
*/
|
|
4
7
|
id?: string;
|
|
8
|
+
/**
|
|
9
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
10
|
+
*/
|
|
5
11
|
testId?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the value of element's class content attribute.
|
|
14
|
+
*/
|
|
15
|
+
className?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether or not the Carousel is infinite slide/scroll. Only for the `slide` variant.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
6
20
|
infiniteMode?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Specifies which navigation elements should be visible.
|
|
23
|
+
* @default complete
|
|
24
|
+
*/
|
|
7
25
|
controls?: 'complete' | 'navigationArrows' | 'paginationBullets';
|
|
26
|
+
/**
|
|
27
|
+
* Specifies the slide transition. Only for the `slide` variant
|
|
28
|
+
*/
|
|
8
29
|
transition?: {
|
|
9
30
|
duration: number;
|
|
10
31
|
property: string;
|
|
11
32
|
delay?: number;
|
|
12
33
|
timing?: string;
|
|
13
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Specifies the number of items per page.
|
|
37
|
+
* @default 1
|
|
38
|
+
*/
|
|
39
|
+
itemsPerPage?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Specifies the Carousel track variant.
|
|
42
|
+
* @default slide
|
|
43
|
+
*/
|
|
44
|
+
variant?: 'slide' | 'scroll';
|
|
45
|
+
/**
|
|
46
|
+
* Specifies the navigation icons.
|
|
47
|
+
*/
|
|
48
|
+
navigationIcons?: {
|
|
49
|
+
left?: ReactNode;
|
|
50
|
+
right?: ReactNode;
|
|
51
|
+
};
|
|
14
52
|
}
|
|
15
|
-
declare function Carousel({ infiniteMode, controls, testId, transition, children, id, ...swipeableConfigOverrides }: PropsWithChildren<CarouselProps>): JSX.Element;
|
|
53
|
+
declare function Carousel({ infiniteMode, controls, testId, transition, children, className, id, variant, itemsPerPage, navigationIcons, ...swipeableConfigOverrides }: PropsWithChildren<CarouselProps>): JSX.Element;
|
|
16
54
|
export default Carousel;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
1
|
+
import React, { useMemo, useRef } from 'react';
|
|
2
2
|
import { RightArrowIcon, LeftArrowIcon } from './Arrows';
|
|
3
|
+
import CarouselItem from './CarouselItem';
|
|
3
4
|
import useSlider from '../../hooks/useSlider/useSlider';
|
|
4
|
-
import useSlideVisibility from './hooks/useSlideVisibility';
|
|
5
5
|
import Bullets from '../Bullets';
|
|
6
6
|
import IconButton from '../IconButton';
|
|
7
7
|
const createTransformValues = (infinite, totalItems) => {
|
|
@@ -17,7 +17,10 @@ const createTransformValues = (infinite, totalItems) => {
|
|
|
17
17
|
function Carousel({ infiniteMode = true, controls = 'complete', testId = 'store-carousel', transition = {
|
|
18
18
|
duration: 400,
|
|
19
19
|
property: 'transform',
|
|
20
|
-
}, children, id = 'store-carousel', ...swipeableConfigOverrides }) {
|
|
20
|
+
}, children, className, id = 'store-carousel', variant = 'slide', itemsPerPage = 1, navigationIcons = undefined, ...swipeableConfigOverrides }) {
|
|
21
|
+
const carouselTrackRef = useRef(null);
|
|
22
|
+
const isSlideCarousel = variant === 'slide';
|
|
23
|
+
const isScrollCarousel = variant === 'scroll';
|
|
21
24
|
const childrenArray = React.Children.toArray(children);
|
|
22
25
|
const childrenCount = childrenArray.length;
|
|
23
26
|
const numberOfSlides = infiniteMode ? childrenCount + 2 : childrenCount;
|
|
@@ -26,19 +29,35 @@ function Carousel({ infiniteMode = true, controls = 'complete', testId = 'store-
|
|
|
26
29
|
const showPaginationBullets = controls === 'complete' || controls === 'paginationBullets';
|
|
27
30
|
const transformValues = useMemo(() => createTransformValues(infiniteMode, numberOfSlides), [numberOfSlides, infiniteMode]);
|
|
28
31
|
const { handlers, slide, sliderState, sliderDispatch } = useSlider({
|
|
29
|
-
|
|
30
|
-
itemsPerPage: 1,
|
|
32
|
+
itemsPerPage,
|
|
31
33
|
infiniteMode,
|
|
32
|
-
...swipeableConfigOverrides,
|
|
33
|
-
});
|
|
34
|
-
const { isItemVisible, shouldRenderItem } = useSlideVisibility({
|
|
35
|
-
itemsPerPage: sliderState.itemsPerPage,
|
|
36
|
-
currentSlide: sliderState.currentItem,
|
|
37
34
|
totalItems: childrenCount,
|
|
35
|
+
shouldSlideOnSwipe: isSlideCarousel,
|
|
36
|
+
...swipeableConfigOverrides,
|
|
38
37
|
});
|
|
39
38
|
const postRenderedSlides = infiniteMode && children ? childrenArray.slice(0, 1) : [];
|
|
40
39
|
const preRenderedSlides = infiniteMode && children ? childrenArray.slice(childrenCount - 1) : [];
|
|
41
40
|
const slides = preRenderedSlides.concat(children ?? [], postRenderedSlides);
|
|
41
|
+
const slideCarouselTrackStyle = useMemo(() => ({
|
|
42
|
+
display: 'flex',
|
|
43
|
+
width: `${numberOfSlides * 100}%`,
|
|
44
|
+
transition: sliderState.sliding ? slidingTransition : undefined,
|
|
45
|
+
transform: `translate3d(${transformValues[sliderState.currentPage]}%, 0, 0)`,
|
|
46
|
+
}), [
|
|
47
|
+
numberOfSlides,
|
|
48
|
+
transformValues,
|
|
49
|
+
slidingTransition,
|
|
50
|
+
sliderState.sliding,
|
|
51
|
+
sliderState.currentPage,
|
|
52
|
+
]);
|
|
53
|
+
const scrollCarouselTrackStyle = useMemo(() => ({
|
|
54
|
+
width: '100%',
|
|
55
|
+
display: 'block',
|
|
56
|
+
overflowX: 'scroll',
|
|
57
|
+
whiteSpace: 'nowrap',
|
|
58
|
+
}), []);
|
|
59
|
+
const carouselTrackStyle = (isSlideCarousel && slideCarouselTrackStyle) ||
|
|
60
|
+
(isScrollCarousel && scrollCarouselTrackStyle);
|
|
42
61
|
const slidePrevious = () => {
|
|
43
62
|
if (sliderState.sliding ||
|
|
44
63
|
(!infiniteMode && sliderState.currentPage === 0)) {
|
|
@@ -53,15 +72,74 @@ function Carousel({ infiniteMode = true, controls = 'complete', testId = 'store-
|
|
|
53
72
|
}
|
|
54
73
|
slide('next', sliderDispatch);
|
|
55
74
|
};
|
|
75
|
+
const onScrollTrack = (event) => {
|
|
76
|
+
if (isSlideCarousel || itemsPerPage > 1) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const itemWidth = Number(event.currentTarget.firstElementChild?.scrollWidth);
|
|
80
|
+
const scrollOffset = event.currentTarget?.scrollLeft;
|
|
81
|
+
const formatter = scrollOffset > itemWidth / 2 ? Math.round : Math.floor;
|
|
82
|
+
const page = formatter(scrollOffset / itemWidth);
|
|
83
|
+
slide(page, sliderDispatch);
|
|
84
|
+
};
|
|
85
|
+
const onTransitionTrackEnd = () => {
|
|
86
|
+
sliderDispatch({
|
|
87
|
+
type: 'STOP_SLIDE',
|
|
88
|
+
});
|
|
89
|
+
if (infiniteMode && sliderState.currentItem >= childrenCount) {
|
|
90
|
+
sliderDispatch({
|
|
91
|
+
type: 'GO_TO_PAGE',
|
|
92
|
+
payload: {
|
|
93
|
+
pageIndex: 0,
|
|
94
|
+
shouldSlide: false,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (infiniteMode && sliderState.currentItem < 0) {
|
|
99
|
+
sliderDispatch({
|
|
100
|
+
type: 'GO_TO_PAGE',
|
|
101
|
+
payload: {
|
|
102
|
+
pageIndex: sliderState.totalPages - 1,
|
|
103
|
+
shouldSlide: false,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const onScrollPagination = async (index, slideDirection) => {
|
|
109
|
+
if (slideDirection === 'previous' && sliderState.currentPage === 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (slideDirection === 'next' &&
|
|
113
|
+
sliderState.currentPage === sliderState.totalPages - 1) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
let scrollOffset;
|
|
117
|
+
const carouselItemsWidth = Number(carouselTrackRef.current?.firstElementChild?.clientWidth);
|
|
118
|
+
if (itemsPerPage > 1) {
|
|
119
|
+
scrollOffset = index * carouselItemsWidth * itemsPerPage;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
scrollOffset = index * carouselItemsWidth - carouselItemsWidth * 0.125;
|
|
123
|
+
}
|
|
124
|
+
carouselTrackRef.current?.scrollTo({
|
|
125
|
+
left: scrollOffset,
|
|
126
|
+
behavior: 'smooth',
|
|
127
|
+
});
|
|
128
|
+
slide(index, sliderDispatch);
|
|
129
|
+
};
|
|
56
130
|
// accessible behavior for tablist
|
|
57
131
|
const handleBulletsKeyDown = (event) => {
|
|
58
132
|
switch (event.key) {
|
|
59
133
|
case 'ArrowLeft': {
|
|
60
|
-
slidePrevious();
|
|
134
|
+
isSlideCarousel && slidePrevious();
|
|
135
|
+
isScrollCarousel &&
|
|
136
|
+
onScrollPagination(sliderState.currentPage - 1, 'previous');
|
|
61
137
|
break;
|
|
62
138
|
}
|
|
63
139
|
case 'ArrowRight': {
|
|
64
|
-
slideNext();
|
|
140
|
+
isSlideCarousel && slideNext();
|
|
141
|
+
isScrollCarousel &&
|
|
142
|
+
onScrollPagination(sliderState.currentPage + 1, 'next');
|
|
65
143
|
break;
|
|
66
144
|
}
|
|
67
145
|
case 'Home': {
|
|
@@ -75,50 +153,31 @@ function Carousel({ infiniteMode = true, controls = 'complete', testId = 'store-
|
|
|
75
153
|
default:
|
|
76
154
|
}
|
|
77
155
|
};
|
|
78
|
-
return (React.createElement("section", { id: id, "data-fs-carousel": true, "data-testid": testId, "aria-label": "carousel", "aria-roledescription": "carousel" },
|
|
79
|
-
React.createElement("div", Object.assign({ "data-carousel-track-container": true, style: {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
shouldSlide: false,
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}, "aria-live": "polite" }, slides.map((currentSlide, idx) => (React.createElement("div", { role: "tabpanel", "aria-roledescription": "slide", key: idx, id: `carousel-item-${idx}`, "data-carousel-item": true, style: { width: '100%' }, "data-visible": isItemVisible(idx - Number(infiniteMode)) || undefined }, shouldRenderItem(idx - Number(infiniteMode))
|
|
108
|
-
? currentSlide
|
|
109
|
-
: null))))),
|
|
110
|
-
showNavigationArrows && (React.createElement("div", { "data-carousel-controls": true },
|
|
111
|
-
React.createElement(IconButton, { "aria-label": "previous", "data-arrow": "left", "aria-controls": id, onClick: slidePrevious, icon: React.createElement(LeftArrowIcon, null) }),
|
|
112
|
-
React.createElement(IconButton, { "aria-label": "next", "data-arrow": "right", "aria-controls": id, onClick: slideNext, icon: React.createElement(RightArrowIcon, null) }))),
|
|
113
|
-
showPaginationBullets && (React.createElement("div", { "data-carousel-bullets": true },
|
|
114
|
-
React.createElement(Bullets, { tabIndex: 0, totalQuantity: childrenCount, activeBullet: sliderState.currentPage, onClick: (_, idx) => {
|
|
115
|
-
if (sliderState.sliding) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
slide(idx, sliderDispatch);
|
|
119
|
-
}, ariaControlsGenerator: (idx) => `carousel-item-${idx}`, onKeyDown: handleBulletsKeyDown, onFocus: (event) => {
|
|
120
|
-
event.currentTarget.focus();
|
|
121
|
-
} })))));
|
|
156
|
+
return (React.createElement("section", { id: id, "data-fs-carousel": true, className: className, "data-testid": testId, "aria-label": "carousel", "aria-roledescription": "carousel" },
|
|
157
|
+
React.createElement("div", Object.assign({ "data-fs-carousel-track-container": true, style: {
|
|
158
|
+
width: '100%',
|
|
159
|
+
overflow: 'hidden',
|
|
160
|
+
display: isScrollCarousel ? 'block' : undefined,
|
|
161
|
+
} }, handlers),
|
|
162
|
+
React.createElement("ul", { "aria-live": "polite", ref: carouselTrackRef, style: carouselTrackStyle, "data-fs-carousel-track": true, onScroll: onScrollTrack, onTransitionEnd: onTransitionTrackEnd }, slides.map((currentSlide, idx) => (React.createElement(CarouselItem, { index: idx, key: String(idx), state: sliderState, totalItems: childrenCount, infiniteMode: infiniteMode, isScrollCarousel: isScrollCarousel }, currentSlide))))),
|
|
163
|
+
showNavigationArrows && (React.createElement("div", { "data-fs-carousel-controls": true },
|
|
164
|
+
React.createElement(IconButton, { "data-fs-carousel-control": "left", "aria-controls": id, "aria-label": "previous", icon: navigationIcons?.left ?? React.createElement(LeftArrowIcon, null), onClick: () => {
|
|
165
|
+
isSlideCarousel && slidePrevious();
|
|
166
|
+
isScrollCarousel &&
|
|
167
|
+
onScrollPagination(sliderState.currentPage - 1, 'previous');
|
|
168
|
+
} }),
|
|
169
|
+
React.createElement(IconButton, { "data-fs-carousel-control": "right", "aria-controls": id, "aria-label": "next", icon: navigationIcons?.right ?? React.createElement(RightArrowIcon, null), onClick: () => {
|
|
170
|
+
isSlideCarousel && slideNext();
|
|
171
|
+
isScrollCarousel &&
|
|
172
|
+
onScrollPagination(sliderState.currentPage + 1, 'next');
|
|
173
|
+
} }))),
|
|
174
|
+
showPaginationBullets && (React.createElement("div", { "data-fs-carousel-bullets": true },
|
|
175
|
+
React.createElement(Bullets, { tabIndex: 0, activeBullet: sliderState.currentPage, totalQuantity: Math.ceil(childrenCount / sliderState.itemsPerPage), onKeyDown: handleBulletsKeyDown, onClick: async (_, idx) => {
|
|
176
|
+
isSlideCarousel &&
|
|
177
|
+
!sliderState.sliding &&
|
|
178
|
+
slide(idx, sliderDispatch);
|
|
179
|
+
isScrollCarousel && onScrollPagination(idx);
|
|
180
|
+
}, onFocus: (event) => event.currentTarget.focus(), ariaControlsGenerator: (idx) => `carousel-item-${idx}` })))));
|
|
122
181
|
}
|
|
123
182
|
export default Carousel;
|
|
124
183
|
//# sourceMappingURL=Carousel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Carousel.js","sourceRoot":"","sources":["../../../src/molecules/Carousel/Carousel.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Carousel.js","sourceRoot":"","sources":["../../../src/molecules/Carousel/Carousel.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAG9C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxD,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,SAAS,MAAM,iCAAiC,CAAA;AACvD,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,UAAU,MAAM,eAAe,CAAA;AAEtC,MAAM,qBAAqB,GAAG,CAAC,QAAiB,EAAE,UAAkB,EAAE,EAAE;IACtE,MAAM,YAAY,GAA2B,EAAE,CAAA;IAC/C,MAAM,UAAU,GAAG,GAAG,GAAG,UAAU,CAAA;IAEnC,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,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A;oBAE5B,gBAAgB,IAAI,kBAAkB,CAAC,GAAG,CAAC,CAAA;gBAC7C,CAAC,EACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,EAC/C,qBAAqB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,iBAAiB,GAAG,EAAE,GACtD,CACE,CACP,CACO,CACX,CAAA;AACH,CAAC;AAED,eAAe,QAAQ,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PropsWithChildren, HTMLAttributes } from 'react';
|
|
2
|
+
import type { SliderState } from '../../hooks/useSlider/useSlider';
|
|
3
|
+
interface CarouselItemProps extends HTMLAttributes<HTMLLIElement> {
|
|
4
|
+
index: number;
|
|
5
|
+
totalItems: number;
|
|
6
|
+
state: SliderState;
|
|
7
|
+
infiniteMode: boolean;
|
|
8
|
+
isScrollCarousel: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function CarouselItem({ index, state, children, totalItems, infiniteMode, isScrollCarousel, }: PropsWithChildren<CarouselItemProps>): JSX.Element;
|
|
11
|
+
export default CarouselItem;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import useSlideVisibility from './hooks/useSlideVisibility';
|
|
3
|
+
function CarouselItem({ index, state, children, totalItems, infiniteMode, isScrollCarousel, }) {
|
|
4
|
+
const { isItemVisible, shouldRenderItem } = useSlideVisibility({
|
|
5
|
+
totalItems,
|
|
6
|
+
currentSlide: state.currentItem,
|
|
7
|
+
itemsPerPage: state.itemsPerPage,
|
|
8
|
+
});
|
|
9
|
+
const style = (!isScrollCarousel && { width: '100%' }) ||
|
|
10
|
+
(isScrollCarousel && {
|
|
11
|
+
maxWidth: '80%',
|
|
12
|
+
display: 'inline-block',
|
|
13
|
+
});
|
|
14
|
+
const shouldDisplayItem = isScrollCarousel || shouldRenderItem(index - Number(infiniteMode));
|
|
15
|
+
return (React.createElement("li", { style: style, "data-fs-carousel-item": true, "aria-roledescription": "slide", id: `carousel-item-${index}`, "data-fs-carousel-item-visible": isItemVisible(index - Number(infiniteMode)) || undefined }, shouldDisplayItem ? children : null));
|
|
16
|
+
}
|
|
17
|
+
export default CarouselItem;
|
|
18
|
+
//# sourceMappingURL=CarouselItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CarouselItem.js","sourceRoot":"","sources":["../../../src/molecules/Carousel/CarouselItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,kBAAkB,MAAM,4BAA4B,CAAA;AAU3D,SAAS,YAAY,CAAC,EACpB,KAAK,EACL,KAAK,EACL,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,gBAAgB,GACqB;IACrC,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,GAAG,kBAAkB,CAAC;QAC7D,UAAU;QACV,YAAY,EAAE,KAAK,CAAC,WAAW;QAC/B,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CAAC,CAAA;IAEF,MAAM,KAAK,GACR,CAAC,CAAC,gBAAgB,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAmB;QAC1D,CAAC,gBAAgB,IAAI;YACpB,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,cAAc;SACxB,CAAmB,CAAA;IAEtB,MAAM,iBAAiB,GACrB,gBAAgB,IAAI,gBAAgB,CAAC,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;IAEpE,OAAO,CACL,4BACE,KAAK,EAAE,KAAK,yDAES,OAAO,EAC5B,EAAE,EAAE,iBAAiB,KAAK,EAAE,mCAE1B,aAAa,CAAC,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,SAAS,IAGzD,iBAAiB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CACjC,CACN,CAAA;AACH,CAAC;AAED,eAAe,YAAY,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/ui",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.23",
|
|
4
4
|
"description": "A lightweight, framework agnostic component library for React",
|
|
5
5
|
"author": "emersonlaurentino",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@reach/popover": "^0.16.0",
|
|
51
51
|
"@storybook/addon-a11y": "^6.4.4",
|
|
52
|
-
"react-swipeable": "^
|
|
52
|
+
"react-swipeable": "^7.0.0",
|
|
53
53
|
"tabbable": "^5.2.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"react-dom": "^17.0.2"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@faststore/shared": "^1.12.
|
|
61
|
-
"@faststore/styles": "^1.12.
|
|
60
|
+
"@faststore/shared": "^1.12.20",
|
|
61
|
+
"@faststore/styles": "^1.12.23",
|
|
62
62
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
63
63
|
"@storybook/addon-actions": "^6.4.4",
|
|
64
64
|
"@storybook/addon-docs": "^6.4.4",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"tsdx": "^0.14.1",
|
|
86
86
|
"typescript": "^4.2.4"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "75646edad6c5c1726d7e2858e7d6677411edf678"
|
|
89
89
|
}
|
|
@@ -152,15 +152,11 @@ const defaultSliderState = (
|
|
|
152
152
|
|
|
153
153
|
const slide = (page: SlideDirection | number, dispatch: Dispatch<Action>) => {
|
|
154
154
|
if (page === 'next') {
|
|
155
|
-
dispatch({
|
|
156
|
-
type: 'NEXT_PAGE',
|
|
157
|
-
})
|
|
155
|
+
dispatch({ type: 'NEXT_PAGE' })
|
|
158
156
|
}
|
|
159
157
|
|
|
160
158
|
if (page === 'previous') {
|
|
161
|
-
dispatch({
|
|
162
|
-
type: 'PREVIOUS_PAGE',
|
|
163
|
-
})
|
|
159
|
+
dispatch({ type: 'PREVIOUS_PAGE' })
|
|
164
160
|
}
|
|
165
161
|
|
|
166
162
|
if (typeof page === 'number') {
|
|
@@ -181,12 +177,15 @@ export interface UseSliderArgs extends SwipeableProps {
|
|
|
181
177
|
itemsPerPage?: number
|
|
182
178
|
/** Whether or not the slider is infinite. */
|
|
183
179
|
infiniteMode?: boolean
|
|
180
|
+
/** Whether or not slide after swiping left/right. */
|
|
181
|
+
shouldSlideOnSwipe?: boolean
|
|
184
182
|
}
|
|
185
183
|
|
|
186
184
|
export default function useSlider({
|
|
187
185
|
totalItems,
|
|
188
186
|
itemsPerPage = 1,
|
|
189
187
|
infiniteMode = false,
|
|
188
|
+
shouldSlideOnSwipe = true,
|
|
190
189
|
...swipeableConfigOverrides
|
|
191
190
|
}: UseSliderArgs) {
|
|
192
191
|
const [sliderState, sliderDispatch] = useReducer(reducer, undefined, () =>
|
|
@@ -194,9 +193,9 @@ export default function useSlider({
|
|
|
194
193
|
)
|
|
195
194
|
|
|
196
195
|
const handlers = useSwipeable({
|
|
197
|
-
onSwipedRight: () =>
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
onSwipedRight: () =>
|
|
197
|
+
shouldSlideOnSwipe && slide('previous', sliderDispatch),
|
|
198
|
+
onSwipedLeft: () => shouldSlideOnSwipe && slide('next', sliderDispatch),
|
|
200
199
|
trackMouse: true,
|
|
201
200
|
...swipeableConfigOverrides,
|
|
202
201
|
})
|
|
@@ -13,17 +13,17 @@ describe('Bullets', () => {
|
|
|
13
13
|
expect(getByTestId('store-bullets')).toHaveAttribute('data-fs-bullets')
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
-
it('should render 5 bullets with `data-bullet
|
|
16
|
+
it('should render 5 bullets with `data-fs-bullet` attribute', () => {
|
|
17
17
|
const { queryAllByTestId } = render(
|
|
18
18
|
<Bullets totalQuantity={5} activeBullet={2} onClick={() => null} />
|
|
19
19
|
)
|
|
20
20
|
|
|
21
|
-
const bulletItems = queryAllByTestId('store-bullets-
|
|
21
|
+
const bulletItems = queryAllByTestId('store-bullets-bullet')
|
|
22
22
|
|
|
23
23
|
expect(bulletItems).toHaveLength(5)
|
|
24
24
|
|
|
25
25
|
bulletItems.forEach((bullet) =>
|
|
26
|
-
expect(bullet).toHaveAttribute('data-bullet
|
|
26
|
+
expect(bullet).toHaveAttribute('data-fs-bullet')
|
|
27
27
|
)
|
|
28
28
|
})
|
|
29
29
|
|
|
@@ -32,7 +32,7 @@ describe('Bullets', () => {
|
|
|
32
32
|
<Bullets totalQuantity={5} activeBullet={2} onClick={() => null} />
|
|
33
33
|
)
|
|
34
34
|
|
|
35
|
-
const bulletItems = queryAllByTestId('store-bullets-
|
|
35
|
+
const bulletItems = queryAllByTestId('store-bullets-bullet')
|
|
36
36
|
|
|
37
37
|
// eslint-disable-next-line prefer-destructuring
|
|
38
38
|
const expectedActiveBullet = bulletItems[2]
|
|
@@ -59,7 +59,7 @@ describe('Bullets', () => {
|
|
|
59
59
|
/>
|
|
60
60
|
)
|
|
61
61
|
|
|
62
|
-
const bulletItems = queryAllByTestId('store-bullets-
|
|
62
|
+
const bulletItems = queryAllByTestId('store-bullets-bullet')
|
|
63
63
|
|
|
64
64
|
expect(bulletItems).toHaveLength(5)
|
|
65
65
|
|
|
@@ -69,11 +69,11 @@ const Bullets = forwardRef<HTMLDivElement, BulletsProps>(function Bullets(
|
|
|
69
69
|
|
|
70
70
|
return (
|
|
71
71
|
<Button
|
|
72
|
-
|
|
72
|
+
key={idx}
|
|
73
73
|
role="tab"
|
|
74
74
|
tabIndex={-1}
|
|
75
|
-
|
|
76
|
-
testId={`${testId}-
|
|
75
|
+
data-fs-bullet
|
|
76
|
+
testId={`${testId}-bullet`}
|
|
77
77
|
onClick={(e) => onClick(e, idx)}
|
|
78
78
|
aria-label={ariaLabelGenerator(idx, isActive)}
|
|
79
79
|
aria-controls={ariaControlsGenerator?.(idx)}
|
|
@@ -17,9 +17,9 @@ import Bullets from '../Bullets'
|
|
|
17
17
|
```css
|
|
18
18
|
[data-fs-bullets] {}
|
|
19
19
|
|
|
20
|
-
[data-bullet
|
|
20
|
+
[data-fs-bullet] {}
|
|
21
21
|
|
|
22
|
-
[data-bullet
|
|
22
|
+
[data-fs-bullet][aria-selected="true"] {}
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
This component inherits [Button](?path=/docs/atoms-button--button#css-selectors) css selectors.
|