@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
34 lines (32 loc) • 1.18 kB
JavaScript
import { isValidElement, useMemo } from "react";
//#region src/hooks/useNativeButton.ts
/**
* Hook to resolve nativeButton prop for Base UI trigger components.
*
* When using `render`, Base UI expects the rendered element to be a native <button> by default.
* If we can infer it's not, we opt out to avoid warnings (users can still override via `nativeButton`).
*/
function useNativeButton({ children, nativeButton, triggerNativeButton }) {
const isNativeButtonTriggerElement = useMemo(() => {
if (!isValidElement(children)) return false;
return typeof children.type === "string" && children.type === "button";
}, [children]);
return {
isNativeButtonTriggerElement,
resolvedNativeButton: useMemo(() => {
if (nativeButton !== void 0) return nativeButton;
if (triggerNativeButton !== void 0) return triggerNativeButton;
if (isNativeButtonTriggerElement) return true;
if (!isValidElement(children)) return void 0;
if (typeof children.type === "string") return false;
}, [
children,
isNativeButtonTriggerElement,
nativeButton,
triggerNativeButton
])
};
}
//#endregion
export { useNativeButton };
//# sourceMappingURL=useNativeButton.mjs.map