mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-18 11:18:14 +08:00
refactor: color-picker panel dom logic (#46327)
* refactor: refactoring custom panel logic * chore: update test case & update snapshot * chore: update un-stable snap??? * docs: update demo * chore: update snapshots * fix: table filterDropdown should accept cssvar (#46314) * chore: revert files * chore: update demo * chore: update snap --------- Co-authored-by: MadCcc <madccc@foxmail.com>
This commit is contained in:
parent
a8fc2ec3f3
commit
ce7da2ef41
@ -15,7 +15,7 @@ interface ColorPickerPanelProps extends ColorPickerBaseProps {
|
|||||||
|
|
||||||
const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
||||||
const { prefixCls, presets, panelRender, color, onChange, onClear, ...injectProps } = props;
|
const { prefixCls, presets, panelRender, color, onChange, onClear, ...injectProps } = props;
|
||||||
const colorPickerPanelPrefixCls = `${prefixCls}-inner-content`;
|
const colorPickerPanelPrefixCls = `${prefixCls}-inner`;
|
||||||
|
|
||||||
// ==== Inject props ===
|
// ==== Inject props ===
|
||||||
const panelPickerProps = {
|
const panelPickerProps = {
|
||||||
@ -38,11 +38,11 @@ const ColorPickerPanel: FC<ColorPickerPanelProps> = (props) => {
|
|||||||
|
|
||||||
// ====================== Render ======================
|
// ====================== Render ======================
|
||||||
const innerPanel = (
|
const innerPanel = (
|
||||||
<>
|
<div className={`${colorPickerPanelPrefixCls}-content`}>
|
||||||
<PanelPicker />
|
<PanelPicker />
|
||||||
{Array.isArray(presets) && <Divider className={`${colorPickerPanelPrefixCls}-divider`} />}
|
{Array.isArray(presets) && <Divider />}
|
||||||
<PanelPresets />
|
<PanelPresets />
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -212,9 +212,6 @@ exports[`renders components/color-picker/demo/panel-render.tsx correctly 1`] = `
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-space-item"
|
class="ant-space-item"
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-row ant-row-middle"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-space ant-space-horizontal ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
|
class="ant-space ant-space-horizontal ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
|
||||||
@ -228,9 +225,6 @@ exports[`renders components/color-picker/demo/panel-render.tsx correctly 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="ant-space-item"
|
class="ant-space-item"
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-col"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-color-picker-trigger"
|
class="ant-color-picker-trigger"
|
||||||
@ -247,13 +241,8 @@ exports[`renders components/color-picker/demo/panel-render.tsx correctly 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
<div
|
||||||
class="ant-space-item"
|
class="ant-space-item"
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-row ant-row-middle"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-space ant-space-horizontal ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
|
class="ant-space ant-space-horizontal ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
|
||||||
@ -267,9 +256,6 @@ exports[`renders components/color-picker/demo/panel-render.tsx correctly 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="ant-space-item"
|
class="ant-space-item"
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-col"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-color-picker-trigger"
|
class="ant-color-picker-trigger"
|
||||||
@ -286,8 +272,6 @@ exports[`renders components/color-picker/demo/panel-render.tsx correctly 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -40,10 +40,13 @@ exports[`ColorPicker Should panelRender work 1`] = `
|
|||||||
class="ant-popover-inner-content"
|
class="ant-popover-inner-content"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-color-picker-inner-content"
|
class="ant-color-picker-inner"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="custom-panel"
|
class="custom-panel"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-color-picker-inner-content"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-color-picker-panel"
|
class="ant-color-picker-panel"
|
||||||
@ -292,6 +295,7 @@ exports[`ColorPicker Should panelRender work 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -323,7 +327,7 @@ exports[`ColorPicker Should panelRender work 2`] = `
|
|||||||
class="ant-popover-inner-content"
|
class="ant-popover-inner-content"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-color-picker-inner-content"
|
class="ant-color-picker-inner"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="custom-panel"
|
class="custom-panel"
|
||||||
|
@ -441,7 +441,8 @@ describe('ColorPicker', () => {
|
|||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
expect(componentContainer.querySelector('.custom-panel')).toBeTruthy();
|
expect(componentContainer.querySelector('.custom-panel')).toBeTruthy();
|
||||||
expect(componentContainer.querySelector('.ant-color-picker-inner-content')).toBeTruthy();
|
expect(componentContainer.querySelector('.ant-color-picker-inner-content')).not.toBeTruthy();
|
||||||
|
expect(componentContainer.querySelector('.ant-color-picker-inner')).toBeTruthy();
|
||||||
expect(componentContainer).toMatchSnapshot();
|
expect(componentContainer).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,12 +1,52 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Col, ColorPicker, Divider, Row, Space } from 'antd';
|
import { Col, ColorPicker, Divider, Row, Space, theme } from 'antd';
|
||||||
|
import type { ColorPickerProps } from 'antd';
|
||||||
|
import { generate, green, presetPalettes, red, cyan } from '@ant-design/colors';
|
||||||
|
|
||||||
const Demo = () => (
|
type Presets = Required<ColorPickerProps>['presets'][number];
|
||||||
<Space direction="vertical">
|
|
||||||
<Row align="middle">
|
const genPresets = (presets = presetPalettes) =>
|
||||||
<Space>
|
Object.entries(presets).map<Presets>(([label, colors]) => ({
|
||||||
<span>Add title: </span>
|
label,
|
||||||
<Col>
|
colors,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const HorizontalLayoutDemo = () => {
|
||||||
|
const { token } = theme.useToken();
|
||||||
|
|
||||||
|
const presets = genPresets({
|
||||||
|
primary: generate(token.colorPrimary),
|
||||||
|
red,
|
||||||
|
green,
|
||||||
|
cyan,
|
||||||
|
});
|
||||||
|
|
||||||
|
const customPanelRender: ColorPickerProps['panelRender'] = (
|
||||||
|
_,
|
||||||
|
{ components: { Picker, Presets } },
|
||||||
|
) => (
|
||||||
|
<Row justify="space-between" wrap={false}>
|
||||||
|
<Col span={12}>
|
||||||
|
<Presets />
|
||||||
|
</Col>
|
||||||
|
<Divider type="vertical" style={{ height: 'auto' }} />
|
||||||
|
<Col flex="auto">
|
||||||
|
<Picker />
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ColorPicker
|
||||||
|
defaultValue={token.colorPrimary}
|
||||||
|
styles={{ popupOverlayInner: { width: 480 } }}
|
||||||
|
presets={presets}
|
||||||
|
panelRender={customPanelRender}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const BasicDemo = () => (
|
||||||
<ColorPicker
|
<ColorPicker
|
||||||
defaultValue="#1677ff"
|
defaultValue="#1677ff"
|
||||||
panelRender={(panel) => (
|
panelRender={(panel) => (
|
||||||
@ -25,103 +65,17 @@ const Demo = () => (
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Col>
|
|
||||||
</Space>
|
|
||||||
</Row>
|
|
||||||
<Row align="middle">
|
|
||||||
<Space>
|
|
||||||
<span>Horizontal layout: </span>
|
|
||||||
<Col>
|
|
||||||
<ColorPicker
|
|
||||||
defaultValue="#1677ff"
|
|
||||||
styles={{
|
|
||||||
popupOverlayInner: {
|
|
||||||
width: 468 + 24,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
presets={[
|
|
||||||
{
|
|
||||||
label: 'Recommended',
|
|
||||||
colors: [
|
|
||||||
'#000000',
|
|
||||||
'#000000E0',
|
|
||||||
'#000000A6',
|
|
||||||
'#00000073',
|
|
||||||
'#00000040',
|
|
||||||
'#00000026',
|
|
||||||
'#0000001A',
|
|
||||||
'#00000012',
|
|
||||||
'#0000000A',
|
|
||||||
'#00000005',
|
|
||||||
'#F5222D',
|
|
||||||
'#FA8C16',
|
|
||||||
'#FADB14',
|
|
||||||
'#8BBB11',
|
|
||||||
'#52C41A',
|
|
||||||
'#13A8A8',
|
|
||||||
'#1677FF',
|
|
||||||
'#2F54EB',
|
|
||||||
'#722ED1',
|
|
||||||
'#EB2F96',
|
|
||||||
'#F5222D4D',
|
|
||||||
'#FA8C164D',
|
|
||||||
'#FADB144D',
|
|
||||||
'#8BBB114D',
|
|
||||||
'#52C41A4D',
|
|
||||||
'#13A8A84D',
|
|
||||||
'#1677FF4D',
|
|
||||||
'#2F54EB4D',
|
|
||||||
'#722ED14D',
|
|
||||||
'#EB2F964D',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Recent',
|
|
||||||
colors: [
|
|
||||||
'#F5222D4D',
|
|
||||||
'#FA8C164D',
|
|
||||||
'#FADB144D',
|
|
||||||
'#8BBB114D',
|
|
||||||
'#52C41A4D',
|
|
||||||
'#13A8A84D',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
panelRender={(_, { components: { Picker, Presets } }) => (
|
|
||||||
<div
|
|
||||||
className="custom-panel"
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
width: 468,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
flex: 1,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Presets />
|
|
||||||
</div>
|
|
||||||
<Divider
|
|
||||||
type="vertical"
|
|
||||||
style={{
|
|
||||||
height: 'auto',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
width: 234,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Picker />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
</Space>
|
|
||||||
</Row>
|
|
||||||
</Space>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
export default Demo;
|
export default () => (
|
||||||
|
<Space direction="vertical">
|
||||||
|
<Space>
|
||||||
|
<span>Add title:</span>
|
||||||
|
<BasicDemo />
|
||||||
|
</Space>
|
||||||
|
<Space>
|
||||||
|
<span>Horizontal layout:</span>
|
||||||
|
<HorizontalLayoutDemo />
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
@ -156,6 +156,7 @@ const genSizeStyle = (token: ColorPickerToken): CSSObject => {
|
|||||||
|
|
||||||
const genColorPickerStyle: GenerateStyle<ColorPickerToken> = (token) => {
|
const genColorPickerStyle: GenerateStyle<ColorPickerToken> = (token) => {
|
||||||
const {
|
const {
|
||||||
|
antCls,
|
||||||
componentCls,
|
componentCls,
|
||||||
colorPickerWidth,
|
colorPickerWidth,
|
||||||
colorPrimary,
|
colorPrimary,
|
||||||
@ -183,14 +184,17 @@ const genColorPickerStyle: GenerateStyle<ColorPickerToken> = (token) => {
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
[componentCls]: {
|
[componentCls]: {
|
||||||
[`${componentCls}-inner-content`]: {
|
[`${componentCls}-inner`]: {
|
||||||
|
'&-content': {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
width: colorPickerWidth,
|
width: colorPickerWidth,
|
||||||
|
|
||||||
'&-divider': {
|
[`& > ${antCls}-divider`]: {
|
||||||
margin: `${unit(marginSM)} 0 ${unit(marginXS)}`,
|
margin: `${unit(marginSM)} 0 ${unit(marginXS)}`,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
|
||||||
[`${componentCls}-panel`]: {
|
[`${componentCls}-panel`]: {
|
||||||
...genPickerStyle(token),
|
...genPickerStyle(token),
|
||||||
},
|
},
|
||||||
|
@ -5391,6 +5391,9 @@ Array [
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-popover-inner-content"
|
class="ant-popover-inner-content"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-color-picker-inner"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-color-picker-inner-content"
|
class="ant-color-picker-inner-content"
|
||||||
@ -5746,6 +5749,7 @@ Array [
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</form>,
|
</form>,
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
@ -21310,6 +21314,9 @@ exports[`renders components/form/demo/validate-other.tsx extend context correctl
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-popover-inner-content"
|
class="ant-popover-inner-content"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-color-picker-inner"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-color-picker-inner-content"
|
class="ant-color-picker-inner-content"
|
||||||
@ -21662,6 +21669,7 @@ exports[`renders components/form/demo/validate-other.tsx extend context correctl
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
class="ant-form-item"
|
class="ant-form-item"
|
||||||
>
|
>
|
||||||
|
@ -150,6 +150,9 @@ exports[`renders components/watermark/demo/custom.tsx extend context correctly 1
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-popover-inner-content"
|
class="ant-popover-inner-content"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="ant-color-picker-inner"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="ant-color-picker-inner-content"
|
class="ant-color-picker-inner-content"
|
||||||
@ -502,6 +505,7 @@ exports[`renders components/watermark/demo/custom.tsx extend context correctly 1
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
class="ant-form-item"
|
class="ant-form-item"
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user