@nova-design-system/nova-react 3.14.0 → 3.15.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.
Files changed (60) hide show
  1. package/dist/cjs/{collapse.animation-acda1bf5-BuORVmQv.js → collapse.animation-6e0b08df-AHWzNGm_.js} +4 -1
  2. package/dist/cjs/{constants-d0f19e7b-s0SCO_vi.js → constants-69bafca2-DpB_ghPF.js} +9 -0
  3. package/dist/cjs/{fade.animation-eb454088-Bma0SpTf.js → fade.animation-9b939939-DV--bM4S.js} +2 -2
  4. package/dist/cjs/{index-CKAZvszR.js → index-BK1_MpRZ.js} +583 -327
  5. package/dist/cjs/index.js +9 -1
  6. package/dist/cjs/{nv-accordion-item.entry-CjBcmF8t.js → nv-accordion-item.entry-BPaDkIFa.js} +5 -4
  7. package/dist/cjs/{nv-accordion.entry-CRk2Wvt3.js → nv-accordion.entry-BaHER2iL.js} +2 -1
  8. package/dist/cjs/{nv-alert.entry-D5qB5xZg.js → nv-alert.entry-Hv-y3Bwl.js} +12 -11
  9. package/dist/cjs/{nv-avatar.entry-CuNYdZl_.js → nv-avatar.entry-BTmGyeGF.js} +8 -7
  10. package/dist/cjs/{nv-badge_2.entry-BDuX1qOQ.js → nv-badge_2.entry-CwlWa72m.js} +11 -10
  11. package/dist/cjs/{nv-breadcrumb.entry-BE9U6AF_.js → nv-breadcrumb.entry-BvHgDgxV.js} +2 -1
  12. package/dist/cjs/{nv-breadcrumbs.entry-DJXqtmMR.js → nv-breadcrumbs.entry-BdptRKYA.js} +2 -1
  13. package/dist/cjs/{nv-button.entry-CF5IDcG3.js → nv-button.entry-6O39hBHY.js} +8 -7
  14. package/dist/cjs/{nv-buttongroup.entry-C0Zc2lOi.js → nv-buttongroup.entry-Bh0f3bAn.js} +2 -1
  15. package/dist/cjs/{nv-calendar.entry-NbVLStMN.js → nv-calendar.entry-BZLITXEC.js} +8 -7
  16. package/dist/cjs/{nv-col.entry-ahFf8a1Z.js → nv-col.entry-I3bCSLB5.js} +2 -1
  17. package/dist/cjs/{nv-datagrid.entry-C-MJXEdi.js → nv-datagrid.entry-BzIkgOV6.js} +7 -6
  18. package/dist/cjs/{nv-datagridcolumn.entry-CxU7soW7.js → nv-datagridcolumn.entry-BuFhEECG.js} +2 -1
  19. package/dist/cjs/{nv-dialog.entry-WlnaC-w2.js → nv-dialog.entry-DIbIIXo2.js} +4 -3
  20. package/dist/cjs/{nv-dialogfooter_2.entry-CEWmTnJc.js → nv-dialogfooter_2.entry-Thzk1kVd.js} +5 -4
  21. package/dist/cjs/{nv-fieldcheckbox.entry-BYhFVrYb.js → nv-fieldcheckbox.entry-mkas423y.js} +3 -2
  22. package/dist/cjs/{nv-fielddate.entry-DVVnRiOT.js → nv-fielddate.entry-Cek70TQM.js} +2 -1
  23. package/dist/cjs/{nv-fielddaterange.entry-Cb4X5Q-C.js → nv-fielddaterange.entry-C3BYAnVq.js} +2 -1
  24. package/dist/cjs/{nv-fielddropdown.entry-D2PKGkpx.js → nv-fielddropdown.entry-Djz5-R1T.js} +2 -1
  25. package/dist/cjs/{nv-fielddropdownitem.entry-BqgMRnIc.js → nv-fielddropdownitem.entry-B2z13jEI.js} +2 -1
  26. package/dist/cjs/{nv-fieldmultiselect.entry-Dzw4c9wO.js → nv-fieldmultiselect.entry-uJ9i2gtz.js} +2 -1
  27. package/dist/cjs/{nv-fieldnumber.entry-Cm5g6tw7.js → nv-fieldnumber.entry-zpWCDG_-.js} +2 -1
  28. package/dist/cjs/{nv-fieldpassword.entry-BMI5M4RR.js → nv-fieldpassword.entry-C835HE_i.js} +2 -1
  29. package/dist/cjs/{nv-fieldradio.entry-BrCJvkMR.js → nv-fieldradio.entry-CzLMbo4W.js} +2 -1
  30. package/dist/cjs/{nv-fieldselect.entry-Cz76Y4Fb.js → nv-fieldselect.entry-BzcYzmqe.js} +2 -1
  31. package/dist/cjs/{nv-fieldslider.entry-C2ynnMK8.js → nv-fieldslider.entry-B5vyrQZw.js} +2 -1
  32. package/dist/cjs/{nv-fieldtext.entry-B6ciu2fU.js → nv-fieldtext.entry-DnPQxVqp.js} +2 -1
  33. package/dist/cjs/{nv-fieldtextarea.entry-BL_gMvTp.js → nv-fieldtextarea.entry-n2MJK2Jg.js} +2 -1
  34. package/dist/cjs/{nv-fieldtime.entry-Be5fujXA.js → nv-fieldtime.entry-DChhvqKi.js} +61 -60
  35. package/dist/cjs/nv-icon.entry-agdqxUMS.js +80 -0
  36. package/dist/cjs/{nv-iconbutton_2.entry-Dlk96yHi.js → nv-iconbutton_2.entry-u0l16LeW.js} +2 -1
  37. package/dist/cjs/{nv-menu.entry-CDn1Tk9J.js → nv-menu.entry-OYVh6iMu.js} +2 -1
  38. package/dist/cjs/{nv-menuitem.entry-DIkQnha9.js → nv-menuitem.entry-Dj6N1n9X.js} +2 -1
  39. package/dist/cjs/nv-notification.entry-D1dVSEYZ.js +262 -0
  40. package/dist/cjs/nv-notificationcontainer.entry-Bp2NR_fe.js +41 -0
  41. package/dist/cjs/{nv-popover.entry-Bz9ZWGlN.js → nv-popover.entry-Bf2AEn9B.js} +7 -6
  42. package/dist/cjs/{nv-row.entry-iJGXINmZ.js → nv-row.entry-Bi9eoQEh.js} +3 -2
  43. package/dist/cjs/{nv-stack.entry-CifEjR2g.js → nv-stack.entry-Dd680LIT.js} +3 -2
  44. package/dist/cjs/{nv-table.entry-Dxg0j3fe.js → nv-table.entry-wxn9GDDo.js} +4 -3
  45. package/dist/cjs/{nv-tablecolumn.entry--29MFEe9.js → nv-tablecolumn.entry-Bo0z0XyB.js} +2 -1
  46. package/dist/cjs/{nv-toggle.entry-D0eQoEqf.js → nv-toggle.entry-gBokGnGe.js} +4 -3
  47. package/dist/cjs/{nv-togglebutton.entry-X4eLeP-C.js → nv-togglebutton.entry-ZpltTrQe.js} +3 -2
  48. package/dist/cjs/{nv-togglebuttongroup.entry-BYO58vql.js → nv-togglebuttongroup.entry-Bu0C6Iq3.js} +3 -2
  49. package/dist/cjs/{nv-tooltip.entry-DaxjQSt1.js → nv-tooltip.entry-DR4aj5qF.js} +3 -2
  50. package/dist/generated/components.js +8 -0
  51. package/dist/generated/components.server.js +8 -1
  52. package/dist/index.js +1 -0
  53. package/dist/providers/NotificationProvider.js +83 -0
  54. package/dist/types/generated/components.d.ts +3 -0
  55. package/dist/types/generated/components.server.d.ts +3 -0
  56. package/dist/types/index.d.ts +1 -0
  57. package/dist/types/providers/NotificationProvider.d.ts +36 -0
  58. package/package.json +4 -1
  59. package/dist/cjs/nv-icon.entry-C-wbfOy3.js +0 -79
  60. package/dist/cjs/nv-notification.entry-BiwnZCkF.js +0 -178
package/dist/index.js 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, } from './providers/NotificationProvider';
@@ -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
  };
@@ -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.14.0",
3
+ "version": "3.15.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",