@transferwise/components 0.0.0-experimental-131de44 → 0.0.0-experimental-18e9dad

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.
@@ -1,3 +1,3 @@
1
1
  import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import{Illustration}from"@wise/art";import{useTheme}from"@wise/components-theming";import classNames from"classnames";import{useEffect,useState}from"react";import Body from"../body";import{Typography}from"../common";import{CloseButton}from"../common/closeButton";import Link from"../link";// WARNING: Changing this will cause nudges to reappear wherever persist nudge is used and privacy team will need to be updated too
2
2
  import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";export var STORAGE_NAME="dismissedNudges";export var Media={GLOBE:"globe",LOCK:"lock",WALLET:"wallet",GEAR:"gear","INVITE-LETTER":"invite-letter","PERSONAL-CARD":"personal-card","BUSINESS-CARD":"business-card"};var getLocalStorage=function(){try{var a=localStorage.getItem(STORAGE_NAME);if(a){var b=JSON.parse(a);if(Array.isArray(b))return b}// eslint-disable-next-line unicorn/prefer-optional-catch-binding, no-empty
3
- }catch(a){}return[]},Nudge=function(a){var b=a.media,c=a.mediaName,d=a.title,e=a.link,f=a.href,g=a.onClick,h=a.onDismiss,i=a.persistDismissal,j=a.id,k=a.className,l=useTheme(),m=l.isModern,n=useState(!1),o=_slicedToArray(n,2),p=o[0],q=o[1],r=useState(!1),s=_slicedToArray(r,2),t=s[0],u=s[1];return useEffect(function(){if(i&&j){var a=getLocalStorage();a&&a.find(function(a){return a===j})&&q(!0)}u(!0)},[j,i]),i&&(p||!t)?null:/*#__PURE__*/_jsxs("div",{className:classNames("wds-nudge",k),id:j,children:[m?!!c&&/*#__PURE__*/_jsx("div",{className:"wds-nudge-media",children:/*#__PURE__*/_jsx(Illustration,{name:c,className:classNames("wds-nudge-media-".concat(c)),size:"small",disablePadding:!0,alt:""})}):/*#__PURE__*/_jsx("div",{className:"wds-nudge-media",children:b}),/*#__PURE__*/_jsxs("div",{className:"wds-nudge-container",children:[/*#__PURE__*/_jsxs("div",{className:"wds-nudge-content",children:[m?/*#__PURE__*/_jsx(Body,{type:Typography.BODY_LARGE,className:classNames("wds-nudge-body"),children:d}):/*#__PURE__*/_jsx("div",{className:"wds-nudge-title",children:d}),e&&/*#__PURE__*/_jsx(Link,{href:f,type:Typography.LINK_LARGE,className:"wds-nudge-link",onClick:g,children:e})]}),h||i?/*#__PURE__*/_jsx(CloseButton,{className:"wds-nudge-control",size:"sm",onClick:function handleOnDismiss(){var a=getLocalStorage();if(i&&j){try{localStorage.setItem(STORAGE_NAME,JSON.stringify([].concat(_toConsumableArray(a?a:[]),[j])))}catch(a){}q(!0)}h&&h()}}):null]})]})};export default Nudge;
3
+ }catch(a){}return[]},Nudge=function(a){var b=a.media,c=a.mediaName,d=a.title,e=a.link,f=a.href,g=a.onClick,h=a.onDismiss,i=a.persistDismissal,j=a.onIsPreviouslyDismissed,k=a.id,l=a.className,m=useTheme(),n=m.isModern,o=useState(!1),p=_slicedToArray(o,2),q=p[0],r=p[1],s=useState(!1),t=_slicedToArray(s,2),u=t[0],v=t[1];return useEffect(function(){if(i&&k){var a=getLocalStorage(),b=!1;a&&a.find(function(a){return a===k})&&(r(!0),b=!0),j&&j(b)}v(!0)},[k,i]),i&&(q||!u)?null:/*#__PURE__*/_jsxs("div",{className:classNames("wds-nudge",l),id:k,children:[n?!!c&&/*#__PURE__*/_jsx("div",{className:"wds-nudge-media",children:/*#__PURE__*/_jsx(Illustration,{name:c,className:classNames("wds-nudge-media-".concat(c)),size:"small",disablePadding:!0,alt:""})}):/*#__PURE__*/_jsx("div",{className:"wds-nudge-media",children:b}),/*#__PURE__*/_jsxs("div",{className:"wds-nudge-container",children:[/*#__PURE__*/_jsxs("div",{className:"wds-nudge-content",children:[n?/*#__PURE__*/_jsx(Body,{type:Typography.BODY_LARGE,className:classNames("wds-nudge-body"),children:d}):/*#__PURE__*/_jsx("div",{className:"wds-nudge-title",children:d}),e&&/*#__PURE__*/_jsx(Link,{href:f,type:Typography.LINK_LARGE,className:"wds-nudge-link",onClick:g,children:e})]}),h||i?/*#__PURE__*/_jsx(CloseButton,{className:"wds-nudge-control",size:"sm",onClick:function handleOnDismiss(){var a=getLocalStorage();if(i&&k){try{localStorage.setItem(STORAGE_NAME,JSON.stringify([].concat(_toConsumableArray(a?a:[]),[k])))}catch(a){}r(!0)}h&&h()}}):null]})]})};export default Nudge;
@@ -1 +1 @@
1
- import _defineProperty from"@babel/runtime/helpers/defineProperty";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import{render,fireEvent,cleanup,screen}from"../test-utils";import Nudge from".";import{jsx as _jsx}from"react/jsx-runtime";describe("Nudge",function(){var a={media:/*#__PURE__*/_jsx("span",{role:"img","aria-label":"Party popper emoji",children:"\uD83C\uDF89"}),title:"A nudge title",link:"CTA",href:"#",onClick:jest.fn(),onDismiss:jest.fn()};afterEach(cleanup),it("renders a media element",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByRole("img");expect(b).toBeInTheDocument()}),it("renders a title",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("A nudge title");expect(b).toBeInTheDocument()}),it("renders a link to the passed href",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("CTA");expect(b).toBeInTheDocument(),expect(b).toHaveAttribute("href",a.href)}),it("calls onClick prop when the link is clicked",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("CTA");fireEvent.click(b),expect(a.onClick).toHaveBeenCalledTimes(1)}),it("calls onDismiss prop when close button is clicked",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByLabelText("Close");fireEvent.click(b),expect(a.onDismiss).toHaveBeenCalledTimes(1)}),it("adds the passed id to the parent container",function(){var b;render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"nudge-id"})));var c=null===(b=screen.getByRole("img").parentElement)||void 0===b?void 0:b.parentElement;expect(null===c||void 0===c?void 0:c.id).toBe("nudge-id")}),it("adds the passed className to the parent container's className",function(){var b;render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{className:"happy-nudge"})));var c=null===(b=screen.getByRole("img").parentElement)||void 0===b?void 0:b.parentElement;expect(c).toHaveClass("happy-nudge")}),describe("Nudge persistance",function(){beforeEach(function(){jest.resetAllMocks()}),it("does NOT render a nudge if localStorage has been set with the id of the nudge",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"CAKE\",\"TEST\"]"),render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.queryByText("A nudge title")).not.toBeInTheDocument()}),it("shows a nudge if localStorage has been set with a different id for a different nudge",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"BANANA\"]"),render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.getByText("A nudge title")).toBeInTheDocument()}),it("calls local storage with updated dismissed nudges value",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"BANANA\"]");var b=jest.spyOn(window.localStorage.__proto__,"setItem");render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.getByText("A nudge title")).toBeInTheDocument();var c=screen.getByLabelText("Close");fireEvent.click(c),expect(a.onDismiss).toHaveBeenCalledTimes(1),expect(b).toHaveBeenCalledWith("dismissedNudges","[\"BANANA\",\"TEST\"]")})})});
1
+ import _defineProperty from"@babel/runtime/helpers/defineProperty";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import{render,fireEvent,cleanup,screen}from"../test-utils";import Nudge from".";import{jsx as _jsx}from"react/jsx-runtime";describe("Nudge",function(){var a={media:/*#__PURE__*/_jsx("span",{role:"img","aria-label":"Party popper emoji",children:"\uD83C\uDF89"}),title:"A nudge title",link:"CTA",href:"#",onClick:jest.fn(),onDismiss:jest.fn()};afterEach(cleanup),it("renders a media element",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByRole("img");expect(b).toBeInTheDocument()}),it("renders a title",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("A nudge title");expect(b).toBeInTheDocument()}),it("renders a link to the passed href",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("CTA");expect(b).toBeInTheDocument(),expect(b).toHaveAttribute("href",a.href)}),it("calls onClick prop when the link is clicked",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("CTA");fireEvent.click(b),expect(a.onClick).toHaveBeenCalledTimes(1)}),it("calls onDismiss prop when close button is clicked",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByLabelText("Close");fireEvent.click(b),expect(a.onDismiss).toHaveBeenCalledTimes(1)}),it("adds the passed id to the parent container",function(){var b;render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"nudge-id"})));var c=null===(b=screen.getByRole("img").parentElement)||void 0===b?void 0:b.parentElement;expect(null===c||void 0===c?void 0:c.id).toBe("nudge-id")}),it("adds the passed className to the parent container's className",function(){var b;render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{className:"happy-nudge"})));var c=null===(b=screen.getByRole("img").parentElement)||void 0===b?void 0:b.parentElement;expect(c).toHaveClass("happy-nudge")}),describe("Nudge persistance",function(){beforeEach(function(){jest.resetAllMocks()}),it("does NOT render a nudge if localStorage has been set with the id of the nudge",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"CAKE\",\"TEST\"]"),render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.queryByText("A nudge title")).not.toBeInTheDocument()}),it("does NOT render a nudge if localStorage has been set with the id of the nudge AND calls is previously dismissed with TRUE",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"CAKE\",\"TEST\"]");var b=jest.fn();render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0,onIsPreviouslyDismissed:b}))),expect(screen.queryByText("A nudge title")).not.toBeInTheDocument(),expect(b).toHaveBeenCalledWith(!0)}),it("shows a nudge if localStorage has been set with a different id for a different nudge and calls is previously dismissed with FALSE",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"BANANA\"]");var b=jest.fn();render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0,onIsPreviouslyDismissed:b}))),expect(screen.getByText("A nudge title")).toBeInTheDocument(),expect(b).toHaveBeenCalledWith(!1)}),it("calls local storage with updated dismissed nudges value",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"BANANA\"]");var b=jest.spyOn(window.localStorage.__proto__,"setItem");render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.getByText("A nudge title")).toBeInTheDocument();var c=screen.getByLabelText("Close");fireEvent.click(c),expect(a.onDismiss).toHaveBeenCalledTimes(1),expect(b).toHaveBeenCalledWith("dismissedNudges","[\"BANANA\",\"TEST\"]")})})});
@@ -1 +1 @@
1
- import{action}from"@storybook/addon-actions";import{Nudge}from"..";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";export default{component:Nudge,title:"Feedback/Nudge"};export var Default=function(){return/*#__PURE__*/_jsxs("div",{className:"d-flex flex-column",children:[/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"lock",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"wallet",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"gear",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"invite-letter",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"personal-card",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"business-card",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")})]})};export var DefaultWithPersist=function(){return/*#__PURE__*/_jsxs("div",{children:[/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",title:"Text that is no longer than two lines.",id:"NEPTUNE_TEST_COMPONENT",className:"m-y-2",persistDismissal:!0,onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",title:"Text that is no longer than two lines2.",id:"NEPTUNE_TEST_COMPONENT_2",className:"m-y-2",persistDismissal:!0,onClick:action("action clicked"),onDismiss:action("dismissed")})]})};
1
+ import{action}from"@storybook/addon-actions";import{Nudge}from"..";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";export default{component:Nudge,title:"Feedback/Nudge"};export var Default=function(){return/*#__PURE__*/_jsxs("div",{className:"d-flex flex-column",children:[/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"lock",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"wallet",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"gear",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"invite-letter",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"personal-card",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"business-card",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")})]})};export var DefaultWithPersist=function(){return/*#__PURE__*/_jsxs("div",{children:[/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",title:"Text that is no longer than two lines.",id:"NEPTUNE_TEST_COMPONENT",className:"m-y-2",persistDismissal:!0,onClick:action("action clicked"),onDismiss:action("dismissed"),onIsPreviouslyDismissed:action("is previously dismissed first alert")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",title:"Text that is no longer than two lines2.",id:"NEPTUNE_TEST_COMPONENT_2",className:"m-y-2",persistDismissal:!0,onClick:action("action clicked"),onDismiss:action("dismissed"),onIsPreviouslyDismissed:action("is previously dismissed second alert")})]})};
@@ -1,3 +1,3 @@
1
1
  import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import"core-js/modules/es.string.link.js";import"core-js/modules/es.array.concat.js";import"core-js/modules/es.array.find.js";import"core-js/modules/es.object.to-string.js";import{Illustration}from"@wise/art";import{useTheme}from"@wise/components-theming";import classNames from"classnames";import{useEffect,useState}from"react";import Body from"../body";import{Typography}from"../common";import{CloseButton}from"../common/closeButton";import Link from"../link";// WARNING: Changing this will cause nudges to reappear wherever persist nudge is used and privacy team will need to be updated too
