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';
|
||||
|
||||
export interface LocaleMap<Key extends string> {
|
||||
cn: Record<Key, string>;
|
||||
en: Record<Key, string>;
|
||||
export interface LocaleMap<
|
||||
K extends PropertyKey = PropertyKey,
|
||||
V extends string | ((...params: any[]) => string) = string,
|
||||
> {
|
||||
cn: Record<K, V>;
|
||||
en: Record<K, V>;
|
||||
}
|
||||
|
||||
function useLocale<Key extends string>(
|
||||
localeMap?: LocaleMap<Key>,
|
||||
): [Record<Key, string>, 'cn' | 'en'] {
|
||||
const useLocale = <
|
||||
K extends PropertyKey = PropertyKey,
|
||||
V extends string | ((...params: any[]) => string) = string,
|
||||
>(
|
||||
localeMap?: LocaleMap<K, V>,
|
||||
): [Record<K, V>, 'cn' | 'en'] => {
|
||||
const { id } = useDumiLocale();
|
||||
const localeType = id === 'zh-CN' ? 'cn' : 'en';
|
||||
return [localeMap?.[localeType]!, localeType];
|
||||
}
|
||||
return [localeMap?.[localeType]!, localeType] as const;
|
||||
};
|
||||
|
||||
export default useLocale;
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { FormattedMessage } from 'dumi';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import React from 'react';
|
||||
import { ColorPicker } from 'antd';
|
||||
import type { Color } from 'antd/es/color-picker';
|
||||
import ColorPatterns from './ColorPatterns';
|
||||
import { FormattedMessage } from 'dumi';
|
||||
|
||||
import useLocale from '../../../hooks/useLocale';
|
||||
import ColorPatterns from './ColorPatterns';
|
||||
|
||||
const primaryMinSaturation = 70; // 主色推荐最小饱和度
|
||||
const primaryMinBrightness = 70; // 主色推荐最小亮度
|
||||
@ -22,8 +23,8 @@ const locales = {
|
||||
};
|
||||
|
||||
const ColorPaletteTool: React.FC = () => {
|
||||
const [primaryColor, setPrimaryColor] = useState<string>('#1890ff');
|
||||
const [primaryColorInstance, setPrimaryColorInstance] = useState<Color>(null);
|
||||
const [primaryColor, setPrimaryColor] = React.useState<string>('#1890ff');
|
||||
const [primaryColorInstance, setPrimaryColorInstance] = React.useState<Color>();
|
||||
|
||||
const [locale] = useLocale(locales);
|
||||
|
||||
@ -32,7 +33,7 @@ const ColorPaletteTool: React.FC = () => {
|
||||
setPrimaryColorInstance(color);
|
||||
};
|
||||
|
||||
const colorValidation = useMemo<React.ReactNode>(() => {
|
||||
const colorValidation = React.useMemo<React.ReactNode>(() => {
|
||||
let text = '';
|
||||
if (primaryColorInstance) {
|
||||
const { s, b } = primaryColorInstance.toHsb() || {};
|
||||
|
Loading…
Reference in New Issue
Block a user