@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.
- package/build/FlowNavigation/FlowNavigation.js +5 -14
- package/build/FlowNavigation/FlowNavigation.js.map +1 -1
- package/build/FlowNavigation/FlowNavigation.mjs +5 -14
- package/build/FlowNavigation/FlowNavigation.mjs.map +1 -1
- package/build/Markup/Markup.js +15 -14
- package/build/Markup/Markup.js.map +1 -1
- package/build/Markup/Markup.mjs +15 -14
- package/build/Markup/Markup.mjs.map +1 -1
- package/build/Popover/Popover.js +4 -0
- package/build/Popover/Popover.js.map +1 -1
- package/build/Popover/Popover.mjs +4 -0
- package/build/Popover/Popover.mjs.map +1 -1
- package/build/_deprecated/OverlayHeader/OverlayHeader.js +6 -41
- package/build/_deprecated/OverlayHeader/OverlayHeader.js.map +1 -1
- package/build/_deprecated/OverlayHeader/OverlayHeader.mjs +6 -41
- package/build/_deprecated/OverlayHeader/OverlayHeader.mjs.map +1 -1
- package/build/common/Panel/Panel.js +13 -4
- package/build/common/Panel/Panel.js.map +1 -1
- package/build/common/Panel/Panel.mjs +14 -5
- package/build/common/Panel/Panel.mjs.map +1 -1
- package/build/common/PropsValues/position.js +29 -0
- package/build/common/PropsValues/position.js.map +1 -1
- package/build/common/PropsValues/position.mjs +28 -1
- package/build/common/PropsValues/position.mjs.map +1 -1
- package/build/main.css +8 -34
- package/build/styles/FlowNavigation/FlowNavigation.css +7 -13
- package/build/styles/main.css +8 -34
- package/build/types/FlowNavigation/FlowNavigation.d.ts +2 -9
- package/build/types/FlowNavigation/FlowNavigation.d.ts.map +1 -1
- package/build/types/Markup/Markup.d.ts.map +1 -1
- package/build/types/Markup/Markup.types.d.ts +16 -5
- package/build/types/Markup/Markup.types.d.ts.map +1 -1
- package/build/types/Markup/index.d.ts +1 -1
- package/build/types/Markup/index.d.ts.map +1 -1
- package/build/types/Popover/Popover.d.ts +1 -1
- package/build/types/Popover/Popover.d.ts.map +1 -1
- package/build/types/_deprecated/OverlayHeader/OverlayHeader.d.ts.map +1 -1
- package/build/types/common/Panel/Panel.d.ts +6 -6
- package/build/types/common/Panel/Panel.d.ts.map +1 -1
- package/build/types/common/PropsValues/position.d.ts +18 -1
- package/build/types/common/PropsValues/position.d.ts.map +1 -1
- package/build/types/common/ResponsivePanel/ResponsivePanel.d.ts +2 -2
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/FlowNavigation/FlowNavigation.css +7 -13
- package/src/FlowNavigation/FlowNavigation.less +6 -15
- package/src/FlowNavigation/FlowNavigation.tsx +6 -27
- package/src/FlowNavigation/_stories/FlowNavigation.story.tsx +0 -86
- package/src/Markup/Markup.test.tsx +8 -7
- package/src/Markup/Markup.tsx +18 -15
- package/src/Markup/Markup.types.ts +16 -6
- package/src/Markup/_stories/Markup.docs.mdx +60 -0
- package/src/Markup/_stories/Markup.story.tsx +7 -8
- package/src/Markup/index.ts +6 -1
- package/src/Popover/Popover.tsx +9 -2
- package/src/_deprecated/OverlayHeader/OverlayHeader.tsx +2 -21
- package/src/common/Panel/Panel.test.tsx +17 -0
- package/src/common/Panel/Panel.tsx +17 -8
- package/src/common/Panel/_stories/Panel.story.tsx +182 -0
- package/src/common/PropsValues/position.ts +54 -0
- package/src/i18n/en.json +1 -0
- package/src/index.ts +1 -1
- package/src/main.css +8 -34
- package/src/main.less +0 -1
- package/build/styles/_deprecated/OverlayHeader/OverlayHeader.css +0 -15
- package/src/_deprecated/OverlayHeader/OverlayHeader.css +0 -15
- 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',
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
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;IACTC,SAAS,EAAEC,SAAI,CACb,6BAA6B,EAC7Bf,QAAQ,IAAI,IAAI,GACZ,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,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',
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
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,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@ const PLACEHOLDER_REGEX = /\{\{(\w+)\}\}/g;
|
|
|
12
12
|
function substituteData(text, data) {
|
|
13
13
|
return text.replace(PLACEHOLDER_REGEX, (match, key) => Object.prototype.hasOwnProperty.call(data, key) ? String(data[key]) : match);
|
|
14
14
|
}
|
|
15
|
-
function renderNodes(nodes,
|
|
16
|
-
return nodes.map((node, index) => renderNode(node,
|
|
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,
|
|
19
|
-
const children = renderNodes(node.children,
|
|
20
|
-
if (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:
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
76
|
+
children: renderNodes(node.children, onAction, data, allowLinks)
|
|
76
77
|
}, key);
|
|
77
78
|
case 'link':
|
|
78
|
-
return renderLinkNode(node,
|
|
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
|
-
|
|
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,
|
|
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 {
|
|
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,IAA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AAA,SAAS,EAAEA,SAAU;AAAC,MAAA,aAAA,EAAaI,MAAO;AAAApB,MAAAA,QAAA,EAC7CA;AAAQ,KACL,CAAC;AAEX,EAAA;AAEA,EAAA,IAAIqB,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;IAAApB,QAAA,EAChDT,WAAW,CAAC8B,IAAI,EAAE5B,QAAQ,EAAEX,IAAI,EAAEY,UAAU;AAAC,GACvC,CAAC;AAEd;;;;;"}
|
package/build/Markup/Markup.mjs
CHANGED
|
@@ -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,
|
|
12
|
-
return nodes.map((node, index) => renderNode(node,
|
|
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,
|
|
15
|
-
const children = renderNodes(node.children,
|
|
16
|
-
if (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:
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
72
|
+
children: renderNodes(node.children, onAction, data, allowLinks)
|
|
72
73
|
}, key);
|
|
73
74
|
case 'link':
|
|
74
|
-
return renderLinkNode(node,
|
|
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
|
-
|
|
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,
|
|
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 {
|
|
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":";;;;;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,MAAMkB,MAAM,GAA0BA,CAAC;EAC5ClB,QAAQ;EACRlB,IAAI;AACJY,EAAAA,UAAU,GAAG,UAAU;EACvBD,QAAQ;EACR0B,EAAE;EACFH,SAAS;AACT,EAAA,aAAa,EAAEI;AAAM,CACtB,KAAI;EACH,MAAMC,IAAI,GAAGC,OAAO,CAClB,MAAO,OAAOtB,QAAQ,KAAK,QAAQ,GAAGuB,WAAW,CAACvB,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,oBACEG,GAAA,CAAA,MAAA,EAAA;AAAMa,MAAAA,SAAS,EAAEA,SAAU;AAAC,MAAA,aAAA,EAAaI,MAAO;AAAApB,MAAAA,QAAA,EAC7CA;AAAQ,KACL,CAAC;AAEX,EAAA;AAEA,EAAA,IAAIqB,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;IAAApB,QAAA,EAChDT,WAAW,CAAC8B,IAAI,EAAE5B,QAAQ,EAAEX,IAAI,EAAEY,UAAU;AAAC,GACvC,CAAC;AAEd;;;;"}
|
package/build/Popover/Popover.js
CHANGED
|
@@ -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 {
|
|
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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AAER,eAAgB;AAACZ,MAAAA,SAAS,EAAC,gBAAgB;MAAAD,QAAA,eACnDsB,oBAAc,CAA2BtB,QAAQ,CAAC,gBAC/CuB,kBAAY,CAACvB,QAAQ,EAAE;QACrBwB,OAAO,EAAEA,MAAK;AACZxB,UAAAA,QAAQ,CAACyB,KAAK,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;;;;"}
|
|
@@ -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 {
|
|
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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