2
2
  import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";export var STORAGE_NAME="dismissedNudges";export var Media={GLOBE:"globe",LOCK:"lock",WALLET:"wallet",GEAR:"gear","INVITE-LETTER":"invite-letter","PERSONAL-CARD":"personal-card","BUSINESS-CARD":"business-card"};var getLocalStorage=function(){try{var a=localStorage.getItem(STORAGE_NAME);if(a){var b=JSON.parse(a);if(Array.isArray(b))return b}// eslint-disable-next-line unicorn/prefer-optional-catch-binding, no-empty
3
- }catch(a){}return[]},Nudge=function(a){var b=a.media,c=a.mediaName,d=a.title,e=a.link,f=a.href,g=a.onClick,h=a.onDismiss,i=a.persistDismissal,j=a.id,k=a.className,l=useTheme(),m=l.isModern,n=useState(!1),o=_slicedToArray(n,2),p=o[0],q=o[1],r=useState(!1),s=_slicedToArray(r,2),t=s[0],u=s[1];return useEffect(function(){if(i&&j){var a=getLocalStorage();a&&a.find(function(a){return a===j})&&q(!0)}u(!0)},[j,i]),i&&(p||!t)?null:/*#__PURE__*/_jsxs("div",{className:classNames("wds-nudge",k),id:j,children:[m?!!c&&/*#__PURE__*/_jsx("div",{className:"wds-nudge-media",children:/*#__PURE__*/_jsx(Illustration,{name:c,className:classNames("wds-nudge-media-".concat(c)),size:"small",disablePadding:!0,alt:""})}):/*#__PURE__*/_jsx("div",{className:"wds-nudge-media",children:b}),/*#__PURE__*/_jsxs("div",{className:"wds-nudge-container",children:[/*#__PURE__*/_jsxs("div",{className:"wds-nudge-content",children:[m?/*#__PURE__*/_jsx(Body,{type:Typography.BODY_LARGE,className:classNames("wds-nudge-body"),children:d}):/*#__PURE__*/_jsx("div",{className:"wds-nudge-title",children:d}),e&&/*#__PURE__*/_jsx(Link,{href:f,type:Typography.LINK_LARGE,className:"wds-nudge-link",onClick:g,children:e})]}),h||i?/*#__PURE__*/_jsx(CloseButton,{className:"wds-nudge-control",size:"sm",onClick:function handleOnDismiss(){var a=getLocalStorage();if(i&&j){try{localStorage.setItem(STORAGE_NAME,JSON.stringify([].concat(_toConsumableArray(a?a:[]),[j])))}catch(a){}q(!0)}h&&h()}}):null]})]})};export default Nudge;
3
+ }catch(a){}return[]},Nudge=function(a){var b=a.media,c=a.mediaName,d=a.title,e=a.link,f=a.href,g=a.onClick,h=a.onDismiss,i=a.persistDismissal,j=a.onIsPreviouslyDismissed,k=a.id,l=a.className,m=useTheme(),n=m.isModern,o=useState(!1),p=_slicedToArray(o,2),q=p[0],r=p[1],s=useState(!1),t=_slicedToArray(s,2),u=t[0],v=t[1];return useEffect(function(){if(i&&k){var a=getLocalStorage(),b=!1;a&&a.find(function(a){return a===k})&&(r(!0),b=!0),j&&j(b)}v(!0)},[k,i]),i&&(q||!u)?null:/*#__PURE__*/_jsxs("div",{className:classNames("wds-nudge",l),id:k,children:[n?!!c&&/*#__PURE__*/_jsx("div",{className:"wds-nudge-media",children:/*#__PURE__*/_jsx(Illustration,{name:c,className:classNames("wds-nudge-media-".concat(c)),size:"small",disablePadding:!0,alt:""})}):/*#__PURE__*/_jsx("div",{className:"wds-nudge-media",children:b}),/*#__PURE__*/_jsxs("div",{className:"wds-nudge-container",children:[/*#__PURE__*/_jsxs("div",{className:"wds-nudge-content",children:[n?/*#__PURE__*/_jsx(Body,{type:Typography.BODY_LARGE,className:classNames("wds-nudge-body"),children:d}):/*#__PURE__*/_jsx("div",{className:"wds-nudge-title",children:d}),e&&/*#__PURE__*/_jsx(Link,{href:f,type:Typography.LINK_LARGE,className:"wds-nudge-link",onClick:g,children:e})]}),h||i?/*#__PURE__*/_jsx(CloseButton,{className:"wds-nudge-control",size:"sm",onClick:function handleOnDismiss(){var a=getLocalStorage();if(i&&k){try{localStorage.setItem(STORAGE_NAME,JSON.stringify([].concat(_toConsumableArray(a?a:[]),[k])))}catch(a){}r(!0)}h&&h()}}):null]})]})};export default Nudge;
@@ -1 +1 @@
1
- import _defineProperty from"@babel/runtime/helpers/defineProperty";import"core-js/modules/es.object.keys.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.array.filter.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.object.get-own-property-descriptor.js";import"core-js/modules/web.dom-collections.for-each.js";import"core-js/modules/es.object.get-own-property-descriptors.js";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import{render,fireEvent,cleanup,screen}from"../test-utils";import Nudge from".";import{jsx as _jsx}from"react/jsx-runtime";describe("Nudge",function(){var a={media:/*#__PURE__*/_jsx("span",{role:"img","aria-label":"Party popper emoji",children:"\uD83C\uDF89"}),title:"A nudge title",link:"CTA",href:"#",onClick:jest.fn(),onDismiss:jest.fn()};afterEach(cleanup),it("renders a media element",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByRole("img");expect(b).toBeInTheDocument()}),it("renders a title",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("A nudge title");expect(b).toBeInTheDocument()}),it("renders a link to the passed href",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("CTA");expect(b).toBeInTheDocument(),expect(b).toHaveAttribute("href",a.href)}),it("calls onClick prop when the link is clicked",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("CTA");fireEvent.click(b),expect(a.onClick).toHaveBeenCalledTimes(1)}),it("calls onDismiss prop when close button is clicked",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByLabelText("Close");fireEvent.click(b),expect(a.onDismiss).toHaveBeenCalledTimes(1)}),it("adds the passed id to the parent container",function(){var b;render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"nudge-id"})));var c=null===(b=screen.getByRole("img").parentElement)||void 0===b?void 0:b.parentElement;expect(null===c||void 0===c?void 0:c.id).toBe("nudge-id")}),it("adds the passed className to the parent container's className",function(){var b;render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{className:"happy-nudge"})));var c=null===(b=screen.getByRole("img").parentElement)||void 0===b?void 0:b.parentElement;expect(c).toHaveClass("happy-nudge")}),describe("Nudge persistance",function(){beforeEach(function(){jest.resetAllMocks()}),it("does NOT render a nudge if localStorage has been set with the id of the nudge",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"CAKE\",\"TEST\"]"),render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.queryByText("A nudge title")).not.toBeInTheDocument()}),it("shows a nudge if localStorage has been set with a different id for a different nudge",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"BANANA\"]"),render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.getByText("A nudge title")).toBeInTheDocument()}),it("calls local storage with updated dismissed nudges value",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"BANANA\"]");var b=jest.spyOn(window.localStorage.__proto__,"setItem");render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.getByText("A nudge title")).toBeInTheDocument();var c=screen.getByLabelText("Close");fireEvent.click(c),expect(a.onDismiss).toHaveBeenCalledTimes(1),expect(b).toHaveBeenCalledWith("dismissedNudges","[\"BANANA\",\"TEST\"]")})})});
1
+ import _defineProperty from"@babel/runtime/helpers/defineProperty";import"core-js/modules/es.object.keys.js";import"core-js/modules/es.symbol.js";import"core-js/modules/es.array.filter.js";import"core-js/modules/es.object.to-string.js";import"core-js/modules/es.object.get-own-property-descriptor.js";import"core-js/modules/web.dom-collections.for-each.js";import"core-js/modules/es.object.get-own-property-descriptors.js";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import{render,fireEvent,cleanup,screen}from"../test-utils";import Nudge from".";import{jsx as _jsx}from"react/jsx-runtime";describe("Nudge",function(){var a={media:/*#__PURE__*/_jsx("span",{role:"img","aria-label":"Party popper emoji",children:"\uD83C\uDF89"}),title:"A nudge title",link:"CTA",href:"#",onClick:jest.fn(),onDismiss:jest.fn()};afterEach(cleanup),it("renders a media element",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByRole("img");expect(b).toBeInTheDocument()}),it("renders a title",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("A nudge title");expect(b).toBeInTheDocument()}),it("renders a link to the passed href",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("CTA");expect(b).toBeInTheDocument(),expect(b).toHaveAttribute("href",a.href)}),it("calls onClick prop when the link is clicked",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByText("CTA");fireEvent.click(b),expect(a.onClick).toHaveBeenCalledTimes(1)}),it("calls onDismiss prop when close button is clicked",function(){render(/*#__PURE__*/_jsx(Nudge,_objectSpread({},a)));var b=screen.getByLabelText("Close");fireEvent.click(b),expect(a.onDismiss).toHaveBeenCalledTimes(1)}),it("adds the passed id to the parent container",function(){var b;render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"nudge-id"})));var c=null===(b=screen.getByRole("img").parentElement)||void 0===b?void 0:b.parentElement;expect(null===c||void 0===c?void 0:c.id).toBe("nudge-id")}),it("adds the passed className to the parent container's className",function(){var b;render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{className:"happy-nudge"})));var c=null===(b=screen.getByRole("img").parentElement)||void 0===b?void 0:b.parentElement;expect(c).toHaveClass("happy-nudge")}),describe("Nudge persistance",function(){beforeEach(function(){jest.resetAllMocks()}),it("does NOT render a nudge if localStorage has been set with the id of the nudge",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"CAKE\",\"TEST\"]"),render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.queryByText("A nudge title")).not.toBeInTheDocument()}),it("does NOT render a nudge if localStorage has been set with the id of the nudge AND calls is previously dismissed with TRUE",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"CAKE\",\"TEST\"]");var b=jest.fn();render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0,onIsPreviouslyDismissed:b}))),expect(screen.queryByText("A nudge title")).not.toBeInTheDocument(),expect(b).toHaveBeenCalledWith(!0)}),it("shows a nudge if localStorage has been set with a different id for a different nudge and calls is previously dismissed with FALSE",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"BANANA\"]");var b=jest.fn();render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0,onIsPreviouslyDismissed:b}))),expect(screen.getByText("A nudge title")).toBeInTheDocument(),expect(b).toHaveBeenCalledWith(!1)}),it("calls local storage with updated dismissed nudges value",function(){jest.spyOn(window.localStorage.__proto__,"getItem").mockReturnValue("[\"BANANA\"]");var b=jest.spyOn(window.localStorage.__proto__,"setItem");render(/*#__PURE__*/_jsx(Nudge,_objectSpread(_objectSpread({},a),{},{id:"TEST",persistDismissal:!0}))),expect(screen.getByText("A nudge title")).toBeInTheDocument();var c=screen.getByLabelText("Close");fireEvent.click(c),expect(a.onDismiss).toHaveBeenCalledTimes(1),expect(b).toHaveBeenCalledWith("dismissedNudges","[\"BANANA\",\"TEST\"]")})})});
@@ -1 +1 @@
1
- import{action}from"@storybook/addon-actions";import{Nudge}from"..";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";export default{component:Nudge,title:"Feedback/Nudge"};export var Default=function(){return/*#__PURE__*/_jsxs("div",{className:"d-flex flex-column",children:[/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"lock",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"wallet",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"gear",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"invite-letter",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"personal-card",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"business-card",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")})]})};export var DefaultWithPersist=function(){return/*#__PURE__*/_jsxs("div",{children:[/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",title:"Text that is no longer than two lines.",id:"NEPTUNE_TEST_COMPONENT",className:"m-y-2",persistDismissal:!0,onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",title:"Text that is no longer than two lines2.",id:"NEPTUNE_TEST_COMPONENT_2",className:"m-y-2",persistDismissal:!0,onClick:action("action clicked"),onDismiss:action("dismissed")})]})};
1
+ import{action}from"@storybook/addon-actions";import{Nudge}from"..";import{jsx as _jsx}from"react/jsx-runtime";import{jsxs as _jsxs}from"react/jsx-runtime";export default{component:Nudge,title:"Feedback/Nudge"};export var Default=function(){return/*#__PURE__*/_jsxs("div",{className:"d-flex flex-column",children:[/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"lock",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"wallet",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"gear",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"invite-letter",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"personal-card",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"business-card",className:"m-b-2",title:"Text that is no longer than two lines.",link:"Link",href:"#",onClick:action("action clicked"),onDismiss:action("dismissed")})]})};export var DefaultWithPersist=function(){return/*#__PURE__*/_jsxs("div",{children:[/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",title:"Text that is no longer than two lines.",id:"NEPTUNE_TEST_COMPONENT",className:"m-y-2",persistDismissal:!0,onClick:action("action clicked"),onDismiss:action("dismissed"),onIsPreviouslyDismissed:action("is previously dismissed first alert")}),/*#__PURE__*/_jsx(Nudge,{mediaName:"globe",title:"Text that is no longer than two lines2.",id:"NEPTUNE_TEST_COMPONENT_2",className:"m-y-2",persistDismissal:!0,onClick:action("action clicked"),onDismiss:action("dismissed"),onIsPreviouslyDismissed:action("is previously dismissed second alert")})]})};
@@ -28,13 +28,20 @@ type BaseProps = {
28
28
  export interface OptionalId extends BaseProps {
29
29
  id?: string;
30
30
  persistDismissal?: false;
31
+ onIsPreviouslyDismissed?: undefined;
31
32
  }
32
33
  export interface RequiredPersistProps extends BaseProps {
33
34
  /** This ID should be completely unique to the page and feature as it uses a shared array which could conflict with other nudges in Wise */
34
35
  id: string;
35
36
  /** Use persist dismissal to keep the nudge dismissed using the browser's localStorage */
36
37
  persistDismissal: true;
38
+ /**
39
+ * Fired on mount for determining if nudge has been dismissed before
40
+ *
41
+ * @param {boolean} isPreviouslyDismissed - set to true if dismissed previously
42
+ */
43
+ onIsPreviouslyDismissed?: (isPreviouslyDismissed: boolean) => void;
37
44
  }
38
45
  export type Props = OptionalId | RequiredPersistProps;
39
- declare const Nudge: ({ media, mediaName, title, link, href, onClick, onDismiss, persistDismissal, id, className, }: Props) => JSX.Element | null;
46
+ declare const Nudge: ({ media, mediaName, title, link, href, onClick, onDismiss, persistDismissal, onIsPreviouslyDismissed, id, className, }: Props) => JSX.Element | null;
40
47
  export default Nudge;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  declare const _default: {
3
- component: ({ media, mediaName, title, link, href, onClick, onDismiss, persistDismissal, id, className, }: import("./Nudge").Props) => JSX.Element | null;
3
+ component: ({ media, mediaName, title, link, href, onClick, onDismiss, persistDismissal, onIsPreviouslyDismissed, id, className, }: import("./Nudge").Props) => JSX.Element | null;
4
4
  title: string;
5
5
  };
6
6
  export default _default;