@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.
Files changed (37) hide show
  1. package/build/common/bottomSheet/BottomSheet.js +8 -2
  2. package/build/common/bottomSheet/BottomSheet.js.map +1 -1
  3. package/build/common/bottomSheet/BottomSheet.mjs +8 -2
  4. package/build/common/bottomSheet/BottomSheet.mjs.map +1 -1
  5. package/build/drawer/Drawer.js +5 -3
  6. package/build/drawer/Drawer.js.map +1 -1
  7. package/build/drawer/Drawer.mjs +5 -3
  8. package/build/drawer/Drawer.mjs.map +1 -1
  9. package/build/flowNavigation/FlowNavigation.js +1 -1
  10. package/build/flowNavigation/FlowNavigation.js.map +1 -1
  11. package/build/flowNavigation/FlowNavigation.mjs +1 -1
  12. package/build/flowNavigation/FlowNavigation.mjs.map +1 -1
  13. package/build/flowNavigation/animatedLabel/AnimatedLabel.js +89 -15
  14. package/build/flowNavigation/animatedLabel/AnimatedLabel.js.map +1 -1
  15. package/build/flowNavigation/animatedLabel/AnimatedLabel.mjs +90 -16
  16. package/build/flowNavigation/animatedLabel/AnimatedLabel.mjs.map +1 -1
  17. package/build/main.css +9 -0
  18. package/build/styles/flowNavigation/animatedLabel/AnimatedLabel.css +9 -0
  19. package/build/styles/main.css +9 -0
  20. package/build/types/common/bottomSheet/BottomSheet.d.ts +3 -3
  21. package/build/types/common/bottomSheet/BottomSheet.d.ts.map +1 -1
  22. package/build/types/drawer/Drawer.d.ts +4 -3
  23. package/build/types/drawer/Drawer.d.ts.map +1 -1
  24. package/build/types/flowNavigation/FlowNavigation.d.ts.map +1 -1
  25. package/build/types/flowNavigation/animatedLabel/AnimatedLabel.d.ts +3 -3
  26. package/build/types/flowNavigation/animatedLabel/AnimatedLabel.d.ts.map +1 -1
  27. package/package.json +3 -3
  28. package/src/common/bottomSheet/BottomSheet.tsx +13 -4
  29. package/src/drawer/Drawer.tsx +7 -5
  30. package/src/flowNavigation/FlowNavigation.story.js +69 -17
  31. package/src/flowNavigation/FlowNavigation.tsx +1 -5
  32. package/src/flowNavigation/animatedLabel/AnimatedLabel.css +9 -0
  33. package/src/flowNavigation/animatedLabel/AnimatedLabel.less +9 -0
  34. package/src/flowNavigation/animatedLabel/AnimatedLabel.spec.js +19 -21
  35. package/src/flowNavigation/animatedLabel/AnimatedLabel.tsx +102 -20
  36. package/src/main.css +9 -0
  37. package/src/flowNavigation/animatedLabel/__snapshots__/AnimatedLabel.spec.js.snap +0 -25
@@ -1,32 +1,114 @@
1
1
  import { clsx } from 'clsx';
2
- import React from 'react';
2
+ import { useId, useState } from 'react';
3
3
 
4
- import Body from '../../body';
5
- import { Typography } from '../../common';
4
+ import type { Step } from '../../stepper/Stepper';
5
+ import BottomSheet from '../../common/bottomSheet';
6
+ import Option from '../../common/Option';
7
+ import { Check, ChevronDown } from '@transferwise/icons';
8
+ import { OverlayIdContext, OverlayIdProvider } from '../../provider/overlay/OverlayIdProvider';
9
+ import { List } from '../../listItem';
6
10
 
7
11
  export interface AnimatedLabelProps {
8
12
  activeLabel: number;
9
13
  className?: string;
10
- labels: readonly React.ReactNode[];
14
+ steps: readonly Step[];
11
15
  }
12
16
 
