From 0abd062e260c0a2379a61d8633ba9915c696135a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=BB=BA=E5=9B=BD?= Date: Fri, 10 Nov 2023 15:38:00 +0800 Subject: [PATCH] imporve(ui): ContentWithQuestion less => cssinjs --- packages/ui/src/ContentWithQuestion/index.tsx | 23 ++++++++----- .../ui/src/ContentWithQuestion/style/index.ts | 33 +++++++++++++++++++ 2 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 packages/ui/src/ContentWithQuestion/style/index.ts diff --git a/packages/ui/src/ContentWithQuestion/index.tsx b/packages/ui/src/ContentWithQuestion/index.tsx index 9b5d28a54..5083135ed 100644 --- a/packages/ui/src/ContentWithQuestion/index.tsx +++ b/packages/ui/src/ContentWithQuestion/index.tsx @@ -1,11 +1,9 @@ import { QuestionCircleOutlined } from '@oceanbase/icons'; -import { Space, Tooltip } from '@oceanbase/design'; +import { ConfigProvider, Space, Tooltip } from '@oceanbase/design'; import classNames from 'classnames'; -import React, { isValidElement } from 'react'; +import React, { useContext, isValidElement } from 'react'; import { getPrefix } from '../_util'; -import './index.less'; - -type IconPosition = 'prefix' | 'suffix'; +import useStyle from './style'; export interface ContentWithQuestionProps { content?: React.ReactNode; @@ -20,6 +18,7 @@ export interface ContentWithQuestionProps { const prefix = getPrefix('content-with-question'); const ContentWithQuestion: React.FC = ({ + prefixCls: customizePrefixCls, content, tooltip, prefixIcon = null, @@ -28,6 +27,10 @@ const ContentWithQuestion: React.FC = ({ children, ...restProps }: any) => { + const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); + const prefixCls = getPrefixCls('content-with-question', customizePrefixCls); + const { wrapSSR } = useStyle(prefixCls); + // FIXME: antd 已经废弃 icon type 的用法,该组件也需要做相应处理,后面将会是传入 Icon 的形式而非 type const getIcon = (iconConfig: React.ReactNode) => { return iconConfig ? ( @@ -35,16 +38,18 @@ const ContentWithQuestion: React.FC = ({ {isValidElement(iconConfig) ? ( iconConfig ) : ( - + )} ) : null; }; - return ( + return wrapSSR( = ({ {getIcon( prefixIcon === true ? ( = (token: any): CSSObject => { + const { componentCls, paddingSM } = token; + + return { + [`${componentCls}-item`]: { + display: 'inline-flex', + alignItems: 'center', + [`${componentCls}-prefix`]: { + marginRight: paddingSM, + }, + [`${componentCls}-suffix`]: { + marginLeft: paddingSM, + }, + [`${componentCls}-help`]: { + cursor: 'help', + }, + [`${componentCls}-color`]: { + color: 'red', + }, + }, + }; +}; + +export default (prefixCls: string) => { + const useStyle = genComponentStyleHook('ContentWithQuestion', token => { + return [genContentWithQuestionStyle(token as any)]; + }); + return useStyle(prefixCls); +};