diff --git a/src/components/AutoComplete/auto-complete-doc.mdx b/src/components/AutoComplete/auto-complete-doc.mdx index d28953a1..abc2edd1 100644 --- a/src/components/AutoComplete/auto-complete-doc.mdx +++ b/src/components/AutoComplete/auto-complete-doc.mdx @@ -1,5 +1,5 @@ -## AutoDrop/AutoComplete +## AutoComplete 自动完成 自动完成搜索组件 `AutoComplete`,通过读取本地数据源,或者请求网络数据源,将搜索和远程数据结合 @@ -30,33 +30,4 @@ import dedent from 'ts-dedent'; ### 具体参数 -export const Template = (args) => - -### 组件展示 - -##### 读取本地数据源 - - -{Template.bind({})} - - -##### 远程搜索 - - -{Template.bind({})} - - -##### 自定义返回选项样式 - - -{Template.bind({})} - \ No newline at end of file +export const Template = (args) => \ No newline at end of file diff --git a/src/components/AutoComplete/autoComplete.stories.tsx b/src/components/AutoComplete/autoComplete.stories.tsx index affee77b..34cd980b 100644 --- a/src/components/AutoComplete/autoComplete.stories.tsx +++ b/src/components/AutoComplete/autoComplete.stories.tsx @@ -1,97 +1,153 @@ -import React from 'react' -import { Story, Meta } from '@storybook/react' -import AutoComplete, { AutoCompleteProps } from './autoComplete' -import { DataSourceType } from './autoComplete' -import { lakersWithNumber } from './dataConfig' -import AutoCompleteDoc from './auto-complete-doc.mdx' +import React from "react"; +import { Story, Meta } from "@storybook/react"; +import AutoComplete, { AutoCompleteProps } from "./autoComplete"; +import { DataSourceType } from "./autoComplete"; +import { lakersWithNumber } from "./dataConfig"; +import AutoCompleteDoc from "./auto-complete-doc.mdx"; +import Card from "../Card/card"; interface GithubUserProps { - login: string; - url: string; - avatar_url: string; + login: string; + url: string; + avatar_url: string; } const handleAsyncFetch = (query: string) => { - return fetch(`https://api.github.com/search/users?q=${query}`) - .then(res => res.json()) - .then(({ items }) => { - return items.length && items.map((item: any) => ({ value: item.login, ...item })) - }) -} + return fetch(`https://api.github.com/search/users?q=${query}`) + .then((res) => res.json()) + .then(({ items }) => { + return ( + items.length && + items.map((item: any) => ({ value: item.login, ...item })) + ); + }); +}; const handleFetch = (query: string) => { - return lakersWithNumber.filter(player => player.value.includes(query) || player.zhValue.includes(query)) -} + return lakersWithNumber.filter( + (player) => player.value.includes(query) || player.zhValue.includes(query) + ); +}; const renderOption = (item: DataSourceType) => { - const itemWithGithub = item as DataSourceType - return ( - <> - avatar - 姓名: {itemWithGithub.value} - - ) -} + const itemWithGithub = item as DataSourceType; + return ( + <> + + avatar + + 姓名: {itemWithGithub.value} + + ); +}; + +const BaseAutoComplete = () => { + const commonCss = { width: 300, marginBottom: 20 }; + const cardCss = { margin: "20px 20px 0 0" }; -const BaseAutoComplete = (props: AutoCompleteProps) => { - const { fetchSuggestions, renderOption, placeholder, size, width, disabled } = props; return ( - - ) -} +
+ + + + + + + + + + + + + + + + +
+ ); +}; export default { component: AutoComplete, - title: 'AutoComplete', + title: "AutoComplete 自动完成", parameters: { controls: { - include: ['disabled', 'size', 'placeholder', 'width'] + include: ["disabled", "size", "placeholder", "width"], }, docs: { - page: AutoCompleteDoc - } + page: AutoCompleteDoc, + }, }, argTypes: { width: { - control: { - type: 'range', min: 100, max: 400, step: 1, - } + control: { + type: "range", + min: 100, + max: 400, + step: 1, + }, }, - } + }, } as Meta; // _default -const _default: Story = (args) => ; +const _default: Story = (args) => ( + +); -export const ConfigSearch = _default.bind({}); +export const Primary = _default.bind({}); -ConfigSearch.args = { +Primary.args = { fetchSuggestions: handleFetch, width: 300, - size: 'sm', + size: "sm", disabled: false, - placeholder: '输入你最喜欢换的水果试试看' -} - -export const RemoteSearch= _default.bind({}); - -RemoteSearch.args = { - ...ConfigSearch.args, - fetchSuggestions: handleAsyncFetch, - placeholder: '随便搜点什么吧' -} - -export const DiyOptions = _default.bind({}); - -DiyOptions.args = { - ...ConfigSearch.args, - fetchSuggestions: handleAsyncFetch, - placeholder: '随便搜点什么吧', - renderOption: renderOption, -} \ No newline at end of file + placeholder: "输入你最喜欢换的水果试试看", +};