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 1010[lints]
1111
1212[options]
13+ suppress_comment=\\(.\\|\n\\)*\\$FlowExpectError
1314
1415[strict]
Original file line number Diff line number Diff line change @@ -244,6 +244,13 @@ const Example = () => (
244244);
245245` ` `
246246
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+
247254## Running Locally
248255
249256#### clone repo
Original file line number Diff line number Diff line change 1818 "build:clean" : " rimraf dist/ && rimraf lib/" ,
1919 "build:es" : " cross-env BABEL_ENV=es babel src --ignore '*.test.js,__mocks__' --out-dir lib/es" ,
2020 "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 " ,
2222 "demo:dev" : " parcel --out-dir demo/dist demo/index.html" ,
2323 "demo:build" : " parcel build --out-dir demo/dist demo/index.html --public-url=/react-popper" ,
2424 "demo:deploy" : " yarn demo:build && gh-pages -d demo/dist" ,
6262 "create-react-context" : " ^0.2.1" ,
6363 "popper.js" : " ^1.14.1" ,
6464 "prop-types" : " ^15.6.1" ,
65+ "typed-styles" : " ^0.0.5" ,
6566 "warning" : " ^3.0.0"
6667 },
6768 "devDependencies" : {
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export const ManagerContext: Context<{
77 referenceNode ?: ?HTMLElement ,
88} > = createContext ( { getReferenceRef : undefined , referenceNode : undefined } ) ;
99
10- type ManagerProps = {
10+ export type ManagerProps = {
1111 children : Node ,
1212} ;
1313type ManagerState = {
Original file line number Diff line number Diff line change @@ -7,33 +7,36 @@ import PopperJS, {
77 type Modifiers ,
88 type ReferenceObject ,
99} from 'popper.js' ;
10+ import type { Style } from 'typed-styles' ;
1011import { ManagerContext } from './Manager' ;
1112import { unwrapArray } from './utils' ;
1213
1314type getRefFn = ( ?HTMLElement ) => void ;
14- type Style = Object ;
15-
1615type ReferenceElement = ReferenceObject | HTMLElement | null ;
16+ type StyleOffsets = { top : number , left : number } ;
17+ type StylePosition = { position : 'absolute' | 'fixed' } ;
1718
18- type RenderProp = ( { |
19+ export type PopperArrowProps = {
20+ ref : getRefFn ,
21+ style : StyleOffsets & Style ,
22+ } ;
23+ export type PopperChildrenProps = { |
1924 ref : getRefFn ,
20- style : Style ,
21- placement : ? Placement ,
25+ style : StyleOffsets & StylePosition & Style ,
26+ placement : Placement ,
2227 outOfBoundaries : ?boolean ,
2328 scheduleUpdate : ( ) => void ,
24- arrowProps : {
25- ref : getRefFn ,
26- style : Style ,
27- } ,
28- | } ) => Node ;
29+ arrowProps : PopperArrowProps ,
30+ | } ;
31+ export type PopperChildren = PopperChildrenProps => Node ;
2932
30- type PopperProps = {
33+ export type PopperProps = {
3134 modifiers ?: Modifiers ,
3235 placement ?: Placement ,
3336 eventsEnabled ?: boolean ,
3437 positionFixed ?: boolean ,
3538 referenceElement ?: ReferenceElement ,
36- children : RenderProp ,
39+ children : PopperChildren ,
3740} ;
3841
3942type PopperState = {
Original file line number Diff line number Diff line change @@ -4,8 +4,9 @@ import warning from 'warning';
44import { ManagerContext } from './Manager' ;
55import { unwrapArray } from './utils' ;
66
7- type ReferenceProps = {
8- children : ( { ref : ( ?HTMLElement ) => void } ) => Node ,
7+ export type ReferenceChildrenProps = { ref : ( ?HTMLElement ) => void } ;
8+ export type ReferenceProps = {
9+ children : ReferenceChildrenProps => Node ,
910} ;
1011
1112export 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 11// @flow
2+
3+ // Public components
24import Popper , { placements } from './Popper' ;
35import Manager from './Manager' ;
46import Reference from './Reference' ;
5-
67export { 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+
14import * as React from 'react' ;
25import { Manager , Reference , Popper } from '../..' ;
36
4- const Test = ( ) => (
7+ export const Test = ( ) => (
58 < Manager >
69 < Reference > { ( { ref } ) => < div ref = { ref } /> } </ Reference >
710 < Popper
Original file line number Diff line number Diff line change @@ -6327,6 +6327,10 @@ type-check@~0.3.2:
63276327 dependencies :
63286328 prelude-ls "~1.1.2"
63296329
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+
63306334typedarray@^0.0.6 :
63316335 version "0.0.6"
63326336 resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
You can’t perform that action at this time.
0 commit comments