-
Notifications
You must be signed in to change notification settings - Fork 4
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
20 changed files
with
183 additions
and
101 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useState } from 'react'; | ||
import { IntlProvider } from 'react-intl'; | ||
import { storage } from '../Utils'; | ||
import { IntlContainerProvider } from './useIntlConfigProvider'; | ||
|
||
type IThemeProvider = { | ||
locales: { | ||
'zh-CN': Record<string, string>; | ||
'en-US': Record<string, string>; | ||
}; | ||
children: React.ReactNode; | ||
locale?: 'zh-CN' | 'en-US'; | ||
}; | ||
|
||
const Provider: React.FC<IThemeProvider> = props => { | ||
const { children, locales } = props; | ||
const [state, setState] = useState<{ locale?: 'zh-CN' | 'en-US' }>(() => { | ||
let { locale = storage.get('locale') } = props; | ||
if (!locale) { | ||
locale = 'en-US'; | ||
} | ||
storage.set('locale', locale); | ||
return { | ||
locale, | ||
}; | ||
}); | ||
|
||
const { locale } = state; | ||
|
||
const messages = locales[locale || 'en-US']; | ||
|
||
const handleLocale = themeConfig => { | ||
const { locale } = themeConfig; | ||
storage.set('locale', locale); | ||
setState(preState => { | ||
return { | ||
...preState, | ||
locale, | ||
}; | ||
}); | ||
}; | ||
console.log('locale111', locale); | ||
|
||
return ( | ||
<IntlContainerProvider value={{ handleLocale }}> | ||
<IntlProvider messages={messages} locale={locale as 'zh-CN' | 'en-US'}> | ||
{children} | ||
</IntlProvider> | ||
</IntlContainerProvider> | ||
); | ||
}; | ||
|
||
export default Provider; |
23 changes: 23 additions & 0 deletions
23
packages/studio-components/src/IntlProvider/useIntlConfigProvider.tsx
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,23 @@ | ||
import { createContext, useContext } from 'react'; | ||
|
||
export interface ThemeProviderType { | ||
locale?: 'zh-CN' | 'en-US'; | ||
} | ||
export interface IContainerContext extends ThemeProviderType { | ||
handleLocale: (value: ThemeProviderType) => void; | ||
} | ||
export const IntlContainerContext = createContext<IContainerContext>({ | ||
handleLocale: ({}) => {}, | ||
locale: 'en-US', | ||
}); | ||
|
||
export const IntlContainerProvider = IntlContainerContext.Provider; | ||
|
||
export const useIntlContainer = () => { | ||
const context = useContext(IntlContainerContext); | ||
|
||
if (context === undefined || Object.keys(context).length === 0) { | ||
throw new Error(`useContext must be used within a ContainerProvider`); | ||
} | ||
return context; | ||
}; |
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
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
29 changes: 29 additions & 0 deletions
29
packages/studio-components/src/Provider/useCustomTheme.tsx
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,29 @@ | ||
import { ThemeProviderType } from './useThemeConfigProvider'; | ||
import { useThemeContainer } from './useThemeConfigProvider'; | ||
export interface IColorStore { | ||
sectionBackground?: string; | ||
containerBackground?: string; | ||
instanceBackground?: string; | ||
jobDetailBorder?: string; | ||
jobDetailColor?: string; | ||
pluginBorder?: string; | ||
editorBackground?: string; | ||
editorForeground?: string; | ||
} | ||
|
||
export const useCustomTheme = () => { | ||
const { algorithm } = useThemeContainer(); | ||
const isLight = algorithm === 'defaultAlgorithm'; | ||
/** 特殊颜色配置 */ | ||
const colorConfig = { | ||
sectionBackground: isLight ? '#fff' : '#0D0D0D', | ||
containerBackground: isLight ? '#f5f7f9' : '#020202', | ||
instanceBackground: isLight ? '#FCFCFC' : '', | ||
jobDetailBorder: isLight ? '#efefef' : '#323232', | ||
jobDetailColor: isLight ? '#1F1F1F' : '#808080', | ||
pluginBorder: isLight ? '#efefef' : '#323232', | ||
editorBackground: isLight ? '#fff' : '#151515', | ||
editorForeground: isLight ? '#212121' : '#FFF', | ||
}; | ||
return colorConfig; | ||
}; |
2 changes: 1 addition & 1 deletion
2
packages/studio-components/src/Provider/useThemeConfigProvider.tsx
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
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
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
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
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
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
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
Oops, something went wrong.