Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(color-picker): add locale support for color mode switch #3221

Merged
merged 4 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/color-picker/components/panel/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { COLOR_MODES } from '../../const';
import Radio, { RadioValue } from '../../../radio';
import { TdColorModes } from '../../interface';
import { TdColorPickerProps } from '../../type';
import { useLocaleReceiver } from '../../../locale/LocalReceiver';

export interface ColorPanelHeaderProps extends TdColorPickerProps {
mode?: TdColorModes;
Expand All @@ -12,6 +13,8 @@ export interface ColorPanelHeaderProps extends TdColorPickerProps {
}

const Header = (props: ColorPanelHeaderProps) => {
const [local, t] = useLocaleReceiver('colorPicker');

const { baseClassName, mode = 'monochrome', colorModes, onModeChange } = props;

const isSingleMode = colorModes?.length === 1;
Expand All @@ -23,17 +26,13 @@ const Header = (props: ColorPanelHeaderProps) => {
return (
<div className={`${baseClassName}__head`}>
<div className={`${baseClassName}__mode`}>
{colorModes?.length === 1 ? (
COLOR_MODES[colorModes[0]]
) : (
<Radio.Group variant="default-filled" size="small" value={mode} onChange={onModeChange}>
{Object.keys(COLOR_MODES).map((key) => (
<Radio.Button key={key} value={key}>
{COLOR_MODES[key]}
</Radio.Button>
))}
</Radio.Group>
)}
<Radio.Group variant="default-filled" size="small" value={mode} onChange={onModeChange}>
{Object.keys(COLOR_MODES).map((key) => (
<Radio.Button key={key} value={key}>
{t(local[COLOR_MODES[key]])}
</Radio.Button>
))}
</Radio.Group>
</div>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/color-picker/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const TD_COLOR_USED_COLORS_MAX_SIZE = 100; // 每行10个

// 颜色模式options配置
export const COLOR_MODES = {
monochrome: '单色',
'linear-gradient': '渐变',
monochrome: 'singleColor',
'linear-gradient': 'gradientColor',
};

// 非透明色格式化类型
Expand Down
Loading