mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
refactor: improve type safety (#5539)
* refactor(popover): consolidate imports from aria-utils module * refactor(popover): remove unnecessary type assertion for child ref * refactor: remove unnecessary type assertions and improve type safety * chore(changeset): add changeset
This commit is contained in:
parent
8eb269df9e
commit
e2aed2e946
10
.changeset/healthy-bottles-search.md
Normal file
10
.changeset/healthy-bottles-search.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
"@heroui/use-aria-accordion-item": patch
|
||||||
|
"@heroui/date-picker": patch
|
||||||
|
"@heroui/shared-utils": patch
|
||||||
|
"@heroui/test-utils": patch
|
||||||
|
"@heroui/popover": patch
|
||||||
|
"@heroui/form": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Code quality improvements: removed unnecessary type assertions across multiple components and utilities, consolidated imports in Popover module, and enhanced type safety.
|
||||||
@ -206,7 +206,7 @@ export const useSandpack = ({
|
|||||||
"react": "18.3.1",
|
"react": "18.3.1",
|
||||||
"react-dom": "18.3.1",
|
"react-dom": "18.3.1",
|
||||||
${Object.entries(
|
${Object.entries(
|
||||||
omit(dependencies as any, [
|
omit(dependencies, [
|
||||||
"react",
|
"react",
|
||||||
"react-dom",
|
"react-dom",
|
||||||
"react-dom/client",
|
"react-dom/client",
|
||||||
|
|||||||
@ -169,7 +169,7 @@ export function useDatePickerBase<T extends DateValue>(originalProps: UseDatePic
|
|||||||
const disableAnimation =
|
const disableAnimation =
|
||||||
originalProps.disableAnimation ?? globalContext?.disableAnimation ?? false;
|
originalProps.disableAnimation ?? globalContext?.disableAnimation ?? false;
|
||||||
|
|
||||||
let stringFormatter = useLocalizedStringFormatter(intlMessages) as any;
|
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
||||||
|
|
||||||
const isDefaultColor = originalProps.color === "default" || !originalProps.color;
|
const isDefaultColor = originalProps.color === "default" || !originalProps.color;
|
||||||
const hasMultipleMonths = visibleMonths > 1;
|
const hasMultipleMonths = visibleMonths > 1;
|
||||||
|
|||||||
@ -136,7 +136,7 @@ export function useContextProps<T, U extends SlotProps, E extends Element>(
|
|||||||
): [T, RefObject<E | null>] {
|
): [T, RefObject<E | null>] {
|
||||||
let ctx = useSlottedContext(context, props.slot) || {};
|
let ctx = useSlottedContext(context, props.slot) || {};
|
||||||
// @ts-ignore - TS says "Type 'unique symbol' cannot be used as an index type." but not sure why.
|
// @ts-ignore - TS says "Type 'unique symbol' cannot be used as an index type." but not sure why.
|
||||||
let {ref: contextRef, ...contextProps} = ctx as any;
|
let {ref: contextRef, ...contextProps} = ctx;
|
||||||
let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef]));
|
let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef]));
|
||||||
let mergedProps = mergeProps(contextProps, props) as unknown as T;
|
let mergedProps = mergeProps(contextProps, props) as unknown as T;
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ const PopoverTrigger = (props: PopoverTriggerProps) => {
|
|||||||
|
|
||||||
// Accessing the ref from props, else fallback to element.ref
|
// Accessing the ref from props, else fallback to element.ref
|
||||||
// https://github.com/facebook/react/pull/28348
|
// https://github.com/facebook/react/pull/28348
|
||||||
const childRef = child.props.ref ?? (child as any).ref;
|
const childRef = child.props.ref ?? child.ref;
|
||||||
|
|
||||||
const {onPress, isDisabled, ...restProps} = useMemo(() => {
|
const {onPress, isDisabled, ...restProps} = useMemo(() => {
|
||||||
return getTriggerProps(mergeProps(otherProps, child.props), childRef);
|
return getTriggerProps(mergeProps(otherProps, child.props), childRef);
|
||||||
|
|||||||
@ -13,9 +13,8 @@ import {useDOMRef} from "@heroui/react-utils";
|
|||||||
import {useOverlayTriggerState} from "@react-stately/overlays";
|
import {useOverlayTriggerState} from "@react-stately/overlays";
|
||||||
import {useFocusRing} from "@react-aria/focus";
|
import {useFocusRing} from "@react-aria/focus";
|
||||||
import {useOverlayTrigger, usePreventScroll} from "@react-aria/overlays";
|
import {useOverlayTrigger, usePreventScroll} from "@react-aria/overlays";
|
||||||
import {getShouldUseAxisPlacement} from "@heroui/aria-utils";
|
import {getShouldUseAxisPlacement, getArrowPlacement} from "@heroui/aria-utils";
|
||||||
import {mapPropsVariants, useProviderContext} from "@heroui/system";
|
import {mapPropsVariants, useProviderContext} from "@heroui/system";
|
||||||
import {getArrowPlacement} from "@heroui/aria-utils";
|
|
||||||
import {popover} from "@heroui/theme";
|
import {popover} from "@heroui/theme";
|
||||||
import {clsx, dataAttr, objectToDeps, mergeProps, mergeRefs} from "@heroui/shared-utils";
|
import {clsx, dataAttr, objectToDeps, mergeProps, mergeRefs} from "@heroui/shared-utils";
|
||||||
import {useMemo, useCallback, useRef} from "react";
|
import {useMemo, useCallback, useRef} from "react";
|
||||||
|
|||||||
@ -49,7 +49,7 @@ export function useAriaAccordionItem<T>(
|
|||||||
if (!manager.canSelectItem(key)) {
|
if (!manager.canSelectItem(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
manager.select(key, e as any);
|
manager.select(key, e);
|
||||||
state.toggleKey(key);
|
state.toggleKey(key);
|
||||||
},
|
},
|
||||||
[key, manager],
|
[key, manager],
|
||||||
|
|||||||
@ -353,9 +353,9 @@ export const intersectionBy = <T>(...args: [...arrays: T[][], iteratee: Iteratee
|
|||||||
|
|
||||||
const getIterateeValue = (item: T): unknown => {
|
const getIterateeValue = (item: T): unknown => {
|
||||||
if (typeof iteratee === "function") {
|
if (typeof iteratee === "function") {
|
||||||
return (iteratee as (value: T) => any)(item);
|
return iteratee(item);
|
||||||
} else if (typeof iteratee === "string") {
|
} else if (typeof iteratee === "string") {
|
||||||
return (item as any)[iteratee];
|
return item[iteratee];
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Iteratee must be a function or a string key of the array elements");
|
throw new Error("Iteratee must be a function or a string key of the array elements");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ export function mockImage() {
|
|||||||
return name in this;
|
return name in this;
|
||||||
}
|
}
|
||||||
getAttribute(name: string) {
|
getAttribute(name: string) {
|
||||||
return name in this ? (this as any)[name] : null;
|
return name in this ? this[name] : null;
|
||||||
}
|
}
|
||||||
constructor() {
|
constructor() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user