Skip to content

Commit 6606232

Browse files
authored
Merge pull request #342 from dabapps/upgrade-transition-group
Upgrade transition group
2 parents f7c0930 + fcef7b8 commit 6606232

File tree

13 files changed

+265
-83
lines changed

13 files changed

+265
-83
lines changed

examples/app.tsx

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { PureComponent } from 'react';
2+
import { PureComponent, ReactElement } from 'react';
33
import {
44
AppRoot,
55
Button,
@@ -11,22 +11,27 @@ import {
1111
DabIpsum,
1212
Footer,
1313
FormGroup,
14+
Highlight,
1415
InputGroup,
1516
InputGroupAddon,
17+
ModalRenderer,
1618
NavBar,
1719
Row,
1820
Section,
1921
SideBar,
2022
SpacedGroup,
2123
SpeechBubble,
2224
} from '../src/ts';
25+
import ExampleModal from './modal';
2326
import NavItems from './nav-items';
2427

2528
const X_CHAR = String.fromCharCode(215);
2629
const MENU_CHAR = String.fromCharCode(9776);
2730

2831
interface AppState {
2932
sidebarOpen: boolean;
33+
highlightActive: boolean;
34+
modals: ReadonlyArray<ReactElement<{}>>;
3035
}
3136

3237
class App extends PureComponent<{}, AppState> {
@@ -35,6 +40,8 @@ class App extends PureComponent<{}, AppState> {
3540

3641
this.state = {
3742
sidebarOpen: false,
43+
highlightActive: false,
44+
modals: [],
3845
};
3946
}
4047

@@ -284,6 +291,31 @@ class App extends PureComponent<{}, AppState> {
284291
</Row>
285292
</Section>
286293
</ContentBox>
294+
295+
<ContentBox>
296+
<Button
297+
className="margin-vertical-large primary"
298+
onClick={this.onClickOpenModal}
299+
>
300+
Open example modal
301+
</Button>
302+
303+
<ModalRenderer modals={this.state.modals} />
304+
</ContentBox>
305+
306+
<Highlight open={this.state.highlightActive}>
307+
<ContentBox>
308+
<Button
309+
className="margin-vertical-large primary"
310+
onClick={this.onClickToggleHighlight}
311+
>
312+
{this.state.highlightActive ? 'Un-highlight' : 'Highlight'}
313+
{' this box'}
314+
</Button>
315+
316+
<ModalRenderer modals={this.state.modals} />
317+
</ContentBox>
318+
</Highlight>
287319
</Container>
288320

289321
<Footer fixed>
@@ -306,6 +338,38 @@ class App extends PureComponent<{}, AppState> {
306338
sidebarOpen: false,
307339
});
308340
};
341+
342+
private onClickToggleHighlight = () => {
343+
this.setState(state => ({
344+
...state,
345+
highlightActive: !state.highlightActive,
346+
}));
347+
};
348+
349+
private onClickOpenModal = () => {
350+
this.setState(state => ({
351+
...state,
352+
modals: [
353+
...state.modals,
354+
<ExampleModal
355+
key={state.modals.length}
356+
onClickClose={this.onClickCloseModal}
357+
/>,
358+
],
359+
}));
360+
};
361+
362+
private onClickCloseModal = () => {
363+
this.setState(state => {
364+
const modalsCopy = [...state.modals];
365+
modalsCopy.pop();
366+
367+
return {
368+
...state,
369+
modals: modalsCopy,
370+
};
371+
});
372+
};
309373
}
310374

311375
export default App;

examples/modal.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from 'react';
2+
import { PureComponent } from 'react';
3+
4+
import {
5+
Button,
6+
Modal,
7+
ModalBody,
8+
ModalCloseIcon,
9+
ModalFooter,
10+
ModalHeader,
11+
SpacedGroup,
12+
} from '../src/ts';
13+
14+
interface ExampleModalProps {
15+
onClickClose: () => void;
16+
}
17+
18+
export default class ExampleModal extends PureComponent<ExampleModalProps> {
19+
public render() {
20+
return (
21+
<Modal onClickOutside={this.props.onClickClose}>
22+
<ModalHeader>
23+
<ModalCloseIcon />
24+
<h1>Hello</h1>
25+
</ModalHeader>
26+
<ModalBody>
27+
<p>I am a modal!</p>
28+
</ModalBody>
29+
<ModalFooter>
30+
<SpacedGroup block className="margin-vertical-large">
31+
<Button onClick={this.props.onClickClose}>Cancel</Button>
32+
<Button onClick={this.props.onClickClose} className="primary">
33+
Done
34+
</Button>
35+
</SpacedGroup>
36+
</ModalFooter>
37+
</Modal>
38+
);
39+
}
40+
}