13
- const AnimatedLabel = ({ activeLabel, className, labels }: AnimatedLabelProps) => {
17
+ const AnimatedLabel = ({ activeLabel, className, steps }: AnimatedLabelProps) => {
18
+ const labelId = useId();
19
+ const [showSteps, setShowSteps] = useState(false);
20
+
21
+ function handleStepAction(onClick: Step['onClick']) {
22
+ return () => {
23
+ setShowSteps(false);
24
+ onClick?.();
25
+ };
26
+ }
27
+
14
28
  return (
15
- <Body type={Typography.BODY_LARGE_BOLD} className={clsx('np-animated-label', className)}>
16
- {labels.map((label, index) => {
17
- const nextLabel = index - 1;
18
- return (
19
- <div
20
- key={nextLabel}
21
- className={clsx('text-xs-center', {
22
- 'np-animated-label--in text-ellipsis': index === activeLabel,
23
- })}
24
- >
25
- {label}
26
- </div>
27
- );
28
- })}
29
- </Body>
29
+ <OverlayIdProvider open={showSteps}>
30
+ <OverlayIdContext.Consumer>
31
+ {(overlayId) => {
32
+ return (
33
+ <>
34
+ <button
35
+ type="button"
36
+ id={labelId}
37
+ aria-haspopup="menu"
38
+ aria-controls={overlayId}
39
+ aria-expanded={showSteps}
40
+ className={clsx(
41
+ 'np-animated-label',
42
+ 'btn-unstyled',
43
+ 'np-text-body-large-bold',
44
+ className,
45
+ )}
46
+ onClick={() => setShowSteps(true)}
47
+ >
48
+ {steps.map(({ label }, index) => {
49
+ const isCurrentStep = activeLabel === index;
50
+ const nextLabel = index - 1;
51
+ return (
52
+ <div
53
+ key={nextLabel}
54
+ aria-hidden={!isCurrentStep}
55
+ className={clsx('text-xs-center', 'd-inline-flex', {
56
+ 'np-animated-label--in text-ellipsis': isCurrentStep,
57
+ })}
58
+ >
59
+ {label} <ChevronDown className="m-l-1" size={24} />
60
+ </div>
61
+ );
62
+ })}
63
+ </button>
64
+ <BottomSheet
65
+ role="menu"
66
+ aria-labelledby={labelId}
67
+ open={showSteps}
68
+ onClose={() => setShowSteps(false)}
69
+ >
70
+ <List className="p-a-1">
71
+ {steps.map((step, index) => {
72
+ const isCurrentStep = activeLabel === index;
73
+ const isDisabled = activeLabel < index;
74
+ const itemId = `step-${index}`;
75
+ return (
76
+ <Option
77
+ key={itemId}
78
+ id={itemId}
79
+ as="li"
80
+ role="menuitem"
81
+ decision={false}
82
+ className={clsx('np-animated-label-option', 'p-x-3', 'p-y-1', 'm-y-1', {
83
+ clickable: !isDisabled,
84
+ })}
85
+ title={step.label}
86
+ content={step.hoverLabel}
87
+ button={isCurrentStep ? <Check size={24} /> : null}
88
+ aria-current={isCurrentStep ? 'step' : false}
89
+ aria-disabled={isDisabled}
90
+ disabled={isDisabled}
91
+ isContainerAligned
92
+ {...(!isDisabled && {
93
+ tabIndex: 0,
94
+ onClick: handleStepAction(step.onClick),
95
+ onKeyDown: (event) => {
96
+ event.preventDefault();
97
+ if (event.code === 'Enter' || event.code === 'Space') {
98
+ handleStepAction(step.onClick)();
99
+ }
100
+ },
101
+ })}
102
+ />
103
+ );
104
+ })}
105
+ </List>
106
+ </BottomSheet>
107
+ </>
108
+ );
109
+ }}
110
+ </OverlayIdContext.Consumer>
111
+ </OverlayIdProvider>
30
112
  );
31
113
  };
32
114
 
package/src/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,25 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`AnimatedLabel renders all labels 1`] = `
4
- <div>
5
- <div
6
- class="np-text-body-large-bold np-animated-label"
7
- >
8
- <div
9
- class="text-xs-center np-animated-label--in text-ellipsis"
10
- >
11
- label1
12
- </div>
13
- <div
14
- class="text-xs-center"
15
- >
16
- label2
17
- </div>
18
- <div
19
- class="text-xs-center"
20
- >
21
- label3
22
- </div>
23
- </div>
24
- </div>
25
- `;