From 05a01796169ee5bf4cb2ad8a2c37faf27be5e0dc Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Mon, 8 Jul 2024 16:01:02 +0800 Subject: [PATCH] demo(AutoComplete): opt options type by AutoCompleteProps (#49768) * demo(AutoComplete): opt options type by AutoCompleteProps * lint fix --- components/auto-complete/demo/allowClear.tsx | 3 ++- components/auto-complete/demo/basic.tsx | 5 +++-- components/auto-complete/demo/custom.tsx | 3 ++- components/auto-complete/demo/options.tsx | 6 +++--- components/auto-complete/demo/status.tsx | 5 +++-- components/auto-complete/demo/uncertain-category.tsx | 4 ++-- components/auto-complete/demo/variant.tsx | 3 ++- 7 files changed, 17 insertions(+), 12 deletions(-) diff --git a/components/auto-complete/demo/allowClear.tsx b/components/auto-complete/demo/allowClear.tsx index 39ebaed713..01ee728335 100644 --- a/components/auto-complete/demo/allowClear.tsx +++ b/components/auto-complete/demo/allowClear.tsx @@ -1,13 +1,14 @@ import React, { useState } from 'react'; import { CloseSquareFilled } from '@ant-design/icons'; import { AutoComplete } from 'antd'; +import type { AutoCompleteProps } from 'antd'; const mockVal = (str: string, repeat = 1) => ({ value: str.repeat(repeat), }); const App: React.FC = () => { - const [options, setOptions] = useState<{ value: string }[]>([]); + const [options, setOptions] = useState([]); const getPanelValue = (searchText: string) => !searchText ? [] : [mockVal(searchText), mockVal(searchText, 2), mockVal(searchText, 3)]; diff --git a/components/auto-complete/demo/basic.tsx b/components/auto-complete/demo/basic.tsx index 42238fc6e2..c37fe6959e 100644 --- a/components/auto-complete/demo/basic.tsx +++ b/components/auto-complete/demo/basic.tsx @@ -1,5 +1,6 @@ import React, { useState } from 'react'; import { AutoComplete } from 'antd'; +import type { AutoCompleteProps } from 'antd'; const mockVal = (str: string, repeat = 1) => ({ value: str.repeat(repeat), @@ -7,8 +8,8 @@ const mockVal = (str: string, repeat = 1) => ({ const App: React.FC = () => { const [value, setValue] = useState(''); - const [options, setOptions] = useState<{ value: string }[]>([]); - const [anotherOptions, setAnotherOptions] = useState<{ value: string }[]>([]); + const [options, setOptions] = useState([]); + const [anotherOptions, setAnotherOptions] = useState([]); const getPanelValue = (searchText: string) => !searchText ? [] : [mockVal(searchText), mockVal(searchText, 2), mockVal(searchText, 3)]; diff --git a/components/auto-complete/demo/custom.tsx b/components/auto-complete/demo/custom.tsx index 6fc062f392..f7fe431b02 100644 --- a/components/auto-complete/demo/custom.tsx +++ b/components/auto-complete/demo/custom.tsx @@ -1,10 +1,11 @@ import React, { useState } from 'react'; import { AutoComplete, Input } from 'antd'; +import type { AutoCompleteProps } from 'antd'; const { TextArea } = Input; const App: React.FC = () => { - const [options, setOptions] = useState<{ value: string }[]>([]); + const [options, setOptions] = useState([]); const handleSearch = (value: string) => { setOptions( diff --git a/components/auto-complete/demo/options.tsx b/components/auto-complete/demo/options.tsx index 337f0d5b0b..8ef609724e 100644 --- a/components/auto-complete/demo/options.tsx +++ b/components/auto-complete/demo/options.tsx @@ -1,15 +1,15 @@ import React from 'react'; import { AutoComplete } from 'antd'; -import type { DefaultOptionType } from 'antd/es/select'; +import type { AutoCompleteProps } from 'antd'; const App: React.FC = () => { - const [options, setOptions] = React.useState([]); + const [options, setOptions] = React.useState([]); const handleSearch = (value: string) => { setOptions(() => { if (!value || value.includes('@')) { return []; } - return ['gmail.com', '163.com', 'qq.com'].map((domain) => ({ + return ['gmail.com', '163.com', 'qq.com'].map((domain) => ({ label: `${value}@${domain}`, value: `${value}@${domain}`, })); diff --git a/components/auto-complete/demo/status.tsx b/components/auto-complete/demo/status.tsx index 4eeffdf077..c7eb9d869f 100644 --- a/components/auto-complete/demo/status.tsx +++ b/components/auto-complete/demo/status.tsx @@ -1,13 +1,14 @@ import React, { useState } from 'react'; import { AutoComplete, Space } from 'antd'; +import type { AutoCompleteProps } from 'antd'; const mockVal = (str: string, repeat = 1) => ({ value: str.repeat(repeat), }); const App: React.FC = () => { - const [options, setOptions] = useState<{ value: string }[]>([]); - const [anotherOptions, setAnotherOptions] = useState<{ value: string }[]>([]); + const [options, setOptions] = useState([]); + const [anotherOptions, setAnotherOptions] = useState([]); const getPanelValue = (searchText: string) => !searchText ? [] : [mockVal(searchText), mockVal(searchText, 2), mockVal(searchText, 3)]; diff --git a/components/auto-complete/demo/uncertain-category.tsx b/components/auto-complete/demo/uncertain-category.tsx index c01f5d356e..f00e46cf97 100644 --- a/components/auto-complete/demo/uncertain-category.tsx +++ b/components/auto-complete/demo/uncertain-category.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { AutoComplete, Input } from 'antd'; -import type { SelectProps } from 'antd'; +import type { AutoCompleteProps } from 'antd'; const getRandomInt = (max: number, min = 0) => Math.floor(Math.random() * (max - min + 1)) + min; @@ -36,7 +36,7 @@ const searchResult = (query: string) => }); const App: React.FC = () => { - const [options, setOptions] = useState['options']>([]); + const [options, setOptions] = useState([]); const handleSearch = (value: string) => { setOptions(value ? searchResult(value) : []); diff --git a/components/auto-complete/demo/variant.tsx b/components/auto-complete/demo/variant.tsx index 058a32219e..ae2a86a7f5 100644 --- a/components/auto-complete/demo/variant.tsx +++ b/components/auto-complete/demo/variant.tsx @@ -1,12 +1,13 @@ import React, { useState } from 'react'; import { AutoComplete, Flex } from 'antd'; +import type { AutoCompleteProps } from 'antd'; const mockVal = (str: string, repeat = 1) => ({ value: str.repeat(repeat), }); const App: React.FC = () => { - const [options, setOptions] = useState<{ value: string }[]>([]); + const [options, setOptions] = useState([]); const getPanelValue = (searchText: string) => !searchText ? [] : [mockVal(searchText), mockVal(searchText, 2), mockVal(searchText, 3)];