@transferwise/components 0.0.0-experimental-c91775b → 0.0.0-experimental-b34fee0

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.
@@ -7,6 +7,7 @@ import { CloseButton } from '../common/closeButton';
7
7
  import FlowHeader from '../common/flowHeader/FlowHeader';
8
8
  import Logo from '../logo';
9
9
  import Stepper, { type Step } from '../stepper/Stepper';
10
+ import Container from '../container';
10
11
 
11
12
  import { useScreenSize } from '../common/hooks/useScreenSize';
12
13
  import messages from './FlowNavigation.messages';
@@ -14,6 +15,8 @@ import AnimatedLabel from './animatedLabel';
14
15
  import IconButton from '../iconButton';
15
16
  import { ArrowLeft } from '@transferwise/icons';
16
17
 
18
+ const defaultLogo = <Logo />;
19
+
17
20
  export interface FlowNavigationProps {
18
21
  /** @default 0 */
19
22
  activeStep?: number;
@@ -28,16 +31,31 @@ export interface FlowNavigationProps {
28
31
  onGoBack?: () => void;
29
32
  /** Steps to be displayed in stepper. If you don't need the stepper, please use OverlayHeader instead */
30
33
  steps: readonly Step[];
34
+ /**
35
+ * When true, renders in composable mode using a fluid Container.
36
+ * This allows the FlowNavigation to be used within custom layout containers.
37
+ * @default false
38
+ */
39
+ composable?: boolean;
40
+ /**
41
+ * Controls whether the bottom border is displayed.
42
+ * - Non-composable variant: When true (default), shows border based on done state (!done). When false, always hides.
43
+ * - Composable variant: Directly controls border visibility, ignoring done state.
44
+ * @default true
45
+ */
46
+ showBottomBorder?: boolean;
31
47
  }
32
48
 
33
49
  const FlowNavigation = ({
34
50
  activeStep = 0,
35
51
  avatar,
36
- logo = <Logo />,
52
+ logo = defaultLogo,
37
53
  done = false,
38
54
  onClose,
39
55
  onGoBack,
40
56
  steps,
57
+ composable = false,
58
+ showBottomBorder = true,
41
59
  }: FlowNavigationProps) => {
42
60
  const intl = useIntl();
43
61
 
@@ -50,62 +68,80 @@ const FlowNavigation = ({
50
68
 
51
69
  const displayGoBack = onGoBack != null && activeStep > 0;
52
70
 
71
+ const flowHeaderContent = (
72
+ <FlowHeader
73
+ className={clsx(
74
+ 'np-flow-navigation__content',
75
+ !composable && 'p-x-3',
76
+ screenSm == null
77
+ ? 'np-flow-navigation--hidden'
78
+ : {
79
+ 'np-flow-navigation--xs-max': !screenSm,
80
+ // Size switches on parent container which may or may not have the same size as the window.
81
+ 'np-flow-navigation--sm': screenSm,
82
+ 'np-flow-navigation--lg': screenLg,
83
+ },
84
+ )}
85
+ leftContent={
86
+ <>
87
+ {!screenSm && displayGoBack ? (
88
+ <IconButton
89
+ size={40}
90
+ priority="tertiary"
91
+ type="default"
92
+ aria-label={intl.formatMessage(messages.back)}
93
+ onClick={onGoBack}
94
+ >
95
+ <ArrowLeft />
96
+ </IconButton>
97
+ ) : (
98
+ <div className="np-flow-header__left">{logo}</div>
99
+ )}
100
+ {!screenSm && !done && (
101
+ <AnimatedLabel className="m-x-1" steps={steps} activeLabel={activeStep} />
102
+ )}
103
+ </>
104
+ }
105
+ rightContent={
106
+ <div className="np-flow-header__right d-flex align-items-center justify-content-end order-2--lg">
107
+ {newAvatar}
108
+ {newAvatar && closeButton && <span className="m-x-1" />}
109
+ {closeButton}
110
+ </div>
111
+ }
112
+ bottomContent={
113
+ !done && steps.length > 0 ? (
114
+ <Stepper
115
+ activeStep={activeStep}
116
+ steps={steps}
117
+ className={clsx('np-flow-navigation__stepper')}
118
+ />
119
+ ) : null
120
+ }
121
+ layout={!screenLg ? Layout.VERTICAL : Layout.HORIZONTAL}
122
+ />
123
+ );
124
+
125
+ if (composable) {
126
+ return (
127
+ <Container
128
+ size="fluid"
129
+ className={clsx('np-flow-navigation np-flow-navigation--composable', {
130
+ 'np-flow-navigation--border-bottom': showBottomBorder,
131
+ })}
132
+ >
133
+ {flowHeaderContent}
134
+ </Container>
135
+ );
136
+ }
137
+
53
138
  return (
54
139
  <div
55
- className={clsx('np-flow-navigation d-flex align-items-center justify-content-center p-y-3', {
56
- 'np-flow-navigation--border-bottom': !done,
140
+ className={clsx('np-flow-navigation p-y-3', {
141
+ 'np-flow-navigation--border-bottom': showBottomBorder && !done,
57
142
  })}
58
143
  >
59
- <FlowHeader
60
- className={clsx(
61
- 'np-flow-navigation__content p-x-3',
62
- screenSm == null
63
- ? 'np-flow-navigation--hidden'
64
- : {
65
- 'np-flow-navigation--xs-max': !screenSm,
66
- // Size switches on parent container which may or may not have the same size as the window.
67
- 'np-flow-navigation--sm': screenSm,
68
- 'np-flow-navigation--lg': screenLg,
69
- },
70
- )}
71
- leftContent={
72
- <>
73
- {!screenSm && displayGoBack ? (
74
- <IconButton
75
- size={40}
76
- priority="tertiary"
77
- type="default"
78
- aria-label={intl.formatMessage(messages.back)}
79
- onClick={onGoBack}
80
- >
81
- <ArrowLeft />
82
- </IconButton>
83
- ) : (
84
- <div className="np-flow-header__left">{logo}</div>
85
- )}
86
- {!screenSm && !done && (
87
- <AnimatedLabel className="m-x-1" steps={steps} activeLabel={activeStep} />
88
- )}
89
- </>
90
- }
91
- rightContent={
92
- <div className="np-flow-header__right d-flex align-items-center justify-content-end order-2--lg">
93
- {newAvatar}
94
- {newAvatar && closeButton && <span className="m-x-1" />}
95
- {closeButton}
96
- </div>
97
- }
98
- bottomContent={
99
- !done && steps.length > 0 ? (
100
- <Stepper
101
- activeStep={activeStep}
102
- steps={steps}
103
- className={clsx('np-flow-navigation__stepper')}
104
- />
105
- ) : null
106
- }
107
- layout={!screenLg ? Layout.VERTICAL : Layout.HORIZONTAL}
108
- />
144
+ {flowHeaderContent}
109
145
  </div>
110
146
  );
111
147
  };
package/src/main.css CHANGED
@@ -28754,12 +28754,14 @@ button.np-option {
28754
28754
  }
28755
28755
 
28756
28756
  .np-flow-navigation {
28757
+ display: flex;
28758
+ align-items: center;
28759
+ justify-content: center;
28757
28760
  width: 100%;
28758
- min-height: 97px;
28761
+ min-height: 96px;
28759
28762
  }
28760
28763
 
28761
28764
  .np-flow-navigation--border-bottom {
28762
- min-height: 96px;
28763
28765
  border-bottom: 1px solid rgba(0,0,0,0.10196);
28764
28766
  border-bottom: 1px solid var(--color-border-neutral);
28765
28767
  }
@@ -28844,6 +28846,20 @@ html:not([dir="rtl"]) .np-flow-navigation--sm .np-flow-navigation__stepper {
28844
28846
  visibility: hidden;
28845
28847
  }
28846
28848
 
28849
+ .np-flow-navigation--composable {
28850
+ min-height: 80px;
28851
+ }
28852
+
28853
+ @media (min-width: 320.02px) {
28854
+ .np-flow-navigation--composable {
28855
+ min-height: 128px;
28856
+ }
28857
+ }
28858
+
28859
+ .np-flow-navigation--composable .np-flow-navigation__content {
28860
+ max-width: none;
28861
+ }
28862
+
28847
28863
  .np-theme-personal--forest-green .np-flow-navigation .np-flow-header__left path,
28848
28864
  .np-theme-personal--bright-green .np-flow-navigation .np-flow-header__left path,
28849
28865
  .np-theme-personal--dark .np-flow-navigation .np-flow-header__left path {
@@ -15,9 +15,13 @@ interface CustomControls {
15
15
  }
16
16
  export type StoryArgs = OverlayHeaderProps & CustomControls;
17
17
 
18
+ /**
19
+ * @deprecated Use `FlowNavigation` component instead
20
+ */
18
21
  const meta: Meta<StoryArgs> = {
19
22
  component: OverlayHeader,
20
23
  title: 'Navigation/OverlayHeader',
24
+ tags: ['deprecated'],
21
25
  argTypes: {
22
26
  avatarType: { control: 'select', options: ['', 'Business', 'Profile'] },
23
27
  avatarURL: { control: 'text' },
@@ -5,6 +5,9 @@ import { CloseButton } from '../common/closeButton';
5
5
  import FlowHeader from '../common/flowHeader';
6
6
  import Logo from '../logo';
7
7
 
8
+ /**
9
+ * @deprecated Use `FlowNavigation` component instead
10
+ */
8
11
  export interface OverlayHeaderProps {
9
12
  /** An Avatar */
10
13
  avatar?: React.ReactNode;
@@ -15,6 +18,9 @@ export interface OverlayHeaderProps {
15
18
 
16
19
  const defaultLogo = <Logo />;
17
20
 
21
+ /**
22
+ * @deprecated Use `FlowNavigation` component instead
23
+ */
18
24
  export default function OverlayHeader({ avatar, onClose, logo = defaultLogo }: OverlayHeaderProps) {
19
25
  const closeButton = onClose && <CloseButton size={Size.LARGE} onClick={onClose} />;
20
26
  return (
@@ -1,190 +0,0 @@
1
- import { Breakpoint } from '@transferwise/neptune-tokens';
2
- import AvatarView from '../avatarView';
3
- import { mockMatchMedia, render, screen } from '../test-utils';
4
-
5
- import FlowNavigation from './FlowNavigation';
6
-
7
- mockMatchMedia();
8
-
9
- jest.mock('./animatedLabel', () => {
10
- return function ({ className, activeLabel }) {
11
- return (
12
- <div className={className} data-testid={`activeLabel-${activeLabel}`}>
13
- AnimatedLabel
14
- </div>
15
- );
16
- };
17
- });
18
-
19
- describe('FlowNavigation', () => {
20
- beforeEach(() => {
21
- window.innerWidth = Breakpoint.LARGE + 1;
22
- });
23
-
24
- const props = {
25
- avatar: <AvatarView profileName="Tim Mike" />,
26
- logo: <img alt="logo" src="logo.svg" width="138" height="24" />,
27
- onClose: jest.fn(),
28
- steps: [
29
- {
30
- label: 'label-0',
31
- },
32
- { label: 'label-1' },
33
- { label: 'label-2' },
34
- ],
35
- activeStep: 0,
36
- };
37
-
38
- it(`renders full Logo`, () => {
39
- render(<FlowNavigation {...props} />);
40
- expect(logoFull()).toBeInTheDocument();
41
- });
42
-
43
- it(`renders separator if avatar and onClose are provided`, () => {
44
- const { container } = render(<FlowNavigation {...props} />);
45
-
46
- expect(container.querySelector('span.m-x-1')).toBeInTheDocument();
47
- });
48
-
49
- it(`doesn't render separator if avatar or onClose are not provided`, () => {
50
- const { container, rerender } = render(<FlowNavigation {...props} onClose={null} />);
51
-
52
- expect(container.querySelector('.separator')).not.toBeInTheDocument();
53
-
54
- rerender(<FlowNavigation {...props} avatar={null} />);
55
-
56
- expect(container.querySelector('.separator')).not.toBeInTheDocument();
57
- });
58
-
59
- it(`doesn't render separator if done is true`, () => {
60
- const { container, rerender } = render(<FlowNavigation {...props} onClose={null} />);
61
-
62
- expect(container.querySelector('.separator')).not.toBeInTheDocument();
63
-
64
- rerender(<FlowNavigation {...props} avatar={null} done />);
65
-
66
- expect(container.querySelector('.separator')).not.toBeInTheDocument();
67
- });
68
-
69
- it(`renders border based on done`, () => {
70
- const { container, rerender } = render(<FlowNavigation {...props} onClose={null} />);
71
-
72
- expect(container.querySelector('.np-flow-navigation--border-bottom')).toBeInTheDocument();
73
-
74
- rerender(<FlowNavigation {...props} avatar={null} done />);
75
-
76
- expect(container.querySelector('.np-flow-navigation--border-bottom')).not.toBeInTheDocument();
77
- });
78
-
79
- it(`hides stepper when done is true`, () => {
80
- const { container, rerender } = render(<FlowNavigation {...props} onClose={null} />);
81
-
82
- expect(container.querySelector('.np-flow-navigation__stepper')).toBeInTheDocument();
83
-
84
- rerender(<FlowNavigation {...props} avatar={null} done />);
85
-
86
- expect(container.querySelector('.np-flow-navigation__stepper')).not.toBeInTheDocument();
87
- });
88
-
89
- it(`does not render stepper when steps is empty`, () => {
90
- const { container } = render(<FlowNavigation {...props} steps={[]} />);
91
-
92
- expect(container.querySelector('.np-flow-navigation__stepper')).not.toBeInTheDocument();
93
- expect(container.querySelector('.tw-stepper')).not.toBeInTheDocument();
94
- });
95
-
96
- it(`hides label when done is true`, () => {
97
- const { rerender } = render(<FlowNavigation {...props} done={false} />);
98
-
99
- expect(screen.getByText('label-0')).toBeInTheDocument();
100
-
101
- rerender(<FlowNavigation {...props} done />);
102
-
103
- expect(screen.queryByText('label-0')).not.toBeInTheDocument();
104
- });
105
-
106
- it(`renders xs-max class`, () => {
107
- window.innerWidth = Breakpoint.SMALL - 1;
108
- const { container } = render(<FlowNavigation {...props} onClose={null} />);
109
-
110
- expect(container.querySelector('.np-flow-navigation--xs-max')).toBeInTheDocument();
111
- });
112
-
113
- it(`renders sm class`, () => {
114
- window.innerWidth = Breakpoint.SMALL;
115
- const { container } = render(<FlowNavigation {...props} onClose={null} />);
116
-
117
- expect(container.querySelector('.np-flow-navigation--sm')).toBeInTheDocument();
118
- });
119
-
120
- it(`renders lg class`, () => {
121
- window.innerWidth = Breakpoint.LARGE;
122
- const { container } = render(<FlowNavigation {...props} onClose={null} />);
123
-
124
- expect(container.querySelector('.np-flow-navigation--lg')).toBeInTheDocument();
125
- });
126
-
127
- describe('on mobile', () => {
128
- beforeEach(() => {
129
- window.innerWidth = Breakpoint.SMALL - 1;
130
- });
131
-
132
- it('renders Logo', () => {
133
- render(<FlowNavigation {...props} />);
134
- expect(screen.getByAltText('logo')).toBeInTheDocument();
135
- });
136
-
137
- it('renders flag if activeStep <= 0 onGoBack or is not provided', () => {
138
- const { rerender } = render(
139
- <FlowNavigation {...props} activeStep={0} onGoBack={undefined} />,
140
- );
141
-
142
- const flag = screen.queryByAltText('logo');
143
-
144
- expect(flag).toBeInTheDocument();
145
-
146
- rerender(<FlowNavigation {...props} activeStep={1} onGoBack={undefined} />);
147
-
148
- expect(flag).toBeInTheDocument();
149
-
150
- rerender(<FlowNavigation {...props} activeStep={0} onGoBack={jest.fn()} />);
151
-
152
- expect(flag).toBeInTheDocument();
153
-
154
- rerender(<FlowNavigation {...props} activeStep={1} onGoBack={jest.fn()} />);
155
-
156
- expect(flag).not.toBeInTheDocument();
157
- });
158
-
159
- it('renders BackButton with AnimatedLabel if onGoBack is provided and activeStep > 0', () => {
160
- const { rerender } = render(<FlowNavigation {...props} onGoBack={jest.fn()} />);
161
-
162
- expect(
163
- screen.queryByRole('button', { name: /back to previous step/i }),
164
- ).not.toBeInTheDocument();
165
-
166
- rerender(<FlowNavigation {...props} activeStep={1} />);
167
- expect(
168
- screen.queryByRole('button', { name: /back to previous step/i }),
169
- ).not.toBeInTheDocument();
170
-
171
- rerender(<FlowNavigation {...props} activeStep={1} onGoBack={jest.fn()} />);
172
-
173
- expect(screen.getByRole('button', { name: /back to previous step/i })).toBeInTheDocument();
174
- expect(screen.getByText('AnimatedLabel')).toBeInTheDocument();
175
- });
176
-
177
- it('renders correct AnimatedLabel', () => {
178
- const { rerender } = render(
179
- <FlowNavigation {...props} activeStep={1} onGoBack={jest.fn()} />,
180
- );
181
-
182
- expect(screen.getByTestId('activeLabel-1')).toBeInTheDocument();
183
-
184
- rerender(<FlowNavigation {...props} activeStep={2} onGoBack={jest.fn()} />);
185
-
186
- expect(screen.getByTestId('activeLabel-2')).toBeInTheDocument();
187
- });
188
- });
189
- const logoFull = () => screen.getByAltText(`logo`);
190
- });