-
Notifications
You must be signed in to change notification settings - Fork 20
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
zzZ
committed
Nov 12, 2024
1 parent
3b5b2a4
commit 1d57456
Showing
41 changed files
with
526 additions
and
247 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useModel } from '@zhangsai/model'; | ||
import { themeColors, themeModel } from '@/models/theme'; | ||
import { ThemeConfig, theme } from 'antd'; | ||
|
||
/** 根据themeModel映射一份antd theme的配置 */ | ||
export function useAntdTheme(darkMode?: boolean): ThemeConfig { | ||
const curDarkMode = useModel(themeModel, 'curDarkMode'); | ||
const colorPrimary = useModel(themeModel, 'colorPrimary'); | ||
const isDark = (darkMode ?? curDarkMode); | ||
|
||
return { | ||
algorithm: isDark ? theme.darkAlgorithm : theme.defaultAlgorithm, | ||
token: { | ||
colorPrimary, | ||
colorBgLayout: isDark ? themeColors.dark['--layout-background-color'] : themeColors.light['--layout-background-color'], | ||
colorBgContainer: isDark ? themeColors.dark['--container-background-color'] : themeColors.light['--container-background-color'], | ||
}, | ||
}; | ||
} |
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,30 @@ | ||
import { PropsWithChildren, useEffect } from 'react'; | ||
import { App as AntdApp } from 'antd'; | ||
import type { MessageInstance } from 'antd/lib/message/interface'; | ||
import type { ModalStaticFunctions } from 'antd/lib/modal/confirm'; | ||
import type { NotificationInstance } from 'antd/lib/notification/interface'; | ||
|
||
let message: MessageInstance; | ||
let notification: NotificationInstance; | ||
let modal: Omit<ModalStaticFunctions, 'warn'>; | ||
|
||
const AntdStaticFnInit = ({ children }: PropsWithChildren) => { | ||
const { | ||
message: antdMessage, | ||
notification: antdNotification, | ||
modal: antdModal, | ||
} = AntdApp.useApp(); | ||
|
||
useEffect(() => { | ||
message = antdMessage; | ||
notification = antdNotification; | ||
modal = antdModal; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return children; | ||
}; | ||
|
||
export default AntdStaticFnInit; | ||
|
||
export { message, notification, modal }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import TooltipIcon from '../components/TooltipIcon'; | ||
import SvgIcon from '@/components/SvgIcon'; | ||
import { themeModel } from '@/models/theme'; | ||
import { useModel } from '@zhangsai/model'; | ||
import { ColorPicker as AntdColorPicker } from 'antd'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export const ColorPrimaryPreset = [{ | ||
label: 'red', | ||
colors: ['#d7003a', '#e2041b', '#c9171e', '#bf242a', '#b94047', '#a73836', '#d9333f', '#a22041', '#d0576b', '#e9546b', '#ec6d71', '#c85179', '#e7609e', '#a25768', '#bb5548'], | ||
}, { | ||
label: 'origin', | ||
colors: ['#ea5506', '#eb6238', '#ec6d51', '#ed6d3d', '#ee7800', '#e17b34', '#f08300', '#f39800', '#f8b862', '#deb068', '#bc763c', '#ad7d4c', '#b68d4c', '#ae7c58', '#e6b422', '#f8b500'], | ||
}, { | ||
label: 'green', | ||
colors: ['#69b076', '#88cb7f', '#98d98e', '#93b881', '#769164', '#316745', '#47885e', '#007b43', '#38b48b', '#3b7960', '#028760', '#7ebea5', '#00552e', '#005243'], | ||
}, { | ||
label: 'blue', | ||
colors: ['#1c305c', '#223a70', '#164a84', '#19448e', '#165e83', '#507ea4', '#5a79ba', '#007bbb', '#0095d9', '#2ca9e1', '#2a83a2', '#008899', '#84b9cb', '#84a2d4', '#a0d8ef'], | ||
}, { | ||
label: 'purple', | ||
colors: ['#4a488e', '#867ba9', '#a59aca', '#674598', '#9079ad', '#65318e', '#522f60', '#493759', '#884898', '#460e44', '#74325c', '#55295b', '#7a4171', '#9d5b8b', '#bc64a4', '#aa4c8f'], | ||
}]; | ||
|
||
export const AntdColorPickerColorPrimaryPreset = ColorPrimaryPreset.map(item => { | ||
return { | ||
label: item.label, | ||
colors: item.colors.slice(0), | ||
}; | ||
}); | ||
|
||
const ColorPicker = () => { | ||
const colorPrimary = useModel(themeModel, 'colorPrimary'); | ||
const { t: t_layout } = useTranslation('layout'); | ||
|
||
return ( | ||
<AntdColorPicker | ||
value={colorPrimary} | ||
onChange={(val) => { | ||
themeModel.setThemeState({ colorPrimary: val.toHexString() }); | ||
}} | ||
presets={AntdColorPickerColorPrimaryPreset} | ||
> | ||
<TooltipIcon | ||
title={t_layout('主题色')} | ||
icon={<SvgIcon name="color_picker" size={20} color={colorPrimary} />} | ||
/> | ||
</AntdColorPicker> | ||
); | ||
}; | ||
|
||
export default ColorPicker; |
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.