|
@@ -1,7 +1,7 @@
|
|
|
-import React, { CSSProperties } from 'react';
|
|
|
|
|
|
|
+import React, { CSSProperties, PropsWithChildren, ReactNode } from 'react';
|
|
|
import ColorPickerFoundation, { ColorPickerProps, ColorPickerState } from '@douyinfe/semi-foundation/colorPicker/foundation';
|
|
import ColorPickerFoundation, { ColorPickerProps, ColorPickerState } from '@douyinfe/semi-foundation/colorPicker/foundation';
|
|
|
import BaseComponent from '../_base/baseComponent';
|
|
import BaseComponent from '../_base/baseComponent';
|
|
|
-import PopoverProps from '../popover';
|
|
|
|
|
|
|
+import { PopoverProps } from '../popover';
|
|
|
import ColorChooseArea from './ColorChooseArea';
|
|
import ColorChooseArea from './ColorChooseArea';
|
|
|
import { ColorPickerAdapter } from '@douyinfe/semi-foundation/colorPicker/foundation';
|
|
import { ColorPickerAdapter } from '@douyinfe/semi-foundation/colorPicker/foundation';
|
|
|
import AlphaSlider from './AlphaSlider';
|
|
import AlphaSlider from './AlphaSlider';
|
|
@@ -10,14 +10,16 @@ import DataPart from './DataPart';
|
|
|
import cls from 'classnames';
|
|
import cls from 'classnames';
|
|
|
import "@douyinfe/semi-foundation/colorPicker/colorPicker.scss";
|
|
import "@douyinfe/semi-foundation/colorPicker/colorPicker.scss";
|
|
|
import { cssClasses } from '@douyinfe/semi-foundation/colorPicker/constants';
|
|
import { cssClasses } from '@douyinfe/semi-foundation/colorPicker/constants';
|
|
|
|
|
+import Popover from '../popover';
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface ColorPickerReactProps extends ColorPickerProps{
|
|
export interface ColorPickerReactProps extends ColorPickerProps{
|
|
|
usePopover?: boolean;
|
|
usePopover?: boolean;
|
|
|
popoverProps?: PopoverProps;
|
|
popoverProps?: PopoverProps;
|
|
|
- className: string;
|
|
|
|
|
- style?: CSSProperties
|
|
|
|
|
-
|
|
|
|
|
|
|
+ className?: string;
|
|
|
|
|
+ style?: CSSProperties;
|
|
|
|
|
+ bottomSlot?: ReactNode;
|
|
|
|
|
+ topSlot?: ReactNode
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -25,7 +27,7 @@ export interface ColorPickerReactState extends ColorPickerState{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-class ColorPicker extends BaseComponent<ColorPickerReactProps, ColorPickerReactState> {
|
|
|
|
|
|
|
+class ColorPicker extends BaseComponent<PropsWithChildren<ColorPickerReactProps>, ColorPickerReactState> {
|
|
|
static __SemiComponentName__ = "ColorPicker";
|
|
static __SemiComponentName__ = "ColorPicker";
|
|
|
public foundation: ColorPickerFoundation;
|
|
public foundation: ColorPickerFoundation;
|
|
|
|
|
|
|
@@ -61,19 +63,22 @@ class ColorPicker extends BaseComponent<ColorPickerReactProps, ColorPickerReactS
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ static colorStringToValue = (raw: string)=>{
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
getCurrentColor = ()=>{
|
|
getCurrentColor = ()=>{
|
|
|
return this.props.value ? (this.props.value) : this.state.currentColor;
|
|
return this.props.value ? (this.props.value) : this.state.currentColor;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- render() {
|
|
|
|
|
|
|
+ renderPicker() {
|
|
|
const { className: userClassName } = this.props;
|
|
const { className: userClassName } = this.props;
|
|
|
const className = cls(`${cssClasses.PREFIX}`, userClassName);
|
|
const className = cls(`${cssClasses.PREFIX}`, userClassName);
|
|
|
const currentColor = this.getCurrentColor();
|
|
const currentColor = this.getCurrentColor();
|
|
|
return <div className={className}>
|
|
return <div className={className}>
|
|
|
-
|
|
|
|
|
|
|
+ {this.props.topSlot}
|
|
|
<ColorChooseArea hsva={this.state.currentColor.hsva} foundation={this.foundation} onChange={({ s, v }) => {
|
|
<ColorChooseArea hsva={this.state.currentColor.hsva} foundation={this.foundation} onChange={({ s, v }) => {
|
|
|
this.foundation.handleChange( { s, v, a: this.state.currentColor.hsva.a, h: this.state.currentColor.hsva.h }, 'hsva');
|
|
this.foundation.handleChange( { s, v, a: this.state.currentColor.hsva.a, h: this.state.currentColor.hsva.h }, 'hsva');
|
|
|
}} handleSize={20} width={this.props.width ?? 280} height={this.props.height ?? 280}/>
|
|
}} handleSize={20} width={this.props.width ?? 280} height={this.props.height ?? 280}/>
|
|
@@ -96,9 +101,19 @@ class ColorPicker extends BaseComponent<ColorPickerReactProps, ColorPickerReactS
|
|
|
width={this.props.width ?? 280 }
|
|
width={this.props.width ?? 280 }
|
|
|
foundation={this.foundation}
|
|
foundation={this.foundation}
|
|
|
defaultFormat={this.props.defaultFormat}/>
|
|
defaultFormat={this.props.defaultFormat}/>
|
|
|
-
|
|
|
|
|
|
|
+ {this.props.bottomSlot}
|
|
|
</div>;
|
|
</div>;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ render() {
|
|
|
|
|
+ if (this.props.usePopover) {
|
|
|
|
|
+ return <Popover {...this.props.popoverProps} className={cls(`${cssClasses.PREFIX}-popover`, this.props.popoverProps?.className)} content={this.renderPicker()}>
|
|
|
|
|
+ {this.props.children}
|
|
|
|
|
+ </Popover>;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return this.renderPicker();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|