@transferwise/components 46.75.0 → 46.76.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.
@@ -52,7 +52,8 @@ function Alert({
52
52
  title,
53
53
  type = 'neutral',
54
54
  variant = 'desktop',
55
- active = true
55
+ active = true,
56
+ dynamicRender = false
56
57
  }) {
57
58
  React.useEffect(() => {
58
59
  if (arrow !== undefined) {
@@ -83,15 +84,16 @@ function Alert({
83
84
  const [shouldFire, setShouldFire] = React.useState();
84
85
  const [shouldShow, setShouldShow] = React.useState();
85
86
  React.useEffect(() => {
86
- if (shouldShow === undefined || !active) {
87
+ if (shouldShow === undefined && !dynamicRender || !active) {
87
88
  setShouldShow(active);
88
89
  } else {
89
90
  setTimeout(() => setShouldShow(active), constants.WDS_LIVE_REGION_DELAY_MS);
90
91
  }
91
- }, [active, shouldShow]);
92
+ }, [active, shouldShow, dynamicRender]);
92
93
  const closeButtonReference = React.useRef(null);
93
94
  return /*#__PURE__*/jsxRuntime.jsx("div", {
94
95
  role: resolvedType === sentiment.Sentiment.NEGATIVE ? 'alert' : 'status',
96
+ className: "wds-alert__liveRegion",
95
97
  children: shouldShow && /*#__PURE__*/jsxRuntime.jsxs("div", {
96
98
  className: clsx.clsx('alert d-flex', `alert-${resolvedType}`, arrow != null && alertArrowClassNames(arrow), className),
97
99
  "data-testid": "alert",
@@ -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","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O,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 /**\n * Controls rendering of the Alert component. <br />\n * Toggle this prop instead using conditional rendering and logical AND (&&)\n * operator, to make the component work with screen readers.\n * @deprecated use `dynamicRender`\n * */\n active?: boolean;\n /**\n * Toggle this prop when dealing with multiple, dynamic Alerts, to make them\n * work with screen readers. This is especially helpful for the BFF use cases.\n * */\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 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 dynamicRender = false,\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 && !dynamicRender) || !active) {\n setShouldShow(active);\n } else {\n setTimeout(() => setShouldShow(active), WDS_LIVE_REGION_DELAY_MS);\n }\n }, [active, shouldShow, dynamicRender]);\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 {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","dynamicRender","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;AA4CD,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,IAAI;AACbC,EAAAA,aAAa,GAAG,KAAA;AACL,CAAA,EAAA;AACXC,EAAAA,eAAS,CAAC,MAAK;IACb,IAAId,KAAK,KA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BAAI0B,cAAA,CAACiC,aAAM,EAAA;AAAC3D,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,iBACRoB,cAAA,CAACkC,uBAAW,EAAA;AAACC,QAAAA,GAAG,EAAErC,oBAAqB;AAACtB,QAAAA,SAAS,EAAC,OAAO;AAAC4D,QAAAA,OAAO,EAAExD,SAAAA;AAAU,OAAG,CACjF,CAAA;KACE,CAAA;AACN,GACE,CAAC,CAAA;AAEV,CAAA;AAEA,SAAS0B,oBAAoBA,CAACjC,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;;;;"}
@@ -48,7 +48,8 @@ function Alert({
48
48
  title,
49
49
  type = 'neutral',
50
50
  variant = 'desktop',
51
- active = true
51
+ active = true,
52
+ dynamicRender = false
52
53
  }) {
53
54
  useEffect(() => {
54
55
  if (arrow !== undefined) {
@@ -79,15 +80,16 @@ function Alert({
79
80
  const [shouldFire, setShouldFire] = useState();
80
81
  const [shouldShow, setShouldShow] = useState();
81
82
  useEffect(() => {
82
- if (shouldShow === undefined || !active) {
83
+ if (shouldShow === undefined && !dynamicRender || !active) {
83
84
  setShouldShow(active);
84
85
  } else {
85
86
  setTimeout(() => setShouldShow(active), WDS_LIVE_REGION_DELAY_MS);
86
87
  }
87
- }, [active, shouldShow]);
88
+ }, [active, shouldShow, dynamicRender]);
88
89
  const closeButtonReference = useRef(null);
89
90
  return /*#__PURE__*/jsx("div", {
90
91
  role: resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status',
92
+ className: "wds-alert__liveRegion",
91
93
  children: shouldShow && /*#__PURE__*/jsxs("div", {
92
94
  className: clsx('alert d-flex', `alert-${resolvedType}`, arrow != null && alertArrowClassNames(arrow), className),
93
95
  "data-testid": "alert",
@@ -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,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,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.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 /**\n * Controls rendering of the Alert component. <br />\n * Toggle this prop instead using conditional rendering and logical AND (&&)\n * operator, to make the component work with screen readers.\n * @deprecated use `dynamicRender`\n * */\n active?: boolean;\n /**\n * Toggle this prop when dealing with multiple, dynamic Alerts, to make them\n * work with screen readers. This is especially helpful for the BFF use cases.\n * */\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 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 dynamicRender = false,\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 && !dynamicRender) || !active) {\n setShouldShow(active);\n } else {\n setTimeout(() => setShouldShow(active), WDS_LIVE_REGION_DELAY_MS);\n }\n }, [active, shouldShow, dynamicRender]);\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 {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","dynamicRender","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,KAA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,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/main.css CHANGED
@@ -216,6 +216,9 @@ div.critical-comms .critical-comms-body {
216
216
  .np-action-btn:not(:disabled):focus {
217
217
  box-shadow: none;
218
218
  }
219
+ .wds-alert__liveRegion {
220
+ display: contents;
221
+ }
219
222
  .tw-avatar {
220
223
  position: relative;
221
224
  -webkit-user-select: none;
@@ -0,0 +1,3 @@
1
+ .wds-alert__liveRegion {
2
+ display: contents;
3
+ }
@@ -216,6 +216,9 @@ div.critical-comms .critical-comms-body {
216
216
  .np-action-btn:not(:disabled):focus {
217
217
  box-shadow: none;
218
218
  }
219
+ .wds-alert__liveRegion {
220
+ display: contents;
221
+ }
219
222
  .tw-avatar {
220
223
  position: relative;
221
224
  -webkit-user-select: none;
@@ -38,8 +38,18 @@ export interface AlertProps {
38
38
  /** The type dictates which icon and colour will be used */
39
39
  type?: AlertType;
40
40
  variant?: `${Variant}`;
41
- /** 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. */
41
+ /**
42
+ * Controls rendering of the Alert component. <br />
43
+ * Toggle this prop instead using conditional rendering and logical AND (&&)
44
+ * operator, to make the component work with screen readers.
45
+ * @deprecated use `dynamicRender`
46
+ * */
42
47
  active?: boolean;
48
+ /**
49
+ * Toggle this prop when dealing with multiple, dynamic Alerts, to make them
50
+ * work with screen readers. This is especially helpful for the BFF use cases.
51
+ * */
52
+ dynamicRender?: boolean;
43
53
  /** @deprecated Use `InlineAlert` instead. */
44
54
  arrow?: `${AlertArrowPosition}`;
45
55
  /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */
@@ -49,6 +59,6 @@ export interface AlertProps {
49
59
  /** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */
50
60
  size?: `${Size}`;
51
61
  }
52
- export default function Alert({ arrow, action, children, className, dismissible, icon, statusIconLabel, onDismiss, message, size, title, type, variant, active, }: AlertProps): import("react").JSX.Element;
62
+ export default function Alert({ arrow, action, children, className, dismissible, icon, statusIconLabel, onDismiss, message, size, title, type, variant, active, dynamicRender, }: AlertProps): import("react").JSX.Element;
53
63
  export {};
54
64
  //# 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,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,kDAAkD;AAClD,KAAK,mBAAmB,GAAG,GAAG,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC;AACrF,KAAK,iBAAiB,GAAG,GACrB,SAAS,CAAC,QAAQ,GAClB,SAAS,CAAC,OAAO,GACjB,SAAS,CAAC,OAAO,GACjB,SAAS,CAAC,QAAQ,EAAE,CAAC;AACzB,MAAM,MAAM,SAAS,GAAG,iBAAiB,GAAG,mBAAmB,CAAC;AAEhE,oBAAY,kBAAkB;IAC5B,QAAQ,YAAY;IACpB,GAAG,cAAc;IACjB,SAAS,aAAa;IACtB,WAAW,cAAc;IACzB,MA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CAAC,EAAE,OAAO,CAAC;IACjB;;;SAGK;IACL,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,KAAK,EACL,MAAM,EACN,QAAQ,EACR,SAAS,EACT,WAAW,EACX,IAAI,EACJ,eAAe,EACf,SAAS,EACT,OAAO,EACP,IAAI,EACJ,KAAK,EACL,IAAgB,EAChB,OAAmB,EACnB,MAAa,EACb,aAAqB,GACtB,EAAE,UAAU,+BAqHZ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "46.75.0",
3
+ "version": "46.76.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",
@@ -0,0 +1,3 @@
1
+ .wds-alert__liveRegion {
2
+ display: contents;
3
+ }
@@ -0,0 +1,3 @@
1
+ .wds-alert__liveRegion {
2
+ display: contents;
3
+ }
@@ -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} active={isActive} className="m-t-4" />
45
+ {isActive && <Alert {...args} dynamicRender className="m-t-4" />}
47
46
  </>
48
47
  );
49
48
  },
@@ -80,7 +79,54 @@ export const ComplexTrigger: Story = {
80
79
  />
81
80
  </Field>
82
81
 
83
- <Alert {...args} active={isActive} className="m-t-2" />
82
+ {isActive && <Alert dynamicRender {...args} className="m-t-2" />}
83
+ </>
84
+ );
85
+ },
86
+ };
87
+
88
+ export const BackendForFrontend: 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 dynamicRender {...props} key={props.title} className="m-t-3" />
129
+ ))}
84
130
  </>
85
131
  );
86
132
  },
@@ -497,4 +497,8 @@ describe('Alert', () => {
497
497
  expect(screen.getByText(message)).toBeInTheDocument();
498
498
  });
499
499
  });
500
+
501
+ describe('dynamicRender', () => {
502
+ it('should', () => {});
503
+ });
500
504
  });
@@ -5,16 +5,17 @@ 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,
15
+ dynamicRender: false,
16
16
  message:
17
17
  'Payments sent to your bank details **today** might not arrive in time for the holidays.',
18
+ active: true,
18
19
  },
19
20
  argTypes: {
20
21
  arrow: {
@@ -112,17 +113,22 @@ export const WithTitle: Story = {
112
113
  * Once present in the accessibility tree (AT), its dynamic contents
113
114
  * will be announced correctly.
114
115
  *
115
- * Because of that, using logical AND (&&) operator is discouraged
116
- * and, instead, engineers should toggle the `active` prop which
117
- * provides that logic internally.
116
+ * It's not a problem if your page includes an Alert that is initially
117
+ * visible upon the very first render, but if it appears as a result
118
+ * of some interaction or is async, e.g. BE-driven then the screen
119
+ * reader might not announce it correctly.
120
+ *
121
+ * In order for this to work, we've introduced a small delay (175ms)
122
+ * between mounting the Alert's live region wrapper and actual DOM
123
+ * content injection to allow screen readers to process it correctly.
124
+ * It also to compensates for focus and AT manipulations commonly
125
+ * introduced by more complex triggers like e.g. `SelectInput`,
126
+ * which prevent the screen readers from announcing simultaneous
127
+ * changes on the page.
118
128
  *
119
- * We're additionally adding a small delay (175ms) between toggling
120
- * the `active` prop and actual DOM injection to compensate for some
121
- * common triggers like e.g. `SelectInput`. Those components affect
122
- * the AT and have programmatic focus control, which prevents the
123
- * screen readers from announcing simultaneous changes on the page.
129
+ * In those cases you should enable the `dynamicRender` prop.
124
130
  */
125
- export const ConditionallyRendered: Story = {
131
+ export const DynamicRender: Story = {
126
132
  render: function Render(args) {
127
133
  const [isActive, setIsActive] = useState(false);
128
134
  const [value, setValue] = useState<string>();
@@ -144,7 +150,7 @@ export const ConditionallyRendered: Story = {
144
150
  />
145
151
  </Field>
146
152
 
147
- <Alert {...args} active={isActive} className="m-t-5" />
153
+ {isActive && <Alert {...args} dynamicRender className="m-t-5" />}
148
154
  </>
149
155
  );
150
156
  },
@@ -173,7 +179,7 @@ function Render(args) {
173
179
  />
174
180
  </Field>
175
181
 
176
- <Alert {...args} active={isActive} className="m-t-5" />
182
+ {isActive && <Alert {...args} dynamicRender className="m-t-5" />}
177
183
  </>
178
184
  );
179
185
  }`,
@@ -181,3 +187,93 @@ function Render(args) {
181
187
  },
182
188
  },
183
189
  };
190
+
191
+ const SENTIMENT = [
192
+ Sentiment.POSITIVE,
193
+ Sentiment.NEGATIVE,
194
+ Sentiment.NEUTRAL,
195
+ Sentiment.WARNING,
196
+ ] as const;
197
+ type AlertProps = Omit<FullAlertProps, 'type'> & { type: (typeof SENTIMENT)[number] };
198
+ const getAlerts = () => {
199
+ const length = Math.ceil(2 + Math.random() * 3);
200
+
201
+ return Array.from({ length }, (_, index) => {
202
+ const type = SENTIMENT[Math.floor(Math.random() * SENTIMENT.length)];
203
+
204
+ return {
205
+ type,
206
+ title: `Title ${index + 1}`,
207
+ children: `This is a ${type} content`,
208
+ };
209
+ });
210
+ };
211
+
212
+ /**
213
+ * When dealing with Backend for Frontend (BFF), sometimes it's not
214
+ * just about conditional rendering but also the fact you don't
215
+ * know how many `Alert`s you're going to get and when.
216
+ *
217
+ * `dynamicRender` prop will work with those scenarios as well.
218
+ *
219
+ * **NB:** Screen readers do not guarantee the order in which they
220
+ * read out multiple injected sibling nodes.
221
+ */
222
+ export const BackendForFrontend: Story = {
223
+ render: function Render() {
224
+ const [isActive, setIsActive] = useState(false);
225
+ const [alerts, setAlerts] = useState<AlertProps[]>([]);
226
+
227
+ return (
228
+ <>
229
+ <Button
230
+ htmlType="button"
231
+ onClick={() => {
232
+ setAlerts(isActive ? [] : getAlerts());
233
+ setIsActive((current) => !current);
234
+ }}
235
+ >
236
+ Generate dynamic alerts
237
+ </Button>
238
+
239
+ {alerts.map((props) => (
240
+ <Alert {...props} key={props.title} dynamicRender className="m-t-3" />
241
+ ))}
242
+ </>
243
+ );
244
+ },
245
+ parameters: {
246
+ docs: {
247
+ source: {
248
+ code: `
249
+ function Render() {
250
+ const [isActive, setIsActive] = useState(false);
251
+ const [alerts, setAlerts] = useState<AlertProps[]>([]);
252
+
253
+ return (
254
+ <>
255
+ <Button
256
+ htmlType="button"
257
+ onClick={() => {
258
+ setAlerts(isActive ? [] : getAlerts());
259
+ setIsActive((current) => !current);
260
+ }}
261
+ >
262
+ Generate dynamic alerts
263
+ </Button>
264
+
265
+ {alerts.map(props => (
266
+ <Alert
267
+ {...props}
268
+ key={props.title}
269
+ className="m-t-3"
270
+ dynamicRender
271
+ />
272
+ ))}
273
+ </>
274
+ );
275
+ },`,
276
+ },
277
+ },
278
+ },
279
+ };
@@ -64,8 +64,18 @@ export interface AlertProps {
64
64
  /** The type dictates which icon and colour will be used */
65
65
  type?: AlertType;
66
66
  variant?: `${Variant}`;
67
- /** 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. */
67
+ /**
68
+ * Controls rendering of the Alert component. <br />
69
+ * Toggle this prop instead using conditional rendering and logical AND (&&)
70
+ * operator, to make the component work with screen readers.
71
+ * @deprecated use `dynamicRender`
72
+ * */
68
73
  active?: boolean;
74
+ /**
75
+ * Toggle this prop when dealing with multiple, dynamic Alerts, to make them
76
+ * work with screen readers. This is especially helpful for the BFF use cases.
77
+ * */
78
+ dynamicRender?: boolean;
69
79
  /** @deprecated Use `InlineAlert` instead. */
70
80
  arrow?: `${AlertArrowPosition}`;
71
81
  /** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */
@@ -104,6 +114,7 @@ export default function Alert({
104
114
  type = 'neutral',
105
115
  variant = 'desktop',
106
116
  active = true,
117
+ dynamicRender = false,
107
118
  }: AlertProps) {
108
119
  useEffect(() => {
109
120
  if (arrow !== undefined) {
@@ -148,17 +159,20 @@ export default function Alert({
148
159
 
149
160
  const [shouldShow, setShouldShow] = useState<boolean>();
150
161
  useEffect(() => {
151
- if (shouldShow === undefined || !active) {
162
+ if ((shouldShow === undefined && !dynamicRender) || !active) {
152
163
  setShouldShow(active);
153
164
  } else {
154
165
  setTimeout(() => setShouldShow(active), WDS_LIVE_REGION_DELAY_MS);
155
166
  }
156
- }, [active, shouldShow]);
167
+ }, [active, shouldShow, dynamicRender]);
157
168
 
158
169
  const closeButtonReference = useRef<HTMLButtonElement>(null);
159
170
 
160
171
  return (
161
- <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>
172
+ <div
173
+ role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}
174
+ className="wds-alert__liveRegion"
175
+ >
162
176
  {shouldShow && (
163
177
  <div
164
178
  className={clsx(
package/src/main.css CHANGED
@@ -216,6 +216,9 @@ div.critical-comms .critical-comms-body {
216
216
  .np-action-btn:not(:disabled):focus {
217
217
  box-shadow: none;
218
218
  }
219
+ .wds-alert__liveRegion {
220
+ display: contents;
221
+ }
219
222
  .tw-avatar {
220
223
  position: relative;
221
224
  -webkit-user-select: none;
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";