Notifications Widget – React SDK

Install the Notifications Widget as an NPM package for first-class React (and TypeScript) support. Supports authenticated access via postMessage, auto-refresh, and full CSS variable theming.

Installation

npm install @legionhandtech/lht-react-widgets

React 17+ is a peer dependency. If your project already has React installed you're good to go.

Quick Start

1import { LegionNotifications } from '@legionhandtech/lht-react-widgets'; 2 3function App() { 4 return ( 5 <LegionNotifications 6 baseUrl="https://your-legion-domain.com" 7 authToken="your-jwt-token" 8 userId="user-42" 9 theme="light" 10 maxNotifications={10} 11 /> 12 ); 13}

You can also import from the dedicated sub-path:

import { LegionNotifications } from '@legionhandtech/lht-react-widgets/notifications';

Props Reference

Core Props

PropTypeDefaultDescription
baseUrlstringrequiredBase URL of your Legion deployment
authTokenstringJWT / API key for authenticated access (sent via postMessage, never in URL)
userIdstringUser ID for notification lookup
theme"light" | "dark""light"Theme preset
maxNotificationsnumber10Maximum number of notifications to display
autoRefreshbooleantrueEnable auto-refresh (every 30 seconds)
emptyTitlestring"You're all caught up"Title shown in empty state
emptySubtitlestring"No notifications right now"Subtitle shown in empty state
accentColorstring"blue" (light) / "gray" (dark)Accent color name
emptyIcon"bell" | "gift" | "activity" | "trophy""bell"Icon for empty state
widthstring"100%"Widget width (CSS value)
heightstring"400px"Widget height (CSS value)
classNamestringCSS class applied to the outer container
styleReact.CSSPropertiesInline styles merged into the container
onLoad(detail) => voidCalled when the widget iframe finishes loading
onError(message: string) => voidCalled if the widget iframe fails to load

Theming Props (selection)

All 45 theming props are optional. Here are the most commonly used ones:

PropCSS VariableExample
notifPrimaryColor--notif-primary-color"#228be6"
notifBackgroundColor--notif-background-color"#f8f9fa"
notifTextColor--notif-text-color"#333"
notifItemBg--notif-item-bg"#fff"
notifItemRadius--notif-item-radius"12px"
notifUnreadBg--notif-unread-bg"#e7f5ff"
notifBadgeBg--notif-badge-bg"#ff6b6b"
notifBadgeColor--notif-badge-color"#fff"
notifFontFamily--notif-font-family"Inter, sans-serif"
notifBorderRadius--notif-border-radius"12px"
notifButtonBg--notif-button-bg"#228be6"
notifButtonRadius--notif-button-radius"6px"

See the TypeScript NotificationsThemingProps interface for the complete list.

Imperative Ref API

1import { useRef } from 'react'; 2import { LegionNotifications, LegionNotificationsHandle } from '@legionhandtech/lht-react-widgets'; 3 4function App() { 5 const widgetRef = useRef<LegionNotificationsHandle>(null); 6 7 return ( 8 <> 9 <button onClick={() => widgetRef.current?.refresh()}> 10 Refresh Notifications 11 </button> 12 <LegionNotifications 13 ref={widgetRef} 14 baseUrl="https://your-legion-domain.com" 15 authToken="your-jwt-token" 16 /> 17 </> 18 ); 19}
MethodDescription
refresh()Reloads the widget iframe

Web Component (from NPM)

import '@legionhandtech/lht-react-widgets/notifications-web-component';
1<legion-notifications 2 base-url="https://your-legion-domain.com" 3 api-key="your-api-key" 4 user-id="user-42" 5 theme="light" 6 max-notifications="10" 7 auto-refresh="true" 8 accent-color="blue"> 9</legion-notifications>

TypeScript

1import type { 2 NotificationsWidgetProps, 3 NotificationsThemingProps, 4 LegionNotificationsHandle, 5} from '@legionhandtech/lht-react-widgets';

Callbacks

onLoad

1<LegionNotifications 2 baseUrl="https://your-legion-domain.com" 3 authToken="your-jwt-token" 4 onLoad={(detail) => { 5 console.log(detail.widget); // "notifications" 6 console.log(detail.theme); // "light" | "dark" 7 }} 8/>

onError

1<LegionNotifications 2 baseUrl="https://your-legion-domain.com" 3 onError={(message) => console.error(message)} 4/>
Documentation | Legion Hand Technologies