react-notify-sdk 1.0.14 → 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.
@@ -0,0 +1,7 @@
1
+ import { NotifyMessage } from './types';
2
+ interface NotifyMessageProps {
3
+ message: NotifyMessage;
4
+ device: string;
5
+ }
6
+ declare const NotificationMessage: ({ message, device }: NotifyMessageProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default NotificationMessage;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ const NotificationMessage = ({ message, device }) => {
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: 5,
10
+ width: device === 'Mobile' ? '100%' : device === 'Tablet' ? '80%' : `${message?.width}%`,
11
+ paddingTop: '4px', // p-4 = 1rem
12
+ paddingBottom: '4px',
13
+ paddingLeft: '12px',
14
+ paddingRight: '12px',
15
+ backgroundColor: message?.backgroundColor,
16
+ border: `1px solid ${message?.textColor}`, // Completed border style
17
+ borderRadius: "8px"
18
+ }, children: [_jsx("p", { className: `text-lg font-semibold text-[${message?.textColor}]`, style: {
19
+ fontSize: '1.125rem', // text-lg = 18px = 1.125rem
20
+ fontWeight: 600, // font-semibold = 600
21
+ color: `${message?.textColor}`,
22
+ }, children: message.title }), _jsx("p", { className: `text-sm text-[${message?.textColor}]`, style: {
23
+ marginTop: '8px',
24
+ fontSize: '0.875rem', // text-sm = 14px = 0.875rem
25
+ color: `${message?.textColor}`,
26
+ }, children: message.content })] }));
27
+ };
28
+ export default NotificationMessage;
@@ -1,2 +1,2 @@
1
1
  import { NotifyMessageProviderProps } from './types';
2
- export declare const NotifyProvider: ({ projectId, disableDefaultStyles, }: NotifyMessageProviderProps) => import("react/jsx-runtime").JSX.Element | null;
2
+ export declare const NotifyProvider: ({ projectId, }: NotifyMessageProviderProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,15 +1,32 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // src/FeatureMessage.tsx
3
3
  import { useEffect, useState } from 'react';
4
4
  import { useLocation } from 'react-router-dom';
5
- import clsx from 'clsx';
5
+ import NotificationMessage from './NotifyMessage';
6
+ import { styled } from "goober";
6
7
  import { supabase } from './supabase/supabaseClient';
7
8
  import useDeviceDetection from './UseDeviceDetection';
8
- export const NotifyProvider = ({ projectId,
9
+ import { fadeIn, fadeOut } from './animations';
10
+ const FadeWrapper = styled("div") `
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;
22
+ `;
23
+ export const NotifyProvider = ({ projectId,
9
24
  //className,
10
25
  //style,
11
- disableDefaultStyles = false, }) => {
26
+ //disableDefaultStyles = true,
27
+ }) => {
12
28
  const [message, setMessage] = useState(null);
29
+ const [visible, setVisible] = useState(false);
13
30
  const location = useLocation();
14
31
  const device = useDeviceDetection();
15
32
  useEffect(() => {
@@ -25,7 +42,15 @@ disableDefaultStyles = false, }) => {
25
42
  .order('created_at', { ascending: false })
26
43
  .limit(1)
27
44
  .single();
28
- 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
+ }
29
54
  };
30
55
  fetchMessage();
31
56
  const subscription = supabase
@@ -38,6 +63,11 @@ disableDefaultStyles = false, }) => {
38
63
  const msg = payload.new;
39
64
  if (msg.project_key === projectId && msg.route === location.pathname && msg.is_active) {
40
65
  setMessage(msg);
66
+ setVisible(true);
67
+ }
68
+ else {
69
+ setVisible(false);
70
+ setTimeout(() => setMessage(null), 300);
41
71
  }
42
72
  })
43
73
  .subscribe();
@@ -47,33 +77,6 @@ disableDefaultStyles = false, }) => {
47
77
  }, [location.pathname, projectId]);
48
78
  if (!message)
49
79
  return null;
50
- 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`;
51
- return (_jsxs("div", { className: clsx(!disableDefaultStyles && defaultClasses), style: !disableDefaultStyles ?
52
- {
53
- position: 'absolute',
54
- top: message?.position === 'top' ? '24px' : undefined,
55
- bottom: message?.position === 'bottom' ? '24px' : undefined,
56
- left: '50%',
57
- transform: 'translateX(-50%)',
58
- zIndex: 20,
59
- width: device === 'Mobile' ? '100%' : device === 'Tablet' ? '80%' : `${message?.width}%`,
60
- paddingTop: '4px', // p-4 = 1rem
61
- paddingBottom: '4px',
62
- paddingLeft: '12px',
63
- paddingRight: '12px',
64
- backgroundColor: message?.backgroundColor,
65
- border: `1px solid ${message?.textColor}`, // Completed border style
66
- borderRadius: "8px"
67
- }
68
- :
69
- {}, children: [_jsx("strong", { className: `block mb-2 text-lg font-semibold text-[${message?.textColor}]`, style: {
70
- display: 'block',
71
- marginBottom: '0.5rem', // mb-2 = 0.5rem
72
- fontSize: '1.125rem', // text-lg = 18px = 1.125rem
73
- fontWeight: 600, // font-semibold = 600
74
- color: `${message?.textColor}`,
75
- }, children: message.title }), _jsx("p", { className: `text-sm text-[${message?.textColor}]`, style: {
76
- fontSize: '0.875rem', // text-sm = 14px = 0.875rem
77
- color: `${message?.textColor}`,
78
- }, children: message.content })] }));
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`;
81
+ return (_jsx(FadeWrapper, { visible: visible, children: _jsx(NotificationMessage, { message: message, device: device }) }));
79
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.14",
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",
@@ -16,7 +16,8 @@
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
18
  "@supabase/supabase-js": "^2.50.0",
19
- "clsx": "^2.1.1"
19
+ "clsx": "^2.1.1",
20
+ "goober": "^2.1.16"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@types/react": "^19.1.8",