box-ui-elements 23.4.0-beta.18 → 23.4.0-beta.19
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/dist/explorer.css +1 -1
- package/dist/explorer.js +1 -1
- package/dist/preview.css +1 -1
- package/dist/preview.js +1 -1
- package/dist/sidebar.css +1 -1
- package/dist/sidebar.js +1 -1
- package/es/elements/common/back-button/BackButton.js.map +1 -0
- package/es/elements/common/back-button/index.js +3 -0
- package/es/elements/common/{nav-button → back-button}/index.js.flow +1 -1
- package/es/elements/common/back-button/index.js.map +1 -0
- package/es/elements/content-sidebar/SidebarNavButton.js +29 -22
- package/es/elements/content-sidebar/SidebarNavButton.js.flow +28 -21
- package/es/elements/content-sidebar/SidebarNavButton.js.map +1 -1
- package/es/elements/content-sidebar/SidebarNavButton.scss +13 -0
- package/es/elements/content-sidebar/versions/StaticVersionSidebar.js +1 -1
- package/es/elements/content-sidebar/versions/StaticVersionSidebar.js.flow +1 -1
- package/es/elements/content-sidebar/versions/StaticVersionSidebar.js.map +1 -1
- package/es/elements/content-sidebar/versions/VersionsSidebar.js +1 -1
- package/es/elements/content-sidebar/versions/VersionsSidebar.js.flow +1 -1
- package/es/elements/content-sidebar/versions/VersionsSidebar.js.map +1 -1
- package/package.json +1 -1
- package/src/elements/common/{nav-button → back-button}/__tests__/BackButton.test.js +1 -1
- package/src/elements/common/{nav-button → back-button}/index.js +1 -1
- package/src/elements/content-sidebar/SidebarNavButton.js +28 -21
- package/src/elements/content-sidebar/SidebarNavButton.scss +13 -0
- package/src/elements/content-sidebar/__tests__/SidebarNavButton.test.js +208 -26
- package/src/elements/content-sidebar/versions/StaticVersionSidebar.js +1 -1
- package/src/elements/content-sidebar/versions/VersionsSidebar.js +1 -1
- package/src/elements/content-sidebar/versions/__tests__/StaticVersionSidebar.test.js +5 -7
- package/src/elements/content-sidebar/versions/__tests__/VersionsSidebar.test.js +5 -7
- package/es/elements/common/nav-button/BackButton.js.map +0 -1
- package/es/elements/common/nav-button/NavButton.js +0 -63
- package/es/elements/common/nav-button/NavButton.js.flow +0 -80
- package/es/elements/common/nav-button/NavButton.js.map +0 -1
- package/es/elements/common/nav-button/index.js +0 -3
- package/es/elements/common/nav-button/index.js.map +0 -1
- package/src/elements/common/nav-button/NavButton.js +0 -80
- package/src/elements/common/nav-button/__tests__/NavButton.test.js +0 -265
- /package/es/elements/common/{nav-button → back-button}/BackButton.js +0 -0
- /package/es/elements/common/{nav-button → back-button}/BackButton.js.flow +0 -0
- /package/es/elements/common/{nav-button → back-button}/BackButton.scss +0 -0
- /package/src/elements/common/{nav-button → back-button}/BackButton.js +0 -0
- /package/src/elements/common/{nav-button → back-button}/BackButton.scss +0 -0
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { MemoryRouter } from 'react-router-dom';
|
|
3
|
-
import {
|
|
4
|
-
import { render, screen, fireEvent } from '@testing-library/react';
|
|
5
|
-
import PlainButton from '../../../components/plain-button';
|
|
2
|
+
import { MemoryRouter, Router } from 'react-router-dom';
|
|
3
|
+
import { render, screen, fireEvent } from '../../../test-utils/testing-library';
|
|
6
4
|
import SidebarNavButton from '../SidebarNavButton';
|
|
7
|
-
import Tooltip from '../../../components/tooltip/Tooltip';
|
|
8
5
|
|
|
9
6
|
describe('elements/content-sidebar/SidebarNavButton', () => {
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const renderWrapper = ({ children, ref, ...props }, path = '/') =>
|
|
12
|
+
render(
|
|
12
13
|
<MemoryRouter initialEntries={[path]}>
|
|
13
|
-
<SidebarNavButton {...props}>
|
|
14
|
+
<SidebarNavButton ref={ref} {...props}>
|
|
15
|
+
{children}
|
|
16
|
+
</SidebarNavButton>
|
|
14
17
|
</MemoryRouter>,
|
|
15
18
|
);
|
|
16
|
-
const getButton = wrapper => wrapper.find(PlainButton).first();
|
|
17
19
|
|
|
18
20
|
test('should render nav button properly', () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
renderWrapper({
|
|
22
|
+
tooltip: 'foo',
|
|
23
|
+
sidebarView: 'activity',
|
|
24
|
+
children: 'test button',
|
|
25
|
+
});
|
|
26
|
+
const button = screen.getByRole('tab');
|
|
21
27
|
|
|
22
|
-
expect(
|
|
23
|
-
expect(button.
|
|
28
|
+
expect(button).toHaveAttribute('aria-label', 'foo');
|
|
29
|
+
expect(button).toHaveAttribute('aria-selected', 'false');
|
|
30
|
+
expect(button).toHaveAttribute('aria-controls', 'activity-content');
|
|
31
|
+
expect(button).toHaveAttribute('role', 'tab');
|
|
32
|
+
expect(button).toHaveAttribute('tabindex', '-1');
|
|
33
|
+
expect(button).toHaveAttribute('type', 'button');
|
|
34
|
+
expect(button).toHaveAttribute('id', 'activity');
|
|
35
|
+
expect(button).toHaveClass('bcs-NavButton');
|
|
36
|
+
expect(button).not.toHaveClass('bcs-is-selected');
|
|
37
|
+
expect(button).toHaveTextContent('test button');
|
|
24
38
|
});
|
|
25
39
|
|
|
26
40
|
test.each`
|
|
@@ -33,11 +47,20 @@ describe('elements/content-sidebar/SidebarNavButton', () => {
|
|
|
33
47
|
isOpen,
|
|
34
48
|
sidebarView: 'activity',
|
|
35
49
|
tooltip: 'foo',
|
|
50
|
+
children: 'test button',
|
|
36
51
|
};
|
|
37
|
-
|
|
38
|
-
const button =
|
|
52
|
+
renderWrapper(props, '/activity');
|
|
53
|
+
const button = screen.getByRole('tab');
|
|
39
54
|
|
|
40
|
-
|
|
55
|
+
if (expected) {
|
|
56
|
+
expect(button).toHaveClass('bcs-is-selected');
|
|
57
|
+
expect(button).toHaveAttribute('aria-selected', 'true');
|
|
58
|
+
expect(button).toHaveAttribute('tabindex', '0');
|
|
59
|
+
} else {
|
|
60
|
+
expect(button).not.toHaveClass('bcs-is-selected');
|
|
61
|
+
expect(button).toHaveAttribute('aria-selected', 'false');
|
|
62
|
+
expect(button).toHaveAttribute('tabindex', '-1');
|
|
63
|
+
}
|
|
41
64
|
});
|
|
42
65
|
|
|
43
66
|
test.each`
|
|
@@ -48,26 +71,185 @@ describe('elements/content-sidebar/SidebarNavButton', () => {
|
|
|
48
71
|
${'/activity/test'} | ${true}
|
|
49
72
|
${'/skills'} | ${false}
|
|
50
73
|
`('should reflect active state ($expected) correctly based on active path', ({ expected, path }) => {
|
|
51
|
-
|
|
52
|
-
|
|
74
|
+
renderWrapper(
|
|
75
|
+
{
|
|
76
|
+
isOpen: true,
|
|
77
|
+
sidebarView: 'activity',
|
|
78
|
+
tooltip: 'foo',
|
|
79
|
+
children: 'test button',
|
|
80
|
+
},
|
|
81
|
+
path,
|
|
82
|
+
);
|
|
83
|
+
const button = screen.getByRole('tab');
|
|
53
84
|
|
|
54
|
-
|
|
85
|
+
if (expected) {
|
|
86
|
+
expect(button).toHaveClass('bcs-is-selected');
|
|
87
|
+
expect(button).toHaveAttribute('aria-selected', 'true');
|
|
88
|
+
expect(button).toHaveAttribute('tabindex', '0');
|
|
89
|
+
} else {
|
|
90
|
+
expect(button).not.toHaveClass('bcs-is-selected');
|
|
91
|
+
expect(button).toHaveAttribute('aria-selected', 'false');
|
|
92
|
+
expect(button).toHaveAttribute('tabindex', '-1');
|
|
93
|
+
}
|
|
55
94
|
});
|
|
56
95
|
|
|
57
96
|
test('should call onClick with sidebarView when clicked', () => {
|
|
58
97
|
const mockOnClick = jest.fn();
|
|
59
98
|
const mockSidebarView = 'activity';
|
|
60
99
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
100
|
+
renderWrapper({
|
|
101
|
+
onClick: mockOnClick,
|
|
102
|
+
sidebarView: mockSidebarView,
|
|
103
|
+
tooltip: 'test',
|
|
104
|
+
children: 'button',
|
|
105
|
+
});
|
|
68
106
|
const button = screen.getByText('button');
|
|
69
107
|
|
|
70
108
|
fireEvent.click(button);
|
|
71
109
|
expect(mockOnClick).toBeCalledWith(mockSidebarView);
|
|
72
110
|
});
|
|
111
|
+
|
|
112
|
+
test.each`
|
|
113
|
+
isDisabled | expected
|
|
114
|
+
${true} | ${true}
|
|
115
|
+
${false} | ${false}
|
|
116
|
+
${undefined} | ${false}
|
|
117
|
+
`('should apply bdl-is-disabled class when isDisabled is $isDisabled', ({ isDisabled, expected }) => {
|
|
118
|
+
const content = 'Activity';
|
|
119
|
+
renderWrapper({
|
|
120
|
+
isDisabled,
|
|
121
|
+
sidebarView: 'activity',
|
|
122
|
+
tooltip: 'Activity',
|
|
123
|
+
children: content,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const button = screen.getByRole('tab');
|
|
127
|
+
if (expected) {
|
|
128
|
+
expect(button).toHaveClass('bdl-is-disabled');
|
|
129
|
+
} else {
|
|
130
|
+
expect(button).not.toHaveClass('bdl-is-disabled');
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test.each`
|
|
135
|
+
elementId | sidebarView | expectedId | expectedAriaControls
|
|
136
|
+
${undefined} | ${'activity'} | ${'activity'} | ${'activity-content'}
|
|
137
|
+
${''} | ${'activity'} | ${'activity'} | ${'activity-content'}
|
|
138
|
+
${'sidebar'} | ${'activity'} | ${'sidebar_activity'} | ${'sidebar_activity-content'}
|
|
139
|
+
${'main'} | ${'skills'} | ${'main_skills'} | ${'main_skills-content'}
|
|
140
|
+
`(
|
|
141
|
+
'should generate correct id and aria-controls with elementId=$elementId and sidebarView=$sidebarView',
|
|
142
|
+
({ elementId, sidebarView, expectedId, expectedAriaControls }) => {
|
|
143
|
+
renderWrapper({
|
|
144
|
+
elementId,
|
|
145
|
+
sidebarView,
|
|
146
|
+
tooltip: 'test',
|
|
147
|
+
children: 'test button',
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const button = screen.getByRole('tab');
|
|
151
|
+
expect(button).toHaveAttribute('id', expectedId);
|
|
152
|
+
expect(button).toHaveAttribute('aria-controls', expectedAriaControls);
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
test('should forward ref to the Button', () => {
|
|
157
|
+
const ref = React.createRef();
|
|
158
|
+
|
|
159
|
+
renderWrapper({
|
|
160
|
+
ref,
|
|
161
|
+
sidebarView: 'activity',
|
|
162
|
+
tooltip: 'test',
|
|
163
|
+
children: 'test button',
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const button = screen.getByRole('tab');
|
|
167
|
+
expect(ref.current).toBe(button);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('navigation on click', () => {
|
|
171
|
+
const mockHistoryPush = jest.fn();
|
|
172
|
+
const mockHistoryReplace = jest.fn();
|
|
173
|
+
const mockHistory = {
|
|
174
|
+
push: mockHistoryPush,
|
|
175
|
+
replace: mockHistoryReplace,
|
|
176
|
+
listen: jest.fn(),
|
|
177
|
+
location: { pathname: '/activity' },
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const renderWithRouter = (props, history = mockHistory) => {
|
|
181
|
+
return render(
|
|
182
|
+
<Router history={history}>
|
|
183
|
+
<SidebarNavButton sidebarView="activity" tooltip="test" {...props}>
|
|
184
|
+
Activity
|
|
185
|
+
</SidebarNavButton>
|
|
186
|
+
</Router>,
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
test('calls onClick handler and history.push on left click when not exact match', () => {
|
|
191
|
+
const mockOnClick = jest.fn();
|
|
192
|
+
const mockHistoryWithDifferentPath = {
|
|
193
|
+
...mockHistory,
|
|
194
|
+
location: { pathname: '/activity/versions' },
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
renderWithRouter({ onClick: mockOnClick }, mockHistoryWithDifferentPath);
|
|
198
|
+
|
|
199
|
+
const button = screen.getByText('Activity');
|
|
200
|
+
fireEvent.click(button, { button: 0 });
|
|
201
|
+
|
|
202
|
+
expect(mockOnClick).toBeCalledWith('activity');
|
|
203
|
+
expect(mockHistoryPush).toBeCalledWith({
|
|
204
|
+
pathname: '/activity',
|
|
205
|
+
state: { open: true },
|
|
206
|
+
});
|
|
207
|
+
expect(mockHistoryReplace).not.toBeCalled();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('calls history.replace on left click when exact match', () => {
|
|
211
|
+
const mockOnClick = jest.fn();
|
|
212
|
+
|
|
213
|
+
renderWithRouter({ onClick: mockOnClick });
|
|
214
|
+
|
|
215
|
+
const button = screen.getByText('Activity');
|
|
216
|
+
fireEvent.click(button, { button: 0 });
|
|
217
|
+
|
|
218
|
+
expect(mockOnClick).toBeCalledWith('activity');
|
|
219
|
+
expect(mockHistoryReplace).toBeCalledWith({
|
|
220
|
+
pathname: '/activity',
|
|
221
|
+
state: { open: true },
|
|
222
|
+
});
|
|
223
|
+
expect(mockHistoryPush).not.toBeCalled();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('does not call history.push on right click', () => {
|
|
227
|
+
const mockOnClick = jest.fn();
|
|
228
|
+
|
|
229
|
+
renderWithRouter({ onClick: mockOnClick });
|
|
230
|
+
|
|
231
|
+
const button = screen.getByText('Activity');
|
|
232
|
+
fireEvent.click(button, { button: 1 });
|
|
233
|
+
|
|
234
|
+
expect(mockOnClick).toBeCalledWith('activity');
|
|
235
|
+
expect(mockHistoryPush).not.toBeCalled();
|
|
236
|
+
expect(mockHistoryReplace).not.toBeCalled();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('does not call history.push on prevented event', () => {
|
|
240
|
+
const mockOnClick = jest.fn();
|
|
241
|
+
|
|
242
|
+
renderWithRouter({ onClick: mockOnClick });
|
|
243
|
+
|
|
244
|
+
const button = screen.getByText('Activity');
|
|
245
|
+
|
|
246
|
+
// Prevent default on the button click
|
|
247
|
+
button.addEventListener('click', e => e.preventDefault());
|
|
248
|
+
fireEvent.click(button, { button: 0 });
|
|
249
|
+
|
|
250
|
+
expect(mockOnClick).toBeCalledWith('activity');
|
|
251
|
+
expect(mockHistoryPush).not.toBeCalled();
|
|
252
|
+
expect(mockHistoryReplace).not.toBeCalled();
|
|
253
|
+
});
|
|
254
|
+
});
|
|
73
255
|
});
|
|
@@ -10,7 +10,7 @@ import { Route } from 'react-router-dom';
|
|
|
10
10
|
|
|
11
11
|
import BoxDrive140 from '../../../illustration/BoxDrive140';
|
|
12
12
|
|
|
13
|
-
import
|
|
13
|
+
import BackButton from '../../common/back-button';
|
|
14
14
|
import PrimaryButton from '../../../components/primary-button';
|
|
15
15
|
import { LoadingIndicatorWrapper } from '../../../components/loading-indicator';
|
|
16
16
|
import VersionsMenu from './VersionsMenu';
|
|
@@ -12,7 +12,7 @@ import InlineError from '../../../components/inline-error';
|
|
|
12
12
|
import messages from './messages';
|
|
13
13
|
import SidebarContent from '../SidebarContent';
|
|
14
14
|
import VersionsMenu from './VersionsMenu';
|
|
15
|
-
import
|
|
15
|
+
import BackButton from '../../common/back-button';
|
|
16
16
|
import { DEFAULT_FETCH_END } from '../../../constants';
|
|
17
17
|
import { LoadingIndicatorWrapper } from '../../../components/loading-indicator';
|
|
18
18
|
import type { BoxItemVersion } from '../../../common/types/core';
|
|
@@ -3,13 +3,11 @@ import { MemoryRouter, Route } from 'react-router-dom';
|
|
|
3
3
|
import { render, screen, userEvent } from '../../../../test-utils/testing-library';
|
|
4
4
|
import StaticVersionSidebar from '../StaticVersionSidebar';
|
|
5
5
|
|
|
6
|
-
jest.mock('../../../common/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
),
|
|
12
|
-
}));
|
|
6
|
+
jest.mock('../../../common/back-button', () => ({ onClick, 'data-resin-target': dataResinTarget }) => (
|
|
7
|
+
<button type="button" onClick={onClick} data-resin-target={dataResinTarget} data-testid="back-button">
|
|
8
|
+
Back
|
|
9
|
+
</button>
|
|
10
|
+
));
|
|
13
11
|
|
|
14
12
|
jest.mock('../VersionsMenu', () => ({ versions, fileId, versionCount, versionLimit }) => (
|
|
15
13
|
<div data-testid="versions-menu">
|
|
@@ -4,13 +4,11 @@ import { render, screen, userEvent } from '../../../../test-utils/testing-librar
|
|
|
4
4
|
import messages from '../messages';
|
|
5
5
|
import VersionsSidebar from '../VersionsSidebar';
|
|
6
6
|
|
|
7
|
-
jest.mock('../../../common/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
),
|
|
13
|
-
}));
|
|
7
|
+
jest.mock('../../../common/back-button', () => ({ onClick, 'data-resin-target': dataResinTarget }) => (
|
|
8
|
+
<button type="button" onClick={onClick} data-resin-target={dataResinTarget} data-testid="back-button">
|
|
9
|
+
Back
|
|
10
|
+
</button>
|
|
11
|
+
));
|
|
14
12
|
|
|
15
13
|
jest.mock('../VersionsMenu', () => ({ versions, fileId, versionCount, versionLimit }) => (
|
|
16
14
|
<div data-testid="versions-menu">
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BackButton.js","names":["React","classNames","FormattedMessage","IconNavigateLeft","messages","PlainButton","BackButton","_ref","className","onClick","rest","_objectWithoutProperties","_excluded","createElement","_extends","type","height","width","back"],"sources":["../../../../src/elements/common/nav-button/BackButton.js"],"sourcesContent":["/**\n * @flow\n * @file Back Button component\n * @author Box\n */\n\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport { FormattedMessage } from 'react-intl';\nimport IconNavigateLeft from '../../../icons/general/IconNavigateLeft';\nimport messages from '../messages';\nimport PlainButton from '../../../components/plain-button';\nimport './BackButton.scss';\n\ntype Props = {\n className?: string,\n onClick: () => void,\n};\n\nconst BackButton = ({ className, onClick, ...rest }: Props) => (\n <PlainButton className={classNames('bdl-BackButton', className)} onClick={onClick} type=\"button\" {...rest}>\n <IconNavigateLeft height={24} width={24} />\n <span className=\"accessibility-hidden\">\n <FormattedMessage {...messages.back} />\n </span>\n </PlainButton>\n);\n\nexport default BackButton;\n"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,OAAOC,gBAAgB,MAAM,yCAAyC;AACtE,OAAOC,QAAQ,MAAM,aAAa;AAClC,OAAOC,WAAW,MAAM,kCAAkC;AAC1D,OAAO,mBAAmB;AAO1B,MAAMC,UAAU,GAAGC,IAAA;EAAA,IAAC;MAAEC,SAAS;MAAEC;IAAwB,CAAC,GAAAF,IAAA;IAAbG,IAAI,GAAAC,wBAAA,CAAAJ,IAAA,EAAAK,SAAA;EAAA,oBAC7CZ,KAAA,CAAAa,aAAA,CAACR,WAAW,EAAAS,QAAA;IAACN,SAAS,EAAEP,UAAU,CAAC,gBAAgB,EAAEO,SAAS,CAAE;IAACC,OAAO,EAAEA,OAAQ;IAACM,IAAI,EAAC;EAAQ,GAAKL,IAAI,gBACrGV,KAAA,CAAAa,aAAA,CAACV,gBAAgB;IAACa,MAAM,EAAE,EAAG;IAACC,KAAK,EAAE;EAAG,CAAE,CAAC,eAC3CjB,KAAA,CAAAa,aAAA;IAAML,SAAS,EAAC;EAAsB,gBAClCR,KAAA,CAAAa,aAAA,CAACX,gBAAgB,EAAKE,QAAQ,CAACc,IAAO,CACpC,CACG,CAAC;AAAA,CACjB;AAED,eAAeZ,UAAU","ignoreList":[]}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const _excluded = ["activeClassName", "children", "className", "component", "exact", "isActive", "isDisabled", "onClick", "replace", "strict", "to"];
|
|
2
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
-
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
4
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @file Nav Button component intended to mimic React Router's NavLink component for non-anchor elements
|
|
8
|
-
* @author Box
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import * as React from 'react';
|
|
12
|
-
import classNames from 'classnames';
|
|
13
|
-
import { Route } from 'react-router-dom';
|
|
14
|
-
import PlainButton from '../../../components/plain-button';
|
|
15
|
-
import { isLeftClick } from '../../../utils/dom';
|
|
16
|
-
const NavButton = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
17
|
-
const {
|
|
18
|
-
activeClassName = 'bdl-is-active',
|
|
19
|
-
children,
|
|
20
|
-
className = 'bdl-NavButton',
|
|
21
|
-
component: Component = PlainButton,
|
|
22
|
-
exact,
|
|
23
|
-
isActive,
|
|
24
|
-
isDisabled,
|
|
25
|
-
onClick,
|
|
26
|
-
replace,
|
|
27
|
-
strict,
|
|
28
|
-
to
|
|
29
|
-
} = props,
|
|
30
|
-
rest = _objectWithoutProperties(props, _excluded);
|
|
31
|
-
const path = typeof to === 'object' ? to.pathname : to;
|
|
32
|
-
const disabledClassName = 'bdl-is-disabled';
|
|
33
|
-
return /*#__PURE__*/React.createElement(Route, {
|
|
34
|
-
exact: exact,
|
|
35
|
-
path: path,
|
|
36
|
-
strict: strict
|
|
37
|
-
}, ({
|
|
38
|
-
history,
|
|
39
|
-
location,
|
|
40
|
-
match
|
|
41
|
-
}) => {
|
|
42
|
-
const isActiveValue = !!(isActive ? isActive(match, location) : match);
|
|
43
|
-
return /*#__PURE__*/React.createElement(Component, _extends({
|
|
44
|
-
className: classNames(className, {
|
|
45
|
-
[activeClassName]: isActiveValue,
|
|
46
|
-
[disabledClassName]: isDisabled
|
|
47
|
-
}),
|
|
48
|
-
isDisabled: isDisabled,
|
|
49
|
-
onClick: event => {
|
|
50
|
-
if (onClick) {
|
|
51
|
-
onClick(event);
|
|
52
|
-
}
|
|
53
|
-
if (!event.defaultPrevented && isLeftClick(event)) {
|
|
54
|
-
const method = replace ? history.replace : history.push;
|
|
55
|
-
method(to);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
ref: ref
|
|
59
|
-
}, rest), children);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
export default NavButton;
|
|
63
|
-
//# sourceMappingURL=NavButton.js.map
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @flow
|
|
3
|
-
* @file Nav Button component intended to mimic React Router's NavLink component for non-anchor elements
|
|
4
|
-
* @author Box
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as React from 'react';
|
|
8
|
-
import classNames from 'classnames';
|
|
9
|
-
import { Route } from 'react-router-dom';
|
|
10
|
-
import type { Match, Location } from 'react-router-dom';
|
|
11
|
-
import PlainButton from '../../../components/plain-button';
|
|
12
|
-
import { isLeftClick } from '../../../utils/dom';
|
|
13
|
-
|
|
14
|
-
type Props = {
|
|
15
|
-
activeClassName?: string,
|
|
16
|
-
children: React.Node,
|
|
17
|
-
className?: string,
|
|
18
|
-
component?: React.ComponentType<any>,
|
|
19
|
-
exact?: boolean,
|
|
20
|
-
isActive?: (match: Match, location: Location) => ?boolean,
|
|
21
|
-
isDisabled?: boolean,
|
|
22
|
-
onClick?: (event: SyntheticEvent<>) => void,
|
|
23
|
-
replace?: boolean,
|
|
24
|
-
strict?: boolean,
|
|
25
|
-
to: string | Location,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const NavButton = React.forwardRef<Props, React.Ref<any>>((props: Props, ref: React.Ref<any>) => {
|
|
29
|
-
const {
|
|
30
|
-
activeClassName = 'bdl-is-active',
|
|
31
|
-
children,
|
|
32
|
-
className = 'bdl-NavButton',
|
|
33
|
-
component: Component = PlainButton,
|
|
34
|
-
exact,
|
|
35
|
-
isActive,
|
|
36
|
-
isDisabled,
|
|
37
|
-
onClick,
|
|
38
|
-
replace,
|
|
39
|
-
strict,
|
|
40
|
-
to,
|
|
41
|
-
...rest
|
|
42
|
-
} = props;
|
|
43
|
-
const path = typeof to === 'object' ? to.pathname : to;
|
|
44
|
-
|
|
45
|
-
const disabledClassName = 'bdl-is-disabled';
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<Route exact={exact} path={path} strict={strict}>
|
|
49
|
-
{({ history, location, match }) => {
|
|
50
|
-
const isActiveValue = !!(isActive ? isActive(match, location) : match);
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<Component
|
|
54
|
-
className={classNames(className, {
|
|
55
|
-
[activeClassName]: isActiveValue,
|
|
56
|
-
[disabledClassName]: isDisabled,
|
|
57
|
-
})}
|
|
58
|
-
isDisabled={isDisabled}
|
|
59
|
-
onClick={event => {
|
|
60
|
-
if (onClick) {
|
|
61
|
-
onClick(event);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!event.defaultPrevented && isLeftClick(event)) {
|
|
65
|
-
const method = replace ? history.replace : history.push;
|
|
66
|
-
method(to);
|
|
67
|
-
}
|
|
68
|
-
}}
|
|
69
|
-
ref={ref}
|
|
70
|
-
{...rest}
|
|
71
|
-
>
|
|
72
|
-
{children}
|
|
73
|
-
</Component>
|
|
74
|
-
);
|
|
75
|
-
}}
|
|
76
|
-
</Route>
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
export default NavButton;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NavButton.js","names":["React","classNames","Route","PlainButton","isLeftClick","NavButton","forwardRef","props","ref","activeClassName","children","className","component","Component","exact","isActive","isDisabled","onClick","replace","strict","to","rest","_objectWithoutProperties","_excluded","path","pathname","disabledClassName","createElement","history","location","match","isActiveValue","_extends","event","defaultPrevented","method","push"],"sources":["../../../../src/elements/common/nav-button/NavButton.js"],"sourcesContent":["/**\n * @flow\n * @file Nav Button component intended to mimic React Router's NavLink component for non-anchor elements\n * @author Box\n */\n\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport { Route } from 'react-router-dom';\nimport type { Match, Location } from 'react-router-dom';\nimport PlainButton from '../../../components/plain-button';\nimport { isLeftClick } from '../../../utils/dom';\n\ntype Props = {\n activeClassName?: string,\n children: React.Node,\n className?: string,\n component?: React.ComponentType<any>,\n exact?: boolean,\n isActive?: (match: Match, location: Location) => ?boolean,\n isDisabled?: boolean,\n onClick?: (event: SyntheticEvent<>) => void,\n replace?: boolean,\n strict?: boolean,\n to: string | Location,\n};\n\nconst NavButton = React.forwardRef<Props, React.Ref<any>>((props: Props, ref: React.Ref<any>) => {\n const {\n activeClassName = 'bdl-is-active',\n children,\n className = 'bdl-NavButton',\n component: Component = PlainButton,\n exact,\n isActive,\n isDisabled,\n onClick,\n replace,\n strict,\n to,\n ...rest\n } = props;\n const path = typeof to === 'object' ? to.pathname : to;\n\n const disabledClassName = 'bdl-is-disabled';\n\n return (\n <Route exact={exact} path={path} strict={strict}>\n {({ history, location, match }) => {\n const isActiveValue = !!(isActive ? isActive(match, location) : match);\n\n return (\n <Component\n className={classNames(className, {\n [activeClassName]: isActiveValue,\n [disabledClassName]: isDisabled,\n })}\n isDisabled={isDisabled}\n onClick={event => {\n if (onClick) {\n onClick(event);\n }\n\n if (!event.defaultPrevented && isLeftClick(event)) {\n const method = replace ? history.replace : history.push;\n method(to);\n }\n }}\n ref={ref}\n {...rest}\n >\n {children}\n </Component>\n );\n }}\n </Route>\n );\n});\n\nexport default NavButton;\n"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,KAAK,QAAQ,kBAAkB;AAExC,OAAOC,WAAW,MAAM,kCAAkC;AAC1D,SAASC,WAAW,QAAQ,oBAAoB;AAgBhD,MAAMC,SAAS,gBAAGL,KAAK,CAACM,UAAU,CAAwB,CAACC,KAAY,EAAEC,GAAmB,KAAK;EAC7F,MAAM;MACFC,eAAe,GAAG,eAAe;MACjCC,QAAQ;MACRC,SAAS,GAAG,eAAe;MAC3BC,SAAS,EAAEC,SAAS,GAAGV,WAAW;MAClCW,KAAK;MACLC,QAAQ;MACRC,UAAU;MACVC,OAAO;MACPC,OAAO;MACPC,MAAM;MACNC;IAEJ,CAAC,GAAGb,KAAK;IADFc,IAAI,GAAAC,wBAAA,CACPf,KAAK,EAAAgB,SAAA;EACT,MAAMC,IAAI,GAAG,OAAOJ,EAAE,KAAK,QAAQ,GAAGA,EAAE,CAACK,QAAQ,GAAGL,EAAE;EAEtD,MAAMM,iBAAiB,GAAG,iBAAiB;EAE3C,oBACI1B,KAAA,CAAA2B,aAAA,CAACzB,KAAK;IAACY,KAAK,EAAEA,KAAM;IAACU,IAAI,EAAEA,IAAK;IAACL,MAAM,EAAEA;EAAO,GAC3C,CAAC;IAAES,OAAO;IAAEC,QAAQ;IAAEC;EAAM,CAAC,KAAK;IAC/B,MAAMC,aAAa,GAAG,CAAC,EAAEhB,QAAQ,GAAGA,QAAQ,CAACe,KAAK,EAAED,QAAQ,CAAC,GAAGC,KAAK,CAAC;IAEtE,oBACI9B,KAAA,CAAA2B,aAAA,CAACd,SAAS,EAAAmB,QAAA;MACNrB,SAAS,EAAEV,UAAU,CAACU,SAAS,EAAE;QAC7B,CAACF,eAAe,GAAGsB,aAAa;QAChC,CAACL,iBAAiB,GAAGV;MACzB,CAAC,CAAE;MACHA,UAAU,EAAEA,UAAW;MACvBC,OAAO,EAAEgB,KAAK,IAAI;QACd,IAAIhB,OAAO,EAAE;UACTA,OAAO,CAACgB,KAAK,CAAC;QAClB;QAEA,IAAI,CAACA,KAAK,CAACC,gBAAgB,IAAI9B,WAAW,CAAC6B,KAAK,CAAC,EAAE;UAC/C,MAAME,MAAM,GAAGjB,OAAO,GAAGU,OAAO,CAACV,OAAO,GAAGU,OAAO,CAACQ,IAAI;UACvDD,MAAM,CAACf,EAAE,CAAC;QACd;MACJ,CAAE;MACFZ,GAAG,EAAEA;IAAI,GACLa,IAAI,GAEPX,QACM,CAAC;EAEpB,CACG,CAAC;AAEhB,CAAC,CAAC;AAEF,eAAeL,SAAS","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["default","BackButton"],"sources":["../../../../src/elements/common/nav-button/index.js"],"sourcesContent":["export { default as BackButton } from './BackButton';\nexport { default } from './NavButton';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,UAAU,QAAQ,cAAc;AACpD,SAASD,OAAO,QAAQ,aAAa","ignoreList":[]}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @flow
|
|
3
|
-
* @file Nav Button component intended to mimic React Router's NavLink component for non-anchor elements
|
|
4
|
-
* @author Box
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as React from 'react';
|
|
8
|
-
import classNames from 'classnames';
|
|
9
|
-
import { Route } from 'react-router-dom';
|
|
10
|
-
import type { Match, Location } from 'react-router-dom';
|
|
11
|
-
import PlainButton from '../../../components/plain-button';
|
|
12
|
-
import { isLeftClick } from '../../../utils/dom';
|
|
13
|
-
|
|
14
|
-
type Props = {
|
|
15
|
-
activeClassName?: string,
|
|
16
|
-
children: React.Node,
|
|
17
|
-
className?: string,
|
|
18
|
-
component?: React.ComponentType<any>,
|
|
19
|
-
exact?: boolean,
|
|
20
|
-
isActive?: (match: Match, location: Location) => ?boolean,
|
|
21
|
-
isDisabled?: boolean,
|
|
22
|
-
onClick?: (event: SyntheticEvent<>) => void,
|
|
23
|
-
replace?: boolean,
|
|
24
|
-
strict?: boolean,
|
|
25
|
-
to: string | Location,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const NavButton = React.forwardRef<Props, React.Ref<any>>((props: Props, ref: React.Ref<any>) => {
|
|
29
|
-
const {
|
|
30
|
-
activeClassName = 'bdl-is-active',
|
|
31
|
-
children,
|
|
32
|
-
className = 'bdl-NavButton',
|
|
33
|
-
component: Component = PlainButton,
|
|
34
|
-
exact,
|
|
35
|
-
isActive,
|
|
36
|
-
isDisabled,
|
|
37
|
-
onClick,
|
|
38
|
-
replace,
|
|
39
|
-
strict,
|
|
40
|
-
to,
|
|
41
|
-
...rest
|
|
42
|
-
} = props;
|
|
43
|
-
const path = typeof to === 'object' ? to.pathname : to;
|
|
44
|
-
|
|
45
|
-
const disabledClassName = 'bdl-is-disabled';
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<Route exact={exact} path={path} strict={strict}>
|
|
49
|
-
{({ history, location, match }) => {
|
|
50
|
-
const isActiveValue = !!(isActive ? isActive(match, location) : match);
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<Component
|
|
54
|
-
className={classNames(className, {
|
|
55
|
-
[activeClassName]: isActiveValue,
|
|
56
|
-
[disabledClassName]: isDisabled,
|
|
57
|
-
})}
|
|
58
|
-
isDisabled={isDisabled}
|
|
59
|
-
onClick={event => {
|
|
60
|
-
if (onClick) {
|
|
61
|
-
onClick(event);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!event.defaultPrevented && isLeftClick(event)) {
|
|
65
|
-
const method = replace ? history.replace : history.push;
|
|
66
|
-
method(to);
|
|
67
|
-
}
|
|
68
|
-
}}
|
|
69
|
-
ref={ref}
|
|
70
|
-
{...rest}
|
|
71
|
-
>
|
|
72
|
-
{children}
|
|
73
|
-
</Component>
|
|
74
|
-
);
|
|
75
|
-
}}
|
|
76
|
-
</Route>
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
export default NavButton;
|