Skip to content

Commit

Permalink
✨ feat: add styled usage
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jan 1, 2023
1 parent 072b7e4 commit ab86f5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './styled';
export * from './types';
export * from './useToken';
32 changes: 32 additions & 0 deletions src/styled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// =========== styled 方案 =========== //
// 适用场景:看上去像是一个自定义样式组件的场景,且可能会有相应的入参
// 推荐使用 styled 将其包裹为一个样式组件
import { Theme, ThemeProvider as Provider } from '@emotion/react';
import { FC, memo, PropsWithChildren } from 'react';

import { AntdToken } from './types';
import { useToken } from './useToken';

declare module '@emotion/react' {
interface Theme extends AntdToken {
stylish?: any;
}
}

export interface ThemeProviderProps {
customToken?: Record<string, any>;
customStylish?: Record<string, string>;
}

export const ThemeProvider: FC<PropsWithChildren<ThemeProviderProps>> = memo(
({ children, customToken, customStylish }) => {
const token = useToken();

const stylish = customStylish ?? {};
const theme: Theme = { ...token, ...customToken, stylish };

return <Provider theme={theme}>{children}</Provider>;
},
);

export { default as styled } from '@emotion/styled';

0 comments on commit ab86f5d

Please sign in to comment.