Skip to content

Commit 4dde5e8

Browse files
authored
♻️ refactor: replace lodash-es with es-toolkit and move docs components (#6)
Replace lodash-es with es-toolkit for smaller bundle size Update antd-style to v4.1.0 and migrate to createStaticStyles Move Dashboard, EmojiItem, and VirtuosoGridList from src/components to docs/components Remove @lobehub/ui dependency from FluentEmoji core component Update docs imports to use local component paths Remove unused peer dependencies (@lobehub/ui, antd)
1 parent 764c8f4 commit 4dde5e8

8 files changed

Lines changed: 28 additions & 28 deletions

File tree

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import emojilib from '@lobehub/emojilib';
22
import { FluentEmoji, FluentEmojiProps, getFluentEmojiCDN } from '@lobehub/fluent-emoji';
33
import { Flexbox, SearchBar } from '@lobehub/ui';
44
import { Segmented } from 'antd';
5-
import { useTheme } from 'antd-style';
5+
import { cssVar } from 'antd-style';
66
import { memo, useMemo, useState } from 'react';
77

88
import EmojiItem from './EmojiItem';
99
import VirtuosoGridList from './VirtuosoGridList';
1010

1111
const Dashboard = memo(() => {
12-
const theme = useTheme();
1312
const [type, setType] = useState<FluentEmojiProps['type']>('3d');
1413
const [keyword, setKeyword] = useState<string>();
1514

@@ -56,7 +55,7 @@ const Dashboard = memo(() => {
5655
},
5756
]}
5857
style={{
59-
border: `1px solid ${theme.colorBorder}`,
58+
border: `1px solid ${cssVar.colorBorder}`,
6059
}}
6160
/>
6261
</Flexbox>
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { Center, CopyButton, Flexbox } from '@lobehub/ui';
22
import { Typography } from 'antd';
3-
import { createStyles } from 'antd-style';
4-
import { capitalize } from 'lodash-es';
3+
import { createStaticStyles } from 'antd-style';
4+
import { capitalize } from 'es-toolkit/string';
55
import { ReactNode, memo, useRef } from 'react';
66

7-
const useStyles = createStyles(({ css, token }) => {
7+
const styles = createStaticStyles(({ css, cssVar }) => {
88
return {
99
card: css`
1010
position: relative;
1111
1212
overflow: hidden;
1313
14-
border: 1px solid ${token.colorBorderSecondary};
15-
border-radius: ${token.borderRadiusLG}px;
14+
border: 1px solid ${cssVar.colorBorderSecondary};
15+
border-radius: ${cssVar.borderRadiusLG};
1616
17-
background: ${token.colorBgContainer};
17+
background: ${cssVar.colorBgContainer};
1818
`,
1919
row: css`
20-
border-block-start: 1px solid ${token.colorFillSecondary};
20+
border-block-start: 1px solid ${cssVar.colorFillSecondary};
2121
`,
2222
title: css`
2323
margin: 0;
@@ -37,7 +37,6 @@ interface IconItemProps {
3737
}
3838

3939
const EmojiItem = memo<IconItemProps>(({ children, title, url, emoji }) => {
40-
const { styles } = useStyles();
4140
const ref = useRef<HTMLDivElement>(null);
4241

4342
return (
File renamed without changes.
File renamed without changes.

docs/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Center, Flexbox, Snippet } from '@lobehub/ui';
22
import { Features, FeaturesProps } from '@lobehub/ui/awesome';
33
import { Expand, GitPullRequest, Trees } from 'lucide-react';
44

5-
import Dashboard from '@/components/Dashboard';
5+
import Dashboard from './components/Dashboard';
66

77
const items: FeaturesProps['items'] = [
88
{

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
},
7474
"dependencies": {
7575
"@lobehub/emojilib": "^1.0.0",
76-
"antd-style": "^4.0.0",
76+
"antd-style": "^4.1.0",
7777
"emoji-regex": "^10.6.0",
78-
"lodash-es": "^4.17.22",
78+
"es-toolkit": "^1.43.0",
7979
"lucide-react": "^0.562.0",
8080
"url-join": "^5.0.0"
8181
},
@@ -85,7 +85,6 @@
8585
"@lobehub/lint": "^1.26.3",
8686
"@lobehub/ui": "^4.1.2",
8787
"@testing-library/react": "^16.3.1",
88-
"@types/lodash-es": "^4.17.12",
8988
"@types/react": "^19.2.7",
9089
"@types/react-dom": "^19.2.3",
9190
"@vitest/coverage-v8": "~1.2.2",
@@ -116,8 +115,6 @@
116115
"vitest": "~1.2.2"
117116
},
118117
"peerDependencies": {
119-
"@lobehub/ui": "^4.0.0",
120-
"antd": "^6.1.1",
121118
"react": "^19.0.0",
122119
"react-dom": "^19.0.0"
123120
},

src/FluentEmoji/index.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use client';
22

3-
import { Center } from '@lobehub/ui';
3+
import { cx } from 'antd-style';
44
import { ElementType, createElement, forwardRef, useMemo, useState } from 'react';
55
import { type HTMLAttributes } from 'react';
66

77
import { getFluentEmojiCDN } from '@/getFluentEmojiCDN';
88
import { EmojiType } from '@/getFluentEmojiCDN/utils';
99

10-
import { useStyles } from './style';
10+
import { styles } from './style';
1111

1212
const createContainer = (as: ElementType) =>
1313
forwardRef((props: any, ref) => createElement(as, { ...props, ref }));
@@ -37,7 +37,6 @@ const FluentEmoji = forwardRef<any, FluentEmojiProps>(
3737
ref,
3838
) => {
3939
const [loadingFail, setLoadingFail] = useState(false);
40-
const { cx, styles } = useStyles();
4140

4241
const ImgContainer = useMemo(() => createContainer(as), [as]);
4342

@@ -48,15 +47,21 @@ const FluentEmoji = forwardRef<any, FluentEmojiProps>(
4847

4948
if (type === 'pure' || !emojiUrl || loadingFail)
5049
return (
51-
<Center
50+
<div
5251
className={cx(styles.container, className)}
53-
flex={'none'}
54-
height={size}
55-
style={{ fontSize: size * 0.9, ...style }}
56-
width={size}
52+
style={{
53+
alignItems: 'center',
54+
display: 'inline-flex',
55+
fontSize: size,
56+
height: size,
57+
justifyContent: 'center',
58+
verticalAlign: 'middle',
59+
width: size,
60+
...style,
61+
}}
5762
>
5863
{emoji}
59-
</Center>
64+
</div>
6065
);
6166

6267
return (

src/FluentEmoji/style.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { createStyles } from 'antd-style';
1+
import { createStaticStyles } from 'antd-style';
22

3-
export const useStyles = createStyles(({ css }) => {
3+
export const styles = createStaticStyles(({ css }) => {
44
return {
55
container: css`
66
position: relative;

0 commit comments

Comments
 (0)