diff --git a/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/CustomRange/index.tsx b/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/CustomRange/index.tsx index 31986e94..a0876bef 100644 --- a/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/CustomRange/index.tsx +++ b/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/CustomRange/index.tsx @@ -21,7 +21,7 @@ type RangeItemType = { }; const CustomRange = (props: CustomRangeProps) => { - const { ranges: defaultRanges, onChange, onCancel, className } = props; + const { ranges: defaultRanges, onChange, className } = props; const prefixCls = usePrefixCls('formily-color-range-selector__custom-range'); const [wrapSSR, hashId] = useStyle(prefixCls); const [ranges, setRanges] = useState([]); @@ -69,7 +69,6 @@ const CustomRange = (props: CustomRangeProps) => { const onSubmit = () => { const list = ranges.map((item) => item.value); onChange(list); - onCancel(); }; return wrapSSR( @@ -109,8 +108,7 @@ const CustomRange = (props: CustomRangeProps) => {
- 取消 - 确定 + 应用
, ); diff --git a/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/DropDownContent.tsx b/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/DropDownContent.tsx index 468e5c4a..376f9a8a 100644 --- a/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/DropDownContent.tsx +++ b/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/DropDownContent.tsx @@ -30,16 +30,23 @@ export interface DropDownContentProps { const DropDownContent = (props: DropDownContentProps) => { const { isOpen, colorRanges, selectedValue } = props; + // 在当前色带中查找,判断是否自定义色带,如果不是自定义色带查找出 colorRanges 中对应 item 确定 type + const selectedColor = colorRanges.find((item) => { + const _colors = selectedValue.isReversed ? selectedValue.colors.slice().reverse() : selectedValue.colors; + return item.colors.toString() === _colors.toString(); + }); + const [paletteConfig, setPaletteConfig] = useState<{ type: string; steps: number; }>({ - type: 'all', + type: selectedColor?.type ?? 'all', steps: selectedValue.colors.length || 6, }); + const isCustomPalette = selectedColor === undefined; // 自定义调色板是否开启 - const [customPaletteOpen, setCustomPaletteOpen] = useState(false); + const [customPaletteOpen, setCustomPaletteOpen] = useState(isCustomPalette); // 颜色列表 const colorRangeList = useMemo(() => { diff --git a/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/index.tsx b/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/index.tsx index f06a656d..7b529436 100644 --- a/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/index.tsx +++ b/packages/li-p2/src/components/Formily/ColorRangeSelector/Internal/index.tsx @@ -42,6 +42,12 @@ const Internal = (props: ColorRangeSelectorProps) => { const [open, setOpen] = useState(false); + const onColorChange = (selectorValue: SelectorValue) => { + if (props.onChange) { + props.onChange(selectorValue); + } + }; + return wrapSSR(