Skip to content

Commit 991af44

Browse files
mofojeddsmmcken
andauthored
refactor: Create SlideTransition and FadeTransition components (#1871)
- Create some components to wrap CSSTransition - Don't have to hardcode class names - Update tests and docs --------- Co-authored-by: Don <dsmmcken@gmail.com>
1 parent 29353c2 commit 991af44

24 files changed

Lines changed: 162 additions & 144 deletions

package-lock.json

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/auth-plugins/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
"@deephaven/redux": "file:../redux",
4343
"@deephaven/utils": "file:../utils",
4444
"classnames": "^2.3.1",
45-
"js-cookie": "^3.0.5",
46-
"react-transition-group": "^4.4.2"
45+
"js-cookie": "^3.0.5"
4746
},
4847
"devDependencies": {
4948
"@types/react": "^17.0.2"

packages/auth-plugins/src/AuthPluginPsk.test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { ReactNode } from 'react';
22
import Cookies from 'js-cookie';
33
import { act, render, screen } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
@@ -20,6 +20,17 @@ jest.mock('@deephaven/jsapi-components', () => ({
2020
}),
2121
}));
2222

23+
jest.mock('@deephaven/components', () => ({
24+
...jest.requireActual('@deephaven/components'),
25+
FadeTransition: ({
26+
children,
27+
in: inProp,
28+
}: {
29+
children: ReactNode;
30+
in: boolean;
31+
}) => (inProp ? children : null),
32+
}));
33+
2334
jest.mock('js-cookie');
2435
const mockedCookie = Cookies as jest.Mocked<typeof Cookies>;
2536
const mockChildText = 'Mock Auth Psk Child';

