@transferwise/components 46.157.1 → 46.159.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 (68) hide show
  1. package/build/FlowNavigation/FlowNavigation.js +5 -14
  2. package/build/FlowNavigation/FlowNavigation.js.map +1 -1
  3. package/build/FlowNavigation/FlowNavigation.mjs +5 -14
  4. package/build/FlowNavigation/FlowNavigation.mjs.map +1 -1
  5. package/build/Markup/Markup.js +15 -14
  6. package/build/Markup/Markup.js.map +1 -1
  7. package/build/Markup/Markup.mjs +15 -14
  8. package/build/Markup/Markup.mjs.map +1 -1
  9. package/build/Popover/Popover.js +4 -0
  10. package/build/Popover/Popover.js.map +1 -1
  11. package/build/Popover/Popover.mjs +4 -0
  12. package/build/Popover/Popover.mjs.map +1 -1
  13. package/build/_deprecated/OverlayHeader/OverlayHeader.js +6 -41
  14. package/build/_deprecated/OverlayHeader/OverlayHeader.js.map +1 -1
  15. package/build/_deprecated/OverlayHeader/OverlayHeader.mjs +6 -41
  16. package/build/_deprecated/OverlayHeader/OverlayHeader.mjs.map +1 -1
  17. package/build/common/Panel/Panel.js +13 -4
  18. package/build/common/Panel/Panel.js.map +1 -1
  19. package/build/common/Panel/Panel.mjs +14 -5
  20. package/build/common/Panel/Panel.mjs.map +1 -1
  21. package/build/common/PropsValues/position.js +29 -0
  22. package/build/common/PropsValues/position.js.map +1 -1
  23. package/build/common/PropsValues/position.mjs +28 -1
  24. package/build/common/PropsValues/position.mjs.map +1 -1
  25. package/build/main.css +8 -34
  26. package/build/styles/FlowNavigation/FlowNavigation.css +7 -13
  27. package/build/styles/main.css +8 -34
  28. package/build/types/FlowNavigation/FlowNavigation.d.ts +2 -9
  29. package/build/types/FlowNavigation/FlowNavigation.d.ts.map +1 -1
  30. package/build/types/Markup/Markup.d.ts.map +1 -1
  31. package/build/types/Markup/Markup.types.d.ts +16 -5
  32. package/build/types/Markup/Markup.types.d.ts.map +1 -1
  33. package/build/types/Markup/index.d.ts +1 -1
  34. package/build/types/Markup/index.d.ts.map +1 -1
  35. package/build/types/Popover/Popover.d.ts +1 -1
  36. package/build/types/Popover/Popover.d.ts.map +1 -1
  37. package/build/types/_deprecated/OverlayHeader/OverlayHeader.d.ts.map +1 -1
  38. package/build/types/common/Panel/Panel.d.ts +6 -6
  39. package/build/types/common/Panel/Panel.d.ts.map +1 -1
  40. package/build/types/common/PropsValues/position.d.ts +18 -1
  41. package/build/types/common/PropsValues/position.d.ts.map +1 -1
  42. package/build/types/common/ResponsivePanel/ResponsivePanel.d.ts +2 -2
  43. package/build/types/index.d.ts +1 -1
  44. package/build/types/index.d.ts.map +1 -1
  45. package/package.json +3 -3
  46. package/src/FlowNavigation/FlowNavigation.css +7 -13
  47. package/src/FlowNavigation/FlowNavigation.less +6 -15
  48. package/src/FlowNavigation/FlowNavigation.tsx +6 -27
  49. package/src/FlowNavigation/_stories/FlowNavigation.story.tsx +0 -86
  50. package/src/Markup/Markup.test.tsx +8 -7
  51. package/src/Markup/Markup.tsx +18 -15
  52. package/src/Markup/Markup.types.ts +16 -6
  53. package/src/Markup/_stories/Markup.docs.mdx +60 -0
  54. package/src/Markup/_stories/Markup.story.tsx +7 -8
  55. package/src/Markup/index.ts +6 -1
  56. package/src/Popover/Popover.tsx +9 -2
  57. package/src/_deprecated/OverlayHeader/OverlayHeader.tsx +2 -21
  58. package/src/common/Panel/Panel.test.tsx +17 -0
  59. package/src/common/Panel/Panel.tsx +17 -8
  60. package/src/common/Panel/_stories/Panel.story.tsx +182 -0
  61. package/src/common/PropsValues/position.ts +54 -0
  62. package/src/i18n/en.json +1 -0
  63. package/src/index.ts +1 -1
  64. package/src/main.css +8 -34
  65. package/src/main.less +0 -1
  66. package/build/styles/_deprecated/OverlayHeader/OverlayHeader.css +0 -15
  67. package/src/_deprecated/OverlayHeader/OverlayHeader.css +0 -15
  68. package/src/_deprecated/OverlayHeader/OverlayHeader.less +0 -24
