@gem-sdk/components 2.0.0-dev.491 → 2.0.0-dev.492

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.
@@ -67,6 +67,23 @@ const config = {
67
67
  }
68
68
  },
69
69
  advanced: {
70
+ hasBoxShadow: {
71
+ desktop: {
72
+ normal: true
73
+ }
74
+ },
75
+ boxShadow: {
76
+ desktop: {
77
+ normal: {
78
+ type: 'shadow-1',
79
+ distance: '0px',
80
+ blur: '10px',
81
+ spread: '0px',
82
+ color: 'rgba(0, 0, 0, 0.1)',
83
+ angle: 90
84
+ }
85
+ }
86
+ },
70
87
  'spacing-setting': {
71
88
  desktop: {
72
89
  margin: {
@@ -112,6 +129,23 @@ const config = {
112
129
  presetId: 'icon-list-ver1-2-image'
113
130
  },
114
131
  advanced: {
132
+ hasBoxShadow: {
133
+ desktop: {
134
+ normal: true
135
+ }
136
+ },
137
+ boxShadow: {
138
+ desktop: {
139
+ normal: {
140
+ type: 'shadow-1',
141
+ distance: '0px',
142
+ blur: '10px',
143
+ spread: '0px',
144
+ color: 'rgba(0, 0, 0, 0.1)',
145
+ angle: 90
146
+ }
147
+ }
148
+ },
115
149
  'spacing-setting': {
116
150
  desktop: {
117
151
  margin: {
@@ -13,7 +13,7 @@ var AddToCartButton = require('./components/AddToCartButton.js');
13
13
  const ProductButton = (props)=>{
14
14
  const { setting, builderProps, style, styles: styles$1, children } = props;
15
15
  const { wrapStyle, restStyle } = styles.getSplitStyle(style);
16
- const { isLoading, isInStock, outOfStockLabel, notiComponent, addToCart } = useAddToCart.useBtnAddToCart({
16
+ const { isLoading, isInStock, outOfStockLabel, notiComponent, addToCart, addToCartRef } = useAddToCart.useBtnAddToCart({
17
17
  setting,
18
18
  styles: styles$1,
19
19
  builderProps
@@ -37,6 +37,7 @@ const ProductButton = (props)=>{
37
37
  };
38
38
  return /*#__PURE__*/ jsxRuntime.jsxs("div", {
39
39
  style: wrapStyle,
40
+ ref: addToCartRef,
40
41
  children: [
41
42
  system.If(isInStock, renderAddToCartButton(), renderSoldOutButton()),
42
43
  notiComponent
@@ -8,6 +8,7 @@ var useCartMessage = require('./useCartMessage.js');
8
8
  var useCartOperations = require('./useCartOperations.js');
9
9
 
10
10
  const useBtnAddToCart = ({ styles, setting, builderProps })=>{
11
+ const addToCartRef = React.useRef(null);
11
12
  const mode = core.useEditorMode();
12
13
  const product = core.useProduct();
13
14
  const { currency } = core.useCurrency();
@@ -15,6 +16,7 @@ const useBtnAddToCart = ({ styles, setting, builderProps })=>{
15
16
  const properties = core.useProductProperties();
16
17
  const currentVariant = core.useCurrentVariant();
17
18
  const { hasPreSelected } = core.useHasPreSelected();
19
+ const setStickyVisible = core.useStickyStore((s)=>s.setStickyVisible);
18
20
  const updateProductSubmit = core.useProductStore((s)=>s.updateIsSubmit);
19
21
  const dispatchEventAddToCart = useDispatchAfterSubmitEvent.useDispatchAfterSubmitEvent(builderProps?.uid);
20
22
  const { showMessage, notiComponent } = useCartMessage.useCartMessage(styles, setting);
@@ -27,6 +29,24 @@ const useBtnAddToCart = ({ styles, setting, builderProps })=>{
27
29
  onSuccess: handleSuccess,
28
30
  onError: handleError
29
31
  });
32
+ React.useEffect(()=>{
33
+ const observer = new IntersectionObserver((entries)=>{
34
+ const entry = entries[0];
35
+ setStickyVisible(entry?.isIntersecting);
36
+ }, {
37
+ threshold: 0.1
38
+ });
39
+ if (addToCartRef.current) {
40
+ observer.observe(addToCartRef.current);
41
+ }
42
+ return ()=>{
43
+ if (addToCartRef.current) {
44
+ observer.unobserve(addToCartRef.current);
45
+ }
46
+ };
47
+ }, [
48
+ setStickyVisible
49
+ ]);
30
50
  const addToCart = React.useCallback(()=>{
31
51
  if (!currentVariant?.baseID || !quantity || !product?.baseID || hasPreSelected !== undefined && !hasPreSelected || mode === 'edit') return;
32
52
  const checkInvalid = properties?.some((item)=>item.required && !item.value);
@@ -88,6 +108,7 @@ const useBtnAddToCart = ({ styles, setting, builderProps })=>{
88
108
  const isLoading = createCartLoading || addToCartLoading;
89
109
  const outOfStockLabel = !currentVariant ? 'Unavailable' : setting?.outOfStockLabel;
90
110
  return {
111
+ addToCartRef,
91
112
  isLoading,
92
113
  isInStock,
93
114
  notiComponent,
@@ -16,13 +16,14 @@ var classes = require('./common/classes.js');
16
16
 
17
17
  const Sticky = ({ children, builderAttrs, setting, style, builderProps, advanced })=>{
18
18
  const { background, preloadBgImage, width, isScrollToTop } = setting ?? {};
19
- const { positionStyle, displayStyle } = useSticky.default(setting);
19
+ const { positionStyle, displayStyle, makeDisplaySettingStyles } = useSticky.default(setting);
20
20
  const computedContainerStyles = system.createStyle({
21
21
  margin: '0 auto',
22
22
  ...displayStyle,
23
23
  ...styles.getStylePadding(style),
24
24
  ...positionStyle,
25
- zIndex: _const.ELEMENT_Z_INDEX.STICKY
25
+ zIndex: _const.ELEMENT_Z_INDEX.STICKY,
26
+ ...makeDisplaySettingStyles
26
27
  });
27
28
  const computedContentStyles = system.createStyle(styles.getContentStyles({
28
29
  width,
@@ -7,6 +7,7 @@ var React = require('react');
7
7
 
8
8
  const useSticky = (setting)=>{
9
9
  const { width, position } = setting ?? {};
10
+ const isStickyVisible = core.useStickyStore((s)=>s.isStickyVisible);
10
11
  const w = core.makeStyleResponsive('w', width);
11
12
  const sidebarMode = core.usePageStore((s)=>s.sidebarMode === 'interaction');
12
13
  const currentDevice = core.useCurrentDevice();
@@ -37,6 +38,19 @@ const useSticky = (setting)=>{
37
38
  sidebarMode,
38
39
  position
39
40
  ]);
41
+ const makeDisplaySettingStyles = React.useMemo(()=>{
42
+ return {
43
+ '--d': setting?.display?.desktop === 'after-first-cart-button' && !isStickyVisible ? 'none' : 'block',
44
+ '--d-tablet': setting?.display?.tablet === 'after-first-cart-button' && !isStickyVisible ? 'none' : 'block',
45
+ '--d-mobile': setting?.display?.mobile === 'after-first-cart-button' && !isStickyVisible ? 'none' : 'block'
46
+ };
47
+ }, [
48
+ isStickyVisible,
49
+ setting?.display?.desktop,
50
+ setting?.display?.mobile,
51
+ setting?.display?.tablet
52
+ ]);
53
+ console.log('makeDisplaySettingStyles', makeDisplaySettingStyles);
40
54
  const displayStyle = React.useMemo(()=>{
41
55
  return {
42
56
  [`--top`]: gap ?? 'auto',
@@ -63,7 +77,8 @@ const useSticky = (setting)=>{
63
77
  w,
64
78
  displayStyle,
65
79
  positionStyle,
66
- getCSSAlign
80
+ getCSSAlign,
81
+ makeDisplaySettingStyles
67
82
  };
68
83
  };
69
84
 
@@ -63,6 +63,23 @@ const config = {
63
63
  }
64
64
  },
65
65
  advanced: {
66
+ hasBoxShadow: {
67
+ desktop: {
68
+ normal: true
69
+ }
70
+ },
71
+ boxShadow: {
72
+ desktop: {
73
+ normal: {
74
+ type: 'shadow-1',
75
+ distance: '0px',
76
+ blur: '10px',
77
+ spread: '0px',
78
+ color: 'rgba(0, 0, 0, 0.1)',
79
+ angle: 90
80
+ }
81
+ }
82
+ },
66
83
  'spacing-setting': {
67
84
  desktop: {
68
85
  margin: {
@@ -108,6 +125,23 @@ const config = {
108
125
  presetId: 'icon-list-ver1-2-image'
109
126
  },
110
127
  advanced: {
128
+ hasBoxShadow: {
129
+ desktop: {
130
+ normal: true
131
+ }
132
+ },
133
+ boxShadow: {
134
+ desktop: {
135
+ normal: {
136
+ type: 'shadow-1',
137
+ distance: '0px',
138
+ blur: '10px',
139
+ spread: '0px',
140
+ color: 'rgba(0, 0, 0, 0.1)',
141
+ angle: 90
142
+ }
143
+ }
144
+ },
111
145
  'spacing-setting': {
112
146
  desktop: {
113
147
  margin: {
@@ -9,7 +9,7 @@ import AddToCartButton from './components/AddToCartButton.js';
9
9
  const ProductButton = (props)=>{
10
10
  const { setting, builderProps, style, styles, children } = props;
11
11
  const { wrapStyle, restStyle } = getSplitStyle(style);
12
- const { isLoading, isInStock, outOfStockLabel, notiComponent, addToCart } = useBtnAddToCart({
12
+ const { isLoading, isInStock, outOfStockLabel, notiComponent, addToCart, addToCartRef } = useBtnAddToCart({
13
13
  setting,
14
14
  styles,
15
15
  builderProps
@@ -33,6 +33,7 @@ const ProductButton = (props)=>{
33
33
  };
34
34
  return /*#__PURE__*/ jsxs("div", {
35
35
  style: wrapStyle,
36
+ ref: addToCartRef,
36
37
  children: [
37
38
  If(isInStock, renderAddToCartButton(), renderSoldOutButton()),
38
39
  notiComponent
@@ -1,11 +1,12 @@
1
- import { useEditorMode, useProduct, useCurrency, useQuantity, useProductProperties, useCurrentVariant, useHasPreSelected, useProductStore, useCreateCart, useAddToCart, useCurrentVariantInStock } from '@gem-sdk/core';
2
- import { useCallback } from 'react';
1
+ import { useEditorMode, useProduct, useCurrency, useQuantity, useProductProperties, useCurrentVariant, useHasPreSelected, useStickyStore, useProductStore, useCreateCart, useAddToCart, useCurrentVariantInStock } from '@gem-sdk/core';
2
+ import { useRef, useEffect, useCallback } from 'react';
3
3
  import { addToCartTracking } from '../../../helpers/tracking.js';
4
4
  import { useDispatchAfterSubmitEvent } from './useDispatchAfterSubmitEvent.js';
5
5
  import { useCartMessage } from './useCartMessage.js';
6
6
  import { useCartOperations } from './useCartOperations.js';
7
7
 
8
8
  const useBtnAddToCart = ({ styles, setting, builderProps })=>{
9
+ const addToCartRef = useRef(null);
9
10
  const mode = useEditorMode();
10
11
  const product = useProduct();
11
12
  const { currency } = useCurrency();
@@ -13,6 +14,7 @@ const useBtnAddToCart = ({ styles, setting, builderProps })=>{
13
14
  const properties = useProductProperties();
14
15
  const currentVariant = useCurrentVariant();
15
16
  const { hasPreSelected } = useHasPreSelected();
17
+ const setStickyVisible = useStickyStore((s)=>s.setStickyVisible);
16
18
  const updateProductSubmit = useProductStore((s)=>s.updateIsSubmit);
17
19
  const dispatchEventAddToCart = useDispatchAfterSubmitEvent(builderProps?.uid);
18
20
  const { showMessage, notiComponent } = useCartMessage(styles, setting);
@@ -25,6 +27,24 @@ const useBtnAddToCart = ({ styles, setting, builderProps })=>{
25
27
  onSuccess: handleSuccess,
26
28
  onError: handleError
27
29
  });
30
+ useEffect(()=>{
31
+ const observer = new IntersectionObserver((entries)=>{
32
+ const entry = entries[0];
33
+ setStickyVisible(entry?.isIntersecting);
34
+ }, {
35
+ threshold: 0.1
36
+ });
37
+ if (addToCartRef.current) {
38
+ observer.observe(addToCartRef.current);
39
+ }
40
+ return ()=>{
41
+ if (addToCartRef.current) {
42
+ observer.unobserve(addToCartRef.current);
43
+ }
44
+ };
45
+ }, [
46
+ setStickyVisible
47
+ ]);
28
48
  const addToCart = useCallback(()=>{
29
49
  if (!currentVariant?.baseID || !quantity || !product?.baseID || hasPreSelected !== undefined && !hasPreSelected || mode === 'edit') return;
30
50
  const checkInvalid = properties?.some((item)=>item.required && !item.value);
@@ -86,6 +106,7 @@ const useBtnAddToCart = ({ styles, setting, builderProps })=>{
86
106
  const isLoading = createCartLoading || addToCartLoading;
87
107
  const outOfStockLabel = !currentVariant ? 'Unavailable' : setting?.outOfStockLabel;
88
108
  return {
109
+ addToCartRef,
89
110
  isLoading,
90
111
  isInStock,
91
112
  notiComponent,
@@ -12,13 +12,14 @@ import { getContainerClasses } from './common/classes.js';
12
12
 
13
13
  const Sticky = ({ children, builderAttrs, setting, style, builderProps, advanced })=>{
14
14
  const { background, preloadBgImage, width, isScrollToTop } = setting ?? {};
15
- const { positionStyle, displayStyle } = useSticky(setting);
15
+ const { positionStyle, displayStyle, makeDisplaySettingStyles } = useSticky(setting);
16
16
  const computedContainerStyles = createStyle({
17
17
  margin: '0 auto',
18
18
  ...displayStyle,
19
19
  ...getStylePadding(style),
20
20
  ...positionStyle,
21
- zIndex: ELEMENT_Z_INDEX.STICKY
21
+ zIndex: ELEMENT_Z_INDEX.STICKY,
22
+ ...makeDisplaySettingStyles
22
23
  });
23
24
  const computedContentStyles = createStyle(getContentStyles({
24
25
  width,
@@ -1,8 +1,9 @@
1
- import { makeStyleResponsive, usePageStore, useCurrentDevice } from '@gem-sdk/core';
1
+ import { useStickyStore, makeStyleResponsive, usePageStore, useCurrentDevice } from '@gem-sdk/core';
2
2
  import { useMemo } from 'react';
3
3
 
4
4
  const useSticky = (setting)=>{
5
5
  const { width, position } = setting ?? {};
6
+ const isStickyVisible = useStickyStore((s)=>s.isStickyVisible);
6
7
  const w = makeStyleResponsive('w', width);
7
8
  const sidebarMode = usePageStore((s)=>s.sidebarMode === 'interaction');
8
9
  const currentDevice = useCurrentDevice();
@@ -33,6 +34,19 @@ const useSticky = (setting)=>{
33
34
  sidebarMode,
34
35
  position
35
36
  ]);
37
+ const makeDisplaySettingStyles = useMemo(()=>{
38
+ return {
39
+ '--d': setting?.display?.desktop === 'after-first-cart-button' && !isStickyVisible ? 'none' : 'block',
40
+ '--d-tablet': setting?.display?.tablet === 'after-first-cart-button' && !isStickyVisible ? 'none' : 'block',
41
+ '--d-mobile': setting?.display?.mobile === 'after-first-cart-button' && !isStickyVisible ? 'none' : 'block'
42
+ };
43
+ }, [
44
+ isStickyVisible,
45
+ setting?.display?.desktop,
46
+ setting?.display?.mobile,
47
+ setting?.display?.tablet
48
+ ]);
49
+ console.log('makeDisplaySettingStyles', makeDisplaySettingStyles);
36
50
  const displayStyle = useMemo(()=>{
37
51
  return {
38
52
  [`--top`]: gap ?? 'auto',
@@ -59,7 +73,8 @@ const useSticky = (setting)=>{
59
73
  w,
60
74
  displayStyle,
61
75
  positionStyle,
62
- getCSSAlign
76
+ getCSSAlign,
77
+ makeDisplaySettingStyles
63
78
  };
64
79
  };
65
80
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/components",
3
- "version": "2.0.0-dev.491",
3
+ "version": "2.0.0-dev.492",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",