package-lock.json

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

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dabapps/roe",
3-
"version": "0.11.3",
3+
"version": "0.12.0",
44
"description": "A collection of React components, styles, mixins, and atomic CSS classes to aid with the development of web applications.",
55
"main": "dist/js/index.js",
66
"types": "dist/js/index.d.ts",
@@ -10,7 +10,7 @@
1010
"dist": "./scripts/dist",
1111
"prettier": "prettier --write '**/*.{ts,tsx,js,jsx,json,md}'",
1212
"prettier-check": "prettier --check '**/*.{ts,tsx,js,jsx,json,md}'",
13-
"lint-js": "eslint ./*.js docs/**/*.js && tslint --project tsconfig.json '@(src|tests|types|docs)/**/*.@(ts|tsx)'",
13+
"lint-js": "eslint ./*.js docs/**/*.js && tslint --project tsconfig.json '@(src|tests|types|docs|examples)/**/*.@(ts|tsx)'",
1414
"lint-less": "lesshint 'src/less/' 'docs/less/'",
1515
"lint": "npm run lint-js && npm run lint-less",
1616
"test-dist-react-16": "npm i @types/[email protected] @types/[email protected] --no-save && tsc --project 'tsconfig.json' --noEmit && npm run dist",
@@ -52,14 +52,14 @@
5252
"@types/random-seed": "^0.3.2",
5353
"@types/react": ">= 15",
5454
"@types/react-dom": ">= 15",
55-
"@types/react-transition-group": "^1.1.4",
55+
"@types/react-transition-group": "^2.9.2",
5656
"classnames": "^2.2.5",
5757
"cookie": "^0.3.1",
5858
"normalize.css": "^8.0.1",
5959
"random-seed": "^0.3.0",
6060
"react": ">= 15",
6161
"react-dom": ">= 15",
62-
"react-transition-group": "^1.2.1"
62+
"react-transition-group": "^2.9.0"
6363
},
6464
"devDependencies": {
6565
"@types/enzyme": "^3.1.5",
@@ -107,7 +107,7 @@
107107
"normalize.css": "8",
108108
"react": ">= 15",
109109
"react-dom": ">= 15",
110-
"react-transition-group": "1"
110+
"react-transition-group": "2"
111111
},
112112
"jest": {
113113
"testURL": "http://localhost/",

src/less/highlight.less

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,40 @@
77
}
88
}
99

10-
.highlight-transition-enter.highlight-transition-enter-active,
11-
.highlight-transition-appear.highlight-transition-appear-active {
10+
.highlight-transition-enter-active,
11+
.highlight-transition-appear-active {
1212
&.highlight-overlay {
1313
opacity: 0.99;
1414
transition: opacity 0.3s ease-in;
1515
}
1616
}
1717

18-
.highlight-transition-leave {
18+
.highlight-transition-enter-done,
19+
.highlight-transition-appear-done {
20+
&.highlight-overlay {
21+
opacity: 1;
22+
}
23+
}
24+
25+
.highlight-transition-exit {
1926
&.highlight-overlay {
2027
opacity: 0.99;
2128
}
2229
}
2330

24-
.highlight-transition-leave.highlight-transition-leave-active {
31+
.highlight-transition-exit-active {
2532
&.highlight-overlay {
2633
opacity: 0.01;
2734
transition: opacity 0.2s ease-in;
2835
}
2936
}
3037

38+
.highlight-transition-exit-done {
39+
&.highlight-overlay {
40+
opacity: 0;
41+
}
42+
}
43+
3144
/* @end Transition */
3245

3346
.highlight {

0 commit comments

Comments
 (0)