@nova-design-system/nova-react 3.13.0 → 3.14.0-beta.0
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.
- package/dist/cjs/{collapse.animation-acda1bf5-BuORVmQv.js → collapse.animation-6e0b08df-AHWzNGm_.js} +4 -1
- package/dist/cjs/{constants-d0f19e7b-s0SCO_vi.js → constants-69bafca2-DpB_ghPF.js} +9 -0
- package/dist/cjs/{fade.animation-eb454088-Bma0SpTf.js → fade.animation-9b939939-DV--bM4S.js} +2 -2
- package/dist/cjs/{index-Jgn7NELT.js → index-CJDePE8Z.js} +583 -327
- package/dist/cjs/index.js +9 -1
- package/dist/cjs/{nv-accordion-item.entry-C7vVmDCg.js → nv-accordion-item.entry-Begcz9SZ.js} +5 -4
- package/dist/cjs/{nv-accordion.entry-CFynyAOo.js → nv-accordion.entry-DQAkheHY.js} +2 -1
- package/dist/cjs/{nv-alert.entry-C_FMs0Yi.js → nv-alert.entry-CEzR0iu0.js} +12 -11
- package/dist/cjs/{nv-avatar.entry-BvjSzIHn.js → nv-avatar.entry-B-u7r30l.js} +8 -7
- package/dist/cjs/{nv-badge_2.entry-CLNvgVtj.js → nv-badge_2.entry-0vhTS5D7.js} +11 -10
- package/dist/cjs/{nv-breadcrumb.entry-Ch2Cvr_a.js → nv-breadcrumb.entry-BkWs1x-W.js} +2 -1
- package/dist/cjs/{nv-breadcrumbs.entry-DmH8AGIm.js → nv-breadcrumbs.entry-DglL-1Ed.js} +2 -1
- package/dist/cjs/{nv-button.entry-B0lusQ2w.js → nv-button.entry-BbT0aeQI.js} +8 -7
- package/dist/cjs/{nv-buttongroup.entry-DLVCcdh9.js → nv-buttongroup.entry-wlJma4qm.js} +2 -1
- package/dist/cjs/{nv-calendar.entry-BmX0f_Or.js → nv-calendar.entry-wIPDRk0B.js} +8 -7
- package/dist/cjs/{nv-col.entry-lysICYEC.js → nv-col.entry-Btsenp2c.js} +2 -1
- package/dist/cjs/{nv-datagrid.entry-vG3h5dj3.js → nv-datagrid.entry-Dae8YlRu.js} +7 -6
- package/dist/cjs/{nv-datagridcolumn.entry-9NynF9K-.js → nv-datagridcolumn.entry-D918Vo_U.js} +2 -1
- package/dist/cjs/{nv-dialog.entry-Ctsz1K-O.js → nv-dialog.entry--cGTlgDZ.js} +4 -3
- package/dist/cjs/{nv-dialogfooter_2.entry-B17HEgyc.js → nv-dialogfooter_2.entry-CXYjGHc5.js} +5 -4
- package/dist/cjs/{nv-fieldcheckbox.entry-DMiADwqV.js → nv-fieldcheckbox.entry-9b_kDQGz.js} +3 -2
- package/dist/cjs/{nv-fielddate.entry-D3X6Jl3u.js → nv-fielddate.entry-CRRTthds.js} +2 -1
- package/dist/cjs/{nv-fielddaterange.entry-C8_SFFXW.js → nv-fielddaterange.entry-BAVePsLs.js} +2 -1
- package/dist/cjs/{nv-fielddropdown.entry-BiBR8Qgs.js → nv-fielddropdown.entry-Dy8sZyze.js} +2 -1
- package/dist/cjs/{nv-fielddropdownitem.entry-DQ8QK4AS.js → nv-fielddropdownitem.entry-CuPocgsF.js} +2 -1
- package/dist/cjs/{nv-fieldmultiselect.entry-J5VTOPum.js → nv-fieldmultiselect.entry-HWSDowQH.js} +2 -1
- package/dist/cjs/{nv-fieldnumber.entry-Djpg1HMq.js → nv-fieldnumber.entry-fObgOYJX.js} +2 -1
- package/dist/cjs/{nv-fieldpassword.entry-DKT9Xn5H.js → nv-fieldpassword.entry-BRhKH_Mb.js} +2 -1
- package/dist/cjs/{nv-fieldradio.entry-CPYf3K2o.js → nv-fieldradio.entry-D74Mlgjc.js} +2 -1
- package/dist/cjs/{nv-fieldselect.entry-DnbL7aZB.js → nv-fieldselect.entry-BS81ItZs.js} +2 -1
- package/dist/cjs/{nv-fieldslider.entry-CNRJuo7v.js → nv-fieldslider.entry-xyqrZxYj.js} +2 -1
- package/dist/cjs/{nv-fieldtext.entry-B9lIHck7.js → nv-fieldtext.entry-BVUKbv4b.js} +2 -1
- package/dist/cjs/{nv-fieldtextarea.entry-B2EDj8cm.js → nv-fieldtextarea.entry-B7hb1so-.js} +2 -1
- package/dist/cjs/{nv-fieldtime.entry-CpoXpAPx.js → nv-fieldtime.entry-DvCbKaOO.js} +61 -60
- package/dist/cjs/nv-icon.entry-DP715dyH.js +80 -0
- package/dist/cjs/{nv-iconbutton_2.entry-DR_wR73O.js → nv-iconbutton_2.entry-FpzwxZe_.js} +2 -1
- package/dist/cjs/{nv-menu.entry-DB_G8hS_.js → nv-menu.entry-ryMNpTHW.js} +2 -1
- package/dist/cjs/{nv-menuitem.entry-PBCNIzPI.js → nv-menuitem.entry-SQBrWIYf.js} +2 -1
- package/dist/cjs/nv-notification.entry-DnCew-lG.js +262 -0
- package/dist/cjs/nv-notificationcontainer.entry-Dwlv9s1v.js +41 -0
- package/dist/cjs/{nv-popover.entry-ttESQMgj.js → nv-popover.entry-DOu6rhco.js} +7 -6
- package/dist/cjs/{nv-row.entry-DPEGaFeS.js → nv-row.entry-Tx_yvWTJ.js} +3 -2
- package/dist/cjs/{nv-stack.entry-CTPwlz23.js → nv-stack.entry-Cn0JrM2N.js} +3 -2
- package/dist/cjs/{nv-table.entry-Dv1mZKcu.js → nv-table.entry-D-uKGKnp.js} +4 -3
- package/dist/cjs/{nv-tablecolumn.entry-DrAaeHm-.js → nv-tablecolumn.entry-BsJzXKCk.js} +2 -1
- package/dist/cjs/{nv-toggle.entry-D2TRd371.js → nv-toggle.entry-DuDRh-Ww.js} +4 -3
- package/dist/cjs/{nv-togglebutton.entry-D95qOQ1K.js → nv-togglebutton.entry-DAlky3tO.js} +3 -2
- package/dist/cjs/{nv-togglebuttongroup.entry-BNvyZgbh.js → nv-togglebuttongroup.entry-DTadjqMQ.js} +3 -2
- package/dist/cjs/{nv-tooltip.entry-oOw6EmyL.js → nv-tooltip.entry-BWzlP6gC.js} +3 -2
- package/dist/generated/components.js +8 -0
- package/dist/generated/components.server.js +8 -1
- package/dist/index.js +1 -0
- package/dist/providers/NotificationProvider.js +83 -0
- package/dist/types/generated/components.d.ts +3 -0
- package/dist/types/generated/components.server.d.ts +3 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/providers/NotificationProvider.d.ts +36 -0
- package/package.json +4 -1
- package/dist/cjs/nv-icon.entry-DbOeEd4f.js +0 -79
- package/dist/cjs/nv-notification.entry-CyumbQS_.js +0 -178
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState, useCallback, createRef, useEffect, useRef, } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { NvNotificationcontainer, NvNotification, NvButton, } from '../generated/components';
|
|
4
|
+
const NotificationContext = createContext(null);
|
|
5
|
+
const DEFAULT_POSITION = 'top-right';
|
|
6
|
+
const DEFAULT_MAX_NOTIFICATIONS = 50;
|
|
7
|
+
const generateId = () => {
|
|
8
|
+
return `notification-${Date.now()}-${Math.random()
|
|
9
|
+
.toString(36)
|
|
10
|
+
.substr(2, 9)}`;
|
|
11
|
+
};
|
|
12
|
+
export const NotificationProvider = ({ children, position = DEFAULT_POSITION, maxNotifications = DEFAULT_MAX_NOTIFICATIONS, className, }) => {
|
|
13
|
+
const [notifications, setNotifications] = useState([]);
|
|
14
|
+
const notificationsRef = useRef([]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
notificationsRef.current = notifications;
|
|
17
|
+
}, [notifications]);
|
|
18
|
+
const show = useCallback((options) => {
|
|
19
|
+
const id = options.id || generateId();
|
|
20
|
+
const ref = createRef();
|
|
21
|
+
const notification = {
|
|
22
|
+
id,
|
|
23
|
+
heading: options.heading,
|
|
24
|
+
message: options.message,
|
|
25
|
+
dismissible: options.dismissible ?? true,
|
|
26
|
+
emphasis: options.emphasis ?? 'medium',
|
|
27
|
+
feedback: options.feedback ?? 'information',
|
|
28
|
+
icon: options.icon,
|
|
29
|
+
actions: options.actions ?? [],
|
|
30
|
+
actionSlot: options.actionSlot,
|
|
31
|
+
createdAt: Date.now(),
|
|
32
|
+
ref,
|
|
33
|
+
};
|
|
34
|
+
setNotifications((prev) => {
|
|
35
|
+
const newNotifications = [notification, ...prev];
|
|
36
|
+
if (newNotifications.length > maxNotifications) {
|
|
37
|
+
return newNotifications.slice(0, maxNotifications);
|
|
38
|
+
}
|
|
39
|
+
return newNotifications;
|
|
40
|
+
});
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
notification.ref.current?.show();
|
|
43
|
+
}, 0);
|
|
44
|
+
return id;
|
|
45
|
+
}, [maxNotifications]);
|
|
46
|
+
const dismiss = useCallback((id) => {
|
|
47
|
+
const n = notificationsRef.current.find((item) => item.id === id);
|
|
48
|
+
n?.ref.current?.dismiss();
|
|
49
|
+
}, []);
|
|
50
|
+
const remove = useCallback((id) => {
|
|
51
|
+
setNotifications((prev) => prev.filter((notification) => notification.id !== id));
|
|
52
|
+
}, []);
|
|
53
|
+
const removeAll = useCallback(() => {
|
|
54
|
+
setNotifications([]);
|
|
55
|
+
}, []);
|
|
56
|
+
const handleNotificationClose = useCallback((id) => {
|
|
57
|
+
remove(id);
|
|
58
|
+
}, [remove]);
|
|
59
|
+
const contextValue = {
|
|
60
|
+
notifications,
|
|
61
|
+
show,
|
|
62
|
+
dismiss,
|
|
63
|
+
remove,
|
|
64
|
+
removeAll,
|
|
65
|
+
};
|
|
66
|
+
return (React.createElement(NotificationContext.Provider, { value: contextValue },
|
|
67
|
+
children,
|
|
68
|
+
createPortal(React.createElement(NvNotificationcontainer, { position: position, className: className, "data-testid": "notification-container" }, notifications.map((notification) => (React.createElement(NvNotification, { key: notification.id, heading: notification.heading, message: notification.message, dismissible: notification.dismissible, emphasis: notification.emphasis, feedback: notification.feedback, icon: notification.icon, onHiddenChanged: (event) => {
|
|
69
|
+
if (event.detail) {
|
|
70
|
+
handleNotificationClose(notification.id);
|
|
71
|
+
}
|
|
72
|
+
}, initiallyHidden: true, ref: notification.ref }, (Boolean(notification.actionSlot) ||
|
|
73
|
+
Boolean(notification.actions.length)) && (React.createElement("div", { slot: "actions" },
|
|
74
|
+
notification.actions.map((action) => (React.createElement(NvButton, { key: action.label, emphasis: "low", size: "md", onClick: action.onClick }, action.label))),
|
|
75
|
+
notification.actionSlot)))))), document.body)));
|
|
76
|
+
};
|
|
77
|
+
export const useNotifications = () => {
|
|
78
|
+
const context = useContext(NotificationContext);
|
|
79
|
+
if (!context) {
|
|
80
|
+
throw new Error('useNotifications must be used within a NotificationProvider');
|
|
81
|
+
}
|
|
82
|
+
return context;
|
|
83
|
+
};
|
|
@@ -36,6 +36,7 @@ import { NvLoader as NvLoaderElement } from "@nova-design-system/nova-webcompone
|
|
|
36
36
|
import { NvMenu as NvMenuElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-menu.js";
|
|
37
37
|
import { NvMenuitem as NvMenuitemElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-menuitem.js";
|
|
38
38
|
import { NvNotification as NvNotificationElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-notification.js";
|
|
39
|
+
import { NvNotificationcontainer as NvNotificationcontainerElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-notificationcontainer.js";
|
|
39
40
|
import { NvPopover as NvPopoverElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-popover.js";
|
|
40
41
|
import { NvRow as NvRowElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-row.js";
|
|
41
42
|
import { NvStack as NvStackElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-stack.js";
|
|
@@ -210,6 +211,8 @@ export type NvNotificationEvents = {
|
|
|
210
211
|
onHiddenChanged: EventName<CustomEvent<boolean>>;
|
|
211
212
|
};
|
|
212
213
|
export declare const NvNotification: StencilReactComponent<NvNotificationElement, NvNotificationEvents>;
|
|
214
|
+
export type NvNotificationcontainerEvents = NonNullable<unknown>;
|
|
215
|
+
export declare const NvNotificationcontainer: StencilReactComponent<NvNotificationcontainerElement, NvNotificationcontainerEvents>;
|
|
213
216
|
export type NvPopoverEvents = {
|
|
214
217
|
onOpenChanged: EventName<CustomEvent<boolean>>;
|
|
215
218
|
};
|
|
@@ -36,6 +36,7 @@ import { NvLoader as NvLoaderElement } from "@nova-design-system/nova-webcompone
|
|
|
36
36
|
import { NvMenu as NvMenuElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-menu.js";
|
|
37
37
|
import { NvMenuitem as NvMenuitemElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-menuitem.js";
|
|
38
38
|
import { NvNotification as NvNotificationElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-notification.js";
|
|
39
|
+
import { NvNotificationcontainer as NvNotificationcontainerElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-notificationcontainer.js";
|
|
39
40
|
import { NvPopover as NvPopoverElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-popover.js";
|
|
40
41
|
import { NvRow as NvRowElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-row.js";
|
|
41
42
|
import { NvStack as NvStackElement } from "@nova-design-system/nova-webcomponents/dist/components/nv-stack.js";
|
|
@@ -212,6 +213,8 @@ export type NvNotificationEvents = {
|
|
|
212
213
|
onHiddenChanged: EventName<CustomEvent<boolean>>;
|
|
213
214
|
};
|
|
214
215
|
export declare const NvNotification: StencilReactComponent<NvNotificationElement, NvNotificationEvents>;
|
|
216
|
+
export type NvNotificationcontainerEvents = NonNullable<unknown>;
|
|
217
|
+
export declare const NvNotificationcontainer: StencilReactComponent<NvNotificationcontainerElement, NvNotificationcontainerEvents>;
|
|
215
218
|
export type NvPopoverEvents = {
|
|
216
219
|
onOpenChanged: EventName<CustomEvent<boolean>>;
|
|
217
220
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export * from './generated/components';
|
|
2
2
|
export * from '@nova-design-system/nova-webcomponents/constants';
|
|
3
3
|
export { defineCustomElements } from '@nova-design-system/nova-webcomponents/loader';
|
|
4
|
+
export { useNotifications, NotificationProvider, type NotificationOptions, type NotificationContextValue, type NotificationProviderProps, type Notification, } from './providers/NotificationProvider';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { type NotificationPosition, type NotificationEmphasis, FeedbackColors } from '../index';
|
|
3
|
+
export interface NotificationAction {
|
|
4
|
+
label: string;
|
|
5
|
+
onClick: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface NotificationOptions {
|
|
8
|
+
id?: string;
|
|
9
|
+
heading?: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
dismissible?: boolean;
|
|
12
|
+
emphasis?: `${NotificationEmphasis}`;
|
|
13
|
+
feedback?: `${FeedbackColors}`;
|
|
14
|
+
icon?: string;
|
|
15
|
+
actions?: NotificationAction[];
|
|
16
|
+
actionSlot?: React.ReactElement;
|
|
17
|
+
}
|
|
18
|
+
export interface Notification extends NotificationOptions {
|
|
19
|
+
createdAt: number;
|
|
20
|
+
ref: React.RefObject<HTMLNvNotificationElement>;
|
|
21
|
+
}
|
|
22
|
+
export interface NotificationContextValue {
|
|
23
|
+
notifications: Notification[];
|
|
24
|
+
show: (options: NotificationOptions) => string;
|
|
25
|
+
dismiss: (id: string) => void;
|
|
26
|
+
remove: (id: string) => void;
|
|
27
|
+
removeAll: () => void;
|
|
28
|
+
}
|
|
29
|
+
export interface NotificationProviderProps {
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
position?: `${NotificationPosition}`;
|
|
32
|
+
maxNotifications?: number;
|
|
33
|
+
className?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare const NotificationProvider: React.FC<NotificationProviderProps>;
|
|
36
|
+
export declare const useNotifications: () => NotificationContextValue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nova-design-system/nova-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0-beta.0",
|
|
4
4
|
"description": "Nova is a design system created by Elia Group to empower creators to efficiently build solutions that people love to use.",
|
|
5
5
|
"author": "Elia Group",
|
|
6
6
|
"homepage": "https://nova.eliagroup.io",
|
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "npm run build:cjs && npm run tsc",
|
|
29
29
|
"build:cjs": "rollup -c",
|
|
30
|
+
"build:watch": "npm run build:cjs:watch & npm run tsc:watch",
|
|
31
|
+
"build:cjs:watch": "rollup -c --watch",
|
|
30
32
|
"tsc": "tsc -p . --outDir ./dist --declarationDir ./dist/types --declaration true",
|
|
33
|
+
"tsc:watch": "tsc -p . --outDir ./dist --declarationDir ./dist/types --declaration true --watch",
|
|
31
34
|
"storybook": "storybook dev -p 6006",
|
|
32
35
|
"storybook.build": "storybook build -o ../../storybook-static/react",
|
|
33
36
|
"clean": "rimraf dist lib/generated",
|