diff --git a/packages/dify-ui/src/alert-dialog/index.stories.tsx b/packages/dify-ui/src/alert-dialog/index.stories.tsx index 0b6f60f01e..e56d6b942f 100644 --- a/packages/dify-ui/src/alert-dialog/index.stories.tsx +++ b/packages/dify-ui/src/alert-dialog/index.stories.tsx @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react-vite' -import { useState } from 'react' +import * as React from 'react' import { AlertDialog, AlertDialogActions, @@ -84,8 +84,8 @@ export const NonDestructive: Story = { } const ControlledDemo = () => { - const [open, setOpen] = useState(false) - const [count, setCount] = useState(0) + const [open, setOpen] = React.useState(false) + const [count, setCount] = React.useState(0) return (
@@ -130,8 +130,8 @@ export const Controlled: Story = { } const LoadingConfirmDemo = () => { - const [pending, setPending] = useState(false) - const [open, setOpen] = useState(false) + const [pending, setPending] = React.useState(false) + const [open, setOpen] = React.useState(false) const handleConfirm = () => { setPending(true) diff --git a/packages/dify-ui/src/alert-dialog/index.tsx b/packages/dify-ui/src/alert-dialog/index.tsx index e3c8cddd7a..f774f26565 100644 --- a/packages/dify-ui/src/alert-dialog/index.tsx +++ b/packages/dify-ui/src/alert-dialog/index.tsx @@ -1,6 +1,6 @@ 'use client' -import type { ComponentPropsWithoutRef, ReactNode } from 'react' +import type * as React from 'react' import type { ButtonProps } from '../button' import { AlertDialog as BaseAlertDialog } from '@base-ui/react/alert-dialog' import { Button } from '../button' @@ -12,7 +12,7 @@ export const AlertDialogTitle = BaseAlertDialog.Title export const AlertDialogDescription = BaseAlertDialog.Description type AlertDialogContentProps = { - children: ReactNode + children: React.ReactNode className?: string backdropClassName?: string backdropProps?: Omit @@ -47,7 +47,7 @@ export function AlertDialogContent({ ) } -type AlertDialogActionsProps = ComponentPropsWithoutRef<'div'> +type AlertDialogActionsProps = React.ComponentProps<'div'> export function AlertDialogActions({ className, ...props }: AlertDialogActionsProps) { return ( @@ -59,7 +59,7 @@ export function AlertDialogActions({ className, ...props }: AlertDialogActionsPr } type AlertDialogCancelButtonProps = Omit & { - children: ReactNode + children: React.ReactNode closeProps?: Omit } diff --git a/packages/dify-ui/src/autocomplete/__tests__/index.spec.tsx b/packages/dify-ui/src/autocomplete/__tests__/index.spec.tsx index d0cab69401..17cdaaacee 100644 --- a/packages/dify-ui/src/autocomplete/__tests__/index.spec.tsx +++ b/packages/dify-ui/src/autocomplete/__tests__/index.spec.tsx @@ -1,4 +1,4 @@ -import type { ReactNode } from 'react' +import * as React from 'react' import { render } from 'vitest-browser-react' import { Autocomplete, @@ -18,7 +18,7 @@ import { AutocompleteTrigger, } from '../index' -const renderWithSafeViewport = (ui: ReactNode) => render( +const renderWithSafeViewport = (ui: React.ReactNode) => render(
{ui}
, @@ -31,13 +31,13 @@ const renderAutocomplete = ({ open = false, defaultValue = 'workflow', }: { - children?: ReactNode + children?: React.ReactNode open?: boolean defaultValue?: string } = {}) => renderWithSafeViewport( {children ?? ( - <> + @@ -65,7 +65,7 @@ const renderAutocomplete = ({ No suggestions - + )} , ) @@ -150,7 +150,7 @@ describe('Autocomplete wrappers', () => { it('should rely on aria-labelledby when provided instead of injecting fallback labels', async () => { const screen = await renderAutocomplete({ children: ( - <> + Clear from label Trigger from label @@ -158,7 +158,7 @@ describe('Autocomplete wrappers', () => { - + ), }) diff --git a/packages/dify-ui/src/autocomplete/index.stories.tsx b/packages/dify-ui/src/autocomplete/index.stories.tsx index 5b98b39f1f..e9f707abe2 100644 --- a/packages/dify-ui/src/autocomplete/index.stories.tsx +++ b/packages/dify-ui/src/autocomplete/index.stories.tsx @@ -1,8 +1,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite' import type { Virtualizer } from '@tanstack/react-virtual' -import type { RefObject } from 'react' import { useVirtualizer } from '@tanstack/react-virtual' -import { useEffect, useMemo, useRef, useState, useTransition } from 'react' +import * as React from 'react' import { Autocomplete, AutocompleteClear, @@ -336,12 +335,12 @@ const LimitedStatus = ({ } const AsyncSearchDemo = () => { - const [searchValue, setSearchValue] = useState('') - const [searchResults, setSearchResults] = useState([]) - const [error, setError] = useState(null) - const [isPending, startTransition] = useTransition() + const [searchValue, setSearchValue] = React.useState('') + const [searchResults, setSearchResults] = React.useState([]) + const [error, setError] = React.useState(null) + const [isPending, startTransition] = React.useTransition() const { contains } = useAutocompleteFilter() - const abortControllerRef = useRef(null) + const abortControllerRef = React.useRef(null) const status = (() => { if (isPending) @@ -419,9 +418,9 @@ const AsyncSearchDemo = () => { const VirtualizedSuggestionList = ({ virtualizerRef, }: { - virtualizerRef: RefObject + virtualizerRef: React.RefObject }) => { - const scrollRef = useRef(null) + const scrollRef = React.useRef(null) const filteredItems = useAutocompleteFilteredItems() const virtualizer = useVirtualizer({ count: filteredItems.length, @@ -430,7 +429,7 @@ const VirtualizedSuggestionList = ({ overscan: 6, }) - useEffect(() => { + React.useEffect(() => { virtualizerRef.current = virtualizer return () => { @@ -490,7 +489,7 @@ const FuzzyHighlight = ({ text: string query: string }) => { - const parts = useMemo(() => { + const parts = React.useMemo(() => { const trimmed = query.trim() if (!trimmed) @@ -501,18 +500,18 @@ const FuzzyHighlight = ({ }, [query, text]) return ( - <> + {parts.map((part, index) => ( part.toLowerCase() === query.trim().toLowerCase() ? {part} : part ))} - + ) } const FuzzyMatchingDemo = () => { - const [value, setValue] = useState('retr') + const [value, setValue] = React.useState('retr') const { contains } = useAutocompleteFilter({ sensitivity: 'base' }) return ( @@ -702,7 +701,7 @@ export const CommandPalette: Story = { } const VirtualizedLongSuggestionsDemo = () => { - const virtualizerRef = useRef(null) + const virtualizerRef = React.useRef(null) return (
diff --git a/packages/dify-ui/src/autocomplete/index.tsx b/packages/dify-ui/src/autocomplete/index.tsx index e12de083df..9721ff1946 100644 --- a/packages/dify-ui/src/autocomplete/index.tsx +++ b/packages/dify-ui/src/autocomplete/index.tsx @@ -1,7 +1,7 @@ 'use client' import type { VariantProps } from 'class-variance-authority' -import type { HTMLAttributes, ReactNode } from 'react' +import type * as React from 'react' import type { Placement } from '../placement' import { Autocomplete as BaseAutocomplete } from '@base-ui/react/autocomplete' import { cva } from 'class-variance-authority' @@ -223,7 +223,7 @@ export function AutocompleteIcon({ } type AutocompleteContentProps = { - children: ReactNode + children: React.ReactNode placement?: Placement sideOffset?: number alignOffset?: number @@ -302,7 +302,7 @@ export function AutocompleteItem({ ) } -export type AutocompleteItemTextProps = HTMLAttributes +export type AutocompleteItemTextProps = React.ComponentProps<'span'> export function AutocompleteItemText({ className, @@ -368,7 +368,7 @@ export function AutocompleteItemIndicator({ className, children, ...props -}: HTMLAttributes) { +}: React.ComponentProps<'span'>) { return ( { }) it('does not submit a form when a loading submit button is clicked', async () => { - const onSubmit = vi.fn((event: FormEvent) => event.preventDefault()) + const onSubmit = vi.fn((event: React.FormEvent) => event.preventDefault()) const screen = await render(
@@ -187,7 +187,7 @@ describe('Button', () => { }) it('does not implicitly submit a form through a loading submit button', async () => { - const onSubmit = vi.fn((event: FormEvent) => event.preventDefault()) + const onSubmit = vi.fn((event: React.FormEvent) => event.preventDefault()) const screen = await render( diff --git a/packages/dify-ui/src/button/index.stories.tsx b/packages/dify-ui/src/button/index.stories.tsx index 9540c2b18a..f8397d9599 100644 --- a/packages/dify-ui/src/button/index.stories.tsx +++ b/packages/dify-ui/src/button/index.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react-vite' +import * as React from 'react' import { Button } from '.' @@ -112,10 +113,10 @@ export const WithIcon: Story = { args: { variant: 'primary', children: ( - <> + Launch - + ), }, } diff --git a/packages/dify-ui/src/checkbox-group/__tests__/index.spec.tsx b/packages/dify-ui/src/checkbox-group/__tests__/index.spec.tsx index 4e98f42861..f716a1eb34 100644 --- a/packages/dify-ui/src/checkbox-group/__tests__/index.spec.tsx +++ b/packages/dify-ui/src/checkbox-group/__tests__/index.spec.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import * as React from 'react' import { render } from 'vitest-browser-react' import { Checkbox } from '../../checkbox' import { FieldItem, FieldLabel, FieldRoot } from '../../field' @@ -10,7 +10,7 @@ const asHTMLElement = (element: HTMLElement | SVGElement) => element as HTMLElem describe('CheckboxGroup', () => { it('should manage selected values and parent mixed state', async () => { function PermissionsDemo() { - const [value, setValue] = useState(['read']) + const [value, setValue] = React.useState(['read']) return ( diff --git a/packages/dify-ui/src/checkbox-group/index.stories.tsx b/packages/dify-ui/src/checkbox-group/index.stories.tsx index ea4e638bab..1fa2643a2e 100644 --- a/packages/dify-ui/src/checkbox-group/index.stories.tsx +++ b/packages/dify-ui/src/checkbox-group/index.stories.tsx @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react-vite' -import { useId, useState } from 'react' +import * as React from 'react' import { CheckboxGroup } from '.' import { Checkbox } from '../checkbox' import { @@ -29,8 +29,8 @@ type Story = StoryObj function DocumentSelectionDemo() { const documentIds = ['doc-1', 'doc-2', 'doc-3'] - const [selected, setSelected] = useState(['doc-1']) - const groupLabelId = useId() + const [selected, setSelected] = React.useState(['doc-1']) + const groupLabelId = React.useId() return ( (['markdown']) + const [selected, setSelected] = React.useState(['markdown']) return ( diff --git a/packages/dify-ui/src/checkbox/index.stories.tsx b/packages/dify-ui/src/checkbox/index.stories.tsx index adf4f28388..ff15aaa987 100644 --- a/packages/dify-ui/src/checkbox/index.stories.tsx +++ b/packages/dify-ui/src/checkbox/index.stories.tsx @@ -1,6 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react-vite' -import type { ComponentProps } from 'react' -import { useState } from 'react' +import * as React from 'react' import { Checkbox, CheckboxSkeleton, @@ -42,8 +41,8 @@ const meta = { export default meta type Story = StoryObj -function CheckboxDemo(args: Partial>) { - const [checked, setChecked] = useState(args.checked ?? false) +function CheckboxDemo(args: Partial>) { + const [checked, setChecked] = React.useState(args.checked ?? false) return (
- + ) } diff --git a/packages/dify-ui/src/combobox/__tests__/index.spec.tsx b/packages/dify-ui/src/combobox/__tests__/index.spec.tsx index 043e0a2e1a..08045eb20e 100644 --- a/packages/dify-ui/src/combobox/__tests__/index.spec.tsx +++ b/packages/dify-ui/src/combobox/__tests__/index.spec.tsx @@ -1,4 +1,4 @@ -import type { ReactNode } from 'react' +import * as React from 'react' import { render } from 'vitest-browser-react' import { Combobox, @@ -24,7 +24,7 @@ import { ComboboxValue, } from '../index' -const renderWithSafeViewport = (ui: ReactNode) => render( +const renderWithSafeViewport = (ui: React.ReactNode) => render(
{ui}
, @@ -36,12 +36,12 @@ const renderSelectLikeCombobox = ({ children, open = false, }: { - children?: ReactNode + children?: React.ReactNode open?: boolean } = {}) => renderWithSafeViewport( {children ?? ( - <> + Resource type @@ -68,7 +68,7 @@ const renderSelectLikeCombobox = ({ No options - + )} , ) @@ -77,12 +77,12 @@ const renderInputCombobox = ({ children, open = false, }: { - children?: ReactNode + children?: React.ReactNode open?: boolean } = {}) => renderWithSafeViewport( {children ?? ( - <> + @@ -96,7 +96,7 @@ const renderInputCombobox = ({ - + )} , ) @@ -208,7 +208,7 @@ describe('Combobox wrappers', () => { it('should rely on aria-labelledby when provided instead of injecting fallback labels', async () => { const screen = await renderInputCombobox({ children: ( - <> + Clear from label Trigger from label @@ -216,7 +216,7 @@ describe('Combobox wrappers', () => { - + ), }) @@ -349,7 +349,7 @@ describe('Combobox wrappers', () => { {(selectedValue: string[]) => ( - <> + {selectedValue.map(item => ( {item} @@ -357,7 +357,7 @@ describe('Combobox wrappers', () => { ))} - + )} @@ -378,7 +378,7 @@ describe('Combobox wrappers', () => { {(selectedValue: string[]) => ( - <> + {selectedValue.map(item => ( Remove Maya @@ -386,7 +386,7 @@ describe('Combobox wrappers', () => { ))} - + )} diff --git a/packages/dify-ui/src/combobox/index.stories.tsx b/packages/dify-ui/src/combobox/index.stories.tsx index 8cf40951af..a1c1badff9 100644 --- a/packages/dify-ui/src/combobox/index.stories.tsx +++ b/packages/dify-ui/src/combobox/index.stories.tsx @@ -1,8 +1,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite' import type { Virtualizer } from '@tanstack/react-virtual' -import type { RefObject } from 'react' import { useVirtualizer } from '@tanstack/react-virtual' -import { useEffect, useMemo, useRef, useState, useTransition } from 'react' +import * as React from 'react' import { Combobox, ComboboxChip, @@ -278,9 +277,9 @@ const GroupedToolList = () => { const VirtualizedModelList = ({ virtualizerRef, }: { - virtualizerRef: RefObject + virtualizerRef: React.RefObject }) => { - const scrollRef = useRef(null) + const scrollRef = React.useRef(null) const filteredItems = useComboboxFilteredItems