Skip to content

Commit c13cda1

Browse files
committed
fix(release): migrate popper.js from v1 to v2
* update Popup module * update docs
1 parent 2dbab6b commit c13cda1

File tree

8 files changed

+88
-156
lines changed

8 files changed

+88
-156
lines changed

docs/src/examples/modules/Popup/Usage/PopupExampleEventsEnabled.js

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

docs/src/examples/modules/Popup/Usage/PopupExampleOffset.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ const PopupExampleOffset = () => (
66
<Popup
77
trigger={<Icon size='large' name='heart' circular />}
88
content='Way off to the left'
9-
offset='0, 50px'
9+
offset={[0, 50]}
1010
position='left center'
1111
/>
1212
<Popup
1313
trigger={<Icon size='large' name='heart' circular />}
1414
content='As expected this popup is way off to the right'
15-
offset='0, 50px'
15+
offset={[0, 50]}
1616
position='right center'
1717
/>
1818
<Popup
1919
trigger={<Icon size='large' name='heart' circular />}
2020
content='Way off to the top'
21-
offset='0, 50px'
21+
offset={[0, 50]}
2222
position='top center'
2323
/>
2424
<Popup
2525
trigger={<Icon size='large' name='heart' circular />}
2626
content='As expected this popup is way off to the bottom'
27-
offset='0, 50px'
27+
offset={[0, 50]}
2828
position='bottom center'
2929
/>
3030
</React.Fragment>

docs/src/examples/modules/Popup/Usage/index.js

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,30 @@ const PopupUsageExamples = () => (
1414
<Message info>
1515
<p>
1616
We are using Popper.js for positioning, so you can use the{' '}
17-
<code>offset</code> prop as it described in their docs. Accepts the
18-
following units:
17+
<code>offset</code> prop as it described in their docs.
18+
</p>
19+
<p>
20+
The basic offset accepts an array with two numbers in the form{' '}
21+
<code>[skidding, distance].</code>
22+
</p>
23+
<p>
24+
The first number, <code>skidding</code>, displaces the popper along
25+
the reference element.
26+
</p>
27+
<p>
28+
The second number, <code>distance</code>, displaces the popper away
29+
from, or toward, the reference element in the direction of its
30+
placement. A positive number displaces it further away, while a
31+
negative number lets it overlap the reference.
1932
</p>
20-
<Message.List>
21-
<Message.Item>
22-
<code>px</code> or unit-less, interpreted as pixels
23-
</Message.Item>
24-
<Message.Item>
25-
<code>%</code>, percentage relative to the length of the trigger
26-
element
27-
</Message.Item>
28-
<Message.Item>
29-
<code>%p</code>, percentage relative to the length of the popup
30-
element
31-
</Message.Item>
32-
<Message.Item>
33-
<code>vw</code>, CSS viewport width unit
34-
</Message.Item>
35-
<Message.Item>
36-
<code>vh</code>, CSS viewport height unit
37-
</Message.Item>
38-
</Message.List>
3933
</Message>
4034
<Button
4135
content='Popper.JS: offset'
42-
href='https://popper.js.org/popper-documentation.html#modifiers..offset'
36+
href='https://popper.js.org/docs/v2/modifiers/offset/'
4337
icon='book'
4438
target='_blank'
4539
/>
4640
</ComponentExample>
47-
<ComponentExample
48-
title={<code>eventsEnabled</code>}
49-
description={
50-
<span>
51-
Enables the <code>Popper.js</code> event listeners.
52-
</span>
53-
}
54-
examplePath='modules/Popup/Usage/PopupExampleEventsEnabled'
55-
/>
5641
<ComponentExample
5742
title='Popper Dependencies'
5843
description={

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"homepage": "https://github.com/Semantic-Org/Semantic-UI-React#readme",
7979
"dependencies": {
8080
"@babel/runtime": "^7.1.2",
81+
"@popperjs/core": "2.4.0",
8182
"@semantic-ui-react/event-stack": "^3.1.0",
8283
"@stardust-ui/react-component-event-listener": "~0.38.0",
8384
"@stardust-ui/react-component-ref": "~0.38.0",
@@ -86,7 +87,7 @@
8687
"lodash": "^4.17.15",
8788
"prop-types": "^15.7.2",
8889
"react-is": "^16.8.6",
89-
"react-popper": "^1.3.4",
90+
"react-popper": "^2.2.3",
9091
"shallowequal": "^1.1.0"
9192
},
9293
"devDependencies": {

src/modules/Popup/Popup.d.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ export interface StrictPopupProps extends StrictPortalProps {
3131
/** A disabled popup only renders its trigger. */
3232
disabled?: boolean
3333

34-
/** Enables the Popper.js event listeners. */
35-
eventsEnabled?: boolean
36-
3734
/** A flowing Popup has no maximum width and continues to flow to fit its content. */
3835
flowing?: boolean
3936

@@ -49,12 +46,14 @@ export interface StrictPopupProps extends StrictPortalProps {
4946
/** Invert the colors of the popup */
5047
inverted?: boolean
5148

52-
/** Offset value to apply to rendered popup. Accepts the following units:
53-
* - px or unit-less, interpreted as pixels
54-
* - %, percentage relative to the length of the trigger element
55-
* - %p, percentage relative to the length of the popup element
56-
* - vw, CSS viewport width unit
57-
* - vh, CSS viewport height unit
49+
/** Offset values in px unit to apply to rendered popup. The basic offset accepts an
50+
* array with two numbers in the form [skidding, distance].
51+
*
52+
* The first number, skidding, displaces the popper along the reference element.
53+
*
54+
* The second number, distance, displaces the popper away from, or toward, the
55+
* reference element in the direction of its placement. A positive number displaces
56+
* it further away, while a negative number lets it overlap the reference.
5857
*/
5958
offset?: number | string
6059

@@ -110,8 +109,8 @@ export interface StrictPopupProps extends StrictPortalProps {
110109
/** Tells `Popper.js` to use the `position: fixed` strategy to position the popover. */
111110
positionFixed?: boolean
112111

113-
/** An object containing custom settings for the Popper.js modifiers. */
114-
popperModifiers?: object
112+
/** An array containing custom settings for the Popper.js modifiers. */
113+
popperModifiers?: any[]
115114

116115
/** A popup can have dependencies which update will schedule a position update. */
117116
popperDependencies?: any[]

src/modules/Popup/Popup.js

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ export default class Popup extends Component {
5252
/** A disabled popup only renders its trigger. */
5353
disabled: PropTypes.bool,
5454

55-
/** Enables the Popper.js event listeners. */
56-
eventsEnabled: PropTypes.bool,
57-
5855
/** A flowing Popup has no maximum width and continues to flow to fit its content. */
5956
flowing: PropTypes.bool,
6057

@@ -74,14 +71,16 @@ export default class Popup extends Component {
7471
/** Invert the colors of the Popup. */
7572
inverted: PropTypes.bool,
7673

77-
/** Offset value to apply to rendered popup. Accepts the following units:
78-
* - px or unit-less, interpreted as pixels
79-
* - %, percentage relative to the length of the trigger element
80-
* - %p, percentage relative to the length of the popup element
81-
* - vw, CSS viewport width unit
82-
* - vh, CSS viewport height unit
74+
/** Offset values in px unit to apply to rendered popup. The basic offset accepts an
75+
* array with two numbers in the form [skidding, distance].
76+
*
77+
* The first number, skidding, displaces the popper along the reference element.
78+
*
79+
* The second number, distance, displaces the popper away from, or toward, the
80+
* reference element in the direction of its placement. A positive number displaces
81+
* it further away, while a negative number lets it overlap the reference.
8382
*/
84-
offset: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
83+
offset: PropTypes.arrayOf(PropTypes.number),
8584

8685
/** Events triggering the popup. */
8786
on: PropTypes.oneOfType([
@@ -130,8 +129,8 @@ export default class Popup extends Component {
130129
/** Tells `Popper.js` to use the `position: fixed` strategy to position the popover. */
131130
positionFixed: PropTypes.bool,
132131

133-
/** An object containing custom settings for the Popper.js modifiers. */
134-
popperModifiers: PropTypes.object,
132+
/** An array containing custom settings for the Popper.js modifiers. */
133+
popperModifiers: PropTypes.array,
135134

136135
/** A popup can have dependencies which update will schedule a position update. */
137136
popperDependencies: PropTypes.array,
@@ -151,8 +150,7 @@ export default class Popup extends Component {
151150

152151
static defaultProps = {
153152
disabled: false,
154-
eventsEnabled: true,
155-
offset: 0,
153+
offset: [0, 0],
156154
on: ['click', 'hover'],
157155
pinned: false,
158156
position: 'top left',
@@ -331,7 +329,6 @@ export default class Popup extends Component {
331329
const {
332330
context,
333331
disabled,
334-
eventsEnabled,
335332
offset,
336333
pinned,
337334
popperModifiers,
@@ -343,17 +340,17 @@ export default class Popup extends Component {
343340

344341
if (closed || disabled) return trigger
345342

346-
const modifiers = _.merge(
347-
{
348-
arrow: { enabled: false },
349-
flip: { enabled: !pinned },
350-
// There are issues with `keepTogether` and `offset`
351-
// https://github.com/FezVrasta/popper.js/issues/557
352-
keepTogether: { enabled: !!offset },
353-
offset: { offset },
354-
},
355-
popperModifiers,
356-
)
343+
const defaultModifiers = [
344+
{ name: 'arrow', enabled: false },
345+
{ name: 'flip', enabled: !pinned },
346+
{ name: 'preventOverflow', enabled: !!offset },
347+
{ name: 'offset', options: { offset } },
348+
]
349+
const modifiers = popperModifiers
350+
? _.unionBy(popperModifiers, defaultModifiers, 'name')
351+
: defaultModifiers
352+
debug('popper modifiers:', modifiers)
353+
357354
const referenceElement = createReferenceProxy(_.isNil(context) ? this.triggerRef : context)
358355

359356
const mergedPortalProps = { ...this.getPortalProps(), ...portalRestProps }
@@ -370,10 +367,9 @@ export default class Popup extends Component {
370367
triggerRef={this.triggerRef}
371368
>
372369
<Popper
373-
eventsEnabled={eventsEnabled}
374370
modifiers={modifiers}
375371
placement={positionsMapping[position]}
376-
positionFixed={positionFixed}
372+
strategy={positionFixed ? 'fixed' : null}
377373
referenceElement={referenceElement}
378374
>
379375
{this.renderContent}

test/specs/modules/Popup/Popup-test.js

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,6 @@ describe('Popup', () => {
110110
})
111111
})
112112

113-
describe('eventsEnabled ', () => {
114-
it(`is "true" by default`, () => {
115-
wrapperMount(<Popup open />)
116-
117-
wrapper.should.have.prop('eventsEnabled', true)
118-
wrapper.find('Popper').should.have.prop('eventsEnabled', true)
119-
})
120-
121-
it(`can be set to "false"`, () => {
122-
wrapperMount(<Popup eventsEnabled={false} open />)
123-
wrapper.find('Popper').should.have.prop('eventsEnabled', false)
124-
})
125-
})
126-
127113
describe('flowing', () => {
128114
it('adds flowing to the popup className', () => {
129115
wrapperMount(<Popup flowing open />)
@@ -174,12 +160,12 @@ describe('Popup', () => {
174160

175161
describe('offset', () => {
176162
it('passes values to Popper', () => {
177-
wrapperMount(<Popup content='foo' open offset='50, 100' position='bottom right' />)
163+
wrapperMount(<Popup content='foo' open offset={[50, 100]} position='bottom right' />)
178164

179165
const modifiers = wrapper.find('Popper').prop('modifiers')
180-
const offset = modifiers.offset
166+
const offset = _.find(modifiers, (m) => m.name === 'offset')
181167

182-
offset.should.have.property('offset', '50, 100')
168+
offset.should.have.property('options').deep.include({ offset: [50, 100] })
183169
})
184170
})
185171

@@ -254,10 +240,13 @@ describe('Popup', () => {
254240
})
255241

256242
describe('pinned', () => {
257-
it(`is "false" by default`, () => {
243+
it(`is "true" by default`, () => {
258244
wrapperMount(<Popup open />)
259245

260-
wrapper.should.have.prop('pinned', false)
246+
wrapper
247+
.find('Popper')
248+
.should.have.prop('modifiers')
249+
.deep.include({ name: 'flip', enabled: true })
261250
})
262251

263252
it(`disables "flip" modifier in PopperJS when is "true"`, () => {
@@ -266,7 +255,7 @@ describe('Popup', () => {
266255
wrapper
267256
.find('Popper')
268257
.should.have.prop('modifiers')
269-
.deep.include({ flip: { enabled: false } })
258+
.deep.include({ name: 'flip', enabled: false })
270259
})
271260

272261
it(`enables "flip" modifier in PopperJS when is "false"`, () => {
@@ -275,7 +264,7 @@ describe('Popup', () => {
275264
wrapper
276265
.find('Popper')
277266
.should.have.prop('modifiers')
278-
.deep.include({ flip: { enabled: true } })
267+
.deep.include({ name: 'flip', enabled: true })
279268
})
280269
})
281270

@@ -299,22 +288,21 @@ describe('Popup', () => {
299288

300289
it(`can be set to "true"`, () => {
301290
wrapperMount(<Popup positionFixed open />)
302-
wrapper.find('Popper').should.have.prop('positionFixed', true)
291+
wrapper.find('Popper').should.have.prop('strategy', 'fixed')
303292
})
304293
})
305294

306295
describe('popperModifiers', () => {
307296
it('are passed to Popper', () => {
308-
const modifiers = {
309-
keepTogether: { enabled: false },
310-
preventOverflow: { padding: 0 },
311-
}
312-
wrapperMount(<Popup popperModifiers={modifiers} open />)
297+
const modifierOffset = { name: 'offset', options: { offset: [0, 10] } }
298+
const modifierPreventOverflow = { name: 'preventOverflow', options: { padding: 0 } }
299+
wrapperMount(<Popup popperModifiers={[modifierOffset, modifierPreventOverflow]} open />)
313300

314301
wrapper
315302
.find('Popper')
316303
.should.have.prop('modifiers')
317-
.deep.include(modifiers)
304+
.deep.include(modifierOffset)
305+
.deep.include(modifierPreventOverflow)
318306
})
319307
})
320308

0 commit comments

Comments
 (0)