packages/auth-plugins/src/AuthPluginPsk.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useCallback, useEffect, useRef, useState } from 'react';
2-
import { CSSTransition } from 'react-transition-group';
3-
import { LoadingOverlay, ThemeExport } from '@deephaven/components';
2+
import { FadeTransition, LoadingOverlay } from '@deephaven/components';
43
import { useClient } from '@deephaven/jsapi-bootstrap';
54
import { useBroadcastLoginListener } from '@deephaven/jsapi-components';
65
import Log from '@deephaven/log';
@@ -169,13 +168,7 @@ function Component({ children, logoPath }: AuthPluginPskProps): JSX.Element {
169168
<>
170169
{isLoggedIn && children}
171170
{isInputRequired && (
172-
<CSSTransition
173-
in={!isLoggedIn}
174-
timeout={ThemeExport.transitionMs}
175-
classNames="fade"
176-
mountOnEnter
177-
unmountOnExit
178-
>
171+
<FadeTransition in={!isLoggedIn} mountOnEnter unmountOnExit>
179172
<Login logoPath={logoPath}>
180173
<LoginForm
181174
errorMessage={getErrorMessage(error)}
@@ -203,7 +196,7 @@ function Component({ children, logoPath }: AuthPluginPskProps): JSX.Element {
203196
</div>
204197
</LoginForm>
205198
</Login>
206-
</CSSTransition>
199+
</FadeTransition>
207200
)}
208201
<LoadingOverlay
209202
data-testid="auth-psk-loading"

packages/code-studio/src/main/AppMainContainer.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import React, {
77
} from 'react';
88
import classNames from 'classnames';
99
import memoize from 'memoize-one';
10-
import { CSSTransition } from 'react-transition-group';
1110
import { connect } from 'react-redux';
1211
import { RouteComponentProps, withRouter } from 'react-router-dom';
1312
import shortid from 'shortid';
@@ -26,6 +25,7 @@ import {
2625
DebouncedModal,
2726
NavTabList,
2827
type NavTabItem,
28+
SlideTransition,
2929
} from '@deephaven/components';
3030
import { SHORTCUTS as IRIS_GRID_SHORTCUTS } from '@deephaven/iris-grid';
3131
import {
@@ -1002,19 +1002,13 @@ export class AppMainContainer extends Component<
10021002
...dashboardPlugins,
10031003
]}
10041004
/>
1005-
<CSSTransition
1006-
in={isSettingsMenuShown}
1007-
timeout={ThemeExport.transitionMidMs}
1008-
classNames="slide-left"
1009-
mountOnEnter
1010-
unmountOnExit
1011-
>
1005+
<SlideTransition in={isSettingsMenuShown} mountOnEnter unmountOnExit>
10121006
<SettingsMenu
10131007
serverConfigValues={serverConfigValues}
10141008
onDone={this.handleSettingsMenuHide}
10151009
user={user}
10161010
/>
1017-
</CSSTransition>
1011+
</SlideTransition>
10181012
<ContextActions actions={contextActions} />
10191013
<input
10201014
ref={this.importElement}

packages/code-studio/src/settings/ColumnSpecificSectionContent.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import React, {
77
import { connect } from 'react-redux';
88
import { dhNewCircleLargeFilled, vsTrash } from '@deephaven/icons';
99
import memoize from 'memoizee';
10-
import { CSSTransition, TransitionGroup } from 'react-transition-group';
10+
import { TransitionGroup } from 'react-transition-group';
1111
import debounce from 'lodash.debounce';
1212
import classNames from 'classnames';
13-
import { Button, Select, ThemeExport } from '@deephaven/components';
13+
import { Button, FadeTransition, Select } from '@deephaven/components';
1414
import {
1515
DateTimeColumnFormatter,
1616
IntegerColumnFormatter,
@@ -577,14 +577,9 @@ export class ColumnSpecificSectionContent extends PureComponent<
577577
const { formatRulesChanged, formatSettings } = this.state;
578578

579579
const formatRules = formatSettings.map((rule, index) => (
580-
<CSSTransition
581-
key={rule.id}
582-
classNames="fade"
583-
timeout={ThemeExport.transitionMs}
584-
onEnter={this.handleFormatRuleEntered}
585-
>
580+
<FadeTransition key={rule.id} onEnter={this.handleFormatRuleEntered}>
586581
{this.renderFormatRule(index, rule)}
587-
</CSSTransition>
582+
</FadeTransition>
588583
));
589584

590585
const addNewRuleButton = (

packages/components/src/ToastNotification.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { vsClose } from '@deephaven/icons';
55
import Button from './Button';
66
import ThemeExport from './ThemeExport';
77
import './ToastNotification.scss';
8+
import { FadeTransition } from './transitions';
89

910
type ToastNotificationProps = {
1011
buttons?: (typeof Button)[];
@@ -50,15 +51,14 @@ function ToastNotification({
5051
<div className="message-container">
5152
<span className="message">{message}</span>
5253
</div>
53-
<CSSTransition
54+
<FadeTransition
5455
in={hasButtons}
5556
timeout={ThemeExport.transitionSlowMs}
56-
classNames="fade"
5757
mountOnEnter
5858
unmountOnExit
5959
>
6060
<div className="buttons-container">{buttons}</div>
61-
</CSSTransition>
61+
</FadeTransition>
6262
{onDismiss && (
6363
<Button
6464
kind="ghost"

packages/components/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export * from './SpectrumUtils';
5353
export * from './TableViewEmptyState';
5454
export * from './TextWithTooltip';
5555
export * from './theme';
56+
export * from './transitions';
5657
export { default as ThemeExport } from './ThemeExport';
5758
export { default as TimeInput } from './TimeInput';
5859
export { default as TimeSlider } from './TimeSlider';

packages/components/src/navigation/Stack.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { render, screen } from '@testing-library/react';
44
import Stack from './Stack';
55

66
// Mock the CSS transitions to appear right away, and call the entered animation after a timeout
7-
jest.mock('react-transition-group', () => ({
8-
CSSTransition: jest.fn(props => {
7+
jest.mock('../transitions', () => ({
8+
SlideTransition: jest.fn(props => {
99
if (props.in === false) {
1010
return null;
1111
}

packages/components/src/navigation/Stack.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { useState, useEffect, useMemo, useCallback } from 'react';
2-
import { CSSTransition } from 'react-transition-group';
32
import { usePrevious } from '@deephaven/react-hooks';
4-
import ThemeExport from '../ThemeExport';
53
import './Stack.scss';
4+
import { SlideTransition } from '../transitions';
65

76
export type StackProps = {
87
children: React.ReactNode | React.ReactNode[];
@@ -88,10 +87,9 @@ export function Stack({
8887
{mainView}
8988
</div>
9089

91-
<CSSTransition
90+
<SlideTransition
91+
direction="right"
9292
in={poppingView != null}
93-
timeout={ThemeExport.transitionMidMs}
94-
classNames="slide-right"
9593
onEntered={popComplete}
9694
>
9795
{/* Without the fragment, the transition doesn't work. Without the conditional render, the stack is blank */}
@@ -101,20 +99,15 @@ export function Stack({
10199
<div className="popping-view">{poppingView}</div>
102100
)}
103101
</>
104-
</CSSTransition>
105-
<CSSTransition
106-
in={pushingView != null}
107-
timeout={ThemeExport.transitionMidMs}
108-
classNames="slide-left"
109-
onEntered={pushComplete}
110-
>
102+
</SlideTransition>
103+
<SlideTransition in={pushingView != null} onEntered={pushComplete}>
111104
{/* eslint-disable-next-line react/jsx-no-useless-fragment */}
112105
<>
113106
{pushingView != null && (
114107
<div className="pushing-view">{pushingView}</div>
115108
)}
116109
</>
117-
</CSSTransition>
110+
</SlideTransition>
118111
</div>
119112
);
120113
}

0 commit comments

Comments
 (0)