@transferwise/components 46.72.1 → 46.73.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.
@@ -5,14 +5,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var clsx = require('clsx');
6
6
  var React = require('react');
7
7
  var Body = require('../body/Body.js');
8
- var CloseButton = require('../common/closeButton/CloseButton.js');
9
8
  var StatusIcon = require('../statusIcon/StatusIcon.js');
10
9
  var Title = require('../title/Title.js');
11
10
  var InlineMarkdown = require('./inlineMarkdown/InlineMarkdown.js');
12
11
  var Action = require('../common/action/Action.js');
13
12
  var jsxRuntime = require('react/jsx-runtime');
14
13
  var logActionRequired = require('../utilities/logActionRequired.js');
14
+ var constants = require('../common/constants.js');
15
15
  var sentiment = require('../common/propsValues/sentiment.js');
16
+ var CloseButton = require('../common/closeButton/CloseButton.js');
16
17
  var size = require('../common/propsValues/size.js');
17
18
  var typography = require('../common/propsValues/typography.js');
18
19
 
@@ -78,11 +79,19 @@ function Alert({
78
79
  logActionRequired.logActionRequired(`Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`);
79
80
  }
80
81
  }, [resolvedType, type]);
81
- const [shouldFire, setShouldFire] = React.useState(false);
82
+ const [shouldFire, setShouldFire] = React.useState();
83
+ const [shouldShow, setShouldShow] = React.useState();
84
+ React.useEffect(() => {
85
+ if (shouldShow === undefined || !active) {
86
+ setShouldShow(active);
87
+ } else {
88
+ setTimeout(() => setShouldShow(active), constants.WDS_LIVE_REGION_DELAY_MS);
89
+ }
90
+ }, [active, shouldShow]);
82
91
  const closeButtonReference = React.useRef(null);
83
92
  return /*#__PURE__*/jsxRuntime.jsx("div", {
84
93
  role: resolvedType === sentiment.Sentiment.NEGATIVE ? 'alert' : 'status',
85
- children: active && /*#__PURE__*/jsxRuntime.jsxs("div", {
94
+ children: shouldShow && /*#__PURE__*/jsxRuntime.jsxs("div", {
86
95
  className: clsx.clsx('alert d-flex', `alert-${resolvedType}`, arrow != null && alertArrowClassNames(arrow), className),
87
96
  "data-testid": "alert",
88
97
  onTouchStart: () => setShouldFire(true),
@@ -125,6 +134,7 @@ function Alert({
125
134
  })]
126
135
  }), action && /*#__PURE__*/jsxRuntime.jsx(Action.Action, {
127
136
  action: action,
137
+ variant: "action-button",
128
138
  className: "m-t-1"
129
139
  })]
130
140
  })]
@@ -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 { Sentiment, Size, Typography, Variant } from '../common';\nimport { CloseButton } from '../common/closeButton';\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 /** 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 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(false);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>\n {active && (\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} />\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} 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","onDismiss","message","size","title","variant","active","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","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","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mappings":";;;;;;;;;;;;;;;;;;AA8BYA,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;AA6BD,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,SAAS;EACTC,OAAO;QACPC,MAAI;EACJC,KAAK;AACLX,EAAAA,IAAI,GAAG,SAAS;AACh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A;KACE,CAAA;AACN,GACE,CAAC,CAAA;AAEV,CAAA;AAEA,SAASqB,oBAAoBA,CAAC3B,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 /** 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 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} />\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","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","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,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C7B,IAAA,KAAK,UAAU;AACb,MAAA,OAAO,mBAAmB,CAAA;AAC5B,IAAA,KAAK,SAAS,CAAA;AACd,IAAA;AACE,MAAA,OAAO,OAAO,CAAA;AAClB,GAAA;AACF;;;;"}
@@ -1,14 +1,15 @@
1
1
  import { clsx } from 'clsx';
2
2
  import { useEffect, useState, useRef } from 'react';
3
3
  import Body from '../body/Body.mjs';
4
- import { CloseButton } from '../common/closeButton/CloseButton.mjs';
5
4
  import StatusIcon from '../statusIcon/StatusIcon.mjs';
6
5
  import Title from '../title/Title.mjs';
7
6
  import InlineMarkdown from './inlineMarkdown/InlineMarkdown.mjs';
8
7
  import { Action } from '../common/action/Action.mjs';
9
8
  import { jsx, jsxs } from 'react/jsx-runtime';
10
9
  import { logActionRequired } from '../utilities/logActionRequired.mjs';
10
+ import { WDS_LIVE_REGION_DELAY_MS } from '../common/constants.mjs';
11
11
  import { Sentiment } from '../common/propsValues/sentiment.mjs';
12
+ import { CloseButton } from '../common/closeButton/CloseButton.mjs';
12
13
  import { Size } from '../common/propsValues/size.mjs';
13
14
  import { Typography } from '../common/propsValues/typography.mjs';
14
15
 
@@ -74,11 +75,19 @@ function Alert({
74
75
  logActionRequired(`Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`);
75
76
  }
76
77
  }, [resolvedType, type]);
77
- const [shouldFire, setShouldFire] = useState(false);
78
+ const [shouldFire, setShouldFire] = useState();
79
+ const [shouldShow, setShouldShow] = useState();
80
+ useEffect(() => {
81
+ if (shouldShow === undefined || !active) {
82
+ setShouldShow(active);
83
+ } else {
84
+ setTimeout(() => setShouldShow(active), WDS_LIVE_REGION_DELAY_MS);
85
+ }
86
+ }, [active, shouldShow]);
78
87
  const closeButtonReference = useRef(null);
79
88
  return /*#__PURE__*/jsx("div", {
80
89
  role: resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status',
81
- children: active && /*#__PURE__*/jsxs("div", {
90
+ children: shouldShow && /*#__PURE__*/jsxs("div", {
82
91
  className: clsx('alert d-flex', `alert-${resolvedType}`, arrow != null && alertArrowClassNames(arrow), className),
83
92
  "data-testid": "alert",
84
93
  onTouchStart: () => setShouldFire(true),
@@ -121,6 +130,7 @@ function Alert({
121
130
  })]
122
131
  }), action && /*#__PURE__*/jsx(Action, {
123
132
  action: action,
133
+ variant: "action-button",
124
134
  className: "m-t-1"
125
135
  })]
126
136
  })]
