Skip to content

Commit

Permalink
imporve(ui): ContentWithQuestion less => cssinjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanleehao committed Nov 10, 2023
1 parent df448d7 commit 0abd062
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/ui/src/ContentWithQuestion/index.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,6 +18,7 @@ export interface ContentWithQuestionProps {
const prefix = getPrefix('content-with-question');

const ContentWithQuestion: React.FC<ContentWithQuestionProps> = ({
prefixCls: customizePrefixCls,
content,
tooltip,
prefixIcon = null,
Expand All @@ -28,23 +27,29 @@ const ContentWithQuestion: React.FC<ContentWithQuestionProps> = ({
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 ? (
<Tooltip {...tooltip}>
{isValidElement(iconConfig) ? (
iconConfig
) : (
<QuestionCircleOutlined className={`${prefix}-help`} />
<QuestionCircleOutlined className={`${prefixCls}-help`} />
)}
</Tooltip>
) : null;
};

return (
return wrapSSR(
<span
// eslint-disable-next-line react/no-unknown-property
prefixCls={customizePrefixCls}
className={classNames({
[`${prefix}-item`]: true,
[`${prefixCls}-item`]: true,
[className]: !!className,
})}
{...restProps}
Expand All @@ -53,7 +58,7 @@ const ContentWithQuestion: React.FC<ContentWithQuestionProps> = ({
{getIcon(
prefixIcon === true ? (
<QuestionCircleOutlined
className={`${prefix}-help`}
className={`${prefixCls}-help`}
style={{
marginRight: 4,
}}
Expand Down
33 changes: 33 additions & 0 deletions packages/ui/src/ContentWithQuestion/style/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { CSSObject } from '@ant-design/cssinjs';
import type { GenerateStyle } from '@oceanbase/design/es/theme';
import { genComponentStyleHook } from '../../_util/genComponentStyleHook';

export const genContentWithQuestionStyle: GenerateStyle<any> = (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);
};

0 comments on commit 0abd062

Please sign in to comment.