mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 05:28:20 +08:00
832cffcdf9
* refactor: support type update * chore: update clear style * chore: bump color picker * chore: use slider * chore: bump color picker * chore: range slider * chore: layout * chore: useModeColor * chore: simplify * chore: bump color picker * refactor: event * chore: tmp lock check * chore: of it * chore: update ts def * chore: update ts def * chore: remove useless ts * chore: linear * chore: adjust style * chore: rm useless code * chore: fill color * chore: basic linear * chore: support toStr * chore: limit minCount * chore: use cache * chore: drag support: * chore: yes * chore: update demo * chore: useLayoutEffect instead * chore: fix click to add point * chore: add smmoth * chore: support of locale * chore: add locale * chore: fix lint * chore: adjust style * chore: fix lint * chore: fix style * test: fix test case * chore: fix popover * test: fix test case * chore: fix test * test: clean up * chore: fix lint * chore: fix lint * chore: fix lint * test: coverage * test: coverage * test: coverage * test: coverage * test: coverage * test: coverage * chore: fix docs * docs: update demo desc * chore: enhance hover range * fix: delete not working * chore: fix lint * test: coverage * test: coverage * chore: clean up * chore: adjust * chore: highlight * chore: adjust style * chore: fix lint * chore: update demo * chore: memo perf * refactor: up to down colors * test: update snapshot
123 lines
2.8 KiB
TypeScript
123 lines
2.8 KiB
TypeScript
import type { FC } from 'react';
|
|
import React from 'react';
|
|
|
|
import Divider from '../divider';
|
|
import PanelPicker from './components/PanelPicker';
|
|
import PanelPresets from './components/PanelPresets';
|
|
import { PanelPickerContext, PanelPresetsContext } from './context';
|
|
import type { PanelPickerContextProps, PanelPresetsContextProps } from './context';
|
|
import type { ColorPickerProps } from './interface';
|
|
|
|
export interface ColorPickerPanelProps
|
|
extends PanelPickerContextProps,
|
|
Omit<PanelPresetsContextProps, 'onChange'> {
|
|
onClear?: () => void;
|
|
panelRender?: ColorPickerProps['panelRender'];
|
|
}
|
|
|
|
const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
|
const {
|
|
prefixCls,
|
|
presets,
|
|
panelRender,
|
|
value,
|
|
onChange,
|
|
onClear,
|
|
allowClear,
|
|
disabledAlpha,
|
|
mode,
|
|
onModeChange,
|
|
modeOptions,
|
|
onChangeComplete,
|
|
activeIndex,
|
|
onActive,
|
|
format,
|
|
onFormatChange,
|
|
gradientDragging,
|
|
onGradientDragging,
|
|
} = props;
|
|
const colorPickerPanelPrefixCls = `${prefixCls}-inner`;
|
|
|
|
// ===================== Context ======================
|
|
const panelContext: PanelPickerContextProps = React.useMemo(
|
|
() => ({
|
|
prefixCls,
|
|
value,
|
|
onChange,
|
|
onClear,
|
|
allowClear,
|
|
disabledAlpha,
|
|
mode,
|
|
onModeChange,
|
|
modeOptions,
|
|
onChangeComplete,
|
|
activeIndex,
|
|
onActive,
|
|
format,
|
|
onFormatChange,
|
|
gradientDragging,
|
|
onGradientDragging,
|
|
}),
|
|
[
|
|
prefixCls,
|
|
value,
|
|
onChange,
|
|
onClear,
|
|
allowClear,
|
|
disabledAlpha,
|
|
mode,
|
|
onModeChange,
|
|
modeOptions,
|
|
onChangeComplete,
|
|
activeIndex,
|
|
onActive,
|
|
format,
|
|
onFormatChange,
|
|
gradientDragging,
|
|
onGradientDragging,
|
|
],
|
|
);
|
|
|
|
const presetContext: PanelPresetsContextProps = React.useMemo(
|
|
() => ({
|
|
prefixCls,
|
|
value,
|
|
presets,
|
|
onChange,
|
|
}),
|
|
[prefixCls, value, presets, onChange],
|
|
);
|
|
|
|
// ====================== Render ======================
|
|
const innerPanel = (
|
|
<div className={`${colorPickerPanelPrefixCls}-content`}>
|
|
<PanelPicker />
|
|
{Array.isArray(presets) && <Divider />}
|
|
<PanelPresets />
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<PanelPickerContext.Provider value={panelContext}>
|
|
<PanelPresetsContext.Provider value={presetContext}>
|
|
<div className={colorPickerPanelPrefixCls}>
|
|
{typeof panelRender === 'function'
|
|
? panelRender(innerPanel, {
|
|
components: {
|
|
Picker: PanelPicker,
|
|
Presets: PanelPresets,
|
|
},
|
|
})
|
|
: innerPanel}
|
|
</div>
|
|
</PanelPresetsContext.Provider>
|
|
</PanelPickerContext.Provider>
|
|
);
|
|
};
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
ColorPickerPanel.displayName = 'ColorPickerPanel';
|
|
}
|
|
|
|
export default ColorPickerPanel;
|