@transferwise/components 0.0.0-experimental-805500d → 0.0.0-experimental-2b2d326
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/common/bottomSheet/BottomSheet.js +8 -2
- package/build/common/bottomSheet/BottomSheet.js.map +1 -1
- package/build/common/bottomSheet/BottomSheet.mjs +8 -2
- package/build/common/bottomSheet/BottomSheet.mjs.map +1 -1
- package/build/drawer/Drawer.js +5 -3
- package/build/drawer/Drawer.js.map +1 -1
- package/build/drawer/Drawer.mjs +5 -3
- package/build/drawer/Drawer.mjs.map +1 -1
- package/build/flowNavigation/FlowNavigation.js +1 -1
- package/build/flowNavigation/FlowNavigation.js.map +1 -1
- package/build/flowNavigation/FlowNavigation.mjs +1 -1
- package/build/flowNavigation/FlowNavigation.mjs.map +1 -1
- package/build/flowNavigation/animatedLabel/AnimatedLabel.js +89 -15
- package/build/flowNavigation/animatedLabel/AnimatedLabel.js.map +1 -1
- package/build/flowNavigation/animatedLabel/AnimatedLabel.mjs +90 -16
- package/build/flowNavigation/animatedLabel/AnimatedLabel.mjs.map +1 -1
- package/build/main.css +9 -0
- package/build/styles/flowNavigation/animatedLabel/AnimatedLabel.css +9 -0
- package/build/styles/main.css +9 -0
- package/build/types/common/bottomSheet/BottomSheet.d.ts +3 -3
- package/build/types/common/bottomSheet/BottomSheet.d.ts.map +1 -1
- package/build/types/drawer/Drawer.d.ts +4 -3
- package/build/types/drawer/Drawer.d.ts.map +1 -1
- package/build/types/flowNavigation/FlowNavigation.d.ts.map +1 -1
- package/build/types/flowNavigation/animatedLabel/AnimatedLabel.d.ts +3 -3
- package/build/types/flowNavigation/animatedLabel/AnimatedLabel.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/common/bottomSheet/BottomSheet.tsx +13 -4
- package/src/drawer/Drawer.tsx +7 -5
- package/src/flowNavigation/FlowNavigation.story.js +69 -17
- package/src/flowNavigation/FlowNavigation.tsx +1 -5
- package/src/flowNavigation/animatedLabel/AnimatedLabel.css +9 -0
- package/src/flowNavigation/animatedLabel/AnimatedLabel.less +9 -0
- package/src/flowNavigation/animatedLabel/AnimatedLabel.spec.js +19 -21
- package/src/flowNavigation/animatedLabel/AnimatedLabel.tsx +102 -20
- package/src/main.css +9 -0
- package/src/flowNavigation/animatedLabel/__snapshots__/AnimatedLabel.spec.js.snap +0 -25
|
@@ -1,25 +1,99 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
|
-
import 'react';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
2
|
+
import { useId, useState } from 'react';
|
|
3
|
+
import BottomSheet from '../../common/bottomSheet/BottomSheet.mjs';
|
|
4
|
+
import Option from '../../common/Option/Option.mjs';
|
|
5
|
+
import { ChevronDown, Check } from '@transferwise/icons';
|
|
6
|
+
import { OverlayIdProvider, OverlayIdContext } from '../../provider/overlay/OverlayIdProvider.mjs';
|
|
7
|
+
import { List } from '../../listItem/List.mjs';
|
|
8
|
+
import '../../body/Body.mjs';
|
|
9
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
10
|
|
|
7
11
|
const AnimatedLabel = ({
|
|
8
12
|
activeLabel,
|
|
9
13
|
className,
|
|
10
|
-
|
|
14
|
+
steps
|
|
11
15
|
}) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const labelId = useId();
|
|
17
|
+
const [showSteps, setShowSteps] = useState(false);
|
|
18
|
+
function handleStepAction(onClick) {
|
|
19
|
+
return () => {
|
|
20
|
+
setShowSteps(false);
|
|
21
|
+
onClick?.();
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return /*#__PURE__*/jsx(OverlayIdProvider, {
|
|
25
|
+
open: showSteps,
|
|
26
|
+
children: /*#__PURE__*/jsx(OverlayIdContext.Consumer, {
|
|
27
|
+
children: overlayId => {
|
|
28
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
29
|
+
children: [/*#__PURE__*/jsx("button", {
|
|
30
|
+
type: "button",
|
|
31
|
+
id: labelId,
|
|
32
|
+
"aria-haspopup": "menu",
|
|
33
|
+
"aria-controls": overlayId,
|
|
34
|
+
"aria-expanded": showSteps,
|
|
35
|
+
className: clsx('np-animated-label', 'btn-unstyled', 'np-text-body-large-bold', className),
|
|
36
|
+
onClick: () => setShowSteps(true),
|
|
37
|
+
children: steps.map(({
|
|
38
|
+
label
|
|
39
|
+
}, index) => {
|
|
40
|
+
const isCurrentStep = activeLabel === index;
|
|
41
|
+
const nextLabel = index - 1;
|
|
42
|
+
return /*#__PURE__*/jsxs("div", {
|
|
43
|
+
"aria-hidden": !isCurrentStep,
|
|
44
|
+
className: clsx('text-xs-center', 'd-inline-flex', {
|
|
45
|
+
'np-animated-label--in text-ellipsis': isCurrentStep
|
|
46
|
+
}),
|
|
47
|
+
children: [label, " ", /*#__PURE__*/jsx(ChevronDown, {
|
|
48
|
+
className: "m-l-1",
|
|
49
|
+
size: 24
|
|
50
|
+
})]
|
|
51
|
+
}, nextLabel);
|
|
52
|
+
})
|
|
53
|
+
}), /*#__PURE__*/jsx(BottomSheet, {
|
|
54
|
+
role: "menu",
|
|
55
|
+
"aria-labelledby": labelId,
|
|
56
|
+
open: showSteps,
|
|
57
|
+
onClose: () => setShowSteps(false),
|
|
58
|
+
children: /*#__PURE__*/jsx(List, {
|
|
59
|
+
className: "p-a-1",
|
|
60
|
+
children: steps.map((step, index) => {
|
|
61
|
+
const isCurrentStep = activeLabel === index;
|
|
62
|
+
const isDisabled = activeLabel < index;
|
|
63
|
+
const itemId = `step-${index}`;
|
|
64
|
+
return /*#__PURE__*/jsx(Option, {
|
|
65
|
+
id: itemId,
|
|
66
|
+
as: "li",
|
|
67
|
+
role: "menuitem",
|
|
68
|
+
decision: false,
|
|
69
|
+
className: clsx('np-animated-label-option', 'p-x-3', 'p-y-1', 'm-y-1', {
|
|
70
|
+
clickable: !isDisabled
|
|
71
|
+
}),
|
|
72
|
+
title: step.label,
|
|
73
|
+
content: step.hoverLabel,
|
|
74
|
+
button: isCurrentStep ? /*#__PURE__*/jsx(Check, {
|
|
75
|
+
size: 24
|
|
76
|
+
}) : null,
|
|
77
|
+
"aria-current": isCurrentStep ? 'step' : false,
|
|
78
|
+
"aria-disabled": isDisabled,
|
|
79
|
+
disabled: isDisabled,
|
|
80
|
+
isContainerAligned: true,
|
|
81
|
+
...(!isDisabled && {
|
|
82
|
+
tabIndex: 0,
|
|
83
|
+
onClick: handleStepAction(step.onClick),
|
|
84
|
+
onKeyDown: event => {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
if (event.code === 'Enter' || event.code === 'Space') {
|
|
87
|
+
handleStepAction(step.onClick)();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
}, itemId);
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
})]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
23
97
|
})
|
|
24
98
|
});
|
|
25
99
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimatedLabel.mjs","sources":["../../../src/flowNavigation/animatedLabel/AnimatedLabel.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport
|
|
1
|
+
{"version":3,"file":"AnimatedLabel.mjs","sources":["../../../src/flowNavigation/animatedLabel/AnimatedLabel.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { useId, useState } from 'react';\n\nimport type { Step } from '../../stepper/Stepper';\nimport BottomSheet from '../../common/bottomSheet';\nimport Option from '../../common/Option';\nimport { Check, ChevronDown } from '@transferwise/icons';\nimport { OverlayIdContext, OverlayIdProvider } from '../../provider/overlay/OverlayIdProvider';\nimport { List } from '../../listItem';\n\nexport interface AnimatedLabelProps {\n activeLabel: number;\n className?: string;\n steps: readonly Step[];\n}\n\nconst AnimatedLabel = ({ activeLabel, className, steps }: AnimatedLabelProps) => {\n const labelId = useId();\n const [showSteps, setShowSteps] = useState(false);\n\n function handleStepAction(onClick: Step['onClick']) {\n return () => {\n setShowSteps(false);\n onClick?.();\n };\n }\n\n return (\n <OverlayIdProvider open={showSteps}>\n <OverlayIdContext.Consumer>\n {(overlayId) => {\n return (\n <>\n <button\n type=\"button\"\n id={labelId}\n aria-haspopup=\"menu\"\n aria-controls={overlayId}\n aria-expanded={showSteps}\n className={clsx(\n 'np-animated-label',\n 'btn-unstyled',\n 'np-text-body-large-bold',\n className,\n )}\n onClick={() => setShowSteps(true)}\n >\n {steps.map(({ label }, index) => {\n const isCurrentStep = activeLabel === index;\n const nextLabel = index - 1;\n return (\n <div\n key={nextLabel}\n aria-hidden={!isCurrentStep}\n className={clsx('text-xs-center', 'd-inline-flex', {\n 'np-animated-label--in text-ellipsis': isCurrentStep,\n })}\n >\n {label} <ChevronDown className=\"m-l-1\" size={24} />\n </div>\n );\n })}\n </button>\n <BottomSheet\n role=\"menu\"\n aria-labelledby={labelId}\n open={showSteps}\n onClose={() => setShowSteps(false)}\n >\n <List className=\"p-a-1\">\n {steps.map((step, index) => {\n const isCurrentStep = activeLabel === index;\n const isDisabled = activeLabel < index;\n const itemId = `step-${index}`;\n return (\n <Option\n key={itemId}\n id={itemId}\n as=\"li\"\n role=\"menuitem\"\n decision={false}\n className={clsx('np-animated-label-option', 'p-x-3', 'p-y-1', 'm-y-1', {\n clickable: !isDisabled,\n })}\n title={step.label}\n content={step.hoverLabel}\n button={isCurrentStep ? <Check size={24} /> : null}\n aria-current={isCurrentStep ? 'step' : false}\n aria-disabled={isDisabled}\n disabled={isDisabled}\n isContainerAligned\n {...(!isDisabled && {\n tabIndex: 0,\n onClick: handleStepAction(step.onClick),\n onKeyDown: (event) => {\n event.preventDefault();\n if (event.code === 'Enter' || event.code === 'Space') {\n handleStepAction(step.onClick)();\n }\n },\n })}\n />\n );\n })}\n </List>\n </BottomSheet>\n </>\n );\n }}\n </OverlayIdContext.Consumer>\n </OverlayIdProvider>\n );\n};\n\nexport default AnimatedLabel;\n"],"names":["AnimatedLabel","activeLabel","className","steps","labelId","useId","showSteps","setShowSteps","useState","handleStepAction","onClick","_jsx","OverlayIdProvider","open","children","OverlayIdContext","Consumer","overlayId","_jsxs","_Fragment","type","id","clsx","map","label","index","isCurrentStep","nextLabel","ChevronDown","size","BottomSheet","role","onClose","List","step","isDisabled","itemId","Option","as","decision","clickable","title","content","hoverLabel","button","Check","disabled","isContainerAligned","tabIndex","onKeyDown","event","preventDefault","code"],"mappings":";;;;;;;;;;AAgBMA,MAAAA,aAAa,GAAGA,CAAC;EAAEC,WAAW;EAAEC,SAAS;AAAEC,EAAAA,KAAAA;AAA2B,CAAA,KAAI;AAC9E,EAAA,MAAMC,OAAO,GAAGC,KAAK,EAAE,CAAA;EACvB,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC,CAAA;EAEjD,SAASC,gBAAgBA,CAACC,OAAwB,EAAA;AAChD,IAAA,OAAO,MAAK;MACVH,YAAY,CAAC,KAAK,CAAC,CAAA;AACnBG,MAAAA,OAAO,IAAI,CAAA;KACZ,CAAA;AACH,GAAA;EAEA,oBACEC,GAAA,CAACC,iBAAiB,EAAA;AAACC,IAAAA,IAAI,EAAEP,SAAU;AAAAQ,IAAAA,QAAA,eACjCH,GAAA,CAACI,gBAAgB,CAACC,QAAQ,EAAA;MAAAF,QAAA,EACtBG,SAAS,IAAI;QACb,oBACEC,IAAA,CAAAC,QAAA,EAAA;AAAAL,UAAAA,QAAA,gBACEH,GAAA,CAAA,QAAA,EAAA;AACES,YAAAA,IAAI,EAAC,QAAQ;AACbC,YAAAA,EAAE,EAAEjB,OAAQ;AACZ,YAAA,eAAA,EAAc,MAAM;AACpB,YAAA,eAAA,EAAea,SAAU;AACzB,YAAA,eAAA,EAAeX,SAAU;YACzBJ,SAAS,EAAEoB,IAAI,CACb,mBAAmB,EACnB,cAAc,EACd,yBAAyB,EACzBpB,SAAS,CACT;AACFQ,YAAAA,OAAO,EAAEA,MAAMH,YAAY,CAAC,IAAI,CAAE;AAAAO,YAAAA,QAAA,EAEjCX,KAAK,CAACoB,GAAG,CAAC,CAAC;AAAEC,cAAAA,KAAAA;aAAO,EAAEC,KAAK,KAAI;AAC9B,cAAA,MAAMC,aAAa,GAAGzB,WAAW,KAAKwB,KAAK,CAAA;AAC3C,cAAA,MAAME,SAAS,GAAGF,KAAK,GAAG,CAAC,CAAA;AAC3B,cAAA,oBACEP,IAAA,CAAA,KAAA,EAAA;AAEE,gBAAA,aAAA,EAAa,CAACQ,aAAc;AAC5BxB,gBAAAA,SAAS,EAAEoB,IAAI,CAAC,gBAAgB,EAAE,eAAe,EAAE;AACjD,kBAAA,qCAAqC,EAAEI,aAAAA;AACxC,iBAAA,CAAE;AAAAZ,gBAAAA,QAAA,GAEFU,KAAK,EAAE,GAAA,eAAAb,GAAA,CAACiB,WAAW,EAAA;AAAC1B,kBAAAA,SAAS,EAAC,OAAO;AAAC2B,kBAAAA,IAAI,EAAE,EAAA;AAAG,iBAClD,CAAA,CAAA;AAAA,eAAA,EAPOF,SAOF,CAAC,CAAA;aAET,CAAA;AAAC,WACI,CACR,eAAAhB,GAAA,CAACmB,WAAW,EAAA;AACVC,YAAAA,IAAI,EAAC,MAAM;AACX,YAAA,iBAAA,EAAiB3B,OAAQ;AACzBS,YAAAA,IAAI,EAAEP,SAAU;AAChB0B,YAAAA,OAAO,EAAEA,MAAMzB,YAAY,CAAC,KAAK,CAAE;YAAAO,QAAA,eAEnCH,GAAA,CAACsB,IAAI,EAAA;AAAC/B,cAAAA,SAAS,EAAC,OAAO;cAAAY,QAAA,EACpBX,KAAK,CAACoB,GAAG,CAAC,CAACW,IAAI,EAAET,KAAK,KAAI;AACzB,gBAAA,MAAMC,aAAa,GAAGzB,WAAW,KAAKwB,KAAK,CAAA;AAC3C,gBAAA,MAAMU,UAAU,GAAGlC,WAAW,GAAGwB,KAAK,CAAA;AACtC,gBAAA,MAAMW,MAAM,GAAG,CAAQX,KAAAA,EAAAA,KAAK,CAAE,CAAA,CAAA;gBAC9B,oBACEd,GAAA,CAAC0B,MAAM,EAAA;AAELhB,kBAAAA,EAAE,EAAEe,MAAO;AACXE,kBAAAA,EAAE,EAAC,IAAI;AACPP,kBAAAA,IAAI,EAAC,UAAU;AACfQ,kBAAAA,QAAQ,EAAE,KAAM;kBAChBrC,SAAS,EAAEoB,IAAI,CAAC,0BAA0B,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE;AACrEkB,oBAAAA,SAAS,EAAE,CAACL,UAAAA;AACb,mBAAA,CAAE;kBACHM,KAAK,EAAEP,IAAI,CAACV,KAAM;kBAClBkB,OAAO,EAAER,IAAI,CAACS,UAAW;AACzBC,kBAAAA,MAAM,EAAElB,aAAa,gBAAGf,GAAA,CAACkC,KAAK,EAAA;AAAChB,oBAAAA,IAAI,EAAE,EAAA;oBAAM,GAAG,IAAK;AACnD,kBAAA,cAAA,EAAcH,aAAa,GAAG,MAAM,GAAG,KAAM;AAC7C,kBAAA,eAAA,EAAeS,UAAW;AAC1BW,kBAAAA,QAAQ,EAAEX,UAAW;kBACrBY,kBAAkB,EAAA,IAAA;kBAAA,IACb,CAACZ,UAAU,IAAI;AAClBa,oBAAAA,QAAQ,EAAE,CAAC;AACXtC,oBAAAA,OAAO,EAAED,gBAAgB,CAACyB,IAAI,CAACxB,OAAO,CAAC;oBACvCuC,SAAS,EAAGC,KAAK,IAAI;sBACnBA,KAAK,CAACC,cAAc,EAAE,CAAA;sBACtB,IAAID,KAAK,CAACE,IAAI,KAAK,OAAO,IAAIF,KAAK,CAACE,IAAI,KAAK,OAAO,EAAE;AACpD3C,wBAAAA,gBAAgB,CAACyB,IAAI,CAACxB,OAAO,CAAC,EAAE,CAAA;AAClC,uBAAA;AACF,qBAAA;mBACD,CAAA;AAAA,iBAAA,EAxBI0B,MAyBL,CAAA,CAAA;eAEL,CAAA;aACG,CAAA;AACR,WAAa,CACf,CAAA;AAAA,SAAA,CAAG,CAAA;AAEP,OAAA;KACyB,CAAA;AAC7B,GAAmB,CAAC,CAAA;AAExB;;;;"}
|
package/build/main.css
CHANGED
|
@@ -2106,6 +2106,15 @@ button.np-option {
|
|
|
2106
2106
|
transform: translateX(0);
|
|
2107
2107
|
transition: all 0.15s ease-in 0.15s;
|
|
2108
2108
|
}
|
|
2109
|
+
.np-animated-label-option {
|
|
2110
|
+
border-radius: 10px;
|
|
2111
|
+
border-radius: var(--radius-small);
|
|
2112
|
+
}
|
|
2113
|
+
.np-animated-label-option:not(.disabled):hover,
|
|
2114
|
+
.np-animated-label-option:not(.disabled):focus-visible {
|
|
2115
|
+
outline: var(--ring-outline-color) solid var(--ring-outline-width);
|
|
2116
|
+
outline-offset: var(--ring-outline-offset);
|
|
2117
|
+
}
|
|
2109
2118
|
.np-back-button {
|
|
2110
2119
|
color: #00a2dd;
|
|
2111
2120
|
color: var(--color-interactive-accent);
|
|
@@ -19,3 +19,12 @@
|
|
|
19
19
|
transform: translateX(0);
|
|
20
20
|
transition: all 0.3s ease-in 0.3s;
|
|
21
21
|
}
|
|
22
|
+
.np-animated-label-option {
|
|
23
|
+
border-radius: 10px;
|
|
24
|
+
border-radius: var(--radius-small);
|
|
25
|
+
}
|
|
26
|
+
.np-animated-label-option:not(.disabled):hover,
|
|
27
|
+
.np-animated-label-option:not(.disabled):focus-visible {
|
|
28
|
+
outline: var(--ring-outline-color) solid var(--ring-outline-width);
|
|
29
|
+
outline-offset: var(--ring-outline-offset);
|
|
30
|
+
}
|
package/build/styles/main.css
CHANGED
|
@@ -2106,6 +2106,15 @@ button.np-option {
|
|
|
2106
2106
|
transform: translateX(0);
|
|
2107
2107
|
transition: all 0.15s ease-in 0.15s;
|
|
2108
2108
|
}
|
|
2109
|
+
.np-animated-label-option {
|
|
2110
|
+
border-radius: 10px;
|
|
2111
|
+
border-radius: var(--radius-small);
|
|
2112
|
+
}
|
|
2113
|
+
.np-animated-label-option:not(.disabled):hover,
|
|
2114
|
+
.np-animated-label-option:not(.disabled):focus-visible {
|
|
2115
|
+
outline: var(--ring-outline-color) solid var(--ring-outline-width);
|
|
2116
|
+
outline-offset: var(--ring-outline-offset);
|
|
2117
|
+
}
|
|
2109
2118
|
.np-back-button {
|
|
2110
2119
|
color: #00a2dd;
|
|
2111
2120
|
color: var(--color-interactive-accent);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { PropsWithChildren, SyntheticEvent } from 'react';
|
|
1
|
+
import { HTMLAttributes, PropsWithChildren, SyntheticEvent } from 'react';
|
|
2
2
|
import { CommonProps } from '../commonProps';
|
|
3
3
|
export type BottomSheetProps = PropsWithChildren<{
|
|
4
4
|
onClose?: (event: Event | SyntheticEvent) => void;
|
|
5
5
|
open: boolean;
|
|
6
|
-
} & CommonProps
|
|
6
|
+
} & CommonProps & Pick<HTMLAttributes<HTMLDivElement>, 'role' | 'aria-labelledby'>>;
|
|
7
7
|
/**
|
|
8
8
|
* Neptune: https://transferwise.github.io/neptune/components/bottom-sheet/
|
|
9
9
|
*
|
|
10
10
|
* Neptune Web: https://transferwise.github.io/neptune-web/components/overlays/BottomSheet
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
|
-
declare const BottomSheet: (props: BottomSheetProps) => import("react").JSX.Element;
|
|
13
|
+
declare const BottomSheet: ({ role, ...props }: BottomSheetProps) => import("react").JSX.Element;
|
|
14
14
|
export default BottomSheet;
|
|
15
15
|
//# sourceMappingURL=BottomSheet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../../../src/common/bottomSheet/BottomSheet.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,iBAAiB,EACjB,cAAc,EAIf,MAAM,OAAO,CAAC;AAOf,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAa7C,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAC9C;IACE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,KAAK,IAAI,CAAC;IAClD,IAAI,EAAE,OAAO,CAAC;CACf,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"BottomSheet.d.ts","sourceRoot":"","sources":["../../../../src/common/bottomSheet/BottomSheet.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EACd,iBAAiB,EACjB,cAAc,EAIf,MAAM,OAAO,CAAC;AAOf,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAa7C,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAC9C;IACE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,KAAK,IAAI,CAAC;IAClD,IAAI,EAAE,OAAO,CAAC;CACf,GAAG,WAAW,GACb,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,CACnE,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,WAAW,uBAAmC,gBAAgB,gCA2LnE,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
1
2
|
import { Position } from '../common';
|
|
2
|
-
export
|
|
3
|
+
export type DrawerProps = {
|
|
3
4
|
/** The content to appear in the drawer body. */
|
|
4
5
|
children?: React.ReactNode;
|
|
5
6
|
className?: string;
|
|
@@ -13,6 +14,6 @@ export interface DrawerProps {
|
|
|
13
14
|
position?: `${Position.LEFT | Position.RIGHT | Position.BOTTOM}`;
|
|
14
15
|
/** The action to perform on close click. */
|
|
15
16
|
onClose?: (event: KeyboardEvent | React.MouseEvent) => void;
|
|
16
|
-
}
|
|
17
|
-
export default function Drawer({ children, className, footerContent, headerTitle, onClose, open, position, }: DrawerProps): import("react").JSX.Element;
|
|
17
|
+
} & Pick<HTMLAttributes<HTMLDivElement>, 'role' | 'aria-labelledby'>;
|
|
18
|
+
export default function Drawer({ children, className, footerContent, headerTitle, onClose, open, position, role, 'aria-labelledby': ariaLabelledBy, }: DrawerProps): import("react").JSX.Element;
|
|
18
19
|
//# sourceMappingURL=Drawer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../../src/drawer/Drawer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../../src/drawer/Drawer.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAqB,MAAM,OAAO,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAc,MAAM,WAAW,CAAC;AASjD,MAAM,MAAM,WAAW,GAAG;IACxB,gDAAgD;IAChD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAChC,kDAAkD;IAClD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,+CAA+C;IAC/C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,uGAAuG;IACvG,QAAQ,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;IACjE,4CAA4C;IAC5C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;CAC7D,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC;AAErE,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAC7B,QAAQ,EACR,SAAS,EACT,aAAa,EACb,WAAW,EACX,OAAO,EACP,IAAY,EACZ,QAAkB,EAClB,IAAe,EACf,iBAAiB,EAAE,cAAc,GAClC,EAAE,WAAW,+BAuCb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowNavigation.d.ts","sourceRoot":"","sources":["../../../src/flowNavigation/FlowNavigation.tsx"],"names":[],"mappings":"AAOA,OAAgB,EAAE,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAOxD,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,2FAA2F;IAC3F,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,sIAAsI;IACtI,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,wGAAwG;IACxG,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACxB;AAED,QAAA,MAAM,cAAc,kEAQjB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"FlowNavigation.d.ts","sourceRoot":"","sources":["../../../src/flowNavigation/FlowNavigation.tsx"],"names":[],"mappings":"AAOA,OAAgB,EAAE,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAOxD,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,2FAA2F;IAC3F,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,sIAAsI;IACtI,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,wGAAwG;IACxG,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACxB;AAED,QAAA,MAAM,cAAc,kEAQjB,mBAAmB,gCA8DrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Step } from '../../stepper/Stepper';
|
|
2
2
|
export interface AnimatedLabelProps {
|
|
3
3
|
activeLabel: number;
|
|
4
4
|
className?: string;
|
|
5
|
-
|
|
5
|
+
steps: readonly Step[];
|
|
6
6
|
}
|
|
7
|
-
declare const AnimatedLabel: ({ activeLabel, className,
|
|
7
|
+
declare const AnimatedLabel: ({ activeLabel, className, steps }: AnimatedLabelProps) => import("react").JSX.Element;
|
|
8
8
|
export default AnimatedLabel;
|
|
9
9
|
//# sourceMappingURL=AnimatedLabel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimatedLabel.d.ts","sourceRoot":"","sources":["../../../../src/flowNavigation/animatedLabel/AnimatedLabel.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AnimatedLabel.d.ts","sourceRoot":"","sources":["../../../../src/flowNavigation/animatedLabel/AnimatedLabel.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAOlD,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACxB;AAED,QAAA,MAAM,aAAa,sCAAuC,kBAAkB,gCAgG3E,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-2b2d326",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -92,9 +92,9 @@
|
|
|
92
92
|
"rollup": "^4.18.1",
|
|
93
93
|
"rollup-preserve-directives": "^1.1.1",
|
|
94
94
|
"storybook": "^8.2.2",
|
|
95
|
-
"@transferwise/
|
|
95
|
+
"@transferwise/less-config": "3.1.0",
|
|
96
96
|
"@wise/components-theming": "1.6.0",
|
|
97
|
-
"@transferwise/
|
|
97
|
+
"@transferwise/neptune-css": "14.15.0"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"@transferwise/icons": "^3.7.0",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import {
|
|
3
3
|
CSSProperties,
|
|
4
|
+
HTMLAttributes,
|
|
4
5
|
PropsWithChildren,
|
|
5
6
|
SyntheticEvent,
|
|
6
7
|
useContext,
|
|
@@ -30,7 +31,8 @@ export type BottomSheetProps = PropsWithChildren<
|
|
|
30
31
|
{
|
|
31
32
|
onClose?: (event: Event | SyntheticEvent) => void;
|
|
32
33
|
open: boolean;
|
|
33
|
-
} & CommonProps
|
|
34
|
+
} & CommonProps &
|
|
35
|
+
Pick<HTMLAttributes<HTMLDivElement>, 'role' | 'aria-labelledby'>
|
|
34
36
|
>;
|
|
35
37
|
|
|
36
38
|
/**
|
|
@@ -39,7 +41,7 @@ export type BottomSheetProps = PropsWithChildren<
|
|
|
39
41
|
* Neptune Web: https://transferwise.github.io/neptune-web/components/overlays/BottomSheet
|
|
40
42
|
*
|
|
41
43
|
*/
|
|
42
|
-
const BottomSheet = (props: BottomSheetProps) => {
|
|
44
|
+
const BottomSheet = ({ role = 'dialog', ...props }: BottomSheetProps) => {
|
|
43
45
|
const bottomSheetReference = useRef<HTMLDivElement>(null);
|
|
44
46
|
const topBarReference = useRef<HTMLDivElement>(null);
|
|
45
47
|
const contentReference = useRef<HTMLDivElement>(null);
|
|
@@ -181,7 +183,13 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
181
183
|
const overlayId = useContext(OverlayIdContext);
|
|
182
184
|
|
|
183
185
|
return is400Zoom ? (
|
|
184
|
-
<Drawer
|
|
186
|
+
<Drawer
|
|
187
|
+
aria-labelledby={props['aria-labelledby']}
|
|
188
|
+
role={role}
|
|
189
|
+
open={props.open}
|
|
190
|
+
className={props.className}
|
|
191
|
+
onClose={close}
|
|
192
|
+
>
|
|
185
193
|
{props.children}
|
|
186
194
|
</Drawer>
|
|
187
195
|
) : (
|
|
@@ -195,7 +203,8 @@ const BottomSheet = (props: BottomSheetProps) => {
|
|
|
195
203
|
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */}
|
|
196
204
|
<div
|
|
197
205
|
id={overlayId}
|
|
198
|
-
|
|
206
|
+
aria-labelledby={props['aria-labelledby']}
|
|
207
|
+
role={role}
|
|
199
208
|
aria-modal
|
|
200
209
|
onTouchStart={onSwipeStart}
|
|
201
210
|
onTouchMove={onSwipeMove}
|
package/src/drawer/Drawer.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
|
-
import { useContext, useId } from 'react';
|
|
2
|
+
import { HTMLAttributes, useContext, useId } from 'react';
|
|
3
3
|
|
|
4
4
|
import { Position, Typography } from '../common';
|
|
5
5
|
import { CloseButton } from '../common/closeButton';
|
|
@@ -10,7 +10,7 @@ import SlidingPanel from '../slidingPanel';
|
|
|
10
10
|
import Title from '../title';
|
|
11
11
|
import { logActionRequiredIf } from '../utilities';
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export type DrawerProps = {
|
|
14
14
|
/** The content to appear in the drawer body. */
|
|
15
15
|
children?: React.ReactNode;
|
|
16
16
|
className?: string;
|
|
@@ -24,7 +24,7 @@ export interface DrawerProps {
|
|
|
24
24
|
position?: `${Position.LEFT | Position.RIGHT | Position.BOTTOM}`;
|
|
25
25
|
/** The action to perform on close click. */
|
|
26
26
|
onClose?: (event: KeyboardEvent | React.MouseEvent) => void;
|
|
27
|
-
}
|
|
27
|
+
} & Pick<HTMLAttributes<HTMLDivElement>, 'role' | 'aria-labelledby'>;
|
|
28
28
|
|
|
29
29
|
export default function Drawer({
|
|
30
30
|
children,
|
|
@@ -34,6 +34,8 @@ export default function Drawer({
|
|
|
34
34
|
onClose,
|
|
35
35
|
open = false,
|
|
36
36
|
position = 'right',
|
|
37
|
+
role = 'dialog',
|
|
38
|
+
'aria-labelledby': ariaLabelledBy,
|
|
37
39
|
}: DrawerProps) {
|
|
38
40
|
logActionRequiredIf(
|
|
39
41
|
'Drawer now expects `onClose`, and will soon make this prop required. Please update your usage to provide it.',
|
|
@@ -50,9 +52,9 @@ export default function Drawer({
|
|
|
50
52
|
<SlidingPanel open={open} position={isMobile ? Position.BOTTOM : position}>
|
|
51
53
|
<div
|
|
52
54
|
id={overlayId}
|
|
53
|
-
role=
|
|
55
|
+
role={role}
|
|
54
56
|
aria-modal
|
|
55
|
-
aria-labelledby={headerTitle ? titleId : undefined}
|
|
57
|
+
aria-labelledby={(ariaLabelledBy ?? headerTitle) ? titleId : undefined}
|
|
56
58
|
className={clsx('np-drawer', className)}
|
|
57
59
|
>
|
|
58
60
|
<div
|
|
@@ -6,11 +6,14 @@ import Avatar, { AvatarType } from '../avatar';
|
|
|
6
6
|
import AvatarWrapper from '../avatarWrapper';
|
|
7
7
|
import Body from '../body';
|
|
8
8
|
import Button from '../button';
|
|
9
|
-
import { ProfileType, Size } from '../common';
|
|
9
|
+
import { ProfileType, Size, Typography } from '../common';
|
|
10
10
|
import Logo from '../logo';
|
|
11
11
|
import OverlayHeader from '../overlayHeader';
|
|
12
12
|
|
|
13
13
|
import FlowNavigation from './FlowNavigation';
|
|
14
|
+
import { lorem10 } from '../test-utils';
|
|
15
|
+
import Display from '../display';
|
|
16
|
+
import Sticky from '../sticky';
|
|
14
17
|
|
|
15
18
|
export default {
|
|
16
19
|
component: FlowNavigation,
|
|
@@ -51,26 +54,12 @@ export const Variants = () => {
|
|
|
51
54
|
steps={[
|
|
52
55
|
{
|
|
53
56
|
label: 'Amount',
|
|
54
|
-
hoverLabel:
|
|
55
|
-
<>
|
|
56
|
-
<div>
|
|
57
|
-
<strong>100 GBP</strong>
|
|
58
|
-
</div>
|
|
59
|
-
0.2351 ETH
|
|
60
|
-
</>
|
|
61
|
-
),
|
|
57
|
+
hoverLabel: <strong>100 GBP</strong>,
|
|
62
58
|
onClick: () => setActiveStep(0),
|
|
63
59
|
},
|
|
64
60
|
{
|
|
65
61
|
label: 'You',
|
|
66
|
-
hoverLabel:
|
|
67
|
-
<>
|
|
68
|
-
<div>
|
|
69
|
-
<strong>Elena Durante</strong>
|
|
70
|
-
</div>
|
|
71
|
-
elenadurante@test.com
|
|
72
|
-
</>
|
|
73
|
-
),
|
|
62
|
+
hoverLabel: <>Elena Durante - elenadurante@test.com</>,
|
|
74
63
|
onClick: () => setActiveStep(1),
|
|
75
64
|
},
|
|
76
65
|
{ label: 'Recipient', hoverLabel: 'Daniele Tomboro', onClick: () => setActiveStep(2) },
|
|
@@ -201,6 +190,69 @@ export const Variants = () => {
|
|
|
201
190
|
) : null;
|
|
202
191
|
};
|
|
203
192
|
|
|
193
|
+
export const SendFlow = () => {
|
|
194
|
+
const [activeStep, setActiveStep] = useState(2);
|
|
195
|
+
const steps = [
|
|
196
|
+
{
|
|
197
|
+
label: 'Recipient',
|
|
198
|
+
onClick: handleStepClick(0),
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
label: 'Amount',
|
|
202
|
+
hoverLabel: (
|
|
203
|
+
<>
|
|
204
|
+
You send 100 GBP <br />
|
|
205
|
+
You get 99.39 GBP{' '}
|
|
206
|
+
</>
|
|
207
|
+
),
|
|
208
|
+
...(activeStep > 1 && { onClick: handleStepClick(1) }),
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
label: 'Review',
|
|
212
|
+
...(activeStep > 2 && { onClick: handleStepClick(2) }),
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
label: 'Pay',
|
|
216
|
+
...(activeStep > 3 && { onClick: handleStepClick(3) }),
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
function handleStepClick(step) {
|
|
220
|
+
return () => {
|
|
221
|
+
setActiveStep(step);
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return (
|
|
225
|
+
<>
|
|
226
|
+
<FlowNavigation
|
|
227
|
+
avatar={
|
|
228
|
+
<Avatar type={AvatarType.ICON} size={Size.MEDIUM}>
|
|
229
|
+
<ProfileIcon />
|
|
230
|
+
</Avatar>
|
|
231
|
+
}
|
|
232
|
+
logo={<Logo />}
|
|
233
|
+
activeStep={activeStep}
|
|
234
|
+
steps={steps}
|
|
235
|
+
onClose={() => alert('close & move away')}
|
|
236
|
+
onGoBack={() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)}
|
|
237
|
+
/>
|
|
238
|
+
|
|
239
|
+
<Body className="m-a-3">
|
|
240
|
+
<Display type={Typography.DISPLAY_SMALL}>{steps[activeStep].label} Step</Display>
|
|
241
|
+
<br />
|
|
242
|
+
{lorem10}
|
|
243
|
+
</Body>
|
|
244
|
+
|
|
245
|
+
<Sticky>
|
|
246
|
+
<div className="d-flex justify-content-center align-items-center p-a-3">
|
|
247
|
+
<Button disabled={activeStep === 4} block onClick={() => setActiveStep(activeStep + 1)}>
|
|
248
|
+
Continue
|
|
249
|
+
</Button>
|
|
250
|
+
</div>
|
|
251
|
+
</Sticky>
|
|
252
|
+
</>
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
|
|
204
256
|
export const WithOverlayHeaderComparison = () => {
|
|
205
257
|
const [activeStep, setActiveStep] = useState(4);
|
|
206
258
|
const [closed, setClosed] = useState(false);
|
|
@@ -71,11 +71,7 @@ const FlowNavigation = ({
|
|
|
71
71
|
<div className="np-flow-header__left">{logo}</div>
|
|
72
72
|
)}
|
|
73
73
|
{!screenSm && !done && (
|
|
74
|
-
<AnimatedLabel
|
|
75
|
-
className="m-x-1"
|
|
76
|
-
labels={steps.map((step) => step.label)}
|
|
77
|
-
activeLabel={activeStep}
|
|
78
|
-
/>
|
|
74
|
+
<AnimatedLabel className="m-x-1" steps={steps} activeLabel={activeStep} />
|
|
79
75
|
)}
|
|
80
76
|
</>
|
|
81
77
|
}
|
|
@@ -19,3 +19,12 @@
|
|
|
19
19
|
transform: translateX(0);
|
|
20
20
|
transition: all 0.3s ease-in 0.3s;
|
|
21
21
|
}
|
|
22
|
+
.np-animated-label-option {
|
|
23
|
+
border-radius: 10px;
|
|
24
|
+
border-radius: var(--radius-small);
|
|
25
|
+
}
|
|
26
|
+
.np-animated-label-option:not(.disabled):hover,
|
|
27
|
+
.np-animated-label-option:not(.disabled):focus-visible {
|
|
28
|
+
outline: var(--ring-outline-color) solid var(--ring-outline-width);
|
|
29
|
+
outline-offset: var(--ring-outline-offset);
|
|
30
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@import (reference) "../../../node_modules/@transferwise/neptune-css/src/less/addons/_spacing-utilities.less";
|
|
2
|
+
@import (reference) "../../../node_modules/@transferwise/neptune-css/src/less/ring.less";
|
|
2
3
|
|
|
3
4
|
@transition-timing-function: ease-in-out;
|
|
4
5
|
@transition-duration: 0.3s;
|
|
@@ -28,4 +29,12 @@
|
|
|
28
29
|
transform: translateX(0);
|
|
29
30
|
transition: all @transition-duration ease-in @transition-duration;
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
&-option {
|
|
34
|
+
border-radius: var(--radius-small);
|
|
35
|
+
&:not(.disabled):hover,
|
|
36
|
+
&:not(.disabled):focus-visible {
|
|
37
|
+
.ring();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
31
40
|
}
|
|
@@ -1,53 +1,51 @@
|
|
|
1
|
-
import { render, screen } from '../../test-utils';
|
|
1
|
+
import { render, screen, mockMatchMedia, mockResizeObserver } from '../../test-utils';
|
|
2
2
|
|
|
3
3
|
import AnimatedLabel from '.';
|
|
4
4
|
|
|
5
|
+
mockMatchMedia();
|
|
6
|
+
mockResizeObserver();
|
|
7
|
+
|
|
5
8
|
const props = {
|
|
6
9
|
activeLabel: 0,
|
|
7
|
-
|
|
10
|
+
steps: [{ label: 'label1' }, { label: 'label2' }, { label: 'label3' }],
|
|
8
11
|
};
|
|
9
12
|
jest.useFakeTimers();
|
|
10
13
|
describe('AnimatedLabel', () => {
|
|
11
|
-
it('renders all labels', () => {
|
|
12
|
-
const { container } = render(<AnimatedLabel {...props} />);
|
|
13
|
-
expect(container).toMatchSnapshot();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
14
|
it('renders only one label with class in', () => {
|
|
17
15
|
const { container } = render(<AnimatedLabel {...props} />);
|
|
18
|
-
expect(screen.getByText(props.
|
|
16
|
+
expect(screen.getByText(props.steps[0].label)).toHaveClass('np-animated-label--in');
|
|
19
17
|
expect(container.querySelectorAll('.np-animated-label--in')).toHaveLength(1);
|
|
20
18
|
});
|
|
21
19
|
|
|
22
20
|
it('renders only one label with class out', () => {
|
|
23
21
|
const { container } = render(<AnimatedLabel {...props} />);
|
|
24
|
-
expect(screen.getByText(props.
|
|
22
|
+
expect(screen.getByText(props.steps[1].label)).not.toHaveClass('np-animated-label--in');
|
|
25
23
|
expect(container.querySelectorAll('.np-animated-label--in')).toHaveLength(1);
|
|
26
24
|
});
|
|
27
25
|
|
|
28
26
|
it('when activeLabel increase it switches class accordingly', () => {
|
|
29
27
|
const { rerender } = render(<AnimatedLabel {...props} />);
|
|
30
|
-
expect(screen.getByText(props.
|
|
31
|
-
expect(screen.getByText(props.
|
|
32
|
-
expect(screen.getByText(props.
|
|
28
|
+
expect(screen.getByText(props.steps[0].label)).toHaveClass('np-animated-label--in');
|
|
29
|
+
expect(screen.getByText(props.steps[1].label)).not.toHaveClass('np-animated-label--in');
|
|
30
|
+
expect(screen.getByText(props.steps[2].label)).not.toHaveClass('np-animated-label--in');
|
|
33
31
|
|
|
34
32
|
rerender(<AnimatedLabel {...props} activeLabel={1} />);
|
|
35
33
|
|
|
36
|
-
expect(screen.getByText(props.
|
|
37
|
-
expect(screen.getByText(props.
|
|
38
|
-
expect(screen.getByText(props.
|
|
34
|
+
expect(screen.getByText(props.steps[0].label)).not.toHaveClass('np-animated-label--in');
|
|
35
|
+
expect(screen.getByText(props.steps[1].label)).toHaveClass('np-animated-label--in');
|
|
36
|
+
expect(screen.getByText(props.steps[2].label)).not.toHaveClass('np-animated-label--in');
|
|
39
37
|
});
|
|
40
38
|
|
|
41
39
|
it('when activeLabel decrease it switches class accordingly', () => {
|
|
42
40
|
const { rerender } = render(<AnimatedLabel {...props} activeLabel={1} />);
|
|
43
|
-
expect(screen.getByText(props.
|
|
44
|
-
expect(screen.getByText(props.
|
|
45
|
-
expect(screen.getByText(props.
|
|
41
|
+
expect(screen.getByText(props.steps[0].label)).not.toHaveClass('np-animated-label--in');
|
|
42
|
+
expect(screen.getByText(props.steps[1].label)).toHaveClass('np-animated-label--in');
|
|
43
|
+
expect(screen.getByText(props.steps[2].label)).not.toHaveClass('np-animated-label--in');
|
|
46
44
|
|
|
47
45
|
rerender(<AnimatedLabel {...props} activeLabel={0} />);
|
|
48
46
|
|
|
49
|
-
expect(screen.getByText(props.
|
|
50
|
-
expect(screen.getByText(props.
|
|
51
|
-
expect(screen.getByText(props.
|
|
47
|
+
expect(screen.getByText(props.steps[0].label)).toHaveClass('np-animated-label--in');
|
|
48
|
+
expect(screen.getByText(props.steps[1].label)).not.toHaveClass('np-animated-label--in');
|
|
49
|
+
expect(screen.getByText(props.steps[2].label)).not.toHaveClass('np-animated-label--in');
|
|
52
50
|
});
|
|
53
51
|
});
|