Browse Source

refactor: optimize ColorPicker code again (#42334)

pull/42340/head
lijianan 2 years ago
committed by GitHub
parent
commit
0470646a5f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/color-picker/__tests__/__snapshots__/demo-extend.test.ts.snap
  2. 2
      components/color-picker/__tests__/__snapshots__/demo.test.ts.snap
  3. 2
      components/color-picker/demo/base.tsx
  4. 4
      components/color-picker/demo/format.tsx
  5. 2
      components/color-picker/demo/pure-panel.tsx
  6. 15
      components/color-picker/demo/trigger.tsx
  7. 6
      components/color-picker/index.en-US.md
  8. 2
      components/color-picker/index.zh-CN.md
  9. 8
      components/color-picker/style/index.ts
  10. 3
      components/color-picker/style/picker.ts

2
components/color-picker/__tests__/__snapshots__/demo-extend.test.ts.snap

@ -3973,7 +3973,7 @@ Array [
style="margin-right: 8px;"
>
<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

2
components/color-picker/__tests__/__snapshots__/demo.test.ts.snap

@ -234,7 +234,7 @@ exports[`renders components/color-picker/demo/trigger.tsx correctly 1`] = `
style="margin-right:8px"
>
<div
style="width:20px;height:20px;border-radius:4px;background:#1677ff"
style="width:20px;height:20px;border-radius:4px;background-color:#1677ff"
/>
</div>
<div

2
components/color-picker/demo/base.tsx

@ -1,5 +1,5 @@
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';
export default () => {

4
components/color-picker/demo/format.tsx

@ -1,5 +1,5 @@
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';
export default () => {
@ -11,10 +11,12 @@ export default () => {
() => (typeof colorHex === 'string' ? colorHex : colorHex.toHexString()),
[colorHex],
);
const hsbString = useMemo(
() => (typeof colorHsb === 'string' ? colorHsb : colorHsb.toHsbString()),
[colorHsb],
);
const rgbString = useMemo(
() => (typeof colorRgb === 'string' ? colorRgb : colorRgb.toRgbString()),
[colorRgb],

2
components/color-picker/demo/pure-panel.tsx

@ -1,5 +1,5 @@
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';
const PureRenderColorPicker = ColorPicker._InternalPanelDoNotUseOrYouWillBeFired;

15
components/color-picker/demo/trigger.tsx

@ -1,11 +1,12 @@
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';
export default () => {
const { token } = theme.useToken();
const [color, setColor] = useState<Color | string>(token.colorPrimary);
const genColor = useMemo(
const bgColor = useMemo<string>(
() => (typeof color === 'string' ? color : color.toHexString()),
[color],
);
@ -15,13 +16,13 @@ export default () => {
<Space>
<div
style={{
width: 20,
height: 20,
borderRadius: 4,
background: genColor,
width: token.sizeMD,
height: token.sizeMD,
borderRadius: token.borderRadiusSM,
backgroundColor: bgColor,
}}
/>
<span>{genColor}</span>
<span>{bgColor}</span>
</Space>
</ColorPicker>
);

6
components/color-picker/index.en-US.md

@ -10,11 +10,11 @@ group:
title: Data Entry
---
Components providing color selection
Components providing color selection, Available since `5.5.0`.
## When To Use
Used when the user needs to customize the color selection
Used when the user needs to customize the color selection.
## Examples
@ -29,7 +29,7 @@ Used when the user needs to customize the color selection
## API
> This component is available since antd@5.5.0
> This component is available since `antd@5.5.0`.
<!-- prettier-ignore -->
| Property | Description | Type | Default |

2
components/color-picker/index.zh-CN.md

@ -11,7 +11,7 @@ group:
title: 数据录入
---
提供颜色选取的组件
提供颜色选取的组件,自 `5.5.0` 版本开始提供该组件。
## 何时使用

8
components/color-picker/style/index.ts

@ -1,10 +1,10 @@
import type { CSSObject } from '@ant-design/cssinjs';
import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
import genPickerStyle from './picker';
import genColorBlockStyle from './color-block';
import genInputStyle from './input';
import genPickerStyle from './picker';
import genPresetsStyle from './presets';
import genColorBlockStyle from './color-block';
export interface ComponentToken {}
@ -137,7 +137,7 @@ export default genComponentStyleHook('ColorPicker', (token) => {
const colorPickerSliderHeight = 8;
const ColorPickerToken = mergeToken<ColorPickerToken>(token, {
const colorPickerToken = mergeToken<ColorPickerToken>(token, {
colorPickerWidth: 234,
colorPickerHandlerSize: 16,
colorPickerHandlerSizeSM: 12,
@ -149,5 +149,5 @@ export default genComponentStyleHook('ColorPicker', (token) => {
colorPickerPreviewSize: colorPickerSliderHeight * 2 + marginSM,
});
return [genColorPickerStyle(ColorPickerToken)];
return [genColorPickerStyle(colorPickerToken)];
});

3
components/color-picker/style/picker.ts

@ -1,7 +1,7 @@
import type { CSSObject } from '@ant-design/cssinjs';
import type { GenerateStyle } from '../../theme/internal';
import type { ColorPickerToken } from './index';
import genColorBlockStyle from './color-block';
import type { ColorPickerToken } from './index';
const genPickerStyle: GenerateStyle<ColorPickerToken, CSSObject> = (token) => {
const {
@ -41,6 +41,7 @@ const genPickerStyle: GenerateStyle<ColorPickerToken, CSSObject> = (token) => {
border: `${lineWidthBold}px solid ${colorBgElevated}`,
position: 'relative',
borderRadius: '50%',
cursor: 'pointer',
boxShadow: `${colorPickerInsetShadow}, 0 0 0 1px ${colorFillSecondary}`,
'&-sm': {
width: colorPickerHandlerSizeSM,

Loading…
Cancel
Save