discourse/app/assets/javascripts/float-kit/addon/lib/constants.js
Kelv 0005565fb3
DEV: allow floatkit components to accept autoPlacement as a placement strategy (#33783)
`flip` and `autoPlacement` are [mutually exclusive
middleware](https://floating-ui.com/docs/autoplacement#conflict-with-flip)
dealing with placement. While our current Floatkit design uses `flip` by
default, there may be use cases where we want to specify using
`autoPlacement` instead.

Terming this as a choice of `visibilityOptimizer` which borrows from
floating-ui terminology of middleware that deals with `visibility
optimization`, while deconflicting with an existing `placementStrategy`
option in select-kit that is unrelated to this.
2025-07-24 11:04:51 +08:00

101 lines
2.2 KiB
JavaScript
Vendored

export const FLOAT_UI_PLACEMENTS = [
"top",
"top-start",
"top-end",
"right",
"right-start",
"right-end",
"bottom",
"bottom-start",
"bottom-end",
"left",
"left-start",
"left-end",
];
export const VISIBILITY_OPTIMIZERS = {
FLIP: "flip",
AUTO_PLACEMENT: "autoPlacement",
};
export const TOOLTIP = {
options: {
animated: true,
arrow: true,
beforeTrigger: null,
closeOnClickOutside: true,
closeOnEscape: true,
closeOnScroll: true,
component: null,
content: null,
identifier: null,
interactive: false,
listeners: false,
maxWidth: 350,
data: null,
offset: 10,
triggers: { mobile: ["click"], desktop: ["hover", "click"] },
untriggers: { mobile: ["click"], desktop: ["hover", "click"] },
placement: "top",
visibilityOptimizer: VISIBILITY_OPTIMIZERS.FLIP,
fallbackPlacements: FLOAT_UI_PLACEMENTS,
autoUpdate: true,
trapTab: true,
onClose: null,
onShow: null,
onRegisterApi: null,
updateOnScroll: true,
},
portalOutletId: "d-tooltip-portal-outlet",
};
export const MENU = {
options: {
animated: true,
arrow: false,
autofocus: false,
beforeTrigger: null,
closeOnEscape: true,
closeOnClickOutside: true,
closeOnScroll: false,
component: null,
content: null,
identifier: null,
interactive: true,
listeners: false,
maxWidth: 400,
data: null,
offset: 10,
triggers: ["click"],
untriggers: ["click"],
placement: "bottom-start",
visibilityOptimizer: VISIBILITY_OPTIMIZERS.FLIP,
fallbackPlacements: FLOAT_UI_PLACEMENTS,
autoUpdate: true,
trapTab: true,
onClose: null,
onShow: null,
onRegisterApi: null,
modalForMobile: false,
inline: null,
groupIdentifier: null,
parentIdentifier: null,
triggerClass: null,
contentClass: null,
class: null,
updateOnScroll: true,
},
portalOutletId: "d-menu-portal-outlet",
};
import DDefaultToast from "float-kit/components/d-default-toast";
export const TOAST = {
options: {
autoClose: true,
duration: "short",
component: DDefaultToast,
showProgressBar: false,
views: ["desktop", "mobile"],
},
};