@wlloyalty/wll-react-sdk 1.0.100 → 1.0.102
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/dist/index.d.ts +3 -1
- package/dist/native.js +85 -45
- package/dist/native.js.map +1 -1
- package/dist/types/components/molecules/Carousel/Carousel.stories.d.ts +3 -0
- package/dist/types/components/molecules/Carousel/index.d.ts +2 -1
- package/dist/types/context/WllSdkContext.d.ts +1 -0
- package/dist/web.js +65 -18
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,10 +3,13 @@ declare const _default: Meta;
|
|
|
3
3
|
export default _default;
|
|
4
4
|
export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, {
|
|
5
5
|
section?: import("../../../types/section").TSection;
|
|
6
|
+
autoRotateInterval?: number;
|
|
6
7
|
}>;
|
|
7
8
|
export declare const SingleItem: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, {
|
|
8
9
|
section?: import("../../../types/section").TSection;
|
|
10
|
+
autoRotateInterval?: number;
|
|
9
11
|
}>;
|
|
10
12
|
export declare const ManyItems: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, {
|
|
11
13
|
section?: import("../../../types/section").TSection;
|
|
14
|
+
autoRotateInterval?: number;
|
|
12
15
|
}>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TSection } from '../../../types/section';
|
|
2
2
|
type CarouselProps = {
|
|
3
3
|
section?: TSection;
|
|
4
|
+
autoRotateInterval?: number;
|
|
4
5
|
};
|
|
5
|
-
declare const Carousel: ({ section }: CarouselProps) => JSX.Element | null;
|
|
6
|
+
declare const Carousel: ({ section, autoRotateInterval, }: CarouselProps) => JSX.Element | null;
|
|
6
7
|
export default Carousel;
|
|
@@ -21,6 +21,7 @@ type WllSdkContextType = ThemeContextType & {
|
|
|
21
21
|
getSectionByID: (id: string) => Promise<APIResponse<TSection>>;
|
|
22
22
|
getTileByID: (id: string) => Promise<APIResponse<Tile>>;
|
|
23
23
|
handleNavigation: (link: string, target: CTALinkTarget) => Promise<void>;
|
|
24
|
+
refreshGroup: (id: string) => Promise<APIResponse<TGroup>>;
|
|
24
25
|
} & Readonly<{
|
|
25
26
|
readonly config: SDKConfig;
|
|
26
27
|
}>;
|
package/dist/web.js
CHANGED
|
@@ -8252,9 +8252,6 @@ var validateTheme = function (theme) {
|
|
|
8252
8252
|
var createSafeColor = function (color) {
|
|
8253
8253
|
try {
|
|
8254
8254
|
var colorInstance = Color(color);
|
|
8255
|
-
console.log('Original color:', color);
|
|
8256
|
-
console.log('Color instance toString:', colorInstance.toString());
|
|
8257
|
-
console.log('Color instance hex:', colorInstance.hex());
|
|
8258
8255
|
return colorInstance;
|
|
8259
8256
|
} catch (error) {
|
|
8260
8257
|
console.error("Invalid color value: ".concat(color), error);
|
|
@@ -8521,6 +8518,13 @@ var WllSdkProvider = function (_a) {
|
|
|
8521
8518
|
var getSectionByID = useGetSectionByID(config);
|
|
8522
8519
|
var getTileByID = useGetTileByID(config);
|
|
8523
8520
|
var handleNavigation = useNavigation(navigationConfig);
|
|
8521
|
+
var refreshGroup = React.useCallback(function (id) {
|
|
8522
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
8523
|
+
return __generator(this, function (_a) {
|
|
8524
|
+
return [2 /*return*/, getGroupByID(id)];
|
|
8525
|
+
});
|
|
8526
|
+
});
|
|
8527
|
+
}, [getGroupByID]);
|
|
8524
8528
|
var contextValue = React.useMemo(function () {
|
|
8525
8529
|
return {
|
|
8526
8530
|
theme: theme,
|
|
@@ -8529,9 +8533,10 @@ var WllSdkProvider = function (_a) {
|
|
|
8529
8533
|
getSectionByID: getSectionByID,
|
|
8530
8534
|
getTileByID: getTileByID,
|
|
8531
8535
|
handleNavigation: handleNavigation,
|
|
8536
|
+
refreshGroup: refreshGroup,
|
|
8532
8537
|
config: config
|
|
8533
8538
|
};
|
|
8534
|
-
}, [theme, setTheme, getGroupByID, getSectionByID, getTileByID, handleNavigation, config]);
|
|
8539
|
+
}, [theme, setTheme, getGroupByID, getSectionByID, getTileByID, handleNavigation, refreshGroup, config]);
|
|
8535
8540
|
return /*#__PURE__*/React.createElement(WllSdkContext.Provider, {
|
|
8536
8541
|
value: contextValue
|
|
8537
8542
|
}, /*#__PURE__*/React.createElement(ResponsiveProvider, null, children));
|
|
@@ -20553,22 +20558,24 @@ var carouselReducer = function (state, action) {
|
|
|
20553
20558
|
}
|
|
20554
20559
|
};
|
|
20555
20560
|
var Carousel = function (_a) {
|
|
20556
|
-
var section = _a.section
|
|
20561
|
+
var section = _a.section,
|
|
20562
|
+
_b = _a.autoRotateInterval,
|
|
20563
|
+
autoRotateInterval = _b === void 0 ? 5000 : _b;
|
|
20557
20564
|
if (!section) return null;
|
|
20558
20565
|
var WINDOW_WIDTH = useWindowDimensions().width;
|
|
20559
20566
|
var containerRef = React.useRef(null);
|
|
20560
20567
|
var styles = useCarouselStyles(BUTTON_SIZE);
|
|
20561
20568
|
var animatedIndex = React.useRef(new Animated$1.Value(0)).current;
|
|
20562
20569
|
var theme = useWllSdk().theme;
|
|
20563
|
-
var
|
|
20564
|
-
isDesktop =
|
|
20565
|
-
isTablet =
|
|
20570
|
+
var _c = useResponsive(),
|
|
20571
|
+
isDesktop = _c.isDesktop,
|
|
20572
|
+
isTablet = _c.isTablet;
|
|
20566
20573
|
var scrollViewRef = React.useRef(null);
|
|
20567
|
-
var
|
|
20574
|
+
var _d = React.useReducer(carouselReducer, __assign(__assign({}, initialState), {
|
|
20568
20575
|
containerWidth: WINDOW_WIDTH
|
|
20569
20576
|
})),
|
|
20570
|
-
state =
|
|
20571
|
-
dispatch =
|
|
20577
|
+
state = _d[0],
|
|
20578
|
+
dispatch = _d[1];
|
|
20572
20579
|
var currentIndex = state.currentIndex,
|
|
20573
20580
|
containerWidth = state.containerWidth;
|
|
20574
20581
|
var sortedTiles = sortByPriority(section.tiles.filter(function (tile) {
|
|
@@ -20599,15 +20606,40 @@ var Carousel = function (_a) {
|
|
|
20599
20606
|
};
|
|
20600
20607
|
var handleNext = function () {
|
|
20601
20608
|
var _a;
|
|
20609
|
+
var nextIndex = Math.min(sortedTiles.length - 1, currentIndex + 1);
|
|
20602
20610
|
dispatch({
|
|
20603
20611
|
type: 'NEXT_SLIDE',
|
|
20604
20612
|
maxIndex: sortedTiles.length - 1
|
|
20605
20613
|
});
|
|
20606
20614
|
(_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
|
|
20607
|
-
x:
|
|
20615
|
+
x: nextIndex * containerWidth,
|
|
20608
20616
|
animated: true
|
|
20609
20617
|
});
|
|
20610
20618
|
};
|
|
20619
|
+
var rotateToNextSlide = React.useCallback(function () {
|
|
20620
|
+
var _a;
|
|
20621
|
+
if (currentIndex >= sortedTiles.length - 1) {
|
|
20622
|
+
dispatch({
|
|
20623
|
+
type: 'SET_CURRENT_INDEX',
|
|
20624
|
+
payload: 0
|
|
20625
|
+
});
|
|
20626
|
+
(_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
|
|
20627
|
+
x: 0,
|
|
20628
|
+
animated: true
|
|
20629
|
+
});
|
|
20630
|
+
} else {
|
|
20631
|
+
handleNext();
|
|
20632
|
+
}
|
|
20633
|
+
}, [currentIndex, containerWidth, sortedTiles.length]);
|
|
20634
|
+
React.useEffect(function () {
|
|
20635
|
+
if (sortedTiles.length <= 1) return;
|
|
20636
|
+
var rotationTimer = setInterval(function () {
|
|
20637
|
+
rotateToNextSlide();
|
|
20638
|
+
}, autoRotateInterval);
|
|
20639
|
+
return function () {
|
|
20640
|
+
return clearInterval(rotationTimer);
|
|
20641
|
+
};
|
|
20642
|
+
}, [rotateToNextSlide, autoRotateInterval, sortedTiles.length]);
|
|
20611
20643
|
var displayControls = sortedTiles.length > 1;
|
|
20612
20644
|
var showPrevButton = displayControls && currentIndex > 0;
|
|
20613
20645
|
var showNextButton = displayControls && currentIndex < sortedTiles.length - 1;
|
|
@@ -21090,8 +21122,15 @@ var useGroupData = function (id) {
|
|
|
21090
21122
|
isLoading = _c[0],
|
|
21091
21123
|
setIsLoading = _c[1];
|
|
21092
21124
|
var fetchGroup = React.useCallback(function () {
|
|
21093
|
-
|
|
21125
|
+
var args_1 = [];
|
|
21126
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
21127
|
+
args_1[_i] = arguments[_i];
|
|
21128
|
+
}
|
|
21129
|
+
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (showLoading) {
|
|
21094
21130
|
var response, err_1;
|
|
21131
|
+
if (showLoading === void 0) {
|
|
21132
|
+
showLoading = true;
|
|
21133
|
+
}
|
|
21095
21134
|
return __generator(this, function (_a) {
|
|
21096
21135
|
switch (_a.label) {
|
|
21097
21136
|
case 0:
|
|
@@ -21100,12 +21139,14 @@ var useGroupData = function (id) {
|
|
|
21100
21139
|
setIsLoading(false);
|
|
21101
21140
|
return [2 /*return*/];
|
|
21102
21141
|
}
|
|
21103
|
-
|
|
21142
|
+
if (showLoading) {
|
|
21143
|
+
setIsLoading(true);
|
|
21144
|
+
}
|
|
21104
21145
|
setError(null);
|
|
21105
21146
|
_a.label = 1;
|
|
21106
21147
|
case 1:
|
|
21107
21148
|
_a.trys.push([1, 3, 4, 5]);
|
|
21108
|
-
return [4 /*yield*/, sdk.
|
|
21149
|
+
return [4 /*yield*/, sdk.refreshGroup(id)];
|
|
21109
21150
|
case 2:
|
|
21110
21151
|
response = _a.sent();
|
|
21111
21152
|
if (response && response.status === 'success' && response.data) {
|
|
@@ -21120,7 +21161,9 @@ var useGroupData = function (id) {
|
|
|
21120
21161
|
console.error('Error fetching group:', err_1);
|
|
21121
21162
|
return [3 /*break*/, 5];
|
|
21122
21163
|
case 4:
|
|
21123
|
-
|
|
21164
|
+
if (showLoading) {
|
|
21165
|
+
setIsLoading(false);
|
|
21166
|
+
}
|
|
21124
21167
|
return [7 /*endfinally*/];
|
|
21125
21168
|
case 5:
|
|
21126
21169
|
return [2 /*return*/];
|
|
@@ -21128,13 +21171,17 @@ var useGroupData = function (id) {
|
|
|
21128
21171
|
});
|
|
21129
21172
|
});
|
|
21130
21173
|
}, [id, sdk]);
|
|
21174
|
+
var refreshGroup = React.useCallback(function () {
|
|
21175
|
+
return fetchGroup(false);
|
|
21176
|
+
}, [fetchGroup]);
|
|
21131
21177
|
React.useEffect(function () {
|
|
21132
|
-
fetchGroup();
|
|
21178
|
+
fetchGroup(true);
|
|
21133
21179
|
}, [fetchGroup]);
|
|
21134
21180
|
return {
|
|
21135
21181
|
groupData: groupData,
|
|
21136
21182
|
isLoading: isLoading,
|
|
21137
|
-
error: error
|
|
21183
|
+
error: error,
|
|
21184
|
+
refreshGroup: refreshGroup
|
|
21138
21185
|
};
|
|
21139
21186
|
};
|
|
21140
21187
|
/**
|