@@ -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 { Sentiment, Size, Typography, Variant } from '../common';\nimport { CloseButton } from '../common/closeButton';\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 /** 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 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(false);\n\n const closeButtonReference = useRef<HTMLButtonElement>(null);\n\n return (\n <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>\n {active && (\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} />\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} 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","onDismiss","message","size","title","variant","active","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","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","Title","Typography","TITLE_BODY","Body","as","BODY_LARGE","InlineMarkdown","Action","CloseButton","ref","onClick"],"mappings":";;;;;;;;;;;;;;IA8BYA,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;AA6BD,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,SAAS;EACTC,OAAO;EACPC,IAAI;EACJC,KAAK;AACLX,EAAAA,IAAI,GAAG,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,CAAA;KACE,CAAA;AACN,GACE,CAAC,CAAA;AAEV,CAAA;AAEA,SAASqB,oBAAoBA,CAAC3B,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.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 /** 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 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} />\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","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","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,GAO7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B,IAAA,KAAK,UAAU;AACb,MAAA,OAAO,mBAAmB,CAAA;AAC5B,IAAA,KAAK,SAAS,CAAA;AACd,IAAA;AACE,MAAA,OAAO,OAAO,CAAA;AAClB,GAAA;AACF;;;;"}
@@ -3,11 +3,14 @@
3
3
  var clsx = require('clsx');
4
4
  var Link = require('../../link/Link.js');
5
5
  var typography = require('../propsValues/typography.js');
6
+ var ActionButton = require('../../actionButton/ActionButton.js');
7
+ var control = require('../propsValues/control.js');
6
8
  var jsxRuntime = require('react/jsx-runtime');
7
9
 
8
10
  function Action({
9
11
  action,
10
- className
12
+ className,
13
+ variant = 'button'
11
14
  }) {
12
15
  if ('href' in action) {
13
16
  return /*#__PURE__*/jsxRuntime.jsx(Link, {
@@ -20,12 +23,18 @@ function Action({
20
23
  children: action.text
21
24
  });
22
25
  }
23
- return /*#__PURE__*/jsxRuntime.jsx("button", {
26
+ return variant === 'button' ? /*#__PURE__*/jsxRuntime.jsx("button", {
24
27
  type: "button",
25
28
  "aria-label": action['aria-label'],
26
29
  className: clsx.clsx('btn-unstyled np-text-link-large', className),
27
30
  onClick: action.onClick,
28
31
  children: action.text
32
+ }) : /*#__PURE__*/jsxRuntime.jsx(ActionButton, {
33
+ "aria-label": action['aria-label'],
34
+ priority: control.Priority.SECONDARY,
35
+ className: clsx.clsx(className),
36
+ onClick: action.onClick,
37
+ children: action.text
29
38
  });
30
39
  }
31
40
 
@@ -1 +1 @@
1
- {"version":3,"file":"Action.js","sources":["../../../src/common/action/Action.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport Link from '../../link';\nimport { Typography } from '../propsValues/typography';\n\nexport type ActionOptions = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\ntype Props = {\n action: ActionOptions;\n className?: string;\n};\n\nexport function Action({ action, className }: Props) {\n if ('href' in action) {\n return (\n <Link\n href={action.href}\n className={className}\n aria-label={action['aria-label']}\n target={action.target}\n type={Typography.LINK_LARGE}\n onClick={action.onClick}\n >\n {action.text}\n </Link>\n );\n }\n\n return (\n <button\n type=\"button\"\n aria-label={action['aria-label']}\n className={clsx('btn-unstyled np-text-link-large', className)}\n onClick={action.onClick}\n >\n {action.text}\n </button>\n );\n}\n"],"names":["Action","action","className","_jsx","Link","href","target","type","Typography","LINK_LARGE","onClick","children","text","clsx"],"mappings":";;;;;;;SAiBgBA,MAAMA,CAAC;EAAEC,MAAM;AAAEC,EAAAA,SAAAA;AAAkB,CAAA,EAAA;EACjD,IAAI,MAAM,IAAID,MAAM,EAAE;IACpB,oBACEE,cAAA,CAACC,IAAI,EAAA;MACHC,IAAI,EAAEJ,MAAM,CAACI,IAAK;AAClBH,MAAAA,SAAS,EAAEA,SAAU;MACrB,YAAYD,EAAAA,MAAM,CAAC,YAAY,CAAE;MACjCK,MAAM,EAAEL,MAAM,CAACK,MAAO;MACtBC,IAAI,EAAEC,qBAAU,CAACC,UAAW;MAC5BC,OAAO,EAAET,MAAM,CAACS,OAAQ;MAAAC,QAAA,EAEvBV,MAAM,CAACW,IAAAA;AAAI,KACR,CAAC,CAAA;AAEX,GAAA;AAEA,EAAA,oBACET,cAAA,CAAA,QAAA,EAAA;AACEI,IAAAA,IAAI,EAAC,QAAQ;IACb,YAAYN,EAAAA,MAAM,CAAC,YAAY,CAAE;AACjCC,IAAAA,SAAS,EAAEW,SAAI,CAAC,iCAAiC,EAAEX,SAAS,CAAE;IAC9DQ,OAAO,EAAET,MAAM,CAACS,OAAQ;IAAAC,QAAA,EAEvBV,MAAM,CAACW,IAAAA;AAAI,GACN,CAAC,CAAA;AAEb;;;;"}
1
+ {"version":3,"file":"Action.js","sources":["../../../src/common/action/Action.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport Link from '../../link';\nimport { Typography } from '../propsValues/typography';\nimport ActionButton from '../../actionButton';\nimport { Priority } from '../propsValues/control';\n\nexport type ActionOptions = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\ntype Props = {\n variant?: 'button' | 'action-button';\n action: ActionOptions;\n className?: string;\n};\n\nexport function Action({ action, className, variant = 'button' }: Props) {\n if ('href' in action) {\n return (\n <Link\n href={action.href}\n className={className}\n aria-label={action['aria-label']}\n target={action.target}\n type={Typography.LINK_LARGE}\n onClick={action.onClick}\n >\n {action.text}\n </Link>\n );\n }\n\n return variant === 'button' ? (\n <button\n type=\"button\"\n aria-label={action['aria-label']}\n className={clsx('btn-unstyled np-text-link-large', className)}\n onClick={action.onClick}\n >\n {action.text}\n </button>\n ) : (\n <ActionButton\n aria-label={action['aria-label']}\n priority={Priority.SECONDARY}\n className={clsx(className)}\n onClick={action.onClick}\n >\n {action.text}\n </ActionButton>\n );\n}\n"],"names":["Action","action","className","variant","_jsx","Link","href","target","type","Typography","LINK_LARGE","onClick","children","text","clsx","ActionButton","priority","Priority","SECONDARY"],"mappings":";;;;;;;;;AAoBM,SAAUA,MAAMA,CAAC;EAAEC,MAAM;EAAEC,SAAS;AAAEC,EAAAA,OAAO,GAAG,QAAA;AAAiB,CAAA,EAAA;EACrE,IAAI,MAAM,IAAIF,MAAM,EAAE;IACpB,oBACEG,cAAA,CAACC,IAAI,EAAA;MACHC,IAAI,EAAEL,MAAM,CAACK,IAAK;AAClBJ,MAAAA,SAAS,EAAEA,SAAU;MACrB,YAAYD,EAAAA,MAAM,CAAC,YAAY,CAAE;MACjCM,MAAM,EAAEN,MAAM,CAACM,MAAO;MACtBC,IAAI,EAAEC,qBAAU,CAACC,UAAW;MAC5BC,OAAO,EAAEV,MAAM,CAACU,OAAQ;MAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,KACR,CAAC,CAAA;AAEX,GAAA;AAEA,EAAA,OAAOV,OAAO,KAAK,QAAQ,gBACzBC,cAAA,CAAA,QAAA,EAAA;AACEI,IAAAA,IAAI,EAAC,QAAQ;IACb,YAAYP,EAAAA,MAAM,CAAC,YAAY,CAAE;AACjCC,IAAAA,SAAS,EAAEY,SAAI,CAAC,iCAAiC,EAAEZ,SAAS,CAAE;IAC9DS,OAAO,EAAEV,MAAM,CAACU,OAAQ;IAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,GACN,CAAC,gBAETT,cAAA,CAACW,YAAY,EAAA;IACX,YAAYd,EAAAA,MAAM,CAAC,YAAY,CAAE;IACjCe,QAAQ,EAAEC,gBAAQ,CAACC,SAAU;AAC7BhB,IAAAA,SAAS,EAAEY,SAAI,CAACZ,SAAS,CAAE;IAC3BS,OAAO,EAAEV,MAAM,CAACU,OAAQ;IAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,GACA,CACf,CAAA;AACH;;;;"}
@@ -1,11 +1,14 @@
1
1
  import { clsx } from 'clsx';
2
2
  import Link from '../../link/Link.mjs';
3
3
  import { Typography } from '../propsValues/typography.mjs';
4
+ import ActionButton from '../../actionButton/ActionButton.mjs';
5
+ import { Priority } from '../propsValues/control.mjs';
4
6
  import { jsx } from 'react/jsx-runtime';
5
7
 
6
8
  function Action({
7
9
  action,
8
- className
10
+ className,
11
+ variant = 'button'
9
12
  }) {
10
13
  if ('href' in action) {
11
14
  return /*#__PURE__*/jsx(Link, {
@@ -18,12 +21,18 @@ function Action({
18
21
  children: action.text
19
22
  });
20
23
  }
21
- return /*#__PURE__*/jsx("button", {
24
+ return variant === 'button' ? /*#__PURE__*/jsx("button", {
22
25
  type: "button",
23
26
  "aria-label": action['aria-label'],
24
27
  className: clsx('btn-unstyled np-text-link-large', className),
25
28
  onClick: action.onClick,
26
29
  children: action.text
30
+ }) : /*#__PURE__*/jsx(ActionButton, {
31
+ "aria-label": action['aria-label'],
32
+ priority: Priority.SECONDARY,
33
+ className: clsx(className),
34
+ onClick: action.onClick,
35
+ children: action.text
27
36
  });
28
37
  }
29
38
 
@@ -1 +1 @@
1
- {"version":3,"file":"Action.mjs","sources":["../../../src/common/action/Action.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport Link from '../../link';\nimport { Typography } from '../propsValues/typography';\n\nexport type ActionOptions = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\ntype Props = {\n action: ActionOptions;\n className?: string;\n};\n\nexport function Action({ action, className }: Props) {\n if ('href' in action) {\n return (\n <Link\n href={action.href}\n className={className}\n aria-label={action['aria-label']}\n target={action.target}\n type={Typography.LINK_LARGE}\n onClick={action.onClick}\n >\n {action.text}\n </Link>\n );\n }\n\n return (\n <button\n type=\"button\"\n aria-label={action['aria-label']}\n className={clsx('btn-unstyled np-text-link-large', className)}\n onClick={action.onClick}\n >\n {action.text}\n </button>\n );\n}\n"],"names":["Action","action","className","_jsx","Link","href","target","type","Typography","LINK_LARGE","onClick","children","text","clsx"],"mappings":";;;;;SAiBgBA,MAAMA,CAAC;EAAEC,MAAM;AAAEC,EAAAA,SAAAA;AAAkB,CAAA,EAAA;EACjD,IAAI,MAAM,IAAID,MAAM,EAAE;IACpB,oBACEE,GAAA,CAACC,IAAI,EAAA;MACHC,IAAI,EAAEJ,MAAM,CAACI,IAAK;AAClBH,MAAAA,SAAS,EAAEA,SAAU;MACrB,YAAYD,EAAAA,MAAM,CAAC,YAAY,CAAE;MACjCK,MAAM,EAAEL,MAAM,CAACK,MAAO;MACtBC,IAAI,EAAEC,UAAU,CAACC,UAAW;MAC5BC,OAAO,EAAET,MAAM,CAACS,OAAQ;MAAAC,QAAA,EAEvBV,MAAM,CAACW,IAAAA;AAAI,KACR,CAAC,CAAA;AAEX,GAAA;AAEA,EAAA,oBACET,GAAA,CAAA,QAAA,EAAA;AACEI,IAAAA,IAAI,EAAC,QAAQ;IACb,YAAYN,EAAAA,MAAM,CAAC,YAAY,CAAE;AACjCC,IAAAA,SAAS,EAAEW,IAAI,CAAC,iCAAiC,EAAEX,SAAS,CAAE;IAC9DQ,OAAO,EAAET,MAAM,CAACS,OAAQ;IAAAC,QAAA,EAEvBV,MAAM,CAACW,IAAAA;AAAI,GACN,CAAC,CAAA;AAEb;;;;"}
1
+ {"version":3,"file":"Action.mjs","sources":["../../../src/common/action/Action.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport Link from '../../link';\nimport { Typography } from '../propsValues/typography';\nimport ActionButton from '../../actionButton';\nimport { Priority } from '../propsValues/control';\n\nexport type ActionOptions = {\n 'aria-label'?: string;\n href?: string;\n target?: string;\n text: React.ReactNode;\n onClick?: () => void;\n};\n\ntype Props = {\n variant?: 'button' | 'action-button';\n action: ActionOptions;\n className?: string;\n};\n\nexport function Action({ action, className, variant = 'button' }: Props) {\n if ('href' in action) {\n return (\n <Link\n href={action.href}\n className={className}\n aria-label={action['aria-label']}\n target={action.target}\n type={Typography.LINK_LARGE}\n onClick={action.onClick}\n >\n {action.text}\n </Link>\n );\n }\n\n return variant === 'button' ? (\n <button\n type=\"button\"\n aria-label={action['aria-label']}\n className={clsx('btn-unstyled np-text-link-large', className)}\n onClick={action.onClick}\n >\n {action.text}\n </button>\n ) : (\n <ActionButton\n aria-label={action['aria-label']}\n priority={Priority.SECONDARY}\n className={clsx(className)}\n onClick={action.onClick}\n >\n {action.text}\n </ActionButton>\n );\n}\n"],"names":["Action","action","className","variant","_jsx","Link","href","target","type","Typography","LINK_LARGE","onClick","children","text","clsx","ActionButton","priority","Priority","SECONDARY"],"mappings":";;;;;;;AAoBM,SAAUA,MAAMA,CAAC;EAAEC,MAAM;EAAEC,SAAS;AAAEC,EAAAA,OAAO,GAAG,QAAA;AAAiB,CAAA,EAAA;EACrE,IAAI,MAAM,IAAIF,MAAM,EAAE;IACpB,oBACEG,GAAA,CAACC,IAAI,EAAA;MACHC,IAAI,EAAEL,MAAM,CAACK,IAAK;AAClBJ,MAAAA,SAAS,EAAEA,SAAU;MACrB,YAAYD,EAAAA,MAAM,CAAC,YAAY,CAAE;MACjCM,MAAM,EAAEN,MAAM,CAACM,MAAO;MACtBC,IAAI,EAAEC,UAAU,CAACC,UAAW;MAC5BC,OAAO,EAAEV,MAAM,CAACU,OAAQ;MAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,KACR,CAAC,CAAA;AAEX,GAAA;AAEA,EAAA,OAAOV,OAAO,KAAK,QAAQ,gBACzBC,GAAA,CAAA,QAAA,EAAA;AACEI,IAAAA,IAAI,EAAC,QAAQ;IACb,YAAYP,EAAAA,MAAM,CAAC,YAAY,CAAE;AACjCC,IAAAA,SAAS,EAAEY,IAAI,CAAC,iCAAiC,EAAEZ,SAAS,CAAE;IAC9DS,OAAO,EAAEV,MAAM,CAACU,OAAQ;IAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,GACN,CAAC,gBAETT,GAAA,CAACW,YAAY,EAAA;IACX,YAAYd,EAAAA,MAAM,CAAC,YAAY,CAAE;IACjCe,QAAQ,EAAEC,QAAQ,CAACC,SAAU;AAC7BhB,IAAAA,SAAS,EAAEY,IAAI,CAACZ,SAAS,CAAE;IAC3BS,OAAO,EAAEV,MAAM,CAACU,OAAQ;IAAAC,QAAA,EAEvBX,MAAM,CAACY,IAAAA;AAAI,GACA,CACf,CAAA;AACH;;;;"}
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * This file holds repository-wide constants that are reusable by more than 1 component.
5
+ */
6
+ /**
7
+ * A delay [ms] after which it's OK to update a live region content,
8
+ * taking under consideration delayed programmatic refocusing
9
+ * of triggering components (e.g., SelectInput) and Accessibility
10
+ * Tree updates that prevent the screen reader announcements.
11
+ */
12
+ const WDS_LIVE_REGION_DELAY_MS = 175;
13
+
14
+ exports.WDS_LIVE_REGION_DELAY_MS = WDS_LIVE_REGION_DELAY_MS;
15
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../src/common/constants.ts"],"sourcesContent":["/**\n * This file holds repository-wide constants that are reusable by more than 1 component.\n */\n\n/**\n * A delay [ms] after which it's OK to update a live region content,\n * taking under consideration delayed programmatic refocusing\n * of triggering components (e.g., SelectInput) and Accessibility\n * Tree updates that prevent the screen reader announcements.\n */\nexport const WDS_LIVE_REGION_DELAY_MS = 175;\n"],"names":["WDS_LIVE_REGION_DELAY_MS"],"mappings":";;AAAA;;AAEG;AAEH;;;;;AAKG;AACI,MAAMA,wBAAwB,GAAG;;;;"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file holds repository-wide constants that are reusable by more than 1 component.
3
+ */
4
+ /**
5
+ * A delay [ms] after which it's OK to update a live region content,
6
+ * taking under consideration delayed programmatic refocusing
7
+ * of triggering components (e.g., SelectInput) and Accessibility
8
+ * Tree updates that prevent the screen reader announcements.
9
+ */
10
+ const WDS_LIVE_REGION_DELAY_MS = 175;
11
+
12
+ export { WDS_LIVE_REGION_DELAY_MS };
13
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","sources":["../../src/common/constants.ts"],"sourcesContent":["/**\n * This file holds repository-wide constants that are reusable by more than 1 component.\n */\n\n/**\n * A delay [ms] after which it's OK to update a live region content,\n * taking under consideration delayed programmatic refocusing\n * of triggering components (e.g., SelectInput) and Accessibility\n * Tree updates that prevent the screen reader announcements.\n */\nexport const WDS_LIVE_REGION_DELAY_MS = 175;\n"],"names":["WDS_LIVE_REGION_DELAY_MS"],"mappings":"AAAA;;AAEG;AAEH;;;;;AAKG;AACI,MAAMA,wBAAwB,GAAG;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Alert.d.ts","sourceRoot":"","sources":["../../../src/alert/Alert.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAc,OAAO,EAAE,MAAM,WAAW,CAAC;AASjE,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,CA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,CAAC;IACvB,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kGAAkG;IAClG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4FAA4F;IAC5F,SAAS,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IACvD,2DAA2D;IAC3D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;IACvB,4LAA4L;IAC5L,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,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,SAAS,EACT,OAAO,EACP,IAAI,EACJ,KAAK,EACL,IAAgB,EAChB,OAAmB,EACnB,MAAa,GACd,EAAE,UAAU,+BAkHZ"}
@@ -6,9 +6,10 @@ export type ActionOptions = {
6
6
  onClick?: () => void;
7
7
  };
8
8
  type Props = {
9
+ variant?: 'button' | 'action-button';
9
10
  action: ActionOptions;
10
11
  className?: string;
11
12
  };
12
- export declare function Action({ action, className }: Props): import("react").JSX.Element;
13
+ export declare function Action({ action, className, variant }: Props): import("react").JSX.Element;
13
14
  export {};
14
15
  //# sourceMappingURL=Action.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Action.d.ts","sourceRoot":"","sources":["../../../../src/common/action/Action.tsx"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG;IAC1B,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,KAAK,KAAK,GAAG;IACX,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,+BA0BlD"}
1
+ {"version":3,"file":"Action.d.ts","sourceRoot":"","sources":["../../../../src/common/action/Action.tsx"],"names":[],"mappings":"AAMA,MAAM,MAAM,aAAa,GAAG;IAC1B,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,KAAK,KAAK,GAAG;IACX,OAAO,CAAC,EAAE,QAAQ,GAAG,eAAe,CAAC;IACrC,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,OAAkB,EAAE,EAAE,KAAK,+BAmCtE"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * This file holds repository-wide constants that are reusable by more than 1 component.
3
+ */
4
+ /**
5
+ * A delay [ms] after which it's OK to update a live region content,
6
+ * taking under consideration delayed programmatic refocusing
7
+ * of triggering components (e.g., SelectInput) and Accessibility
8
+ * Tree updates that prevent the screen reader announcements.
9
+ */
10
+ export declare const WDS_LIVE_REGION_DELAY_MS = 175;
11
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/common/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC"}
@@ -14,6 +14,7 @@ export * from "./locale";
14
14
  export * from "./commonProps";
15
15
  export * from "./initials";
16
16
  export * from "./colors";
17
+ export * from "./constants";
17
18
  export { Breakpoint } from "./propsValues/breakpoint";
18
19
  export { Type } from "./propsValues/type";
19
20
  export { DateMode } from "./propsValues/dateMode";
@@ -23,5 +24,6 @@ export { Sentiment } from "./propsValues/sentiment";
23
24
  export { Variant } from "./propsValues/variant";
24
25
  export { MarkdownNodeType } from "./propsValues/markdownNodeType";
25
26
  export { FileType } from "./fileType";
27
+ export { CloseButton } from "./closeButton";
26
28
  export { addNoScrollClass, removeNoScrollClass } from "./DOMOperations";
27
29
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "46.72.1",
3
+ "version": "46.73.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,87 @@
1
+ import { useState } from 'react';
2
+ import { userEvent, within, expect, waitFor } from '@storybook/test';
3
+ import { Button, Field, SelectInput, Sentiment } from '..';
4
+ import Alert from './Alert';
5
+
6
+ import { Meta, StoryObj } from '@storybook/react';
7
+
8
+ const meta = {
9
+ title: 'Feedback/Alert/tests',
10
+ component: Alert,
11
+ argTypes: {},
12
+ args: {
13
+ type: Sentiment.POSITIVE,
14
+ active: true,
15
+ message: 'Payments sent to your bank details today might not arrive in time for the holidays.',
16
+ },
17
+ } satisfies Meta<typeof Alert>;
18
+ export default meta;
19
+
20
+ type Story = StoryObj<typeof meta>;
21
+
22
+ const wait = async (duration = 500) =>
23
+ new Promise<void>((resolve) => {
24
+ setTimeout(resolve, duration);
25
+ });
26
+
27
+ export const SimpleTrigger: Story = {
28
+ play: async ({ args, canvasElement }) => {
29
+ const canvas = within(canvasElement);
30
+ await wait();
31
+ await userEvent.tab();
32
+ await wait();
33
+ await userEvent.keyboard('{Enter}');
34
+
35
+ await waitFor(async () => expect(canvas.getByText(args.message || '')).toBeInTheDocument());
36
+ },
37
+ render: function Render(args) {
38
+ const [isActive, setIsActive] = useState(false);
39
+
40
+ return (
41
+ <>
42
+ <Button htmlType="button" onClick={() => setIsActive(true)}>
43
+ Trigger Alert
44
+ </Button>
45
+
46
+ <Alert {...args} active={isActive} className="m-t-4" />
47
+ </>
48
+ );
49
+ },
50
+ };
51
+
52
+ export const ComplexTrigger: Story = {
53
+ play: async ({ args, canvasElement }) => {
54
+ const canvas = within(canvasElement);
55
+ await wait();
56
+ await userEvent.tab();
57
+ await wait();
58
+ await userEvent.keyboard('{ArrowDown}');
59
+ await wait();
60
+ await userEvent.keyboard('{ArrowDown}');
61
+ await wait();
62
+ await userEvent.keyboard('{Enter}');
63
+
64
+ await waitFor(async () => expect(canvas.getByText(args.message || '')).toBeInTheDocument());
65
+ },
66
+ render: function Render(args) {
67
+ const [isActive, setIsActive] = useState(false);
68
+ const [value, setValue] = useState<string>();
69
+
70
+ return (
71
+ <>
72
+ <Field label="Select option to triger Alert">
73
+ <SelectInput
74
+ items={[
75
+ { type: 'option', value: 'one' },
76
+ { type: 'option', value: 'two' },
77
+ ]}
78
+ onChange={setValue}
79
+ onClose={() => setIsActive(Boolean(value))}
80
+ />
81
+ </Field>
82
+
83
+ <Alert {...args} active={isActive} className="m-t-2" />
84
+ </>
85
+ );
86
+ },
87
+ };
@@ -4,7 +4,7 @@ import { action } from '@storybook/addon-actions';
4
4
  import { ClockBorderless } from '@transferwise/icons';
5
5
 
6
6
  import { Sentiment } from '../common';
7
- import { Button } from '..';
7
+ import { Button, Field, SelectInput } from '..';
8
8
  import Alert, { AlertArrowPosition } from './Alert';
9
9
 
10
10
  export default {
@@ -109,23 +109,41 @@ export const WithTitle: Story = {
109
109
  * For ARIA live region to function correctly with screen readers,
110
110
  * the container with an appropriate ARIA role (in the case of this
111
111
  * component, it's `status` or `alert`) must be rendered first.
112
- * Once present in the accessibility tree, its dynamic contents
112
+ * Once present in the accessibility tree (AT), its dynamic contents
113
113
  * will be announced correctly.
114
114
  *
115
115
  * Because of that, using logical AND (&&) operator is discouraged
116
116
  * and, instead, engineers should toggle the `active` prop which
117
117
  * provides that logic internally.
118
+ *
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.
118
124
  */
119
125
  export const ConditionallyRendered: Story = {
120
126
  render: function Render(args) {
121
127
  const [isActive, setIsActive] = useState(false);
128
+ const [value, setValue] = useState<string>();
122
129
 
123
130
  return (
124
131
  <>
125
- <Button htmlType="button" onClick={() => setIsActive((value) => !value)}>
132
+ <Button htmlType="button" onClick={() => setIsActive((current) => !current)}>
126
133
  Trigger Alert
127
134
  </Button>
128
135
 
136
+ <Field label="Select `two` to triger Alert" className="m-t-3">
137
+ <SelectInput
138
+ items={[
139
+ { type: 'option', value: 'one' },
140
+ { type: 'option', value: 'two' },
141
+ ]}
142
+ onChange={setValue}
143
+ onClose={() => setIsActive(value === 'two')}
144
+ />
145
+ </Field>
146
+
129
147
  <Alert {...args} active={isActive} className="m-t-5" />
130
148
  </>
131
149
  );
@@ -134,18 +152,30 @@ export const ConditionallyRendered: Story = {
134
152
  docs: {
135
153
  source: {
136
154
  code: `
137
- function Render (args) {
155
+ function Render(args) {
138
156
  const [isActive, setIsActive] = useState(false);
157
+ const [value, setValue] = useState<string>();
139
158
 
140
159
  return (
141
160
  <>
142
- <Button htmlType="button" onClick={() => setIsActive(value => !value)}>
161
+ <Button htmlType="button" onClick={() => setIsActive((current) => !current)}>
143
162
  Trigger Alert
144
163
  </Button>
145
164
 
165
+ <Field label="Select 'two' to triger Alert" className="m-t-3">
166
+ <SelectInput
167
+ items={[
168
+ { type: 'option', value: 'one' },
169
+ { type: 'option', value: 'two' },
170
+ ]}
171
+ onChange={setValue}
172
+ onClose={() => setIsActive(value === 'two')}
173
+ />
174
+ </Field>
175
+
146
176
  <Alert {...args} active={isActive} className="m-t-5" />
147
177
  </>
148
- )
178
+ );
149
179
  }`,
150
180
  },
151
181
  },
@@ -2,8 +2,15 @@ import { clsx } from 'clsx';
2
2
  import { useState, useRef, useEffect } from 'react';
3
3
 
4
4
  import Body from '../body/Body';
5
- import { Sentiment, Size, Typography, Variant } from '../common';
6
- import { CloseButton } from '../common/closeButton';
5
+ import {
6
+ CloseButton,
7
+ Sentiment,
8
+ Size,
9
+ Typography,
10
+ Variant,
11
+ WDS_LIVE_REGION_DELAY_MS,
12
+ } from '../common';
13
+
7
14
  import StatusIcon from '../statusIcon';
8
15
  import Title from '../title/Title';
9
16
  import { logActionRequired } from '../utilities';
@@ -131,13 +138,22 @@ export default function Alert({
131
138
  }
132
139
  }, [resolvedType, type]);
133
140
 
134
- const [shouldFire, setShouldFire] = useState(false);
141
+ const [shouldFire, setShouldFire] = useState<boolean>();
142
+
143
+ const [shouldShow, setShouldShow] = useState<boolean>();
144
+ useEffect(() => {
145
+ if (shouldShow === undefined || !active) {
146
+ setShouldShow(active);
147
+ } else {
148
+ setTimeout(() => setShouldShow(active), WDS_LIVE_REGION_DELAY_MS);
149
+ }
150
+ }, [active, shouldShow]);
135
151
 
136
152
  const closeButtonReference = useRef<HTMLButtonElement>(null);
137
153
 
138
154
  return (
139
155
  <div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>
140
- {active && (
156
+ {shouldShow && (
141
157
  <div
142
158
  className={clsx(
143
159
  'alert d-flex',
@@ -186,7 +202,7 @@ export default function Alert({
186
202
  {children || <InlineMarkdown>{message}</InlineMarkdown>}
187
203
  </Body>
188
204
  </div>
189
- {action && <Action action={action} className="m-t-1" />}
205
+ {action && <Action action={action} variant="action-button" className="m-t-1" />}
190
206
  </div>
191
207
  </div>
192
208
  {onDismiss && (
@@ -1,6 +1,8 @@
1
1
  import { clsx } from 'clsx';
2
2
  import Link from '../../link';
3
3
  import { Typography } from '../propsValues/typography';
4
+ import ActionButton from '../../actionButton';
5
+ import { Priority } from '../propsValues/control';
4
6
 
5
7
  export type ActionOptions = {
6
8
  'aria-label'?: string;
@@ -11,11 +13,12 @@ export type ActionOptions = {
11
13
  };
12
14
 
13
15
  type Props = {
16
+ variant?: 'button' | 'action-button';
14
17
  action: ActionOptions;
15
18
  className?: string;
16
19
  };
17
20
 
18
- export function Action({ action, className }: Props) {
21
+ export function Action({ action, className, variant = 'button' }: Props) {
19
22
  if ('href' in action) {
20
23
  return (
21
24
  <Link
@@ -31,7 +34,7 @@ export function Action({ action, className }: Props) {
31
34
  );
32
35
  }
33
36
 
34
- return (
37
+ return variant === 'button' ? (
35
38
  <button
36
39
  type="button"
37
40
  aria-label={action['aria-label']}
@@ -40,5 +43,14 @@ export function Action({ action, className }: Props) {
40
43
  >
41
44
  {action.text}
42
45
  </button>
46
+ ) : (
47
+ <ActionButton
48
+ aria-label={action['aria-label']}
49
+ priority={Priority.SECONDARY}
50
+ className={clsx(className)}
51
+ onClick={action.onClick}
52
+ >
53
+ {action.text}
54
+ </ActionButton>
43
55
  );
44
56
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * This file holds repository-wide constants that are reusable by more than 1 component.
3
+ */
4
+
5
+ /**
6
+ * A delay [ms] after which it's OK to update a live region content,
7
+ * taking under consideration delayed programmatic refocusing
8
+ * of triggering components (e.g., SelectInput) and Accessibility
9
+ * Tree updates that prevent the screen reader announcements.
10
+ */
11
+ export const WDS_LIVE_REGION_DELAY_MS = 175;
@@ -25,3 +25,5 @@ export * from './locale';
25
25
  export * from './commonProps';
26
26
  export * from './initials';
27
27
  export * from './colors';
28
+ export * from './constants';
29
+ export { CloseButton } from './closeButton';