@@ -46,7 +46,6 @@ const FlowNavigation = ({
46
46
  onClose,
47
47
  onGoBack,
48
48
  steps,
49
- composable = false,
50
49
  showBottomBorder = true
51
50
  }) => {
52
51
  const intl = reactIntl.useIntl();
@@ -59,7 +58,7 @@ const FlowNavigation = ({
59
58
  const newAvatar = done ? null : avatar;
60
59
  const displayGoBack = onGoBack != null && activeStep > 0;
61
60
  const flowHeaderContent = /*#__PURE__*/jsxRuntime.jsx(FlowHeader.default, {
62
- className: clsx.clsx('np-flow-navigation__content', !composable && 'p-x-3', screenSm == null ? 'np-flow-navigation--hidden' : {
61
+ className: clsx.clsx('np-flow-navigation__content', screenSm == null ? 'np-flow-navigation--hidden' : {
63
62
  'np-flow-navigation--xs-max': !screenSm,
64
63
  // Size switches on parent container which may or may not have the same size as the window.
65
64
  'np-flow-navigation--sm': screenSm,
@@ -95,18 +94,10 @@ const FlowNavigation = ({
95
94
  }) : null,
96
95
  layout: !screenLg ? layouts.Layout.VERTICAL : layouts.Layout.HORIZONTAL
97
96
  });
98
- if (composable) {
99
- return /*#__PURE__*/jsxRuntime.jsx(Container.default, {
100
- size: "fluid",
101
- className: clsx.clsx('np-flow-navigation np-flow-navigation--composable', {
102
- 'np-flow-navigation--border-bottom': showBottomBorder
103
- }),
104
- children: flowHeaderContent
105
- });
106
- }
107
- return /*#__PURE__*/jsxRuntime.jsx("div", {
108
- className: clsx.clsx('np-flow-navigation p-y-3', {
109
- 'np-flow-navigation--border-bottom': !done
97
+ return /*#__PURE__*/jsxRuntime.jsx(Container.default, {
98
+ size: "fluid",
99
+ className: clsx.clsx('np-flow-navigation', {
100
+ 'np-flow-navigation--border-bottom': showBottomBorder
110
101
  }),
111
102
  children: flowHeaderContent
112
103
  });
@@ -1 +1 @@
1
- {"version":3,"file":"FlowNavigation.js","sources":["../../src/FlowNavigation/FlowNavigation.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useIntl } from 'react-intl';\nimport { Breakpoint } from '@transferwise/neptune-tokens';\n\nimport { Layout } from '../common';\nimport { CloseButton } from '../common/CloseButton';\nimport FlowHeader from '../common/FlowHeader/FlowHeader';\nimport Logo from '../Logo';\nimport Stepper, { type Step } from '../Stepper/Stepper';\nimport Container from '../Container';\n\nimport { useScreenSize } from '../common/hooks/useScreenSize';\nimport messages from './FlowNavigation.messages';\nimport AnimatedLabel from './AnimatedLabel';\nimport IconButton from '../IconButton';\nimport { ArrowLeft } from '@transferwise/icons';\n\nconst defaultLogo = <Logo />;\n\nexport interface FlowNavigationProps {\n /** @default 0 */\n activeStep?: number;\n avatar?: React.ReactNode;\n /** @default <Logo /> */\n logo?: React.ReactNode;\n /** @default false */\n done?: boolean;\n /** Called when the close button is clicked. If not provided the close button won't show */\n onClose?: () => void;\n /** Called when the back button is clicked. If not provided the back button won't show. The back button only shows on small screens */\n onGoBack?: () => void;\n /** Steps to be displayed in stepper. If not provided, the stepper won't show. */\n steps?: readonly Step[];\n /**\n * When true, renders in composable mode using a fluid Container.\n * This allows the FlowNavigation to be used within custom layout containers.\n * @default false\n */\n composable?: boolean;\n /**\n * Controls whether the bottom border is displayed.\n * Only applies to the composable variant. Non-composable variant always uses the done state.\n * @default true\n */\n showBottomBorder?: boolean;\n}\n\nconst FlowNavigation = ({\n activeStep = 0,\n avatar,\n logo = defaultLogo,\n done = false,\n onClose,\n onGoBack,\n steps,\n composable = false,\n showBottomBorder = true,\n}: FlowNavigationProps) => {\n const intl = useIntl();\n const screenSm = useScreenSize(Breakpoint.SMALL);\n const screenLg = useScreenSize(Breakpoint.LARGE);\n\n const closeButton = onClose != null && <CloseButton size=\"lg\" onClick={onClose} />;\n\n const newAvatar = done ? null : avatar;\n const displayGoBack = onGoBack != null && activeStep > 0;\n\n const flowHeaderContent = (\n <FlowHeader\n className={clsx(\n 'np-flow-navigation__content',\n !composable && 'p-x-3',\n screenSm == null\n ? 'np-flow-navigation--hidden'\n : {\n 'np-flow-navigation--xs-max': !screenSm,\n // Size switches on parent container which may or may not have the same size as the window.\n 'np-flow-navigation--sm': screenSm,\n 'np-flow-navigation--lg': screenLg,\n },\n )}\n leftContent={\n <>\n {!screenSm && displayGoBack ? (\n <IconButton\n size={40}\n priority=\"tertiary\"\n type=\"default\"\n aria-label={intl.formatMessage(messages.back)}\n onClick={onGoBack}\n >\n <ArrowLeft />\n </IconButton>\n ) : (\n <div className=\"np-flow-header__left\">{logo}</div>\n )}\n {!screenSm && !done && steps && steps.length > 0 && (\n <AnimatedLabel className=\"m-x-1\" steps={steps} activeLabel={activeStep} />\n )}\n </>\n }\n rightContent={\n <div className=\"np-flow-header__right d-flex align-items-center justify-content-end order-2--lg\">\n {newAvatar}\n {newAvatar && closeButton && <span className=\"m-x-1\" />}\n {closeButton}\n </div>\n }\n bottomContent={\n !done && steps && steps.length > 0 ? (\n <Stepper\n activeStep={activeStep}\n steps={steps}\n className={clsx('np-flow-navigation__stepper')}\n />\n ) : null\n }\n layout={!screenLg ? Layout.VERTICAL : Layout.HORIZONTAL}\n />\n );\n\n if (composable) {\n return (\n <Container\n size=\"fluid\"\n className={clsx('np-flow-navigation np-flow-navigation--composable', {\n 'np-flow-navigation--border-bottom': showBottomBorder,\n })}\n >\n {flowHeaderContent}\n </Container>\n );\n }\n\n return (\n <div\n className={clsx('np-flow-navigation p-y-3', {\n 'np-flow-navigation--border-bottom': !done,\n })}\n >\n {flowHeaderContent}\n </div>\n );\n};\n\nexport default FlowNavigation;\n"],"names":["defaultLogo","_jsx","Logo","FlowNavigation","activeStep","avatar","logo","done","onClose","onGoBack","steps","composable","showBottomBorder","intl","useIntl","screenSm","useScreenSize","Breakpoint","SMALL","screenLg","LARGE","closeButton","CloseButton","size","onClick","newAvatar","displayGoBack","flowHeaderContent","FlowHeader","className","clsx","leftContent","_jsxs","_Fragment","children","IconButton","priority","type","formatMessage","messages","back","ArrowLeft","length","AnimatedLabel","activeLabel","rightContent","bottomContent","Stepper","layout","Layout","VERTICAL","HORIZONTAL","Container"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,WAAW,gB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A,CAE3D;AAED,EAAA,IAAIxC,UAAU,EAAE;IACd,oBACEV,cAAA,CAACmD,iBAAS,EAAA;AACR7B,MAAAA,IAAI,EAAC,OAAO;AACZM,MAAAA,SAAS,EAAEC,SAAI,CAAC,mDAAmD,EAAE;AACnE,QAAA,mCAAmC,EAAElB;AACtC,OAAA,CAAE;AAAAsB,MAAAA,QAAA,EAEFP;AAAiB,KACT,CAAC;AAEhB,EAAA;AAEA,EAAA,oBACE1B,cAAA,CAAA,KAAA,EAAA;AACE4B,IAAAA,SAAS,EAAEC,SAAI,CAAC,0BAA0B,EAAE;AAC1C,MAAA,mCAAmC,EAAE,CAACvB;AACvC,KAAA,CAAE;AAAA2B,IAAAA,QAAA,EAEFP;AAAiB,GACf,CAAC;AAEV;;;;"}
1
+ {"version":3,"file":"FlowNavigation.js","sources":["../../src/FlowNavigation/FlowNavigation.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useIntl } from 'react-intl';\nimport { Breakpoint } from '@transferwise/neptune-tokens';\n\nimport { Layout } from '../common';\nimport { CloseButton } from '../common/CloseButton';\nimport FlowHeader from '../common/FlowHeader/FlowHeader';\nimport Logo from '../Logo';\nimport Stepper, { type Step } from '../Stepper/Stepper';\nimport Container from '../Container';\n\nimport { useScreenSize } from '../common/hooks/useScreenSize';\nimport messages from './FlowNavigation.messages';\nimport AnimatedLabel from './AnimatedLabel';\nimport IconButton from '../IconButton';\nimport { ArrowLeft } from '@transferwise/icons';\n\nconst defaultLogo = <Logo />;\n\nexport interface FlowNavigationProps {\n /** @default 0 */\n activeStep?: number;\n avatar?: React.ReactNode;\n /** @default <Logo /> */\n logo?: React.ReactNode;\n /** @default false */\n done?: boolean;\n /** Called when the close button is clicked. If not provided the close button won't show */\n onClose?: (() => void) | React.MouseEventHandler<HTMLButtonElement>;\n /** Called when the back button is clicked. If not provided the back button won't show. The back button only shows on small screens */\n onGoBack?: () => void;\n /** Steps to be displayed in stepper. If not provided, the stepper won't show. */\n steps?: readonly Step[];\n /**\n * Controls whether the bottom border is displayed.\n * @default true\n */\n showBottomBorder?: boolean;\n}\n\nconst FlowNavigation = ({\n activeStep = 0,\n avatar,\n logo = defaultLogo,\n done = false,\n onClose,\n onGoBack,\n steps,\n showBottomBorder = true,\n}: FlowNavigationProps) => {\n const intl = useIntl();\n const screenSm = useScreenSize(Breakpoint.SMALL);\n const screenLg = useScreenSize(Breakpoint.LARGE);\n\n const closeButton = onClose != null && <CloseButton size=\"lg\" onClick={onClose} />;\n\n const newAvatar = done ? null : avatar;\n const displayGoBack = onGoBack != null && activeStep > 0;\n\n const flowHeaderContent = (\n <FlowHeader\n className={clsx(\n 'np-flow-navigation__content',\n screenSm == null\n ? 'np-flow-navigation--hidden'\n : {\n 'np-flow-navigation--xs-max': !screenSm,\n // Size switches on parent container which may or may not have the same size as the window.\n 'np-flow-navigation--sm': screenSm,\n 'np-flow-navigation--lg': screenLg,\n },\n )}\n leftContent={\n <>\n {!screenSm && displayGoBack ? (\n <IconButton\n size={40}\n priority=\"tertiary\"\n type=\"default\"\n aria-label={intl.formatMessage(messages.back)}\n onClick={onGoBack}\n >\n <ArrowLeft />\n </IconButton>\n ) : (\n <div className=\"np-flow-header__left\">{logo}</div>\n )}\n {!screenSm && !done && steps && steps.length > 0 && (\n <AnimatedLabel className=\"m-x-1\" steps={steps} activeLabel={activeStep} />\n )}\n </>\n }\n rightContent={\n <div className=\"np-flow-header__right d-flex align-items-center justify-content-end order-2--lg\">\n {newAvatar}\n {newAvatar && closeButton && <span className=\"m-x-1\" />}\n {closeButton}\n </div>\n }\n bottomContent={\n !done && steps && steps.length > 0 ? (\n <Stepper\n activeStep={activeStep}\n steps={steps}\n className={clsx('np-flow-navigation__stepper')}\n />\n ) : null\n }\n layout={!screenLg ? Layout.VERTICAL : Layout.HORIZONTAL}\n />\n );\n\n return (\n <Container\n size=\"fluid\"\n className={clsx('np-flow-navigation', {\n 'np-flow-navigation--border-bottom': showBottomBorder,\n })}\n >\n {flowHeaderContent}\n </Container>\n );\n};\n\nexport default FlowNavigation;\n"],"names":["defaultLogo","_jsx","Logo","FlowNavigation","activeStep","avatar","logo","done","onClose","onGoBack","steps","showBottomBorder","intl","useIntl","screenSm","useScreenSize","Breakpoint","SMALL","screenLg","LARGE","closeButton","CloseButton","size","onClick","newAvatar","displayGoBack","flowHeaderContent","FlowHeader","className","clsx","leftContent","_jsxs","_Fragment","children","IconButton","priority","type","formatMessage","messages","back","ArrowLeft","length","AnimatedLabel","activeLabel","rightContent","bottomContent","Stepper","layout","Layout","VERTICAL","HORIZONTAL","Container"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,WAAW,gBAAGC,cAAA,CAACC,YAAI,KAAG;AAuB5B,MAAMC,cAAc,GAAGA,CAAC;AACtBC,EAAAA,UAAU,GAAG,CAAC;EACdC,MAAM;AACNC,EAAAA,IAAI,GAAGN,WAAW;AAClBO,EAAAA,IAAI,GAAG,KAAK;EACZC,OAAO;EACPC,QAAQ;EACRC,KAAK;AACLC,EAAAA,gBAAgB,GAAG;AAAI,CACH,KAAI;AACxB,EAAA,MAAMC,IAAI,GAAGC,iBAAO,EAAE;AACtB,EAAA,MAAMC,QAAQ,GAAGC,2BAAa,CAACC,wBAAU,CAACC,KAAK,CAAC;AAChD,EAAA,MAAMC,QAAQ,GAAGH,2BAAa,CAACC,wBAAU,CAACG,KAAK,CAAC;EAEhD,MAAMC,WAAW,GAAGZ,OAAO,IAAI,IAAI,iBAAIP,cAAA,CAACoB,uBAAW,EAAA;AAACC,IAAAA,IAAI,EAAC,IAAI;AAACC,IAAAA,OAAO,EAAEf;AAAQ,IAAG;AAElF,EAAA,MAAMgB,SAAS,GAAGjB,IAAI,GAAG,IAAI,GAAGF,MAAM;EACtC,MAAMoB,aAAa,GAAGhB,QAAQ,IAAI,IAAI,IAAIL,UAAU,GAAG,CAAC;AAExD,EAAA,MAAMsB,iBAAiB,gBACrBzB,cAAA,CAAC0B,kBAAU,EAAA;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KACT,CACN;AACDyB,IAAAA,aAAa,EACX,CAACtC,IAAI,IAAIG,KAAK,IAAIA,KAAK,CAAC+B,MAAM,GAAG,CAAC,gBAChCxC,cAAA,CAAC6C,eAAO,EAAA;AACN1C,MAAAA,UAAU,EAAEA,UAAW;AACvBM,MAAAA,KAAK,EAAEA,KAAM;MACbkB,SAAS,EAAEC,SAAI,CAAC,6BAA6B;KAAE,CAC/C,GACA,IACL;IACDkB,MAAM,EAAE,CAAC7B,QAAQ,GAAG8B,cAAM,CAACC,QAAQ,GAAGD,cAAM,CAACE;AAAW,GAAA,CAE3D;EAED,oBACEjD,cAAA,CAACkD,iBAAS,EAAA;AACR7B,IAAAA,IAAI,EAAC,OAAO;AACZM,IAAAA,SAAS,EAAEC,SAAI,CAAC,oBAAoB,EAAE;AACpC,MAAA,mCAAmC,EAAElB;AACtC,KAAA,CAAE;AAAAsB,IAAAA,QAAA,EAEFP;AAAiB,GACT,CAAC;AAEhB;;;;"}
@@ -42,7 +42,6 @@ const FlowNavigation = ({
42
42
  onClose,
43
43
  onGoBack,
44
44
  steps,
45
- composable = false,
46
45
  showBottomBorder = true
47
46
  }) => {
48
47
  const intl = useIntl();
@@ -55,7 +54,7 @@ const FlowNavigation = ({
55
54
  const newAvatar = done ? null : avatar;
56
55
  const displayGoBack = onGoBack != null && activeStep > 0;
57
56
  const flowHeaderContent = /*#__PURE__*/jsx(FlowHeader, {
58
- className: clsx('np-flow-navigation__content', !composable && 'p-x-3', screenSm == null ? 'np-flow-navigation--hidden' : {
57
+ className: clsx('np-flow-navigation__content', screenSm == null ? 'np-flow-navigation--hidden' : {
59
58
  'np-flow-navigation--xs-max': !screenSm,
60
59
  // Size switches on parent container which may or may not have the same size as the window.
61
60
  'np-flow-navigation--sm': screenSm,
@@ -91,18 +90,10 @@ const FlowNavigation = ({
91
90
  }) : null,
92
91
  layout: !screenLg ? Layout.VERTICAL : Layout.HORIZONTAL
93
92
  });
94
- if (composable) {
95
- return /*#__PURE__*/jsx(Container, {
96
- size: "fluid",
97
- className: clsx('np-flow-navigation np-flow-navigation--composable', {
98
- 'np-flow-navigation--border-bottom': showBottomBorder
99
- }),
100
- children: flowHeaderContent
101
- });
102
- }
103
- return /*#__PURE__*/jsx("div", {
104
- className: clsx('np-flow-navigation p-y-3', {
105
- 'np-flow-navigation--border-bottom': !done
93
+ return /*#__PURE__*/jsx(Container, {
94
+ size: "fluid",
95
+ className: clsx('np-flow-navigation', {
96
+ 'np-flow-navigation--border-bottom': showBottomBorder
106
97
  }),
107
98
  children: flowHeaderContent
108
99
  });
@@ -1 +1 @@
1
- {"version":3,"file":"FlowNavigation.mjs","sources":["../../src/FlowNavigation/FlowNavigation.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useIntl } from 'react-intl';\nimport { Breakpoint } from '@transferwise/neptune-tokens';\n\nimport { Layout } from '../common';\nimport { CloseButton } from '../common/CloseButton';\nimport FlowHeader from '../common/FlowHeader/FlowHeader';\nimport Logo from '../Logo';\nimport Stepper, { type Step } from '../Stepper/Stepper';\nimport Container from '../Container';\n\nimport { useScreenSize } from '../common/hooks/useScreenSize';\nimport messages from './FlowNavigation.messages';\nimport AnimatedLabel from './AnimatedLabel';\nimport IconButton from '../IconButton';\nimport { ArrowLeft } from '@transferwise/icons';\n\nconst defaultLogo = <Logo />;\n\nexport interface FlowNavigationProps {\n /** @default 0 */\n activeStep?: number;\n avatar?: React.ReactNode;\n /** @default <Logo /> */\n logo?: React.ReactNode;\n /** @default false */\n done?: boolean;\n /** Called when the close button is clicked. If not provided the close button won't show */\n onClose?: () => void;\n /** Called when the back button is clicked. If not provided the back button won't show. The back button only shows on small screens */\n onGoBack?: () => void;\n /** Steps to be displayed in stepper. If not provided, the stepper won't show. */\n steps?: readonly Step[];\n /**\n * When true, renders in composable mode using a fluid Container.\n * This allows the FlowNavigation to be used within custom layout containers.\n * @default false\n */\n composable?: boolean;\n /**\n * Controls whether the bottom border is displayed.\n * Only applies to the composable variant. Non-composable variant always uses the done state.\n * @default true\n */\n showBottomBorder?: boolean;\n}\n\nconst FlowNavigation = ({\n activeStep = 0,\n avatar,\n logo = defaultLogo,\n done = false,\n onClose,\n onGoBack,\n steps,\n composable = false,\n showBottomBorder = true,\n}: FlowNavigationProps) => {\n const intl = useIntl();\n const screenSm = useScreenSize(Breakpoint.SMALL);\n const screenLg = useScreenSize(Breakpoint.LARGE);\n\n const closeButton = onClose != null && <CloseButton size=\"lg\" onClick={onClose} />;\n\n const newAvatar = done ? null : avatar;\n const displayGoBack = onGoBack != null && activeStep > 0;\n\n const flowHeaderContent = (\n <FlowHeader\n className={clsx(\n 'np-flow-navigation__content',\n !composable && 'p-x-3',\n screenSm == null\n ? 'np-flow-navigation--hidden'\n : {\n 'np-flow-navigation--xs-max': !screenSm,\n // Size switches on parent container which may or may not have the same size as the window.\n 'np-flow-navigation--sm': screenSm,\n 'np-flow-navigation--lg': screenLg,\n },\n )}\n leftContent={\n <>\n {!screenSm && displayGoBack ? (\n <IconButton\n size={40}\n priority=\"tertiary\"\n type=\"default\"\n aria-label={intl.formatMessage(messages.back)}\n onClick={onGoBack}\n >\n <ArrowLeft />\n </IconButton>\n ) : (\n <div className=\"np-flow-header__left\">{logo}</div>\n )}\n {!screenSm && !done && steps && steps.length > 0 && (\n <AnimatedLabel className=\"m-x-1\" steps={steps} activeLabel={activeStep} />\n )}\n </>\n }\n rightContent={\n <div className=\"np-flow-header__right d-flex align-items-center justify-content-end order-2--lg\">\n {newAvatar}\n {newAvatar && closeButton && <span className=\"m-x-1\" />}\n {closeButton}\n </div>\n }\n bottomContent={\n !done && steps && steps.length > 0 ? (\n <Stepper\n activeStep={activeStep}\n steps={steps}\n className={clsx('np-flow-navigation__stepper')}\n />\n ) : null\n }\n layout={!screenLg ? Layout.VERTICAL : Layout.HORIZONTAL}\n />\n );\n\n if (composable) {\n return (\n <Container\n size=\"fluid\"\n className={clsx('np-flow-navigation np-flow-navigation--composable', {\n 'np-flow-navigation--border-bottom': showBottomBorder,\n })}\n >\n {flowHeaderContent}\n </Container>\n );\n }\n\n return (\n <div\n className={clsx('np-flow-navigation p-y-3', {\n 'np-flow-navigation--border-bottom': !done,\n })}\n >\n {flowHeaderContent}\n </div>\n );\n};\n\nexport default FlowNavigation;\n"],"names":["defaultLogo","_jsx","Logo","FlowNavigation","activeStep","avatar","logo","done","onClose","onGoBack","steps","composable","showBottomBorder","intl","useIntl","screenSm","useScreenSize","Breakpoint","SMALL","screenLg","LARGE","closeButton","CloseButton","size","onClick","newAvatar","displayGoBack","flowHeaderContent","FlowHeader","className","clsx","leftContent","_jsxs","_Fragment","children","IconButton","priority","type","formatMessage","messages","back","ArrowLeft","length","AnimatedLabel","activeLabel","rightContent","bottomContent","Stepper","layout","Layout","VERTICAL","HORIZONTAL","Container"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,WAAW,gBAAGC,GAAA,CAACC,IAAI,KAAG;AA8B5B,MAAMC,cAAc,GAAGA,CAAC;AACtBC,EAAAA,UAAU,GAAG,CAAC;EACdC,MAAM;AACNC,EAAAA,IAAI,GAAGN,WAAW;AAClBO,EAAAA,IAAI,GAAG,KAAK;EACZC,OAAO;EACPC,QAAQ;EACRC,KAAK;AACLC,EAAAA,UAAU,GAAG,KAAK;AAClBC,EAAAA,gBAAgB,GAAG;AAAI,CACH,KAAI;AACxB,EAAA,MAAMC,IAAI,GAAGC,OAAO,EAAE;AACtB,EAAA,MAAMC,QAAQ,GAAGC,aAAa,CAACC,UAAU,CAACC,KAAK,CAAC;AAChD,EAAA,MAAMC,QAAQ,GAAGH,aAAa,CAACC,UAAU,CAACG,KAAK,CAAC;EAEhD,MAAMC,WAAW,GAAGb,OAAO,IAAI,IAAI,iBAAIP,GAAA,CAACqB,WAAW,EAAA;AAACC,IAAAA,IAAI,EAAC,IAAI;AAACC,IAAAA,OAAO,EAAEhB;AAAQ,IAAG;AAElF,EAAA,MAAMiB,SAAS,GAAGlB,IAAI,GAAG,IAAI,GAAGF,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,SAAS,EAAC,iFAAiF;AAAAK,MAAAA,QAAA,GAC7FT,SAAS,EACTA,SAAS,IAAIJ,WAAW,iBAAIpB,GAAA,CAAA,MAAA,EAAA;AAAM4B,QAAAA,SAAS,EAAC;OAAO,CAAG,EACtDR,WAAW;AAAA,KACT,CACN;AACDyB,IAAAA,aAAa,EACX,CAACvC,IAAI,IAAIG,KAAK,IAAIA,KAAK,CAACgC,MAAM,GAAG,CAAC,gBAChCzC,GAAA,CAAC8C,OAAO,EAAA;AACN3C,MAAAA,UAAU,EAAEA,UAAW;AACvBM,MAAAA,KAAK,EAAEA,KAAM;MACbmB,SAAS,EAAEC,IAAI,CAAC,6BAA6B;KAAE,CAC/C,GACA,IACL;IACDkB,MAAM,EAAE,CAAC7B,QAAQ,GAAG8B,MAAM,CAACC,QAAQ,GAAGD,MAAM,CAACE;AAAW,GAAA,CAE3D;AAED,EAAA,IAAIxC,UAAU,EAAE;IACd,oBACEV,GAAA,CAACmD,SAAS,EAAA;AACR7B,MAAAA,IAAI,EAAC,OAAO;AACZM,MAAAA,SAAS,EAAEC,IAAI,CAAC,mDAAmD,EAAE;AACnE,QAAA,mCAAmC,EAAElB;AACtC,OAAA,CAAE;AAAAsB,MAAAA,QAAA,EAEFP;AAAiB,KACT,CAAC;AAEhB,EAAA;AAEA,EAAA,oBACE1B,GAAA,CAAA,KAAA,EAAA;AACE4B,IAAAA,SAAS,EAAEC,IAAI,CAAC,0BAA0B,EAAE;AAC1C,MAAA,mCAAmC,EAAE,CAACvB;AACvC,KAAA,CAAE;AAAA2B,IAAAA,QAAA,EAEFP;AAAiB,GACf,CAAC;AAEV;;;;"}
1
+ {"version":3,"file":"FlowNavigation.mjs","sources":["../../src/FlowNavigation/FlowNavigation.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useIntl } from 'react-intl';\nimport { Breakpoint } from '@transferwise/neptune-tokens';\n\nimport { Layout } from '../common';\nimport { CloseButton } from '../common/CloseButton';\nimport FlowHeader from '../common/FlowHeader/FlowHeader';\nimport Logo from '../Logo';\nimport Stepper, { type Step } from '../Stepper/Stepper';\nimport Container from '../Container';\n\nimport { useScreenSize } from '../common/hooks/useScreenSize';\nimport messages from './FlowNavigation.messages';\nimport AnimatedLabel from './AnimatedLabel';\nimport IconButton from '../IconButton';\nimport { ArrowLeft } from '@transferwise/icons';\n\nconst defaultLogo = <Logo />;\n\nexport interface FlowNavigationProps {\n /** @default 0 */\n activeStep?: number;\n avatar?: React.ReactNode;\n /** @default <Logo /> */\n logo?: React.ReactNode;\n /** @default false */\n done?: boolean;\n /** Called when the close button is clicked. If not provided the close button won't show */\n onClose?: (() => void) | React.MouseEventHandler<HTMLButtonElement>;\n /** Called when the back button is clicked. If not provided the back button won't show. The back button only shows on small screens */\n onGoBack?: () => void;\n /** Steps to be displayed in stepper. If not provided, the stepper won't show. */\n steps?: readonly Step[];\n /**\n * Controls whether the bottom border is displayed.\n * @default true\n */\n showBottomBorder?: boolean;\n}\n\nconst FlowNavigation = ({\n activeStep = 0,\n avatar,\n logo = defaultLogo,\n done = false,\n onClose,\n onGoBack,\n steps,\n showBottomBorder = true,\n}: FlowNavigationProps) => {\n const intl = useIntl();\n const screenSm = useScreenSize(Breakpoint.SMALL);\n const screenLg = useScreenSize(Breakpoint.LARGE);\n\n const closeButton = onClose != null && <CloseButton size=\"lg\" onClick={onClose} />;\n\n const newAvatar = done ? null : avatar;\n const displayGoBack = onGoBack != null && activeStep > 0;\n\n const flowHeaderContent = (\n <FlowHeader\n className={clsx(\n 'np-flow-navigation__content',\n screenSm == null\n ? 'np-flow-navigation--hidden'\n : {\n 'np-flow-navigation--xs-max': !screenSm,\n // Size switches on parent container which may or may not have the same size as the window.\n 'np-flow-navigation--sm': screenSm,\n 'np-flow-navigation--lg': screenLg,\n },\n )}\n leftContent={\n <>\n {!screenSm && displayGoBack ? (\n <IconButton\n size={40}\n priority=\"tertiary\"\n type=\"default\"\n aria-label={intl.formatMessage(messages.back)}\n onClick={onGoBack}\n >\n <ArrowLeft />\n </IconButton>\n ) : (\n <div className=\"np-flow-header__left\">{logo}</div>\n )}\n {!screenSm && !done && steps && steps.length > 0 && (\n <AnimatedLabel className=\"m-x-1\" steps={steps} activeLabel={activeStep} />\n )}\n </>\n }\n rightContent={\n <div className=\"np-flow-header__right d-flex align-items-center justify-content-end order-2--lg\">\n {newAvatar}\n {newAvatar && closeButton && <span className=\"m-x-1\" />}\n {closeButton}\n </div>\n }\n bottomContent={\n !done && steps && steps.length > 0 ? (\n <Stepper\n activeStep={activeStep}\n steps={steps}\n className={clsx('np-flow-navigation__stepper')}\n />\n ) : null\n }\n layout={!screenLg ? Layout.VERTICAL : Layout.HORIZONTAL}\n />\n );\n\n return (\n <Container\n size=\"fluid\"\n className={clsx('np-flow-navigation', {\n 'np-flow-navigation--border-bottom': showBottomBorder,\n })}\n >\n {flowHeaderContent}\n </Container>\n );\n};\n\nexport default FlowNavigation;\n"],"names":["defaultLogo","_jsx","Logo","FlowNavigation","activeStep","avatar","logo","done","onClose","onGoBack","steps","showBottomBorder","intl","useIntl","screenSm","useScreenSize","Breakpoint","SMALL","screenLg","LARGE","closeButton","CloseButton","size","onClick","newAvatar","displayGoBack","flowHeaderContent","FlowHeader","className","clsx","leftContent","_jsxs","_Fragment","children","IconButton","priority","type","formatMessage","messages","back","ArrowLeft","length","AnimatedLabel","activeLabel","rightContent","bottomContent","Stepper","layout","Layout","VERTICAL","HORIZONTAL","Container"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAMA,WAAW,gBAAGC,GAAA,CAACC,IAAI,KAAG;AAuB5B,MAAMC,cAAc,GAAGA,CAAC;AACtBC,EAAAA,UAAU,GAAG,CAAC;EACdC,MAAM;AACNC,EAAAA,IAAI,GAAGN,WAAW;AAClBO,EAAAA,IAAI,GAAG,KAAK;EACZC,OAAO;EACPC,QAAQ;EACRC,KAAK;AACLC,EAAAA,gBAAgB,GAAG;AAAI,CACH,KAAI;AACxB,EAAA,MAAMC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, key) => Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match);
14
14
  }
15
- function renderNodes(nodes, actions, data, allowLinks) {
16
- return nodes.map((node, index) => renderNode(node, actions, data, allowLinks, index));
15
+ function renderNodes(nodes, onAction, data, allowLinks) {
16
+ return nodes.map((node, index) => renderNode(node, onAction, data, allowLinks, index));
17
17
  }
18
- function renderLinkNode(node, actions, data, allowLinks, key) {
19
- const children = renderNodes(node.children, actions, data, allowLinks);
20
- if (node.action && actions?.[node.action]) {
18
+ function renderLinkNode(node, onAction, data, allowLinks, key) {
19
+ const children = renderNodes(node.children, onAction, data, allowLinks);
20
+ if (node.action && onAction) {
21
+ const actionId = node.action;
21
22
  return (
22
23
  /*#__PURE__*/
23
24
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events
24
25
  jsxRuntime.jsx(Link.default, {
25
26
  "aria-label": node.accessibilityLabel,
26
- onClick: actions[node.action],
27
+ onClick: () => onAction(actionId),
27
28
  children: children
28
29
  }, key)
29
30
  );
@@ -41,7 +42,7 @@ function renderLinkNode(node, actions, data, allowLinks, key) {
41
42
  children: children
42
43
  }, key);
43
44
  }
44
- function renderNode(node, actions, data, allowLinks, key) {
45
+ function renderNode(node, onAction, data, allowLinks, key) {
45
46
  switch (node.type) {
46
47
  case 'text':
47
48
  return /*#__PURE__*/jsxRuntime.jsx(React.Fragment, {
@@ -55,27 +56,27 @@ function renderNode(node, actions, data, allowLinks, key) {
55
56
  return /*#__PURE__*/jsxRuntime.jsx("em", {
56
57
  className: `wds-markup-emphasis wds-markup-emphasis--${node.type}`,
57
58
  "aria-label": node.accessibilityLabel,
58
- children: renderNodes(node.children, actions, data, allowLinks)
59
+ children: renderNodes(node.children, onAction, data, allowLinks)
59
60
  }, key);
60
61
  case 'strong':
61
62
  return /*#__PURE__*/jsxRuntime.jsx("strong", {
62
63
  className: "wds-markup-strong",
63
64
  "aria-label": node.accessibilityLabel,
64
- children: renderNodes(node.children, actions, data, allowLinks)
65
+ children: renderNodes(node.children, onAction, data, allowLinks)
65
66
  }, key);
66
67
  case 'strikethrough':
67
68
  return /*#__PURE__*/jsxRuntime.jsx("del", {
68
69
  className: "wds-markup-strikethrough",
69
70
  "aria-label": node.accessibilityLabel,
70
- children: renderNodes(node.children, actions, data, allowLinks)
71
+ children: renderNodes(node.children, onAction, data, allowLinks)
71
72
  }, key);
72
73
  case 'paragraph':
73
74
  return /*#__PURE__*/jsxRuntime.jsx("p", {
74
75
  className: "wds-markup-paragraph",
75
- children: renderNodes(node.children, actions, data, allowLinks)
76
+ children: renderNodes(node.children, onAction, data, allowLinks)
76
77
  }, key);
77
78
  case 'link':
78
- return renderLinkNode(node, actions, data, allowLinks, key);
79
+ return renderLinkNode(node, onAction, data, allowLinks, key);
79
80
  }
80
81
  }
81
82
  function hasParagraph(nodes) {
@@ -106,7 +107,7 @@ const Markup = ({
106
107
  children,
107
108
  data,
108
109
  allowLinks = 'internal',
109
- actions,
110
+ onAction,
110
111
  as,
111
112
  className,
112
113
  'data-testid': testId
@@ -129,7 +130,7 @@ const Markup = ({
129
130
  return /*#__PURE__*/jsxRuntime.jsx(Element, {
130
131
  className: className,
131
132
  "data-testid": testId,
132
- children: renderNodes(tree, actions, data, allowLinks)
133
+ children: renderNodes(tree, onAction, data, allowLinks)
133
134
  });
134
135
  };
135
136
 
@@ -1 +1 @@
1
- {"version":3,"file":"Markup.js","sources":["../../src/Markup/Markup.tsx"],"sourcesContent":["import React, { Fragment, useMemo } from 'react';\n\nimport Link from '../Link';\n\nimport { parseMarkup } from './utils/parseMarkup';\nimport { type AllowLinksMode, isHrefAllowedByMode, sanitiseHref } from './utils/sanitise';\nimport type { MarkupActions, MarkupNode, MarkupProps } from './Markup.types';\n\nconst PLACEHOLDER_REGEX = /\\{\\{(\\w+)\\}\\}/g;\n\ntype MarkupData = Record<string, string | number>;\n\nfunction substituteData(text: string, data: MarkupData): string {\n return text.replace(PLACEHOLDER_REGEX, (match, key: string) =>\n Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match,\n );\n}\n\nfunction renderNodes(\n nodes: MarkupNode[],\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n): React.ReactNode[] {\n return nodes.map((node, index) => renderNode(node, actions, data, allowLinks, index));\n}\n\nfunction renderLinkNode(\n node: Extract<MarkupNode, { type: 'link' }>,\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n const children = renderNodes(node.children, actions, data, allowLinks);\n\n if (node.action && actions?.[node.action]) {\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <Link key={key} aria-label={node.accessibilityLabel} onClick={actions[node.action]}>\n {children}\n </Link>\n );\n }\n\n const sanitisedHref = node.href ? sanitiseHref(node.href) : undefined;\n if (sanitisedHref && isHrefAllowedByMode(sanitisedHref, allowLinks)) {\n return (\n <Link\n key={key}\n href={sanitisedHref}\n target={node.target}\n aria-label={node.accessibilityLabel}\n >\n {children}\n </Link>\n );\n }\n\n return <Fragment key={key}>{children}</Fragment>;\n}\n\nfunction renderNode(\n node: MarkupNode,\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n switch (node.type) {\n case 'text':\n return (\n <Fragment key={key}>{data ? substituteData(node.content, data) : node.content}</Fragment>\n );\n case 'newline':\n return <br key={key} />;\n case 'important':\n case 'positive':\n case 'negative':\n return (\n <em\n key={key}\n className={`wds-markup-emphasis wds-markup-emphasis--${node.type}`}\n aria-label={node.accessibilityLabel}\n >\n {renderNodes(node.children, actions, data, allowLinks)}\n </em>\n );\n case 'strong':\n return (\n <strong key={key} className=\"wds-markup-strong\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, actions, data, allowLinks)}\n </strong>\n );\n case 'strikethrough':\n return (\n <del key={key} className=\"wds-markup-strikethrough\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, actions, data, allowLinks)}\n </del>\n );\n case 'paragraph':\n return (\n <p key={key} className=\"wds-markup-paragraph\">\n {renderNodes(node.children, actions, data, allowLinks)}\n </p>\n );\n case 'link':\n return renderLinkNode(node, actions, data, allowLinks, key);\n }\n}\n\nfunction hasParagraph(nodes: MarkupNode[]): boolean {\n for (const node of nodes) {\n if (node.type === 'paragraph') {\n return true;\n }\n if ('children' in node && hasParagraph(node.children)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Parses a markup string and renders it as React elements. Supports `<important>`,\n * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),\n * and `<link>` (alias `<a>`) with secure href validation.\n *\n * It only processes `string` input, while `ReactNode` is passed-through without processing.\n *\n * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be\n * eventually deprecated.\n *\n * @see http://storybook.wise.design/?path=/docs/typography-markup--docs\n * @link ../emphasis/Emphasis | Emphasis\n */\nexport const Markup: React.FC<MarkupProps> = ({\n children,\n data,\n allowLinks = 'internal',\n actions,\n as,\n className,\n 'data-testid': testId,\n}) => {\n const tree = useMemo(\n () => (typeof children === 'string' ? parseMarkup(children) : []),\n [children],\n );\n\n if (typeof children !== 'string') {\n if (children == null) {\n return null;\n }\n return (\n <span className={className} data-testid={testId}>\n {children}\n </span>\n );\n }\n\n if (tree.length === 0) {\n return null;\n }\n\n const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');\n\n return (\n <Element className={className} data-testid={testId}>\n {renderNodes(tree, actions, data, allowLinks)}\n </Element>\n );\n};\n\nexport default Markup;\n"],"names":["PLACEHOLDER_REGEX","substituteData","text","data","replace","match","key","Object","prototype","hasOwnProperty","call","String","renderNodes","nodes","actions","allowLinks","map","node","index","renderNode","renderLinkNode","children","action","_jsx","Link","accessibilityLabel","onClick","sanitisedHref","href","sanitiseHref","undefined","isHrefAllowedByMode","target","Fragment","type","content","className","hasParagraph","Markup","as","testId","tree","useMemo","parseMarkup","length","Element"],"mappings":";;;;;;;;;;AAQA,MA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C;EAC5CjB,QAAQ;EACRlB,IAAI;AACJY,EAAAA,UAAU,GAAG,UAAU;EACvBD,OAAO;EACPyB,EAAE;EACFH,SAAS;AACT,EAAA,aAAa,EAAEI;AAAM,CACtB,KAAI;EACH,MAAMC,IAAI,GAAGC,aAAO,CAClB,MAAO,OAAOrB,QAAQ,KAAK,QAAQ,GAAGsB,uBAAW,CAACtB,QAAQ,CAAC,GAAG,EAAG,EACjE,CAACA,QAAQ,CAAC,CACX;AAED,EAAA,IAAI,OAAOA,QAAQ,KAAK,QAAQ,EAAE;IAChC,IAAIA,QAAQ,IAAI,IAAI,EAAE;AACpB,MAAA,OAAO,IAAI;AACb,IAAA;AACA,IAAA,oBACEE,cAAA,CAAA,MAAA,EAAA;AAAMa,MAAAA,SAAS,EAAEA,SAAU;AAAC,MAAA,aAAA,EAAaI,MAAO;AAAAnB,MAAAA,QAAA,EAC7CA;AAAQ,KACL,CAAC;AAEX,EAAA;AAEA,EAAA,IAAIoB,IAAI,CAACG,MAAM,KAAK,CAAC,EAAE;AACrB,IAAA,OAAO,IAAI;AACb,EAAA;AAEA,EAAA,MAAMC,OAAO,GAAGN,EAAE,KAAKF,YAAY,CAACI,IAAI,CAAC,GAAG,KAAK,GAAG,MAAM,CAAC;EAE3D,oBACElB,cAAA,CAACsB,OAAO,EAAA;AAACT,IAAAA,SAAS,EAAEA,SAAU;AAAC,IAAA,aAAA,EAAaI,MAAO;IAAAnB,QAAA,EAChDT,WAAW,CAAC6B,IAAI,EAAE3B,OAAO,EAAEX,IAAI,EAAEY,UAAU;AAAC,GACtC,CAAC;AAEd;;;;;"}
1
+ {"version":3,"file":"Markup.js","sources":["../../src/Markup/Markup.tsx"],"sourcesContent":["import React, { Fragment, useMemo } from 'react';\n\nimport Link from '../Link';\n\nimport { parseMarkup } from './utils/parseMarkup';\nimport { type AllowLinksMode, isHrefAllowedByMode, sanitiseHref } from './utils/sanitise';\nimport type { MarkupActionHandler, MarkupNode, MarkupProps } from './Markup.types';\n\nconst PLACEHOLDER_REGEX = /\\{\\{(\\w+)\\}\\}/g;\n\ntype MarkupData = Record<string, string | number>;\n\nfunction substituteData(text: string, data: MarkupData): string {\n return text.replace(PLACEHOLDER_REGEX, (match, key: string) =>\n Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match,\n );\n}\n\ntype OnAction = MarkupActionHandler | undefined;\n\nfunction renderNodes(\n nodes: MarkupNode[],\n onAction: OnAction,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n): React.ReactNode[] {\n return nodes.map((node, index) => renderNode(node, onAction, data, allowLinks, index));\n}\n\nfunction renderLinkNode(\n node: Extract<MarkupNode, { type: 'link' }>,\n onAction: OnAction,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n const children = renderNodes(node.children, onAction, data, allowLinks);\n\n if (node.action && onAction) {\n const actionId = node.action;\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <Link key={key} aria-label={node.accessibilityLabel} onClick={() => onAction(actionId)}>\n {children}\n </Link>\n );\n }\n\n const sanitisedHref = node.href ? sanitiseHref(node.href) : undefined;\n if (sanitisedHref && isHrefAllowedByMode(sanitisedHref, allowLinks)) {\n return (\n <Link\n key={key}\n href={sanitisedHref}\n target={node.target}\n aria-label={node.accessibilityLabel}\n >\n {children}\n </Link>\n );\n }\n\n return <Fragment key={key}>{children}</Fragment>;\n}\n\nfunction renderNode(\n node: MarkupNode,\n onAction: OnAction,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n switch (node.type) {\n case 'text':\n return (\n <Fragment key={key}>{data ? substituteData(node.content, data) : node.content}</Fragment>\n );\n case 'newline':\n return <br key={key} />;\n case 'important':\n case 'positive':\n case 'negative':\n return (\n <em\n key={key}\n className={`wds-markup-emphasis wds-markup-emphasis--${node.type}`}\n aria-label={node.accessibilityLabel}\n >\n {renderNodes(node.children, onAction, data, allowLinks)}\n </em>\n );\n case 'strong':\n return (\n <strong key={key} className=\"wds-markup-strong\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, onAction, data, allowLinks)}\n </strong>\n );\n case 'strikethrough':\n return (\n <del key={key} className=\"wds-markup-strikethrough\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, onAction, data, allowLinks)}\n </del>\n );\n case 'paragraph':\n return (\n <p key={key} className=\"wds-markup-paragraph\">\n {renderNodes(node.children, onAction, data, allowLinks)}\n </p>\n );\n case 'link':\n return renderLinkNode(node, onAction, data, allowLinks, key);\n }\n}\n\nfunction hasParagraph(nodes: MarkupNode[]): boolean {\n for (const node of nodes) {\n if (node.type === 'paragraph') {\n return true;\n }\n if ('children' in node && hasParagraph(node.children)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Parses a markup string and renders it as React elements. Supports `<important>`,\n * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),\n * and `<link>` (alias `<a>`) with secure href validation.\n *\n * It only processes `string` input, while `ReactNode` is passed-through without processing.\n *\n * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be\n * eventually deprecated.\n *\n * @see http://storybook.wise.design/?path=/docs/typography-markup--docs\n * @link ../emphasis/Emphasis | Emphasis\n */\nexport const Markup: React.FC<MarkupProps> = ({\n children,\n data,\n allowLinks = 'internal',\n onAction,\n as,\n className,\n 'data-testid': testId,\n}) => {\n const tree = useMemo(\n () => (typeof children === 'string' ? parseMarkup(children) : []),\n [children],\n );\n\n if (typeof children !== 'string') {\n if (children == null) {\n return null;\n }\n return (\n <span className={className} data-testid={testId}>\n {children}\n </span>\n );\n }\n\n if (tree.length === 0) {\n return null;\n }\n\n const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');\n\n return (\n <Element className={className} data-testid={testId}>\n {renderNodes(tree, onAction, data, allowLinks)}\n </Element>\n );\n};\n\nexport default Markup;\n"],"names":["PLACEHOLDER_REGEX","substituteData","text","data","replace","match","key","Object","prototype","hasOwnProperty","call","String","renderNodes","nodes","onAction","allowLinks","map","node","index","renderNode","renderLinkNode","children","action","actionId","_jsx","Link","accessibilityLabel","onClick","sanitisedHref","href","sanitiseHref","undefined","isHrefAllowedByMode","target","Fragment","type","content","className","hasParagraph","Markup","as","testId","tree","useMemo","parseMarkup","length","Element"],"mappings":";;;;;;;;;;AAQA,MAAMA,iBAAiB,GAAG,gBAAgB;AAI1C,SAASC,cAAcA,CAACC,IAAY,EAAEC,IAAgB,EAAA;AACpD,EAAA,OAAOD,IAAI,CAACE,OAAO,CAACJ,iBAAiB,EAAE,CAACK,KAAK,EAAEC,GAAW,KACxDC,MAAM,CAACC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACP,IAAI,EAAEG,GAAG,CAAC,GAAGK,MAAM,CAACR,IAAI,CAACG,GAAG,CAAC,CAAC,GAAGD,KAAK,CAC5E;AACH;AAIA,SAASO,WAAWA,CAClBC,KAAmB,EACnBC,QAAkB,EAClBX,IAA4B,EAC5BY,UAA0B,EAAA;EAE1B,OAAOF,KAAK,CAACG,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAKC,UAAU,CAACF,IAAI,EAAEH,QAAQ,EAAEX,IAAI,EAAEY,UAAU,EAAEG,KAAK,CAAC,CAAC;AACxF;AAEA,SAASE,cAAcA,CACrBH,IAA2C,EAC3CH,QAAkB,EAClBX,IAA4B,EAC5BY,UAA0B,EAC1BT,GAAW,EAAA;AAEX,EAAA,MAAMe,QAAQ,GAAGT,WAAW,CAACK,IAAI,CAACI,QAAQ,EAAEP,QAAQ,EAAEX,IAAI,EAAEY,UAAU,CAAC;AAEvE,EAAA,IAAIE,IAAI,CAACK,MAAM,IAAIR,QAAQ,EAAE;AAC3B,IAAA,MAAMS,QAAQ,GAAGN,IAAI,CAACK,MAAM;AAC5B,IAAA;AAAA;AACE;AACAE,MAAAA,cAAA,CAACC,YAAI,EAAA;QAAW,YAAA,EAAYR,IAAI,CAACS,kBAAmB;AAACC,QAAAA,OAAO,EAAEA,MAA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8,18 +8,19 @@ const PLACEHOLDER_REGEX = /\{\{(\w+)\}\}/g;
8
8
  function substituteData(text, data) {
9
9
  return text.replace(PLACEHOLDER_REGEX, (match, key) => Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match);
10
10
  }
11
- function renderNodes(nodes, actions, data, allowLinks) {
12
- return nodes.map((node, index) => renderNode(node, actions, data, allowLinks, index));
11
+ function renderNodes(nodes, onAction, data, allowLinks) {
12
+ return nodes.map((node, index) => renderNode(node, onAction, data, allowLinks, index));
13
13
  }
14
- function renderLinkNode(node, actions, data, allowLinks, key) {
15
- const children = renderNodes(node.children, actions, data, allowLinks);
16
- if (node.action && actions?.[node.action]) {
14
+ function renderLinkNode(node, onAction, data, allowLinks, key) {
15
+ const children = renderNodes(node.children, onAction, data, allowLinks);
16
+ if (node.action && onAction) {
17
+ const actionId = node.action;
17
18
  return (
18
19
  /*#__PURE__*/
19
20
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events
20
21
  jsx(Link, {
21
22
  "aria-label": node.accessibilityLabel,
22
- onClick: actions[node.action],
23
+ onClick: () => onAction(actionId),
23
24
  children: children
24
25
  }, key)
25
26
  );
@@ -37,7 +38,7 @@ function renderLinkNode(node, actions, data, allowLinks, key) {
37
38
  children: children
38
39
  }, key);
39
40
  }
40
- function renderNode(node, actions, data, allowLinks, key) {
41
+ function renderNode(node, onAction, data, allowLinks, key) {
41
42
  switch (node.type) {
42
43
  case 'text':
43
44
  return /*#__PURE__*/jsx(Fragment, {
@@ -51,27 +52,27 @@ function renderNode(node, actions, data, allowLinks, key) {
51
52
  return /*#__PURE__*/jsx("em", {
52
53
  className: `wds-markup-emphasis wds-markup-emphasis--${node.type}`,
53
54
  "aria-label": node.accessibilityLabel,
54
- children: renderNodes(node.children, actions, data, allowLinks)
55
+ children: renderNodes(node.children, onAction, data, allowLinks)
55
56
  }, key);
56
57
  case 'strong':
57
58
  return /*#__PURE__*/jsx("strong", {
58
59
  className: "wds-markup-strong",
59
60
  "aria-label": node.accessibilityLabel,
60
- children: renderNodes(node.children, actions, data, allowLinks)
61
+ children: renderNodes(node.children, onAction, data, allowLinks)
61
62
  }, key);
62
63
  case 'strikethrough':
63
64
  return /*#__PURE__*/jsx("del", {
64
65
  className: "wds-markup-strikethrough",
65
66
  "aria-label": node.accessibilityLabel,
66
- children: renderNodes(node.children, actions, data, allowLinks)
67
+ children: renderNodes(node.children, onAction, data, allowLinks)
67
68
  }, key);
68
69
  case 'paragraph':
69
70
  return /*#__PURE__*/jsx("p", {
70
71
  className: "wds-markup-paragraph",
71
- children: renderNodes(node.children, actions, data, allowLinks)
72
+ children: renderNodes(node.children, onAction, data, allowLinks)
72
73
  }, key);
73
74
  case 'link':
74
- return renderLinkNode(node, actions, data, allowLinks, key);
75
+ return renderLinkNode(node, onAction, data, allowLinks, key);
75
76
  }
76
77
  }
77
78
  function hasParagraph(nodes) {
@@ -102,7 +103,7 @@ const Markup = ({
102
103
  children,
103
104
  data,
104
105
  allowLinks = 'internal',
105
- actions,
106
+ onAction,
106
107
  as,
107
108
  className,
108
109
  'data-testid': testId
@@ -125,7 +126,7 @@ const Markup = ({
125
126
  return /*#__PURE__*/jsx(Element, {
126
127
  className: className,
127
128
  "data-testid": testId,
128
- children: renderNodes(tree, actions, data, allowLinks)
129
+ children: renderNodes(tree, onAction, data, allowLinks)
129
130
  });
130
131
  };
131
132
 
@@ -1 +1 @@
1
- {"version":3,"file":"Markup.mjs","sources":["../../src/Markup/Markup.tsx"],"sourcesContent":["import React, { Fragment, useMemo } from 'react';\n\nimport Link from '../Link';\n\nimport { parseMarkup } from './utils/parseMarkup';\nimport { type AllowLinksMode, isHrefAllowedByMode, sanitiseHref } from './utils/sanitise';\nimport type { MarkupActions, MarkupNode, MarkupProps } from './Markup.types';\n\nconst PLACEHOLDER_REGEX = /\\{\\{(\\w+)\\}\\}/g;\n\ntype MarkupData = Record<string, string | number>;\n\nfunction substituteData(text: string, data: MarkupData): string {\n return text.replace(PLACEHOLDER_REGEX, (match, key: string) =>\n Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match,\n );\n}\n\nfunction renderNodes(\n nodes: MarkupNode[],\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n): React.ReactNode[] {\n return nodes.map((node, index) => renderNode(node, actions, data, allowLinks, index));\n}\n\nfunction renderLinkNode(\n node: Extract<MarkupNode, { type: 'link' }>,\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n const children = renderNodes(node.children, actions, data, allowLinks);\n\n if (node.action && actions?.[node.action]) {\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <Link key={key} aria-label={node.accessibilityLabel} onClick={actions[node.action]}>\n {children}\n </Link>\n );\n }\n\n const sanitisedHref = node.href ? sanitiseHref(node.href) : undefined;\n if (sanitisedHref && isHrefAllowedByMode(sanitisedHref, allowLinks)) {\n return (\n <Link\n key={key}\n href={sanitisedHref}\n target={node.target}\n aria-label={node.accessibilityLabel}\n >\n {children}\n </Link>\n );\n }\n\n return <Fragment key={key}>{children}</Fragment>;\n}\n\nfunction renderNode(\n node: MarkupNode,\n actions: MarkupActions | undefined,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n switch (node.type) {\n case 'text':\n return (\n <Fragment key={key}>{data ? substituteData(node.content, data) : node.content}</Fragment>\n );\n case 'newline':\n return <br key={key} />;\n case 'important':\n case 'positive':\n case 'negative':\n return (\n <em\n key={key}\n className={`wds-markup-emphasis wds-markup-emphasis--${node.type}`}\n aria-label={node.accessibilityLabel}\n >\n {renderNodes(node.children, actions, data, allowLinks)}\n </em>\n );\n case 'strong':\n return (\n <strong key={key} className=\"wds-markup-strong\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, actions, data, allowLinks)}\n </strong>\n );\n case 'strikethrough':\n return (\n <del key={key} className=\"wds-markup-strikethrough\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, actions, data, allowLinks)}\n </del>\n );\n case 'paragraph':\n return (\n <p key={key} className=\"wds-markup-paragraph\">\n {renderNodes(node.children, actions, data, allowLinks)}\n </p>\n );\n case 'link':\n return renderLinkNode(node, actions, data, allowLinks, key);\n }\n}\n\nfunction hasParagraph(nodes: MarkupNode[]): boolean {\n for (const node of nodes) {\n if (node.type === 'paragraph') {\n return true;\n }\n if ('children' in node && hasParagraph(node.children)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Parses a markup string and renders it as React elements. Supports `<important>`,\n * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),\n * and `<link>` (alias `<a>`) with secure href validation.\n *\n * It only processes `string` input, while `ReactNode` is passed-through without processing.\n *\n * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be\n * eventually deprecated.\n *\n * @see http://storybook.wise.design/?path=/docs/typography-markup--docs\n * @link ../emphasis/Emphasis | Emphasis\n */\nexport const Markup: React.FC<MarkupProps> = ({\n children,\n data,\n allowLinks = 'internal',\n actions,\n as,\n className,\n 'data-testid': testId,\n}) => {\n const tree = useMemo(\n () => (typeof children === 'string' ? parseMarkup(children) : []),\n [children],\n );\n\n if (typeof children !== 'string') {\n if (children == null) {\n return null;\n }\n return (\n <span className={className} data-testid={testId}>\n {children}\n </span>\n );\n }\n\n if (tree.length === 0) {\n return null;\n }\n\n const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');\n\n return (\n <Element className={className} data-testid={testId}>\n {renderNodes(tree, actions, data, allowLinks)}\n </Element>\n );\n};\n\nexport default Markup;\n"],"names":["PLACEHOLDER_REGEX","substituteData","text","data","replace","match","key","Object","prototype","hasOwnProperty","call","String","renderNodes","nodes","actions","allowLinks","map","node","index","renderNode","renderLinkNode","children","action","_jsx","Link","accessibilityLabel","onClick","sanitisedHref","href","sanitiseHref","undefined","isHrefAllowedByMode","target","Fragment","type","content","className","hasParagraph","Markup","as","testId","tree","useMemo","parse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G;AACI,MAAMiB,MAAM,GAA0BA,CAAC;EAC5CjB,QAAQ;EACRlB,IAAI;AACJY,EAAAA,UAAU,GAAG,UAAU;EACvBD,OAAO;EACPyB,EAAE;EACFH,SAAS;AACT,EAAA,aAAa,EAAEI;AAAM,CACtB,KAAI;EACH,MAAMC,IAAI,GAAGC,OAAO,CAClB,MAAO,OAAOrB,QAAQ,KAAK,QAAQ,GAAGsB,WAAW,CAACtB,QAAQ,CAAC,GAAG,EAAG,EACjE,CAACA,QAAQ,CAAC,CACX;AAED,EAAA,IAAI,OAAOA,QAAQ,KAAK,QAAQ,EAAE;IAChC,IAAIA,QAAQ,IAAI,IAAI,EAAE;AACpB,MAAA,OAAO,IAAI;AACb,IAAA;AACA,IAAA,oBACEE,GAAA,CAAA,MAAA,EAAA;AAAMa,MAAAA,SAAS,EAAEA,SAAU;AAAC,MAAA,aAAA,EAAaI,MAAO;AAAAnB,MAAAA,QAAA,EAC7CA;AAAQ,KACL,CAAC;AAEX,EAAA;AAEA,EAAA,IAAIoB,IAAI,CAACG,MAAM,KAAK,CAAC,EAAE;AACrB,IAAA,OAAO,IAAI;AACb,EAAA;AAEA,EAAA,MAAMC,OAAO,GAAGN,EAAE,KAAKF,YAAY,CAACI,IAAI,CAAC,GAAG,KAAK,GAAG,MAAM,CAAC;EAE3D,oBACElB,GAAA,CAACsB,OAAO,EAAA;AAACT,IAAAA,SAAS,EAAEA,SAAU;AAAC,IAAA,aAAA,EAAaI,MAAO;IAAAnB,QAAA,EAChDT,WAAW,CAAC6B,IAAI,EAAE3B,OAAO,EAAEX,IAAI,EAAEY,UAAU;AAAC,GACtC,CAAC;AAEd;;;;"}
1
+ {"version":3,"file":"Markup.mjs","sources":["../../src/Markup/Markup.tsx"],"sourcesContent":["import React, { Fragment, useMemo } from 'react';\n\nimport Link from '../Link';\n\nimport { parseMarkup } from './utils/parseMarkup';\nimport { type AllowLinksMode, isHrefAllowedByMode, sanitiseHref } from './utils/sanitise';\nimport type { MarkupActionHandler, MarkupNode, MarkupProps } from './Markup.types';\n\nconst PLACEHOLDER_REGEX = /\\{\\{(\\w+)\\}\\}/g;\n\ntype MarkupData = Record<string, string | number>;\n\nfunction substituteData(text: string, data: MarkupData): string {\n return text.replace(PLACEHOLDER_REGEX, (match, key: string) =>\n Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match,\n );\n}\n\ntype OnAction = MarkupActionHandler | undefined;\n\nfunction renderNodes(\n nodes: MarkupNode[],\n onAction: OnAction,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n): React.ReactNode[] {\n return nodes.map((node, index) => renderNode(node, onAction, data, allowLinks, index));\n}\n\nfunction renderLinkNode(\n node: Extract<MarkupNode, { type: 'link' }>,\n onAction: OnAction,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n const children = renderNodes(node.children, onAction, data, allowLinks);\n\n if (node.action && onAction) {\n const actionId = node.action;\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events\n <Link key={key} aria-label={node.accessibilityLabel} onClick={() => onAction(actionId)}>\n {children}\n </Link>\n );\n }\n\n const sanitisedHref = node.href ? sanitiseHref(node.href) : undefined;\n if (sanitisedHref && isHrefAllowedByMode(sanitisedHref, allowLinks)) {\n return (\n <Link\n key={key}\n href={sanitisedHref}\n target={node.target}\n aria-label={node.accessibilityLabel}\n >\n {children}\n </Link>\n );\n }\n\n return <Fragment key={key}>{children}</Fragment>;\n}\n\nfunction renderNode(\n node: MarkupNode,\n onAction: OnAction,\n data: MarkupData | undefined,\n allowLinks: AllowLinksMode,\n key: number,\n): React.ReactNode {\n switch (node.type) {\n case 'text':\n return (\n <Fragment key={key}>{data ? substituteData(node.content, data) : node.content}</Fragment>\n );\n case 'newline':\n return <br key={key} />;\n case 'important':\n case 'positive':\n case 'negative':\n return (\n <em\n key={key}\n className={`wds-markup-emphasis wds-markup-emphasis--${node.type}`}\n aria-label={node.accessibilityLabel}\n >\n {renderNodes(node.children, onAction, data, allowLinks)}\n </em>\n );\n case 'strong':\n return (\n <strong key={key} className=\"wds-markup-strong\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, onAction, data, allowLinks)}\n </strong>\n );\n case 'strikethrough':\n return (\n <del key={key} className=\"wds-markup-strikethrough\" aria-label={node.accessibilityLabel}>\n {renderNodes(node.children, onAction, data, allowLinks)}\n </del>\n );\n case 'paragraph':\n return (\n <p key={key} className=\"wds-markup-paragraph\">\n {renderNodes(node.children, onAction, data, allowLinks)}\n </p>\n );\n case 'link':\n return renderLinkNode(node, onAction, data, allowLinks, key);\n }\n}\n\nfunction hasParagraph(nodes: MarkupNode[]): boolean {\n for (const node of nodes) {\n if (node.type === 'paragraph') {\n return true;\n }\n if ('children' in node && hasParagraph(node.children)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Parses a markup string and renders it as React elements. Supports `<important>`,\n * `<positive>`, `<negative>`, `<strong>`, `<strikethrough>`, `<paragraph>` (alias `<p>`),\n * and `<link>` (alias `<a>`) with secure href validation.\n *\n * It only processes `string` input, while `ReactNode` is passed-through without processing.\n *\n * > The component supersedes [Emphasis](?path=/docs/typography-emphasis--docs), which will be\n * eventually deprecated.\n *\n * @see http://storybook.wise.design/?path=/docs/typography-markup--docs\n * @link ../emphasis/Emphasis | Emphasis\n */\nexport const Markup: React.FC<MarkupProps> = ({\n children,\n data,\n allowLinks = 'internal',\n onAction,\n as,\n className,\n 'data-testid': testId,\n}) => {\n const tree = useMemo(\n () => (typeof children === 'string' ? parseMarkup(children) : []),\n [children],\n );\n\n if (typeof children !== 'string') {\n if (children == null) {\n return null;\n }\n return (\n <span className={className} data-testid={testId}>\n {children}\n </span>\n );\n }\n\n if (tree.length === 0) {\n return null;\n }\n\n const Element = as ?? (hasParagraph(tree) ? 'div' : 'span');\n\n return (\n <Element className={className} data-testid={testId}>\n {renderNodes(tree, onAction, data, allowLinks)}\n </Element>\n );\n};\n\nexport default Markup;\n"],"names":["PLACEHOLDER_REGEX","substituteData","text","data","replace","match","key","Object","prototype","hasOwnProperty","call","String","renderNodes","nodes","onAction","allowLinks","map","node","index","renderNode","renderLinkNode","children","action","actionId","_jsx","Link","accessibilityLabel","onClick","sanitisedHref","href","sanitiseHref","undefined","isHrefAllowedByMode","target","Fragment","type","content","className","hasParagraph","Markup","as","testId","tree","useMemo","parseMarkup","length","Element"],"mappings":";;;;;;AAQA,MAAMA,iBAAiB,GAAG,gBAAgB;AAI1C,SAASC,cAAcA,CAACC,IAAY,EAAEC,IAAgB,EAAA;AACpD,EAAA,OAAOD,IAAI,CAACE,OAAO,CAACJ,iBAAiB,EAAE,CAACK,KAAK,EAAEC,GAAW,KACxDC,MAAM,CAACC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACP,IAAI,EAAEG,GAAG,CAAC,GAAGK,MAAM,CAACR,IAAI,CAACG,GAAG,CAAC,CAAC,GAAGD,KAAK,CAC5E;AACH;AAIA,SAASO,WAAWA,CAClBC,KAAmB,EACnBC,QAAkB,EAClBX,IAA4B,EAC5BY,UAA0B,EAAA;EAE1B,OAAOF,KAAK,CAACG,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAKC,UAAU,CAACF,IAAI,EAAEH,QAAQ,EAAEX,IAAI,EAAEY,UAAU,EAAEG,KAAK,CAAC,CAAC;AACxF;AAEA,SAASE,cAAcA,CACrBH,IAA2C,EAC3CH,QAAkB,EAClBX,IAA4B,EAC5BY,UAA0B,EAC1BT,GAAW,EAAA;AAEX,EAAA,MAAMe,QAAQ,GAAGT,WAAW,CAACK,IAAI,CAACI,QAAQ,EAAEP,QAAQ,EAAEX,IAAI,EAAEY,UAAU,CAAC;AAEvE,EAAA,IAAIE,IAAI,CAACK,MAAM,IAAIR,QAAQ,EAAE;AAC3B,IAAA,MAAMS,QAAQ,GAAGN,IAAI,CAACK,MAAM;AAC5B,IAAA;AAAA;AACE;AACAE,MAAAA,GAAA,CAACC,IAAI,EAAA;QAAW,YAAA,EAAYR,IAAI,CAACS,kBAAmB;A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,CAAC;AAEd;;;;"}
@@ -34,11 +34,15 @@ var logActionRequired = require('../utilities/logActionRequired.js');
34
34
 
35
35
  function resolvePlacement(preferredPlacement) {
36
36
  switch (preferredPlacement) {
37
+ case 'top-left':
38
+ case 'top-right':
37
39
  case 'left-top':
38
40
  case 'right-top':
39
41
  return 'top';
40
42
  case 'bottom-left':
41
43
  case 'bottom-right':
44
+ case 'left-bottom':
45
+ case 'right-bottom':
42
46
  return 'bottom';
43
47
  default:
44
48
  return preferredPlacement;
@@ -1 +1 @@
1
- {"version":3,"file":"Popover.js","sources":["../../src/Popover/Popover.tsx"],"sourcesContent":["import { useTheme } from '@wise/components-theming';\nimport { clsx } from 'clsx';\nimport { useRef, useState, cloneElement, useEffect, isValidElement, useId } from 'react';\n\nimport { Position, Typography } from '../common';\nimport ResponsivePanel from '../common/ResponsivePanel';\nimport Title from '../Title';\nimport { logActionRequired } from '../utilities';\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype PopoverPreferredPlacementDeprecated =\n | `${Position.LEFT_TOP}`\n | `${Position.RIGHT_TOP}`\n | `${Position.BOTTOM_RIGHT}`\n | `${Position.BOTTOM_LEFT}`;\n\nexport type PopoverPreferredPlacement =\n | `${Position.TOP}`\n | `${Position.RIGHT}`\n | `${Position.BOTTOM}`\n | `${Position.LEFT}`\n | PopoverPreferredPlacementDeprecated;\n\nexport interface PopoverProps {\n children?: React.ReactNode;\n title?: React.ReactNode;\n /** Screen-reader-friendly title. Must be provided if `title` prop is not set. */\n 'aria-label'?: string;\n /** @default 'right' */\n preferredPlacement?: PopoverPreferredPlacement;\n content: React.ReactNode;\n onClose?: () => void;\n className?: string;\n}\n\nfunction resolvePlacement(preferredPlacement: PopoverPreferredPlacement) {\n switch (preferredPlacement) {\n case 'left-top':\n case 'right-top':\n return 'top';\n case 'bottom-left':\n case 'bottom-right':\n return 'bottom';\n default:\n return preferredPlacement;\n }\n}\n\nexport default function Popover({\n children,\n className,\n content,\n preferredPlacement = Position.RIGHT,\n title,\n onClose,\n 'aria-label': ariaLabel,\n}: PopoverProps) {\n const titleId = useId();\n\n const resolvedPlacement = resolvePlacement(preferredPlacement);\n useEffect(() => {\n if (resolvedPlacement !== preferredPlacement) {\n logActionRequired(\n `Popover has deprecated ${preferredPlacement} value for the 'preferredPlacement' prop. Please use ${resolvedPlacement} instead.`,\n );\n }\n }, [preferredPlacement, resolvedPlacement]);\n\n const anchorReference = useRef(null);\n const [open, setOpen] = useState(false);\n\n const handleOnClose = () => {\n setOpen(false);\n onClose?.();\n };\n\n return (\n <span className=\"np-popover\">\n <span ref={anchorReference} className=\"d-inline-block\">\n {isValidElement<{ onClick?: () => void }>(children)\n ? cloneElement(children, {\n onClick: () => {\n children.props.onClick?.();\n setOpen((prevOpen) => !prevOpen);\n },\n })\n : children}\n </span>\n <ResponsivePanel\n aria-label={ariaLabel}\n aria-labelledby={title && !ariaLabel ? titleId : undefined}\n open={open}\n anchorRef={anchorReference}\n position={resolvedPlacement}\n arrow\n className={clsx('np-popover__container', className)}\n onClose={handleOnClose}\n >\n <div className=\"np-popover__content np-text-default-body\">\n {title && (\n <Title type={Typography.TITLE_BODY} id={titleId} className=\"m-b-1\">\n {title}\n </Title>\n )}\n {content}\n </div>\n </ResponsivePanel>\n </span>\n );\n}\n"],"names":["resolvePlacement","preferredPlacement","Popover","children","className","content","Position","RIGHT","title","onClose","ariaLabel","titleId","useId","resolvedPlacement","useEffect","logActionRequired","anchorReference","useRef","open","setOpen","useState","handleOnClose","_jsxs","_jsx","ref","isValidElement","cloneElement","onClick","props","prevOpen","ResponsivePanel","undefined","anchorRef","position","arrow","clsx","Title","type","Typography","TITLE_BODY","id"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAASA,gBAAgBA,CAACC,kBAA6C,EAAA;AACrE,EAAA,QAAQA,kBAAkB;AACxB,IAAA,KAAK,UAAU;AACf,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,KAAK;AACd,IAAA,KA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AAK,CAACD,OAAO,IAAI;AAC1BR,UAAAA,OAAO,CAAEU,QAAQ,IAAK,CAACA,QAAQ,CAAC;AAClC,QAAA;OACD,CAAC,GACF1B;AAAQ,KACR,CACN,eAAAoB,cAAA,CAACO,uBAAe,EAAA;AACd,MAAA,YAAA,EAAYpB,SAAU;AACtB,MAAA,iBAAA,EAAiBF,KAAK,IAAI,CAACE,SAAS,GAAGC,OAAO,GAAGoB,SAAU;AAC3Db,MAAAA,IAAI,EAAEA,IAAK;AACXc,MAAAA,SAAS,EAAEhB,eAAgB;AAC3BiB,MAAAA,QAAQ,EAAEpB,iBAAkB;MAC5BqB,KAAK,EAAA,IAAA;AACL9B,MAAAA,SAAS,EAAE+B,SAAI,CAAC,uBAAuB,EAAE/B,SAAS,CAAE;AACpDK,MAAAA,OAAO,EAAEY,aAAc;AAAAlB,MAAAA,QAAA,eAEvBmB,eAAA,CAAA,KAAA,EAAA;AAAKlB,QAAAA,SAAS,EAAC,0CAA0C;AAAAD,QAAAA,QAAA,EAAA,CACtDK,KAAK,iBACJe,cAAA,CAACa,aAAK,EAAA;UAACC,IAAI,EAAEC,qBAAU,CAACC,UAAW;AAACC,UAAAA,EAAE,EAAE7B,OAAQ;AAACP,UAAAA,SAAS,EAAC,OAAO;AAAAD,UAAAA,QAAA,EAC/DK;SACI,CACR,EACAH,OAAO;OACL;AACP,KAAiB,CACnB;AAAA,GAAM,CAAC;AAEX;;;;"}
1
+ {"version":3,"file":"Popover.js","sources":["../../src/Popover/Popover.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useRef, useState, cloneElement, useEffect, isValidElement, useId } from 'react';\n\nimport { Position, Typography } from '../common';\nimport ResponsivePanel from '../common/ResponsivePanel';\nimport Title from '../Title';\nimport { logActionRequired } from '../utilities';\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype PopoverPreferredPlacementDeprecated =\n | `${Position.TOP_LEFT}`\n | `${Position.TOP_RIGHT}`\n | `${Position.LEFT_TOP}`\n | `${Position.RIGHT_TOP}`\n | `${Position.BOTTOM_RIGHT}`\n | `${Position.BOTTOM_LEFT}`\n | `${Position.LEFT_BOTTOM}`\n | `${Position.RIGHT_BOTTOM}`;\n\nexport type PopoverPreferredPlacement =\n | `${Position.TOP}`\n | `${Position.RIGHT}`\n | `${Position.BOTTOM}`\n | `${Position.LEFT}`\n | PopoverPreferredPlacementDeprecated;\n\nexport interface PopoverProps {\n children?: React.ReactNode;\n title?: React.ReactNode;\n /** Screen-reader-friendly title. Must be provided if `title` prop is not set. */\n 'aria-label'?: string;\n /** @default 'right' */\n preferredPlacement?: PopoverPreferredPlacement;\n content: React.ReactNode;\n onClose?: () => void;\n className?: string;\n}\n\nfunction resolvePlacement(preferredPlacement: PopoverPreferredPlacement) {\n switch (preferredPlacement) {\n case 'top-left':\n case 'top-right':\n case 'left-top':\n case 'right-top':\n return 'top';\n case 'bottom-left':\n case 'bottom-right':\n case 'left-bottom':\n case 'right-bottom':\n return 'bottom';\n default:\n return preferredPlacement;\n }\n}\n\nexport default function Popover({\n children,\n className,\n content,\n preferredPlacement = Position.RIGHT,\n title,\n onClose,\n 'aria-label': ariaLabel,\n}: PopoverProps) {\n const titleId = useId();\n\n const resolvedPlacement = resolvePlacement(preferredPlacement);\n useEffect(() => {\n if (resolvedPlacement !== preferredPlacement) {\n logActionRequired(\n `Popover has deprecated ${preferredPlacement} value for the 'preferredPlacement' prop. Please use ${resolvedPlacement} instead.`,\n );\n }\n }, [preferredPlacement, resolvedPlacement]);\n\n const anchorReference = useRef(null);\n const [open, setOpen] = useState(false);\n\n const handleOnClose = () => {\n setOpen(false);\n onClose?.();\n };\n\n return (\n <span className=\"np-popover\">\n <span ref={anchorReference} className=\"d-inline-block\">\n {isValidElement<{ onClick?: () => void }>(children)\n ? cloneElement(children, {\n onClick: () => {\n children.props.onClick?.();\n setOpen((prevOpen) => !prevOpen);\n },\n })\n : children}\n </span>\n <ResponsivePanel\n aria-label={ariaLabel}\n aria-labelledby={title && !ariaLabel ? titleId : undefined}\n open={open}\n anchorRef={anchorReference}\n position={resolvedPlacement}\n arrow\n className={clsx('np-popover__container', className)}\n onClose={handleOnClose}\n >\n <div className=\"np-popover__content np-text-default-body\">\n {title && (\n <Title type={Typography.TITLE_BODY} id={titleId} className=\"m-b-1\">\n {title}\n </Title>\n )}\n {content}\n </div>\n </ResponsivePanel>\n </span>\n );\n}\n"],"names":["resolvePlacement","preferredPlacement","Popover","children","className","content","Position","RIGHT","title","onClose","ariaLabel","titleId","useId","resolvedPlacement","useEffect","logActionRequired","anchorReference","useRef","open","setOpen","useState","handleOnClose","_jsxs","_jsx","ref","isValidElement","cloneElement","onClick","props","prevOpen","ResponsivePanel","undefined","anchorRef","position","arrow","clsx","Title","type","Typography","TITLE_BODY","id"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAASA,gBAAgBA,CAACC,kBAA6C,EAAA;AACrE,EAAA,QAAQA,kBAAkB;AACxB,IAAA,KAAK,UAAU;AACf,IAAA,KAAK,WAAW;AAChB,IAAA,KAAK,UAAU;AACf,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,KAAK;AACd,IAAA,KAAK,aAAa;AAClB,IAAA,KAAK,cAAc;AACnB,IAAA,KAAK,aAAa;AAClB,IAAA,KAAK,cAAc;AACjB,MAAA,OAAO,QAAQ;AACjB,IAAA;AACE,MAAA,OAAOA,kBAAkB;AAC7B;AACF;AAEc,SAAUC,OAAOA,CAAC;EAC9BC,QAAQ;EACRC,SAAS;EACTC,OAAO;EACPJ,kBAAkB,GAAGK,iBAAQ,CAACC,KAAK;EACnCC,KAAK;EACLC,OAAO;AACP,EAAA,YAAY,EAAEC;AAAS,CACV,EAAA;AACb,EAAA,MAAMC,OAAO,GAAGC,WAAK,EAAE;AAEvB,EAAA,MAAMC,iBAAiB,GAAGb,gBAAgB,CAACC,kBAAkB,CAAC;AAC9Da,EAAAA,eAAS,CAAC,MAAK;IACb,IAAID,iBAAiB,KAAKZ,k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BAAuB,EAAE/B,SAAS,CAAE;AACpDK,MAAAA,OAAO,EAAEY,aAAc;AAAAlB,MAAAA,QAAA,eAEvBmB,eAAA,CAAA,KAAA,EAAA;AAAKlB,QAAAA,SAAS,EAAC,0CAA0C;AAAAD,QAAAA,QAAA,EAAA,CACtDK,KAAK,iBACJe,cAAA,CAACa,aAAK,EAAA;UAACC,IAAI,EAAEC,qBAAU,CAACC,UAAW;AAACC,UAAAA,EAAE,EAAE7B,OAAQ;AAACP,UAAAA,SAAS,EAAC,OAAO;AAAAD,UAAAA,QAAA,EAC/DK;SACI,CACR,EACAH,OAAO;OACL;AACP,KAAiB,CACnB;AAAA,GAAM,CAAC;AAEX;;;;"}
@@ -30,11 +30,15 @@ import { logActionRequired } from '../utilities/logActionRequired.mjs';
30
30
 
31
31
  function resolvePlacement(preferredPlacement) {
32
32
  switch (preferredPlacement) {
33
+ case 'top-left':
34
+ case 'top-right':
33
35
  case 'left-top':
34
36
  case 'right-top':
35
37
  return 'top';
36
38
  case 'bottom-left':
37
39
  case 'bottom-right':
40
+ case 'left-bottom':
41
+ case 'right-bottom':
38
42
  return 'bottom';
39
43
  default:
40
44
  return preferredPlacement;
@@ -1 +1 @@
1
- {"version":3,"file":"Popover.mjs","sources":["../../src/Popover/Popover.tsx"],"sourcesContent":["import { useTheme } from '@wise/components-theming';\nimport { clsx } from 'clsx';\nimport { useRef, useState, cloneElement, useEffect, isValidElement, useId } from 'react';\n\nimport { Position, Typography } from '../common';\nimport ResponsivePanel from '../common/ResponsivePanel';\nimport Title from '../Title';\nimport { logActionRequired } from '../utilities';\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype PopoverPreferredPlacementDeprecated =\n | `${Position.LEFT_TOP}`\n | `${Position.RIGHT_TOP}`\n | `${Position.BOTTOM_RIGHT}`\n | `${Position.BOTTOM_LEFT}`;\n\nexport type PopoverPreferredPlacement =\n | `${Position.TOP}`\n | `${Position.RIGHT}`\n | `${Position.BOTTOM}`\n | `${Position.LEFT}`\n | PopoverPreferredPlacementDeprecated;\n\nexport interface PopoverProps {\n children?: React.ReactNode;\n title?: React.ReactNode;\n /** Screen-reader-friendly title. Must be provided if `title` prop is not set. */\n 'aria-label'?: string;\n /** @default 'right' */\n preferredPlacement?: PopoverPreferredPlacement;\n content: React.ReactNode;\n onClose?: () => void;\n className?: string;\n}\n\nfunction resolvePlacement(preferredPlacement: PopoverPreferredPlacement) {\n switch (preferredPlacement) {\n case 'left-top':\n case 'right-top':\n return 'top';\n case 'bottom-left':\n case 'bottom-right':\n return 'bottom';\n default:\n return preferredPlacement;\n }\n}\n\nexport default function Popover({\n children,\n className,\n content,\n preferredPlacement = Position.RIGHT,\n title,\n onClose,\n 'aria-label': ariaLabel,\n}: PopoverProps) {\n const titleId = useId();\n\n const resolvedPlacement = resolvePlacement(preferredPlacement);\n useEffect(() => {\n if (resolvedPlacement !== preferredPlacement) {\n logActionRequired(\n `Popover has deprecated ${preferredPlacement} value for the 'preferredPlacement' prop. Please use ${resolvedPlacement} instead.`,\n );\n }\n }, [preferredPlacement, resolvedPlacement]);\n\n const anchorReference = useRef(null);\n const [open, setOpen] = useState(false);\n\n const handleOnClose = () => {\n setOpen(false);\n onClose?.();\n };\n\n return (\n <span className=\"np-popover\">\n <span ref={anchorReference} className=\"d-inline-block\">\n {isValidElement<{ onClick?: () => void }>(children)\n ? cloneElement(children, {\n onClick: () => {\n children.props.onClick?.();\n setOpen((prevOpen) => !prevOpen);\n },\n })\n : children}\n </span>\n <ResponsivePanel\n aria-label={ariaLabel}\n aria-labelledby={title && !ariaLabel ? titleId : undefined}\n open={open}\n anchorRef={anchorReference}\n position={resolvedPlacement}\n arrow\n className={clsx('np-popover__container', className)}\n onClose={handleOnClose}\n >\n <div className=\"np-popover__content np-text-default-body\">\n {title && (\n <Title type={Typography.TITLE_BODY} id={titleId} className=\"m-b-1\">\n {title}\n </Title>\n )}\n {content}\n </div>\n </ResponsivePanel>\n </span>\n );\n}\n"],"names":["resolvePlacement","preferredPlacement","Popover","children","className","content","Position","RIGHT","title","onClose","ariaLabel","titleId","useId","resolvedPlacement","useEffect","logActionRequired","anchorReference","useRef","open","setOpen","useState","handleOnClose","_jsxs","_jsx","ref","isValidElement","cloneElement","onClick","props","prevOpen","ResponsivePanel","undefined","anchorRef","position","arrow","clsx","Title","type","Typography","TITLE_BODY","id"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAASA,gBAAgBA,CAACC,kBAA6C,EAAA;AACrE,EAAA,QAAQA,kBAAkB;AACxB,IAAA,KAAK,UAAU;AACf,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,KAAK;AACd,IAAA,KAAK,aAAa;AAClB,IAAA,KAAK,cAAc;AACjB,MAAA,OAAO,QAAQ;AACjB,IAAA;AACE,MAAA,OAAOA,kBAAkB;AAC7B;AACF;AAEc,SAAUC,OAAOA,CAAC;EAC9BC,QAAQ;EACRC,SAAS;EACTC,OAAO;EACPJ,kBAAkB,GAAGK,QAAQ,CAACC,KAAK;EACnCC,KAAK;EACLC,OAAO;AACP,EAAA,YAAY,EAAEC;AAAS,CACV,EAAA;AACb,EAAA,MAAMC,OAAO,GAAGC,KAAK,EAAE;AAEvB,EAAA,MAAMC,iBAAiB,GAAGb,gBAAgB,CAACC,kBAAkB,CAAC;AAC9Da,EAAAA,SAAS,CAAC,MAAK;IACb,IAAID,iBAAiB,KAAKZ,kBAAkB,EAAE;AAC5Cc,MAAAA,iBAAiB,CACf,CAAA,uBAAA,EAA0Bd,kBAAkB,CAAA,qDAAA,EAAwDY,iBAAiB,WAAW,CACjI;AACH,IAAA;AACF,EAAA,CAAC,EAAE,CAACZ,kBAAkB,EAAEY,iBAAiB,CAAC,CAAC;AAE3C,EAAA,MAAMG,eAAe,GAAGC,MAAM,CAAC,IAAI,CAAC;EACpC,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;EAEvC,MAAMC,aAAa,GAAGA,MAAK;IAC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ACAH,OAAO;OACL;AACP,KAAiB,CACnB;AAAA,GAAM,CAAC;AAEX;;;;"}
1
+ {"version":3,"file":"Popover.mjs","sources":["../../src/Popover/Popover.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useRef, useState, cloneElement, useEffect, isValidElement, useId } from 'react';\n\nimport { Position, Typography } from '../common';\nimport ResponsivePanel from '../common/ResponsivePanel';\nimport Title from '../Title';\nimport { logActionRequired } from '../utilities';\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype PopoverPreferredPlacementDeprecated =\n | `${Position.TOP_LEFT}`\n | `${Position.TOP_RIGHT}`\n | `${Position.LEFT_TOP}`\n | `${Position.RIGHT_TOP}`\n | `${Position.BOTTOM_RIGHT}`\n | `${Position.BOTTOM_LEFT}`\n | `${Position.LEFT_BOTTOM}`\n | `${Position.RIGHT_BOTTOM}`;\n\nexport type PopoverPreferredPlacement =\n | `${Position.TOP}`\n | `${Position.RIGHT}`\n | `${Position.BOTTOM}`\n | `${Position.LEFT}`\n | PopoverPreferredPlacementDeprecated;\n\nexport interface PopoverProps {\n children?: React.ReactNode;\n title?: React.ReactNode;\n /** Screen-reader-friendly title. Must be provided if `title` prop is not set. */\n 'aria-label'?: string;\n /** @default 'right' */\n preferredPlacement?: PopoverPreferredPlacement;\n content: React.ReactNode;\n onClose?: () => void;\n className?: string;\n}\n\nfunction resolvePlacement(preferredPlacement: PopoverPreferredPlacement) {\n switch (preferredPlacement) {\n case 'top-left':\n case 'top-right':\n case 'left-top':\n case 'right-top':\n return 'top';\n case 'bottom-left':\n case 'bottom-right':\n case 'left-bottom':\n case 'right-bottom':\n return 'bottom';\n default:\n return preferredPlacement;\n }\n}\n\nexport default function Popover({\n children,\n className,\n content,\n preferredPlacement = Position.RIGHT,\n title,\n onClose,\n 'aria-label': ariaLabel,\n}: PopoverProps) {\n const titleId = useId();\n\n const resolvedPlacement = resolvePlacement(preferredPlacement);\n useEffect(() => {\n if (resolvedPlacement !== preferredPlacement) {\n logActionRequired(\n `Popover has deprecated ${preferredPlacement} value for the 'preferredPlacement' prop. Please use ${resolvedPlacement} instead.`,\n );\n }\n }, [preferredPlacement, resolvedPlacement]);\n\n const anchorReference = useRef(null);\n const [open, setOpen] = useState(false);\n\n const handleOnClose = () => {\n setOpen(false);\n onClose?.();\n };\n\n return (\n <span className=\"np-popover\">\n <span ref={anchorReference} className=\"d-inline-block\">\n {isValidElement<{ onClick?: () => void }>(children)\n ? cloneElement(children, {\n onClick: () => {\n children.props.onClick?.();\n setOpen((prevOpen) => !prevOpen);\n },\n })\n : children}\n </span>\n <ResponsivePanel\n aria-label={ariaLabel}\n aria-labelledby={title && !ariaLabel ? titleId : undefined}\n open={open}\n anchorRef={anchorReference}\n position={resolvedPlacement}\n arrow\n className={clsx('np-popover__container', className)}\n onClose={handleOnClose}\n >\n <div className=\"np-popover__content np-text-default-body\">\n {title && (\n <Title type={Typography.TITLE_BODY} id={titleId} className=\"m-b-1\">\n {title}\n </Title>\n )}\n {content}\n </div>\n </ResponsivePanel>\n </span>\n );\n}\n"],"names":["resolvePlacement","preferredPlacement","Popover","children","className","content","Position","RIGHT","title","onClose","ariaLabel","titleId","useId","resolvedPlacement","useEffect","logActionRequired","anchorReference","useRef","open","setOpen","useState","handleOnClose","_jsxs","_jsx","ref","isValidElement","cloneElement","onClick","props","prevOpen","ResponsivePanel","undefined","anchorRef","position","arrow","clsx","Title","type","Typography","TITLE_BODY","id"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAASA,gBAAgBA,CAACC,kBAA6C,EAAA;AACrE,EAAA,QAAQA,kBAAkB;AACxB,IAAA,KAAK,UAAU;AACf,IAAA,KAAK,WAAW;AAChB,IAAA,KAAK,UAAU;AACf,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,KAAK;AACd,IAAA,KAAK,aAAa;AAClB,IAAA,KAAK,cAAc;AACnB,IAAA,KAAK,aAAa;AAClB,IAAA,KAAK,cAAc;AACjB,MAAA,OAAO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