react-notify-sdk 1.0.15 → 1.0.17

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.
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { NotifyMessage } from './types';
3
+ interface FadeWrapperProps {
4
+ visible: boolean;
5
+ message: NotifyMessage;
6
+ device: string;
7
+ }
8
+ export declare const FadeWrapper: import("goober").StyledVNode<Omit<React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement> & import("goober").DefaultTheme & FadeWrapperProps, never>>;
9
+ export default FadeWrapper;
@@ -0,0 +1,15 @@
1
+ import { styled } from "goober";
2
+ import { fadeIn, fadeOut } from './animations';
3
+ export const FadeWrapper = styled("div") `
4
+ opacity: ${(props) => (props.visible ? 1 : 0)};
5
+ animation: ${(props) => (props.visible ? fadeIn : fadeOut)} 0.3s ease forwards;
6
+ transition: opacity 0.3s ease;
7
+ position: absolute;
8
+ width: ${(props) => props.device === 'Mobile' ? '100%' : props.device === 'Tablet' ? '80%' : `${props.message?.width}%`};
9
+ top: ${(props) => props.message?.position === 'top' ? '24px' : ''};
10
+ bottom: ${(props) => props.message?.position === 'bottom' ? '24px' : ''};
11
+ left: 50%;
12
+ transform: translateX(-50%);
13
+ z-index: 5;
14
+ `;
15
+ export default FadeWrapper;
@@ -1,7 +1,6 @@
1
1
  import { NotifyMessage } from './types';
2
2
  interface NotifyMessageProps {
3
3
  message: NotifyMessage;
4
- device: string;
5
4
  }
6
- declare const NotificationMessage: ({ message, device }: NotifyMessageProps) => import("react/jsx-runtime").JSX.Element;
5
+ declare const NotificationMessage: ({ message }: NotifyMessageProps) => import("react/jsx-runtime").JSX.Element;
7
6
  export default NotificationMessage;
@@ -1,13 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- const NotificationMessage = ({ message, device }) => {
2
+ const NotificationMessage = ({ message }) => {
3
3
  return (_jsxs("div", { style: {
4
- position: 'absolute',
5
- top: message?.position === 'top' ? '24px' : undefined,
6
- bottom: message?.position === 'bottom' ? '24px' : undefined,
7
- left: '50%',
8
- transform: 'translateX(-50%)',
9
- zIndex: 20,
10
- width: device === 'Mobile' ? '100%' : device === 'Tablet' ? '80%' : `${message?.width}%`,
4
+ width: '100%',
11
5
  paddingTop: '4px', // p-4 = 1rem
12
6
  paddingBottom: '4px',
13
7
  paddingLeft: '12px',
@@ -3,38 +3,16 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useEffect, useState } from 'react';
4
4
  import { useLocation } from 'react-router-dom';
5
5
  import NotificationMessage from './NotifyMessage';
6
- import { styled } from "goober";
7
6
  import { supabase } from './supabase/supabaseClient';
8
7
  import useDeviceDetection from './UseDeviceDetection';
9
- 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
- }
31
- `;
8
+ import FadeWrapper from './FadeWrapper';
32
9
  export const NotifyProvider = ({ projectId,
33
10
  //className,
34
11
  //style,
35
12
  //disableDefaultStyles = true,
36
13
  }) => {
37
14
  const [message, setMessage] = useState(null);
15
+ const [visible, setVisible] = useState(false);
38
16
  const location = useLocation();
39
17
  const device = useDeviceDetection();
40
18
  useEffect(() => {
@@ -50,7 +28,15 @@ export const NotifyProvider = ({ projectId,
50
28
  .order('created_at', { ascending: false })
51
29
  .limit(1)
52
30
  .single();
53
- setMessage(data);
31
+ if (data) {
32
+ setMessage(data);
33
+ setVisible(true); // Fade in
34
+ }
35
+ else {
36
+ // Trigger fade out before removing message
37
+ setVisible(false);
38
+ setTimeout(() => setMessage(null), 300); // match fadeOut duration
39
+ }
54
40
  };
55
41
  fetchMessage();
56
42
  const subscription = supabase
@@ -63,6 +49,11 @@ export const NotifyProvider = ({ projectId,
63
49
  const msg = payload.new;
64
50
  if (msg.project_key === projectId && msg.route === location.pathname && msg.is_active) {
65
51
  setMessage(msg);
52
+ setVisible(true);
53
+ }
54
+ else {
55
+ setVisible(false);
56
+ setTimeout(() => setMessage(null), 300);
66
57
  }
67
58
  })
68
59
  .subscribe();
@@ -73,5 +64,5 @@ export const NotifyProvider = ({ projectId,
73
64
  if (!message)
74
65
  return null;
75
66
  //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 }) }));
67
+ return (_jsx(FadeWrapper, { visible: visible, device: device, message: message, children: _jsx(NotificationMessage, { message: message }) }));
77
68
  };
@@ -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.17",
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",