import { IClassName, IReactNullableElement } from "../../types"; import { ReactNode } from "react"; import { ViewProps } from "react-native"; import { IVariantPropsMenu } from "../../variants/menu"; import { INavItemProps, INavItemsProps } from "../Nav/types"; /** * Represents the possible positions where the menu can be displayed * relative to its anchor element. * * This type is used to specify the alignment of a menu in relation to * another UI component, such as a button or an icon. Depending on the * value provided, the menu will render in one of the four cardinal * directions: above, below, to the left, or to the right of the anchor. * * @enum {string} * @example * // Usage in a component to determine the menu position * const menuPosition: IMenuPosition = 'bottom'; * * // This will render the menu below the anchor element * renderMenu(menuPosition); * * // Other examples of possible values: * const topMenu: IMenuPosition = 'top'; // Menu appears above the anchor * const leftMenu: IMenuPosition = 'left'; // Menu appears to the left of the anchor * const rightMenu: IMenuPosition = 'right';// Menu appears to the right of the anchor */ export type IMenuPosition = 'top' | 'bottom' | 'left' | 'right'; /** * Measurements of the anchor element's position and size. * * This interface provides the necessary dimensions and coordinates * of an anchor element, which can be used to position related UI * components, such as menus or tooltips, accurately on the screen. * * It captures the anchor's position in the viewport and its size, * allowing developers to dynamically adjust the placement of * associated elements based on the anchor's measurements. * * @interface IMenuAnchorMeasurements * @property {number} pageX - X coordinate of the anchor element * relative to the entire window. This value * indicates how far the anchor is from the * left edge of the viewport. * @property {number} pageY - Y coordinate of the anchor element * relative to the entire window. This value * indicates how far the anchor is from the * top edge of the viewport. * @property {number} width - The width of the anchor element in pixels. * This is useful for calculating horizontal * alignment of related UI components. * @property {number} height - The height of the anchor element in pixels. * This is useful for calculating vertical * alignment of related UI components. * * @example * // Example of using IMenuAnchorMeasurements to position a menu * const anchorMeasurements: IMenuAnchorMeasurements = { * pageX: 100, * pageY: 200, * width: 50, * height: 30, * }; * * // Function to calculate menu position based on anchor measurements * const calculateMenuPosition = (measurements: IMenuAnchorMeasurements) => { * const { pageX, pageY, width, height } = measurements; * // Position menu to the right of the anchor * return { * left: pageX + width, * top: pageY, * }; * }; * * const menuPosition = calculateMenuPosition(anchorMeasurements); * // This will position the menu at (150, 200) based on the anchor's measurements */ export interface IMenuAnchorMeasurements { pageX: number; pageY: number; width: number; height: number; } /** * Result of position calculations containing the final position and coordinates. * * This interface encapsulates the outcome of calculations performed to * determine the appropriate position of a menu relative to its anchor * element. It includes both the designated position (e.g., top, bottom, * left, right) as well as the exact coordinates where the menu should * be rendered on the screen. * * By using this interface, developers can easily access both the * positioning strategy and the pixel-perfect coordinates needed to * render the menu accurately. * * @interface IMenuCalculatedPosition * @property {IMenuPosition} position - The calculated position of the menu * relative to the anchor element. This * will be one of the values defined in * the `IMenuPosition` type, indicating * where the menu is intended to appear * (e.g., 'top', 'bottom', 'left', or * 'right'). * @property {number} x - Final X coordinate in pixels where the menu * should be rendered on the screen. This value is * calculated based on the anchor's measurements and * the desired position of the menu. * @property {number} y - Final Y coordinate in pixels where the menu * should be rendered on the screen. Similar to the * X coordinate, this value is derived from the anchor * measurements and the calculated position. * * @example * // Example of using IMenuCalculatedPosition to render a menu * const calculatedPosition: IMenuCalculatedPosition = { * position: 'bottom', // Indicates the menu should appear below the anchor * x: 150, // Final X coordinate for the menu * y: 220, // Final Y coordinate for the menu * }; * * // Function to render the menu based on calculated position * const renderMenu = (menuPosition: IMenuCalculatedPosition) => { * const { position, x, y } = menuPosition; * // Render the menu at the specified coordinates * return ( *
* ); * }; * * // Call the render function with the calculated position * renderMenu(calculatedPosition); */ export interface IMenuCalculatedPosition { xPosition?: IMenuPosition; yPosition?: IMenuPosition; left?: number; top?: number; height?: number; width?: number; bottom?: number; calculatedFromPosition: IMenuPosition; right?: number; /** * The max width of the menu. */ maxWidth?: number; /** * The max height of the menu. */ maxHeight?: number; } export type IMenuContext