Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 4754c50

Browse files
sgrishchenkosgrishchenko
andauthored
feat: migration to popper v2 (#333)
Co-authored-by: sgrishchenko <[email protected]>
1 parent 4ddde9d commit 4754c50

File tree

19 files changed

+1887
-1174
lines changed

19 files changed

+1887
-1174
lines changed

.flowconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
[ignore]
2-
.*/node_modules/config-chain/.*
32
/lib/.*
43
.*/.cache
54

65
[include]
76

87
[libs]
9-
node_modules/popper.js/index.js.flow
108

119
[lints]
1210

1311
[options]
1412
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectError
1513

1614
[strict]
15+
16+
[declarations]
17+
<PROJECT_ROOT>/node_modules

.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
22
"dist/index.umd.js": {
3-
"bundled": 88323,
4-
"minified": 32847,
5-
"gzipped": 9575
3+
"bundled": 84846,
4+
"minified": 30911,
5+
"gzipped": 9420
66
},
77
"dist/index.umd.min.js": {
8-
"bundled": 52955,
9-
"minified": 21926,
10-
"gzipped": 6619
8+
"bundled": 49580,
9+
"minified": 20040,
10+
"gzipped": 6478
1111
},
1212
"dist/index.esm.js": {
13-
"bundled": 12824,
14-
"minified": 7630,
15-
"gzipped": 2103,
13+
"bundled": 13500,
14+
"minified": 7562,
15+
"gzipped": 2164,
1616
"treeshaked": {
1717
"rollup": {
18-
"code": 3829,
19-
"import_statements": 163
18+
"code": 3816,
19+
"import_statements": 184
2020
},
2121
"webpack": {
22-
"code": 4978
22+
"code": 4957
2323
}
2424
}
2525
}

demo/index.js

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,68 @@ const enhance = compose(
4747
withState('isPopper2Open', 'togglePopper2', false)
4848
);
4949

50-
const modifiers = {
51-
flip: { enabled: false },
52-
preventOverflow: { enabled: false },
53-
hide: { enabled: false },
54-
};
50+
const modifiers = [
51+
{
52+
name: 'flip',
53+
enabled: false,
54+
},
55+
{
56+
name: 'hide',
57+
enabled: false,
58+
},
59+
];
5560

56-
const animatedModifiers = {
61+
const popperModifiers = [
5762
...modifiers,
63+
{
64+
name: 'arrow',
65+
options: {
66+
padding: 5,
67+
},
68+
},
69+
{
70+
name: 'offset',
71+
options: {
72+
offset: [0, 14],
73+
},
74+
},
75+
];
76+
77+
const dotModifiers = [
78+
...modifiers,
79+
{
80+
name: 'offset',
81+
options: {
82+
offset: [0, 56],
83+
},
84+
}
85+
];
86+
87+
const mainModifiers = [
88+
...popperModifiers,
89+
// We can't use adaptive styles with CSS transitions
90+
{
91+
name: 'computeStyles',
92+
options: {
93+
adaptive: false,
94+
}
95+
},
96+
];
97+
98+
const animatedModifiers = [
99+
...popperModifiers,
58100
// We disable the built-in gpuAcceleration so that
59101
// Popper.js will return us easy to interpolate values
60102
// (top, left instead of transform: translate3d)
61103
// We'll then use these values to generate the needed
62-
// css tranform values blended with the react-spring values
63-
computeStyle: { gpuAcceleration: false },
64-
}
104+
// css transform values blended with the react-spring values
105+
{
106+
name: 'computeStyles',
107+
options: {
108+
gpuAcceleration: false,
109+
}
110+
},
111+
];
65112

66113
const Demo = enhance(
67114
({ activePlacement, setActivePlacement, isPopper2Open, togglePopper2 }) => (
@@ -81,7 +128,7 @@ const Demo = enhance(
81128
)}
82129
</Reference>
83130
<PoppersContainer>
84-
<Popper placement={activePlacement} modifiers={modifiers}>
131+
<Popper placement={activePlacement} modifiers={mainModifiers}>
85132
{({ ref, style, placement, arrowProps }) => (
86133
<TransitionedPopperBox innerRef={ref} style={style}>
87134
{placement}
@@ -94,7 +141,7 @@ const Demo = enhance(
94141
)}
95142
</Popper>
96143
{placements.filter(p => p !== activePlacement).map(p => (
97-
<Popper placement={p} key={p} modifiers={modifiers}>
144+
<Popper placement={p} key={p} modifiers={dotModifiers}>
98145
{({ ref, style }) => (
99146
<PopperDot
100147
innerRef={ref}
@@ -148,7 +195,7 @@ const Demo = enhance(
148195
position,
149196
padding: '1em',
150197
width: '10em',
151-
transform: `translate3d(${left}px, ${top +
198+
transform: `translate3d(${left}, ${parseInt(top) +
152199
topOffset}px, 0) scale(${scale}) rotate(${rotation})`,
153200
transformOrigin: 'top center',
154201
}}

demo/styles.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export const PopperBox = styled('div')`
6060
background-color: #232323;
6161
color: #ffffff;
6262
border-radius: 10px;
63-
margin: 0.9em;
6463
padding: 0.5em;
6564
text-align: center;
6665
${props => props.popperStyle};
@@ -93,7 +92,6 @@ export const PopperDot = styled('button')`
9392
height: 1em;
9493
border-radius: 50%;
9594
background-color: #232323;
96-
margin: 3.5em;
9795
animation: ${pulse} 2s ease infinite;
9896
`;
9997

jest.setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @flow
2+
import '@babel/polyfill';
23
import Enzyme from 'enzyme';
34
import EnzymeAdapter from 'enzyme-adapter-react-16';
45

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
"/typings/react-popper.d.ts"
1616
],
1717
"scripts": {
18-
"build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:flow",
18+
"build": "yarn build:clean && yarn build:esm && yarn build:cjs && yarn build:umd && yarn build:flow",
1919
"build:clean": "rimraf dist/ && rimraf lib/",
2020
"build:umd": "rollup -c && rimraf dist/index.esm.js",
2121
"build:esm": "cross-env BABEL_ENV=esm babel src --out-dir lib/esm",
2222
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir lib/cjs",
23-
"build:flow": "flow-copy-source --ignore '{__mocks__/*,*.test}.js' src lib/cjs",
23+
"build:flow": "flow-copy-source --ignore '{__typings__/*,*.test}.js' src lib/cjs",
2424
"demo:dev": "parcel --out-dir demo/dist demo/index.html",
2525
"demo:build": "parcel build --out-dir demo/dist demo/index.html --public-url=/react-popper",
2626
"demo:deploy": "yarn demo:build && gh-pages -d demo/dist",
27-
"test": "npm run test:eslint && npm run test:flow && npm run test:ts && npm run test:jest",
27+
"test": "yarn test:eslint && yarn test:flow && yarn test:ts && yarn test:jest",
2828
"test:ts": "tsc --project ./typings/tests",
2929
"test:flow": "flow check",
3030
"test:jest": "jest",
3131
"test:eslint": "eslint src",
32-
"prepare": "npm run build",
32+
"prepare": "yarn build",
3333
"precommit": "pretty-quick --staged && test",
3434
"prepublishOnly": "git-branch-is master"
3535
},
@@ -58,15 +58,14 @@
5858
"popover"
5959
],
6060
"peerDependencies": {
61+
"@popperjs/core": "^2.0.0",
6162
"react": "0.14.x || ^15.0.0 || ^16.0.0"
6263
},
6364
"dependencies": {
6465
"@babel/runtime": "^7.1.2",
6566
"create-react-context": "^0.3.0",
6667
"deep-equal": "^1.1.1",
67-
"popper.js": "^1.14.4",
6868
"prop-types": "^15.6.1",
69-
"typed-styles": "^0.0.7",
7069
"warning": "^4.0.2"
7170
},
7271
"devDependencies": {
@@ -76,10 +75,12 @@
7675
"@babel/plugin-proposal-class-properties": "^7.1.0",
7776
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
7877
"@babel/plugin-transform-runtime": "^7.1.0",
78+
"@babel/polyfill": "^7.8.3",
7979
"@babel/preset-env": "^7.1.0",
8080
"@babel/preset-flow": "^7.0.0",
8181
"@babel/preset-react": "^7.0.0",
8282
"@babel/preset-stage-2": "^7.0.0",
83+
"@popperjs/core": "^2.0.4",
8384
"@types/react": "^16.1.0",
8485
"babel-eslint": "^10.0.1",
8586
"babel-jest": "^24.0.0",
@@ -94,8 +95,8 @@
9495
"eslint-plugin-jest": "^21.15.0",
9596
"eslint-plugin-promise": "^3.7.0",
9697
"eslint-plugin-react": "^7.7.0",
97-
"flow-bin": "^0.69.0",
98-
"flow-copy-source": "^1.3.0",
98+
"flow-bin": "^0.117.0",
99+
"flow-copy-source": "^2.0.9",
99100
"gh-pages": "^1.1.0",
100101
"git-branch-is": "^0.1.0",
101102
"jest": "^24.0.0",
@@ -115,6 +116,6 @@
115116
"rollup-plugin-replace": "^2.0.0",
116117
"rollup-plugin-size-snapshot": "^0.5.1",
117118
"rollup-plugin-uglify": "^4.0.0",
118-
"typescript": "^2.8.1"
119+
"typescript": "^3.7.5"
119120
}
120121
}

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const input = './src/index.js';
99

1010
const umdGlobals = {
1111
react: 'React',
12-
'popper.js': 'Popper',
12+
'@popperjs/core': 'Popper',
1313
};
1414

1515
const getBabelOptions = () => ({

0 commit comments

Comments
 (0)