Skip to content

Commit

Permalink
♻️ fix: 将 styled-components 替换为 @emotion/styled, 减少产物体积
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 17, 2023
1 parent 727fefb commit 616d464
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion example/.dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default defineConfig({
alias: {
'dumi-theme-antd-style': path.join(__dirname, '../src'),
},

extraBabelPlugins: ['@emotion'],
styles: [
`html, body { background: transparent; }
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"dependencies": {
"@babel/runtime": "^7",
"@emotion/styled": "^11",
"@floating-ui/react": "^0.17",
"animated-scroll-to": "^2",
"antd-style": "alpha",
Expand All @@ -68,13 +69,14 @@
"react-layout-kit": "^1",
"react-syntax-highlighter": "^15",
"shiki-es": "^0.2",
"styled-components": "beta",
"use-merge-value": "^1",
"zustand": "^4"
},
"devDependencies": {
"@ant-design/icons": "^5",
"@commitlint/cli": "^17",
"@emotion/babel-plugin": "^11",
"@emotion/react": "^11",
"@emotion/styled": "^11.10.5",
"@testing-library/jest-dom": "^5",
"@testing-library/react": "^13",
Expand Down
10 changes: 7 additions & 3 deletions src/components/ApiHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import NpmFilled from './NpmFilled';
import PackagePhobia from './PackagePhobia';
import Unpkg from './Unpkg';

import { Label, useStyles } from './style';
import { useStyles } from './style';

interface ApiTitleProps {
title: string;
Expand Down Expand Up @@ -93,9 +93,13 @@ export const ApiHeader: FC<ApiTitleProps> = memo(
)}
<Flexbox style={{ marginTop: 16 }} gap={mobile ? 16 : 24}>
<Flexbox horizontal={!mobile} gap={mobile ? 12 : 0}>
<Label type={'secondary'} style={{ display: 'flex', alignItems: 'center' }}>
<Typography.Text
className={styles.label}
type={'secondary'}
style={{ display: 'flex', alignItems: 'center' }}
>
引入方法
</Label>
</Typography.Text>
<Code>{`import { ${componentName} } from '${pkg}';`}</Code>
</Flexbox>
<Divider dashed style={{ margin: '2px 0' }} />
Expand Down
9 changes: 3 additions & 6 deletions src/components/ApiHeader/style.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import { Typography } from 'antd';
import { createStyles } from 'antd-style';
import { styled } from 'styled-components';

export const Label = styled(Typography.Text)`
width: 80px;
` as any;

export const useStyles = createStyles(({ css, token, responsive: r, stylish }) => ({
title: css`
Expand All @@ -14,6 +8,9 @@ export const useStyles = createStyles(({ css, token, responsive: r, stylish }) =
font-size: 32px !important;
}
`,
label: css`
width: 80px;
`,
desc: css`
font-size: ${token.fontSizeLG}px;
line-height: ${token.lineHeightLG}px;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Burger/style.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from '@emotion/styled';
import { createStyles } from 'antd-style';
import { rgba } from 'polished';
import { styled } from 'styled-components';

export const FillRect = styled.div`
background: ${(p) => rgba(p.theme.colorBgContainer, 0.8)};
Expand Down
4 changes: 2 additions & 2 deletions src/components/NativeSelect/SelectItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useStyles } from './style';
interface SelectItemProps {
value: any;
label: any;
prefixCls?: string;
prefixCls: string;
isSelected?: boolean;
isActive?: boolean;
ref?: ForwardedRef<HTMLButtonElement>;
Expand All @@ -14,7 +14,7 @@ interface SelectItemProps {

const SelectItem: FC<SelectItemProps> = forwardRef(
({ value, label, prefixCls, isSelected, isActive, disabled, ...props }, ref) => {
const { styles, cx } = useStyles({ prefixCls, selected: isSelected });
const { styles, cx } = useStyles(prefixCls);

return (
<button
Expand Down
1 change: 1 addition & 0 deletions src/components/NativeSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const NativeSelect: FC<NativeSelectProps> = ({
{options.map((item, i) => {
return (
<SelectItem
prefixCls={cls}
key={item.value}
value={item.value}
label={renderItem ? renderItem(item, i) : item.label}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ThemeSwitch/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from '@emotion/styled';
import type { ThemeMode } from 'antd-style';
import { memo, ReactNode, type FC } from 'react';
import { Flexbox } from 'react-layout-kit';
import { styled } from 'styled-components';

import { useThemeStore } from '../../store/useThemeStore';
import NativeSelect from '../NativeSelect';
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["src", "tests", ".dumi/**/*", "example/.dumirc.ts", "*.ts"],
"include": ["src", "tests", ".dumi/**/*", "typings", "example/.dumirc.ts", "*.ts"],
"compilerOptions": {
"strict": true,
"declaration": true,
Expand Down
6 changes: 6 additions & 0 deletions typings/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Theme as AntdStyleTheme } from 'antd-style';

declare module '@emotion/react' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Theme extends AntdStyleTheme {}
}

1 comment on commit 616d464

@vercel
Copy link

@vercel vercel bot commented on 616d464 Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.