2024-03-25 20:10:47 +08:00
|
|
|
import type { CSSProperties, FC, ReactNode } from 'react';
|
2023-05-12 14:43:48 +08:00
|
|
|
import type { Color } from './color';
|
2024-03-25 20:10:47 +08:00
|
|
|
import type { ColorPickerProps as RcColorPickerProps } from '@rc-component/color-picker';
|
|
|
|
import type { SizeType } from '../config-provider/SizeContext';
|
|
|
|
import type { PopoverProps } from '../popover';
|
2023-05-12 14:43:48 +08:00
|
|
|
|
|
|
|
export enum ColorFormat {
|
|
|
|
hex = 'hex',
|
|
|
|
rgb = 'rgb',
|
|
|
|
hsb = 'hsb',
|
|
|
|
}
|
|
|
|
|
2023-05-13 23:05:26 +08:00
|
|
|
export interface PresetsItem {
|
|
|
|
label: ReactNode;
|
|
|
|
colors: (string | Color)[];
|
2023-11-03 11:47:52 +08:00
|
|
|
/**
|
|
|
|
* Whether the initial state is collapsed
|
|
|
|
* @since 5.11.0
|
2023-11-03 16:49:22 +08:00
|
|
|
* @default true
|
2023-11-03 11:47:52 +08:00
|
|
|
*/
|
2023-11-03 16:49:22 +08:00
|
|
|
defaultOpen?: boolean;
|
2023-05-13 23:05:26 +08:00
|
|
|
}
|
2023-05-18 13:34:06 +08:00
|
|
|
export type TriggerType = 'click' | 'hover';
|
2023-05-12 14:43:48 +08:00
|
|
|
|
2023-05-18 13:34:06 +08:00
|
|
|
export type TriggerPlacement =
|
|
|
|
| 'top'
|
|
|
|
| 'topLeft'
|
|
|
|
| 'topRight'
|
|
|
|
| 'bottom'
|
|
|
|
| 'bottomLeft'
|
|
|
|
| 'bottomRight';
|
2023-05-12 14:43:48 +08:00
|
|
|
export interface ColorPickerBaseProps {
|
|
|
|
color?: Color;
|
|
|
|
prefixCls: string;
|
|
|
|
format?: keyof typeof ColorFormat;
|
|
|
|
allowClear?: boolean;
|
|
|
|
disabled?: boolean;
|
2023-07-12 19:42:33 +08:00
|
|
|
disabledAlpha?: boolean;
|
2023-05-12 14:43:48 +08:00
|
|
|
presets?: PresetsItem[];
|
2023-06-29 11:46:11 +08:00
|
|
|
panelRender?: ColorPickerProps['panelRender'];
|
2023-05-12 14:43:48 +08:00
|
|
|
onFormatChange?: ColorPickerProps['onFormatChange'];
|
2023-07-10 13:37:43 +08:00
|
|
|
onChangeComplete?: ColorPickerProps['onChangeComplete'];
|
2023-05-12 14:43:48 +08:00
|
|
|
}
|
2023-07-12 10:15:04 +08:00
|
|
|
|
|
|
|
export type ColorValueType = Color | string | null;
|
2024-03-25 20:10:47 +08:00
|
|
|
|
|
|
|
export type ColorPickerProps = Omit<
|
|
|
|
RcColorPickerProps,
|
|
|
|
'onChange' | 'value' | 'defaultValue' | 'panelRender' | 'disabledAlpha' | 'onChangeComplete'
|
|
|
|
> & {
|
|
|
|
value?: ColorValueType;
|
|
|
|
defaultValue?: ColorValueType;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
open?: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
placement?: TriggerPlacement;
|
|
|
|
trigger?: TriggerType;
|
|
|
|
format?: keyof typeof ColorFormat;
|
|
|
|
defaultFormat?: keyof typeof ColorFormat;
|
|
|
|
allowClear?: boolean;
|
|
|
|
presets?: PresetsItem[];
|
|
|
|
arrow?: boolean | { pointAtCenter: boolean };
|
|
|
|
panelRender?: (
|
|
|
|
panel: React.ReactNode,
|
|
|
|
extra: { components: { Picker: FC; Presets: FC } },
|
|
|
|
) => React.ReactNode;
|
|
|
|
showText?: boolean | ((color: Color) => React.ReactNode);
|
|
|
|
size?: SizeType;
|
|
|
|
styles?: { popup?: CSSProperties; popupOverlayInner?: CSSProperties };
|
|
|
|
rootClassName?: string;
|
|
|
|
disabledAlpha?: boolean;
|
|
|
|
[key: `data-${string}`]: string;
|
|
|
|
onOpenChange?: (open: boolean) => void;
|
|
|
|
onFormatChange?: (format: ColorFormat) => void;
|
|
|
|
onChange?: (value: Color, hex: string) => void;
|
|
|
|
onClear?: () => void;
|
|
|
|
onChangeComplete?: (value: Color) => void;
|
|
|
|
} & Pick<PopoverProps, 'getPopupContainer' | 'autoAdjustOverflow' | 'destroyTooltipOnHide'>;
|