@transferwise/components 46.75.0 → 46.77.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/alert/Alert.js +19 -13
- package/build/alert/Alert.js.map +1 -1
- package/build/alert/Alert.mjs +19 -13
- package/build/alert/Alert.mjs.map +1 -1
- package/build/main.css +3 -0
- package/build/styles/alert/Alert.css +3 -0
- package/build/styles/main.css +3 -0
- package/build/types/alert/Alert.d.ts +4 -2
- package/build/types/alert/Alert.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/alert/Alert.css +3 -0
- package/src/alert/Alert.less +3 -0
- package/src/alert/Alert.spec.story.tsx +131 -4
- package/src/alert/Alert.spec.tsx +36 -10
- package/src/alert/Alert.story.tsx +134 -23
- package/src/alert/Alert.tsx +27 -14
- package/src/main.css +3 -0
- package/src/main.less +1 -0
package/build/alert/Alert.js
CHANGED
|
@@ -39,21 +39,27 @@ function resolveType(type) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
function Alert({
|
|
42
|
-
arrow,
|
|
43
42
|
action,
|
|
44
|
-
children,
|
|
45
43
|
className,
|
|
46
|
-
dismissible,
|
|
47
44
|
icon,
|
|
48
45
|
statusIconLabel,
|
|
49
46
|
onDismiss,
|
|
50
47
|
message,
|
|
51
|
-
size: size$1,
|
|
52
48
|
title,
|
|
53
49
|
type = 'neutral',
|
|
54
50
|
variant = 'desktop',
|
|
55
|
-
|
|
51
|
+
arrow,
|
|
52
|
+
children,
|
|
53
|
+
size: size$1,
|
|
54
|
+
dismissible,
|
|
55
|
+
active = true,
|
|
56
|
+
dynamicRender
|
|
56
57
|
}) {
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
if (active !== undefined || dynamicRender !== undefined) {
|
|
60
|
+
logActionRequired.logActionRequired("Alert component doesn't support `active` or `dynamicRender` anymore, please remove that prop.");
|
|
61
|
+
}
|
|
62
|
+
}, [active, dynamicRender]);
|
|
57
63
|
React.useEffect(() => {
|
|
58
64
|
if (arrow !== undefined) {
|
|
59
65
|
logActionRequired.logActionRequired("Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.");
|
|
@@ -81,18 +87,18 @@ function Alert({
|
|
|
81
87
|
}
|
|
82
88
|
}, [resolvedType, type]);
|
|
83
89
|
const [shouldFire, setShouldFire] = React.useState();
|
|
84
|
-
const [
|
|
90
|
+
const [shouldAnnounce, setShouldAnnounce] = React.useState(false);
|
|
85
91
|
React.useEffect(() => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
}, [active, shouldShow]);
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
setShouldAnnounce(true);
|
|
94
|
+
}, constants.WDS_LIVE_REGION_DELAY_MS);
|
|
95
|
+
}, []);
|
|
92
96
|
const closeButtonReference = React.useRef(null);
|
|
93
97
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
94
98
|
role: resolvedType === sentiment.Sentiment.NEGATIVE ? 'alert' : 'status',
|
|
95
|
-
|
|
99
|
+
className: "wds-alert__liveRegion",
|
|
100
|
+
children: active && /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
101
|
+
"aria-hidden": shouldAnnounce ? undefined : 'true',
|
|
96
102
|
className: clsx.clsx('alert d-flex', `alert-${resolvedType}`, arrow != null && alertArrowClassNames(arrow), className),
|
|
97
103
|
"data-testid": "alert",
|
|
98
104
|
onTouchStart: () => setShouldFire(true),
|
package/build/alert/Alert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.js","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport {\n CloseButton,\n Sentiment,\n Size,\n Typography,\n Variant,\n WDS_LIVE_REGION_DELAY_MS,\n} from '../common';\n\nimport StatusIcon from '../statusIcon';\nimport Title from '../title/Title';\nimport { logActionRequired } from '../utilities';\n\nimport InlineMarkdown from './inlineMarkdown';\nimport { Action } from '../common/action/Action';\n\nexport type AlertAction = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;\ntype AlertTypeResolved = `${\n | Sentiment.POSITIVE\n | Sentiment.NEUTRAL\n | Sentiment.WARNING\n | Sentiment.NEGATIVE}`;\nexport type AlertType = AlertTypeResolved | AlertTypeDeprecated;\n\nexport enum AlertArrowPosition {\n TOP_LEFT = 'up-left',\n TOP = 'up-center',\n TOP_RIGHT = 'up-right',\n BOTTOM_LEFT = 'down-left',\n BOTTOM = 'down-center',\n BOTTOM_RIGHT = 'down-right',\n}\n\nexport interface AlertProps {\n /** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */\n action?: AlertAction;\n className?: string;\n /** An optional icon. If not provided, we will default the icon to something appropriate for the type */\n icon?: React.ReactNode;\n /**\n * Override for [StatusIcon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)\n * announced by the screen readers\n * */\n statusIconLabel?: string;\n /** Title for the alert component */\n title?: string;\n /** The main body of the alert. Accepts plain text and bold words specified with **double stars */\n message?: string;\n /** The presence of the onDismiss handler will trigger the visibility of the close button */\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n /** The type dictates which icon and colour will be used */\n type?: AlertType;\n variant?: `${Variant}`;\n /** Controls rendering of the Alert component. <br /> Toggle this prop instead using conditional rendering and logical AND (&&) operator, to make the component work with screen readers. */\n active?: boolean;\n /** @deprecated Use `InlineAlert` instead. */\n arrow?: `${AlertArrowPosition}`;\n /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */\n children?: React.ReactNode;\n /** @deprecated Use `onDismiss` instead. */\n dismissible?: boolean;\n /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */\n size?: `${Size}`;\n}\n\nfunction resolveType(type: AlertType): AlertTypeResolved {\n switch (type) {\n case 'success':\n return 'positive';\n case 'info':\n return 'neutral';\n case 'error':\n return 'negative';\n default:\n return type;\n }\n}\n\nexport default function Alert({\n arrow,\n action,\n children,\n className,\n dismissible,\n icon,\n statusIconLabel,\n onDismiss,\n message,\n size,\n title,\n type = 'neutral',\n variant = 'desktop',\n active = true,\n}: AlertProps) {\n useEffect(() => {\n if (arrow !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.\",\n );\n }\n }, [arrow]);\n\n useEffect(() => {\n if (children !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'children' anymore, use 'message' instead.\",\n );\n }\n }, [children]);\n\n useEffect(() => {\n if (dismissible !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.\",\n );\n }\n }, [dismissible]);\n\n useEffect(() => {\n if (size !== undefined) {\n logActionRequired(\"Alert component doesn't support 'size' anymore, please remove that prop.\");\n }\n }, [size]);\n\n const resolvedType = resolveType(type);\n useEffect(() => {\n if (resolvedType !== type) {\n logActionRequired(\n `Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,\n );\n }\n }, [resolvedType, type]);\n\n const [shouldFire, setShouldFire] = useState<boolean>();\n\n const [shouldShow, setShouldShow] = useState<boolean>();\n useEffect(() => {\n if (shouldShow === undefined || !active) {\n setShouldShow(active);\n } else {\n setTimeout(() => setShouldShow(active), WDS_LIVE_REGION_DELAY_MS);\n }\n }, [active, shouldShow]);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>\n {shouldShow && (\n <div\n className={clsx(\n 'alert d-flex',\n `alert-${resolvedType}`,\n arrow != null && alertArrowClassNames(arrow),\n className,\n )}\n data-testid=\"alert\"\n onTouchStart={() => setShouldFire(true)}\n onTouchEnd={(event) => {\n if (\n shouldFire &&\n action?.href &&\n // Check if current event is triggered from closeButton\n event.target instanceof Node &&\n closeButtonReference.current &&\n !closeButtonReference.current.contains(event.target)\n ) {\n if (action.target === '_blank') {\n window.top?.open(action.href);\n } else {\n window.top?.location.assign(action.href);\n }\n }\n setShouldFire(false);\n }}\n onTouchMove={() => setShouldFire(false)}\n >\n <div\n className={clsx('alert__content', 'd-flex', 'flex-grow-1', variant)}\n data-testid={variant}\n >\n {icon ? (\n <div className=\"alert__icon\">{icon}</div>\n ) : (\n <StatusIcon size={Size.LARGE} sentiment={resolvedType} iconLabel={statusIconLabel} />\n )}\n <div className=\"alert__message\">\n <div>\n {title && (\n <Title className=\"m-b-1\" type={Typography.TITLE_BODY}>\n {title}\n </Title>\n )}\n <Body as=\"span\" className=\"d-block\" type={Typography.BODY_LARGE}>\n {children || <InlineMarkdown>{message}</InlineMarkdown>}\n </Body>\n </div>\n {action && <Action action={action} variant=\"action-button\" className=\"m-t-1\" />}\n </div>\n </div>\n {onDismiss && (\n <CloseButton ref={closeButtonReference} className=\"m-l-2\" onClick={onDismiss} />\n )}\n </div>\n )}\n </div>\n );\n}\n\nfunction alertArrowClassNames(arrow: `${AlertArrowPosition}`) {\n switch (arrow) {\n case 'down-center':\n return 'arrow arrow-bottom arrow-center';\n case 'down-left':\n return 'arrow arrow-bottom arrow-left';\n case 'down-right':\n return 'arrow arrow-bottom arrow-right';\n case 'up-center':\n return 'arrow arrow-center';\n case 'up-right':\n return 'arrow arrow-right';\n case 'up-left':\n default:\n return 'arrow';\n }\n}\n"],"names":["AlertArrowPosition","resolveType","type","Alert","arrow","action","children","className","dismissible","icon","statusIconLabel","onDismiss","message","size","title","variant","active","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","shouldShow","setShouldShow","setTimeout","WDS_LIVE_REGION_DELAY_MS","closeButtonReference","useRef","_jsx","role","Sentiment","NEGATIVE","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","StatusIcon","Size","LARGE","sentiment","iconLabel","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mappings":";;;;;;;;;;;;;;;;;;;AAqCYA,oCAOX;AAPD,CAAA,UAAYA,kBAAkB,EAAA;AAC5BA,EAAAA,kBAAA,CAAA,UAAA,CAAA,GAAA,SAAoB,CAAA;AACpBA,EAAAA,kBAAA,CAAA,KAAA,CAAA,GAAA,WAAiB,CAAA;AACjBA,EAAAA,kBAAA,CAAA,WAAA,CAAA,GAAA,UAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,aAAA,CAAA,GAAA,WAAyB,CAAA;AACzBA,EAAAA,kBAAA,CAAA,QAAA,CAAA,GAAA,aAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,cAAA,CAAA,GAAA,YAA2B,CAAA;AAC7B,CAAC,EAPWA,0BAAkB,KAAlBA,0BAAkB,GAO7B,EAAA,CAAA,CAAA,CAAA;AAkCD,SAASC,WAAWA,CAACC,IAAe,EAAA;AAClC,EAAA,QAAQA,IAAI;AACV,IAAA,KAAK,SAAS;AACZ,MAAA,OAAO,UAAU,CAAA;AACnB,IAAA,KAAK,MAAM;AACT,MAAA,OAAO,SAAS,CAAA;AAClB,IAAA,KAAK,OAAO;AACV,MAAA,OAAO,UAAU,CAAA;AACnB,IAAA;AACE,MAAA,OAAOA,IAAI,CAAA;AACf,GAAA;AACF,CAAA;AAEc,SAAUC,KAAKA,CAAC;EAC5BC,KAAK;EACLC,MAAM;EACNC,QAAQ;EACRC,SAAS;EACTC,WAAW;EACXC,IAAI;EACJC,eAAe;EACfC,SAAS;EACTC,OAAO;QACPC,MAAI;EACJC,KAAK;AACLZ,EAAAA,IAAI,GAAG,SAAS;AAChBa,EAAAA,OAAO,GAAG,SAAS;AACnBC,EAAAA,MAAM,GAAG,IAAA;AACE,CAAA,EAAA;AACXC,EAAAA,eAAS,CAAC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A;AAAC1D,YAAAA,MAAM,EAAEA,MAAO;AAACU,YAAAA,OAAO,EAAC,eAAe;AAACR,YAAAA,SAAS,EAAC,OAAA;AAAO,YAAG,CAAA;AAAA,SAC5E,CACP,CAAA;AAAA,OAAK,CACL,EAACI,SAAS,iBACRmB,cAAA,CAACkC,uBAAW,EAAA;AAACC,QAAAA,GAAG,EAAErC,oBAAqB;AAACrB,QAAAA,SAAS,EAAC,OAAO;AAAC2D,QAAAA,OAAO,EAAEvD,SAAAA;AAAU,OAAG,CACjF,CAAA;KACE,CAAA;AACN,GACE,CAAC,CAAA;AAEV,CAAA;AAEA,SAASyB,oBAAoBA,CAAChC,KAA8B,EAAA;AAC1D,EAAA,QAAQA,KAAK;AACX,IAAA,KAAK,aAAa;AAChB,MAAA,OAAO,iCAAiC,CAAA;AAC1C,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,+BAA+B,CAAA;AACxC,IAAA,KAAK,YAAY;AACf,MAAA,OAAO,gCAAgC,CAAA;AACzC,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,oBAAoB,CAAA;AAC7B,IAAA,KAAK,UAAU;AACb,MAAA,OAAO,mBAAmB,CAAA;AAC5B,IAAA,KAAK,SAAS,CAAA;AACd,IAAA;AACE,MAAA,OAAO,OAAO,CAAA;AAClB,GAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"Alert.js","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport {\n CloseButton,\n Sentiment,\n Size,\n Typography,\n Variant,\n WDS_LIVE_REGION_DELAY_MS,\n} from '../common';\n\nimport StatusIcon from '../statusIcon';\nimport Title from '../title/Title';\nimport { logActionRequired } from '../utilities';\n\nimport InlineMarkdown from './inlineMarkdown';\nimport { Action } from '../common/action/Action';\n\nexport type AlertAction = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;\ntype AlertTypeResolved = `${\n | Sentiment.POSITIVE\n | Sentiment.NEUTRAL\n | Sentiment.WARNING\n | Sentiment.NEGATIVE}`;\nexport type AlertType = AlertTypeResolved | AlertTypeDeprecated;\n\nexport enum AlertArrowPosition {\n TOP_LEFT = 'up-left',\n TOP = 'up-center',\n TOP_RIGHT = 'up-right',\n BOTTOM_LEFT = 'down-left',\n BOTTOM = 'down-center',\n BOTTOM_RIGHT = 'down-right',\n}\n\nexport interface AlertProps {\n /** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */\n action?: AlertAction;\n className?: string;\n /** An optional icon. If not provided, we will default the icon to something appropriate for the type */\n icon?: React.ReactNode;\n /**\n * Override for [StatusIcon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)\n * announced by the screen readers\n * */\n statusIconLabel?: string;\n /** Title for the alert component */\n title?: string;\n /** The main body of the alert. Accepts plain text and bold words specified with **double stars */\n message?: string;\n /** The presence of the onDismiss handler will trigger the visibility of the close button */\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n /** The type dictates which icon and colour will be used */\n type?: AlertType;\n variant?: `${Variant}`;\n /** @deprecated Safe to remove */\n active?: boolean;\n /** @deprecated Safe to remove */\n dynamicRender?: boolean;\n /** @deprecated Use `InlineAlert` instead. */\n arrow?: `${AlertArrowPosition}`;\n /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */\n children?: React.ReactNode;\n /** @deprecated Use `onDismiss` instead. */\n dismissible?: boolean;\n /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */\n size?: `${Size}`;\n}\n\nfunction resolveType(type: AlertType): AlertTypeResolved {\n switch (type) {\n case 'success':\n return 'positive';\n case 'info':\n return 'neutral';\n case 'error':\n return 'negative';\n default:\n return type;\n }\n}\n\nexport default function Alert({\n action,\n className,\n icon,\n statusIconLabel,\n onDismiss,\n message,\n title,\n type = 'neutral',\n variant = 'desktop',\n arrow,\n children,\n size,\n dismissible,\n active = true,\n dynamicRender,\n}: AlertProps) {\n useEffect(() => {\n if (active !== undefined || dynamicRender !== undefined) {\n logActionRequired(\n \"Alert component doesn't support `active` or `dynamicRender` anymore, please remove that prop.\",\n );\n }\n }, [active, dynamicRender]);\n\n useEffect(() => {\n if (arrow !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.\",\n );\n }\n }, [arrow]);\n\n useEffect(() => {\n if (children !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'children' anymore, use 'message' instead.\",\n );\n }\n }, [children]);\n\n useEffect(() => {\n if (dismissible !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.\",\n );\n }\n }, [dismissible]);\n\n useEffect(() => {\n if (size !== undefined) {\n logActionRequired(\"Alert component doesn't support 'size' anymore, please remove that prop.\");\n }\n }, [size]);\n\n const resolvedType = resolveType(type);\n useEffect(() => {\n if (resolvedType !== type) {\n logActionRequired(\n `Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,\n );\n }\n }, [resolvedType, type]);\n\n const [shouldFire, setShouldFire] = useState<boolean>();\n\n const [shouldAnnounce, setShouldAnnounce] = useState<boolean>(false);\n useEffect(() => {\n setTimeout(() => {\n setShouldAnnounce(true);\n }, WDS_LIVE_REGION_DELAY_MS);\n }, []);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div\n role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}\n className=\"wds-alert__liveRegion\"\n >\n {active && (\n <div\n aria-hidden={shouldAnnounce ? undefined : 'true'}\n className={clsx(\n 'alert d-flex',\n `alert-${resolvedType}`,\n arrow != null && alertArrowClassNames(arrow),\n className,\n )}\n data-testid=\"alert\"\n onTouchStart={() => setShouldFire(true)}\n onTouchEnd={(event) => {\n if (\n shouldFire &&\n action?.href &&\n // Check if current event is triggered from closeButton\n event.target instanceof Node &&\n closeButtonReference.current &&\n !closeButtonReference.current.contains(event.target)\n ) {\n if (action.target === '_blank') {\n window.top?.open(action.href);\n } else {\n window.top?.location.assign(action.href);\n }\n }\n setShouldFire(false);\n }}\n onTouchMove={() => setShouldFire(false)}\n >\n <div\n className={clsx('alert__content', 'd-flex', 'flex-grow-1', variant)}\n data-testid={variant}\n >\n {icon ? (\n <div className=\"alert__icon\">{icon}</div>\n ) : (\n <StatusIcon size={Size.LARGE} sentiment={resolvedType} iconLabel={statusIconLabel} />\n )}\n <div className=\"alert__message\">\n <div>\n {title && (\n <Title className=\"m-b-1\" type={Typography.TITLE_BODY}>\n {title}\n </Title>\n )}\n <Body as=\"span\" className=\"d-block\" type={Typography.BODY_LARGE}>\n {children || <InlineMarkdown>{message}</InlineMarkdown>}\n </Body>\n </div>\n {action && <Action action={action} variant=\"action-button\" className=\"m-t-1\" />}\n </div>\n </div>\n {onDismiss && (\n <CloseButton ref={closeButtonReference} className=\"m-l-2\" onClick={onDismiss} />\n )}\n </div>\n )}\n </div>\n );\n}\n\nfunction alertArrowClassNames(arrow: `${AlertArrowPosition}`) {\n switch (arrow) {\n case 'down-center':\n return 'arrow arrow-bottom arrow-center';\n case 'down-left':\n return 'arrow arrow-bottom arrow-left';\n case 'down-right':\n return 'arrow arrow-bottom arrow-right';\n case 'up-center':\n return 'arrow arrow-center';\n case 'up-right':\n return 'arrow arrow-right';\n case 'up-left':\n default:\n return 'arrow';\n }\n}\n"],"names":["AlertArrowPosition","resolveType","type","Alert","action","className","icon","statusIconLabel","onDismiss","message","title","variant","arrow","children","size","dismissible","active","dynamicRender","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","shouldAnnounce","setShouldAnnounce","setTimeout","WDS_LIVE_REGION_DELAY_MS","closeButtonReference","useRef","_jsx","role","Sentiment","NEGATIVE","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","StatusIcon","Size","LARGE","sentiment","iconLabel","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mappings":";;;;;;;;;;;;;;;;;;;AAqCYA,oCAOX;AAPD,CAAA,UAAYA,kBAAkB,EAAA;AAC5BA,EAAAA,kBAAA,CAAA,UAAA,CAAA,GAAA,SAAoB,CAAA;AACpBA,EAAAA,kBAAA,CAAA,KAAA,CAAA,GAAA,WAAiB,CAAA;AACjBA,EAAAA,kBAAA,CAAA,WAAA,CAAA,GAAA,UAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,aAAA,CAAA,GAAA,WAAyB,CAAA;AACzBA,EAAAA,kBAAA,CAAA,QAAA,CAAA,GAAA,aAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,cAAA,CAAA,GAAA,YAA2B,CAAA;AAC7B,CAAC,EAPWA,0BAAkB,KAAlBA,0BAAkB,GAO7B,EAAA,CAAA,CAAA,CAAA;AAoCD,SAASC,WAAWA,CAACC,IAAe,EAAA;AAClC,EAAA,QAAQA,IAAI;AACV,IAAA,KAAK,SAAS;AACZ,MAAA,OAAO,UAAU,CAAA;AACnB,IAAA,KAAK,MAAM;AACT,MAAA,OAAO,SAAS,CAAA;AAClB,IAAA,KAAK,OAAO;AACV,MAAA,OAAO,UAAU,CAAA;AACnB,IAAA;AACE,MAAA,OAAOA,IAAI,CAAA;AACf,GAAA;AACF,CAAA;AAEc,SAAUC,KAAKA,CAAC;EAC5BC,MAAM;EACNC,SAAS;EACTC,IAAI;EACJC,eAAe;EACfC,SAAS;EACTC,OAAO;EACPC,KAAK;AACLR,EAAAA,IAAI,GAAG,SAAS;AAChBS,EAAAA,OAAO,GAAG,SAAS;EACnBC,KAAK;EACLC,QAAQ;QACRC,MAAI;EACJC,WAAW;AACXC,EAAAA,MAAM,GAAG,IAAI;AACbC,EAAAA,aAAAA;AACW,CAAA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U,CAACI,UAAW;AAAAjD,cAAAA,QAAA,EAC7DA,QAAQ,iBAAIkB,cAAA,CAACgC,cAAc,EAAA;AAAAlD,gBAAAA,QAAA,EAAEJ,OAAAA;eAAwB,CAAA;AAAC,aACnD,CACR,CAAA;AAAA,WAAK,CACL,EAACL,MAAM,iBAAI2B,cAAA,CAACiC,aAAM,EAAA;AAAC5D,YAAAA,MAAM,EAAEA,MAAO;AAACO,YAAAA,OAAO,EAAC,eAAe;AAACN,YAAAA,SAAS,EAAC,OAAA;AAAO,YAAG,CAAA;AAAA,SAC5E,CACP,CAAA;AAAA,OAAK,CACL,EAACG,SAAS,iBACRuB,cAAA,CAACkC,uBAAW,EAAA;AAACC,QAAAA,GAAG,EAAErC,oBAAqB;AAACxB,QAAAA,SAAS,EAAC,OAAO;AAAC8D,QAAAA,OAAO,EAAE3D,SAAAA;AAAU,OAAG,CACjF,CAAA;KACE,CAAA;AACN,GACE,CAAC,CAAA;AAEV,CAAA;AAEA,SAAS6B,oBAAoBA,CAACzB,KAA8B,EAAA;AAC1D,EAAA,QAAQA,KAAK;AACX,IAAA,KAAK,aAAa;AAChB,MAAA,OAAO,iCAAiC,CAAA;AAC1C,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,+BAA+B,CAAA;AACxC,IAAA,KAAK,YAAY;AACf,MAAA,OAAO,gCAAgC,CAAA;AACzC,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,oBAAoB,CAAA;AAC7B,IAAA,KAAK,UAAU;AACb,MAAA,OAAO,mBAAmB,CAAA;AAC5B,IAAA,KAAK,SAAS,CAAA;AACd,IAAA;AACE,MAAA,OAAO,OAAO,CAAA;AAClB,GAAA;AACF;;;;"}
|
package/build/alert/Alert.mjs
CHANGED
|
@@ -35,21 +35,27 @@ function resolveType(type) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
function Alert({
|
|
38
|
-
arrow,
|
|
39
38
|
action,
|
|
40
|
-
children,
|
|
41
39
|
className,
|
|
42
|
-
dismissible,
|
|
43
40
|
icon,
|
|
44
41
|
statusIconLabel,
|
|
45
42
|
onDismiss,
|
|
46
43
|
message,
|
|
47
|
-
size,
|
|
48
44
|
title,
|
|
49
45
|
type = 'neutral',
|
|
50
46
|
variant = 'desktop',
|
|
51
|
-
|
|
47
|
+
arrow,
|
|
48
|
+
children,
|
|
49
|
+
size,
|
|
50
|
+
dismissible,
|
|
51
|
+
active = true,
|
|
52
|
+
dynamicRender
|
|
52
53
|
}) {
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (active !== undefined || dynamicRender !== undefined) {
|
|
56
|
+
logActionRequired("Alert component doesn't support `active` or `dynamicRender` anymore, please remove that prop.");
|
|
57
|
+
}
|
|
58
|
+
}, [active, dynamicRender]);
|
|
53
59
|
useEffect(() => {
|
|
54
60
|
if (arrow !== undefined) {
|
|
55
61
|
logActionRequired("Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.");
|
|
@@ -77,18 +83,18 @@ function Alert({
|
|
|
77
83
|
}
|
|
78
84
|
}, [resolvedType, type]);
|
|
79
85
|
const [shouldFire, setShouldFire] = useState();
|
|
80
|
-
const [
|
|
86
|
+
const [shouldAnnounce, setShouldAnnounce] = useState(false);
|
|
81
87
|
useEffect(() => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
}, [active, shouldShow]);
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
setShouldAnnounce(true);
|
|
90
|
+
}, WDS_LIVE_REGION_DELAY_MS);
|
|
91
|
+
}, []);
|
|
88
92
|
const closeButtonReference = useRef(null);
|
|
89
93
|
return /*#__PURE__*/jsx("div", {
|
|
90
94
|
role: resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status',
|
|
91
|
-
|
|
95
|
+
className: "wds-alert__liveRegion",
|
|
96
|
+
children: active && /*#__PURE__*/jsxs("div", {
|
|
97
|
+
"aria-hidden": shouldAnnounce ? undefined : 'true',
|
|
92
98
|
className: clsx('alert d-flex', `alert-${resolvedType}`, arrow != null && alertArrowClassNames(arrow), className),
|
|
93
99
|
"data-testid": "alert",
|
|
94
100
|
onTouchStart: () => setShouldFire(true),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.mjs","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport {\n CloseButton,\n Sentiment,\n Size,\n Typography,\n Variant,\n WDS_LIVE_REGION_DELAY_MS,\n} from '../common';\n\nimport StatusIcon from '../statusIcon';\nimport Title from '../title/Title';\nimport { logActionRequired } from '../utilities';\n\nimport InlineMarkdown from './inlineMarkdown';\nimport { Action } from '../common/action/Action';\n\nexport type AlertAction = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;\ntype AlertTypeResolved = `${\n | Sentiment.POSITIVE\n | Sentiment.NEUTRAL\n | Sentiment.WARNING\n | Sentiment.NEGATIVE}`;\nexport type AlertType = AlertTypeResolved | AlertTypeDeprecated;\n\nexport enum AlertArrowPosition {\n TOP_LEFT = 'up-left',\n TOP = 'up-center',\n TOP_RIGHT = 'up-right',\n BOTTOM_LEFT = 'down-left',\n BOTTOM = 'down-center',\n BOTTOM_RIGHT = 'down-right',\n}\n\nexport interface AlertProps {\n /** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */\n action?: AlertAction;\n className?: string;\n /** An optional icon. If not provided, we will default the icon to something appropriate for the type */\n icon?: React.ReactNode;\n /**\n * Override for [StatusIcon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)\n * announced by the screen readers\n * */\n statusIconLabel?: string;\n /** Title for the alert component */\n title?: string;\n /** The main body of the alert. Accepts plain text and bold words specified with **double stars */\n message?: string;\n /** The presence of the onDismiss handler will trigger the visibility of the close button */\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n /** The type dictates which icon and colour will be used */\n type?: AlertType;\n variant?: `${Variant}`;\n /** Controls rendering of the Alert component. <br /> Toggle this prop instead using conditional rendering and logical AND (&&) operator, to make the component work with screen readers. */\n active?: boolean;\n /** @deprecated Use `InlineAlert` instead. */\n arrow?: `${AlertArrowPosition}`;\n /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */\n children?: React.ReactNode;\n /** @deprecated Use `onDismiss` instead. */\n dismissible?: boolean;\n /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */\n size?: `${Size}`;\n}\n\nfunction resolveType(type: AlertType): AlertTypeResolved {\n switch (type) {\n case 'success':\n return 'positive';\n case 'info':\n return 'neutral';\n case 'error':\n return 'negative';\n default:\n return type;\n }\n}\n\nexport default function Alert({\n arrow,\n action,\n children,\n className,\n dismissible,\n icon,\n statusIconLabel,\n onDismiss,\n message,\n size,\n title,\n type = 'neutral',\n variant = 'desktop',\n active = true,\n}: AlertProps) {\n useEffect(() => {\n if (arrow !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.\",\n );\n }\n }, [arrow]);\n\n useEffect(() => {\n if (children !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'children' anymore, use 'message' instead.\",\n );\n }\n }, [children]);\n\n useEffect(() => {\n if (dismissible !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.\",\n );\n }\n }, [dismissible]);\n\n useEffect(() => {\n if (size !== undefined) {\n logActionRequired(\"Alert component doesn't support 'size' anymore, please remove that prop.\");\n }\n }, [size]);\n\n const resolvedType = resolveType(type);\n useEffect(() => {\n if (resolvedType !== type) {\n logActionRequired(\n `Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,\n );\n }\n }, [resolvedType, type]);\n\n const [shouldFire, setShouldFire] = useState<boolean>();\n\n const [shouldShow, setShouldShow] = useState<boolean>();\n useEffect(() => {\n if (shouldShow === undefined || !active) {\n setShouldShow(active);\n } else {\n setTimeout(() => setShouldShow(active), WDS_LIVE_REGION_DELAY_MS);\n }\n }, [active, shouldShow]);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>\n {shouldShow && (\n <div\n className={clsx(\n 'alert d-flex',\n `alert-${resolvedType}`,\n arrow != null && alertArrowClassNames(arrow),\n className,\n )}\n data-testid=\"alert\"\n onTouchStart={() => setShouldFire(true)}\n onTouchEnd={(event) => {\n if (\n shouldFire &&\n action?.href &&\n // Check if current event is triggered from closeButton\n event.target instanceof Node &&\n closeButtonReference.current &&\n !closeButtonReference.current.contains(event.target)\n ) {\n if (action.target === '_blank') {\n window.top?.open(action.href);\n } else {\n window.top?.location.assign(action.href);\n }\n }\n setShouldFire(false);\n }}\n onTouchMove={() => setShouldFire(false)}\n >\n <div\n className={clsx('alert__content', 'd-flex', 'flex-grow-1', variant)}\n data-testid={variant}\n >\n {icon ? (\n <div className=\"alert__icon\">{icon}</div>\n ) : (\n <StatusIcon size={Size.LARGE} sentiment={resolvedType} iconLabel={statusIconLabel} />\n )}\n <div className=\"alert__message\">\n <div>\n {title && (\n <Title className=\"m-b-1\" type={Typography.TITLE_BODY}>\n {title}\n </Title>\n )}\n <Body as=\"span\" className=\"d-block\" type={Typography.BODY_LARGE}>\n {children || <InlineMarkdown>{message}</InlineMarkdown>}\n </Body>\n </div>\n {action && <Action action={action} variant=\"action-button\" className=\"m-t-1\" />}\n </div>\n </div>\n {onDismiss && (\n <CloseButton ref={closeButtonReference} className=\"m-l-2\" onClick={onDismiss} />\n )}\n </div>\n )}\n </div>\n );\n}\n\nfunction alertArrowClassNames(arrow: `${AlertArrowPosition}`) {\n switch (arrow) {\n case 'down-center':\n return 'arrow arrow-bottom arrow-center';\n case 'down-left':\n return 'arrow arrow-bottom arrow-left';\n case 'down-right':\n return 'arrow arrow-bottom arrow-right';\n case 'up-center':\n return 'arrow arrow-center';\n case 'up-right':\n return 'arrow arrow-right';\n case 'up-left':\n default:\n return 'arrow';\n }\n}\n"],"names":["AlertArrowPosition","resolveType","type","Alert","arrow","action","children","className","dismissible","icon","statusIconLabel","onDismiss","message","size","title","variant","active","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","shouldShow","setShouldShow","setTimeout","WDS_LIVE_REGION_DELAY_MS","closeButtonReference","useRef","_jsx","role","Sentiment","NEGATIVE","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","StatusIcon","Size","LARGE","sentiment","iconLabel","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mappings":";;;;;;;;;;;;;;;IAqCYA,mBAOX;AAPD,CAAA,UAAYA,kBAAkB,EAAA;AAC5BA,EAAAA,kBAAA,CAAA,UAAA,CAAA,GAAA,SAAoB,CAAA;AACpBA,EAAAA,kBAAA,CAAA,KAAA,CAAA,GAAA,WAAiB,CAAA;AACjBA,EAAAA,kBAAA,CAAA,WAAA,CAAA,GAAA,UAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,aAAA,CAAA,GAAA,WAAyB,CAAA;AACzBA,EAAAA,kBAAA,CAAA,QAAA,CAAA,GAAA,aAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,cAAA,CAAA,GAAA,YAA2B,CAAA;AAC7B,CAAC,EAPWA,kBAAkB,KAAlBA,kBAAkB,GAO7B,EAAA,CAAA,CAAA,CAAA;AAkCD,SAASC,WAAWA,CAACC,IAAe,EAAA;AAClC,EAAA,QAAQA,IAAI;AACV,IAAA,KAAK,SAAS;AACZ,MAAA,OAAO,UAAU,CAAA;AACnB,IAAA,KAAK,MAAM;AACT,MAAA,OAAO,SAAS,CAAA;AAClB,IAA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
|
+
{"version":3,"file":"Alert.mjs","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport {\n CloseButton,\n Sentiment,\n Size,\n Typography,\n Variant,\n WDS_LIVE_REGION_DELAY_MS,\n} from '../common';\n\nimport StatusIcon from '../statusIcon';\nimport Title from '../title/Title';\nimport { logActionRequired } from '../utilities';\n\nimport InlineMarkdown from './inlineMarkdown';\nimport { Action } from '../common/action/Action';\n\nexport type AlertAction = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\n/** @deprecated Use `\"top\" | \"bottom\"` instead. */\ntype AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;\ntype AlertTypeResolved = `${\n | Sentiment.POSITIVE\n | Sentiment.NEUTRAL\n | Sentiment.WARNING\n | Sentiment.NEGATIVE}`;\nexport type AlertType = AlertTypeResolved | AlertTypeDeprecated;\n\nexport enum AlertArrowPosition {\n TOP_LEFT = 'up-left',\n TOP = 'up-center',\n TOP_RIGHT = 'up-right',\n BOTTOM_LEFT = 'down-left',\n BOTTOM = 'down-center',\n BOTTOM_RIGHT = 'down-right',\n}\n\nexport interface AlertProps {\n /** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */\n action?: AlertAction;\n className?: string;\n /** An optional icon. If not provided, we will default the icon to something appropriate for the type */\n icon?: React.ReactNode;\n /**\n * Override for [StatusIcon's default, accessible name](/?path=/docs/other-statusicon-accessibility--docs)\n * announced by the screen readers\n * */\n statusIconLabel?: string;\n /** Title for the alert component */\n title?: string;\n /** The main body of the alert. Accepts plain text and bold words specified with **double stars */\n message?: string;\n /** The presence of the onDismiss handler will trigger the visibility of the close button */\n onDismiss?: React.MouseEventHandler<HTMLButtonElement>;\n /** The type dictates which icon and colour will be used */\n type?: AlertType;\n variant?: `${Variant}`;\n /** @deprecated Safe to remove */\n active?: boolean;\n /** @deprecated Safe to remove */\n dynamicRender?: boolean;\n /** @deprecated Use `InlineAlert` instead. */\n arrow?: `${AlertArrowPosition}`;\n /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */\n children?: React.ReactNode;\n /** @deprecated Use `onDismiss` instead. */\n dismissible?: boolean;\n /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */\n size?: `${Size}`;\n}\n\nfunction resolveType(type: AlertType): AlertTypeResolved {\n switch (type) {\n case 'success':\n return 'positive';\n case 'info':\n return 'neutral';\n case 'error':\n return 'negative';\n default:\n return type;\n }\n}\n\nexport default function Alert({\n action,\n className,\n icon,\n statusIconLabel,\n onDismiss,\n message,\n title,\n type = 'neutral',\n variant = 'desktop',\n arrow,\n children,\n size,\n dismissible,\n active = true,\n dynamicRender,\n}: AlertProps) {\n useEffect(() => {\n if (active !== undefined || dynamicRender !== undefined) {\n logActionRequired(\n \"Alert component doesn't support `active` or `dynamicRender` anymore, please remove that prop.\",\n );\n }\n }, [active, dynamicRender]);\n\n useEffect(() => {\n if (arrow !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.\",\n );\n }\n }, [arrow]);\n\n useEffect(() => {\n if (children !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'children' anymore, use 'message' instead.\",\n );\n }\n }, [children]);\n\n useEffect(() => {\n if (dismissible !== undefined) {\n logActionRequired(\n \"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.\",\n );\n }\n }, [dismissible]);\n\n useEffect(() => {\n if (size !== undefined) {\n logActionRequired(\"Alert component doesn't support 'size' anymore, please remove that prop.\");\n }\n }, [size]);\n\n const resolvedType = resolveType(type);\n useEffect(() => {\n if (resolvedType !== type) {\n logActionRequired(\n `Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,\n );\n }\n }, [resolvedType, type]);\n\n const [shouldFire, setShouldFire] = useState<boolean>();\n\n const [shouldAnnounce, setShouldAnnounce] = useState<boolean>(false);\n useEffect(() => {\n setTimeout(() => {\n setShouldAnnounce(true);\n }, WDS_LIVE_REGION_DELAY_MS);\n }, []);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div\n role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}\n className=\"wds-alert__liveRegion\"\n >\n {active && (\n <div\n aria-hidden={shouldAnnounce ? undefined : 'true'}\n className={clsx(\n 'alert d-flex',\n `alert-${resolvedType}`,\n arrow != null && alertArrowClassNames(arrow),\n className,\n )}\n data-testid=\"alert\"\n onTouchStart={() => setShouldFire(true)}\n onTouchEnd={(event) => {\n if (\n shouldFire &&\n action?.href &&\n // Check if current event is triggered from closeButton\n event.target instanceof Node &&\n closeButtonReference.current &&\n !closeButtonReference.current.contains(event.target)\n ) {\n if (action.target === '_blank') {\n window.top?.open(action.href);\n } else {\n window.top?.location.assign(action.href);\n }\n }\n setShouldFire(false);\n }}\n onTouchMove={() => setShouldFire(false)}\n >\n <div\n className={clsx('alert__content', 'd-flex', 'flex-grow-1', variant)}\n data-testid={variant}\n >\n {icon ? (\n <div className=\"alert__icon\">{icon}</div>\n ) : (\n <StatusIcon size={Size.LARGE} sentiment={resolvedType} iconLabel={statusIconLabel} />\n )}\n <div className=\"alert__message\">\n <div>\n {title && (\n <Title className=\"m-b-1\" type={Typography.TITLE_BODY}>\n {title}\n </Title>\n )}\n <Body as=\"span\" className=\"d-block\" type={Typography.BODY_LARGE}>\n {children || <InlineMarkdown>{message}</InlineMarkdown>}\n </Body>\n </div>\n {action && <Action action={action} variant=\"action-button\" className=\"m-t-1\" />}\n </div>\n </div>\n {onDismiss && (\n <CloseButton ref={closeButtonReference} className=\"m-l-2\" onClick={onDismiss} />\n )}\n </div>\n )}\n </div>\n );\n}\n\nfunction alertArrowClassNames(arrow: `${AlertArrowPosition}`) {\n switch (arrow) {\n case 'down-center':\n return 'arrow arrow-bottom arrow-center';\n case 'down-left':\n return 'arrow arrow-bottom arrow-left';\n case 'down-right':\n return 'arrow arrow-bottom arrow-right';\n case 'up-center':\n return 'arrow arrow-center';\n case 'up-right':\n return 'arrow arrow-right';\n case 'up-left':\n default:\n return 'arrow';\n }\n}\n"],"names":["AlertArrowPosition","resolveType","type","Alert","action","className","icon","statusIconLabel","onDismiss","message","title","variant","arrow","children","size","dismissible","active","dynamicRender","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","shouldAnnounce","setShouldAnnounce","setTimeout","WDS_LIVE_REGION_DELAY_MS","closeButtonReference","useRef","_jsx","role","Sentiment","NEGATIVE","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","StatusIcon","Size","LARGE","sentiment","iconLabel","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mappings":";;;;;;;;;;;;;;;IAqCYA,mBAOX;AAPD,CAAA,UAAYA,kBAAkB,EAAA;AAC5BA,EAAAA,kBAAA,CAAA,UAAA,CAAA,GAAA,SAAoB,CAAA;AACpBA,EAAAA,kBAAA,CAAA,KAAA,CAAA,GAAA,WAAiB,CAAA;AACjBA,EAAAA,kBAAA,CAAA,WAAA,CAAA,GAAA,UAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,aAAA,CAAA,GAAA,WAAyB,CAAA;AACzBA,EAAAA,kBAAA,CAAA,QAAA,CAAA,GAAA,aAAsB,CAAA;AACtBA,EAAAA,kBAAA,CAAA,cAAA,CAAA,GAAA,YAA2B,CAAA;AAC7B,CAAC,EAPWA,kBAAkB,KAAlBA,kBAAkB,GAO7B,EAAA,CAAA,CAAA,CAAA;AAoCD,SAASC,WAAWA,CAACC,IAAe,EAAA;AAClC,EAAA,QAAQA,IAAI;AACV,IAAA,KAAK,SAAS;AACZ,MAAA,OAAO,UAAU,CAAA;AACnB,IAAA,KAAK,MAAM;AACT,MAAA,OAAO,SAAS,CAAA;AAClB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AA;AACzC,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,oBAAoB,CAAA;AAC7B,IAAA,KAAK,UAAU;AACb,MAAA,OAAO,mBAAmB,CAAA;AAC5B,IAAA,KAAK,SAAS,CAAA;AACd,IAAA;AACE,MAAA,OAAO,OAAO,CAAA;AAClB,GAAA;AACF;;;;"}
|
package/build/main.css
CHANGED
package/build/styles/main.css
CHANGED
|
@@ -38,8 +38,10 @@ export interface AlertProps {
|
|
|
38
38
|
/** The type dictates which icon and colour will be used */
|
|
39
39
|
type?: AlertType;
|
|
40
40
|
variant?: `${Variant}`;
|
|
41
|
-
/**
|
|
41
|
+
/** @deprecated Safe to remove */
|
|
42
42
|
active?: boolean;
|
|
43
|
+
/** @deprecated Safe to remove */
|
|
44
|
+
dynamicRender?: boolean;
|
|
43
45
|
/** @deprecated Use `InlineAlert` instead. */
|
|
44
46
|
arrow?: `${AlertArrowPosition}`;
|
|
45
47
|
/** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */
|
|
@@ -49,6 +51,6 @@ export interface AlertProps {
|
|
|
49
51
|
/** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */
|
|
50
52
|
size?: `${Size}`;
|
|
51
53
|
}
|
|
52
|
-
export default function Alert({
|
|
54
|
+
export default function Alert({ action, className, icon, statusIconLabel, onDismiss, message, title, type, variant, arrow, children, size, dismissible, active, dynamicRender, }: AlertProps): import("react").JSX.Element;
|
|
53
55
|
export {};
|
|
54
56
|
//# sourceMappingURL=Alert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.d.ts","sourceRoot":"","sources":["../../../src/alert/Alert.tsx"],"names":[],"mappings":"AAIA,OAAO,EAEL,SAAS,EACT,IAAI,EAEJ,OAAO,EAER,MAAM,WAAW,CAAC;AASnB,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,M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;IACvB,iCAAiC;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,iCAAiC;IACjC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,GAAG,kBAAkB,EAAE,CAAC;IAChC,oHAAoH;IACpH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,2FAA2F;IAC3F,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC;CAClB;AAeD,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAC5B,MAAM,EACN,SAAS,EACT,IAAI,EACJ,eAAe,EACf,SAAS,EACT,OAAO,EACP,KAAK,EACL,IAAgB,EAChB,OAAmB,EACnB,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,MAAa,EACb,aAAa,GACd,EAAE,UAAU,+BA4HZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "46.
|
|
3
|
+
"version": "46.77.0",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -91,9 +91,9 @@
|
|
|
91
91
|
"rollup": "^4.18.1",
|
|
92
92
|
"rollup-preserve-directives": "^1.1.1",
|
|
93
93
|
"storybook": "^8.2.2",
|
|
94
|
-
"@transferwise/less-config": "3.1.0",
|
|
95
94
|
"@transferwise/neptune-css": "14.19.1",
|
|
96
|
-
"@wise/components-theming": "1.6.1"
|
|
95
|
+
"@wise/components-theming": "1.6.1",
|
|
96
|
+
"@transferwise/less-config": "3.1.0"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"@transferwise/icons": "^3.13.1",
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
3
|
import { userEvent, within, expect, waitFor } from '@storybook/test';
|
|
3
4
|
import { Button, Field, SelectInput, Sentiment } from '..';
|
|
4
|
-
import Alert from './Alert';
|
|
5
|
-
|
|
6
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
5
|
+
import Alert, { type AlertProps } from './Alert';
|
|
7
6
|
|
|
8
7
|
const meta = {
|
|
9
8
|
title: 'Feedback/Alert/tests',
|
|
@@ -43,7 +42,7 @@ export const SimpleTrigger: Story = {
|
|
|
43
42
|
Trigger Alert
|
|
44
43
|
</Button>
|
|
45
44
|
|
|
46
|
-
<Alert {...args}
|
|
45
|
+
{isActive && <Alert {...args} className="m-t-4" />}
|
|
47
46
|
</>
|
|
48
47
|
);
|
|
49
48
|
},
|
|
@@ -80,6 +79,134 @@ export const ComplexTrigger: Story = {
|
|
|
80
79
|
/>
|
|
81
80
|
</Field>
|
|
82
81
|
|
|
82
|
+
{isActive && <Alert {...args} className="m-t-2" />}
|
|
83
|
+
</>
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const MultipleDynamicAlerts: Story = {
|
|
89
|
+
play: async ({ canvasElement }) => {
|
|
90
|
+
const canvas = within(canvasElement);
|
|
91
|
+
await expect(canvas.queryAllByRole('status')).toHaveLength(0);
|
|
92
|
+
await expect(canvas.queryAllByRole('alert')).toHaveLength(0);
|
|
93
|
+
await wait();
|
|
94
|
+
await userEvent.tab();
|
|
95
|
+
await userEvent.keyboard('{Enter}');
|
|
96
|
+
await waitFor(async () => expect(canvas.getAllByRole('graphics-symbol')).toHaveLength(3));
|
|
97
|
+
await expect(canvas.getAllByRole('status')).toHaveLength(2);
|
|
98
|
+
await expect(canvas.getAllByRole('alert')).toHaveLength(1);
|
|
99
|
+
},
|
|
100
|
+
render: function Render() {
|
|
101
|
+
const [alerts, setAlerts] = useState<AlertProps[]>([]);
|
|
102
|
+
|
|
103
|
+
const getAlerts: () => AlertProps[] = () => [
|
|
104
|
+
{
|
|
105
|
+
type: Sentiment.POSITIVE,
|
|
106
|
+
title: `Title 1`,
|
|
107
|
+
children: `This is a ${Sentiment.POSITIVE} content`,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: Sentiment.WARNING,
|
|
111
|
+
title: `Title 2`,
|
|
112
|
+
children: `This is a ${Sentiment.WARNING} content`,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: Sentiment.NEGATIVE,
|
|
116
|
+
title: `Title 3`,
|
|
117
|
+
children: `This is a ${Sentiment.NEGATIVE} content`,
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
<Button htmlType="button" onClick={() => setAlerts(getAlerts())}>
|
|
124
|
+
Generate dynamic alerts
|
|
125
|
+
</Button>
|
|
126
|
+
|
|
127
|
+
{alerts.map((props) => (
|
|
128
|
+
<Alert {...props} key={props.title} className="m-t-3" />
|
|
129
|
+
))}
|
|
130
|
+
</>
|
|
131
|
+
);
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** Making sure using `active` is non-breaking **/
|
|
136
|
+
export const SimpleTriggerDeprecated: Story = {
|
|
137
|
+
name: 'Deprecated: Simple Trigger',
|
|
138
|
+
play: async ({ args, canvasElement }) => {
|
|
139
|
+
const canvas = within(canvasElement);
|
|
140
|
+
await wait();
|
|
141
|
+
await userEvent.tab();
|
|
142
|
+
await wait();
|
|
143
|
+
await userEvent.keyboard('{Enter}');
|
|
144
|
+
|
|
145
|
+
await waitFor(async () => expect(canvas.getByText(args.message || '')).toBeInTheDocument());
|
|
146
|
+
await wait(1000);
|
|
147
|
+
await userEvent.keyboard('{Enter}');
|
|
148
|
+
await wait();
|
|
149
|
+
await waitFor(async () =>
|
|
150
|
+
expect(canvas.queryByText(args.message || '')).not.toBeInTheDocument(),
|
|
151
|
+
);
|
|
152
|
+
},
|
|
153
|
+
render: function Render(args) {
|
|
154
|
+
const [isActive, setIsActive] = useState(false);
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<>
|
|
158
|
+
<Button htmlType="button" onClick={() => setIsActive((current) => !current)}>
|
|
159
|
+
Trigger Alert
|
|
160
|
+
</Button>
|
|
161
|
+
|
|
162
|
+
<Alert {...args} active={isActive} className="m-t-4" />
|
|
163
|
+
</>
|
|
164
|
+
);
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/** Making sure using `active` is non-breaking **/
|
|
169
|
+
export const ComplexTriggerDeprecated: Story = {
|
|
170
|
+
name: 'Deprecated: Complex Trigger',
|
|
171
|
+
play: async ({ args, canvasElement }) => {
|
|
172
|
+
const canvas = within(canvasElement);
|
|
173
|
+
await wait();
|
|
174
|
+
await userEvent.tab();
|
|
175
|
+
await wait();
|
|
176
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
177
|
+
await wait();
|
|
178
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
179
|
+
await wait();
|
|
180
|
+
await userEvent.keyboard('{ArrowDown}');
|
|
181
|
+
await wait();
|
|
182
|
+
await userEvent.keyboard('{Enter}');
|
|
183
|
+
|
|
184
|
+
await waitFor(async () => expect(canvas.getByText(args.message || '')).toBeInTheDocument());
|
|
185
|
+
await wait(1000);
|
|
186
|
+
await userEvent.keyboard('{Enter}');
|
|
187
|
+
await wait();
|
|
188
|
+
await userEvent.keyboard('{ArrowUp}');
|
|
189
|
+
await wait();
|
|
190
|
+
await userEvent.keyboard('{Enter}');
|
|
191
|
+
// await waitFor(async () => expect(canvas.queryByText(args.message || '')).not.toBeInTheDocument());
|
|
192
|
+
},
|
|
193
|
+
render: function Render(args) {
|
|
194
|
+
const [isActive, setIsActive] = useState(false);
|
|
195
|
+
const [value, setValue] = useState<string>();
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<>
|
|
199
|
+
<Field label="Select option to triger Alert">
|
|
200
|
+
<SelectInput
|
|
201
|
+
items={[
|
|
202
|
+
{ type: 'option', value: 'one' },
|
|
203
|
+
{ type: 'option', value: 'two' },
|
|
204
|
+
]}
|
|
205
|
+
onChange={setValue}
|
|
206
|
+
onClose={() => setIsActive(Boolean(value === 'two'))}
|
|
207
|
+
/>
|
|
208
|
+
</Field>
|
|
209
|
+
|
|
83
210
|
<Alert {...args} active={isActive} className="m-t-2" />
|
|
84
211
|
</>
|
|
85
212
|
);
|
package/src/alert/Alert.spec.tsx
CHANGED
|
@@ -4,7 +4,14 @@ import { ThemeProvider } from '@wise/components-theming';
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
|
|
6
6
|
import { Sentiment, Size, Theme, Variant } from '../common';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
render,
|
|
9
|
+
cleanup,
|
|
10
|
+
screen,
|
|
11
|
+
userEvent as user,
|
|
12
|
+
fireEvent,
|
|
13
|
+
mockMatchMedia,
|
|
14
|
+
} from '../test-utils';
|
|
8
15
|
|
|
9
16
|
import Alert, { AlertAction, AlertArrowPosition, AlertType } from './Alert';
|
|
10
17
|
|
|
@@ -25,6 +32,9 @@ describe('Alert', () => {
|
|
|
25
32
|
let alert: HTMLElement;
|
|
26
33
|
let closeButton: HTMLElement;
|
|
27
34
|
let action: AlertAction;
|
|
35
|
+
const userEvent = user.setup({
|
|
36
|
+
advanceTimers: jest.advanceTimersByTimeAsync,
|
|
37
|
+
});
|
|
28
38
|
|
|
29
39
|
const classForType = (type: AlertType) => `alert-${type}`;
|
|
30
40
|
|
|
@@ -39,7 +49,6 @@ describe('Alert', () => {
|
|
|
39
49
|
});
|
|
40
50
|
|
|
41
51
|
afterEach(() => {
|
|
42
|
-
cleanup();
|
|
43
52
|
jest.clearAllMocks();
|
|
44
53
|
});
|
|
45
54
|
|
|
@@ -100,6 +109,24 @@ describe('Alert', () => {
|
|
|
100
109
|
);
|
|
101
110
|
});
|
|
102
111
|
|
|
112
|
+
it('active is ignored and a warning is logged', () => {
|
|
113
|
+
render(<Alert active message={message} />);
|
|
114
|
+
|
|
115
|
+
expect(screen.getByText(message)).toBeInTheDocument();
|
|
116
|
+
expect(mockedWarn).toHaveBeenCalledWith(
|
|
117
|
+
expect.stringMatching(/Alert component doesn't support `active`/),
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('dynamicRender is ignored and a warning is logged', () => {
|
|
122
|
+
render(<Alert dynamicRender message={message} />);
|
|
123
|
+
|
|
124
|
+
expect(screen.getByText(message)).toBeInTheDocument();
|
|
125
|
+
expect(mockedWarn).toHaveBeenCalledWith(
|
|
126
|
+
expect.stringMatching(/Alert component doesn't support.*?`dynamicRender`/),
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
103
130
|
it('dismissible is ignored and a warning is logged', () => {
|
|
104
131
|
({ container } = render(<Alert dismissible message={message} />));
|
|
105
132
|
|
|
@@ -252,18 +279,17 @@ describe('Alert', () => {
|
|
|
252
279
|
});
|
|
253
280
|
|
|
254
281
|
describe('onDismiss', () => {
|
|
255
|
-
it('renders the close button if onDismiss is provided', () => {
|
|
282
|
+
it('renders the close button if onDismiss is provided', async () => {
|
|
256
283
|
render(<Alert message={message} onDismiss={jest.fn()} />);
|
|
257
|
-
|
|
258
|
-
expect(
|
|
284
|
+
const button = await screen.findByRole('button', { name: 'Close' });
|
|
285
|
+
expect(button).toBeEnabled();
|
|
259
286
|
});
|
|
260
287
|
|
|
261
288
|
it('calls onDismiss when the close button is clicked', async () => {
|
|
262
289
|
const onDismiss = jest.fn();
|
|
263
|
-
|
|
264
290
|
render(<Alert message={message} onDismiss={onDismiss} />);
|
|
265
|
-
|
|
266
|
-
await userEvent.click(
|
|
291
|
+
const button = await screen.findByRole('button', { name: 'Close' });
|
|
292
|
+
await userEvent.click(button);
|
|
267
293
|
|
|
268
294
|
expect(onDismiss).toHaveBeenCalledTimes(1);
|
|
269
295
|
});
|
|
@@ -478,7 +504,7 @@ describe('Alert', () => {
|
|
|
478
504
|
});
|
|
479
505
|
});
|
|
480
506
|
|
|
481
|
-
describe('`active` prop', () => {
|
|
507
|
+
describe('`active` prop backward compatibility', () => {
|
|
482
508
|
it('should render wrapper and alert if `active` is unset', () => {
|
|
483
509
|
render(<Alert message={message} />);
|
|
484
510
|
expect(screen.getByRole('status')).toBeInTheDocument();
|
|
@@ -492,7 +518,7 @@ describe('Alert', () => {
|
|
|
492
518
|
});
|
|
493
519
|
|
|
494
520
|
it('should render wrapper and alert if `active` is set', () => {
|
|
495
|
-
render(<Alert message={message} />);
|
|
521
|
+
render(<Alert message={message} active />);
|
|
496
522
|
expect(screen.getByRole('status')).toBeInTheDocument();
|
|
497
523
|
expect(screen.getByText(message)).toBeInTheDocument();
|
|
498
524
|
});
|
|
@@ -5,14 +5,13 @@ import { ClockBorderless } from '@transferwise/icons';
|
|
|
5
5
|
|
|
6
6
|
import { Sentiment } from '../common';
|
|
7
7
|
import { Button, Field, SelectInput } from '..';
|
|
8
|
-
import Alert, { AlertArrowPosition } from './Alert';
|
|
8
|
+
import Alert, { AlertArrowPosition, type AlertProps as FullAlertProps } from './Alert';
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
11
|
component: Alert,
|
|
12
12
|
title: 'Feedback/Alert',
|
|
13
13
|
args: {
|
|
14
14
|
type: Sentiment.POSITIVE,
|
|
15
|
-
active: true,
|
|
16
15
|
message:
|
|
17
16
|
'Payments sent to your bank details **today** might not arrive in time for the holidays.',
|
|
18
17
|
},
|
|
@@ -106,30 +105,43 @@ export const WithTitle: Story = {
|
|
|
106
105
|
};
|
|
107
106
|
|
|
108
107
|
/**
|
|
109
|
-
* For ARIA live region to function correctly with screen readers,
|
|
108
|
+
* For ARIA live region to function correctly with screen readers (SR),
|
|
110
109
|
* the container with an appropriate ARIA role (in the case of this
|
|
111
110
|
* component, it's `status` or `alert`) must be rendered first.
|
|
112
111
|
* Once present in the accessibility tree (AT), its dynamic contents
|
|
113
112
|
* will be announced correctly.
|
|
114
113
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
114
|
+
* It's not a problem if your page includes an Alert that is initially
|
|
115
|
+
* visible at the very first render, but if it appears as a result of
|
|
116
|
+
* user interaction or is async, e.g. BE-driven, then the screen reader
|
|
117
|
+
* might not announce it correctly. It becomes even more tricky if an
|
|
118
|
+
* Alert is triggerred by a component that causes refocusing or introduces
|
|
119
|
+
* many modifications to the AT, such as MoneyInput, for example, as that
|
|
120
|
+
* entirely hijacks screen-reader's attention and prevents it from
|
|
121
|
+
* announcing live region changes.
|
|
118
122
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
123
|
+
* In order for this to work, we've introduced a simple mechanism which
|
|
124
|
+
* overcomes all of the above:
|
|
125
|
+
* 1. On the component mount, we render the live region wrapper.
|
|
126
|
+
* 2. We also render the actual Alert but set `aria-hidden` on it.
|
|
127
|
+
* 3. After 175ms, which has been confirmed as sufficient delay for
|
|
128
|
+
* the SRs to become responsive after trigger's activity, we remove the
|
|
129
|
+
* `aria-hidden` attribute, which, in turn, initiates the announcements.
|
|
130
|
+
*
|
|
131
|
+
* **NB:** While this approach has no visual side-effects (e.g. layout
|
|
132
|
+
* shift), it makes the Alert hidden from the assistive tech for 175ms.
|
|
133
|
+
* It's our belief that such short pause between announcements is
|
|
134
|
+
* negligible for the user.
|
|
124
135
|
*/
|
|
125
|
-
export const
|
|
136
|
+
export const DynamicRender: Story = {
|
|
126
137
|
render: function Render(args) {
|
|
127
|
-
const [
|
|
138
|
+
const [isOneActive, setIsOneActive] = useState(false);
|
|
139
|
+
const [isTwoActive, setIsTwoActive] = useState(false);
|
|
128
140
|
const [value, setValue] = useState<string>();
|
|
129
141
|
|
|
130
142
|
return (
|
|
131
143
|
<>
|
|
132
|
-
<Button htmlType="button" onClick={() =>
|
|
144
|
+
<Button htmlType="button" onClick={() => setIsOneActive(true)}>
|
|
133
145
|
Trigger Alert
|
|
134
146
|
</Button>
|
|
135
147
|
|
|
@@ -140,11 +152,16 @@ export const ConditionallyRendered: Story = {
|
|
|
140
152
|
{ type: 'option', value: 'two' },
|
|
141
153
|
]}
|
|
142
154
|
onChange={setValue}
|
|
143
|
-
onClose={() =>
|
|
155
|
+
onClose={() => setIsTwoActive(value === 'two')}
|
|
144
156
|
/>
|
|
145
157
|
</Field>
|
|
146
158
|
|
|
147
|
-
<Alert {...args}
|
|
159
|
+
{isOneActive && <Alert {...args}>This Alert has a simple trigger.</Alert>}
|
|
160
|
+
{isTwoActive && (
|
|
161
|
+
<Alert {...args} type={Sentiment.WARNING}>
|
|
162
|
+
This Alert has a complex trigger.
|
|
163
|
+
</Alert>
|
|
164
|
+
)}
|
|
148
165
|
</>
|
|
149
166
|
);
|
|
150
167
|
},
|
|
@@ -153,27 +170,33 @@ export const ConditionallyRendered: Story = {
|
|
|
153
170
|
source: {
|
|
154
171
|
code: `
|
|
155
172
|
function Render(args) {
|
|
156
|
-
|
|
157
|
-
|
|
173
|
+
const [isOneActive, setIsOneActive] = useState(false);
|
|
174
|
+
const [isTwoActive, setIsTwoActive] = useState(false);
|
|
175
|
+
const [value, setValue] = useState<string>();
|
|
158
176
|
|
|
159
177
|
return (
|
|
160
178
|
<>
|
|
161
|
-
<Button htmlType="button" onClick={() =>
|
|
179
|
+
<Button htmlType="button" onClick={() => setIsOneActive(true)}>
|
|
162
180
|
Trigger Alert
|
|
163
181
|
</Button>
|
|
164
182
|
|
|
165
|
-
<Field label="Select
|
|
183
|
+
<Field label="Select \`two\` to triger Alert" className="m-t-3">
|
|
166
184
|
<SelectInput
|
|
167
185
|
items={[
|
|
168
186
|
{ type: 'option', value: 'one' },
|
|
169
187
|
{ type: 'option', value: 'two' },
|
|
170
188
|
]}
|
|
171
189
|
onChange={setValue}
|
|
172
|
-
onClose={() =>
|
|
190
|
+
onClose={() => setIsTwoActive(value === 'two')}
|
|
173
191
|
/>
|
|
174
192
|
</Field>
|
|
175
|
-
|
|
176
|
-
<Alert {...args}
|
|
193
|
+
|
|
194
|
+
{isOneActive && <Alert {...args}>This Alert has a simple trigger.</Alert>}
|
|
195
|
+
{isTwoActive && (
|
|
196
|
+
<Alert {...args} type={Sentiment.WARNING}>
|
|
197
|
+
This Alert has a complex trigger.
|
|
198
|
+
</Alert>
|
|
199
|
+
)}
|
|
177
200
|
</>
|
|
178
201
|
);
|
|
179
202
|
}`,
|
|
@@ -181,3 +204,91 @@ function Render(args) {
|
|
|
181
204
|
},
|
|
182
205
|
},
|
|
183
206
|
};
|
|
207
|
+
|
|
208
|
+
const SENTIMENT = [
|
|
209
|
+
Sentiment.POSITIVE,
|
|
210
|
+
Sentiment.NEGATIVE,
|
|
211
|
+
Sentiment.NEUTRAL,
|
|
212
|
+
Sentiment.WARNING,
|
|
213
|
+
] as const;
|
|
214
|
+
type AlertProps = Omit<FullAlertProps, 'type'> & { type: (typeof SENTIMENT)[number] };
|
|
215
|
+
const getAlerts = () => {
|
|
216
|
+
const length = Math.ceil(2 + Math.random() * 3);
|
|
217
|
+
|
|
218
|
+
return Array.from({ length }, (_, index) => {
|
|
219
|
+
const type = SENTIMENT[Math.floor(Math.random() * SENTIMENT.length)];
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
type,
|
|
223
|
+
title: `Title ${index + 1}`,
|
|
224
|
+
children: `This is a ${type} content`,
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Sometimes, especially when dealing with Backend for Frontend (BFF),
|
|
231
|
+
* it's not just about conditional rendering but also the fact that
|
|
232
|
+
* you don't know how many `Alert`s you'll need to render.
|
|
233
|
+
*
|
|
234
|
+
* If you have to inject multiple Alerts simultaneously into the page,
|
|
235
|
+
* please note that we currently have no means of guaranteeing the order
|
|
236
|
+
* in which they screen reader will read them out.
|
|
237
|
+
*/
|
|
238
|
+
export const MultipleDynamicAlerts: Story = {
|
|
239
|
+
render: function Render() {
|
|
240
|
+
const [isActive, setIsActive] = useState(false);
|
|
241
|
+
const [alerts, setAlerts] = useState<AlertProps[]>([]);
|
|
242
|
+
|
|
243
|
+
return (
|
|
244
|
+
<>
|
|
245
|
+
<Button
|
|
246
|
+
htmlType="button"
|
|
247
|
+
onClick={() => {
|
|
248
|
+
setAlerts(isActive ? [] : getAlerts());
|
|
249
|
+
setIsActive((current) => !current);
|
|
250
|
+
}}
|
|
251
|
+
>
|
|
252
|
+
Generate dynamic alerts
|
|
253
|
+
</Button>
|
|
254
|
+
|
|
255
|
+
{alerts.map((props) => (
|
|
256
|
+
<Alert {...props} key={props.title} className="m-t-3" />
|
|
257
|
+
))}
|
|
258
|
+
</>
|
|
259
|
+
);
|
|
260
|
+
},
|
|
261
|
+
parameters: {
|
|
262
|
+
docs: {
|
|
263
|
+
source: {
|
|
264
|
+
code: `
|
|
265
|
+
function Render() {
|
|
266
|
+
const [isActive, setIsActive] = useState(false);
|
|
267
|
+
const [alerts, setAlerts] = useState<AlertProps[]>([]);
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<>
|
|
271
|
+
<Button
|
|
272
|
+
htmlType="button"
|
|
273
|
+
onClick={() => {
|
|
274
|
+
setAlerts(isActive ? [] : getAlerts());
|
|
275
|
+
setIsActive((current) => !current);
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
Generate dynamic alerts
|
|
279
|
+
</Button>
|
|
280
|
+
|
|
281
|
+
{alerts.map(props => (
|
|
282
|
+
<Alert
|
|
283
|
+
{...props}
|
|
284
|
+
key={props.title}
|
|
285
|
+
className="m-t-3"
|
|
286
|
+
/>
|
|
287
|
+
))}
|
|
288
|
+
</>
|
|
289
|
+
);
|
|
290
|
+
},`,
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
};
|
package/src/alert/Alert.tsx
CHANGED
|
@@ -64,8 +64,10 @@ export interface AlertProps {
|
|
|
64
64
|
/** The type dictates which icon and colour will be used */
|
|
65
65
|
type?: AlertType;
|
|
66
66
|
variant?: `${Variant}`;
|
|
67
|
-
/**
|
|
67
|
+
/** @deprecated Safe to remove */
|
|
68
68
|
active?: boolean;
|
|
69
|
+
/** @deprecated Safe to remove */
|
|
70
|
+
dynamicRender?: boolean;
|
|
69
71
|
/** @deprecated Use `InlineAlert` instead. */
|
|
70
72
|
arrow?: `${AlertArrowPosition}`;
|
|
71
73
|
/** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */
|
|
@@ -90,21 +92,30 @@ function resolveType(type: AlertType): AlertTypeResolved {
|
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
export default function Alert({
|
|
93
|
-
arrow,
|
|
94
95
|
action,
|
|
95
|
-
children,
|
|
96
96
|
className,
|
|
97
|
-
dismissible,
|
|
98
97
|
icon,
|
|
99
98
|
statusIconLabel,
|
|
100
99
|
onDismiss,
|
|
101
100
|
message,
|
|
102
|
-
size,
|
|
103
101
|
title,
|
|
104
102
|
type = 'neutral',
|
|
105
103
|
variant = 'desktop',
|
|
104
|
+
arrow,
|
|
105
|
+
children,
|
|
106
|
+
size,
|
|
107
|
+
dismissible,
|
|
106
108
|
active = true,
|
|
109
|
+
dynamicRender,
|
|
107
110
|
}: AlertProps) {
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (active !== undefined || dynamicRender !== undefined) {
|
|
113
|
+
logActionRequired(
|
|
114
|
+
"Alert component doesn't support `active` or `dynamicRender` anymore, please remove that prop.",
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}, [active, dynamicRender]);
|
|
118
|
+
|
|
108
119
|
useEffect(() => {
|
|
109
120
|
if (arrow !== undefined) {
|
|
110
121
|
logActionRequired(
|
|
@@ -146,21 +157,23 @@ export default function Alert({
|
|
|
146
157
|
|
|
147
158
|
const [shouldFire, setShouldFire] = useState<boolean>();
|
|
148
159
|
|
|
149
|
-
const [
|
|
160
|
+
const [shouldAnnounce, setShouldAnnounce] = useState<boolean>(false);
|
|
150
161
|
useEffect(() => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
}, [active, shouldShow]);
|
|
162
|
+
setTimeout(() => {
|
|
163
|
+
setShouldAnnounce(true);
|
|
164
|
+
}, WDS_LIVE_REGION_DELAY_MS);
|
|
165
|
+
}, []);
|
|
157
166
|
|
|
158
167
|
const closeButtonReference = useRef<HTMLButtonElement>(null);
|
|
159
168
|
|
|
160
169
|
return (
|
|
161
|
-
<div
|
|
162
|
-
{
|
|
170
|
+
<div
|
|
171
|
+
role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}
|
|
172
|
+
className="wds-alert__liveRegion"
|
|
173
|
+
>
|
|
174
|
+
{active && (
|
|
163
175
|
<div
|
|
176
|
+
aria-hidden={shouldAnnounce ? undefined : 'true'}
|
|
164
177
|
className={clsx(
|
|
165
178
|
'alert d-flex',
|
|
166
179
|
`alert-${resolvedType}`,
|
package/src/main.css
CHANGED
package/src/main.less
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
@import "./criticalBanner/CriticalCommsBanner.less";
|
|
2
2
|
@import "./accordion/Accordion.less";
|
|
3
3
|
@import "./actionButton/ActionButton.less";
|
|
4
|
+
@import "./alert/Alert.less";
|
|
4
5
|
@import "./avatar/Avatar.less";
|
|
5
6
|
@import "./badge/Badge.less";
|
|
6
7
|
@import "./button/Button.less";
|