@transferwise/components 46.71.7 → 46.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/alert/Alert.js +52 -49
- package/build/alert/Alert.js.map +1 -1
- package/build/alert/Alert.mjs +53 -50
- package/build/alert/Alert.mjs.map +1 -1
- package/build/dateLookup/dateTrigger/DateTrigger.js +6 -1
- package/build/dateLookup/dateTrigger/DateTrigger.js.map +1 -1
- package/build/dateLookup/dateTrigger/DateTrigger.mjs +7 -2
- package/build/dateLookup/dateTrigger/DateTrigger.mjs.map +1 -1
- package/build/types/alert/Alert.d.ts +3 -1
- package/build/types/alert/Alert.d.ts.map +1 -1
- package/build/types/dateLookup/dateTrigger/DateTrigger.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/alert/Alert.spec.tsx +20 -0
- package/src/alert/Alert.story.tsx +50 -2
- package/src/alert/Alert.tsx +57 -50
- package/src/dateLookup/DateLookup.rtl.spec.tsx +1 -1
- package/src/dateLookup/DateLookup.story.tsx +1 -1
- package/src/dateLookup/DateLookup.testingLibrary.spec.js +20 -3
- package/src/dateLookup/dateTrigger/DateTrigger.tsx +7 -5
package/build/alert/Alert.js
CHANGED
|
@@ -49,7 +49,8 @@ function Alert({
|
|
|
49
49
|
size: size$1,
|
|
50
50
|
title,
|
|
51
51
|
type = 'neutral',
|
|
52
|
-
variant = 'desktop'
|
|
52
|
+
variant = 'desktop',
|
|
53
|
+
active = true
|
|
53
54
|
}) {
|
|
54
55
|
React.useEffect(() => {
|
|
55
56
|
if (arrow !== undefined) {
|
|
@@ -79,58 +80,60 @@ function Alert({
|
|
|
79
80
|
}, [resolvedType, type]);
|
|
80
81
|
const [shouldFire, setShouldFire] = React.useState(false);
|
|
81
82
|
const closeButtonReference = React.useRef(null);
|
|
82
|
-
return /*#__PURE__*/jsxRuntime.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
84
|
+
role: resolvedType === sentiment.Sentiment.NEGATIVE ? 'alert' : 'status',
|
|
85
|
+
children: active && /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
86
|
+
className: clsx.clsx('alert d-flex', `alert-${resolvedType}`, arrow != null && alertArrowClassNames(arrow), className),
|
|
87
|
+
"data-testid": "alert",
|
|
88
|
+
onTouchStart: () => setShouldFire(true),
|
|
89
|
+
onTouchEnd: event => {
|
|
90
|
+
if (shouldFire && action?.href &&
|
|
91
|
+
// Check if current event is triggered from closeButton
|
|
92
|
+
event.target instanceof Node && closeButtonReference.current && !closeButtonReference.current.contains(event.target)) {
|
|
93
|
+
if (action.target === '_blank') {
|
|
94
|
+
window.top?.open(action.href);
|
|
95
|
+
} else {
|
|
96
|
+
window.top?.location.assign(action.href);
|
|
97
|
+
}
|
|
94
98
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
99
|
+
setShouldFire(false);
|
|
100
|
+
},
|
|
101
|
+
onTouchMove: () => setShouldFire(false),
|
|
102
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
103
|
+
className: clsx.clsx('alert__content', 'd-flex', 'flex-grow-1', variant),
|
|
104
|
+
"data-testid": variant,
|
|
105
|
+
children: [icon ? /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
106
|
+
className: "alert__icon",
|
|
107
|
+
children: icon
|
|
108
|
+
}) : /*#__PURE__*/jsxRuntime.jsx(StatusIcon, {
|
|
109
|
+
size: size.Size.LARGE,
|
|
110
|
+
sentiment: resolvedType
|
|
111
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
112
|
+
className: "alert__message",
|
|
113
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
114
|
+
children: [title && /*#__PURE__*/jsxRuntime.jsx(Title, {
|
|
115
|
+
className: "m-b-1",
|
|
116
|
+
type: typography.Typography.TITLE_BODY,
|
|
117
|
+
children: title
|
|
118
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Body, {
|
|
119
|
+
as: "span",
|
|
120
|
+
className: "d-block",
|
|
121
|
+
type: typography.Typography.BODY_LARGE,
|
|
122
|
+
children: children || /*#__PURE__*/jsxRuntime.jsx(InlineMarkdown, {
|
|
123
|
+
children: message
|
|
124
|
+
})
|
|
125
|
+
})]
|
|
126
|
+
}), action && /*#__PURE__*/jsxRuntime.jsx(Action.Action, {
|
|
127
|
+
action: action,
|
|
128
|
+
className: "m-t-1"
|
|
123
129
|
})]
|
|
124
|
-
}), action && /*#__PURE__*/jsxRuntime.jsx(Action.Action, {
|
|
125
|
-
action: action,
|
|
126
|
-
className: "m-t-1"
|
|
127
130
|
})]
|
|
131
|
+
}), onDismiss && /*#__PURE__*/jsxRuntime.jsx(CloseButton.CloseButton, {
|
|
132
|
+
ref: closeButtonReference,
|
|
133
|
+
className: "m-l-2",
|
|
134
|
+
onClick: onDismiss
|
|
128
135
|
})]
|
|
129
|
-
})
|
|
130
|
-
ref: closeButtonReference,
|
|
131
|
-
className: "m-l-2",
|
|
132
|
-
onClick: onDismiss
|
|
133
|
-
})]
|
|
136
|
+
})
|
|
134
137
|
});
|
|
135
138
|
}
|
|
136
139
|
function alertArrowClassNames(arrow) {
|
package/build/alert/Alert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.js","sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useState, useRef, useEffect } from 'react';\n\nimport Body from '../body/Body';\nimport { 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 /** @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}: 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\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 role={Sentiment.NEGATIVE === resolvedType ? 'alert' : 'status'}>\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}\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","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","closeButtonReference","useRef","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","_jsx","StatusIcon","Size","LARGE","sentiment","role","Sentiment","NEGATIVE","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;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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","on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,YAAY;AACf,MAAA,OAAO,gCAAgC,CAAA;AACzC,IAAA,KAAK,WAAW;AACd,MAAA,OAAO,oBAAoB,CAAA;AAC7B,IAAA,KAAK,UAAU;AACb,MAAA,OAAO,mBAAmB,CAAA;AAC5B,IAAA,KAAK,SAAS,CAAA;AACd,IAAA;AACE,MAAA,OAAO,OAAO,CAAA;AAClB,GAAA;AACF;;;;"}
|
package/build/alert/Alert.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import StatusIcon from '../statusIcon/StatusIcon.mjs';
|
|
|
6
6
|
import Title from '../title/Title.mjs';
|
|
7
7
|
import InlineMarkdown from './inlineMarkdown/InlineMarkdown.mjs';
|
|
8
8
|
import { Action } from '../common/action/Action.mjs';
|
|
9
|
-
import {
|
|
9
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
10
10
|
import { logActionRequired } from '../utilities/logActionRequired.mjs';
|
|
11
11
|
import { Sentiment } from '../common/propsValues/sentiment.mjs';
|
|
12
12
|
import { Size } from '../common/propsValues/size.mjs';
|
|
@@ -45,7 +45,8 @@ function Alert({
|
|
|
45
45
|
size,
|
|
46
46
|
title,
|
|
47
47
|
type = 'neutral',
|
|
48
|
-
variant = 'desktop'
|
|
48
|
+
variant = 'desktop',
|
|
49
|
+
active = true
|
|
49
50
|
}) {
|
|
50
51
|
useEffect(() => {
|
|
51
52
|
if (arrow !== undefined) {
|
|
@@ -75,58 +76,60 @@ function Alert({
|
|
|
75
76
|
}, [resolvedType, type]);
|
|
76
77
|
const [shouldFire, setShouldFire] = useState(false);
|
|
77
78
|
const closeButtonReference = useRef(null);
|
|
78
|
-
return /*#__PURE__*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
return /*#__PURE__*/jsx("div", {
|
|
80
|
+
role: resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status',
|
|
81
|
+
children: active && /*#__PURE__*/jsxs("div", {
|
|
82
|
+
className: clsx('alert d-flex', `alert-${resolvedType}`, arrow != null && alertArrowClassNames(arrow), className),
|
|
83
|
+
"data-testid": "alert",
|
|
84
|
+
onTouchStart: () => setShouldFire(true),
|
|
85
|
+
onTouchEnd: event => {
|
|
86
|
+
if (shouldFire && action?.href &&
|
|
87
|
+
// Check if current event is triggered from closeButton
|
|
88
|
+
event.target instanceof Node && closeButtonReference.current && !closeButtonReference.current.contains(event.target)) {
|
|
89
|
+
if (action.target === '_blank') {
|
|
90
|
+
window.top?.open(action.href);
|
|
91
|
+
} else {
|
|
92
|
+
window.top?.location.assign(action.href);
|
|
93
|
+
}
|
|
90
94
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
95
|
+
setShouldFire(false);
|
|
96
|
+
},
|
|
97
|
+
onTouchMove: () => setShouldFire(false),
|
|
98
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
99
|
+
className: clsx('alert__content', 'd-flex', 'flex-grow-1', variant),
|
|
100
|
+
"data-testid": variant,
|
|
101
|
+
children: [icon ? /*#__PURE__*/jsx("div", {
|
|
102
|
+
className: "alert__icon",
|
|
103
|
+
children: icon
|
|
104
|
+
}) : /*#__PURE__*/jsx(StatusIcon, {
|
|
105
|
+
size: Size.LARGE,
|
|
106
|
+
sentiment: resolvedType
|
|
107
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
108
|
+
className: "alert__message",
|
|
109
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
110
|
+
children: [title && /*#__PURE__*/jsx(Title, {
|
|
111
|
+
className: "m-b-1",
|
|
112
|
+
type: Typography.TITLE_BODY,
|
|
113
|
+
children: title
|
|
114
|
+
}), /*#__PURE__*/jsx(Body, {
|
|
115
|
+
as: "span",
|
|
116
|
+
className: "d-block",
|
|
117
|
+
type: Typography.BODY_LARGE,
|
|
118
|
+
children: children || /*#__PURE__*/jsx(InlineMarkdown, {
|
|
119
|
+
children: message
|
|
120
|
+
})
|
|
121
|
+
})]
|
|
122
|
+
}), action && /*#__PURE__*/jsx(Action, {
|
|
123
|
+
action: action,
|
|
124
|
+
className: "m-t-1"
|
|
119
125
|
})]
|
|
120
|
-
}), action && /*#__PURE__*/jsx(Action, {
|
|
121
|
-
action: action,
|
|
122
|
-
className: "m-t-1"
|
|
123
126
|
})]
|
|
127
|
+
}), onDismiss && /*#__PURE__*/jsx(CloseButton, {
|
|
128
|
+
ref: closeButtonReference,
|
|
129
|
+
className: "m-l-2",
|
|
130
|
+
onClick: onDismiss
|
|
124
131
|
})]
|
|
125
|
-
})
|
|
126
|
-
ref: closeButtonReference,
|
|
127
|
-
className: "m-l-2",
|
|
128
|
-
onClick: onDismiss
|
|
129
|
-
})]
|
|
132
|
+
})
|
|
130
133
|
});
|
|
131
134
|
}
|
|
132
135
|
function alertArrowClassNames(arrow) {
|
|
@@ -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 /** @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}: 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\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 role={Sentiment.NEGATIVE === resolvedType ? 'alert' : 'status'}>\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}\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","useEffect","undefined","logActionRequired","resolvedType","shouldFire","setShouldFire","useState","closeButtonReference","useRef","_jsxs","clsx","alertArrowClassNames","onTouchStart","onTouchEnd","event","href","target","Node","current","contains","window","top","open","location","assign","onTouchMove","_jsx","StatusIcon","Size","LARGE","sentiment","role","Sentiment","NEGATIVE","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,KAAl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QAAA,EAAEK,OAAAA;aAAwB,CAAA;AAAC,WACnD,CACR,CAAA;AAAA,SAAK,CACL,EAACN,MAAM,iBAAIoC,GAAA,CAACe,MAAM,EAAA;AAACnD,UAAAA,MAAM,EAAEA,MAAO;AAACE,UAAAA,SAAS,EAAC,OAAA;AAAO,UAAG,CAAA;AAAA,OACpD,CACP,CAAA;AAAA,KAAK,CACL,EAACG,SAAS,iBACR+B,GAAA,CAACgB,WAAW,EAAA;AAACC,MAAAA,GAAG,EAAEpC,oBAAqB;AAACf,MAAAA,SAAS,EAAC,OAAO;AAACoD,MAAAA,OAAO,EAAEjD,SAAAA;AAAU,KAAG,CACjF,CAAA;AAAA,GACE,CAAC,CAAA;AAEV,CAAA;AAEA,SAASgB,oBAAoBA,CAACtB,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 { 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,kB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l.useIntl();
|
|
31
|
+
const valueIdPrefix = React.useId();
|
|
31
32
|
const overlayId = React.useContext(OverlayIdProvider.OverlayIdContext);
|
|
33
|
+
const ariaLabelIds = [ariaLabelledBy, `${valueIdPrefix}:prefix`, `${valueIdPrefix}:value`];
|
|
32
34
|
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
33
35
|
children: [/*#__PURE__*/jsxRuntime.jsxs("button", {
|
|
34
36
|
"aria-haspopup": "dialog",
|
|
35
37
|
"aria-expanded": overlayId != null,
|
|
36
38
|
"aria-controls": overlayId,
|
|
37
|
-
"aria-labelledby":
|
|
39
|
+
"aria-labelledby": ariaLabelIds.filter(Boolean).join(' '),
|
|
38
40
|
className: `btn btn-${size$1} btn-input np-date-trigger`,
|
|
39
41
|
disabled: disabled,
|
|
40
42
|
type: "button",
|
|
@@ -42,10 +44,12 @@ const DateTrigger = ({
|
|
|
42
44
|
children: [label && /*#__PURE__*/jsxRuntime.jsx(Body, {
|
|
43
45
|
as: "span",
|
|
44
46
|
className: "np-date-trigger-label m-r-1",
|
|
47
|
+
id: ariaLabelIds[1],
|
|
45
48
|
children: label
|
|
46
49
|
}), selectedDate ? /*#__PURE__*/jsxRuntime.jsx(Body, {
|
|
47
50
|
as: "span",
|
|
48
51
|
type: typography.Typography.BODY_LARGE,
|
|
52
|
+
id: ariaLabelIds[2],
|
|
49
53
|
children: formatting.formatDate(selectedDate, locale, {
|
|
50
54
|
day: 'numeric',
|
|
51
55
|
month: monthFormat,
|
|
@@ -53,6 +57,7 @@ const DateTrigger = ({
|
|
|
53
57
|
})
|
|
54
58
|
}) : /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
55
59
|
className: "form-control-placeholder visible-xs-inline visible-sm-inline visible-md-inline visible-lg-inline visible-xl-inline",
|
|
60
|
+
id: ariaLabelIds[2],
|
|
56
61
|
children: placeholder
|
|
57
62
|
}), !onClear ? /*#__PURE__*/jsxRuntime.jsx(Chevron, {
|
|
58
63
|
orientation: position.Position.BOTTOM,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTrigger.js","sources":["../../../src/dateLookup/dateTrigger/DateTrigger.tsx"],"sourcesContent":["import { formatDate } from '@transferwise/formatting';\nimport { useIntl } from 'react-intl';\n\nimport Chevron from '../../chevron';\nimport { Size, Position, SizeSmall, SizeMedium, SizeLarge, Typography } from '../../common';\nimport { CloseButton } from '../../common/closeButton/CloseButton';\n\nimport messages from './DateTrigger.messages';\nimport { useContext } from 'react';\nimport { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider';\nimport Body from '../../body';\n\ninterface DateTriggerProps {\n ariaLabelledBy?: string;\n selectedDate: Date | null;\n size: SizeSmall | SizeMedium | SizeLarge;\n placeholder: string;\n label: string;\n monthFormat: 'short' | 'long';\n disabled: boolean;\n onClick: () => void;\n onClear?: () => void;\n}\n\nconst DateTrigger: React.FC<DateTriggerProps> = ({\n selectedDate,\n size = Size.MEDIUM,\n placeholder,\n label,\n monthFormat,\n disabled,\n ariaLabelledBy,\n onClick,\n onClear,\n}) => {\n const { locale, formatMessage } = useIntl();\n
|
|
1
|
+
{"version":3,"file":"DateTrigger.js","sources":["../../../src/dateLookup/dateTrigger/DateTrigger.tsx"],"sourcesContent":["import { formatDate } from '@transferwise/formatting';\nimport { useIntl } from 'react-intl';\n\nimport Chevron from '../../chevron';\nimport { Size, Position, SizeSmall, SizeMedium, SizeLarge, Typography } from '../../common';\nimport { CloseButton } from '../../common/closeButton/CloseButton';\n\nimport messages from './DateTrigger.messages';\nimport { useContext, useId } from 'react';\nimport { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider';\nimport Body from '../../body';\n\ninterface DateTriggerProps {\n ariaLabelledBy?: string;\n selectedDate: Date | null;\n size: SizeSmall | SizeMedium | SizeLarge;\n placeholder: string;\n label: string;\n monthFormat: 'short' | 'long';\n disabled: boolean;\n onClick: () => void;\n onClear?: () => void;\n}\n\nconst DateTrigger: React.FC<DateTriggerProps> = ({\n selectedDate,\n size = Size.MEDIUM,\n placeholder,\n label,\n monthFormat,\n disabled,\n ariaLabelledBy,\n onClick,\n onClear,\n}) => {\n const { locale, formatMessage } = useIntl();\n const valueIdPrefix = useId();\n const overlayId = useContext(OverlayIdContext);\n const ariaLabelIds = [ariaLabelledBy, `${valueIdPrefix}:prefix`, `${valueIdPrefix}:value`];\n\n return (\n <>\n <button\n aria-haspopup=\"dialog\"\n aria-expanded={overlayId != null}\n aria-controls={overlayId}\n aria-labelledby={ariaLabelIds.filter(Boolean).join(' ')}\n className={`btn btn-${size} btn-input np-date-trigger`}\n disabled={disabled}\n type=\"button\"\n onClick={onClick}\n >\n {label && (\n <Body as=\"span\" className=\"np-date-trigger-label m-r-1\" id={ariaLabelIds[1]}>\n {label}\n </Body>\n )}\n {selectedDate ? (\n <Body as=\"span\" type={Typography.BODY_LARGE} id={ariaLabelIds[2]}>\n {formatDate(selectedDate, locale, {\n day: 'numeric',\n month: monthFormat,\n year: 'numeric',\n })}\n </Body>\n ) : (\n <span\n className=\"form-control-placeholder visible-xs-inline visible-sm-inline\n visible-md-inline visible-lg-inline visible-xl-inline\"\n id={ariaLabelIds[2]}\n >\n {placeholder}\n </span>\n )}\n {!onClear ? <Chevron orientation={Position.BOTTOM} disabled={disabled} /> : null}\n </button>\n {onClear ? (\n <>\n <div className=\"clearfix\" />\n <span className=\"input-group-addon\">\n <CloseButton\n className={`clear-btn clear-btn--${size}`}\n aria-label={`${formatMessage(messages.ariaLabel)} ${label}`}\n size={Size.SMALL}\n onClick={(event: React.MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation();\n event.preventDefault();\n onClear();\n }}\n />\n </span>\n </>\n ) : null}\n </>\n );\n};\n\nexport default DateTrigger;\n"],"names":["DateTrigger","selectedDate","size","Size","MEDIUM","placeholder","label","monthFormat","disabled","ariaLabelledBy","onClick","onClear","locale","formatMessage","useIntl","valueIdPrefix","useId","overlayId","useContext","OverlayIdContext","ariaLabelIds","_jsxs","_Fragment","children","filter","Boolean","join","className","type","_jsx","Body","as","id","Typography","BODY_LARGE","formatDate","day","month","year","Chevron","orientation","Position","BOTTOM","CloseButton","messages","ariaLabel","SMALL","event","stopPropagation","preventDefault"],"mappings":";;;;;;;;;;;;;;;AAwBMA,MAAAA,WAAW,GAA+BA,CAAC;EAC/CC,YAAY;QACZC,MAAI,GAAGC,SAAI,CAACC,MAAM;EAClBC,WAAW;EACXC,KAAK;EACLC,WAAW;EACXC,QAAQ;EACRC,cAAc;EACdC,OAAO;AACPC,EAAAA,OAAAA;AACD,CAAA,KAAI;EACH,MAAM;IAAEC,MAAM;AAAEC,IAAAA,aAAAA;GAAe,GAAGC,iBAAO,EAAE,CAAA;AAC3C,EAAA,MAAMC,aAAa,GAAGC,WAAK,EAAE,CAAA;AAC7B,EAAA,MAAMC,SAAS,GAAGC,gBAAU,CAACC,kCAAgB,CAAC,CAAA;AAC9C,EAAA,MAAMC,YAAY,GAAG,CAACX,cAAc,EAAE,CAAA,EAAGM,aAAa,CAAA,OAAA,CAAS,EAAE,CAAA,EAAGA,aAAa,CAAA,MAAA,CAAQ,CAAC,CAAA;EAE1F,oBACEM,eAAA,CAAAC,mBAAA,EAAA;AAAAC,IAAAA,QAAA,gBACEF,eAAA,CAAA,QAAA,EAAA;AACE,MAAA,eAAA,EAAc,QAAQ;MACtB,eAAeJ,EAAAA,SAAS,IAAI,IAAK;AACjC,MAAA,eAAA,EAAeA,SAAU;MACzB,iBAAiBG,EAAAA,YAAY,CAACI,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAE;MACxDC,SAAS,EAAE,CAAWzB,QAAAA,EAAAA,MAAI,CAA6B,0BAAA,CAAA;AACvDM,MAAAA,QAAQ,EAAEA,QAAS;AACnBoB,MAAAA,IAAI,EAAC,QAAQ;AACblB,MAAAA,OAAO,EAAEA,OAAQ;AAAAa,MAAAA,QAAA,EAEhBjB,CAAAA,KAAK,iBACJuB,cAAA,CAACC,IAAI,EAAA;AAACC,QAAA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,CAACC,SAAS,CAAC,CAAIvC,CAAAA,EAAAA,KAAK,CAAG,CAAA;UAC5DJ,IAAI,EAAEC,SAAI,CAAC2C,KAAM;UACjBpC,OAAO,EAAGqC,KAA0C,IAAI;YACtDA,KAAK,CAACC,eAAe,EAAE,CAAA;YACvBD,KAAK,CAACE,cAAc,EAAE,CAAA;AACtBtC,YAAAA,OAAO,EAAE,CAAA;AACX,WAAA;SAEJ,CAAA;AAAA,OAAM,CACR,CAAA;KAAA,CAAG,GACD,IAAI,CAAA;AAAA,GACV,CAAG,CAAA;AAEP;;;;"}
|
|
@@ -3,7 +3,7 @@ import { useIntl } from 'react-intl';
|
|
|
3
3
|
import Chevron from '../../chevron/Chevron.mjs';
|
|
4
4
|
import { CloseButton } from '../../common/closeButton/CloseButton.mjs';
|
|
5
5
|
import dateTriggerMessages from './DateTrigger.messages.mjs';
|
|
6
|
-
import { useContext } from 'react';
|
|
6
|
+
import { useId, useContext } from 'react';
|
|
7
7
|
import { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider.mjs';
|
|
8
8
|
import Body from '../../body/Body.mjs';
|
|
9
9
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
@@ -26,13 +26,15 @@ const DateTrigger = ({
|
|
|
26
26
|
locale,
|
|
27
27
|
formatMessage
|
|
28
28
|
} = useIntl();
|
|
29
|
+
const valueIdPrefix = useId();
|
|
29
30
|
const overlayId = useContext(OverlayIdContext);
|
|
31
|
+
const ariaLabelIds = [ariaLabelledBy, `${valueIdPrefix}:prefix`, `${valueIdPrefix}:value`];
|
|
30
32
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
31
33
|
children: [/*#__PURE__*/jsxs("button", {
|
|
32
34
|
"aria-haspopup": "dialog",
|
|
33
35
|
"aria-expanded": overlayId != null,
|
|
34
36
|
"aria-controls": overlayId,
|
|
35
|
-
"aria-labelledby":
|
|
37
|
+
"aria-labelledby": ariaLabelIds.filter(Boolean).join(' '),
|
|
36
38
|
className: `btn btn-${size} btn-input np-date-trigger`,
|
|
37
39
|
disabled: disabled,
|
|
38
40
|
type: "button",
|
|
@@ -40,10 +42,12 @@ const DateTrigger = ({
|
|
|
40
42
|
children: [label && /*#__PURE__*/jsx(Body, {
|
|
41
43
|
as: "span",
|
|
42
44
|
className: "np-date-trigger-label m-r-1",
|
|
45
|
+
id: ariaLabelIds[1],
|
|
43
46
|
children: label
|
|
44
47
|
}), selectedDate ? /*#__PURE__*/jsx(Body, {
|
|
45
48
|
as: "span",
|
|
46
49
|
type: Typography.BODY_LARGE,
|
|
50
|
+
id: ariaLabelIds[2],
|
|
47
51
|
children: formatDate(selectedDate, locale, {
|
|
48
52
|
day: 'numeric',
|
|
49
53
|
month: monthFormat,
|
|
@@ -51,6 +55,7 @@ const DateTrigger = ({
|
|
|
51
55
|
})
|
|
52
56
|
}) : /*#__PURE__*/jsx("span", {
|
|
53
57
|
className: "form-control-placeholder visible-xs-inline visible-sm-inline visible-md-inline visible-lg-inline visible-xl-inline",
|
|
58
|
+
id: ariaLabelIds[2],
|
|
54
59
|
children: placeholder
|
|
55
60
|
}), !onClear ? /*#__PURE__*/jsx(Chevron, {
|
|
56
61
|
orientation: Position.BOTTOM,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTrigger.mjs","sources":["../../../src/dateLookup/dateTrigger/DateTrigger.tsx"],"sourcesContent":["import { formatDate } from '@transferwise/formatting';\nimport { useIntl } from 'react-intl';\n\nimport Chevron from '../../chevron';\nimport { Size, Position, SizeSmall, SizeMedium, SizeLarge, Typography } from '../../common';\nimport { CloseButton } from '../../common/closeButton/CloseButton';\n\nimport messages from './DateTrigger.messages';\nimport { useContext } from 'react';\nimport { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider';\nimport Body from '../../body';\n\ninterface DateTriggerProps {\n ariaLabelledBy?: string;\n selectedDate: Date | null;\n size: SizeSmall | SizeMedium | SizeLarge;\n placeholder: string;\n label: string;\n monthFormat: 'short' | 'long';\n disabled: boolean;\n onClick: () => void;\n onClear?: () => void;\n}\n\nconst DateTrigger: React.FC<DateTriggerProps> = ({\n selectedDate,\n size = Size.MEDIUM,\n placeholder,\n label,\n monthFormat,\n disabled,\n ariaLabelledBy,\n onClick,\n onClear,\n}) => {\n const { locale, formatMessage } = useIntl();\n
|
|
1
|
+
{"version":3,"file":"DateTrigger.mjs","sources":["../../../src/dateLookup/dateTrigger/DateTrigger.tsx"],"sourcesContent":["import { formatDate } from '@transferwise/formatting';\nimport { useIntl } from 'react-intl';\n\nimport Chevron from '../../chevron';\nimport { Size, Position, SizeSmall, SizeMedium, SizeLarge, Typography } from '../../common';\nimport { CloseButton } from '../../common/closeButton/CloseButton';\n\nimport messages from './DateTrigger.messages';\nimport { useContext, useId } from 'react';\nimport { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider';\nimport Body from '../../body';\n\ninterface DateTriggerProps {\n ariaLabelledBy?: string;\n selectedDate: Date | null;\n size: SizeSmall | SizeMedium | SizeLarge;\n placeholder: string;\n label: string;\n monthFormat: 'short' | 'long';\n disabled: boolean;\n onClick: () => void;\n onClear?: () => void;\n}\n\nconst DateTrigger: React.FC<DateTriggerProps> = ({\n selectedDate,\n size = Size.MEDIUM,\n placeholder,\n label,\n monthFormat,\n disabled,\n ariaLabelledBy,\n onClick,\n onClear,\n}) => {\n const { locale, formatMessage } = useIntl();\n const valueIdPrefix = useId();\n const overlayId = useContext(OverlayIdContext);\n const ariaLabelIds = [ariaLabelledBy, `${valueIdPrefix}:prefix`, `${valueIdPrefix}:value`];\n\n return (\n <>\n <button\n aria-haspopup=\"dialog\"\n aria-expanded={overlayId != null}\n aria-controls={overlayId}\n aria-labelledby={ariaLabelIds.filter(Boolean).join(' ')}\n className={`btn btn-${size} btn-input np-date-trigger`}\n disabled={disabled}\n type=\"button\"\n onClick={onClick}\n >\n {label && (\n <Body as=\"span\" className=\"np-date-trigger-label m-r-1\" id={ariaLabelIds[1]}>\n {label}\n </Body>\n )}\n {selectedDate ? (\n <Body as=\"span\" type={Typography.BODY_LARGE} id={ariaLabelIds[2]}>\n {formatDate(selectedDate, locale, {\n day: 'numeric',\n month: monthFormat,\n year: 'numeric',\n })}\n </Body>\n ) : (\n <span\n className=\"form-control-placeholder visible-xs-inline visible-sm-inline\n visible-md-inline visible-lg-inline visible-xl-inline\"\n id={ariaLabelIds[2]}\n >\n {placeholder}\n </span>\n )}\n {!onClear ? <Chevron orientation={Position.BOTTOM} disabled={disabled} /> : null}\n </button>\n {onClear ? (\n <>\n <div className=\"clearfix\" />\n <span className=\"input-group-addon\">\n <CloseButton\n className={`clear-btn clear-btn--${size}`}\n aria-label={`${formatMessage(messages.ariaLabel)} ${label}`}\n size={Size.SMALL}\n onClick={(event: React.MouseEvent<HTMLButtonElement>) => {\n event.stopPropagation();\n event.preventDefault();\n onClear();\n }}\n />\n </span>\n </>\n ) : null}\n </>\n );\n};\n\nexport default DateTrigger;\n"],"names":["DateTrigger","selectedDate","size","Size","MEDIUM","placeholder","label","monthFormat","disabled","ariaLabelledBy","onClick","onClear","locale","formatMessage","useIntl","valueIdPrefix","useId","overlayId","useContext","OverlayIdContext","ariaLabelIds","_jsxs","_Fragment","children","filter","Boolean","join","className","type","_jsx","Body","as","id","Typography","BODY_LARGE","formatDate","day","month","year","Chevron","orientation","Position","BOTTOM","CloseButton","messages","ariaLabel","SMALL","event","stopPropagation","preventDefault"],"mappings":";;;;;;;;;;;;;AAwBMA,MAAAA,WAAW,GAA+BA,CAAC;EAC/CC,YAAY;EACZC,IAAI,GAAGC,IAAI,CAACC,MAAM;EAClBC,WAAW;EACXC,KAAK;EACLC,WAAW;EACXC,QAAQ;EACRC,cAAc;EACdC,OAAO;AACPC,EAAAA,OAAAA;AACD,CAAA,KAAI;EACH,MAAM;IAAEC,MAAM;AAAEC,IAAAA,aAAAA;GAAe,GAAGC,OAAO,EAAE,CAAA;AAC3C,EAAA,MAAMC,aAAa,GAAGC,KAAK,EAAE,CAAA;AAC7B,EAAA,MAAMC,SAAS,GAA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C,gBAEPT,GAAA,CAAA,MAAA,EAAA;AACEF,QAAAA,SAAS,EAAC,oHACuD;AACjEK,QAAAA,EAAE,EAAEZ,YAAY,CAAC,CAAC,CAAE;AAAAG,QAAAA,QAAA,EAEnBlB,WAAAA;AAAW,OACR,CACP,EACA,CAACM,OAAO,gBAAGkB,GAAA,CAACU,OAAO,EAAA;QAACC,WAAW,EAAEC,QAAQ,CAACC,MAAO;AAAClC,QAAAA,QAAQ,EAAEA,QAAAA;OAAS,CAAG,GAAG,IAAI,CAAA;AAAA,KAC1E,CACR,EAACG,OAAO,gBACNU,IAAA,CAAAC,QAAA,EAAA;AAAAC,MAAAA,QAAA,gBACEM,GAAA,CAAA,KAAA,EAAA;AAAKF,QAAAA,SAAS,EAAC,UAAA;OACf,CAAA,eAAAE,GAAA,CAAA,MAAA,EAAA;AAAMF,QAAAA,SAAS,EAAC,mBAAmB;QAAAJ,QAAA,eACjCM,GAAA,CAACc,WAAW,EAAA;UACVhB,SAAS,EAAE,CAAwBzB,qBAAAA,EAAAA,IAAI,CAAG,CAAA;UAC1C,YAAY,EAAA,CAAA,EAAGW,aAAa,CAAC+B,mBAAQ,CAACC,SAAS,CAAC,CAAIvC,CAAAA,EAAAA,KAAK,CAAG,CAAA;UAC5DJ,IAAI,EAAEC,IAAI,CAAC2C,KAAM;UACjBpC,OAAO,EAAGqC,KAA0C,IAAI;YACtDA,KAAK,CAACC,eAAe,EAAE,CAAA;YACvBD,KAAK,CAACE,cAAc,EAAE,CAAA;AACtBtC,YAAAA,OAAO,EAAE,CAAA;AACX,WAAA;SAEJ,CAAA;AAAA,OAAM,CACR,CAAA;KAAA,CAAG,GACD,IAAI,CAAA;AAAA,GACV,CAAG,CAAA;AAEP;;;;"}
|
|
@@ -33,6 +33,8 @@ export interface AlertProps {
|
|
|
33
33
|
/** The type dictates which icon and colour will be used */
|
|
34
34
|
type?: AlertType;
|
|
35
35
|
variant?: `${Variant}`;
|
|
36
|
+
/** 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. */
|
|
37
|
+
active?: boolean;
|
|
36
38
|
/** @deprecated Use `InlineAlert` instead. */
|
|
37
39
|
arrow?: `${AlertArrowPosition}`;
|
|
38
40
|
/** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */
|
|
@@ -42,6 +44,6 @@ export interface AlertProps {
|
|
|
42
44
|
/** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */
|
|
43
45
|
size?: `${Size}`;
|
|
44
46
|
}
|
|
45
|
-
export default function Alert({ arrow, action, children, className, dismissible, icon, onDismiss, message, size, title, type, variant, }: AlertProps): import("react").JSX.Element;
|
|
47
|
+
export default function Alert({ arrow, action, children, className, dismissible, icon, onDismiss, message, size, title, type, variant, active, }: AlertProps): import("react").JSX.Element;
|
|
46
48
|
export {};
|
|
47
49
|
//# sourceMappingURL=Alert.d.ts.map
|
|
@@ -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,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,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O,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,+BAyGZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTrigger.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/dateTrigger/DateTrigger.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAkB,SAAS,EAAE,UAAU,EAAE,SAAS,EAAc,MAAM,cAAc,CAAC;AAQ5F,UAAU,gBAAgB;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,GAAG,MAAM,CAAC;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"DateTrigger.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/dateTrigger/DateTrigger.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAkB,SAAS,EAAE,UAAU,EAAE,SAAS,EAAc,MAAM,cAAc,CAAC;AAQ5F,UAAU,gBAAgB;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,GAAG,MAAM,CAAC;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAuE3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/package.json
CHANGED
package/src/alert/Alert.spec.tsx
CHANGED
|
@@ -467,4 +467,24 @@ describe('Alert', () => {
|
|
|
467
467
|
expect(screen.getByTestId('status-icon')).toBeInTheDocument();
|
|
468
468
|
});
|
|
469
469
|
});
|
|
470
|
+
|
|
471
|
+
describe('`active` prop', () => {
|
|
472
|
+
it('should render wrapper and alert if `active` is unset', () => {
|
|
473
|
+
render(<Alert message={message} />);
|
|
474
|
+
expect(screen.getByRole('status')).toBeInTheDocument();
|
|
475
|
+
expect(screen.getByText(message)).toBeInTheDocument();
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it('should render wrapper and alert if `active={false}', () => {
|
|
479
|
+
render(<Alert message={message} active={false} />);
|
|
480
|
+
expect(screen.getByRole('status')).toBeInTheDocument();
|
|
481
|
+
expect(screen.queryByText(message)).not.toBeInTheDocument();
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it('should render wrapper and alert if `active` is set', () => {
|
|
485
|
+
render(<Alert message={message} />);
|
|
486
|
+
expect(screen.getByRole('status')).toBeInTheDocument();
|
|
487
|
+
expect(screen.getByText(message)).toBeInTheDocument();
|
|
488
|
+
});
|
|
489
|
+
});
|
|
470
490
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { useState } from 'react';
|
|
2
2
|
import { Meta, StoryObj } from '@storybook/react';
|
|
3
3
|
import { action } from '@storybook/addon-actions';
|
|
4
4
|
import { ClockBorderless } from '@transferwise/icons';
|
|
5
5
|
|
|
6
6
|
import { Sentiment } from '../common';
|
|
7
|
-
|
|
7
|
+
import { Button } from '..';
|
|
8
8
|
import Alert, { AlertArrowPosition } from './Alert';
|
|
9
9
|
|
|
10
10
|
export default {
|
|
@@ -12,6 +12,7 @@ export default {
|
|
|
12
12
|
title: 'Feedback/Alert',
|
|
13
13
|
args: {
|
|
14
14
|
type: Sentiment.POSITIVE,
|
|
15
|
+
active: true,
|
|
15
16
|
message:
|
|
16
17
|
'Payments sent to your bank details **today** might not arrive in time for the holidays.',
|
|
17
18
|
},
|
|
@@ -103,3 +104,50 @@ export const WithTitle: Story = {
|
|
|
103
104
|
onDismiss: () => {},
|
|
104
105
|
},
|
|
105
106
|
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* For ARIA live region to function correctly with screen readers,
|
|
110
|
+
* the container with an appropriate ARIA role (in the case of this
|
|
111
|
+
* component, it's `status` or `alert`) must be rendered first.
|
|
112
|
+
* Once present in the accessibility tree, its dynamic contents
|
|
113
|
+
* will be announced correctly.
|
|
114
|
+
*
|
|
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.
|
|
118
|
+
*/
|
|
119
|
+
export const ConditionallyRendered: Story = {
|
|
120
|
+
render: function Render(args) {
|
|
121
|
+
const [isActive, setIsActive] = useState(false);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<>
|
|
125
|
+
<Button htmlType="button" onClick={() => setIsActive((value) => !value)}>
|
|
126
|
+
Trigger Alert
|
|
127
|
+
</Button>
|
|
128
|
+
|
|
129
|
+
<Alert {...args} active={isActive} className="m-t-5" />
|
|
130
|
+
</>
|
|
131
|
+
);
|
|
132
|
+
},
|
|
133
|
+
parameters: {
|
|
134
|
+
docs: {
|
|
135
|
+
source: {
|
|
136
|
+
code: `
|
|
137
|
+
function Render (args) {
|
|
138
|
+
const [isActive, setIsActive] = useState(false);
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<>
|
|
142
|
+
<Button htmlType="button" onClick={() => setIsActive(value => !value)}>
|
|
143
|
+
Trigger Alert
|
|
144
|
+
</Button>
|
|
145
|
+
|
|
146
|
+
<Alert {...args} active={isActive} className="m-t-5" />
|
|
147
|
+
</>
|
|
148
|
+
)
|
|
149
|
+
}`,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|
package/src/alert/Alert.tsx
CHANGED
|
@@ -52,6 +52,8 @@ export interface AlertProps {
|
|
|
52
52
|
/** The type dictates which icon and colour will be used */
|
|
53
53
|
type?: AlertType;
|
|
54
54
|
variant?: `${Variant}`;
|
|
55
|
+
/** 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. */
|
|
56
|
+
active?: boolean;
|
|
55
57
|
/** @deprecated Use `InlineAlert` instead. */
|
|
56
58
|
arrow?: `${AlertArrowPosition}`;
|
|
57
59
|
/** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */
|
|
@@ -88,6 +90,7 @@ export default function Alert({
|
|
|
88
90
|
title,
|
|
89
91
|
type = 'neutral',
|
|
90
92
|
variant = 'desktop',
|
|
93
|
+
active = true,
|
|
91
94
|
}: AlertProps) {
|
|
92
95
|
useEffect(() => {
|
|
93
96
|
if (arrow !== undefined) {
|
|
@@ -133,59 +136,63 @@ export default function Alert({
|
|
|
133
136
|
const closeButtonReference = useRef<HTMLButtonElement>(null);
|
|
134
137
|
|
|
135
138
|
return (
|
|
136
|
-
<div
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
<div role={Sentiment.NEGATIVE === resolvedType ? 'alert' : 'status'}>
|
|
175
|
-
{title && (
|
|
176
|
-
<Title className="m-b-1" type={Typography.TITLE_BODY}>
|
|
177
|
-
{title}
|
|
178
|
-
</Title>
|
|
139
|
+
<div role={resolvedType === Sentiment.NEGATIVE ? 'alert' : 'status'}>
|
|
140
|
+
{active && (
|
|
141
|
+
<div
|
|
142
|
+
className={clsx(
|
|
143
|
+
'alert d-flex',
|
|
144
|
+
`alert-${resolvedType}`,
|
|
145
|
+
arrow != null && alertArrowClassNames(arrow),
|
|
146
|
+
className,
|
|
147
|
+
)}
|
|
148
|
+
data-testid="alert"
|
|
149
|
+
onTouchStart={() => setShouldFire(true)}
|
|
150
|
+
onTouchEnd={(event) => {
|
|
151
|
+
if (
|
|
152
|
+
shouldFire &&
|
|
153
|
+
action?.href &&
|
|
154
|
+
// Check if current event is triggered from closeButton
|
|
155
|
+
event.target instanceof Node &&
|
|
156
|
+
closeButtonReference.current &&
|
|
157
|
+
!closeButtonReference.current.contains(event.target)
|
|
158
|
+
) {
|
|
159
|
+
if (action.target === '_blank') {
|
|
160
|
+
window.top?.open(action.href);
|
|
161
|
+
} else {
|
|
162
|
+
window.top?.location.assign(action.href);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
setShouldFire(false);
|
|
166
|
+
}}
|
|
167
|
+
onTouchMove={() => setShouldFire(false)}
|
|
168
|
+
>
|
|
169
|
+
<div
|
|
170
|
+
className={clsx('alert__content', 'd-flex', 'flex-grow-1', variant)}
|
|
171
|
+
data-testid={variant}
|
|
172
|
+
>
|
|
173
|
+
{icon ? (
|
|
174
|
+
<div className="alert__icon">{icon}</div>
|
|
175
|
+
) : (
|
|
176
|
+
<StatusIcon size={Size.LARGE} sentiment={resolvedType} />
|
|
179
177
|
)}
|
|
180
|
-
<
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
<div className="alert__message">
|
|
179
|
+
<div>
|
|
180
|
+
{title && (
|
|
181
|
+
<Title className="m-b-1" type={Typography.TITLE_BODY}>
|
|
182
|
+
{title}
|
|
183
|
+
</Title>
|
|
184
|
+
)}
|
|
185
|
+
<Body as="span" className="d-block" type={Typography.BODY_LARGE}>
|
|
186
|
+
{children || <InlineMarkdown>{message}</InlineMarkdown>}
|
|
187
|
+
</Body>
|
|
188
|
+
</div>
|
|
189
|
+
{action && <Action action={action} className="m-t-1" />}
|
|
190
|
+
</div>
|
|
183
191
|
</div>
|
|
184
|
-
{
|
|
192
|
+
{onDismiss && (
|
|
193
|
+
<CloseButton ref={closeButtonReference} className="m-l-2" onClick={onDismiss} />
|
|
194
|
+
)}
|
|
185
195
|
</div>
|
|
186
|
-
</div>
|
|
187
|
-
{onDismiss && (
|
|
188
|
-
<CloseButton ref={closeButtonReference} className="m-l-2" onClick={onDismiss} />
|
|
189
196
|
)}
|
|
190
197
|
</div>
|
|
191
198
|
);
|
|
@@ -28,7 +28,7 @@ describe('DateLookup', () => {
|
|
|
28
28
|
<DateLookup value={initialValue} onChange={() => {}} />
|
|
29
29
|
</Field>,
|
|
30
30
|
);
|
|
31
|
-
const button = screen.getByRole('button', { name:
|
|
31
|
+
const button = screen.getByRole('button', { name: /^Date of birth/ });
|
|
32
32
|
|
|
33
33
|
expect(button).toBeInTheDocument();
|
|
34
34
|
expect(button).toHaveAttribute('aria-haspopup');
|
|
@@ -66,7 +66,7 @@ export const WithField = () => {
|
|
|
66
66
|
const disabled = boolean('disabled', false);
|
|
67
67
|
const label = text('label', 'label');
|
|
68
68
|
const monthFormat = select('monthFormat', ['long', 'short'], 'long');
|
|
69
|
-
const placeholder = text('placeholder', '
|
|
69
|
+
const placeholder = text('placeholder', 'Select date');
|
|
70
70
|
const id = text('id', 'date-lookup');
|
|
71
71
|
|
|
72
72
|
const clearable = boolean('clearable', true);
|
|
@@ -23,7 +23,7 @@ describe('DateLookup (events)', () => {
|
|
|
23
23
|
/** @type {jest.Mock} */
|
|
24
24
|
let handleChange;
|
|
25
25
|
|
|
26
|
-
const setup = async () => {
|
|
26
|
+
const setup = async (overrides = {}) => {
|
|
27
27
|
handleChange = jest.fn();
|
|
28
28
|
|
|
29
29
|
/** @type {import('@testing-library/react').RenderResult} */
|
|
@@ -38,13 +38,14 @@ describe('DateLookup (events)', () => {
|
|
|
38
38
|
min={min}
|
|
39
39
|
max={max}
|
|
40
40
|
size="lg"
|
|
41
|
-
placeholder="
|
|
41
|
+
placeholder="Select date"
|
|
42
42
|
label="label"
|
|
43
43
|
aria-labelledby="prioritized-label"
|
|
44
44
|
disabled={false}
|
|
45
45
|
clearable={false}
|
|
46
46
|
onChange={handleChange}
|
|
47
47
|
onClick={jest.fn()}
|
|
48
|
+
{...overrides}
|
|
48
49
|
/>
|
|
49
50
|
</>,
|
|
50
51
|
);
|
|
@@ -148,7 +149,23 @@ describe('DateLookup (events)', () => {
|
|
|
148
149
|
|
|
149
150
|
it('supports custom `aria-labelledby` attribute', async () => {
|
|
150
151
|
const view = await setup();
|
|
151
|
-
expect(screen.getByRole('button', { name:
|
|
152
|
+
expect(screen.getByRole('button', { name: /^Prioritized label/ })).toBeInTheDocument();
|
|
153
|
+
await closeDateLookup(view);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('reads our the HTML label as well as the input prefix and the value', async () => {
|
|
157
|
+
const view = await setup();
|
|
158
|
+
expect(
|
|
159
|
+
screen.getByRole('button', { name: 'Prioritized label label 27 December 2018' }),
|
|
160
|
+
).toBeInTheDocument();
|
|
161
|
+
await closeDateLookup(view);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('reads our the HTML label as well as the input prefix and the placeholder', async () => {
|
|
165
|
+
const view = await setup({ value: undefined });
|
|
166
|
+
expect(
|
|
167
|
+
screen.getByRole('button', { name: 'Prioritized label label Select date' }),
|
|
168
|
+
).toBeInTheDocument();
|
|
152
169
|
await closeDateLookup(view);
|
|
153
170
|
});
|
|
154
171
|
});
|
|
@@ -6,7 +6,7 @@ import { Size, Position, SizeSmall, SizeMedium, SizeLarge, Typography } from '..
|
|
|
6
6
|
import { CloseButton } from '../../common/closeButton/CloseButton';
|
|
7
7
|
|
|
8
8
|
import messages from './DateTrigger.messages';
|
|
9
|
-
import { useContext } from 'react';
|
|
9
|
+
import { useContext, useId } from 'react';
|
|
10
10
|
import { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider';
|
|
11
11
|
import Body from '../../body';
|
|
12
12
|
|
|
@@ -34,8 +34,9 @@ const DateTrigger: React.FC<DateTriggerProps> = ({
|
|
|
34
34
|
onClear,
|
|
35
35
|
}) => {
|
|
36
36
|
const { locale, formatMessage } = useIntl();
|
|
37
|
-
|
|
37
|
+
const valueIdPrefix = useId();
|
|
38
38
|
const overlayId = useContext(OverlayIdContext);
|
|
39
|
+
const ariaLabelIds = [ariaLabelledBy, `${valueIdPrefix}:prefix`, `${valueIdPrefix}:value`];
|
|
39
40
|
|
|
40
41
|
return (
|
|
41
42
|
<>
|
|
@@ -43,19 +44,19 @@ const DateTrigger: React.FC<DateTriggerProps> = ({
|
|
|
43
44
|
aria-haspopup="dialog"
|
|
44
45
|
aria-expanded={overlayId != null}
|
|
45
46
|
aria-controls={overlayId}
|
|
46
|
-
aria-labelledby={
|
|
47
|
+
aria-labelledby={ariaLabelIds.filter(Boolean).join(' ')}
|
|
47
48
|
className={`btn btn-${size} btn-input np-date-trigger`}
|
|
48
49
|
disabled={disabled}
|
|
49
50
|
type="button"
|
|
50
51
|
onClick={onClick}
|
|
51
52
|
>
|
|
52
53
|
{label && (
|
|
53
|
-
<Body as="span" className="np-date-trigger-label m-r-1">
|
|
54
|
+
<Body as="span" className="np-date-trigger-label m-r-1" id={ariaLabelIds[1]}>
|
|
54
55
|
{label}
|
|
55
56
|
</Body>
|
|
56
57
|
)}
|
|
57
58
|
{selectedDate ? (
|
|
58
|
-
<Body as="span" type={Typography.BODY_LARGE}>
|
|
59
|
+
<Body as="span" type={Typography.BODY_LARGE} id={ariaLabelIds[2]}>
|
|
59
60
|
{formatDate(selectedDate, locale, {
|
|
60
61
|
day: 'numeric',
|
|
61
62
|
month: monthFormat,
|
|
@@ -66,6 +67,7 @@ const DateTrigger: React.FC<DateTriggerProps> = ({
|
|
|
66
67
|
<span
|
|
67
68
|
className="form-control-placeholder visible-xs-inline visible-sm-inline
|
|
68
69
|
visible-md-inline visible-lg-inline visible-xl-inline"
|
|
70
|
+
id={ariaLabelIds[2]}
|
|
69
71
|
>
|
|
70
72
|
{placeholder}
|
|
71
73
|
</span>
|