Skip to content

Commit 8e700ab

Browse files
authored
feat: Add visible status (#12)
* feat: Add visible status * chore: Use github action
1 parent 06f2be1 commit 8e700ab

File tree

5 files changed

+137
-31
lines changed

5 files changed

+137
-31
lines changed

.github/workflows/main.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
setup:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: checkout
14+
uses: actions/checkout@master
15+
16+
- uses: actions/setup-node@v1
17+
with:
18+
node-version: '12'
19+
20+
- name: cache package-lock.json
21+
uses: actions/cache@v2
22+
with:
23+
path: package-temp-dir
24+
key: lock-${{ github.sha }}
25+
26+
- name: create package-lock.json
27+
run: npm i --package-lock-only
28+
29+
- name: hack for singe file
30+
run: |
31+
if [ ! -d "package-temp-dir" ]; then
32+
mkdir package-temp-dir
33+
fi
34+
cp package-lock.json package-temp-dir
35+
- name: cache node_modules
36+
id: node_modules_cache_id
37+
uses: actions/cache@v2
38+
with:
39+
path: node_modules
40+
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
41+
42+
- name: install
43+
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
44+
run: npm ci
45+
46+
lint:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: checkout
50+
uses: actions/checkout@master
51+
52+
- name: restore cache from package-lock.json
53+
uses: actions/cache@v2
54+
with:
55+
path: package-temp-dir
56+
key: lock-${{ github.sha }}
57+
58+
- name: restore cache from node_modules
59+
uses: actions/cache@v2
60+
with:
61+
path: node_modules
62+
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
63+
64+
- name: lint
65+
run: npm run lint
66+
67+
needs: setup
68+
69+
compile:
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: checkout
73+
uses: actions/checkout@master
74+
75+
- name: restore cache from package-lock.json
76+
uses: actions/cache@v2
77+
with:
78+
path: package-temp-dir
79+
key: lock-${{ github.sha }}
80+
81+
- name: restore cache from node_modules
82+
uses: actions/cache@v2
83+
with:
84+
path: node_modules
85+
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
86+
87+
- name: compile
88+
run: npm run compile
89+
90+
needs: setup
91+
92+
coverage:
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: checkout
96+
uses: actions/checkout@master
97+
98+
- name: restore cache from package-lock.json
99+
uses: actions/cache@v2
100+
with:
101+
path: package-temp-dir
102+
key: lock-${{ github.sha }}
103+
104+
- name: restore cache from node_modules
105+
uses: actions/cache@v2
106+
with:
107+
path: node_modules
108+
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
109+
110+
- name: coverage
111+
run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash)
112+
113+
needs: setup

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# rc-motion
22

3-
[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![build status][travis-image]][travis-url] [![Codecov][codecov-image]][codecov-url] [![Dependencies][david-image]](david-url) [![DevDependencies][david-dev-image]][david-dev-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
3+
[![NPM version][npm-image]][npm-url]
4+
[![npm download][download-image]][download-url]
5+
[![build status][github-actions-image]][github-actions-url]
6+
[![Codecov][codecov-image]][codecov-url]
7+
[![Dependencies][david-image]](david-url)
8+
[![DevDependencies][david-dev-image]][david-dev-url]
9+
[![bundle size][bundlephobia-image]][bundlephobia-url]
410

511
[npm-image]: http://img.shields.io/npm/v/rc-motion.svg?style=flat-square
612
[npm-url]: http://npmjs.org/package/rc-motion
7-
[travis-image]: https://img.shields.io/travis/com/react-component/motion.svg?style=flat-square
8-
[travis-url]: https://travis-ci.com/react-component/motion
13+
[github-actions-image]: https://github.com/react-component/motion/workflows/CI/badge.svg
14+
[github-actions-url]: https://github.com/react-component/motion/actions
915
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/motion/master.svg?style=flat-square
1016
[codecov-url]: https://codecov.io/gh/react-component/motion/branch/master
1117
[david-url]: https://david-dm.org/react-component/motion

src/CSSMotion.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export interface CSSMotionProps {
8484

8585
children?: (
8686
props: {
87+
visible: boolean;
8788
className?: string;
8889
style?: React.CSSProperties;
8990
[key: string]: any;
@@ -167,22 +168,23 @@ export function genCSSMotion(
167168

168169
// ===================== Render =====================
169170
let motionChildren: React.ReactNode;
171+
const mergedProps = { ...eventProps, visible };
170172

171173
if (!children) {
172174
// No children
173175
motionChildren = null;
174176
} else if (status === STATUS_NONE || !isSupportTransition(props)) {
175177
// Stable children
176178
if (mergedVisible) {
177-
motionChildren = children({ ...eventProps }, setNodeRef);
179+
motionChildren = children({ ...mergedProps }, setNodeRef);
178180
} else if (!removeOnLeave) {
179181
motionChildren = children(
180-
{ ...eventProps, className: leavedClassName },
182+
{ ...mergedProps, className: leavedClassName },
181183
setNodeRef,
182184
);
183185
} else if (forceRender) {
184186
motionChildren = children(
185-
{ ...eventProps, style: { display: 'none' } },
187+
{ ...mergedProps, style: { display: 'none' } },
186188
setNodeRef,
187189
);
188190
} else {
@@ -201,7 +203,7 @@ export function genCSSMotion(
201203

202204
motionChildren = children(
203205
{
204-
...eventProps,
206+
...mergedProps,
205207
className: classNames(getTransitionName(motionName, status), {
206208
[getTransitionName(
207209
motionName,

tests/CSSMotion.spec.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,15 @@ describe('CSSMotion', () => {
8888
visible={this.state.visible}
8989
{...props}
9090
>
91-
{({ style, className }) => (
92-
<div
93-
style={style}
94-
className={classNames('motion-box', className)}
95-
/>
96-
)}
91+
{({ style, className, visible: motionVisible }) => {
92+
expect(motionVisible).toEqual(this.state.visible);
93+
return (
94+
<div
95+
style={style}
96+
className={classNames('motion-box', className)}
97+
/>
98+
);
99+
}}
97100
</CSSMotion>
98101
);
99102
}

0 commit comments

Comments
 (0)