diff --git a/packages/accordion/src/accordion.tsx b/packages/accordion/src/accordion.tsx index afc5a4fe..d1b2691c 100644 --- a/packages/accordion/src/accordion.tsx +++ b/packages/accordion/src/accordion.tsx @@ -18,10 +18,7 @@ import type { const AccordionContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, type, disabled, collapsible = true, @@ -29,9 +26,7 @@ const Root = React.forwardRef( onValueChange: onValueChangeProps, defaultValue, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const [value = type === 'multiple' ? [] : undefined, onValueChange] = useControllableState< (string | undefined) | string[] >({ @@ -55,7 +50,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeAccordion'; @@ -76,8 +70,7 @@ type AccordionItemContext = ItemProps & { const AccordionItemContext = React.createContext(null); -const Item = React.forwardRef( - ({ asChild, value, disabled, ...viewProps }, ref) => { +function Item({ ref, asChild, value, disabled, ...viewProps }: ItemProps & { ref?: React.Ref }) { const { value: rootValue } = useRootContext(); const nativeID = React.useId(); @@ -95,7 +88,6 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemNativeAccordion'; @@ -109,7 +101,7 @@ function useItemContext() { return context; } -const Header = React.forwardRef(({ asChild, ...props }, ref) => { +function Header({ ref, asChild, ...props }: HeaderProps & { ref?: React.Ref }) { const { disabled: rootDisabled } = useRootContext(); const { disabled: itemDisabled, isExpanded } = useItemContext(); @@ -123,12 +115,11 @@ const Header = React.forwardRef(({ asChild, ...props }, {...props} /> ); -}); +} Header.displayName = 'HeaderNativeAccordion'; -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled: disabledProp, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled: disabledProp, ...props }: TriggerProps & { ref?: React.Ref }) { const { disabled: rootDisabled, type, @@ -175,12 +166,10 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativeAccordion'; -const Content = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Content({ ref, asChild, forceMount, ...props }: ContentProps & { ref?: React.Ref }) { const { type } = useRootContext(); const { nativeID, isExpanded } = useItemContext(); @@ -201,7 +190,6 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeAccordion'; diff --git a/packages/accordion/src/accordion.web.tsx b/packages/accordion/src/accordion.web.tsx index f8650f5d..328929ca 100644 --- a/packages/accordion/src/accordion.web.tsx +++ b/packages/accordion/src/accordion.web.tsx @@ -22,10 +22,7 @@ import type { const AccordionContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, value: valueProp, onValueChange: onValueChangeProps, defaultValue, @@ -35,9 +32,7 @@ const Root = React.forwardRef( orientation = 'vertical', collapsible, ...props - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const [value = type === 'multiple' ? [] : undefined, onValueChange] = useControllableState< (string | undefined) | string[] >({ @@ -75,7 +70,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebAccordion'; @@ -93,8 +87,7 @@ const AccordionItemContext = React.createContext<(ItemProps & { isExpanded: bool null ); -const Item = React.forwardRef( - ({ asChild, value: itemValue, disabled, ...props }, ref) => { +function Item({ ref, asChild, value: itemValue, disabled, ...props }: ItemProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { value, orientation, disabled: disabledRoot } = useRootContext(); @@ -133,7 +126,6 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemWebAccordion'; @@ -147,7 +139,7 @@ function useItemContext() { return context; } -const Header = React.forwardRef(({ asChild, ...props }, ref) => { +function Header({ ref, asChild, ...props }: HeaderProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { disabled, isExpanded } = useItemContext(); const { orientation, disabled: disabledRoot } = useRootContext(); @@ -177,7 +169,7 @@ const Header = React.forwardRef(({ asChild, ...props }, ); -}); +} Header.displayName = 'HeaderWebAccordion'; @@ -189,8 +181,7 @@ const HIDDEN_STYLE: React.CSSProperties = { opacity: 0, }; -const Trigger = React.forwardRef( - ({ asChild, disabled: disabledProp, ...props }, ref) => { +function Trigger({ ref, asChild, disabled: disabledProp, ...props }: TriggerProps & { ref?: React.Ref }) { const { disabled: disabledRoot } = useRootContext(); const { disabled, isExpanded } = useItemContext(); const triggerRef = React.useRef(null); @@ -246,12 +237,10 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebAccordion'; -const Content = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Content({ ref, asChild, forceMount, ...props }: ContentProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { orientation, disabled: disabledRoot } = useRootContext(); @@ -283,7 +272,6 @@ const Content = React.forwardRef( ); } -); Content.displayName = 'ContentWebAccordion'; diff --git a/packages/alert-dialog/src/alert-dialog.tsx b/packages/alert-dialog/src/alert-dialog.tsx index ced572d8..9be83762 100644 --- a/packages/alert-dialog/src/alert-dialog.tsx +++ b/packages/alert-dialog/src/alert-dialog.tsx @@ -26,8 +26,7 @@ import type { const AlertDialogContext = React.createContext<(RootContext & { nativeID: string }) | null>(null); -const Root = React.forwardRef( - ({ asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [open = false, onOpenChange] = useControllableState({ prop: openProp, @@ -47,7 +46,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeAlertDialog'; @@ -61,8 +59,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { open: value, onOpenChange } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -82,7 +79,6 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativeAlertDialog'; @@ -105,8 +101,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { ); } -const Overlay = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, ...props }: OverlayProps & { ref?: React.Ref }) { const { open: value } = useRootContext(); if (!forceMount) { @@ -118,12 +113,10 @@ const Overlay = React.forwardRef( const Component = asChild ? Slot.View : View; return ; } -); Overlay.displayName = 'OverlayNativeAlertDialog'; -const Content = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Content({ ref, asChild, forceMount, ...props }: ContentProps & { ref?: React.Ref }) { const { open: value, nativeID, onOpenChange } = useRootContext(); React.useEffect(() => { @@ -156,12 +149,10 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeAlertDialog'; -const Cancel = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Cancel({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: CancelProps & { ref?: React.Ref }) { const { onOpenChange } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -182,12 +173,10 @@ const Cancel = React.forwardRef( /> ); } -); Cancel.displayName = 'CloseNativeAlertDialog'; -const Action = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Action({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: ActionProps & { ref?: React.Ref }) { const { onOpenChange } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -208,25 +197,22 @@ const Action = React.forwardRef( /> ); } -); Action.displayName = 'ActionNativeAlertDialog'; -const Title = React.forwardRef(({ asChild, ...props }, ref) => { +function Title({ ref, asChild, ...props }: TitleProps & { ref?: React.Ref }) { const { nativeID } = useRootContext(); const Component = asChild ? Slot.Text : Text; return ; -}); +} Title.displayName = 'TitleNativeAlertDialog'; -const Description = React.forwardRef( - ({ asChild, ...props }, ref) => { +function Description({ ref, asChild, ...props }: DescriptionProps & { ref?: React.Ref }) { const { nativeID } = useRootContext(); const Component = asChild ? Slot.Text : Text; return ; } -); Description.displayName = 'DescriptionNativeAlertDialog'; diff --git a/packages/alert-dialog/src/alert-dialog.web.tsx b/packages/alert-dialog/src/alert-dialog.web.tsx index e2bfc96f..92ee07c6 100644 --- a/packages/alert-dialog/src/alert-dialog.web.tsx +++ b/packages/alert-dialog/src/alert-dialog.web.tsx @@ -30,8 +30,7 @@ import type { const AlertDialogContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const [open = false, onOpenChange] = useControllableState({ prop: openProp, defaultProp: defaultOpen, @@ -46,7 +45,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootAlertWebDialog'; @@ -60,8 +58,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, role: _role, disabled, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, role: _role, disabled, ...props }: TriggerProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { onOpenChange, open } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -92,7 +89,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerAlertWebDialog'; @@ -100,8 +96,7 @@ function Portal({ forceMount, container, children }: PortalProps) { return ; } -const Overlay = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, ...props }: OverlayProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -109,12 +104,10 @@ const Overlay = React.forwardRef( ); } -); Overlay.displayName = 'OverlayAlertWebDialog'; -const Content = React.forwardRef( - ({ asChild, forceMount, onOpenAutoFocus, onCloseAutoFocus, onEscapeKeyDown, ...props }, ref) => { +function Content({ ref, asChild, forceMount, onOpenAutoFocus, onCloseAutoFocus, onEscapeKeyDown, ...props }: ContentProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { open } = useRootContext(); @@ -138,12 +131,10 @@ const Content = React.forwardRef( ); } -); Content.displayName = 'ContentAlertWebDialog'; -const Cancel = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled, ...props }, ref) => { +function Cancel({ ref, asChild, onPress: onPressProp, disabled, ...props }: CancelProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { onOpenChange, open } = useRootContext(); @@ -176,12 +167,10 @@ const Cancel = React.forwardRef( ); } -); Cancel.displayName = 'CancelAlertWebDialog'; -const Action = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled, ...props }, ref) => { +function Action({ ref, asChild, onPress: onPressProp, disabled, ...props }: ActionProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { onOpenChange, open } = useRootContext(); @@ -214,23 +203,21 @@ const Action = React.forwardRef( ); } -); Action.displayName = 'ActionAlertWebDialog'; -const Title = React.forwardRef(({ asChild, ...props }, ref) => { +function Title({ ref, asChild, ...props }: TitleProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ( ); -}); +} Title.displayName = 'TitleAlertWebDialog'; -const Description = React.forwardRef( - ({ asChild, ...props }, ref) => { +function Description({ ref, asChild, ...props }: DescriptionProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ( @@ -238,7 +225,6 @@ const Description = React.forwardRef( ); } -); Description.displayName = 'DescriptionAlertWebDialog'; diff --git a/packages/aspect-ratio/src/aspect-ratio.tsx b/packages/aspect-ratio/src/aspect-ratio.tsx index c7871b36..8466394c 100644 --- a/packages/aspect-ratio/src/aspect-ratio.tsx +++ b/packages/aspect-ratio/src/aspect-ratio.tsx @@ -10,12 +10,10 @@ type RootProps = Omit & { type RootRef = ViewRef; -const Root = React.forwardRef( - ({ asChild, ratio = 1, style, ...props }, ref) => { +function Root({ ref, asChild, ratio = 1, style, ...props }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; } -); Root.displayName = 'RootAspectRatio'; diff --git a/packages/avatar/src/avatar.tsx b/packages/avatar/src/avatar.tsx index 5d68d434..169e64e6 100644 --- a/packages/avatar/src/avatar.tsx +++ b/packages/avatar/src/avatar.tsx @@ -20,7 +20,7 @@ interface IRootContext extends RootProps { const RootContext = React.createContext(null); -const Root = React.forwardRef(({ asChild, alt, ...viewProps }, ref) => { +function Root({ ref, asChild, alt, ...viewProps }: RootProps & { ref?: React.Ref }) { const [status, setStatus] = React.useState('error'); const Component = asChild ? Slot.View : View; return ( @@ -28,7 +28,7 @@ const Root = React.forwardRef(({ asChild, alt, ...viewProps ); -}); +} Root.displayName = 'RootAvatar'; @@ -40,53 +40,48 @@ function useRootContext() { return context; } -const Image = React.forwardRef( - ( - { asChild, onLoad: onLoadProps, onError: onErrorProps, onLoadingStatusChange, ...props }, - ref - ) => { - const { alt, setStatus, status } = useRootContext(); - - useIsomorphicLayoutEffect(() => { - if (isValidSource(props?.source)) { - setStatus('loading'); - } - - return () => { - setStatus('error'); - }; - }, [props?.source]); - - const onLoad = React.useCallback( - (e: NativeSyntheticEvent) => { - setStatus('loaded'); - onLoadingStatusChange?.('loaded'); - onLoadProps?.(e); - }, - [onLoadProps] - ); - - const onError = React.useCallback( - (e: NativeSyntheticEvent) => { - setStatus('error'); - onLoadingStatusChange?.('error'); - onErrorProps?.(e); - }, - [onErrorProps] - ); - - if (status === 'error') { - return null; +function Image({ ref, asChild, onLoad: onLoadProps, onError: onErrorProps, onLoadingStatusChange, ...props }: ImageProps & { ref?: React.Ref }) { + const { alt, setStatus, status } = useRootContext(); + + useIsomorphicLayoutEffect(() => { + if (isValidSource(props?.source)) { + setStatus('loading'); } - const Component = asChild ? Slot.Image : RNImage; - return ; + return () => { + setStatus('error'); + }; + }, [props?.source]); + + const onLoad = React.useCallback( + (e: NativeSyntheticEvent) => { + setStatus('loaded'); + onLoadingStatusChange?.('loaded'); + onLoadProps?.(e); + }, + [onLoadProps] + ); + + const onError = React.useCallback( + (e: NativeSyntheticEvent) => { + setStatus('error'); + onLoadingStatusChange?.('error'); + onErrorProps?.(e); + }, + [onErrorProps] + ); + + if (status === 'error') { + return null; } -); + + const Component = asChild ? Slot.Image : RNImage; + return ; +} Image.displayName = 'ImageAvatar'; -const Fallback = React.forwardRef(({ asChild, ...props }, ref) => { +function Fallback({ ref, asChild, ...props }: FallbackProps & { ref?: React.Ref }) { const { alt, status } = useRootContext(); if (status !== 'error') { @@ -94,7 +89,7 @@ const Fallback = React.forwardRef(({ asChild, ...pro } const Component = asChild ? Slot.View : View; return ; -}); +} Fallback.displayName = 'FallbackAvatar'; diff --git a/packages/checkbox/src/checkbox.tsx b/packages/checkbox/src/checkbox.tsx index f5a87220..dfe2f655 100644 --- a/packages/checkbox/src/checkbox.tsx +++ b/packages/checkbox/src/checkbox.tsx @@ -10,22 +10,20 @@ interface RootContext extends RootProps { const CheckboxContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, disabled = false, checked, onCheckedChange, nativeID, ...props }, ref) => { - return ( - - - - ); - } -); +function Root({ ref, asChild, disabled = false, checked, onCheckedChange, nativeID, ...props }: RootProps & { ref?: React.Ref }) { + return ( + + + + ); +} Root.displayName = 'RootNativeCheckbox'; @@ -39,61 +37,57 @@ function useCheckboxContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, ...props }, ref) => { - const { disabled, checked, onCheckedChange, nativeID } = useCheckboxContext(); +function Trigger({ ref, asChild, onPress: onPressProp, ...props }: SlottablePressableProps & { ref?: React.Ref }) { + const { disabled, checked, onCheckedChange, nativeID } = useCheckboxContext(); - function onPress(ev: GestureResponderEvent) { - if (disabled) return; - const newValue = !checked; - onCheckedChange(newValue); - onPressProp?.(ev); - } - - const Component = asChild ? Slot.Pressable : Pressable; - return ( - - ); + function onPress(ev: GestureResponderEvent) { + if (disabled) return; + const newValue = !checked; + onCheckedChange(newValue); + onPressProp?.(ev); } -); + + const Component = asChild ? Slot.Pressable : Pressable; + return ( + + ); +} Trigger.displayName = 'TriggerNativeCheckbox'; -const Indicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { - const { checked, disabled } = useCheckboxContext(); +function Indicator({ ref, asChild, forceMount, ...props }: IndicatorProps & { ref?: React.Ref }) { + const { checked, disabled } = useCheckboxContext(); - if (!forceMount) { - if (!checked) { - return null; - } + if (!forceMount) { + if (!checked) { + return null; } - - const Component = asChild ? Slot.View : View; - return ( - - ); } -); + + const Component = asChild ? Slot.View : View; + return ( + + ); +} Indicator.displayName = 'IndicatorNativeCheckbox'; diff --git a/packages/checkbox/src/checkbox.web.tsx b/packages/checkbox/src/checkbox.web.tsx index d59db1ac..e7b3be70 100644 --- a/packages/checkbox/src/checkbox.web.tsx +++ b/packages/checkbox/src/checkbox.web.tsx @@ -7,61 +7,56 @@ import type { IndicatorProps, IndicatorRef, RootProps, RootRef } from './types'; const CheckboxContext = React.createContext(null); -const Root = React.forwardRef( - ( - { asChild, disabled, checked, onCheckedChange, onPress: onPressProp, role: _role, ...props }, - ref - ) => { - const augmentedRef = useAugmentedRef({ ref }); +function Root({ ref, asChild, disabled, checked, onCheckedChange, onPress: onPressProp, role: _role, ...props }: RootProps & { ref?: React.Ref }) { + const augmentedRef = useAugmentedRef({ ref }); - function onPress(ev: GestureResponderEvent) { - onPressProp?.(ev); - onCheckedChange(!checked); - } + function onPress(ev: GestureResponderEvent) { + onPressProp?.(ev); + onCheckedChange(!checked); + } - useIsomorphicLayoutEffect(() => { - if (augmentedRef.current) { - const augRef = augmentedRef.current as unknown as HTMLButtonElement; - augRef.dataset.state = checked ? 'checked' : 'unchecked'; - augRef.value = checked ? 'on' : 'off'; - } - }, [checked]); + useIsomorphicLayoutEffect(() => { + if (augmentedRef.current) { + const augRef = augmentedRef.current as unknown as HTMLButtonElement; + augRef.dataset.state = checked ? 'checked' : 'unchecked'; + augRef.value = checked ? 'on' : 'off'; + } + }, [checked]); - useIsomorphicLayoutEffect(() => { - if (augmentedRef.current) { - const augRef = augmentedRef.current as unknown as HTMLButtonElement; - augRef.type = 'button'; - augRef.role = 'checkbox'; + useIsomorphicLayoutEffect(() => { + if (augmentedRef.current) { + const augRef = augmentedRef.current as unknown as HTMLButtonElement; + augRef.type = 'button'; + augRef.role = 'checkbox'; - if (disabled) { - augRef.dataset.disabled = 'true'; - } else { - augRef.dataset.disabled = undefined; - } + if (disabled) { + augRef.dataset.disabled = 'true'; + } else { + augRef.dataset.disabled = undefined; } - }, [disabled]); + } + }, [disabled]); - const Component = asChild ? Slot.Pressable : Pressable; - return ( - - + + - - - - ); - } -); + {...props} + /> + + + ); +} Root.displayName = 'RootWebCheckbox'; @@ -75,37 +70,35 @@ function useCheckboxContext() { return context; } -const Indicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { - const { checked, disabled } = useCheckboxContext(); - const augmentedRef = useAugmentedRef({ ref }); +function Indicator({ ref, asChild, forceMount, ...props }: IndicatorProps & { ref?: React.Ref }) { + const { checked, disabled } = useCheckboxContext(); + const augmentedRef = useAugmentedRef({ ref }); - useIsomorphicLayoutEffect(() => { - if (augmentedRef.current) { - const augRef = augmentedRef.current as unknown as HTMLDivElement; - augRef.dataset.state = checked ? 'checked' : 'unchecked'; - } - }, [checked]); + useIsomorphicLayoutEffect(() => { + if (augmentedRef.current) { + const augRef = augmentedRef.current as unknown as HTMLDivElement; + augRef.dataset.state = checked ? 'checked' : 'unchecked'; + } + }, [checked]); - useIsomorphicLayoutEffect(() => { - if (augmentedRef.current) { - const augRef = augmentedRef.current as unknown as HTMLDivElement; - if (disabled) { - augRef.dataset.disabled = 'true'; - } else { - augRef.dataset.disabled = undefined; - } + useIsomorphicLayoutEffect(() => { + if (augmentedRef.current) { + const augRef = augmentedRef.current as unknown as HTMLDivElement; + if (disabled) { + augRef.dataset.disabled = 'true'; + } else { + augRef.dataset.disabled = undefined; } - }, [disabled]); + } + }, [disabled]); - const Component = asChild ? Slot.View : View; - return ( - - - - ); - } -); + const Component = asChild ? Slot.View : View; + return ( + + + + ); +} Indicator.displayName = 'IndicatorWebCheckbox'; diff --git a/packages/collapsible/src/collapsible.tsx b/packages/collapsible/src/collapsible.tsx index 12e10f95..625b5cf7 100644 --- a/packages/collapsible/src/collapsible.tsx +++ b/packages/collapsible/src/collapsible.tsx @@ -14,18 +14,13 @@ import type { const CollapsibleContext = React.createContext<(RootContext & { nativeID: string }) | null>(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, disabled = false, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [open = false, onOpenChange] = useControllableState({ prop: openProp, @@ -46,8 +41,7 @@ const Root = React.forwardRef( ); - } -); +} Root.displayName = 'RootNativeCollapsible'; @@ -61,8 +55,7 @@ function useCollapsibleContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled: disabledProp = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled: disabledProp = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { disabled, open, onOpenChange, nativeID } = useCollapsibleContext(); function onPress(ev: GestureResponderEvent) { @@ -87,13 +80,11 @@ const Trigger = React.forwardRef( {...props} /> ); - } -); +} Trigger.displayName = 'TriggerNativeCollapsible'; -const Content = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Content({ ref, asChild, forceMount, ...props }: ContentProps & { ref?: React.Ref }) { const { nativeID, open } = useCollapsibleContext(); if (!forceMount) { @@ -112,8 +103,7 @@ const Content = React.forwardRef( {...props} /> ); - } -); +} Content.displayName = 'ContentNativeCollapsible'; diff --git a/packages/collapsible/src/collapsible.web.tsx b/packages/collapsible/src/collapsible.web.tsx index c7957c10..95a0d3fd 100644 --- a/packages/collapsible/src/collapsible.web.tsx +++ b/packages/collapsible/src/collapsible.web.tsx @@ -19,24 +19,19 @@ import type { const CollapsibleContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, disabled = false, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const [open = false, onOpenChange] = useControllableState({ prop: openProp, defaultProp: defaultOpen, onChange: onOpenChangeProp, }); - const augmentedRef = useAugmentedRef({ ref }); + const augmentedRef = useAugmentedRef({ ref: ref || React.createRef() }); useIsomorphicLayoutEffect(() => { if (augmentedRef.current) { @@ -75,8 +70,7 @@ const Root = React.forwardRef( ); - } -); +} Root.displayName = 'RootWebCollapsible'; @@ -90,10 +84,9 @@ function useCollapsibleContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled: disabledProp = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled: disabledProp = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { disabled, open, onOpenChange } = useCollapsibleContext(); - const augmentedRef = useAugmentedRef({ ref }); + const augmentedRef = useAugmentedRef({ ref: ref || React.createRef() }); useIsomorphicLayoutEffect(() => { if (augmentedRef.current) { @@ -132,14 +125,12 @@ const Trigger = React.forwardRef( /> ); - } -); +} Trigger.displayName = 'TriggerWebCollapsible'; -const Content = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { - const augmentedRef = useAugmentedRef({ ref }); +function Content({ ref, asChild, forceMount, ...props }: ContentProps & { ref?: React.Ref }) { + const augmentedRef = useAugmentedRef({ ref: ref || React.createRef() }); const { open } = useCollapsibleContext(); useIsomorphicLayoutEffect(() => { @@ -155,8 +146,7 @@ const Content = React.forwardRef( ); - } -); +} Content.displayName = 'ContentWebCollapsible'; diff --git a/packages/context-menu/src/context-menu.tsx b/packages/context-menu/src/context-menu.tsx index d004ea85..d9dc94c3 100644 --- a/packages/context-menu/src/context-menu.tsx +++ b/packages/context-menu/src/context-menu.tsx @@ -63,8 +63,7 @@ interface IRootContext extends RootProps { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, relativeTo = 'longPress', onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, relativeTo = 'longPress', onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [pressPosition, setPressPosition] = React.useState(null); const [contentLayout, setContentLayout] = React.useState(null); @@ -93,7 +92,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeContextMenu'; @@ -109,17 +107,12 @@ function useRootContext() { const accessibilityActions = [{ name: 'longpress' }]; -const Trigger = React.forwardRef( - ( - { - asChild, +function Trigger({ ref, asChild, onLongPress: onLongPressProp, disabled = false, onAccessibilityAction: onAccessibilityActionProp, ...props - }, - ref - ) => { + }: TriggerProps & { ref?: React.Ref }) { const { open, onOpenChange, relativeTo, setPressPosition } = useRootContext(); const augmentedRef = useAugmentedRef({ ref, @@ -186,7 +179,6 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativeContextMenu'; @@ -213,8 +205,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { ); } -const Overlay = React.forwardRef( - ({ asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }: OverlayProps & { ref?: React.Ref }) { const { open, onOpenChange, setContentLayout, setPressPosition } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -235,14 +226,10 @@ const Overlay = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayNativeContextMenu'; -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'start', side = 'bottom', @@ -254,9 +241,7 @@ const Content = React.forwardRef( style, disablePositioningStyle, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const { open, onOpenChange, @@ -318,15 +303,10 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeContextMenu'; -const Item = React.forwardRef( - ( - { asChild, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }, - ref - ) => { +function Item({ ref, asChild, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }: ItemProps & { ref?: React.Ref }) { const { onOpenChange, setContentLayout, setPressPosition } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -352,21 +332,20 @@ const Item = React.forwardRef( /> ); } -); Item.displayName = 'ItemNativeContextMenu'; -const Group = React.forwardRef(({ asChild, ...props }, ref) => { +function Group({ ref, asChild, ...props }: GroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Group.displayName = 'GroupNativeContextMenu'; -const Label = React.forwardRef(({ asChild, ...props }, ref) => { +function Label({ ref, asChild, ...props }: LabelProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ; -}); +} Label.displayName = 'LabelNativeContextMenu'; @@ -379,10 +358,7 @@ type FormItemContext = const FormItemContext = React.createContext(null); -const CheckboxItem = React.forwardRef( - ( - { - asChild, +function CheckboxItem({ ref, asChild, checked, onCheckedChange, textValue, @@ -390,9 +366,7 @@ const CheckboxItem = React.forwardRef( closeOnPress = true, disabled = false, ...props - }, - ref - ) => { + }: CheckboxItemProps & { ref?: React.Ref }) { const { onOpenChange, setContentLayout, setPressPosition, nativeID } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -422,7 +396,6 @@ const CheckboxItem = React.forwardRef( ); } -); CheckboxItem.displayName = 'CheckboxItemNativeContextMenu'; @@ -436,8 +409,7 @@ function useFormItemContext() { return context; } -const RadioGroup = React.forwardRef( - ({ asChild, value, onValueChange, ...props }, ref) => { +function RadioGroup({ ref, asChild, value, onValueChange, ...props }: RadioGroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -445,7 +417,6 @@ const RadioGroup = React.forwardRef( ); } -); RadioGroup.displayName = 'RadioGroupNativeContextMenu'; @@ -455,19 +426,14 @@ type BothFormItemContext = Exclude & { const RadioItemContext = React.createContext({} as { itemValue: string }); -const RadioItem = React.forwardRef( - ( - { - asChild, +function RadioItem({ ref, asChild, value: itemValue, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props - }, - ref - ) => { + }: RadioItemProps & { ref?: React.Ref }) { const { onOpenChange, setContentLayout, setPressPosition } = useRootContext(); const { value, onValueChange } = useFormItemContext() as BothFormItemContext; @@ -500,7 +466,6 @@ const RadioItem = React.forwardRef( ); } -); RadioItem.displayName = 'RadioItemNativeContextMenu'; @@ -508,8 +473,7 @@ function useItemIndicatorContext() { return React.useContext(RadioItemContext); } -const ItemIndicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function ItemIndicator({ ref, asChild, forceMount, ...props }: ItemIndicatorProps & { ref?: React.Ref }) { const { itemValue } = useItemIndicatorContext(); const { checked, value } = useFormItemContext() as BothFormItemContext; @@ -524,16 +488,13 @@ const ItemIndicator = React.forwardRef( const Component = asChild ? Slot.View : View; return ; } -); ItemIndicator.displayName = 'ItemIndicatorNativeContextMenu'; -const Separator = React.forwardRef( - ({ asChild, decorative, ...props }, ref) => { +function Separator({ ref, asChild, decorative, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; } -); Separator.displayName = 'SeparatorNativeContextMenu'; @@ -543,8 +504,7 @@ const SubContext = React.createContext<{ onOpenChange: (value: boolean) => void; } | null>(null); -const Sub = React.forwardRef( - ({ asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }, ref) => { +function Sub({ ref, asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }: SubProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [open = false, onOpenChange] = useControllableState({ prop: openProp, @@ -565,7 +525,6 @@ const Sub = React.forwardRef( ); } -); Sub.displayName = 'SubNativeContextMenu'; @@ -577,8 +536,7 @@ function useSubContext() { return context; } -const SubTrigger = React.forwardRef( - ({ asChild, textValue, onPress: onPressProp, disabled = false, ...props }, ref) => { +function SubTrigger({ ref, asChild, textValue, onPress: onPressProp, disabled = false, ...props }: SubTriggerProps & { ref?: React.Ref }) { const { nativeID, open, onOpenChange } = useSubContext(); function onPress(ev: GestureResponderEvent) { @@ -602,12 +560,10 @@ const SubTrigger = React.forwardRef( /> ); } -); SubTrigger.displayName = 'SubTriggerNativeContextMenu'; -const SubContent = React.forwardRef( - ({ asChild = false, forceMount, ...props }, ref) => { +function SubContent({ ref, asChild = false, forceMount, ...props }: SubContentProps & { ref?: React.Ref }) { const { open, nativeID } = useSubContext(); if (!forceMount) { @@ -619,7 +575,6 @@ const SubContent = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Content.displayName = 'ContentNativeContextMenu'; diff --git a/packages/context-menu/src/context-menu.web.tsx b/packages/context-menu/src/context-menu.web.tsx index 5e384b9e..ebebcea9 100644 --- a/packages/context-menu/src/context-menu.web.tsx +++ b/packages/context-menu/src/context-menu.web.tsx @@ -47,8 +47,7 @@ const ContextMenuContext = React.createContext<{ onOpenChange: (open: boolean) => void; } | null>(null); -const Root = React.forwardRef( - ({ asChild, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const [open, setOpen] = React.useState(false); function onOpenChange(value: boolean) { @@ -65,7 +64,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebContextMenu'; @@ -79,8 +77,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { open } = useRootContext(); const augmentedRef = useAugmentedRef({ ref, @@ -119,7 +116,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebContextMenu'; @@ -127,10 +123,10 @@ function Portal({ forceMount, container, children }: PortalProps) { return ; } -const Overlay = React.forwardRef(({ asChild, ...props }, ref) => { +function Overlay({ ref, asChild, ...props }: OverlayProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} Overlay.displayName = 'OverlayWebContextMenu'; @@ -138,10 +134,7 @@ const ContextMenuContentContext = React.createContext<{ close: () => void; } | null>(null); -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align: _align, side: _side, @@ -159,9 +152,7 @@ const Content = React.forwardRef( sticky, hideWhenDetached, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const itemRef = React.useRef(null); function close() { @@ -199,7 +190,6 @@ const Content = React.forwardRef( ); } -); Content.displayName = 'ContentWebContextMenu'; @@ -213,8 +203,7 @@ function useContextMenuContentContext() { return context; } -const Item = React.forwardRef( - ({ asChild, textValue, closeOnPress = true, onPress: onPressProp, ...props }, ref) => { +function Item({ ref, asChild, textValue, closeOnPress = true, onPress: onPressProp, ...props }: ItemProps & { ref?: React.Ref }) { const { close } = useContextMenuContentContext(); function onKeyDown(ev: React.KeyboardEvent) { @@ -245,36 +234,32 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemWebContextMenu'; -const Group = React.forwardRef(({ asChild, ...props }, ref) => { +function Group({ ref, asChild, ...props }: GroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Group.displayName = 'GroupWebContextMenu'; -const Label = React.forwardRef(({ asChild, ...props }, ref) => { +function Label({ ref, asChild, ...props }: LabelProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ( ); -}); +} Label.displayName = 'LabelWebContextMenu'; -const CheckboxItem = React.forwardRef( - ( - { - asChild, +function CheckboxItem({ ref, asChild, checked, onCheckedChange, textValue, @@ -283,9 +268,7 @@ const CheckboxItem = React.forwardRef( onPress: onPressProp, onKeyDown: onKeyDownProp, ...props - }, - ref - ) => { + }: CheckboxItemProps & { ref?: React.Ref }) { const { close } = useContextMenuContentContext(); function onKeyDown(ev: React.KeyboardEvent) { @@ -329,7 +312,6 @@ const CheckboxItem = React.forwardRef( ); } -); CheckboxItem.displayName = 'CheckboxItemWebContextMenu'; @@ -338,8 +320,7 @@ const ContextMenuRadioGroupContext = React.createContext<{ onValueChange?: (value: string) => void; } | null>(null); -const RadioGroup = React.forwardRef( - ({ asChild, value, onValueChange, ...props }, ref) => { +function RadioGroup({ ref, asChild, value, onValueChange, ...props }: RadioGroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -349,7 +330,6 @@ const RadioGroup = React.forwardRef( ); } -); RadioGroup.displayName = 'RadioGroupWebContextMenu'; @@ -363,19 +343,14 @@ function useContextMenuRadioGroupContext() { return context; } -const RadioItem = React.forwardRef( - ( - { - asChild, +function RadioItem({ ref, asChild, value, textValue, closeOnPress = true, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props - }, - ref - ) => { + }: RadioItemProps & { ref?: React.Ref }) { const { onValueChange } = useContextMenuRadioGroupContext(); const { close } = useContextMenuContentContext(); @@ -416,12 +391,10 @@ const RadioItem = React.forwardRef( ); } -); RadioItem.displayName = 'RadioItemWebContextMenu'; -const ItemIndicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function ItemIndicator({ ref, asChild, forceMount, ...props }: ItemIndicatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -429,12 +402,10 @@ const ItemIndicator = React.forwardRef( ); } -); ItemIndicator.displayName = 'ItemIndicatorWebContextMenu'; -const Separator = React.forwardRef( - ({ asChild, decorative, ...props }, ref) => { +function Separator({ ref, asChild, decorative, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -442,7 +413,6 @@ const Separator = React.forwardRef( ); } -); Separator.displayName = 'SeparatorWebContextMenu'; @@ -451,8 +421,7 @@ const ContextMenuSubContext = React.createContext<{ onOpenChange: (open: boolean) => void; } | null>(null); -const Sub = React.forwardRef( - ({ asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }, ref) => { +function Sub({ ref, asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }: SubProps & { ref?: React.Ref }) { const [open = false, onOpenChange] = useControllableState({ prop: openProp, defaultProp: defaultOpen, @@ -468,7 +437,6 @@ const Sub = React.forwardRef( ); } -); Sub.displayName = 'SubWebContextMenu'; @@ -482,8 +450,7 @@ function useSubContext() { return context; } -const SubTrigger = React.forwardRef( - ({ asChild, textValue, disabled = false, onPress: onPressProp, ...props }, ref) => { +function SubTrigger({ ref, asChild, textValue, disabled = false, onPress: onPressProp, ...props }: SubTriggerProps & { ref?: React.Ref }) { const { onOpenChange } = useSubContext(); function onPress(ev: GestureResponderEvent) { @@ -498,12 +465,10 @@ const SubTrigger = React.forwardRef( ); } -); SubTrigger.displayName = 'SubTriggerWebContextMenu'; -const SubContent = React.forwardRef( - ({ asChild = false, forceMount, ...props }, ref) => { +function SubContent({ ref, asChild = false, forceMount, ...props }: SubContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ( @@ -513,7 +478,6 @@ const SubContent = React.forwardRef( ); } -); Content.displayName = 'ContentWebContextMenu'; diff --git a/packages/dialog/src/dialog.tsx b/packages/dialog/src/dialog.tsx index 03657774..601f5298 100644 --- a/packages/dialog/src/dialog.tsx +++ b/packages/dialog/src/dialog.tsx @@ -24,8 +24,7 @@ import type { const DialogContext = React.createContext<(RootContext & { nativeID: string }) | null>(null); -const Root = React.forwardRef( - ({ asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [open = false, onOpenChange] = useControllableState({ prop: openProp, @@ -46,7 +45,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeDialog'; @@ -58,8 +56,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { open, onOpenChange } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -81,7 +78,6 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativeDialog'; @@ -104,8 +100,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { ); } -const Overlay = React.forwardRef( - ({ asChild, forceMount, closeOnPress = true, onPress: OnPressProp, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, closeOnPress = true, onPress: OnPressProp, ...props }: OverlayProps & { ref?: React.Ref }) { const { open, onOpenChange } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -124,12 +119,10 @@ const Overlay = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayNativeDialog'; -const Content = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Content({ ref, asChild, forceMount, ...props }: ContentProps & { ref?: React.Ref }) { const { open, nativeID, onOpenChange } = useRootContext(); React.useEffect(() => { @@ -163,12 +156,10 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeDialog'; -const Close = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Close({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: CloseProps & { ref?: React.Ref }) { const { onOpenChange } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -189,21 +180,20 @@ const Close = React.forwardRef( /> ); } -); Close.displayName = 'CloseNativeDialog'; -const Title = React.forwardRef((props, ref) => { +function Title({ ref, ...props }: TitleProps & { ref?: React.Ref }) { const { nativeID } = useRootContext(); return ; -}); +} Title.displayName = 'TitleNativeDialog'; -const Description = React.forwardRef((props, ref) => { +function Description({ ref, ...props }: DescriptionProps & { ref?: React.Ref }) { const { nativeID } = useRootContext(); return ; -}); +} Description.displayName = 'DescriptionNativeDialog'; diff --git a/packages/dialog/src/dialog.web.tsx b/packages/dialog/src/dialog.web.tsx index a4274588..0676a850 100644 --- a/packages/dialog/src/dialog.web.tsx +++ b/packages/dialog/src/dialog.web.tsx @@ -28,8 +28,7 @@ import type { const DialogContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const [open = false, onOpenChange] = useControllableState({ prop: openProp, defaultProp: defaultOpen, @@ -44,7 +43,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebDialog'; @@ -56,8 +54,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, role: _role, disabled, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, role: _role, disabled, ...props }: TriggerProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { onOpenChange, open } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -88,7 +85,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebDialog'; @@ -96,8 +92,7 @@ function Portal({ forceMount, container, children }: PortalProps) { return ; } -const Overlay = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, ...props }: OverlayProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ( @@ -105,14 +100,10 @@ const Overlay = React.forwardRef( ); } -); Overlay.displayName = 'OverlayWebDialog'; -const Content = React.forwardRef( - ( - { - asChild, +function Content({ ref, asChild, forceMount, onOpenAutoFocus, onCloseAutoFocus, @@ -120,9 +111,7 @@ const Content = React.forwardRef( onInteractOutside, onPointerDownOutside, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Content.displayName = 'ContentWebDialog'; -const Close = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled, ...props }, ref) => { +function Close({ ref, asChild, onPress: onPressProp, disabled, ...props }: CloseProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { onOpenChange, open } = useRootContext(); @@ -175,23 +162,21 @@ const Close = React.forwardRef( ); } -); Close.displayName = 'CloseWebDialog'; -const Title = React.forwardRef(({ asChild, ...props }, ref) => { +function Title({ ref, asChild, ...props }: TitleProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ( ); -}); +} Title.displayName = 'TitleWebDialog'; -const Description = React.forwardRef( - ({ asChild, ...props }, ref) => { +function Description({ ref, asChild, ...props }: DescriptionProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ( @@ -199,7 +184,6 @@ const Description = React.forwardRef( ); } -); Description.displayName = 'DescriptionWebDialog'; diff --git a/packages/dropdown-menu/src/dropdown-menu.tsx b/packages/dropdown-menu/src/dropdown-menu.tsx index 458ef97c..7e264eb5 100644 --- a/packages/dropdown-menu/src/dropdown-menu.tsx +++ b/packages/dropdown-menu/src/dropdown-menu.tsx @@ -62,8 +62,7 @@ interface IRootContext { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [triggerPosition, setTriggerPosition] = React.useState(null); const [contentLayout, setContentLayout] = React.useState(null); @@ -91,7 +90,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeDropdownMenu'; @@ -105,8 +103,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { open, onOpenChange, setTriggerPosition } = useRootContext(); const augmentedRef = useAugmentedRef({ @@ -148,7 +145,6 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativeDropdownMenu'; @@ -175,8 +171,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { ); } -const Overlay = React.forwardRef( - ({ asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }: OverlayProps & { ref?: React.Ref }) { const { open, onOpenChange, setContentLayout, setTriggerPosition } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -197,17 +192,13 @@ const Overlay = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayNativeDropdownMenu'; /** * @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`. */ -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'start', side = 'bottom', @@ -219,9 +210,7 @@ const Content = React.forwardRef( style, disablePositioningStyle, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const { open, onOpenChange, @@ -282,15 +271,10 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeDropdownMenu'; -const Item = React.forwardRef( - ( - { asChild, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }, - ref - ) => { +function Item({ ref, asChild, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }: ItemProps & { ref?: React.Ref }) { const { onOpenChange, setTriggerPosition, setContentLayout } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -316,21 +300,20 @@ const Item = React.forwardRef( /> ); } -); Item.displayName = 'ItemNativeDropdownMenu'; -const Group = React.forwardRef(({ asChild, ...props }, ref) => { +function Group({ ref, asChild, ...props }: GroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Group.displayName = 'GroupNativeDropdownMenu'; -const Label = React.forwardRef(({ asChild, ...props }, ref) => { +function Label({ ref, asChild, ...props }: LabelProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ; -}); +} Label.displayName = 'LabelNativeDropdownMenu'; @@ -343,10 +326,7 @@ type FormItemContext = const FormItemContext = React.createContext(null); -const CheckboxItem = React.forwardRef( - ( - { - asChild, +function CheckboxItem({ ref, asChild, checked, onCheckedChange, textValue, @@ -354,9 +334,7 @@ const CheckboxItem = React.forwardRef( closeOnPress = true, disabled = false, ...props - }, - ref - ) => { + }: CheckboxItemProps & { ref?: React.Ref }) { const { onOpenChange, setContentLayout, setTriggerPosition, nativeID } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -386,7 +364,6 @@ const CheckboxItem = React.forwardRef( ); } -); CheckboxItem.displayName = 'CheckboxItemNativeDropdownMenu'; @@ -400,8 +377,7 @@ function useFormItemContext() { return context; } -const RadioGroup = React.forwardRef( - ({ asChild, value, onValueChange, ...props }, ref) => { +function RadioGroup({ ref, asChild, value, onValueChange, ...props }: RadioGroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -409,7 +385,6 @@ const RadioGroup = React.forwardRef( ); } -); RadioGroup.displayName = 'RadioGroupNativeDropdownMenu'; @@ -419,19 +394,14 @@ type BothFormItemContext = Exclude & { const RadioItemContext = React.createContext({} as { itemValue: string }); -const RadioItem = React.forwardRef( - ( - { - asChild, +function RadioItem({ ref, asChild, value: itemValue, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props - }, - ref - ) => { + }: RadioItemProps & { ref?: React.Ref }) { const { onOpenChange, setContentLayout, setTriggerPosition } = useRootContext(); const { value, onValueChange } = useFormItemContext() as BothFormItemContext; @@ -464,7 +434,6 @@ const RadioItem = React.forwardRef( ); } -); RadioItem.displayName = 'RadioItemNativeDropdownMenu'; @@ -472,8 +441,7 @@ function useItemIndicatorContext() { return React.useContext(RadioItemContext); } -const ItemIndicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function ItemIndicator({ ref, asChild, forceMount, ...props }: ItemIndicatorProps & { ref?: React.Ref }) { const { itemValue } = useItemIndicatorContext(); const { checked, value } = useFormItemContext() as BothFormItemContext; @@ -488,16 +456,13 @@ const ItemIndicator = React.forwardRef( const Component = asChild ? Slot.View : View; return ; } -); ItemIndicator.displayName = 'ItemIndicatorNativeDropdownMenu'; -const Separator = React.forwardRef( - ({ asChild, decorative, ...props }, ref) => { +function Separator({ ref, asChild, decorative, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; } -); Separator.displayName = 'SeparatorNativeDropdownMenu'; @@ -507,8 +472,7 @@ const SubContext = React.createContext<{ onOpenChange: (value: boolean) => void; } | null>(null); -const Sub = React.forwardRef( - ({ asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }, ref) => { +function Sub({ ref, asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }: SubProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [open = false, onOpenChange] = useControllableState({ prop: openProp, @@ -529,7 +493,6 @@ const Sub = React.forwardRef( ); } -); Sub.displayName = 'SubNativeDropdownMenu'; @@ -541,8 +504,7 @@ function useSubContext() { return context; } -const SubTrigger = React.forwardRef( - ({ asChild, textValue, onPress: onPressProp, disabled = false, ...props }, ref) => { +function SubTrigger({ ref, asChild, textValue, onPress: onPressProp, disabled = false, ...props }: SubTriggerProps & { ref?: React.Ref }) { const { nativeID, open, onOpenChange } = useSubContext(); function onPress(ev: GestureResponderEvent) { @@ -566,12 +528,10 @@ const SubTrigger = React.forwardRef( /> ); } -); SubTrigger.displayName = 'SubTriggerNativeDropdownMenu'; -const SubContent = React.forwardRef( - ({ asChild = false, forceMount, ...props }, ref) => { +function SubContent({ ref, asChild = false, forceMount, ...props }: SubContentProps & { ref?: React.Ref }) { const { open, nativeID } = useSubContext(); if (!forceMount) { @@ -583,7 +543,6 @@ const SubContent = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Content.displayName = 'ContentNativeDropdownMenu'; diff --git a/packages/dropdown-menu/src/dropdown-menu.web.tsx b/packages/dropdown-menu/src/dropdown-menu.web.tsx index bf1e558c..17faaeef 100644 --- a/packages/dropdown-menu/src/dropdown-menu.web.tsx +++ b/packages/dropdown-menu/src/dropdown-menu.web.tsx @@ -47,8 +47,7 @@ const DropdownMenuContext = React.createContext<{ onOpenChange: (open: boolean) => void; } | null>(null); -const Root = React.forwardRef( - ({ asChild, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const [open, setOpen] = React.useState(false); function onOpenChange(open: boolean) { @@ -65,7 +64,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebDropdownMenu'; @@ -79,8 +77,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { open, onOpenChange } = useRootContext(); const augmentedRef = useAugmentedRef({ ref, @@ -119,7 +116,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebDropdownMenu'; @@ -127,10 +123,10 @@ function Portal({ forceMount, container, children }: PortalProps) { return ; } -const Overlay = React.forwardRef(({ asChild, ...props }, ref) => { +function Overlay({ ref, asChild, ...props }: OverlayProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} Overlay.displayName = 'OverlayWebDropdownMenu'; @@ -138,10 +134,7 @@ const DropdownMenuContentContext = React.createContext<{ close: () => void; } | null>(null); -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align, side, @@ -159,9 +152,7 @@ const Content = React.forwardRef( sticky, hideWhenDetached, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const itemRef = React.useRef(null); function close() { @@ -201,7 +192,6 @@ const Content = React.forwardRef( ); } -); Content.displayName = 'ContentWebDropdownMenu'; @@ -215,18 +205,13 @@ function useDropdownMenuContentContext() { return context; } -const Item = React.forwardRef( - ( - { - asChild, +function Item({ ref, asChild, textValue, closeOnPress = true, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props - }, - ref - ) => { + }: ItemProps & { ref?: React.Ref }) { const { close } = useDropdownMenuContentContext(); function onKeyDown(ev: React.KeyboardEvent) { @@ -264,36 +249,32 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemWebDropdownMenu'; -const Group = React.forwardRef(({ asChild, ...props }, ref) => { +function Group({ ref, asChild, ...props }: GroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Group.displayName = 'GroupWebDropdownMenu'; -const Label = React.forwardRef(({ asChild, ...props }, ref) => { +function Label({ ref, asChild, ...props }: LabelProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ( ); -}); +} Label.displayName = 'LabelWebDropdownMenu'; -const CheckboxItem = React.forwardRef( - ( - { - asChild, +function CheckboxItem({ ref, asChild, checked, onCheckedChange, textValue, @@ -302,9 +283,7 @@ const CheckboxItem = React.forwardRef( onPress: onPressProp, onKeyDown: onKeyDownProp, ...props - }, - ref - ) => { + }: CheckboxItemProps & { ref?: React.Ref }) { const { close } = useDropdownMenuContentContext(); function onKeyDown(ev: React.KeyboardEvent) { @@ -346,7 +325,6 @@ const CheckboxItem = React.forwardRef( ); } -); CheckboxItem.displayName = 'CheckboxItemWebDropdownMenu'; @@ -355,8 +333,7 @@ const DropdownMenuRadioGroupContext = React.createContext<{ onValueChange?: (value: string) => void; } | null>(null); -const RadioGroup = React.forwardRef( - ({ asChild, value, onValueChange, ...props }, ref) => { +function RadioGroup({ ref, asChild, value, onValueChange, ...props }: RadioGroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -366,7 +343,6 @@ const RadioGroup = React.forwardRef( ); } -); RadioGroup.displayName = 'RadioGroupWebDropdownMenu'; @@ -380,19 +356,14 @@ function useDropdownMenuRadioGroupContext() { return context; } -const RadioItem = React.forwardRef( - ( - { - asChild, +function RadioItem({ ref, asChild, value, textValue, closeOnPress = true, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props - }, - ref - ) => { + }: RadioItemProps & { ref?: React.Ref }) { const { onValueChange } = useDropdownMenuRadioGroupContext(); const { close } = useDropdownMenuContentContext(); @@ -433,12 +404,10 @@ const RadioItem = React.forwardRef( ); } -); RadioItem.displayName = 'RadioItemWebDropdownMenu'; -const ItemIndicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function ItemIndicator({ ref, asChild, forceMount, ...props }: ItemIndicatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -446,12 +415,10 @@ const ItemIndicator = React.forwardRef( ); } -); ItemIndicator.displayName = 'ItemIndicatorWebDropdownMenu'; -const Separator = React.forwardRef( - ({ asChild, decorative, ...props }, ref) => { +function Separator({ ref, asChild, decorative, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -459,7 +426,6 @@ const Separator = React.forwardRef( ); } -); Separator.displayName = 'SeparatorWebDropdownMenu'; @@ -468,8 +434,7 @@ const DropdownMenuSubContext = React.createContext<{ onOpenChange: (open: boolean) => void; } | null>(null); -const Sub = React.forwardRef( - ({ asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }, ref) => { +function Sub({ ref, asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }: SubProps & { ref?: React.Ref }) { const [open = false, onOpenChange] = useControllableState({ prop: openProp, defaultProp: defaultOpen, @@ -485,7 +450,6 @@ const Sub = React.forwardRef( ); } -); Sub.displayName = 'SubWebDropdownMenu'; @@ -499,8 +463,7 @@ function useSubContext() { return context; } -const SubTrigger = React.forwardRef( - ({ asChild, textValue, disabled = false, onPress: onPressProp, ...props }, ref) => { +function SubTrigger({ ref, asChild, textValue, disabled = false, onPress: onPressProp, ...props }: SubTriggerProps & { ref?: React.Ref }) { const { onOpenChange } = useSubContext(); function onPress(ev: GestureResponderEvent) { @@ -515,12 +478,10 @@ const SubTrigger = React.forwardRef( ); } -); SubTrigger.displayName = 'SubTriggerWebDropdownMenu'; -const SubContent = React.forwardRef( - ({ asChild = false, forceMount, ...props }, ref) => { +function SubContent({ ref, asChild = false, forceMount, ...props }: SubContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ( @@ -530,7 +491,6 @@ const SubContent = React.forwardRef( ); } -); Content.displayName = 'ContentWebDropdownMenu'; diff --git a/packages/hover-card/src/hover-card.tsx b/packages/hover-card/src/hover-card.tsx index 1915c629..cd6b7884 100644 --- a/packages/hover-card/src/hover-card.tsx +++ b/packages/hover-card/src/hover-card.tsx @@ -35,17 +35,12 @@ interface IRootContext extends SharedRootContext { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, openDelay: _openDelay, closeDelay: _closeDelay, onOpenChange: onOpenChangeProp, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [triggerPosition, setTriggerPosition] = React.useState(null); const [contentLayout, setContentLayout] = React.useState(null); @@ -73,7 +68,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeHoverCard'; @@ -87,8 +81,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { open, onOpenChange, setTriggerPosition } = useRootContext(); const augmentedRef = useAugmentedRef({ @@ -129,7 +122,6 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativeHoverCard'; @@ -156,8 +148,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { ); } -const Overlay = React.forwardRef( - ({ asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }: OverlayProps & { ref?: React.Ref }) { const { open, onOpenChange, setTriggerPosition, setContentLayout } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -178,17 +169,13 @@ const Overlay = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayNativeHoverCard'; /** * @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`. */ -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'start', side = 'bottom', @@ -200,9 +187,7 @@ const Content = React.forwardRef( style, disablePositioningStyle, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const { open, onOpenChange, @@ -264,7 +249,6 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeHoverCard'; diff --git a/packages/hover-card/src/hover-card.web.tsx b/packages/hover-card/src/hover-card.web.tsx index b35915cd..d407b7aa 100644 --- a/packages/hover-card/src/hover-card.web.tsx +++ b/packages/hover-card/src/hover-card.web.tsx @@ -18,8 +18,7 @@ import type { const HoverCardContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, openDelay, closeDelay, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, openDelay, closeDelay, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const [open, setOpen] = React.useState(false); function onOpenChange(value: boolean) { @@ -41,7 +40,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebHoverCard'; @@ -55,7 +53,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef(({ asChild, ...props }, ref) => { +function Trigger({ ref, asChild, ...props }: TriggerProps & { ref?: React.Ref }) { const { onOpenChange } = useRootContext(); const augmentedRef = useAugmentedRef({ ref, @@ -75,7 +73,7 @@ const Trigger = React.forwardRef(({ asChild, ...props ); -}); +} Trigger.displayName = 'TriggerWebHoverCard'; @@ -83,17 +81,14 @@ function Portal({ forceMount, container, children }: PortalProps) { return ; } -const Overlay = React.forwardRef(({ asChild, ...props }, ref) => { +function Overlay({ ref, asChild, ...props }: OverlayProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} Overlay.displayName = 'OverlayWebHoverCard'; -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align, side, @@ -111,9 +106,7 @@ const Content = React.forwardRef( sticky, hideWhenDetached, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ( ( ); } -); Content.displayName = 'ContentWebHoverCard'; diff --git a/packages/label/src/label.tsx b/packages/label/src/label.tsx index f9b69016..86c979c7 100644 --- a/packages/label/src/label.tsx +++ b/packages/label/src/label.tsx @@ -3,17 +3,17 @@ import * as React from 'react'; import { Pressable, Text as RNText } from 'react-native'; import type { RootProps, RootRef, TextProps, TextRef } from './types'; -const Root = React.forwardRef(({ asChild, ...props }, ref) => { +function Root({ ref, asChild, ...props }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} Root.displayName = 'RootNativeLabel'; -const Text = React.forwardRef(({ asChild, ...props }, ref) => { +function Text({ ref, asChild, ...props }: TextProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : RNText; return ; -}); +} Text.displayName = 'TextNativeLabel'; diff --git a/packages/label/src/label.web.tsx b/packages/label/src/label.web.tsx index f7750e94..67b0be18 100644 --- a/packages/label/src/label.web.tsx +++ b/packages/label/src/label.web.tsx @@ -4,23 +4,21 @@ import * as React from 'react'; import { Pressable, Text as RNText } from 'react-native'; import type { RootProps, RootRef, TextProps, TextRef } from './types'; -const Root = React.forwardRef(({ asChild, tabIndex = -1, ...props }, ref) => { +function Root({ ref, asChild, tabIndex = -1, ...props }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} Root.displayName = 'RootWebLabel'; -const Text = React.forwardRef( - ({ asChild, nativeID, htmlFor, ...props }, ref) => { - const Component = asChild ? Slot.Text : RNText; - return ( - - - - ); - } -); +function Text({ ref, asChild, nativeID, htmlFor, ...props }: TextProps & { ref?: React.Ref }) { + const Component = asChild ? Slot.Text : RNText; + return ( + + + + ); +} Text.displayName = 'TextWebLabel'; diff --git a/packages/menubar/src/menubar.tsx b/packages/menubar/src/menubar.tsx index 5451007a..b518ae54 100644 --- a/packages/menubar/src/menubar.tsx +++ b/packages/menubar/src/menubar.tsx @@ -62,8 +62,7 @@ interface IMenuContext extends RootProps { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, value, onValueChange, ...viewProps }, ref) => { +function Root({ ref, asChild, value, onValueChange, ...viewProps }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [triggerPosition, setTriggerPosition] = React.useState(null); const [contentLayout, setContentLayout] = React.useState(null); @@ -85,7 +84,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootMenubar'; @@ -99,7 +97,7 @@ function useRootContext() { const MenuContext = React.createContext(null); -const Menu = React.forwardRef(({ asChild, value, ...viewProps }, ref) => { +function Menu({ ref, asChild, value, ...viewProps }: MenuProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( (({ asChild, value, ...viewProp ); -}); +} Menu.displayName = 'MenuMenubar'; @@ -122,8 +120,7 @@ function useMenuContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const triggerRef = useAugmentedRef({ ref }); const { value, onValueChange, setTriggerPosition } = useRootContext(); const { value: menuValue } = useMenuContext(); @@ -151,7 +148,6 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerMenubar'; @@ -183,8 +179,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { ); } -const Overlay = React.forwardRef( - ({ asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }: OverlayProps & { ref?: React.Ref }) { const { value, onValueChange, setContentLayout, setTriggerPosition } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -205,17 +200,13 @@ const Overlay = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayMenubar'; /** * @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`. */ -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'start', side = 'bottom', @@ -227,9 +218,7 @@ const Content = React.forwardRef( style, disablePositioningStyle, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const { value, onValueChange, @@ -292,15 +281,10 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentMenubar'; -const Item = React.forwardRef( - ( - { asChild, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }, - ref - ) => { +function Item({ ref, asChild, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }: ItemProps & { ref?: React.Ref }) { const { onValueChange, setContentLayout, setTriggerPosition } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -326,21 +310,20 @@ const Item = React.forwardRef( /> ); } -); Item.displayName = 'ItemMenubar'; -const Group = React.forwardRef(({ asChild, ...props }, ref) => { +function Group({ ref, asChild, ...props }: GroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Group.displayName = 'GroupMenubar'; -const Label = React.forwardRef(({ asChild, ...props }, ref) => { +function Label({ ref, asChild, ...props }: LabelProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ; -}); +} Label.displayName = 'LabelMenubar'; @@ -353,10 +336,7 @@ type FormItemContext = const FormItemContext = React.createContext(null); -const CheckboxItem = React.forwardRef( - ( - { - asChild, +function CheckboxItem({ ref, asChild, checked, onCheckedChange, textValue, @@ -364,9 +344,7 @@ const CheckboxItem = React.forwardRef( closeOnPress = true, disabled = false, ...props - }, - ref - ) => { + }: CheckboxItemProps & { ref?: React.Ref }) { const { onValueChange, setTriggerPosition, setContentLayout, nativeID } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -396,7 +374,6 @@ const CheckboxItem = React.forwardRef( ); } -); CheckboxItem.displayName = 'CheckboxItemMenubar'; @@ -410,8 +387,7 @@ function useFormItemContext() { return context; } -const RadioGroup = React.forwardRef( - ({ asChild, value, onValueChange, ...props }, ref) => { +function RadioGroup({ ref, asChild, value, onValueChange, ...props }: RadioGroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -419,7 +395,6 @@ const RadioGroup = React.forwardRef( ); } -); RadioGroup.displayName = 'RadioGroupMenubar'; @@ -429,19 +404,14 @@ type BothFormItemContext = Exclude & { const RadioItemContext = React.createContext({} as { itemValue: string }); -const RadioItem = React.forwardRef( - ( - { - asChild, +function RadioItem({ ref, asChild, value: itemValue, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props - }, - ref - ) => { + }: RadioItemProps & { ref?: React.Ref }) { const { onValueChange: onRootValueChange, setTriggerPosition, @@ -478,7 +448,6 @@ const RadioItem = React.forwardRef( ); } -); RadioItem.displayName = 'RadioItemMenubar'; @@ -486,8 +455,7 @@ function useItemIndicatorContext() { return React.useContext(RadioItemContext); } -const ItemIndicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function ItemIndicator({ ref, asChild, forceMount, ...props }: ItemIndicatorProps & { ref?: React.Ref }) { const { itemValue } = useItemIndicatorContext(); const { checked, value } = useFormItemContext() as BothFormItemContext; @@ -502,16 +470,13 @@ const ItemIndicator = React.forwardRef( const Component = asChild ? Slot.View : View; return ; } -); ItemIndicator.displayName = 'ItemIndicatorMenubar'; -const Separator = React.forwardRef( - ({ asChild, decorative, ...props }, ref) => { +function Separator({ ref, asChild, decorative, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; } -); Separator.displayName = 'SeparatorMenubar'; @@ -521,8 +486,7 @@ const SubContext = React.createContext<{ onOpenChange: (value: boolean) => void; } | null>(null); -const Sub = React.forwardRef( - ({ asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }, ref) => { +function Sub({ ref, asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }: SubProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [open = false, onOpenChange] = useControllableState({ prop: openProp, @@ -543,7 +507,6 @@ const Sub = React.forwardRef( ); } -); Sub.displayName = 'SubMenubar'; @@ -555,8 +518,7 @@ function useSubContext() { return context; } -const SubTrigger = React.forwardRef( - ({ asChild, textValue, onPress: onPressProp, disabled = false, ...props }, ref) => { +function SubTrigger({ ref, asChild, textValue, onPress: onPressProp, disabled = false, ...props }: SubTriggerProps & { ref?: React.Ref }) { const { nativeID, open, onOpenChange } = useSubContext(); function onPress(ev: GestureResponderEvent) { @@ -580,12 +542,10 @@ const SubTrigger = React.forwardRef( /> ); } -); SubTrigger.displayName = 'SubTriggerMenubar'; -const SubContent = React.forwardRef( - ({ asChild = false, forceMount, ...props }, ref) => { +function SubContent({ ref, asChild = false, forceMount, ...props }: SubContentProps & { ref?: React.Ref }) { const { open, nativeID } = useSubContext(); if (!forceMount) { @@ -597,7 +557,6 @@ const SubContent = React.forwardRef( const Component = asChild ? Slot.View : View; return ; } -); SubContent.displayName = 'SubContentMenubar'; diff --git a/packages/menubar/src/menubar.web.tsx b/packages/menubar/src/menubar.web.tsx index 8fc6e964..419a9c63 100644 --- a/packages/menubar/src/menubar.web.tsx +++ b/packages/menubar/src/menubar.web.tsx @@ -46,8 +46,7 @@ import type { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, value, onValueChange, ...viewProps }, ref) => { +function Root({ ref, asChild, value, onValueChange, ...viewProps }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -57,7 +56,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebMenubar'; @@ -71,7 +69,7 @@ function useRootContext() { const MenuContext = React.createContext(null); -const Menu = React.forwardRef(({ asChild, value, ...viewProps }, ref) => { +function Menu({ ref, asChild, value, ...viewProps }: MenuProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -80,7 +78,7 @@ const Menu = React.forwardRef(({ asChild, value, ...viewProp ); -}); +} Menu.displayName = 'MenuWebMenubar'; @@ -92,8 +90,7 @@ function useMenuContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { value: menuValue } = useMenuContext(); const { value } = useRootContext(); @@ -123,7 +120,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebMenubar'; @@ -131,10 +127,10 @@ function Portal({ forceMount, container, children }: PortalProps) { return ; } -const Overlay = React.forwardRef(({ asChild, ...props }, ref) => { +function Overlay({ ref, asChild, ...props }: OverlayProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} Overlay.displayName = 'OverlayWebMenubar'; @@ -142,10 +138,7 @@ const MenubarContentContext = React.createContext<{ close: () => void; } | null>(null); -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align, side, @@ -163,9 +156,7 @@ const Content = React.forwardRef( sticky, hideWhenDetached, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const itemRef = React.useRef(null); function close() { @@ -206,7 +197,6 @@ const Content = React.forwardRef( ); } -); Content.displayName = 'ContentWebMenubar'; @@ -220,18 +210,13 @@ function useMenubarContentContext() { return context; } -const Item = React.forwardRef( - ( - { - asChild, +function Item({ ref, asChild, textValue, closeOnPress = true, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props - }, - ref - ) => { + }: ItemProps & { ref?: React.Ref }) { const { close } = useMenubarContentContext(); function onKeyDown(ev: React.KeyboardEvent) { @@ -269,36 +254,32 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemWebMenubar'; -const Group = React.forwardRef(({ asChild, ...props }, ref) => { +function Group({ ref, asChild, ...props }: GroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Group.displayName = 'GroupWebMenubar'; -const Label = React.forwardRef(({ asChild, ...props }, ref) => { +function Label({ ref, asChild, ...props }: LabelProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ( ); -}); +} Label.displayName = 'LabelWebMenubar'; -const CheckboxItem = React.forwardRef( - ( - { - asChild, +function CheckboxItem({ ref, asChild, checked, onCheckedChange, textValue, @@ -307,9 +288,7 @@ const CheckboxItem = React.forwardRef( onPress: onPressProp, onKeyDown: onKeyDownProp, ...props - }, - ref - ) => { + }: CheckboxItemProps & { ref?: React.Ref }) { function onKeyDown(ev: React.KeyboardEvent) { onKeyDownProp?.(ev); if (ev.key === 'Enter' || ev.key === ' ') { @@ -349,7 +328,6 @@ const CheckboxItem = React.forwardRef( ); } -); CheckboxItem.displayName = 'CheckboxItemWebMenubar'; @@ -358,8 +336,7 @@ const MenubarRadioGroupContext = React.createContext<{ onValueChange?: (value: string) => void; } | null>(null); -const RadioGroup = React.forwardRef( - ({ asChild, value, onValueChange, ...props }, ref) => { +function RadioGroup({ ref, asChild, value, onValueChange, ...props }: RadioGroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -369,7 +346,6 @@ const RadioGroup = React.forwardRef( ); } -); RadioGroup.displayName = 'RadioGroupWebMenubar'; @@ -383,19 +359,14 @@ function useMenubarRadioGroupContext() { return context; } -const RadioItem = React.forwardRef( - ( - { - asChild, +function RadioItem({ ref, asChild, value, textValue, closeOnPress = true, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props - }, - ref - ) => { + }: RadioItemProps & { ref?: React.Ref }) { const { onValueChange } = useMenubarRadioGroupContext(); const { close } = useMenubarContentContext(); @@ -436,12 +407,10 @@ const RadioItem = React.forwardRef( ); } -); RadioItem.displayName = 'RadioItemWebMenubar'; -const ItemIndicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function ItemIndicator({ ref, asChild, forceMount, ...props }: ItemIndicatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -449,12 +418,10 @@ const ItemIndicator = React.forwardRef( ); } -); ItemIndicator.displayName = 'ItemIndicatorWebMenubar'; -const Separator = React.forwardRef( - ({ asChild, decorative, ...props }, ref) => { +function Separator({ ref, asChild, decorative, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -462,7 +429,6 @@ const Separator = React.forwardRef( ); } -); Separator.displayName = 'SeparatorWebMenubar'; @@ -471,8 +437,7 @@ const MenubarSubContext = React.createContext<{ onOpenChange: (open: boolean) => void; } | null>(null); -const Sub = React.forwardRef( - ({ asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }, ref) => { +function Sub({ ref, asChild, defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }: SubProps & { ref?: React.Ref }) { const [open = false, onOpenChange] = useControllableState({ prop: openProp, defaultProp: defaultOpen, @@ -487,7 +452,6 @@ const Sub = React.forwardRef( ); } -); Sub.displayName = 'SubWebMenubar'; @@ -501,8 +465,7 @@ function useSubContext() { return context; } -const SubTrigger = React.forwardRef( - ({ asChild, textValue, disabled = false, onPress: onPressProp, ...props }, ref) => { +function SubTrigger({ ref, asChild, textValue, disabled = false, onPress: onPressProp, ...props }: SubTriggerProps & { ref?: React.Ref }) { const { onOpenChange } = useSubContext(); function onPress(ev: GestureResponderEvent) { @@ -517,12 +480,10 @@ const SubTrigger = React.forwardRef( ); } -); SubTrigger.displayName = 'SubTriggerWebMenubar'; -const SubContent = React.forwardRef( - ({ asChild = false, forceMount, ...props }, ref) => { +function SubContent({ ref, asChild = false, forceMount, ...props }: SubContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -532,7 +493,6 @@ const SubContent = React.forwardRef( ); } -); Content.displayName = 'ContentWebMenubar'; diff --git a/packages/navigation-menu/src/navigation-menu.tsx b/packages/navigation-menu/src/navigation-menu.tsx index 51cd15c7..2f421e6c 100644 --- a/packages/navigation-menu/src/navigation-menu.tsx +++ b/packages/navigation-menu/src/navigation-menu.tsx @@ -40,8 +40,7 @@ interface INavigationMenuRootContext extends RootProps { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, value, onValueChange, ...viewProps }, ref) => { +function Root({ ref, asChild, value, onValueChange, ...viewProps }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [triggerPosition, setTriggerPosition] = React.useState(null); const [contentLayout, setContentLayout] = React.useState(null); @@ -63,7 +62,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeNavigationMenu'; @@ -77,16 +75,16 @@ function useRootContext() { return context; } -const List = React.forwardRef(({ asChild, ...viewProps }, ref) => { +function List({ ref, asChild, ...viewProps }: ListProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} List.displayName = 'ListNativeNavigationMenu'; const ItemContext = React.createContext<(ItemProps & { nativeID: string }) | null>(null); -const Item = React.forwardRef(({ asChild, value, ...viewProps }, ref) => { +function Item({ ref, asChild, value, ...viewProps }: ItemProps & { ref?: React.Ref }) { const nativeID = React.useId(); const Component = asChild ? Slot.View : View; @@ -100,7 +98,7 @@ const Item = React.forwardRef(({ asChild, value, ...viewProp ); -}); +} Item.displayName = 'ItemNativeNavigationMenu'; @@ -114,8 +112,7 @@ function useItemContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const triggerRef = React.useRef(null); const { value, onValueChange, setTriggerPosition } = useRootContext(); const { value: menuValue } = useItemContext(); @@ -154,7 +151,6 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativeNavigationMenu'; @@ -190,10 +186,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { /** * @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`. */ -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'center', side = 'bottom', @@ -205,9 +198,7 @@ const Content = React.forwardRef( style, disablePositioningStyle, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const { value, onValueChange, @@ -269,27 +260,26 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeNavigationMenu'; -const Link = React.forwardRef(({ asChild, ...props }, ref) => { +function Link({ ref, asChild, ...props }: LinkProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} Link.displayName = 'LinkNativeNavigationMenu'; -const Viewport = React.forwardRef((props, ref) => { +function Viewport({ ref, ...props }: ViewportProps & { ref?: React.Ref }) { return ; -}); +} Viewport.displayName = 'ViewportNativeNavigationMenu'; -const Indicator = React.forwardRef(({ asChild, ...props }, ref) => { +function Indicator({ ref, asChild, ...props }: IndicatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Indicator.displayName = 'IndicatorNativeNavigationMenu'; diff --git a/packages/navigation-menu/src/navigation-menu.web.tsx b/packages/navigation-menu/src/navigation-menu.web.tsx index d9ab6fc3..642beb3a 100644 --- a/packages/navigation-menu/src/navigation-menu.web.tsx +++ b/packages/navigation-menu/src/navigation-menu.web.tsx @@ -26,10 +26,7 @@ import type { const NavigationMenuContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, value, onValueChange, delayDuration, @@ -37,9 +34,7 @@ const Root = React.forwardRef( dir, orientation, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -56,7 +51,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebNavigationMenu'; @@ -70,7 +64,7 @@ function useRootContext() { return context; } -const List = React.forwardRef(({ asChild, ...viewProps }, ref) => { +function List({ ref, asChild, ...viewProps }: ListProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { orientation } = useRootContext(); @@ -87,13 +81,13 @@ const List = React.forwardRef(({ asChild, ...viewProps }, re ); -}); +} List.displayName = 'ListWebNavigationMenu'; const ItemContext = React.createContext(null); -const Item = React.forwardRef(({ asChild, value, ...props }, ref) => { +function Item({ ref, asChild, value, ...props }: ItemProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -102,7 +96,7 @@ const Item = React.forwardRef(({ asChild, value, ...props }, ); -}); +} Item.displayName = 'ItemWebNavigationMenu'; @@ -116,11 +110,7 @@ function useItemContext() { return context; } -const Trigger = React.forwardRef( - ( - { asChild, onPress: onPressProp, disabled = false, onKeyDown: onKeyDownProp, ...props }, - ref - ) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, onKeyDown: onKeyDownProp, ...props }: TriggerProps & { ref?: React.Ref }) { const { value: rootValue, onValueChange } = useRootContext(); const { value } = useItemContext(); function onKeyDown(ev: React.KeyboardEvent) { @@ -149,7 +139,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebNavigationMenu'; @@ -157,10 +146,7 @@ function Portal({ children }: PortalProps) { return <>{children}; } -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align: _align, side: _side, @@ -175,9 +161,7 @@ const Content = React.forwardRef( onFocusOutside, onInteractOutside, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Content.displayName = 'ContentWebNavigationMenu'; -const Link = React.forwardRef( - ({ asChild, active, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props }, ref) => { +function Link({ ref, asChild, active, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props }: LinkProps & { ref?: React.Ref }) { const { onValueChange } = useRootContext(); function onKeyDown(ev: React.KeyboardEvent) { onKeyDownProp?.(ev); @@ -225,28 +207,27 @@ const Link = React.forwardRef( ); } -); Link.displayName = 'LinkWebNavigationMenu'; -const Viewport = React.forwardRef((props, ref) => { +function Viewport({ ref, ...props }: ViewportProps & { ref?: React.Ref }) { return ( ); -}); +} Viewport.displayName = 'ViewportWebNavigationMenu'; -const Indicator = React.forwardRef(({ asChild, ...props }, ref) => { +function Indicator({ ref, asChild, ...props }: IndicatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Indicator.displayName = 'IndicatorWebNavigationMenu'; diff --git a/packages/popover/src/popover.tsx b/packages/popover/src/popover.tsx index 7da87de7..3c13ead4 100644 --- a/packages/popover/src/popover.tsx +++ b/packages/popover/src/popover.tsx @@ -36,8 +36,7 @@ interface IRootContext { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { +function Root({ ref, asChild, onOpenChange: onOpenChangeProp, ...viewProps }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [triggerPosition, setTriggerPosition] = React.useState(null); const [contentLayout, setContentLayout] = React.useState(null); @@ -65,7 +64,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativePopover'; @@ -77,8 +75,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { onOpenChange, open, setTriggerPosition } = useRootContext(); const augmentedRef = useAugmentedRef({ @@ -118,7 +115,6 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativePopover'; @@ -145,8 +141,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { ); } -const Overlay = React.forwardRef( - ({ asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }: OverlayProps & { ref?: React.Ref }) { const { open, onOpenChange, setTriggerPosition, setContentLayout } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -167,17 +162,13 @@ const Overlay = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayNativePopover'; /** * @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`. */ -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'start', side = 'bottom', @@ -190,9 +181,7 @@ const Content = React.forwardRef( disablePositioningStyle, onOpenAutoFocus: _onOpenAutoFocus, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const { open, onOpenChange, @@ -254,12 +243,10 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativePopover'; -const Close = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Close({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: CloseProps & { ref?: React.Ref }) { const { onOpenChange, setContentLayout, setTriggerPosition } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -282,7 +269,6 @@ const Close = React.forwardRef( /> ); } -); Close.displayName = 'CloseNativePopover'; diff --git a/packages/popover/src/popover.web.tsx b/packages/popover/src/popover.web.tsx index 2ebcdc95..e2337271 100644 --- a/packages/popover/src/popover.web.tsx +++ b/packages/popover/src/popover.web.tsx @@ -22,24 +22,22 @@ const RootContext = React.createContext<{ onOpenChange: (open: boolean) => void; } | null>(null); -const Root = React.forwardRef void }>( - ({ asChild, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => { - const [open, setOpen] = React.useState(false); +function Root({ ref, asChild, onOpenChange: onOpenChangeProp, ...viewProps }: (RootProps & { onOpenChange?: (open: boolean) => void }) & { ref?: React.Ref }) { + const [open, setOpen] = React.useState(false); - function onOpenChange(value: boolean) { - setOpen(value); - onOpenChangeProp?.(value); - } - const Component = asChild ? Slot.View : View; - return ( - - - - - - ); + function onOpenChange(value: boolean) { + setOpen(value); + onOpenChangeProp?.(value); } -); + const Component = asChild ? Slot.View : View; + return ( + + + + + + ); +} Root.displayName = 'RootWebPopover'; @@ -51,8 +49,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, role: _role, disabled, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, role: _role, disabled, ...props }: TriggerProps & { ref?: React.Ref }) { const { onOpenChange, open } = useRootContext(); const augmentedRef = useAugmentedRef({ ref, @@ -93,7 +90,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebPopover'; @@ -101,19 +97,14 @@ function Portal({ forceMount, container, children }: PortalProps) { return ; } -const Overlay = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, ...props }: OverlayProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayWebPopover'; -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'start', side = 'bottom', @@ -128,9 +119,7 @@ const Content = React.forwardRef( onPointerDownOutside, onOpenAutoFocus, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Content.displayName = 'ContentWebPopover'; -const Close = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled, ...props }, ref) => { +function Close({ ref, asChild, onPress: onPressProp, disabled, ...props }: CloseProps & { ref?: React.Ref }) { const augmentedRef = useAugmentedRef({ ref }); const { onOpenChange, open } = useRootContext(); @@ -188,7 +175,6 @@ const Close = React.forwardRef( ); } -); Close.displayName = 'CloseWebPopover'; diff --git a/packages/progress/src/progress.tsx b/packages/progress/src/progress.tsx index 46e991a5..735b832d 100644 --- a/packages/progress/src/progress.tsx +++ b/packages/progress/src/progress.tsx @@ -9,11 +9,7 @@ import type { IndicatorProps, IndicatorRef, RootProps, RootRef } from './types'; const DEFAULT_MAX = 100; -const Root = React.forwardRef( - ( - { asChild, value: valueProp, max: maxProp, getValueLabel = defaultGetValueLabel, ...props }, - ref - ) => { +function Root({ ref, asChild, value: valueProp, max: maxProp, getValueLabel = defaultGetValueLabel, ...props }: RootProps & { ref?: React.Ref }) { const max = maxProp ?? DEFAULT_MAX; const value = isValidValueNumber(valueProp, max) ? valueProp : 0; @@ -36,14 +32,13 @@ const Root = React.forwardRef( /> ); } -); Root.displayName = 'RootProgress'; -const Indicator = React.forwardRef(({ asChild, ...props }, ref) => { +function Indicator({ ref, asChild, ...props }: IndicatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Indicator.displayName = 'IndicatorProgress'; diff --git a/packages/progress/src/progress.web.tsx b/packages/progress/src/progress.web.tsx index 4b32e8e3..14282194 100644 --- a/packages/progress/src/progress.web.tsx +++ b/packages/progress/src/progress.web.tsx @@ -6,8 +6,7 @@ import type { IndicatorProps, IndicatorRef, RootProps, RootRef } from './types'; const ProgressContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, value, max, getValueLabel, ...props }, ref) => { +function Root({ ref, asChild, value, max, getValueLabel, ...props }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -17,18 +16,17 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootProgress'; -const Indicator = React.forwardRef(({ asChild, ...props }, ref) => { +function Indicator({ ref, asChild, ...props }: IndicatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Indicator.displayName = 'IndicatorProgress'; diff --git a/packages/radio-group/src/radio-group.tsx b/packages/radio-group/src/radio-group.tsx index de533a57..c1bc8094 100644 --- a/packages/radio-group/src/radio-group.tsx +++ b/packages/radio-group/src/radio-group.tsx @@ -5,8 +5,7 @@ import type { IndicatorProps, IndicatorRef, ItemProps, ItemRef, RootProps, RootR const RadioGroupContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, value, onValueChange, disabled = false, ...viewProps }, ref) => { +function Root({ ref, asChild, value, onValueChange, disabled = false, ...viewProps }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Root.displayName = 'RootRadioGroup'; @@ -40,11 +38,7 @@ interface RadioItemContext { const RadioItemContext = React.createContext(null); -const Item = React.forwardRef( - ( - { asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, - ref - ) => { +function Item({ ref, asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }: ItemProps & { ref?: React.Ref }) { const { disabled, value, onValueChange } = useRadioGroupContext(); function onPress(ev: GestureResponderEvent) { @@ -75,7 +69,6 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemRadioGroup'; @@ -89,8 +82,7 @@ function useRadioItemContext() { return context; } -const Indicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Indicator({ ref, asChild, forceMount, ...props }: IndicatorProps & { ref?: React.Ref }) { const { value } = useRadioGroupContext(); const { itemValue } = useRadioItemContext(); @@ -102,7 +94,6 @@ const Indicator = React.forwardRef( const Component = asChild ? Slot.View : View; return ; } -); Indicator.displayName = 'IndicatorRadioGroup'; diff --git a/packages/radio-group/src/radio-group.web.tsx b/packages/radio-group/src/radio-group.web.tsx index 497ffb37..48d34062 100644 --- a/packages/radio-group/src/radio-group.web.tsx +++ b/packages/radio-group/src/radio-group.web.tsx @@ -6,8 +6,7 @@ import type { IndicatorProps, IndicatorRef, ItemProps, ItemRef, RootProps, RootR const RadioGroupContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, value, onValueChange, disabled = false, ...viewProps }, ref) => { +function Root({ ref, asChild, value, onValueChange, disabled = false, ...viewProps }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Root.displayName = 'RootRadioGroup'; function useRadioGroupContext() { @@ -35,8 +33,7 @@ function useRadioGroupContext() { } return context; } -const Item = React.forwardRef( - ({ asChild, value, onPress: onPressProps, ...props }, ref) => { +function Item({ ref, asChild, value, onPress: onPressProps, ...props }: ItemProps & { ref?: React.Ref }) { const { onValueChange } = useRadioGroupContext(); function onPress(ev: GestureResponderEvent) { @@ -53,12 +50,10 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemRadioGroup'; -const Indicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Indicator({ ref, asChild, forceMount, ...props }: IndicatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -66,7 +61,6 @@ const Indicator = React.forwardRef( ); } -); Indicator.displayName = 'IndicatorRadioGroup'; diff --git a/packages/select/src/select.tsx b/packages/select/src/select.tsx index d316a9b5..6a3c1e9a 100644 --- a/packages/select/src/select.tsx +++ b/packages/select/src/select.tsx @@ -58,19 +58,14 @@ interface IRootContext extends SharedRootContext { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, value: valueProp, defaultValue, onValueChange: onValueChangeProp, onOpenChange: onOpenChangeProp, disabled, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [value, onValueChange] = useControllableState({ prop: valueProp, @@ -106,7 +101,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeSelect'; @@ -118,8 +112,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { open, onOpenChange, disabled: disabledRoot, setTriggerPosition } = useRootContext(); const augmentedRef = useAugmentedRef({ @@ -160,11 +153,10 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativeSelect'; -const Value = React.forwardRef(({ asChild, placeholder, ...props }, ref) => { +function Value({ ref, asChild, placeholder, ...props }: ValueProps & { ref?: React.Ref }) { const { value } = useRootContext(); const Component = asChild ? Slot.Text : Text; return ( @@ -172,7 +164,7 @@ const Value = React.forwardRef(({ asChild, placeholder, .. {value?.label ?? placeholder} ); -}); +} Value.displayName = 'ValueNativeSelect'; @@ -199,8 +191,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { ); } -const Overlay = React.forwardRef( - ({ asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }: OverlayProps & { ref?: React.Ref }) { const { open, onOpenChange, setTriggerPosition, setContentLayout } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -221,17 +212,13 @@ const Overlay = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayNativeSelect'; /** * @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`. */ -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'start', side = 'bottom', @@ -244,9 +231,7 @@ const Content = React.forwardRef( disablePositioningStyle, position: _position, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const { open, onOpenChange, @@ -308,7 +293,6 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeSelect'; @@ -317,19 +301,14 @@ const ItemContext = React.createContext<{ label: string; } | null>(null); -const Item = React.forwardRef( - ( - { - asChild, +function Item({ ref, asChild, value: itemValue, label, onPress: onPressProp, disabled = false, closeOnPress = true, ...props - }, - ref - ) => { + }: ItemProps & { ref?: React.Ref }) { const { onOpenChange, value, onValueChange, setTriggerPosition, setContentLayout } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -363,7 +342,6 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemNativeSelect'; @@ -375,7 +353,7 @@ function useItemContext() { return context; } -const ItemText = React.forwardRef(({ asChild, ...props }, ref) => { +function ItemText({ ref, asChild, ...props }: ItemTextProps & { ref?: React.Ref }) { const { label } = useItemContext(); const Component = asChild ? Slot.Text : Text; @@ -384,12 +362,11 @@ const ItemText = React.forwardRef(({ asChild, ...pro {label} ); -}); +} ItemText.displayName = 'ItemTextNativeSelect'; -const ItemIndicator = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function ItemIndicator({ ref, asChild, forceMount, ...props }: ItemIndicatorProps & { ref?: React.Ref }) { const { itemValue } = useItemContext(); const { value } = useRootContext(); @@ -401,30 +378,27 @@ const ItemIndicator = React.forwardRef( const Component = asChild ? Slot.View : View; return ; } -); ItemIndicator.displayName = 'ItemIndicatorNativeSelect'; -const Group = React.forwardRef(({ asChild, ...props }, ref) => { +function Group({ ref, asChild, ...props }: GroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Group.displayName = 'GroupNativeSelect'; -const Label = React.forwardRef(({ asChild, ...props }, ref) => { +function Label({ ref, asChild, ...props }: LabelProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ; -}); +} Label.displayName = 'LabelNativeSelect'; -const Separator = React.forwardRef( - ({ asChild, decorative, ...props }, ref) => { +function Separator({ ref, asChild, decorative, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; } -); Separator.displayName = 'SeparatorNativeSelect'; diff --git a/packages/select/src/select.web.tsx b/packages/select/src/select.web.tsx index 62d03fc1..1d60a657 100644 --- a/packages/select/src/select.web.tsx +++ b/packages/select/src/select.web.tsx @@ -49,18 +49,13 @@ const SelectContext = React.createContext< * @web Parameter of `onValueChange` has the value of `value` for the `value` and the `label` of the selected Option * @ex When an Option with a label of Green Apple, the parameter passed to `onValueChange` is { value: 'green-apple', label: 'green-apple' } */ -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, value: valueProp, defaultValue, onValueChange: onValueChangeProp, onOpenChange: onOpenChangeProp, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const [value, onValueChange] = useControllableState({ prop: valueProp, defaultProp: defaultValue, @@ -99,7 +94,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebSelect'; @@ -111,8 +105,7 @@ function useRootContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, role: _role, disabled, ...props }, ref) => { +function Trigger({ ref, asChild, role: _role, disabled, ...props }: TriggerProps & { ref?: React.Ref }) { const { open, onOpenChange } = useRootContext(); const augmentedRef = useAugmentedRef({ ref, @@ -141,19 +134,16 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebSelect'; -const Value = React.forwardRef( - ({ asChild, placeholder, children, ...props }, ref) => { +function Value({ ref, asChild, placeholder, children, ...props }: ValueProps & { ref?: React.Ref }) { return ( {children} ); } -); Value.displayName = 'ValueWebSelect'; @@ -161,8 +151,7 @@ function Portal({ container, children }: PortalProps) { return ; } -const Overlay = React.forwardRef( - ({ asChild, forceMount, children, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, children, ...props }: OverlayProps & { ref?: React.Ref }) { const { open } = useRootContext(); const Component = asChild ? Slot.Pressable : Pressable; @@ -173,14 +162,10 @@ const Overlay = React.forwardRef( ); } -); Overlay.displayName = 'OverlayWebSelect'; -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount: _forceMount, align = 'start', side = 'bottom', @@ -194,9 +179,7 @@ const Content = React.forwardRef( onInteractOutside: _onInteractOutside, onPointerDownOutside, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Content.displayName = 'ContentWebSelect'; @@ -223,8 +205,7 @@ const ItemContext = React.createContext<{ label: string; } | null>(null); -const Item = React.forwardRef( - ({ asChild, closeOnPress = true, label, value, children, ...props }, ref) => { +function Item({ ref, asChild, closeOnPress = true, label, value, children, ...props }: ItemProps & { ref?: React.Ref }) { return ( @@ -235,7 +216,6 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemWebSelect'; @@ -247,25 +227,22 @@ function useItemContext() { return context; } -const ItemText = React.forwardRef>( - ({ asChild, ...props }, ref) => { - const { label } = useItemContext(); +function ItemText({ ref, asChild, ...props }: Omit & { ref?: React.Ref }) { + const { label } = useItemContext(); - const Component = asChild ? Slot.Text : Text; - return ( - - - {label} - - - ); - } -); + const Component = asChild ? Slot.Text : Text; + return ( + + + {label} + + + ); +} ItemText.displayName = 'ItemTextWebSelect'; -const ItemIndicator = React.forwardRef( - ({ asChild, forceMount: _forceMount, ...props }, ref) => { +function ItemIndicator({ ref, asChild, forceMount: _forceMount, ...props }: ItemIndicatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -273,34 +250,32 @@ const ItemIndicator = React.forwardRef( ); } -); ItemIndicator.displayName = 'ItemIndicatorWebSelect'; -const Group = React.forwardRef(({ asChild, ...props }, ref) => { +function Group({ ref, asChild, ...props }: GroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Group.displayName = 'GroupWebSelect'; -const Label = React.forwardRef(({ asChild, ...props }, ref) => { +function Label({ ref, asChild, ...props }: LabelProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Text : Text; return ( ); -}); +} Label.displayName = 'LabelWebSelect'; -const Separator = React.forwardRef( - ({ asChild, decorative, ...props }, ref) => { +function Separator({ ref, asChild, decorative, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -308,7 +283,6 @@ const Separator = React.forwardRef( ); } -); Separator.displayName = 'SeparatorWebSelect'; diff --git a/packages/separator/src/separator.tsx b/packages/separator/src/separator.tsx index 735444f1..f7093b65 100644 --- a/packages/separator/src/separator.tsx +++ b/packages/separator/src/separator.tsx @@ -3,19 +3,17 @@ import * as React from 'react'; import { View } from 'react-native'; import type { RootProps, RootRef } from './types'; -const Root = React.forwardRef( - ({ asChild, decorative, orientation = 'horizontal', ...props }, ref) => { - const Component = asChild ? Slot.View : View; - return ( - - ); - } -); +function Root({ ref, asChild, decorative, orientation = 'horizontal', ...props }: RootProps & { ref?: React.Ref }) { + const Component = asChild ? Slot.View : View; + return ( + + ); +} Root.displayName = 'RootSeparator'; diff --git a/packages/slider/src/slider.tsx b/packages/slider/src/slider.tsx index e1e23309..ae48af38 100644 --- a/packages/slider/src/slider.tsx +++ b/packages/slider/src/slider.tsx @@ -14,10 +14,7 @@ import type { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, value, disabled, min, @@ -27,9 +24,7 @@ const Root = React.forwardRef( step: _step, onValueChange: _onValueChange, ...props - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -37,7 +32,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeSlider'; @@ -49,7 +43,7 @@ function useSliderContext() { return context; } -const Track = React.forwardRef(({ asChild, ...props }, ref) => { +function Track({ ref, asChild, ...props }: TrackProps & { ref?: React.Ref }) { const { value, min, max, disabled } = useSliderContext(); const Component = asChild ? Slot.View : View; @@ -65,21 +59,21 @@ const Track = React.forwardRef(({ asChild, ...props }, ref {...props} /> ); -}); +} Track.displayName = 'TrackNativeSlider'; -const Range = React.forwardRef(({ asChild, ...props }, ref) => { +function Range({ ref, asChild, ...props }: RangeProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Range.displayName = 'RangeNativeSlider'; -const Thumb = React.forwardRef(({ asChild, ...props }, ref) => { +function Thumb({ ref, asChild, ...props }: ThumbProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Thumb.displayName = 'ThumbNativeSlider'; diff --git a/packages/slider/src/slider.web.tsx b/packages/slider/src/slider.web.tsx index 2c6522ac..14c842f3 100644 --- a/packages/slider/src/slider.web.tsx +++ b/packages/slider/src/slider.web.tsx @@ -13,11 +13,7 @@ import type { TrackRef, } from './types'; -const Root = React.forwardRef( - ( - { asChild, value, disabled, min, max, dir, inverted, step = 1, onValueChange, ...props }, - ref - ) => { +function Root({ ref, asChild, value, disabled, min, max, dir, inverted, step = 1, onValueChange, ...props }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Root.displayName = 'RootWebSlider'; -const Track = React.forwardRef(({ asChild, ...props }, ref) => { +function Track({ ref, asChild, ...props }: TrackProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Track.displayName = 'TrackWebSlider'; -const Range = React.forwardRef(({ asChild, ...props }, ref) => { +function Range({ ref, asChild, ...props }: RangeProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Range.displayName = 'RangeWebSlider'; -const Thumb = React.forwardRef(({ asChild, ...props }, ref) => { +function Thumb({ ref, asChild, ...props }: ThumbProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Thumb.displayName = 'ThumbWebSlider'; diff --git a/packages/slot/src/slot.tsx b/packages/slot/src/slot.tsx index 0e7e15a3..eefccb30 100644 --- a/packages/slot/src/slot.tsx +++ b/packages/slot/src/slot.tsx @@ -14,66 +14,60 @@ import { type StyleProp, } from 'react-native'; -const Pressable = React.forwardRef, RNPressableProps>( - (props, forwardedRef) => { - const { children, ...pressableSlotProps } = props; +function Pressable({ ref: forwardedRef, ...props }: RNPressableProps & { ref?: React.Ref> }) { + const { children, ...pressableSlotProps } = props; - if (!React.isValidElement(children)) { - console.log('Slot.Pressable - Invalid asChild element', children); - return null; - } - - return React.cloneElement< - React.ComponentPropsWithoutRef, - React.ElementRef - >(isTextChildren(children) ? <> : children, { - ...mergeProps(pressableSlotProps, children.props as AnyProps), - ref: forwardedRef ? composeRefs(forwardedRef, (children as any).ref) : (children as any).ref, - }); + if (!React.isValidElement(children)) { + console.log('Slot.Pressable - Invalid asChild element', children); + return null; } -); -Pressable.displayName = 'SlotPressable'; + return React.cloneElement< + React.ComponentPropsWithoutRef, + React.ElementRef + >(isTextChildren(children) ? <> : children, { + ...mergeProps(pressableSlotProps, children.props as AnyProps), + ref: forwardedRef ? composeRefs(forwardedRef, (children as any).ref) : (children as any).ref, + }); +} -const View = React.forwardRef, RNViewProps>( - (props, forwardedRef) => { - const { children, ...viewSlotProps } = props; +Pressable.displayName = 'SlotPressable'; - if (!React.isValidElement(children)) { - console.log('Slot.View - Invalid asChild element', children); - return null; - } +function View({ ref: forwardedRef, ...props }: RNViewProps & { ref?: React.Ref> }) { + const { children, ...viewSlotProps } = props; - return React.cloneElement< - React.ComponentPropsWithoutRef, - React.ElementRef - >(isTextChildren(children) ? <> : children, { - ...mergeProps(viewSlotProps, children.props as AnyProps), - ref: forwardedRef ? composeRefs(forwardedRef, (children as any).ref) : (children as any).ref, - }); + if (!React.isValidElement(children)) { + console.log('Slot.View - Invalid asChild element', children); + return null; } -); -View.displayName = 'SlotView'; + return React.cloneElement< + React.ComponentPropsWithoutRef, + React.ElementRef + >(isTextChildren(children) ? <> : children, { + ...mergeProps(viewSlotProps, children.props as AnyProps), + ref: forwardedRef ? composeRefs(forwardedRef, (children as any).ref) : (children as any).ref, + }); +} -const Text = React.forwardRef, RNTextProps>( - (props, forwardedRef) => { - const { children, ...textSlotProps } = props; +View.displayName = 'SlotView'; - if (!React.isValidElement(children)) { - console.log('Slot.Text - Invalid asChild element', children); - return null; - } +function Text({ ref: forwardedRef, ...props }: RNTextProps & { ref?: React.Ref> }) { + const { children, ...textSlotProps } = props; - return React.cloneElement< - React.ComponentPropsWithoutRef, - React.ElementRef - >(isTextChildren(children) ? <> : children, { - ...mergeProps(textSlotProps, children.props as AnyProps), - ref: forwardedRef ? composeRefs(forwardedRef, (children as any).ref) : (children as any).ref, - }); + if (!React.isValidElement(children)) { + console.log('Slot.Text - Invalid asChild element', children); + return null; } -); + + return React.cloneElement< + React.ComponentPropsWithoutRef, + React.ElementRef + >(isTextChildren(children) ? <> : children, { + ...mergeProps(textSlotProps, children.props as AnyProps), + ref: forwardedRef ? composeRefs(forwardedRef, (children as any).ref) : (children as any).ref, + }); +} Text.displayName = 'SlotText'; @@ -81,24 +75,22 @@ type ImageSlotProps = RNImageProps & { children?: React.ReactNode; }; -const Image = React.forwardRef, ImageSlotProps>( - (props, forwardedRef) => { - const { children, ...imageSlotProps } = props; +function Image({ ref: forwardedRef, ...props }: ImageSlotProps & { ref?: React.Ref> }) { + const { children, ...imageSlotProps } = props; - if (!React.isValidElement(children)) { - console.log('Slot.Image - Invalid asChild element', children); - return null; - } - - return React.cloneElement< - React.ComponentPropsWithoutRef, - React.ElementRef - >(isTextChildren(children) ? <> : children, { - ...mergeProps(imageSlotProps, children.props as AnyProps), - ref: forwardedRef ? composeRefs(forwardedRef, (children as any).ref) : (children as any).ref, - }); + if (!React.isValidElement(children)) { + console.log('Slot.Image - Invalid asChild element', children); + return null; } -); + + return React.cloneElement< + React.ComponentPropsWithoutRef, + React.ElementRef + >(isTextChildren(children) ? <> : children, { + ...mergeProps(imageSlotProps, children.props as AnyProps), + ref: forwardedRef ? composeRefs(forwardedRef, (children as any).ref) : (children as any).ref, + }); +} Image.displayName = 'SlotImage'; diff --git a/packages/switch/src/switch.tsx b/packages/switch/src/switch.tsx index 689fa29c..e55fb5de 100644 --- a/packages/switch/src/switch.tsx +++ b/packages/switch/src/switch.tsx @@ -3,51 +3,38 @@ import * as React from 'react'; import { Pressable, View, type GestureResponderEvent } from 'react-native'; import type { RootProps, RootRef, ThumbProps, ThumbRef } from './types'; -const Root = React.forwardRef( - ( - { - asChild, - checked, - onCheckedChange, - disabled, - onPress: onPressProp, - 'aria-valuetext': ariaValueText, - ...props - }, - ref - ) => { - function onPress(ev: GestureResponderEvent) { - if (disabled) return; - onCheckedChange(!checked); - onPressProp?.(ev); - } - - const Component = asChild ? Slot.Pressable : Pressable; - return ( - - ); +function Root({ ref, asChild, checked, onCheckedChange, disabled, onPress: onPressProp, 'aria-valuetext': ariaValueText, ...props }: RootProps & { ref?: React.Ref }) { + function onPress(ev: GestureResponderEvent) { + if (disabled) return; + onCheckedChange(!checked); + onPressProp?.(ev); } -); + + const Component = asChild ? Slot.Pressable : Pressable; + return ( + + ); +} Root.displayName = 'RootNativeSwitch'; -const Thumb = React.forwardRef(({ asChild, ...props }, ref) => { +function Thumb({ ref, asChild, ...props }: ThumbProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Thumb.displayName = 'ThumbNativeSwitch'; diff --git a/packages/switch/src/switch.web.tsx b/packages/switch/src/switch.web.tsx index dbbec2ed..efff7408 100644 --- a/packages/switch/src/switch.web.tsx +++ b/packages/switch/src/switch.web.tsx @@ -4,57 +4,44 @@ import * as React from 'react'; import { Pressable, View, type GestureResponderEvent } from 'react-native'; import type { RootProps, RootRef, ThumbProps, ThumbRef } from './types'; -const Root = React.forwardRef( - ( - { - asChild, - checked, - onCheckedChange, - disabled, - onPress: onPressProp, - onKeyDown: onKeyDownProp, - ...props - }, - ref - ) => { - function onPress(ev: GestureResponderEvent) { - onCheckedChange(!checked); - onPressProp?.(ev); - } +function Root({ ref, asChild, checked, onCheckedChange, disabled, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props }: RootProps & { ref?: React.Ref }) { + function onPress(ev: GestureResponderEvent) { + onCheckedChange(!checked); + onPressProp?.(ev); + } - function onKeyDown(ev: React.KeyboardEvent) { - onKeyDownProp?.(ev); - if (ev.key === ' ') { - onCheckedChange(!checked); - } + function onKeyDown(ev: React.KeyboardEvent) { + onKeyDownProp?.(ev); + if (ev.key === ' ') { + onCheckedChange(!checked); } - - const Component = asChild ? Slot.Pressable : Pressable; - return ( - - - - ); } -); + + const Component = asChild ? Slot.Pressable : Pressable; + return ( + + + + ); +} Root.displayName = 'RootWebSwitch'; -const Thumb = React.forwardRef(({ asChild, ...props }, ref) => { +function Thumb({ ref, asChild, ...props }: ThumbProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} Thumb.displayName = 'ThumbWebSwitch'; diff --git a/packages/table/src/table.tsx b/packages/table/src/table.tsx index b7e1cdcd..d075fd39 100644 --- a/packages/table/src/table.tsx +++ b/packages/table/src/table.tsx @@ -11,64 +11,64 @@ import { Pressable, View } from 'react-native'; type RootProps = SlottableViewProps; type RootRef = ViewRef; -const Root = React.forwardRef(({ asChild, ...props }, ref) => { +function Root({ ref, asChild, ...props }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Root.displayName = 'RootTable'; type HeaderProps = SlottableViewProps; type HeaderRef = ViewRef; -const Header = React.forwardRef(({ asChild, ...props }, ref) => { +function Header({ ref, asChild, ...props }: HeaderProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Header.displayName = 'HeaderTable'; type RowProps = SlottablePressableProps; type RowRef = PressableRef; -const Row = React.forwardRef(({ asChild, ...props }, ref) => { +function Row({ ref, asChild, ...props }: RowProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} Row.displayName = 'RowTable'; type HeadProps = SlottableViewProps; type HeadRef = ViewRef; -const Head = React.forwardRef(({ asChild, ...props }, ref) => { +function Head({ ref, asChild, ...props }: HeadProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Head.displayName = 'HeadTable'; type BodyProps = SlottableViewProps; type BodyRef = ViewRef; -const Body = React.forwardRef(({ asChild, ...props }, ref) => { +function Body({ ref, asChild, ...props }: BodyProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Body.displayName = 'BodyTable'; type CellProps = SlottableViewProps; type CellRef = ViewRef; -const Cell = React.forwardRef(({ asChild, ...props }, ref) => { +function Cell({ ref, asChild, ...props }: CellProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Cell.displayName = 'CellTable'; type FooterProps = SlottableViewProps; type FooterRef = ViewRef; -const Footer = React.forwardRef(({ asChild, ...props }, ref) => { +function Footer({ ref, asChild, ...props }: FooterProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Footer.displayName = 'FooterTable'; export { Body, Cell, Footer, Head, Header, Root, Row }; diff --git a/packages/tabs/src/tabs.tsx b/packages/tabs/src/tabs.tsx index 7df9b16e..6ffe3e8e 100644 --- a/packages/tabs/src/tabs.tsx +++ b/packages/tabs/src/tabs.tsx @@ -18,19 +18,14 @@ interface RootContext extends RootProps { const TabsContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, value, onValueChange, orientation: _orientation, dir: _dir, activationMode: _activationMode, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const Component = asChild ? Slot.View : View; return ( @@ -45,7 +40,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeTabs'; @@ -57,17 +51,16 @@ function useRootContext() { return context; } -const List = React.forwardRef(({ asChild, ...props }, ref) => { +function List({ ref, asChild, ...props }: ListProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} List.displayName = 'ListNativeTabs'; const TriggerContext = React.createContext<{ value: string } | null>(null); -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled, value: tabValue, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled, value: tabValue, ...props }: TriggerProps & { ref?: React.Ref }) { const { onValueChange, value: rootValue, nativeID } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -96,7 +89,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerNativeTabs'; @@ -110,8 +102,7 @@ function useTriggerContext() { return context; } -const Content = React.forwardRef( - ({ asChild, forceMount, value: tabValue, ...props }, ref) => { +function Content({ ref, asChild, forceMount, value: tabValue, ...props }: ContentProps & { ref?: React.Ref }) { const { value: rootValue, nativeID } = useRootContext(); if (!forceMount) { @@ -131,7 +122,6 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeTabs'; diff --git a/packages/tabs/src/tabs.web.tsx b/packages/tabs/src/tabs.web.tsx index 5c54320d..2ee29d9a 100644 --- a/packages/tabs/src/tabs.web.tsx +++ b/packages/tabs/src/tabs.web.tsx @@ -14,8 +14,7 @@ import type { } from './types'; const TabsContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, value, onValueChange, orientation, dir, activationMode, ...viewProps }, ref) => { +function Root({ ref, asChild, value, onValueChange, orientation, dir, activationMode, ...viewProps }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Root.displayName = 'RootWebTabs'; @@ -49,20 +47,19 @@ function useRootContext() { return context; } -const List = React.forwardRef(({ asChild, ...props }, ref) => { +function List({ ref, asChild, ...props }: ListProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ); -}); +} List.displayName = 'ListWebTabs'; const TriggerContext = React.createContext<{ value: string } | null>(null); -const Trigger = React.forwardRef( - ({ asChild, value: tabValue, ...props }, ref) => { +function Trigger({ ref, asChild, value: tabValue, ...props }: TriggerProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ( @@ -72,7 +69,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebTabs'; @@ -86,8 +82,7 @@ function useTriggerContext() { return context; } -const Content = React.forwardRef( - ({ asChild, forceMount, value, tabIndex = -1, ...props }, ref) => { +function Content({ ref, asChild, forceMount, value, tabIndex = -1, ...props }: ContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -95,7 +90,6 @@ const Content = React.forwardRef( ); } -); Content.displayName = 'ContentWebTabs'; diff --git a/packages/toast/src/toast.tsx b/packages/toast/src/toast.tsx index 2f54ba0f..ad016a8b 100644 --- a/packages/toast/src/toast.tsx +++ b/packages/toast/src/toast.tsx @@ -19,8 +19,7 @@ interface RootContext extends RootProps { } const ToastContext = React.createContext(null); -const Root = React.forwardRef( - ({ asChild, type = 'foreground', open, onOpenChange, ...viewProps }, ref) => { +function Root({ ref, asChild, type = 'foreground', open, onOpenChange, ...viewProps }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); if (!open) { @@ -46,7 +45,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootToast'; @@ -58,8 +56,7 @@ function useToastContext() { return context; } -const Close = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Close({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: CloseProps & { ref?: React.Ref }) { const { onOpenChange } = useToastContext(); function onPress(ev: GestureResponderEvent) { @@ -80,12 +77,10 @@ const Close = React.forwardRef( /> ); } -); Close.displayName = 'CloseToast'; -const Action = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Action({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: ActionProps & { ref?: React.Ref }) { const { onOpenChange } = useToastContext(); function onPress(ev: GestureResponderEvent) { @@ -106,27 +101,24 @@ const Action = React.forwardRef( /> ); } -); Action.displayName = 'ActionToast'; -const Title = React.forwardRef(({ asChild, ...props }, ref) => { +function Title({ ref, asChild, ...props }: TitleProps & { ref?: React.Ref }) { const { nativeID } = useToastContext(); const Component = asChild ? Slot.Text : Text; return ; -}); +} Title.displayName = 'TitleToast'; -const Description = React.forwardRef( - ({ asChild, ...props }, ref) => { +function Description({ ref, asChild, ...props }: DescriptionProps & { ref?: React.Ref }) { const { nativeID } = useToastContext(); const Component = asChild ? Slot.Text : Text; return ; } -); Description.displayName = 'DescriptionToast'; diff --git a/packages/toggle-group/src/toggle-group.tsx b/packages/toggle-group/src/toggle-group.tsx index 2d720f15..4d5399b1 100644 --- a/packages/toggle-group/src/toggle-group.tsx +++ b/packages/toggle-group/src/toggle-group.tsx @@ -6,10 +6,7 @@ import type { ItemProps, ItemRef, RootProps, RootRef } from './types'; const ToggleGroupContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, type, value, onValueChange, @@ -19,9 +16,7 @@ const Root = React.forwardRef( dir: _dir, loop: _loop, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Root.displayName = 'RootToggleGroup'; @@ -54,11 +48,7 @@ function useRootContext() { const ItemContext = React.createContext(null); -const Item = React.forwardRef( - ( - { asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, - ref - ) => { +function Item({ ref, asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }: ItemProps & { ref?: React.Ref }) { const id = React.useId(); const { type, disabled, value, onValueChange } = useRootContext(); @@ -99,7 +89,6 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemToggleGroup'; diff --git a/packages/toggle-group/src/toggle-group.web.tsx b/packages/toggle-group/src/toggle-group.web.tsx index 71808ca8..06f23c4c 100644 --- a/packages/toggle-group/src/toggle-group.web.tsx +++ b/packages/toggle-group/src/toggle-group.web.tsx @@ -7,10 +7,7 @@ import type { ItemProps, ItemRef, RootProps, RootRef } from './types'; const ToggleGroupContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, type, value, onValueChange, @@ -20,9 +17,7 @@ const Root = React.forwardRef( dir, loop, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Root.displayName = 'RootToggleGroup'; @@ -67,11 +61,7 @@ function useRootContext() { const ItemContext = React.createContext(null); -const Item = React.forwardRef( - ( - { asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, - ref - ) => { +function Item({ ref, asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }: ItemProps & { ref?: React.Ref }) { const { type, disabled, value, onValueChange } = useRootContext(); function onPress(ev: GestureResponderEvent) { @@ -99,7 +89,6 @@ const Item = React.forwardRef( ); } -); Item.displayName = 'ItemToggleGroup'; diff --git a/packages/toggle/src/toggle.tsx b/packages/toggle/src/toggle.tsx index 606cfad3..efab9d81 100644 --- a/packages/toggle/src/toggle.tsx +++ b/packages/toggle/src/toggle.tsx @@ -3,8 +3,7 @@ import * as React from 'react'; import { Pressable, type GestureResponderEvent } from 'react-native'; import type { RootProps, RootRef } from './types'; -const Root = React.forwardRef( - ({ asChild, pressed, onPressedChange, disabled, onPress: onPressProp, ...props }, ref) => { +function Root({ ref, asChild, pressed, onPressedChange, disabled, onPress: onPressProp, ...props }: RootProps & { ref?: React.Ref }) { function onPress(ev: GestureResponderEvent) { if (disabled) return; const newValue = !pressed; @@ -28,8 +27,7 @@ const Root = React.forwardRef( {...props} /> ); - } -); +} Root.displayName = 'RootNativeToggle'; diff --git a/packages/toggle/src/toggle.web.tsx b/packages/toggle/src/toggle.web.tsx index 046d064a..089383eb 100644 --- a/packages/toggle/src/toggle.web.tsx +++ b/packages/toggle/src/toggle.web.tsx @@ -4,8 +4,7 @@ import * as React from 'react'; import { Pressable, type GestureResponderEvent } from 'react-native'; import type { RootProps, RootRef } from './types'; -const Root = React.forwardRef( - ({ asChild, pressed, onPressedChange, disabled, onPress: onPressProp, ...props }, ref) => { +function Root({ ref, asChild, pressed, onPressedChange, disabled, onPress: onPressProp, ...props }: RootProps & { ref?: React.Ref }) { function onPress(ev: GestureResponderEvent) { onPressProp?.(ev); onPressedChange(!pressed); @@ -17,8 +16,7 @@ const Root = React.forwardRef( ); - } -); +} Root.displayName = 'RootWebToggle'; diff --git a/packages/toolbar/src/toolbar.tsx b/packages/toolbar/src/toolbar.tsx index f572bcf5..fbf38c63 100644 --- a/packages/toolbar/src/toolbar.tsx +++ b/packages/toolbar/src/toolbar.tsx @@ -17,19 +17,16 @@ import type { ToggleItemRef, } from './types'; -const Root = React.forwardRef( - ({ asChild, orientation: _orientation, dir: _dir, loop: _loop, ...props }, ref) => { +function Root({ ref, asChild, orientation: _orientation, dir: _dir, loop: _loop, ...props }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; } -); Root.displayName = 'RootNativeToolbar'; const ToggleGroupContext = React.createContext(null); -const ToggleGroup = React.forwardRef( - ({ asChild, type, value, onValueChange, disabled = false, ...viewProps }, ref) => { +function ToggleGroup({ ref, asChild, type, value, onValueChange, disabled = false, ...viewProps }: ToggleGroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); ToggleGroup.displayName = 'ToggleGroupNativeToolbar'; @@ -60,11 +56,7 @@ function useToggleGroupContext() { return context; } -const ToggleItem = React.forwardRef( - ( - { asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, - ref - ) => { +function ToggleItem({ ref, asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }: ToggleItemProps & { ref?: React.Ref }) { const { type, disabled, value, onValueChange } = useToggleGroupContext(); function onPress(ev: GestureResponderEvent) { @@ -102,27 +94,26 @@ const ToggleItem = React.forwardRef( /> ); } -); ToggleItem.displayName = 'ToggleItemNativeToolbar'; -const Separator = React.forwardRef(({ asChild, ...props }, ref) => { +function Separator({ ref, asChild, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; -}); +} Separator.displayName = 'SeparatorNativeToolbar'; -const Link = React.forwardRef(({ asChild, ...props }, ref) => { +function Link({ ref, asChild, ...props }: LinkProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} Link.displayName = 'LinkNativeToolbar'; -const Button = React.forwardRef(({ asChild, ...props }, ref) => { +function Button({ ref, asChild, ...props }: ButtonProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; -}); +} export { Button, Link, Root, Separator, ToggleGroup, ToggleItem }; diff --git a/packages/toolbar/src/toolbar.web.tsx b/packages/toolbar/src/toolbar.web.tsx index f7fa25dc..2272fa2f 100644 --- a/packages/toolbar/src/toolbar.web.tsx +++ b/packages/toolbar/src/toolbar.web.tsx @@ -18,8 +18,7 @@ import type { ToggleItemRef, } from './types'; -const Root = React.forwardRef( - ({ asChild, orientation, dir, loop, style, ...props }, ref) => { +function Root({ ref, asChild, orientation, dir, loop, style, ...props }: RootProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( @@ -27,14 +26,12 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebToolbar'; const ToggleGroupContext = React.createContext(null); -const ToggleGroup = React.forwardRef( - ({ asChild, type, value, onValueChange, disabled = false, style, ...viewProps }, ref) => { +function ToggleGroup({ ref, asChild, type, value, onValueChange, disabled = false, style, ...viewProps }: ToggleGroupProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); ToggleGroup.displayName = 'ToggleGroupWebToolbar'; @@ -73,18 +69,13 @@ function useToggleGroupContext() { return context; } -const ToggleItem = React.forwardRef( - ( - { - asChild, +function ToggleItem({ ref, asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, style, ...props - }, - ref - ) => { + }: ToggleItemProps & { ref?: React.Ref }) { const { type, disabled, value, onValueChange } = useToggleGroupContext(); function onPress(ev: GestureResponderEvent) { @@ -105,37 +96,34 @@ const ToggleItem = React.forwardRef( ); } -); ToggleItem.displayName = 'ToggleItemWebToolbar'; -const Separator = React.forwardRef( - ({ asChild, style, ...props }, ref) => { +function Separator({ ref, asChild, style, ...props }: SeparatorProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ; } -); Separator.displayName = 'SeparatorWebToolbar'; -const Link = React.forwardRef(({ asChild, style, ...props }, ref) => { +function Link({ ref, asChild, style, ...props }: LinkProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ( ); -}); +} Link.displayName = 'LinkWebToolbar'; -const Button = React.forwardRef(({ asChild, style, ...props }, ref) => { +function Button({ ref, asChild, style, ...props }: ButtonProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ( ); -}); +} export { Button, Link, Root, Separator, ToggleGroup, ToggleItem }; diff --git a/packages/tooltip/src/tooltip.tsx b/packages/tooltip/src/tooltip.tsx index c285d400..dbfc48c2 100644 --- a/packages/tooltip/src/tooltip.tsx +++ b/packages/tooltip/src/tooltip.tsx @@ -34,18 +34,13 @@ interface IRootContext { const RootContext = React.createContext(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, delayDuration: _delayDuration, skipDelayDuration: _skipDelayDuration, disableHoverableContent: _disableHoverableContent, onOpenChange: onOpenChangeProp, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const nativeID = React.useId(); const [triggerPosition, setTriggerPosition] = React.useState(null); const [contentLayout, setContentLayout] = React.useState(null); @@ -73,7 +68,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootNativeTooltip'; @@ -85,8 +79,7 @@ function useTooltipContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, disabled = false, ...props }: TriggerProps & { ref?: React.Ref }) { const { open, onOpenChange, setTriggerPosition } = useTooltipContext(); const augmentedRef = useAugmentedRef({ @@ -127,7 +120,6 @@ const Trigger = React.forwardRef( /> ); } -); Trigger.displayName = 'TriggerNativeTooltip'; @@ -154,8 +146,7 @@ function Portal({ forceMount, hostName, children }: PortalProps) { ); } -const Overlay = React.forwardRef( - ({ asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }: OverlayProps & { ref?: React.Ref }) { const { open, onOpenChange, setContentLayout, setTriggerPosition } = useTooltipContext(); function onPress(ev: GestureResponderEvent) { @@ -176,17 +167,13 @@ const Overlay = React.forwardRef( const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayNativeTooltip'; /** * @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior on native by setting `disablePositioningStyle` to `true`. */ -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'center', side = 'top', @@ -198,9 +185,7 @@ const Content = React.forwardRef( style, disablePositioningStyle, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const { open, onOpenChange, @@ -262,7 +247,6 @@ const Content = React.forwardRef( /> ); } -); Content.displayName = 'ContentNativeTooltip'; diff --git a/packages/tooltip/src/tooltip.web.tsx b/packages/tooltip/src/tooltip.web.tsx index 2aa735da..dd7ff1f4 100644 --- a/packages/tooltip/src/tooltip.web.tsx +++ b/packages/tooltip/src/tooltip.web.tsx @@ -20,18 +20,13 @@ const RootContext = React.createContext<{ onOpenChange: (open: boolean) => void; } | null>(null); -const Root = React.forwardRef( - ( - { - asChild, +function Root({ ref, asChild, delayDuration, skipDelayDuration, disableHoverableContent, onOpenChange: onOpenChangeProp, ...viewProps - }, - ref - ) => { + }: RootProps & { ref?: React.Ref }) { const [open, setOpen] = React.useState(false); function onOpenChange(value: boolean) { @@ -59,7 +54,6 @@ const Root = React.forwardRef( ); } -); Root.displayName = 'RootWebTooltip'; @@ -71,8 +65,7 @@ function useTooltipContext() { return context; } -const Trigger = React.forwardRef( - ({ asChild, onPress: onPressProp, role: _role, disabled, ...props }, ref) => { +function Trigger({ ref, asChild, onPress: onPressProp, role: _role, disabled, ...props }: TriggerProps & { ref?: React.Ref }) { const { onOpenChange, open } = useTooltipContext(); const augmentedRef = useAugmentedRef({ ref, @@ -113,7 +106,6 @@ const Trigger = React.forwardRef( ); } -); Trigger.displayName = 'TriggerWebTooltip'; @@ -121,19 +113,14 @@ function Portal({ forceMount, container, children }: PortalProps) { return ; } -const Overlay = React.forwardRef( - ({ asChild, forceMount, ...props }, ref) => { +function Overlay({ ref, asChild, forceMount, ...props }: OverlayProps & { ref?: React.Ref }) { const Component = asChild ? Slot.Pressable : Pressable; return ; } -); Overlay.displayName = 'OverlayWebTooltip'; -const Content = React.forwardRef( - ( - { - asChild = false, +function Content({ ref, asChild = false, forceMount, align = 'center', side = 'top', @@ -149,9 +136,7 @@ const Content = React.forwardRef( sticky, hideWhenDetached, ...props - }, - ref - ) => { + }: ContentProps & { ref?: React.Ref }) { const Component = asChild ? Slot.View : View; return ( ( ); } -); Content.displayName = 'ContentWebTooltip';