| 1 |
import Popper, { Data, Modifiers, PopperOptions } from 'popper.js'; |
| 2 |
|
| 3 |
|
| 4 |
const modifiers: Modifiers = { |
| 5 |
shift: {}, |
| 6 |
offset: { |
| 7 |
order: 0, |
| 8 |
offset: 'a string offset' |
| 9 |
}, |
| 10 |
preventOverflow: {}, |
| 11 |
keepTogether: { |
| 12 |
enabled: true |
| 13 |
}, |
| 14 |
arrow: { |
| 15 |
fn(data, options) { |
| 16 |
return { ...data, flipped: false, ...options }; |
| 17 |
} |
| 18 |
}, |
| 19 |
flip: { |
| 20 |
behavior: 'flip' |
| 21 |
}, |
| 22 |
inner: { |
| 23 |
enabled: false, |
| 24 |
order: 1 |
| 25 |
}, |
| 26 |
hide: {}, |
| 27 |
applyStyle: { |
| 28 |
onLoad() { |
| 29 |
|
| 30 |
}, |
| 31 |
gpuAcceleration: true |
| 32 |
}, |
| 33 |
computeStyle: { |
| 34 |
gpuAcceleration: false, |
| 35 |
x: 'top', |
| 36 |
y: 'right' |
| 37 |
}, |
| 38 |
otherModifier: { |
| 39 |
allowsAnyKey: null |
| 40 |
} |
| 41 |
}; |
| 42 |
// Ensure backwards compatibility with < v1.14 typings, where all the types were part of the Popper namespace |
| 43 |
const options: Popper.PopperOptions = { |
| 44 |
positionFixed: true, |
| 45 |
placement: 'auto-start', |
| 46 |
eventsEnabled: false, |
| 47 |
modifiers, |
| 48 |
removeOnDestroy: true, |
| 49 |
onCreate(data) { |
| 50 |
console.log(data); |
| 51 |
}, |
| 52 |
onUpdate(data) { |
| 53 |
console.log('x-out-of-boundaries', data.attributes); |
| 54 |
console.log('x-placement', data.attributes['x-placement']); |
| 55 |
data.styles.alignContent = 'flex-start'; |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
Popper.modifiers.map(mod => mod.name); |
| 60 |
Popper.placements.forEach(placement => placement.toLowerCase()); |
| 61 |
Popper.Defaults.onCreate = function (data: Data) { |
| 62 |
|
| 63 |
}; |
| 64 |
|
| 65 |
const popper = new Popper(document.createElement('div'), document.createElement('span')); |
| 66 |
const popperWithOptions = new Popper(document.createElement('div'), document.createElement('span'), options); |
| 67 |
|
| 68 |
popper.options.positionFixed = false; |
| 69 |
popper.destroy(); |
| 70 |
popper.update(); |
| 71 |
popper.scheduleUpdate(); |
| 72 |
popper.enableEventListeners(); |
| 73 |
popper.disableEventListeners(); |