@carbon/ibm-products
Version:
Carbon for IBM Products
103 lines (94 loc) • 2.84 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
;
var floatingUi_dom = require('../../dom/dist/floating-ui.dom.js');
require('react');
require('react-dom');
/**
* Provides data to position an inner element of the floating element so that it
* appears centered to the reference element.
* This wraps the core `arrow` middleware to allow React refs as the element.
* @see https://floating-ui.com/docs/arrow
*/
const arrow$1 = options => {
function isRef(value) {
return {}.hasOwnProperty.call(value, 'current');
}
return {
name: 'arrow',
options,
fn(state) {
const {
element,
padding
} = typeof options === 'function' ? options(state) : options;
if (element && isRef(element)) {
if (element.current != null) {
return floatingUi_dom.arrow({
element: element.current,
padding
}).fn(state);
}
return {};
}
if (element) {
return floatingUi_dom.arrow({
element,
padding
}).fn(state);
}
return {};
}
};
};
/**
* Modifies the placement by translating the floating element along the
* specified axes.
* A number (shorthand for `mainAxis` or distance), or an axes configuration
* object may be passed.
* @see https://floating-ui.com/docs/offset
*/
const offset = (options, deps) => ({
...floatingUi_dom.offset(options),
options: [options, deps]
});
/**
* Optimizes the visibility of the floating element by shifting it in order to
* keep it in view when it will overflow the clipping boundary.
* @see https://floating-ui.com/docs/shift
*/
const shift = (options, deps) => ({
...floatingUi_dom.shift(options),
options: [options, deps]
});
/**
* Optimizes the visibility of the floating element by flipping the `placement`
* in order to keep it in view when the preferred placement(s) will overflow the
* clipping boundary. Alternative to `autoPlacement`.
* @see https://floating-ui.com/docs/flip
*/
const flip = (options, deps) => ({
...floatingUi_dom.flip(options),
options: [options, deps]
});
/**
* Provides data to position an inner element of the floating element so that it
* appears centered to the reference element.
* This wraps the core `arrow` middleware to allow React refs as the element.
* @see https://floating-ui.com/docs/arrow
*/
const arrow = (options, deps) => ({
...arrow$1(options),
options: [options, deps]
});
exports.autoUpdate = floatingUi_dom.autoUpdate;
exports.computePosition = floatingUi_dom.computePosition;
exports.platform = floatingUi_dom.platform;
exports.arrow = arrow;
exports.flip = flip;
exports.offset = offset;
exports.shift = shift;