generated from arvinxx/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './styled'; | ||
export * from './types'; | ||
export * from './useToken'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |