Skip to content

Commit a939554

Browse files
chore: upgrade to latest substyle (#52)
* chore: upgrade to latest substyle BREAKING CHANGE: requires upgrade to latest versions of substyle-jss/substyle-glamor if these are used * upgrade to latest substyle * fix width handling * chore: upgrade to latest substyle version * chore: clear out unused recompose dep * chore: fix test to enforce line break closes #62 * chore: get rid of lodash dep * chore: fix flow typings * some smaller changes Co-authored-by: Philipp Giese <[email protected]>
1 parent 301c2e9 commit a939554

File tree

16 files changed

+178
-289
lines changed

16 files changed

+178
-289
lines changed

babel.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ module.exports = {
1717
plugins: [
1818
'@babel/transform-runtime',
1919
'@babel/plugin-proposal-object-rest-spread',
20-
21-
'lodash',
2220
],
2321
}

demo/src/PositionAlignOverview.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { compact } from 'lodash'
21
import React, { useCallback, useRef, useState } from 'react'
32

43
import Stick from '../../es'
54
import { useWatcher } from './hooks'
65

76
const formPairs = (listA: Array<string>, listB: Array<string>) =>
8-
compact(
9-
listA.map((a: string) =>
7+
listA
8+
.map((a: string) =>
109
listB.map((b: string) => {
1110
if (a === b) {
1211
return null
@@ -15,7 +14,7 @@ const formPairs = (listA: Array<string>, listB: Array<string>) =>
1514
return `${a} ${b}`
1615
})
1716
)
18-
)
17+
.filter((pair) => pair !== null)
1918

2019
const verticals = ['top', 'middle', 'bottom']
2120
const horizontals = ['left', 'center', 'right']

demo/src/regressions/FitOnPage.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { times } from 'lodash'
21
import React from 'react'
32

43
import Stick from '../../../es'
@@ -25,7 +24,7 @@ const node = (
2524
minHeight: 18,
2625
}}
2726
>
28-
{times(1, () => 'Lorem ipsum dolor sit amet.').join(' ')}
27+
{Array(10).fill('Lorem ipsum dolor sit amet.').join(' ')}
2928
</div>
3029
)
3130

demo/src/regressions/StickNodeWidth.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ const Examples = ({ inline }) => (
5656
position="middle right"
5757
node={
5858
<Node>
59-
This text must line-break as it would reach off-screen otherwise
59+
This text must line-break as it would reach off-screen otherwise.
60+
After we've increased page width, this text needed to be extended a
61+
bit.
6062
</Node>
6163
}
6264
>

demo/src/regressions/StickOnHover.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { range } from 'lodash'
21
import React, { useState } from 'react'
32

43
import Stick from '../../../es'
@@ -14,11 +13,13 @@ function StickOnHover() {
1413
description="Move your mouse over the squares. When you're hovering one another node should be shown. However, there should always only be one node at the same time."
1514
>
1615
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
17-
{range(100).map(i => (
18-
<div key={i} style={{ marginLeft: 20, marginBottom: 20 }}>
19-
<Popover />
20-
</div>
21-
))}
16+
{Array(100)
17+
.fill(null)
18+
.map((_, i) => (
19+
<div key={i} style={{ marginLeft: 20, marginBottom: 20 }}>
20+
<Popover />
21+
</div>
22+
))}
2223
</div>
2324
</Regression>
2425
)
@@ -44,7 +45,7 @@ const Anchor = () => (
4445
style={{
4546
height: 30,
4647
width: 30,
47-
backgroundColor: 'rgb(24, 170, 177)'
48+
backgroundColor: 'rgb(24, 170, 177)',
4849
}}
4950
/>
5051
)
@@ -54,7 +55,7 @@ const Node = ({ children }) => (
5455
style={{
5556
backgroundColor: '#ae0d5c',
5657
width: 10,
57-
height: 10
58+
height: 10,
5859
}}
5960
>
6061
{children}

nwb.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = {
22
type: 'react-component',
33
babel: {
4-
cherryPick: 'lodash',
54
env: {
65
targets: {
76
browsers: ['chrome >= 50', 'firefox >= 52', 'safari >= 10', 'ie >= 11'],

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
},
2828
"dependencies": {
2929
"invariant": "^2.2.4",
30-
"lodash": "^4.17.4",
31-
"recompose": "0.30.0",
3230
"requestidlecallback": "^0.3.0",
33-
"substyle": "^7.1.3"
31+
"substyle": "^9.1.0"
3432
},
3533
"devDependencies": {
3634
"@babel/core": "7.9.6",
@@ -63,7 +61,7 @@
6361
"react-dom": "16.13.1",
6462
"regenerator-runtime": "0.13.5",
6563
"semantic-release": "17.0.7",
66-
"substyle-glamor": "4.0.0",
64+
"substyle-glamor": "4.0.1",
6765
"webpack": "4.43.0",
6866
"webpack-cli": "3.3.11",
6967
"webpack-dev-server": "3.10.3"

src/Stick.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,35 @@
22
import 'requestidlecallback'
33

44
import invariant from 'invariant'
5-
import { some } from 'lodash'
65
import React, {
76
useCallback,
87
useContext,
98
useEffect,
109
useRef,
1110
useState,
1211
} from 'react'
13-
import { type HOC } from 'recompose'
14-
import { type Substyle, defaultStyle } from 'substyle'
12+
import useStyles from 'substyle'
1513

1614
import { StickContext } from './StickContext'
1715
import StickInline from './StickInline'
1816
import StickNode from './StickNode'
1917
import StickPortal from './StickPortal'
2018
import DEFAULT_POSITION from './defaultPosition'
21-
import { type AlignT, type ApiPropsT, type PositionT } from './flowTypes'
19+
import { type AlignT, type PositionT, type StickPropsT } from './flowTypes'
2220
import { useAutoFlip, useWatcher } from './hooks'
2321
import { getDefaultAlign, getModifiers, scrollX, uniqueId } from './utils'
2422

25-
type PropsT = {|
26-
...ApiPropsT,
27-
28-
style: Substyle,
29-
|}
23+
const defaultStyles = {
24+
node: {
25+
position: 'absolute',
26+
zIndex: 99,
27+
textAlign: 'left',
28+
},
29+
}
3030

3131
function Stick({
3232
inline,
3333
node,
34-
style,
3534
sameWidth,
3635
children,
3736
updateOnAnimationFrame,
@@ -42,8 +41,11 @@ function Stick({
4241
autoFlipHorizontally,
4342
autoFlipVertically,
4443
onClickOutside,
44+
style,
45+
className,
46+
classNames,
4547
...rest
46-
}: PropsT) {
48+
}: StickPropsT) {
4749
const [width, setWidth] = useState(0)
4850
const [containerNestingKeyExtension] = useState(() => uniqueId())
4951
const nestingKey = [useContext(StickContext), containerNestingKeyExtension]
@@ -61,6 +63,16 @@ function Stick({
6163
align || getDefaultAlign(position || DEFAULT_POSITION)
6264
)
6365

66+
const styles = useStyles(
67+
defaultStyles,
68+
{ style, className, classNames },
69+
getModifiers({
70+
position: resolvedPosition,
71+
align: resolvedAlign,
72+
sameWidth,
73+
})
74+
)
75+
6476
useEffect(() => {
6577
const handleScroll = () => {
6678
if (!nodeRef.current || !anchorRef.current) {
@@ -122,10 +134,6 @@ function Stick({
122134

123135
useWatcher(measure, { updateOnAnimationFrame: !!updateOnAnimationFrame })
124136

125-
const resolvedStyle = style(
126-
getModifiers({ position: resolvedPosition, align: resolvedAlign })
127-
)
128-
129137
const handleReposition = useCallback(() => {
130138
if (nodeRef.current && anchorRef.current) {
131139
checkAlignment(nodeRef.current, anchorRef.current)
@@ -139,7 +147,7 @@ function Stick({
139147
{...rest}
140148
position={resolvedPosition}
141149
align={resolvedAlign}
142-
style={resolvedStyle}
150+
style={styles}
143151
node={
144152
node && (
145153
<StickNode
@@ -195,7 +203,7 @@ function Stick({
195203
</StickNode>
196204
)
197205
}
198-
style={resolvedStyle}
206+
style={styles}
199207
nestingKey={nestingKey}
200208
containerRef={containerRef}
201209
onReposition={handleReposition}
@@ -221,7 +229,13 @@ function isOutside(anchorRef, containerRef, target: HTMLElement) {
221229
const nestedStickNodes = document.querySelectorAll(
222230
`[data-stickNestingKey^='${nestingKey}']`
223231
)
224-
return !some(nestedStickNodes, (stickNode) => stickNode.contains(target))
232+
233+
return (
234+
!nestedStickNodes ||
235+
!Array.from(nestedStickNodes).some((stickNode) =>
236+
stickNode.contains(target)
237+
)
238+
)
225239
}
226240

227241
return true
@@ -273,15 +287,4 @@ function calculateWidth(
273287
return 0
274288
}
275289

276-
const styled: HOC<*, ApiPropsT> = defaultStyle(
277-
{
278-
node: {
279-
position: 'absolute',
280-
zIndex: 99,
281-
textAlign: 'left',
282-
},
283-
},
284-
getModifiers
285-
)
286-
287-
export default styled(Stick)
290+
export default Stick

src/StickInline.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,80 @@
11
// @flow
22
import React from 'react'
3-
import { type HOC } from 'recompose'
4-
import { defaultStyle } from 'substyle'
3+
import useStyles from 'substyle'
54

65
import { type StickInlinePropsT } from './flowTypes'
76
import { getModifiers } from './utils'
87

98
function StickInline({
109
node,
1110
children,
12-
style,
1311
component,
1412
containerRef,
1513
nestingKey,
1614
align,
1715
position,
16+
style,
1817
...rest
1918
}: StickInlinePropsT) {
19+
const styles = useStyles(
20+
defaultStyle,
21+
{ style },
22+
getModifiers({ align, position })
23+
)
2024
const Component = component || 'div'
2125
return (
2226
<Component
23-
{...style}
2427
{...rest}
28+
{...styles}
2529
ref={containerRef}
2630
data-sticknestingkey={nestingKey}
2731
>
2832
{children}
29-
{node && <div {...style('node')}>{node}</div>}
33+
{node && <div {...styles('node')}>{node}</div>}
3034
</Component>
3135
)
3236
}
3337

34-
const styled: HOC<*, StickInlinePropsT> = defaultStyle(
35-
{
36-
position: 'relative',
38+
const defaultStyle = {
39+
position: 'relative',
3740

38-
node: {
39-
position: 'absolute',
40-
zIndex: 99,
41-
textAlign: 'left',
42-
},
41+
node: {
42+
position: 'absolute',
43+
zIndex: 99,
44+
textAlign: 'left',
45+
},
4346

44-
'&position-top': {
45-
node: {
46-
top: 0,
47-
},
47+
'&position-top': {
48+
node: {
49+
top: 0,
4850
},
49-
'&position-middle': {
50-
node: {
51-
top: '50%',
52-
},
51+
},
52+
'&position-middle': {
53+
node: {
54+
top: '50%',
5355
},
54-
'&position-bottom': {
55-
node: {
56-
top: '100%',
57-
},
56+
},
57+
'&position-bottom': {
58+
node: {
59+
top: '100%',
5860
},
61+
},
5962

60-
'&position-left': {
61-
node: {
62-
left: 0,
63-
},
63+
'&position-left': {
64+
node: {
65+
left: 0,
6466
},
65-
'&position-center': {
66-
node: {
67-
left: '50%',
68-
},
67+
},
68+
'&position-center': {
69+
node: {
70+
left: '50%',
6971
},
70-
'&position-right': {
71-
node: {
72-
left: '100%',
73-
},
72+
},
73+
'&position-right': {
74+
node: {
75+
left: '100%',
7476
},
7577
},
76-
getModifiers
77-
)
78+
}
7879

79-
export default styled(StickInline)
80+
export default StickInline

0 commit comments

Comments
 (0)