@meonode/ui
Version:
A structured approach to component composition with built-in theming, prop separation, and dynamic children handling.
86 lines • 4.4 kB
TypeScript
import type { ComponentProps, CSSProperties, ElementType } from 'react';
import type { NodeElement, FinalNodeProps, NodeInstance } from './node.type.js';
/**
* Returns a string describing the type of a given React component or element.
*
* Checks for common React types (class, forwardRef, memo, etc.) and returns a string
* such as 'class', 'forwardRef', 'memo', 'object-with-render', 'function', or other
* React-specific types. Falls back to `typeof` or 'unknown' if not recognized.
* @param component The React component, element type, or element-like object to check.
* @returns A string describing the component type.
* @example
* getComponentType(class extends React.Component {}) // 'class'
* getComponentType(React.forwardRef(() => <div/>)) // 'forwardRef'
* getComponentType(React.memo(() => <div/>)) // 'memo'
* getComponentType(() => <div/>) // 'function'
*/
export declare const getComponentType: (component?: NodeElement) => "class" | "forwardRef" | "memo" | "object" | "function" | "fragment" | "portal" | "profiler" | "strict-mode" | "suspense" | "suspense-list" | "context-consumer" | "context-provider" | "lazy" | "element" | "unknown" | string;
/**
* Generates a string name for an ElementType or ReactElement.
*
* This function attempts to extract a meaningful name from a React ElementType
* (string, function, class, HOC) or a ReactElement instance.
* It prioritizes `displayName` and `name` properties and unwraps HOCs like
* `React.memo` and `React.forwardRef` to get the underlying component name.
*
* If a name cannot be determined, it returns a fallback like 'UnknownElementType' or 'AnonymousComponent'.
* @param node The ElementType or ReactElement (e.g., 'div', MyComponent, <MyComponent />).
* @returns A string representation of the element type's name.
*/
export declare function getElementTypeName(node: unknown): string;
/**
* A set of valid CSS property names in camelCase, including CSS custom properties, used for validation.
* This set contains all CSS properties including non-standard vendor prefixed properties.
*/
export declare const CSSPropertySet: Set<string>;
/**
* Filters an object to only include valid CSS properties
* @param props The object containing potential CSS properties
* @returns An object containing only valid CSS properties
* @example
* ```ts
* getCSSProps({
* backgroundColor: 'red',
* invalid: true
* }) // { backgroundColor: 'red' }
* ```
*/
export declare function getCSSProps<T extends Record<string, any>>(props: T): Partial<CSSProperties>;
/**
* Filters component props to include only valid DOM properties and attributes.
*
* This function iterates through the provided props and retains only those that
* are not CSS properties (as determined by `cssPropertySet`). This is useful for
* separating style-related props from standard DOM attributes when rendering
* elements.
* @ty E - The type of the React element.
* @typeParam T - The type of the component props.
* @param props The component props to filter.
* @returns An object containing only valid DOM props.
*/
export declare function getDOMProps<E extends ElementType, T extends ComponentProps<E>>(props: T): Partial<FinalNodeProps>;
/**
* Retrieves a deeply nested value from an object using a dot-separated string path.
*
* This function traverses an object based on the provided path, which is a
* string of keys separated by dots. It returns the value found at the end of
* the path or `undefined` if any key in the path is not found or if the object
* is nullish at any point during traversal.
* @param obj The object to traverse. Defaults to an empty object if not provided.
* @param path The dot-separated path string (e.g., 'background.primary').
* @returns The value at the specified path, or undefined if not found.
*/
export declare function getValueByPath(obj: Record<string, any> | undefined, path: string): Record<string, any>;
/**
* Type guard to check if an object is a NodeInstance.
*
* A NodeInstance is expected to be a non-null object with:
* - an 'element' property,
* - a 'render' method,
* - a 'toPortal' method,
* - and an 'isBaseNode' property.
* @param obj The object to check.
* @returns True if the object is a NodeInstance, false otherwise.
*/
export declare const isNodeInstance: (obj: unknown) => obj is NodeInstance<any>;
//# sourceMappingURL=node.helper.d.ts.map