mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
commit
890a65f1bd
@ -85,8 +85,11 @@ const IconSearch: React.FC = () => {
|
|||||||
iconList = iconList.filter((iconName) => iconName.toLowerCase().includes(matchKey));
|
iconList = iconList.filter((iconName) => iconName.toLowerCase().includes(matchKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyrightCircle is same as Copyright, don't show it
|
const ignore = [
|
||||||
iconList = iconList.filter((icon) => icon !== 'CopyrightCircle');
|
'CopyrightCircle', // same as Copyright
|
||||||
|
'DollarCircle', // same as Dollar
|
||||||
|
];
|
||||||
|
iconList = iconList.filter((icon) => !ignore.includes(icon));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
category: key,
|
category: key,
|
||||||
@ -121,11 +124,11 @@ const IconSearch: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="markdown">
|
<div className='markdown'>
|
||||||
<Affix offsetTop={24} onChange={setSearchBarAffixed}>
|
<Affix offsetTop={24} onChange={setSearchBarAffixed}>
|
||||||
<div css={iconSearchAffix} style={searchBarAffixed ? affixedStyle : {}}>
|
<div css={iconSearchAffix} style={searchBarAffixed ? affixedStyle : {}}>
|
||||||
<Segmented
|
<Segmented
|
||||||
size="large"
|
size='large'
|
||||||
value={displayState.theme}
|
value={displayState.theme}
|
||||||
options={options(intl)}
|
options={options(intl)}
|
||||||
onChange={handleChangeTheme}
|
onChange={handleChangeTheme}
|
||||||
@ -135,7 +138,7 @@ const IconSearch: React.FC = () => {
|
|||||||
style={{ flex: 1, marginInlineStart: 16 }}
|
style={{ flex: 1, marginInlineStart: 16 }}
|
||||||
allowClear
|
allowClear
|
||||||
autoFocus
|
autoFocus
|
||||||
size="large"
|
size='large'
|
||||||
onChange={handleSearchIcon}
|
onChange={handleSearchIcon}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
1
.husky/.gitignore
vendored
1
.husky/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
_
|
|
@ -28,7 +28,7 @@ export interface ColorPickerProps
|
|||||||
> {
|
> {
|
||||||
value?: Color | string;
|
value?: Color | string;
|
||||||
defaultValue?: Color | string;
|
defaultValue?: Color | string;
|
||||||
children?: React.ReactElement;
|
children?: React.ReactNode;
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
placement?: TriggerPlacement;
|
placement?: TriggerPlacement;
|
||||||
|
@ -17,7 +17,7 @@ const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
|||||||
const { prefixCls, allowClear, presets, onChange, onClear, color, ...injectProps } = props;
|
const { prefixCls, allowClear, presets, onChange, onClear, color, ...injectProps } = props;
|
||||||
const colorPickerPanelPrefixCls = `${prefixCls}-inner-panel`;
|
const colorPickerPanelPrefixCls = `${prefixCls}-inner-panel`;
|
||||||
|
|
||||||
const extraPanelRender = (panel: React.ReactElement) => (
|
const extraPanelRender = (panel: React.ReactNode) => (
|
||||||
<div className={colorPickerPanelPrefixCls}>
|
<div className={colorPickerPanelPrefixCls}>
|
||||||
{allowClear && (
|
{allowClear && (
|
||||||
<ColorClear
|
<ColorClear
|
||||||
@ -31,22 +31,11 @@ const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{panel}
|
{panel}
|
||||||
<ColorInput
|
<ColorInput value={color} onChange={onChange} prefixCls={prefixCls} {...injectProps} />
|
||||||
value={color}
|
|
||||||
onChange={(value) => onChange?.(value)}
|
|
||||||
prefixCls={prefixCls}
|
|
||||||
{...injectProps}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{Array.isArray(presets) && (
|
{Array.isArray(presets) && (
|
||||||
<>
|
<>
|
||||||
<Divider className={`${colorPickerPanelPrefixCls}-divider`} />
|
<Divider className={`${colorPickerPanelPrefixCls}-divider`} />
|
||||||
<ColorPresets
|
<ColorPresets value={color} presets={presets} prefixCls={prefixCls} onChange={onChange} />
|
||||||
value={color}
|
|
||||||
presets={presets}
|
|
||||||
onChange={(value) => onChange?.(value)}
|
|
||||||
prefixCls={prefixCls}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@ -60,4 +49,9 @@ const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
ColorPickerPanel.displayName = 'ColorPickerPanel';
|
||||||
|
}
|
||||||
|
|
||||||
export default ColorPickerPanel;
|
export default ColorPickerPanel;
|
||||||
|
@ -2187,7 +2187,7 @@ exports[`renders components/color-picker/demo/format.tsx extend context correctl
|
|||||||
>
|
>
|
||||||
HSB:
|
HSB:
|
||||||
<span>
|
<span>
|
||||||
hsb(215,91%,100%)
|
hsb(215, 91%, 100%)
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -2815,7 +2815,7 @@ exports[`renders components/color-picker/demo/format.tsx extend context correctl
|
|||||||
>
|
>
|
||||||
RGB:
|
RGB:
|
||||||
<span>
|
<span>
|
||||||
rgb(22,119,255)
|
rgb(22, 119, 255)
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -3973,7 +3973,7 @@ Array [
|
|||||||
style="margin-right: 8px;"
|
style="margin-right: 8px;"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
style="width: 20px; height: 20px; border-radius: 4px; background: rgb(22, 119, 255);"
|
style="width: 20px; height: 20px; border-radius: 4px; background-color: rgb(22, 119, 255);"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
@ -135,7 +135,7 @@ exports[`renders components/color-picker/demo/format.tsx correctly 1`] = `
|
|||||||
>
|
>
|
||||||
HSB:
|
HSB:
|
||||||
<span>
|
<span>
|
||||||
hsb(215,91%,100%)
|
hsb(215, 91%, 100%)
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -180,7 +180,7 @@ exports[`renders components/color-picker/demo/format.tsx correctly 1`] = `
|
|||||||
>
|
>
|
||||||
RGB:
|
RGB:
|
||||||
<span>
|
<span>
|
||||||
rgb(22,119,255)
|
rgb(22, 119, 255)
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -234,7 +234,7 @@ exports[`renders components/color-picker/demo/trigger.tsx correctly 1`] = `
|
|||||||
style="margin-right:8px"
|
style="margin-right:8px"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
style="width:20px;height:20px;border-radius:4px;background:#1677ff"
|
style="width:20px;height:20px;border-radius:4px;background-color:#1677ff"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
@ -12,7 +12,7 @@ interface ColorAlphaInputProps extends Pick<ColorPickerBaseProps, 'prefixCls'> {
|
|||||||
|
|
||||||
const ColorAlphaInput: FC<ColorAlphaInputProps> = ({ prefixCls, value, onChange }) => {
|
const ColorAlphaInput: FC<ColorAlphaInputProps> = ({ prefixCls, value, onChange }) => {
|
||||||
const colorAlphaInputPrefixCls = `${prefixCls}-alpha-input`;
|
const colorAlphaInputPrefixCls = `${prefixCls}-alpha-input`;
|
||||||
const [alphaValue, setAlphaValue] = useState(generateColor(value || '#000'));
|
const [alphaValue, setAlphaValue] = useState<Color>(generateColor(value || '#000'));
|
||||||
|
|
||||||
// Update step value
|
// Update step value
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -18,7 +18,7 @@ const ColorClear: FC<ColorClearProps> = ({ prefixCls, value, onChange }) => {
|
|||||||
onChange?.(genColor);
|
onChange?.(genColor);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return <div className={`${prefixCls}-clear`} onClick={handleClick} />;
|
return <div className={`${prefixCls}-clear`} onClick={handleClick} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ColorClear;
|
export default ColorClear;
|
||||||
|
@ -14,7 +14,7 @@ interface ColorHsbInputProps extends Pick<ColorPickerBaseProps, 'prefixCls'> {
|
|||||||
|
|
||||||
const ColorHsbInput: FC<ColorHsbInputProps> = ({ prefixCls, value, onChange }) => {
|
const ColorHsbInput: FC<ColorHsbInputProps> = ({ prefixCls, value, onChange }) => {
|
||||||
const colorHsbInputPrefixCls = `${prefixCls}-hsb-input`;
|
const colorHsbInputPrefixCls = `${prefixCls}-hsb-input`;
|
||||||
const [hsbValue, setHsbValue] = useState(generateColor(value || '#000'));
|
const [hsbValue, setHsbValue] = useState<Color>(generateColor(value || '#000'));
|
||||||
|
|
||||||
// Update step value
|
// Update step value
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import type { FC } from 'react';
|
|
||||||
import React from 'react';
|
|
||||||
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
||||||
|
import type { FC } from 'react';
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
import Select from '../../select';
|
import Select from '../../select';
|
||||||
|
import type { Color } from '../color';
|
||||||
import type { ColorPickerBaseProps } from '../interface';
|
import type { ColorPickerBaseProps } from '../interface';
|
||||||
import { ColorFormat } from '../interface';
|
import { ColorFormat } from '../interface';
|
||||||
import type { Color } from '../color';
|
|
||||||
import ColorAlphaInput from './ColorAlphaInput';
|
import ColorAlphaInput from './ColorAlphaInput';
|
||||||
import ColorHexInput from './ColorHexInput';
|
import ColorHexInput from './ColorHexInput';
|
||||||
import ColorHsbInput from './ColorHsbInput';
|
import ColorHsbInput from './ColorHsbInput';
|
||||||
@ -16,8 +16,13 @@ interface ColorInputProps
|
|||||||
onChange?: (value: Color) => void;
|
onChange?: (value: Color) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectOptions = [ColorFormat.hex, ColorFormat.hsb, ColorFormat.rgb].map((format) => ({
|
||||||
|
value: format,
|
||||||
|
label: format.toLocaleUpperCase(),
|
||||||
|
}));
|
||||||
|
|
||||||
const ColorInput: FC<ColorInputProps> = (props) => {
|
const ColorInput: FC<ColorInputProps> = (props) => {
|
||||||
const { prefixCls, format, onFormatChange, value, onChange } = props;
|
const { prefixCls, format, value, onFormatChange, onChange } = props;
|
||||||
const [colorFormat, setColorFormat] = useMergedState('hex', {
|
const [colorFormat, setColorFormat] = useMergedState('hex', {
|
||||||
value: format,
|
value: format,
|
||||||
onChange: onFormatChange,
|
onChange: onFormatChange,
|
||||||
@ -29,17 +34,18 @@ const ColorInput: FC<ColorInputProps> = (props) => {
|
|||||||
setColorFormat(newFormat);
|
setColorFormat(newFormat);
|
||||||
};
|
};
|
||||||
|
|
||||||
const steppersRender = () => {
|
const steppersNode = useMemo<React.ReactNode>(() => {
|
||||||
|
const inputProps = { value, prefixCls, onChange };
|
||||||
switch (colorFormat) {
|
switch (colorFormat) {
|
||||||
case ColorFormat.hsb:
|
case ColorFormat.hsb:
|
||||||
return <ColorHsbInput value={value} onChange={onChange} prefixCls={prefixCls} />;
|
return <ColorHsbInput {...inputProps} />;
|
||||||
case ColorFormat.rgb:
|
case ColorFormat.rgb:
|
||||||
return <ColorRgbInput value={value} onChange={onChange} prefixCls={prefixCls} />;
|
return <ColorRgbInput {...inputProps} />;
|
||||||
case ColorFormat.hex:
|
case ColorFormat.hex:
|
||||||
default:
|
default:
|
||||||
return <ColorHexInput value={value} onChange={onChange} prefixCls={prefixCls} />;
|
return <ColorHexInput {...inputProps} />;
|
||||||
}
|
}
|
||||||
};
|
}, [colorFormat, prefixCls, value, onChange]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`${colorInputPrefixCls}-container`}>
|
<div className={`${colorInputPrefixCls}-container`}>
|
||||||
@ -52,24 +58,12 @@ const ColorInput: FC<ColorInputProps> = (props) => {
|
|||||||
onChange={handleFormatChange}
|
onChange={handleFormatChange}
|
||||||
className={`${prefixCls}-format-select`}
|
className={`${prefixCls}-format-select`}
|
||||||
size="small"
|
size="small"
|
||||||
options={[
|
options={selectOptions}
|
||||||
{
|
|
||||||
label: ColorFormat.hex.toLocaleUpperCase(),
|
|
||||||
value: ColorFormat.hex,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: ColorFormat.hsb.toLocaleUpperCase(),
|
|
||||||
value: ColorFormat.hsb,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: ColorFormat.rgb.toLocaleUpperCase(),
|
|
||||||
value: ColorFormat.rgb,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
/>
|
||||||
<div className={colorInputPrefixCls}>{steppersRender()}</div>
|
<div className={colorInputPrefixCls}>{steppersNode}</div>
|
||||||
<ColorAlphaInput prefixCls={prefixCls} value={value} onChange={onChange} />
|
<ColorAlphaInput prefixCls={prefixCls} value={value} onChange={onChange} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ColorInput;
|
export default ColorInput;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
import { ColorBlock } from '@rc-component/color-picker';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
||||||
import type { FC } from 'react';
|
import type { FC } from 'react';
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { ColorBlock } from '@rc-component/color-picker';
|
|
||||||
import Collapse from '../../collapse';
|
import Collapse from '../../collapse';
|
||||||
import { useLocale } from '../../locale';
|
import { useLocale } from '../../locale';
|
||||||
import type { Color } from '../color';
|
import type { Color } from '../color';
|
||||||
@ -19,7 +19,7 @@ interface ColorPresetsProps extends Pick<ColorPickerBaseProps, 'prefixCls'> {
|
|||||||
|
|
||||||
const genPresetColor = (list: PresetsItem[]) =>
|
const genPresetColor = (list: PresetsItem[]) =>
|
||||||
list.map((value) => {
|
list.map((value) => {
|
||||||
value.colors = value.colors.map((color) => generateColor(color));
|
value.colors = value.colors.map(generateColor);
|
||||||
return value;
|
return value;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -35,11 +35,11 @@ const ColorPresets: FC<ColorPresetsProps> = ({ prefixCls, presets, value: color,
|
|||||||
const [locale] = useLocale('ColorPicker');
|
const [locale] = useLocale('ColorPicker');
|
||||||
const [presetsValue] = useMergedState(genPresetColor(presets), {
|
const [presetsValue] = useMergedState(genPresetColor(presets), {
|
||||||
value: genPresetColor(presets),
|
value: genPresetColor(presets),
|
||||||
postState: (item) => genPresetColor(item),
|
postState: genPresetColor,
|
||||||
});
|
});
|
||||||
const colorPresetsPrefixCls = `${prefixCls}-presets`;
|
const colorPresetsPrefixCls = `${prefixCls}-presets`;
|
||||||
|
|
||||||
const activeKey = useMemo(
|
const activeKeys = useMemo<string[]>(
|
||||||
() => presetsValue.map((preset) => `panel-${preset.label}`),
|
() => presetsValue.map((preset) => `panel-${preset.label}`),
|
||||||
[presetsValue],
|
[presetsValue],
|
||||||
);
|
);
|
||||||
@ -50,14 +50,14 @@ const ColorPresets: FC<ColorPresetsProps> = ({ prefixCls, presets, value: color,
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={colorPresetsPrefixCls}>
|
<div className={colorPresetsPrefixCls}>
|
||||||
<Collapse defaultActiveKey={activeKey} ghost>
|
<Collapse defaultActiveKey={activeKeys} ghost>
|
||||||
{presetsValue.map((preset) => (
|
{presetsValue.map((preset) => (
|
||||||
<Panel
|
<Panel
|
||||||
header={<div className={`${colorPresetsPrefixCls}-label`}>{preset?.label}</div>}
|
header={<div className={`${colorPresetsPrefixCls}-label`}>{preset?.label}</div>}
|
||||||
key={`panel-${preset?.label}`}
|
key={`panel-${preset?.label}`}
|
||||||
>
|
>
|
||||||
<div className={`${colorPresetsPrefixCls}-items`}>
|
<div className={`${colorPresetsPrefixCls}-items`}>
|
||||||
{Array.isArray(preset?.colors) && preset?.colors.length > 0 ? (
|
{Array.isArray(preset?.colors) && preset.colors?.length > 0 ? (
|
||||||
preset.colors.map((presetColor: Color) => (
|
preset.colors.map((presetColor: Color) => (
|
||||||
<ColorBlock
|
<ColorBlock
|
||||||
key={`preset-${presetColor.toHexString()}`}
|
key={`preset-${presetColor.toHexString()}`}
|
||||||
@ -81,4 +81,5 @@ const ColorPresets: FC<ColorPresetsProps> = ({ prefixCls, presets, value: color,
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ColorPresets;
|
export default ColorPresets;
|
||||||
|
@ -13,7 +13,7 @@ interface ColorRgbInputProps extends Pick<ColorPickerBaseProps, 'prefixCls'> {
|
|||||||
|
|
||||||
const ColorRgbInput: FC<ColorRgbInputProps> = ({ prefixCls, value, onChange }) => {
|
const ColorRgbInput: FC<ColorRgbInputProps> = ({ prefixCls, value, onChange }) => {
|
||||||
const colorRgbInputPrefixCls = `${prefixCls}-rgb-input`;
|
const colorRgbInputPrefixCls = `${prefixCls}-rgb-input`;
|
||||||
const [rgbValue, setRgbValue] = useState(generateColor(value || '#000'));
|
const [rgbValue, setRgbValue] = useState<Color>(generateColor(value || '#000'));
|
||||||
|
|
||||||
// Update step value
|
// Update step value
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
import { ColorBlock } from '@rc-component/color-picker';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import type { CSSProperties, MouseEventHandler } from 'react';
|
import type { CSSProperties, MouseEventHandler } from 'react';
|
||||||
import React, { forwardRef, useMemo } from 'react';
|
import React, { forwardRef, useMemo } from 'react';
|
||||||
import { ColorBlock } from '@rc-component/color-picker';
|
|
||||||
import type { ColorPickerBaseProps } from '../interface';
|
import type { ColorPickerBaseProps } from '../interface';
|
||||||
import ColorClear from './ColorClear';
|
import ColorClear from './ColorClear';
|
||||||
|
|
||||||
@ -20,14 +20,14 @@ const ColorTrigger = forwardRef<HTMLDivElement, colorTriggerProps>((props, ref)
|
|||||||
const { color, prefixCls, open, clearColor, disabled, className, ...rest } = props;
|
const { color, prefixCls, open, clearColor, disabled, className, ...rest } = props;
|
||||||
const colorTriggerPrefixCls = `${prefixCls}-trigger`;
|
const colorTriggerPrefixCls = `${prefixCls}-trigger`;
|
||||||
|
|
||||||
const containerRender = useMemo(
|
const containerNode = useMemo<React.ReactNode>(
|
||||||
() =>
|
() =>
|
||||||
clearColor ? (
|
clearColor ? (
|
||||||
<ColorClear prefixCls={prefixCls} />
|
<ColorClear prefixCls={prefixCls} />
|
||||||
) : (
|
) : (
|
||||||
<ColorBlock color={color.toRgbString()} prefixCls={prefixCls} />
|
<ColorBlock prefixCls={prefixCls} color={color.toRgbString()} />
|
||||||
),
|
),
|
||||||
[color, clearColor],
|
[color, clearColor, prefixCls],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -39,8 +39,9 @@ const ColorTrigger = forwardRef<HTMLDivElement, colorTriggerProps>((props, ref)
|
|||||||
})}
|
})}
|
||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
{containerRender}
|
{containerNode}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default ColorTrigger;
|
export default ColorTrigger;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ColorPicker, theme } from 'antd';
|
import { ColorPicker, theme } from 'antd';
|
||||||
import type { Color } from 'antd/lib/color-picker';
|
import type { Color } from 'antd/es/color-picker';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
import { Col, ColorPicker, Row, Space } from 'antd';
|
import { Col, ColorPicker, Row, Space } from 'antd';
|
||||||
import type { Color } from 'antd/lib/color-picker';
|
import type { Color } from 'antd/es/color-picker';
|
||||||
import React, { useMemo, useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const [colorHex, setColorHex] = useState<Color | string>('#1677ff');
|
const [colorHex, setColorHex] = useState<Color | string>('#1677ff');
|
||||||
const [colorHsb, setColorHsb] = useState<Color | string>('hsb(215,91%,100%)');
|
const [colorHsb, setColorHsb] = useState<Color | string>('hsb(215, 91%, 100%)');
|
||||||
const [colorRgb, setColorRgb] = useState<Color | string>('rgb(22,119,255)');
|
const [colorRgb, setColorRgb] = useState<Color | string>('rgb(22, 119, 255)');
|
||||||
|
|
||||||
const hexString = useMemo(
|
const hexString = useMemo(
|
||||||
() => (typeof colorHex === 'string' ? colorHex : colorHex.toHexString()),
|
() => (typeof colorHex === 'string' ? colorHex : colorHex.toHexString()),
|
||||||
[colorHex],
|
[colorHex],
|
||||||
);
|
);
|
||||||
|
|
||||||
const hsbString = useMemo(
|
const hsbString = useMemo(
|
||||||
() => (typeof colorHsb === 'string' ? colorHsb : colorHsb.toHsbString()),
|
() => (typeof colorHsb === 'string' ? colorHsb : colorHsb.toHsbString()),
|
||||||
[colorHsb],
|
[colorHsb],
|
||||||
);
|
);
|
||||||
|
|
||||||
const rgbString = useMemo(
|
const rgbString = useMemo(
|
||||||
() => (typeof colorRgb === 'string' ? colorRgb : colorRgb.toRgbString()),
|
() => (typeof colorRgb === 'string' ? colorRgb : colorRgb.toRgbString()),
|
||||||
[colorRgb],
|
[colorRgb],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ColorPicker, theme } from 'antd';
|
import { ColorPicker, theme } from 'antd';
|
||||||
import type { Color } from 'antd/lib/color-picker';
|
import type { Color } from 'antd/es/color-picker';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
const PureRenderColorPicker = ColorPicker._InternalPanelDoNotUseOrYouWillBeFired;
|
const PureRenderColorPicker = ColorPicker._InternalPanelDoNotUseOrYouWillBeFired;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { ColorPicker, Space, theme } from 'antd';
|
import { ColorPicker, Space, theme } from 'antd';
|
||||||
import type { Color } from 'antd/lib/color-picker';
|
import type { Color } from 'antd/es/color-picker';
|
||||||
import React, { useMemo, useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const { token } = theme.useToken();
|
const { token } = theme.useToken();
|
||||||
const [color, setColor] = useState<Color | string>(token.colorPrimary);
|
const [color, setColor] = useState<Color | string>(token.colorPrimary);
|
||||||
const genColor = useMemo(
|
|
||||||
|
const bgColor = useMemo<string>(
|
||||||
() => (typeof color === 'string' ? color : color.toHexString()),
|
() => (typeof color === 'string' ? color : color.toHexString()),
|
||||||
[color],
|
[color],
|
||||||
);
|
);
|
||||||
@ -15,13 +16,13 @@ export default () => {
|
|||||||
<Space>
|
<Space>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
width: 20,
|
width: token.sizeMD,
|
||||||
height: 20,
|
height: token.sizeMD,
|
||||||
borderRadius: 4,
|
borderRadius: token.borderRadiusSM,
|
||||||
background: genColor,
|
backgroundColor: bgColor,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span>{genColor}</span>
|
<span>{bgColor}</span>
|
||||||
</Space>
|
</Space>
|
||||||
</ColorPicker>
|
</ColorPicker>
|
||||||
);
|
);
|
||||||
|
@ -2,20 +2,17 @@ import { useEffect, useState } from 'react';
|
|||||||
import type { Color } from '../color';
|
import type { Color } from '../color';
|
||||||
import { generateColor } from '../util';
|
import { generateColor } from '../util';
|
||||||
|
|
||||||
function hasValue(value: Color | string | undefined) {
|
function hasValue(value?: Color | string) {
|
||||||
return value !== undefined;
|
return value !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useColorState = (
|
const useColorState = (
|
||||||
defaultStateValue: Color | string,
|
defaultStateValue: Color | string,
|
||||||
option: {
|
option: { defaultValue?: Color | string; value?: Color | string },
|
||||||
defaultValue?: Color | string;
|
): readonly [Color, React.Dispatch<React.SetStateAction<Color>>] => {
|
||||||
value?: Color | string;
|
|
||||||
},
|
|
||||||
): [Color, React.Dispatch<React.SetStateAction<Color>>] => {
|
|
||||||
const { defaultValue, value } = option;
|
const { defaultValue, value } = option;
|
||||||
const [colorValue, setColorValue] = useState(() => {
|
const [colorValue, setColorValue] = useState<Color>(() => {
|
||||||
let mergeState;
|
let mergeState: string | Color | undefined;
|
||||||
if (hasValue(value)) {
|
if (hasValue(value)) {
|
||||||
mergeState = value;
|
mergeState = value;
|
||||||
} else if (hasValue(defaultValue)) {
|
} else if (hasValue(defaultValue)) {
|
||||||
@ -23,8 +20,7 @@ const useColorState = (
|
|||||||
} else {
|
} else {
|
||||||
mergeState = defaultStateValue;
|
mergeState = defaultStateValue;
|
||||||
}
|
}
|
||||||
const genColor = generateColor(mergeState || '');
|
return generateColor(mergeState || '');
|
||||||
return genColor;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -33,7 +29,7 @@ const useColorState = (
|
|||||||
}
|
}
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
return [colorValue, setColorValue];
|
return [colorValue, setColorValue] as const;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useColorState;
|
export default useColorState;
|
||||||
|
@ -10,11 +10,11 @@ group:
|
|||||||
title: Data Entry
|
title: Data Entry
|
||||||
---
|
---
|
||||||
|
|
||||||
Components providing color selection
|
Components providing color selection, Available since `5.5.0`.
|
||||||
|
|
||||||
## When To Use
|
## When To Use
|
||||||
|
|
||||||
Used when the user needs to customize the color selection
|
Used when the user needs to customize the color selection.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ Used when the user needs to customize the color selection
|
|||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
> This component is available since antd@5.5.0
|
> This component is available since `antd@5.5.0`.
|
||||||
|
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
| Property | Description | Type | Default |
|
| Property | Description | Type | Default |
|
||||||
@ -41,7 +41,7 @@ Used when the user needs to customize the color selection
|
|||||||
| onChange | Callback when `value` is changed | `(value: Color, hex: string) => void` | - |
|
| onChange | Callback when `value` is changed | `(value: Color, hex: string) => void` | - |
|
||||||
| allowClear | Allow clearing color selected | boolean | false |
|
| allowClear | Allow clearing color selected | boolean | false |
|
||||||
| presets | Preset colors | `{ label: ReactNode, colors: Array<string \| Color> }[]` | - |
|
| presets | Preset colors | `{ label: ReactNode, colors: Array<string \| Color> }[]` | - |
|
||||||
| children | Trigger of ColorPicker | ReactElement | - |
|
| children | Trigger of ColorPicker | React.ReactNode | - |
|
||||||
| trigger | ColorPicker trigger mode | `hover` \| `click` | `click` |
|
| trigger | ColorPicker trigger mode | `hover` \| `click` | `click` |
|
||||||
| open | Whether to show popup | boolean | - |
|
| open | Whether to show popup | boolean | - |
|
||||||
| onOpenChange | Callback when `open` is changed | `(open: boolean) => void` | - |
|
| onOpenChange | Callback when `open` is changed | `(open: boolean) => void` | - |
|
||||||
|
@ -11,7 +11,7 @@ group:
|
|||||||
title: 数据录入
|
title: 数据录入
|
||||||
---
|
---
|
||||||
|
|
||||||
提供颜色选取的组件
|
提供颜色选取的组件,自 `5.5.0` 版本开始提供该组件。
|
||||||
|
|
||||||
## 何时使用
|
## 何时使用
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ group:
|
|||||||
| onChange | 颜色变化的回调 | `(value: Color, hex: string) => void` | - |
|
| onChange | 颜色变化的回调 | `(value: Color, hex: string) => void` | - |
|
||||||
| allowClear | 允许清除选择的颜色 | boolean | false |
|
| allowClear | 允许清除选择的颜色 | boolean | false |
|
||||||
| presets | 预设的颜色 | `{ label: ReactNode, colors: Array<string \| Color> }[]` | - |
|
| presets | 预设的颜色 | `{ label: ReactNode, colors: Array<string \| Color> }[]` | - |
|
||||||
| children | 颜色选择器的触发器 | ReactElement | - |
|
| children | 颜色选择器的触发器 | React.ReactNode | - |
|
||||||
| trigger | 颜色选择器的触发模式 | `hover` \| `click` | `click` |
|
| trigger | 颜色选择器的触发模式 | `hover` \| `click` | `click` |
|
||||||
| open | 是否显示弹出窗口 | boolean | - |
|
| open | 是否显示弹出窗口 | boolean | - |
|
||||||
| onOpenChange | 当 `open` 被改变时的回调 | `(open: boolean) => void` | - |
|
| onOpenChange | 当 `open` 被改变时的回调 | `(open: boolean) => void` | - |
|
||||||
|
@ -8,7 +8,10 @@ export enum ColorFormat {
|
|||||||
hsb = 'hsb',
|
hsb = 'hsb',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PresetsItem = { label: ReactNode; colors: Array<string | Color> };
|
export interface PresetsItem {
|
||||||
|
label: ReactNode;
|
||||||
|
colors: (string | Color)[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface ColorPickerBaseProps {
|
export interface ColorPickerBaseProps {
|
||||||
color?: Color;
|
color?: Color;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import type { CSSObject } from '@ant-design/cssinjs';
|
import type { CSSObject } from '@ant-design/cssinjs';
|
||||||
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
||||||
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
||||||
import genPickerStyle from './picker';
|
|
||||||
import genInputStyle from './input';
|
|
||||||
import genPresetsStyle from './presets';
|
|
||||||
import genColorBlockStyle from './color-block';
|
import genColorBlockStyle from './color-block';
|
||||||
|
import genInputStyle from './input';
|
||||||
|
import genPickerStyle from './picker';
|
||||||
|
import genPresetsStyle from './presets';
|
||||||
|
|
||||||
export interface ComponentToken {}
|
export interface ComponentToken {}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ export default genComponentStyleHook('ColorPicker', (token) => {
|
|||||||
|
|
||||||
const colorPickerSliderHeight = 8;
|
const colorPickerSliderHeight = 8;
|
||||||
|
|
||||||
const ColorPickerToken = mergeToken<ColorPickerToken>(token, {
|
const colorPickerToken = mergeToken<ColorPickerToken>(token, {
|
||||||
colorPickerWidth: 234,
|
colorPickerWidth: 234,
|
||||||
colorPickerHandlerSize: 16,
|
colorPickerHandlerSize: 16,
|
||||||
colorPickerHandlerSizeSM: 12,
|
colorPickerHandlerSizeSM: 12,
|
||||||
@ -149,5 +149,5 @@ export default genComponentStyleHook('ColorPicker', (token) => {
|
|||||||
colorPickerPreviewSize: colorPickerSliderHeight * 2 + marginSM,
|
colorPickerPreviewSize: colorPickerSliderHeight * 2 + marginSM,
|
||||||
});
|
});
|
||||||
|
|
||||||
return [genColorPickerStyle(ColorPickerToken)];
|
return [genColorPickerStyle(colorPickerToken)];
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import type { CSSObject } from '@ant-design/cssinjs';
|
import type { CSSObject } from '@ant-design/cssinjs';
|
||||||
import type { GenerateStyle } from '../../theme/internal';
|
import type { GenerateStyle } from '../../theme/internal';
|
||||||
import type { ColorPickerToken } from './index';
|
|
||||||
import genColorBlockStyle from './color-block';
|
import genColorBlockStyle from './color-block';
|
||||||
|
import type { ColorPickerToken } from './index';
|
||||||
|
|
||||||
const genPickerStyle: GenerateStyle<ColorPickerToken, CSSObject> = (token) => {
|
const genPickerStyle: GenerateStyle<ColorPickerToken, CSSObject> = (token) => {
|
||||||
const {
|
const {
|
||||||
@ -41,6 +41,7 @@ const genPickerStyle: GenerateStyle<ColorPickerToken, CSSObject> = (token) => {
|
|||||||
border: `${lineWidthBold}px solid ${colorBgElevated}`,
|
border: `${lineWidthBold}px solid ${colorBgElevated}`,
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
borderRadius: '50%',
|
borderRadius: '50%',
|
||||||
|
cursor: 'pointer',
|
||||||
boxShadow: `${colorPickerInsetShadow}, 0 0 0 1px ${colorFillSecondary}`,
|
boxShadow: `${colorPickerInsetShadow}, 0 0 0 1px ${colorFillSecondary}`,
|
||||||
'&-sm': {
|
'&-sm': {
|
||||||
width: colorPickerHandlerSizeSM,
|
width: colorPickerHandlerSizeSM,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import type { CSSObject } from '@ant-design/cssinjs';
|
import type { CSSObject } from '@ant-design/cssinjs';
|
||||||
|
import { resetComponent } from '../../style';
|
||||||
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
||||||
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
||||||
import { resetComponent } from '../../style';
|
|
||||||
|
|
||||||
/** Component only token. Which will handle additional calculation of alias token */
|
/** Component only token. Which will handle additional calculation of alias token */
|
||||||
export interface ComponentToken {
|
export interface ComponentToken {
|
||||||
@ -105,7 +105,7 @@ const genSharedDividerStyle: GenerateStyle<DividerToken> = (token): CSSObject =>
|
|||||||
},
|
},
|
||||||
|
|
||||||
[`&-vertical${componentCls}-dashed`]: {
|
[`&-vertical${componentCls}-dashed`]: {
|
||||||
borderInlineStart: lineWidth,
|
borderInlineStartWidth: lineWidth,
|
||||||
borderInlineEnd: 0,
|
borderInlineEnd: 0,
|
||||||
borderBlockStart: 0,
|
borderBlockStart: 0,
|
||||||
borderBlockEnd: 0,
|
borderBlockEnd: 0,
|
||||||
|
@ -28,12 +28,10 @@ const Circle: React.FC<CircleProps> = (props) => {
|
|||||||
type,
|
type,
|
||||||
children,
|
children,
|
||||||
success,
|
success,
|
||||||
size,
|
size = originWidth,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const mergedSize = size ?? [originWidth, originWidth];
|
const [width, height] = getSize(size, 'circle');
|
||||||
|
|
||||||
const [width, height] = getSize(mergedSize, 'circle');
|
|
||||||
|
|
||||||
let { strokeWidth } = props;
|
let { strokeWidth } = props;
|
||||||
if (strokeWidth === undefined) {
|
if (strokeWidth === undefined) {
|
||||||
|
@ -264,6 +264,13 @@ describe('Progress', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not warning if not pass the `size` prop in type Circle', () => {
|
||||||
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
errorSpy.mockClear();
|
||||||
|
render(<Progress type="circle" />);
|
||||||
|
expect(errorSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should warnning if pass number[] into `size` in type dashboard', () => {
|
it('should warnning if pass number[] into `size` in type dashboard', () => {
|
||||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
render(<Progress size={[60, 20]} type="dashboard" />);
|
render(<Progress size={[60, 20]} type="dashboard" />);
|
||||||
|
Loading…
Reference in New Issue
Block a user