Skip to content

Commit

Permalink
chore: use context
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Aug 3, 2024
1 parent 650b3c0 commit bb5d52d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
10 changes: 0 additions & 10 deletions components/_util/getPrefixCls.ts

This file was deleted.

4 changes: 3 additions & 1 deletion components/bubble/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { BubbleProps } from './interface';
import Loading from './loading';
import useStyle from './style';
import useTypedEffect from './hooks/useTypedEffect';
import getPrefixCls from '../_util/getPrefixCls';
import { Avatar } from 'antd';
import useTypingConfig from './hooks/useTypingConfig';
import useConfigContext from '../config-provider/useConfigContext';

const Bubble: React.FC<Readonly<BubbleProps>> = (props) => {
const {
Expand All @@ -26,6 +26,8 @@ const Bubble: React.FC<Readonly<BubbleProps>> = (props) => {
...otherHtmlProps
} = props;

const { getPrefixCls } = useConfigContext();

const prefixCls = getPrefixCls('bubble', customizePrefixCls);

const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
Expand Down
7 changes: 7 additions & 0 deletions components/config-provider/useConfigContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ConfigProvider } from 'antd';
import * as React from 'react';

export default function useConfigContext() {
const context = React.useContext(ConfigProvider.ConfigContext);
return context;
}
7 changes: 3 additions & 4 deletions components/theme/genStyleUtils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { genStyleUtils } from '@ant-design/cssinjs-utils';
import type { ComponentTokenMap } from './components';
import type { AnyObject } from '../_util/type';
import React from 'react';
import useAntdToken from 'antd/lib/theme/useToken';
import { ConfigContext } from 'antd/lib/config-provider';
import useConfigContext from '../config-provider/useConfigContext';

export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = genStyleUtils<
ComponentTokenMap,
AnyObject,
AnyObject
>({
usePrefix: () => {
const { getPrefixCls, iconPrefixCls } = React.useContext(ConfigContext);
const { getPrefixCls, iconPrefixCls } = useConfigContext();
return {
iconPrefixCls,
rootPrefixCls: getPrefixCls(),
Expand All @@ -22,7 +21,7 @@ export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = ge
return { theme, token, hashId, realToken, cssVar };
},
useCSP: () => {
const { csp } = React.useContext(ConfigContext);
const { csp } = useConfigContext();
return csp ?? {};
},
});

0 comments on commit bb5d52d

Please sign in to comment.