mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-29 18:50:00 +08:00
type: fix useLocale type error of site (#48204)
This commit is contained in:
parent
ff231ab557
commit
4eaa664d2e
@ -1,16 +1,22 @@
|
|||||||
import { useLocale as useDumiLocale } from 'dumi';
|
import { useLocale as useDumiLocale } from 'dumi';
|
||||||
|
|
||||||
export interface LocaleMap<Key extends string> {
|
export interface LocaleMap<
|
||||||
cn: Record<Key, string>;
|
K extends PropertyKey = PropertyKey,
|
||||||
en: Record<Key, string>;
|
V extends string | ((...params: any[]) => string) = string,
|
||||||
|
> {
|
||||||
|
cn: Record<K, V>;
|
||||||
|
en: Record<K, V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function useLocale<Key extends string>(
|
const useLocale = <
|
||||||
localeMap?: LocaleMap<Key>,
|
K extends PropertyKey = PropertyKey,
|
||||||
): [Record<Key, string>, 'cn' | 'en'] {
|
V extends string | ((...params: any[]) => string) = string,
|
||||||
|
>(
|
||||||
|
localeMap?: LocaleMap<K, V>,
|
||||||
|
): [Record<K, V>, 'cn' | 'en'] => {
|
||||||
const { id } = useDumiLocale();
|
const { id } = useDumiLocale();
|
||||||
const localeType = id === 'zh-CN' ? 'cn' : 'en';
|
const localeType = id === 'zh-CN' ? 'cn' : 'en';
|
||||||
return [localeMap?.[localeType]!, localeType];
|
return [localeMap?.[localeType]!, localeType] as const;
|
||||||
}
|
};
|
||||||
|
|
||||||
export default useLocale;
|
export default useLocale;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { FormattedMessage } from 'dumi';
|
import React from 'react';
|
||||||
import React, { useMemo, useState } from 'react';
|
|
||||||
import { ColorPicker } from 'antd';
|
import { ColorPicker } from 'antd';
|
||||||
import type { Color } from 'antd/es/color-picker';
|
import type { Color } from 'antd/es/color-picker';
|
||||||
import ColorPatterns from './ColorPatterns';
|
import { FormattedMessage } from 'dumi';
|
||||||
|
|
||||||
import useLocale from '../../../hooks/useLocale';
|
import useLocale from '../../../hooks/useLocale';
|
||||||
|
import ColorPatterns from './ColorPatterns';
|
||||||
|
|
||||||
const primaryMinSaturation = 70; // 主色推荐最小饱和度
|
const primaryMinSaturation = 70; // 主色推荐最小饱和度
|
||||||
const primaryMinBrightness = 70; // 主色推荐最小亮度
|
const primaryMinBrightness = 70; // 主色推荐最小亮度
|
||||||
@ -22,8 +23,8 @@ const locales = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ColorPaletteTool: React.FC = () => {
|
const ColorPaletteTool: React.FC = () => {
|
||||||
const [primaryColor, setPrimaryColor] = useState<string>('#1890ff');
|
const [primaryColor, setPrimaryColor] = React.useState<string>('#1890ff');
|
||||||
const [primaryColorInstance, setPrimaryColorInstance] = useState<Color>(null);
|
const [primaryColorInstance, setPrimaryColorInstance] = React.useState<Color>();
|
||||||
|
|
||||||
const [locale] = useLocale(locales);
|
const [locale] = useLocale(locales);
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ const ColorPaletteTool: React.FC = () => {
|
|||||||
setPrimaryColorInstance(color);
|
setPrimaryColorInstance(color);
|
||||||
};
|
};
|
||||||
|
|
||||||
const colorValidation = useMemo<React.ReactNode>(() => {
|
const colorValidation = React.useMemo<React.ReactNode>(() => {
|
||||||
let text = '';
|
let text = '';
|
||||||
if (primaryColorInstance) {
|
if (primaryColorInstance) {
|
||||||
const { s, b } = primaryColorInstance.toHsb() || {};
|
const { s, b } = primaryColorInstance.toHsb() || {};
|
||||||
|
Loading…
Reference in New Issue
Block a user