From df4542e20c425db91454069d3b0e73cadec82c63 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 4 Jan 2023 18:49:55 +0800 Subject: [PATCH] site: make icon search affix (#40002) * feature: update IconDisplay component in Icon docs template, affix icon search input box to the top of page * style: change shadow style Co-authored-by: Chang Wei --- .dumi/theme/builtins/IconSearch/index.tsx | 90 +++++++++++++++-------- 1 file changed, 58 insertions(+), 32 deletions(-) diff --git a/.dumi/theme/builtins/IconSearch/index.tsx b/.dumi/theme/builtins/IconSearch/index.tsx index c58c6e055e..96a1da38c1 100644 --- a/.dumi/theme/builtins/IconSearch/index.tsx +++ b/.dumi/theme/builtins/IconSearch/index.tsx @@ -1,13 +1,13 @@ import * as React from 'react'; import Icon, * as AntdIcons from '@ant-design/icons'; -import { Radio, Input, Empty } from 'antd'; -import type { RadioChangeEvent } from 'antd/es/radio/interface'; +import { Segmented, Input, Empty, Affix } from 'antd'; import { useIntl } from 'dumi'; import debounce from 'lodash/debounce'; import Category from './Category'; import { FilledIcon, OutlinedIcon, TwoToneIcon } from './themeIcons'; import type { CategoriesKeys } from './fields'; import { categories } from './fields'; +import useSiteToken from '../../../hooks/useSiteToken'; export enum ThemeType { Filled = 'Filled', @@ -38,8 +38,8 @@ const IconSearch: React.FC = () => { [], ); - const handleChangeTheme = React.useCallback((e: RadioChangeEvent) => { - setDisplayState((prevState) => ({ ...prevState, theme: e.target.value as ThemeType })); + const handleChangeTheme = React.useCallback((value) => { + setDisplayState((prevState) => ({ ...prevState, theme: value as ThemeType })); }, []); const renderCategories = React.useMemo(() => { @@ -79,37 +79,63 @@ const IconSearch: React.FC = () => { )); return categoriesResult.length === 0 ? : categoriesResult; }, [displayState.searchKey, displayState.theme]); + + const [searchBarAffixed, setSearchBarAffixed] = React.useState(false); + const { token } = useSiteToken(); + const { borderRadius, colorBgContainer } = token; + const affixedStyle = searchBarAffixed + ? { + boxShadow: 'rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px', + padding: 8, + margin: -8, + borderRadius, + background: colorBgContainer, + } + : {}; + return (
-
- setSearchBarAffixed(affixed)}> +
- - {' '} - {intl.formatMessage({ id: 'app.docs.components.icon.outlined' })} - - - {' '} - {intl.formatMessage({ id: 'app.docs.components.icon.filled' })} - - - {' '} - {intl.formatMessage({ id: 'app.docs.components.icon.two-tone' })} - - - handleSearchIcon(e.currentTarget.value)} - size="large" - autoFocus - /> -
+ , + label: intl.formatMessage({ id: 'app.docs.components.icon.outlined' }), + value: ThemeType.Outlined, + }, + { + icon: , + label: intl.formatMessage({ id: 'app.docs.components.icon.filled' }), + value: ThemeType.Filled, + }, + { + icon: , + label: intl.formatMessage({ id: 'app.docs.components.icon.two-tone' }), + value: ThemeType.TwoTone, + }, + ]} + /> + handleSearchIcon(e.currentTarget.value)} + size="large" + autoFocus + /> +
+ {renderCategories}
);