UNPKG

@carbon/ibm-products

Version:
73 lines (71 loc) 1.6 kB
/** * Copyright IBM Corp. 2020, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import "./enums.js"; //#region src/components/Coachmark/utils/constants.js /** * If the coachmark's target is a link, button, etc. (i.e. not a beacon), * this adjusts the coachmark's position based on the position and size of the target. * @param {object} coachmark target reference * @param {string} kind type of coachmark * @returns {object} {top:number, left:number} */ const getOffsetTune = (coachmark, kind) => { const { width, height } = coachmark.targetRect; const distanceOffset = 24; let top = 0; let left = 0; if (kind !== "tooltip") switch (coachmark.align) { case "top": left = width / 2; break; case "top-left": left = distanceOffset; break; case "top-right": left = width - distanceOffset; break; case "bottom": top = height; left = width / 2; break; case "bottom-left": top = height; left = distanceOffset; break; case "bottom-right": top = height; left = width - distanceOffset; break; case "left": top = height / 2; break; case "left-top": top = distanceOffset; break; case "left-bottom": top = height - distanceOffset; break; case "right": top = height / 2; left = width; break; case "right-top": top = distanceOffset; left = width; break; case "right-bottom": top = height - distanceOffset; left = width; break; } return { top, left }; }; //#endregion export { getOffsetTune };