Skip to content

Commit d8e8ff0

Browse files
committed
fix: stop using typescript in renderprops API
Babel has a bug where a destructured object does not produce the expected variables, causing a reference error at runtime. More info: #923
1 parent e6622be commit d8e8ff0

File tree

10 files changed

+99
-80
lines changed

10 files changed

+99
-80
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { useSpring } from '../hooks'
2+
3+
export function Spring({ children, ...props }) {
4+
return children(useSpring(props))
5+
}

packages/core/src/components/Spring.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
import { is } from 'shared'
3+
import { useTrail } from '../hooks'
4+
5+
export function Trail({ items, children, ...props }) {
6+
const trails = useTrail(items.length, props)
7+
return (
8+
<>
9+
{items.map((item, index) => {
10+
const result = children(item, index)
11+
return is.fun(result) ? result(trails[index]) : result
12+
})}
13+
</>
14+
)
15+
}

packages/core/src/components/Trail.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react'
2+
import { useTransition } from '../hooks'
3+
4+
export function Transition({ items, children, ...props }) {
5+
return <>{useTransition(items, props)(children)}</>
6+
}

packages/core/src/components/Transition.tsx

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { ReactNode } from 'react'
2+
import { NoInfer, Falsy, UnknownProps } from 'shared'
3+
import { Valid } from '../types/common'
4+
import {
5+
PickAnimated,
6+
SpringValues,
7+
SpringToFn,
8+
SpringChain,
9+
TransitionComponentProps,
10+
} from '../types'
11+
import { UseSpringProps } from '../hooks/useSpring'
12+
13+
//
14+
// <Spring>
15+
//
16+
17+
export type SpringComponentProps<
18+
State extends object = UnknownProps
19+
> = unknown &
20+
UseSpringProps<State> & {
21+
children: (values: SpringValues<State>) => JSX.Element | null
22+
}
23+
24+
// This overload infers `State` using the `from` object prop.
25+
export function Spring<State extends object>(
26+
props: {
27+
from: State
28+
to?: SpringChain<NoInfer<State>> | SpringToFn<NoInfer<State>>
29+
} & Omit<SpringComponentProps<NoInfer<State>>, 'from' | 'to'>
30+
): JSX.Element | null
31+
32+
// This overload infers `State` using the `to` object prop.
33+
export function Spring<State extends object>(
34+
props: { to: State } & Omit<SpringComponentProps<NoInfer<State>>, 'to'>
35+
): JSX.Element | null
36+
37+
//
38+
// <Transition>
39+
//
40+
41+
export function Transition<
42+
Item extends any,
43+
Props extends TransitionComponentProps<Item>
44+
>({
45+
items,
46+
children,
47+
...props
48+
}:
49+
| TransitionComponentProps<Item>
50+
| (Props & Valid<Props, TransitionComponentProps<Item, Props>>)): JSX.Element
51+
52+
export type TrailComponentProps<Item, Props extends object = any> = unknown &
53+
UseSpringProps<Props> & {
54+
items: readonly Item[]
55+
children: (
56+
item: NoInfer<Item>,
57+
index: number
58+
) => ((values: SpringValues<PickAnimated<Props>>) => ReactNode) | Falsy
59+
}
60+
61+
//
62+
// <Trail>
63+
//
64+
65+
export function Trail<Item, Props extends TrailComponentProps<Item>>({
66+
items,
67+
children,
68+
...props
69+
}: Props & Valid<Props, TrailComponentProps<Item, Props>>): JSX.Element

packages/core/src/components/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { Spring } from './Spring'
2+
export { Trail } from './Trail'
3+
export { Transition } from './Transition'

packages/core/src/components/index.ts

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

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { terser } from 'rollup-plugin-terser'
99

1010
const root = process.platform === 'win32' ? path.resolve('/') : '/'
1111
const external = id => !id.startsWith('.') && !id.startsWith(root)
12-
const extensions = ['.tsx', '.ts', '.js']
12+
const extensions = ['.tsx', '.ts', '.js', '.jsx']
1313
const packages = readPackages()
1414
const packageNames = Object.keys(packages)
1515

0 commit comments

Comments
 (0)