This repository was archived by the owner on Dec 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +110
-18
lines changed Expand file tree Collapse file tree 10 files changed +110
-18
lines changed Original file line number Diff line number Diff line change 10
10
[lints]
11
11
12
12
[options]
13
+ suppress_comment=\\(.\\|\n\\)*\\$FlowExpectError
13
14
14
15
[strict]
Original file line number Diff line number Diff line change @@ -244,6 +244,13 @@ const Example = () => (
244
244
);
245
245
` ` `
246
246
247
+ ## Flow and TypeScript types
248
+
249
+ This library is built with Flow but it supports TypeScript as well.
250
+
251
+ You can find the exported Flow types in ` src/ index .js ` , and the
252
+ TypeScript definitions in ` typings/ react- popper .d .ts ` .
253
+
247
254
## Running Locally
248
255
249
256
#### clone repo
Original file line number Diff line number Diff line change 18
18
"build:clean" : " rimraf dist/ && rimraf lib/" ,
19
19
"build:es" : " cross-env BABEL_ENV=es babel src --ignore '*.test.js,__mocks__' --out-dir lib/es" ,
20
20
"build:cjs" : " cross-env BABEL_ENV=cjs babel src --ignore '*.test.js,__mocks__' --out-dir lib/cjs" ,
21
- "build:flow" : " flow-copy-source --ignore '{__mocks__/*,*.test}.js' src lib/es " ,
21
+ "build:flow" : " flow-copy-source --ignore '{__mocks__/*,*.test}.js' src lib/cjs " ,
22
22
"demo:dev" : " parcel --out-dir demo/dist demo/index.html" ,
23
23
"demo:build" : " parcel build --out-dir demo/dist demo/index.html --public-url=/react-popper" ,
24
24
"demo:deploy" : " yarn demo:build && gh-pages -d demo/dist" ,
62
62
"create-react-context" : " ^0.2.1" ,
63
63
"popper.js" : " ^1.14.1" ,
64
64
"prop-types" : " ^15.6.1" ,
65
+ "typed-styles" : " ^0.0.5" ,
65
66
"warning" : " ^3.0.0"
66
67
},
67
68
"devDependencies" : {
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export const ManagerContext: Context<{
7
7
referenceNode ?: ?HTMLElement ,
8
8
} > = createContext ( { getReferenceRef : undefined , referenceNode : undefined } ) ;
9
9
10
- type ManagerProps = {
10
+ export type ManagerProps = {
11
11
children : Node ,
12
12
} ;
13
13
type ManagerState = {
Original file line number Diff line number Diff line change @@ -7,33 +7,36 @@ import PopperJS, {
7
7
type Modifiers ,
8
8
type ReferenceObject ,
9
9
} from 'popper.js' ;
10
+ import type { Style } from 'typed-styles' ;
10
11
import { ManagerContext } from './Manager' ;
11
12
import { unwrapArray } from './utils' ;
12
13
13
14
type getRefFn = ( ?HTMLElement ) => void ;
14
- type Style = Object ;
15
-
16
15
type ReferenceElement = ReferenceObject | HTMLElement | null ;
16
+ type StyleOffsets = { top : number , left : number } ;
17
+ type StylePosition = { position : 'absolute' | 'fixed' } ;
17
18
18
- type RenderProp = ( { |
19
+ export type PopperArrowProps = {
20
+ ref : getRefFn ,
21
+ style : StyleOffsets & Style ,
22
+ } ;
23
+ export type PopperChildrenProps = { |
19
24
ref : getRefFn ,
20
- style : Style ,
21
- placement : ? Placement ,
25
+ style : StyleOffsets & StylePosition & Style ,
26
+ placement : Placement ,
22
27
outOfBoundaries : ?boolean ,
23
28
scheduleUpdate : ( ) => void ,
24
- arrowProps : {
25
- ref : getRefFn ,
26
- style : Style ,
27
- } ,
28
- | } ) => Node ;
29
+ arrowProps : PopperArrowProps ,
30
+ | } ;
31
+ export type PopperChildren = PopperChildrenProps => Node ;
29
32
30
- type PopperProps = {
33
+ export type PopperProps = {
31
34
modifiers ?: Modifiers ,
32
35
placement ?: Placement ,
33
36
eventsEnabled ?: boolean ,
34
37
positionFixed ?: boolean ,
35
38
referenceElement ?: ReferenceElement ,
36
- children : RenderProp ,
39
+ children : PopperChildren ,
37
40
} ;
38
41
39
42
type PopperState = {
Original file line number Diff line number Diff line change @@ -4,8 +4,9 @@ import warning from 'warning';
4
4
import { ManagerContext } from './Manager' ;
5
5
import { unwrapArray } from './utils' ;
6
6
7
- type ReferenceProps = {
8
- children : ( { ref : ( ?HTMLElement ) => void } ) => Node ,
7
+ export type ReferenceChildrenProps = { ref : ( ?HTMLElement ) => void } ;
8
+ export type ReferenceProps = {
9
+ children : ReferenceChildrenProps => Node ,
9
10
} ;
10
11
11
12
export default function Reference ( { children } : ReferenceProps ) {
Original file line number Diff line number Diff line change
1
+ // @flow
2
+
3
+ // Please remember to update also the TypeScript test files that can
4
+ // be found under `/typings/tests` please. Thanks! 🤗
5
+
6
+ import React from 'react' ;
7
+ import { Manager , Reference , Popper } from '..' ;
8
+
9
+ export const Test = ( ) => (
10
+ < Manager >
11
+ { /* $FlowExpectError: empty children */ }
12
+ < Reference />
13
+ < Reference > { ( { ref } ) => < div ref = { ref } /> } </ Reference >
14
+ < Popper
15
+ // $FlowExpectError: should be boolean
16
+ eventsEnabled = "foo"
17
+ eventsEnabled
18
+ // $FlowExpectError: should be boolean
19
+ positionFixed = { 2 }
20
+ positionFixed
21
+ // $FlowExpectError: enabled should be boolean, order number
22
+ modifiers = { { flip : { enabled : 'bar' , order : 'foo' } } }
23
+ modifiers = { { flip : { enabled : false } } }
24
+ >
25
+ { ( {
26
+ ref,
27
+ style,
28
+ placement,
29
+ outOfBoundaries,
30
+ scheduleUpdate,
31
+ arrowProps,
32
+ } ) => (
33
+ < div
34
+ ref = { ref }
35
+ style = { { ...style , opacity : outOfBoundaries ? 0 : 1 } }
36
+ data-placement = { placement }
37
+ onClick = { ( ) => scheduleUpdate ( ) }
38
+ >
39
+ Popper
40
+ < div ref = { arrowProps . ref } style = { arrowProps . style } />
41
+ </ div >
42
+ ) }
43
+ </ Popper >
44
+ < Popper >
45
+ { ( { ref, style, placement } ) => (
46
+ < div ref = { ref } style = { style } data-placement = { placement } >
47
+ Popper
48
+ </ div >
49
+ ) }
50
+ </ Popper >
51
+ </ Manager >
52
+ ) ;
Original file line number Diff line number Diff line change 1
1
// @flow
2
+
3
+ // Public components
2
4
import Popper , { placements } from './Popper' ;
3
5
import Manager from './Manager' ;
4
6
import Reference from './Reference' ;
5
-
6
7
export { Popper , placements , Manager , Reference } ;
8
+
9
+ // Public types
10
+ import type { Placement } from 'popper.js' ;
11
+ import type { ManagerProps } from './Manager' ;
12
+ import type { ReferenceProps , ReferenceChildrenProps } from './Reference' ;
13
+ import type {
14
+ PopperChildrenProps ,
15
+ PopperArrowProps ,
16
+ PopperProps ,
17
+ } from './Popper' ;
18
+ export type {
19
+ Placement ,
20
+ ManagerProps ,
21
+ ReferenceProps ,
22
+ ReferenceChildrenProps ,
23
+ PopperChildrenProps ,
24
+ PopperArrowProps ,
25
+ PopperProps ,
26
+ } ;
Original file line number Diff line number Diff line change
1
+ // Please remember to update also the Flow test files that can
2
+ // be found under `/src/__typings__` please. Thanks! 🤗
3
+
1
4
import * as React from 'react' ;
2
5
import { Manager , Reference , Popper } from '../..' ;
3
6
4
- const Test = ( ) => (
7
+ export const Test = ( ) => (
5
8
< Manager >
6
9
< Reference > { ( { ref } ) => < div ref = { ref } /> } </ Reference >
7
10
< Popper
Original file line number Diff line number Diff line change @@ -6327,6 +6327,10 @@ type-check@~0.3.2:
6327
6327
dependencies :
6328
6328
prelude-ls "~1.1.2"
6329
6329
6330
+ typed-styles@^0.0.5 :
6331
+ version "0.0.5"
6332
+ resolved "https://registry.yarnpkg.com/typed-styles/-/typed-styles-0.0.5.tgz#a60df245d482a9b1adf9c06c078d0f06085ed1cf"
6333
+
6330
6334
typedarray@^0.0.6 :
6331
6335
version "0.0.6"
6332
6336
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
You can’t perform that action at this time.
0 commit comments