@crystaldesign/widget-image-carousel 25.9.0-rc.9 → 25.10.0-beta.10

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,14 +1,15 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import { useState, useCallback, useEffect } from 'react';
3
- import { useCss, useProductData, useConfiguration } from '@crystaldesign/widget-library';
4
- import { Swiper, SwiperSlide } from 'swiper/react';
5
- import { Navigation } from 'swiper/modules';
6
- import 'swiper/css';
7
- import 'swiper/css/navigation';
3
+ import { useCss, useProductData, MediaItem, useConfiguration } from '@crystaldesign/widget-library';
4
+ import { useDivaCore } from '@crystaldesign/diva-core';
8
5
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
9
6
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
10
7
  import _regeneratorRuntime from '@babel/runtime/regenerator';
8
+ import { Swiper, SwiperSlide } from 'swiper/react';
9
+ import { Navigation } from 'swiper/modules';
11
10
  import classNames from 'classnames';
11
+ import 'swiper/css';
12
+ import 'swiper/css/navigation';
12
13
  import { jsx, jsxs } from 'react/jsx-runtime';
13
14
 
14
15
  (function() {
@@ -402,92 +403,125 @@ function useImageCarousel(_ref) {
402
403
  }
403
404
  }
404
405
 
405
- function styleInject(css, ref) {
406
- if ( ref === void 0 ) ref = {};
407
- var insertAt = ref.insertAt;
408
-
409
- if (!css || typeof document === 'undefined') { return; }
410
-
411
- var head = document.head || document.getElementsByTagName('head')[0];
412
- var style = document.createElement('style');
413
- style.type = 'text/css';
414
-
415
- if (insertAt === 'top') {
416
- if (head.firstChild) {
417
- head.insertBefore(style, head.firstChild);
418
- } else {
419
- head.appendChild(style);
420
- }
421
- } else {
422
- head.appendChild(style);
423
- }
424
-
425
- if (style.styleSheet) {
426
- style.styleSheet.cssText = css;
427
- } else {
428
- style.appendChild(document.createTextNode(css));
429
- }
430
- }
431
-
432
- var imageCarouselContainer = "imageCarouselContainer-5xR1Z";
433
- var imageCarousel = "imageCarousel-doGe7";
434
- var slide = "slide-kzTjO";
435
- var slideImage = "slideImage-25uCG";
436
- var slideDescriptionImage = "slideDescriptionImage-qebF3";
437
- var slideDescription = "slideDescription-UOsb1";
438
- var css_248z = ".imageCarouselContainer-5xR1Z {\n width: 100%;\n overflow: hidden;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 20px;\n}\n\n.imageCarousel-doGe7 {\n height: 100%;\n width: 100%;\n}\n\n.slide-kzTjO {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 100%;\n}\n\n.slideImage-25uCG {\n max-height: 100%;\n max-width: 100%;\n -o-object-fit: contain;\n object-fit: contain;\n cursor: pointer;\n}\n\n.slideDescriptionImage-qebF3 {\n display: flex;\n flex-direction: column;\n align-items: center;\n height: 100%;\n}\n\n.slideDescriptionImage-qebF3 img {\n cursor: pointer;\n display: block;\n width: 100%;\n max-height: 75%;\n height: auto;\n -o-object-fit: contain;\n object-fit: contain;\n}\n\n.slideDescription-UOsb1 {\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 25%;\n background: lightgrey;\n color: black;\n text-align: center;\n}\n\n.slideDescription-UOsb1 span {\n font-size: 26px;\n}\n";
439
- styleInject(css_248z);
440
-
441
406
  function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
442
407
  function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
443
- function MainComponent(props) {
444
- var _useImageCarousel = useImageCarousel(props),
445
- media = _useImageCarousel.media,
446
- error = _useImageCarousel.error,
447
- loading = _useImageCarousel.loading,
448
- setSelectedProductId = _useImageCarousel.setSelectedProductId;
449
- if (loading) return /*#__PURE__*/jsx("div", {
450
- children: "Loading..."
451
- });
452
- if (error) return /*#__PURE__*/jsx("div", {
453
- children: "Error"
454
- });
408
+ var SwiperComponent = function SwiperComponent(_ref) {
409
+ var media = _ref.media,
410
+ settings = _ref.settings,
411
+ setSelectedProductId = _ref.setSelectedProductId;
455
412
  return /*#__PURE__*/jsx("div", {
456
- className: classNames([imageCarouselContainer, 'diva-widget-image-carousel-container']),
413
+ className: classNames(['diva-widget-image-carousel-container']),
457
414
  children: /*#__PURE__*/jsx(Swiper, _objectSpread$1(_objectSpread$1({
458
415
  modules: [Navigation],
459
416
  navigation: true,
460
- className: classNames([imageCarousel, 'diva-widget-image-carousel-swiper'])
461
- }, props.settings.sliderProp), {}, {
417
+ className: classNames(['diva-widget-image-carousel-swiper'])
418
+ }, settings.sliderProp), {}, {
462
419
  children: media.map(function (m, i) {
463
420
  return /*#__PURE__*/jsx(SwiperSlide, {
464
- className: classNames([slide, 'diva-widget-image-carousel-slide']),
465
- children: props.settings.description ? /*#__PURE__*/jsxs("div", {
466
- className: classNames([slideDescriptionImage, 'diva-widget-image-carousel-slide-description-image']),
421
+ className: classNames(['diva-widget-image-carousel-slide']),
422
+ children: settings.description ? /*#__PURE__*/jsxs("div", {
423
+ className: classNames(['diva-widget-image-carousel-slide-description-image']),
467
424
  onClick: function onClick() {
468
425
  return setSelectedProductId(m.productId);
469
426
  },
470
- children: [/*#__PURE__*/jsx("img", {
471
- src: m.url,
472
- alt: "carousel image"
427
+ children: [/*#__PURE__*/jsx(MediaItem, {
428
+ mediaUrl: m.url,
429
+ isCurrentlyVisible: true,
430
+ config: {
431
+ disableSirv: false,
432
+ sirvProps: settings.sirvProps
433
+ }
473
434
  }), /*#__PURE__*/jsx("div", {
474
- className: classNames([slideDescription, 'diva-widget-image-carousel-slide-description']),
435
+ className: classNames(['diva-widget-image-carousel-slide-description']),
475
436
  children: /*#__PURE__*/jsx("span", {
476
437
  children: m.description
477
438
  })
478
439
  })]
479
- }) : /*#__PURE__*/jsx("img", {
480
- src: m.url,
481
- alt: "carousel image",
482
- className: classNames([slideImage, 'diva-widget-image-carousel-slide-image']),
440
+ }) : /*#__PURE__*/jsx(MediaItem, {
441
+ mediaUrl: m.url,
442
+ isCurrentlyVisible: true,
443
+ config: {
444
+ disableSirv: false,
445
+ sirvProps: settings.sirvProps
446
+ },
447
+ className: classNames(['diva-widget-image-carousel-slide-image']),
483
448
  onClick: function onClick() {
484
449
  return setSelectedProductId(m.productId);
485
450
  }
486
- }, m.productId + 'img')
487
- }, m.productId);
451
+ })
452
+ }, i);
488
453
  })
489
454
  }))
490
455
  });
456
+ };
457
+
458
+ var ImageList = function ImageList(_ref) {
459
+ var media = _ref.media,
460
+ settings = _ref.settings,
461
+ setSelectedProductId = _ref.setSelectedProductId;
462
+ return /*#__PURE__*/jsx("div", {
463
+ className: classNames(['diva-widget-image-list']),
464
+ children: media.map(function (m, i) {
465
+ return /*#__PURE__*/jsx("div", {
466
+ className: classNames(['diva-widget-image-list-item']),
467
+ children: settings.description ? /*#__PURE__*/jsxs("div", {
468
+ className: classNames(['diva-widget-image-list-item-description-image']),
469
+ onClick: function onClick() {
470
+ return setSelectedProductId(m.productId);
471
+ },
472
+ children: [/*#__PURE__*/jsx(MediaItem, {
473
+ mediaUrl: m.url,
474
+ isCurrentlyVisible: true,
475
+ config: {
476
+ disableSirv: false,
477
+ sirvProps: settings.sirvProps
478
+ }
479
+ }), /*#__PURE__*/jsx("div", {
480
+ className: classNames(['diva-widget-image-list-item-description']),
481
+ children: /*#__PURE__*/jsx("span", {
482
+ children: m.description
483
+ })
484
+ })]
485
+ }) : /*#__PURE__*/jsx(MediaItem, {
486
+ mediaUrl: m.url,
487
+ isCurrentlyVisible: true,
488
+ config: {
489
+ disableSirv: false,
490
+ sirvProps: settings.sirvProps
491
+ },
492
+ className: classNames(['diva-widget-image-list-item-image']),
493
+ onClick: function onClick() {
494
+ return setSelectedProductId(m.productId);
495
+ }
496
+ })
497
+ }, i);
498
+ })
499
+ });
500
+ };
501
+
502
+ function MainComponent(props) {
503
+ var _useImageCarousel = useImageCarousel(props),
504
+ media = _useImageCarousel.media,
505
+ error = _useImageCarousel.error;
506
+ _useImageCarousel.loading;
507
+ var setSelectedProductId = _useImageCarousel.setSelectedProductId;
508
+ var _useDivaCore = useDivaCore(),
509
+ isMobile = _useDivaCore.state.isMobile;
510
+ if (error) return /*#__PURE__*/jsx("div", {
511
+ children: "Error"
512
+ });
513
+ if (isMobile && !props.settings.avoidUsingSwiperOnMobile) {
514
+ return /*#__PURE__*/jsx(ImageList, {
515
+ media: media,
516
+ settings: props.settings,
517
+ setSelectedProductId: setSelectedProductId
518
+ });
519
+ }
520
+ return /*#__PURE__*/jsx(SwiperComponent, {
521
+ media: media,
522
+ settings: props.settings,
523
+ setSelectedProductId: setSelectedProductId
524
+ });
491
525
  }
492
526
 
493
527
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { Media } from '@crystaldesign/widget-image-carousel/useImageCarousel';
3
+ import { Configuration } from '@crystaldesign/widget-image-carousel/types';
4
+ interface ImageListProps {
5
+ media: Media[];
6
+ settings: Configuration;
7
+ setSelectedProductId: (id: string) => void;
8
+ }
9
+ export declare const ImageList: React.FC<ImageListProps>;
10
+ export {};
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/ImageList/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,KAAK,EAAE,MAAM,uDAAuD,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAE3E,UAAU,cAAc;IACtB,KAAK,EAAE,KAAK,EAAE,CAAC;IACf,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAyB9C,CAAC"}
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import 'swiper/css';
3
+ import 'swiper/css/navigation';
4
+ import { Media } from '@crystaldesign/widget-image-carousel/useImageCarousel';
5
+ import { Configuration } from '@crystaldesign/widget-image-carousel/types';
6
+ interface SwiperComponentProps {
7
+ media: Media[];
8
+ settings: Configuration;
9
+ setSelectedProductId: (id: string) => void;
10
+ }
11
+ export declare const SwiperComponent: React.FC<SwiperComponentProps>;
12
+ export {};
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Swiper/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,YAAY,CAAC;AACpB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,uDAAuD,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAE3E,UAAU,oBAAoB;IAC5B,KAAK,EAAE,KAAK,EAAE,CAAC;IACf,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA2B1D,CAAC"}
@@ -1,6 +1,4 @@
1
1
  import React from 'react';
2
- import 'swiper/css';
3
- import 'swiper/css/navigation';
4
2
  import { ImageCarouselProps } from '../types';
5
3
  export default function MainComponent(props: ImageCarouselProps): React.JSX.Element;
6
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,YAAY,CAAC;AACpB,OAAO,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAM9C,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,kBAAkB,qBAwC9D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAK9C,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,kBAAkB,qBAW9D"}
@@ -10,5 +10,9 @@ export interface Configuration extends BaseConfiguration {
10
10
  description?: string;
11
11
  sliderProp?: SwiperProps;
12
12
  disableScrollToTop?: boolean;
13
+ sirvProps?: {
14
+ [data: string]: string;
15
+ };
16
+ avoidUsingSwiperOnMobile?: boolean;
13
17
  }
14
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,IAAI,EAAE,cAAc,GAAG,kBAAkB,CAAC;IAC1C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACtD,IAAI,EAAE,cAAc,GAAG,kBAAkB,CAAC;IAC1C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,CAAC,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvC,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC"}
@@ -1,5 +1,5 @@
1
1
  import { ImageCarouselProps } from './types';
2
- interface Media {
2
+ export interface Media {
3
3
  url: string;
4
4
  description?: string;
5
5
  productId: string;
@@ -10,5 +10,4 @@ export declare function useImageCarousel({ productId, settings }: ImageCarouselP
10
10
  loading: boolean;
11
11
  setSelectedProductId: (productId: string) => void;
12
12
  };
13
- export {};
14
13
  //# sourceMappingURL=useImageCarousel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useImageCarousel.d.ts","sourceRoot":"","sources":["../../../../src/useImageCarousel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM7C,UAAU,KAAK;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,kBAAkB;;;;sCAa5D,MAAM;EA6JrB"}
1
+ {"version":3,"file":"useImageCarousel.d.ts","sourceRoot":"","sources":["../../../../src/useImageCarousel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM7C,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,kBAAkB;;;;sCAa5D,MAAM;EA6JrB"}