react-notify-sdk 1.0.15 → 1.0.16

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.
@@ -6,7 +6,7 @@ const NotificationMessage = ({ message, device }) => {
6
6
  bottom: message?.position === 'bottom' ? '24px' : undefined,
7
7
  left: '50%',
8
8
  transform: 'translateX(-50%)',
9
- zIndex: 20,
9
+ zIndex: 5,
10
10
  width: device === 'Mobile' ? '100%' : device === 'Tablet' ? '80%' : `${message?.width}%`,
11
11
  paddingTop: '4px', // p-4 = 1rem
12
12
  paddingBottom: '4px',
@@ -6,28 +6,19 @@ import NotificationMessage from './NotifyMessage';
6
6
  import { styled } from "goober";
7
7
  import { supabase } from './supabase/supabaseClient';
8
8
  import useDeviceDetection from './UseDeviceDetection';
9
+ import { fadeIn, fadeOut } from './animations';
9
10
  const FadeWrapper = styled("div") `
10
- animation: fadeIn 0.4s ease-out, fadeOut 0.4s ease-in 2.6s;
11
- @keyframes fadeIn {
12
- from {
13
- opacity: 0;
14
- transform: translateY(-0.5rem);
15
- }
16
- to {
17
- opacity: 1;
18
- transform: translateY(0);
19
- }
20
- }
21
- @keyframes fadeOut {
22
- from {
23
- opacity: 1;
24
- transform: translateY(0);
25
- }
26
- to {
27
- opacity: 0;
28
- transform: translateY(-0.5rem);
29
- }
30
- }
11
+ opacity: ${(props) => (props.visible ? 1 : 0)};
12
+ animation: ${(props) => (props.visible ? fadeIn : fadeOut)} 0.3s ease forwards;
13
+ transition: opacity 0.3s ease;
14
+ position: fixed;
15
+ bottom: 20px;
16
+ left: 20px;
17
+ background: #1f2937;
18
+ color: white;
19
+ padding: 12px 16px;
20
+ border-radius: 8px;
21
+ z-index: 1000;
31
22
  `;
32
23
  export const NotifyProvider = ({ projectId,
33
24
  //className,
@@ -35,6 +26,7 @@ export const NotifyProvider = ({ projectId,
35
26
  //disableDefaultStyles = true,
36
27
  }) => {
37
28
  const [message, setMessage] = useState(null);
29
+ const [visible, setVisible] = useState(false);
38
30
  const location = useLocation();
39
31
  const device = useDeviceDetection();
40
32
  useEffect(() => {
@@ -50,7 +42,15 @@ export const NotifyProvider = ({ projectId,
50
42
  .order('created_at', { ascending: false })
51
43
  .limit(1)
52
44
  .single();
53
- setMessage(data);
45
+ if (data) {
46
+ setMessage(data);
47
+ setVisible(true); // Fade in
48
+ }
49
+ else {
50
+ // Trigger fade out before removing message
51
+ setVisible(false);
52
+ setTimeout(() => setMessage(null), 300); // match fadeOut duration
53
+ }
54
54
  };
55
55
  fetchMessage();
56
56
  const subscription = supabase
@@ -63,6 +63,11 @@ export const NotifyProvider = ({ projectId,
63
63
  const msg = payload.new;
64
64
  if (msg.project_key === projectId && msg.route === location.pathname && msg.is_active) {
65
65
  setMessage(msg);
66
+ setVisible(true);
67
+ }
68
+ else {
69
+ setVisible(false);
70
+ setTimeout(() => setMessage(null), 300);
66
71
  }
67
72
  })
68
73
  .subscribe();
@@ -73,5 +78,5 @@ export const NotifyProvider = ({ projectId,
73
78
  if (!message)
74
79
  return null;
75
80
  //const defaultClasses = `absolute ${message?.position}-6 left-1/2 transform -translate-x-1/2 z-20 w-full md:w-[${message?.width}%] px-3 py-1 bg-[${message?.backgroundColor}] border border-[${message?.borderColor}] text-[${message?.textColor}] rounded-lg shadow`;
76
- return (_jsx(FadeWrapper, { children: _jsx(NotificationMessage, { message: message, device: device }) }));
81
+ return (_jsx(FadeWrapper, { visible: visible, children: _jsx(NotificationMessage, { message: message, device: device }) }));
77
82
  };
@@ -0,0 +1,2 @@
1
+ export declare const fadeIn: string;
2
+ export declare const fadeOut: string;
@@ -0,0 +1,10 @@
1
+ // styles/animations.ts
2
+ import { keyframes } from 'goober';
3
+ export const fadeIn = keyframes `
4
+ from { opacity: 0; transform: translateY(10px); }
5
+ to { opacity: 1; transform: translateY(0); }
6
+ `;
7
+ export const fadeOut = keyframes `
8
+ from { opacity: 1; transform: translateY(0); }
9
+ to { opacity: 0; transform: translateY(10px); }
10
+ `;
package/dist/index.js CHANGED
@@ -1 +1,4 @@
1
+ import { setup } from 'goober';
2
+ import { createElement } from 'react';
3
+ setup(createElement);
1
4
  export { NotifyProvider } from './NotifyProvider';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-notify-sdk",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "SDK for displaying real-time route-specific messages in React apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",