diff --git a/src/_common b/src/_common index c31a009819..c06bc0962f 160000 --- a/src/_common +++ b/src/_common @@ -1 +1 @@ -Subproject commit c31a0098192ca4cd14185ab0baf0d03559beb6eb +Subproject commit c06bc0962fc97eba87be69bfea8c42a8bb97a4a3 diff --git a/src/color-picker/_example/color-mode.jsx b/src/color-picker/_example/color-mode.jsx index d840c5ecad..85fd20b116 100644 --- a/src/color-picker/_example/color-mode.jsx +++ b/src/color-picker/_example/color-mode.jsx @@ -2,7 +2,7 @@ import React from 'react'; import { ColorPicker, Space } from 'tdesign-react'; export default function ColorMode() { - const color1 = '#0052d9'; + const color1 = 'rgba(0, 82, 217, 1)'; const color2 = '#0052d9'; const color3 = 'linear-gradient(45deg, #4facfe 0%, #00f2fe 100%)'; @@ -14,7 +14,7 @@ export default function ColorMode() {
仅单色模式
- +
diff --git a/src/color-picker/_example/enable-alpha.jsx b/src/color-picker/_example/enable-alpha.jsx index f85f3a8f57..92496e1bef 100644 --- a/src/color-picker/_example/enable-alpha.jsx +++ b/src/color-picker/_example/enable-alpha.jsx @@ -2,11 +2,11 @@ import React, { useState } from 'react'; import { ColorPickerPanel } from 'tdesign-react'; export default function EnableAlpha() { - const [value, setValue] = useState('#0052d9'); + const [value, setValue] = useState('#0052D9CC'); const handleChange = (value) => { setValue(value); }; - return ; + return ; } diff --git a/src/color-picker/_example/trigger.jsx b/src/color-picker/_example/trigger.jsx index c727c4980d..27bd19049c 100644 --- a/src/color-picker/_example/trigger.jsx +++ b/src/color-picker/_example/trigger.jsx @@ -2,5 +2,5 @@ import React from 'react'; import { ColorPicker } from 'tdesign-react'; export default function PanelExample() { - return ; + return ; } diff --git a/src/color-picker/components/panel/format/index.tsx b/src/color-picker/components/panel/format/index.tsx index 21bf52e25d..4c5eb51547 100644 --- a/src/color-picker/components/panel/format/index.tsx +++ b/src/color-picker/components/panel/format/index.tsx @@ -16,7 +16,6 @@ export interface TdColorFormatProps extends TdColorPickerProps { const FormatPanel = (props: TdColorFormatProps) => { const { baseClassName, format, onModeChange, selectInputProps } = props; const [formatMode, setFormatMode] = useState(format); - const handleModeChange = (v: TdColorPickerProps['format']) => { setFormatMode(v); onModeChange(v); diff --git a/src/color-picker/components/panel/index.tsx b/src/color-picker/components/panel/index.tsx index 713959f7ef..ec2ef68f6d 100644 --- a/src/color-picker/components/panel/index.tsx +++ b/src/color-picker/components/panel/index.tsx @@ -44,17 +44,25 @@ const Panel = forwardRef((props, ref) => { closeBtn, colorModes = ['linear-gradient', 'monochrome'], showPrimaryColorPreview = true, + onRecentColorsChange, } = props; const [innerValue, setInnerValue] = useControlled(props, 'value', onChange); const [mode, setMode] = useState(colorModes?.length === 1 ? colorModes[0] : 'monochrome'); - const isGradient = mode === 'linear-gradient'; // 判断是否为gradient模式 + const [updateId, setUpdateId] = useState(0); + const isGradient = mode === 'linear-gradient'; // 判断是否为 linear-gradient 模式 const defaultEmptyColor = isGradient ? DEFAULT_LINEAR_GRADIENT : DEFAULT_COLOR; + + const [recentlyUsedColors, setRecentlyUsedColors] = useControlled(props, 'recentColors', onRecentColorsChange, { + defaultRecentColors: colorPickerDefaultProps.recentColors, + }); + const colorInstanceRef = useRef(new Color(innerValue || defaultEmptyColor)); - const getmodeByColor = colorInstanceRef.current.isGradient ? 'linear-gradient' : 'monochrome'; - const [updateId, setUpdateId] = useState(0); + const getModeByColor = colorInstanceRef.current.isGradient ? 'linear-gradient' : 'monochrome'; + const formatRef = useRef(colorInstanceRef.current.isGradient ? 'CSS' : format ?? 'RGB'); + const update = useCallback( - (value) => { + (value: string) => { colorInstanceRef.current.update(value); setUpdateId(updateId + 1); }, @@ -66,9 +74,9 @@ const Panel = forwardRef((props, ref) => { if (mode === 'linear-gradient') { return colorInstanceRef.current.linearGradient; } - - return colorInstanceRef.current.getFormatsColorMap()[format] || colorInstanceRef.current.css; - }, [format, mode]); + const finalFormat = format === 'HEX' && enableAlpha ? 'HEX8' : format; // hex should transfer to hex8 when alpha channel is opened + return colorInstanceRef.current.getFormatsColorMap()[finalFormat] || colorInstanceRef.current.css; + }, [format, enableAlpha, mode]); const emitColorChange = useCallback( (trigger?: ColorPickerChangeTrigger) => { @@ -84,7 +92,6 @@ const Panel = forwardRef((props, ref) => { if (typeof value === 'undefined' || mode === 'linear-gradient') { return; } - // common Color new 的时候使用 hsv ,一个 rgba 可以对应两个 hsv ,这里先直接用 tinycolor 比较下颜色是否修改了 const newUniqColor = tinyColor(value).toRgb(); const { r, g, b, a } = newUniqColor; @@ -106,16 +113,9 @@ const Panel = forwardRef((props, ref) => { if (colorModes.length === 1) { setMode(colorModes[0]); } else { - setMode(getmodeByColor); + setMode(getModeByColor); } - }, [colorModes, getmodeByColor]); - - const formatRef = useRef(colorInstanceRef.current.isGradient ? 'CSS' : 'RGB'); - - const { onRecentColorsChange } = props; - const [recentlyUsedColors, setRecentlyUsedColors] = useControlled(props, 'recentColors', onRecentColorsChange, { - defaultRecentColors: colorPickerDefaultProps.recentColors, - }); + }, [colorModes, getModeByColor]); const baseProps = { color: colorInstanceRef.current, @@ -259,7 +259,7 @@ const Panel = forwardRef((props, ref) => { color.update(value); color.updateCurrentGradientColor(); } else { - console.warn('该模式不支持渐变色'); + console.warn('linear-gradient is not supported in this mode'); } } else if (mode === 'linear-gradient') { setMode('monochrome'); diff --git a/test/snap/__snapshots__/csr.test.jsx.snap b/test/snap/__snapshots__/csr.test.jsx.snap index a175385e6f..4dd31892ec 100644 --- a/test/snap/__snapshots__/csr.test.jsx.snap +++ b/test/snap/__snapshots__/csr.test.jsx.snap @@ -51308,7 +51308,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/color-mode.jsx 1 >
csr test src/color-picker/_example/color-mode.jsx 1 class="t-input__inner" placeholder="请输入" type="text" - value="#0052d9" + value="rgba(0, 82, 217, 1)" /> - #0052d9 + rgba(0, 82, 217, 1)
@@ -51475,7 +51475,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/color-mode.jsx 1 >
csr test src/color-picker/_example/color-mode.jsx 1 class="t-input__inner" placeholder="请输入" type="text" - value="#0052d9" + value="rgba(0, 82, 217, 1)" /> - #0052d9 + rgba(0, 82, 217, 1)
@@ -51794,7 +51794,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/enable-alpha.jsx
@@ -51805,7 +51805,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/enable-alpha.jsx > @@ -51823,7 +51823,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/enable-alpha.jsx >
csr test src/color-picker/_example/enable-alpha.jsx placeholder="请选择" readonly="" type="text" - value="RGB" + value="HEX" /> - RGB + HEX csr test src/color-picker/_example/enable-alpha.jsx >
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
-
-
- -
+
@@ -51957,7 +51903,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/enable-alpha.jsx >
csr test src/color-picker/_example/enable-alpha.jsx class="t-input__inner" placeholder="请输入" type="text" - value="100%" + value="80%" />
@@ -52627,7 +52573,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/enable-alpha.jsx
@@ -52638,7 +52584,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/enable-alpha.jsx >
@@ -52656,7 +52602,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/enable-alpha.jsx >
csr test src/color-picker/_example/enable-alpha.jsx placeholder="请选择" readonly="" type="text" - value="RGB" + value="HEX" /> - RGB + HEX csr test src/color-picker/_example/enable-alpha.jsx >
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
+
@@ -52790,7 +52682,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/enable-alpha.jsx >
csr test src/color-picker/_example/enable-alpha.jsx class="t-input__inner" placeholder="请输入" type="text" - value="100%" + value="80%" />
@@ -53530,7 +53422,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/panel.jsx 1`] = >
csr test src/color-picker/_example/panel.jsx 1`] = placeholder="请选择" readonly="" type="text" - value="RGB" + value="HEX" /> - RGB + HEX csr test src/color-picker/_example/panel.jsx 1`] = >
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
-
-
- -
+
@@ -54318,7 +54156,7 @@ exports[`csr snapshot test > csr test src/color-picker/_example/panel.jsx 1`] = >
csr test src/color-picker/_example/panel.jsx 1`] = placeholder="请选择" readonly="" type="text" - value="RGB" + value="HEX" /> - RGB + HEX csr test src/color-picker/_example/panel.jsx 1`] = >
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
+
diff --git a/test/snap/__snapshots__/ssr.test.jsx.snap b/test/snap/__snapshots__/ssr.test.jsx.snap index 0a29b1ad32..f0d2871094 100644 --- a/test/snap/__snapshots__/ssr.test.jsx.snap +++ b/test/snap/__snapshots__/ssr.test.jsx.snap @@ -228,11 +228,11 @@ exports[`ssr snapshot test > ssr test src/collapse/_example/other.jsx 1`] = `" ssr test src/collapse/_example/rightSlot.jsx 1`] = `"
这是一个折叠标题
这部分是每个折叠面板折叠或展开的内容,可根据不同业务或用户的使用诉求,进行自定义填充。可以是纯文本、图文、子列表等内容形式。
这是一个折叠标题
这部分是每个折叠面板折叠或展开的内容,可根据不同业务或用户的使用诉求,进行自定义填充。可以是纯文本、图文、子列表等内容形式。
这是一个折叠标题
这部分是每个折叠面板折叠或展开的内容,可根据不同业务或用户的使用诉求,进行自定义填充。可以是纯文本、图文、子列表等内容形式。
"`; -exports[`ssr snapshot test > ssr test src/color-picker/_example/color-mode.jsx 1`] = `"
默认(单色 + 线性渐变)
#0052d9
仅单色模式
#0052d9
仅线性渐变模式
linear-gradient(45deg, #4facfe 0%, #00f2fe 100%)
"`; +exports[`ssr snapshot test > ssr test src/color-picker/_example/color-mode.jsx 1`] = `"
默认(单色 + 线性渐变)
rgba(0, 82, 217, 1)
仅单色模式
#0052d9
仅线性渐变模式
linear-gradient(45deg, #4facfe 0%, #00f2fe 100%)
"`; -exports[`ssr snapshot test > ssr test src/color-picker/_example/enable-alpha.jsx 1`] = `"
请选择

最近使用颜色

    系统预设颜色

    "`; +exports[`ssr snapshot test > ssr test src/color-picker/_example/enable-alpha.jsx 1`] = `"
    请选择

    最近使用颜色

      系统预设颜色

      "`; -exports[`ssr snapshot test > ssr test src/color-picker/_example/panel.jsx 1`] = `"
      请选择

      最近使用颜色

        系统预设颜色

        "`; +exports[`ssr snapshot test > ssr test src/color-picker/_example/panel.jsx 1`] = `"
        请选择

        最近使用颜色

          系统预设颜色

          "`; exports[`ssr snapshot test > ssr test src/color-picker/_example/recent-color.jsx 1`] = `"
          预设最近使用色
          请选择

          最近使用颜色

          系统预设颜色

          完全不显示最近使用色
          请选择

          系统预设颜色

          "`;