Add color picker
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
@import "../Theme/Theme.scss";
|
||||
|
||||
$line-min-height: 24px;
|
||||
$root-min-height: 26px;
|
||||
$line-min-height: 26px;
|
||||
|
||||
div.attr-input {
|
||||
width: 100%;
|
||||
@@ -23,7 +22,7 @@ div.attr-input {
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
max-width: 180px;
|
||||
min-height: $root-min-height;
|
||||
min-height: $line-min-height;
|
||||
|
||||
div.input-content {
|
||||
box-sizing: border-box;
|
||||
@@ -33,14 +32,13 @@ div.attr-input {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
min-height: $root-min-height;
|
||||
height: $line-min-height;
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
outline:none;
|
||||
min-height: $line-min-height;
|
||||
};
|
||||
|
||||
input:focus {
|
||||
@@ -73,17 +71,35 @@ div.attr-input {
|
||||
padding-top: 5px;
|
||||
min-height: $line-min-height;
|
||||
}
|
||||
|
||||
div.error-view {
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: $line-min-height;
|
||||
text-overflow: ellipsis;
|
||||
word-wrap: none;
|
||||
word-break: keep-all;
|
||||
white-space: nowrap;
|
||||
cursor:not-allowed;
|
||||
|
||||
span {
|
||||
padding-left: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div.dark.attr-input {
|
||||
|
||||
div.input-content,
|
||||
div.input-content, div.error-view,
|
||||
div.input-content input {
|
||||
background-color: $lt-bg-color-lvl3-dark;
|
||||
color: $lt-font-color-normal-dark;
|
||||
}
|
||||
|
||||
div.error-view:hover,
|
||||
div.button-left:hover, div.button-right:hover {
|
||||
background-color: $lt-bg-color-lvl2-dark;
|
||||
}
|
||||
@@ -91,12 +107,13 @@ div.dark.attr-input {
|
||||
|
||||
div.light.attr-input {
|
||||
|
||||
div.input-content,
|
||||
div.input-content, div.error-view,
|
||||
div.input-content input {
|
||||
background-color: $lt-bg-color-lvl3-light;
|
||||
color: $lt-font-color-normal-light;
|
||||
}
|
||||
|
||||
div.error-view:hover,
|
||||
div.button-left:hover, div.button-right:hover {
|
||||
background-color: $lt-bg-color-lvl2-light;
|
||||
}
|
||||
|
||||
@@ -153,6 +153,16 @@ class AttrInput extends Component<IAttrInputProps> {
|
||||
this.error = this.check(value.toString());
|
||||
}
|
||||
|
||||
private renderErrorInput() {
|
||||
return <div className="error-view">
|
||||
{
|
||||
this.props.disableI18n ?
|
||||
<Localization i18nKey={this.props.disableI18n}/> :
|
||||
<span>{this.props.value}</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
public render(): ReactNode {
|
||||
|
||||
return <Theme
|
||||
@@ -165,9 +175,7 @@ class AttrInput extends Component<IAttrInputProps> {
|
||||
<div className="root-content">
|
||||
{
|
||||
this.props.disable ?
|
||||
this.props.disableI18n ?
|
||||
<Localization i18nKey={this.props.disableI18n}/> :
|
||||
<div>{this.props.value}</div> :
|
||||
this.renderErrorInput() :
|
||||
this.renderInput()
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
@import "../Theme/Theme.scss";
|
||||
|
||||
$line-min-height: 26px;
|
||||
|
||||
div.color-input-root {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
min-height: $line-min-height;
|
||||
padding: 5px 0;
|
||||
|
||||
div.input-intro {
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
max-width: 220px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-right: 5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
div.root-content {
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
max-width: 180px;
|
||||
min-height: $line-min-height;
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
|
||||
div.color-view {
|
||||
width: $line-min-height;
|
||||
max-width: $line-min-height;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
div.color-box {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
div.value-view {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: $line-min-height;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
div.text-box {
|
||||
padding-left: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
div.error-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-left: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div.dark.color-input-root {
|
||||
|
||||
div.root-content {
|
||||
background-color: $lt-bg-color-lvl3-dark;
|
||||
color: $lt-font-color-normal-dark;
|
||||
}
|
||||
|
||||
div.root-content:hover {
|
||||
background-color: $lt-bg-color-lvl2-dark;
|
||||
}
|
||||
}
|
||||
|
||||
div.light.color-input-root {
|
||||
|
||||
div.root-content {
|
||||
background-color: $lt-bg-color-lvl3-light;
|
||||
color: $lt-font-color-normal-light;
|
||||
}
|
||||
|
||||
div.root-content:hover {
|
||||
background-color: $lt-bg-color-lvl2-light;
|
||||
}
|
||||
}
|
||||
|
||||
div.color-picker-root {
|
||||
width: 300px;
|
||||
height: 340px;
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import { Component, createRef, ReactNode } from "react";
|
||||
import { FontLevel, Theme } from "@Component/Theme/Theme";
|
||||
import { Callout, ColorPicker, DirectionalHint } from "@fluentui/react";
|
||||
import { AllI18nKeys, Localization } from "@Component/Localization/Localization";
|
||||
import "./ColorInput.scss";
|
||||
|
||||
interface IColorInputProps {
|
||||
keyI18n: AllI18nKeys;
|
||||
infoI18n?: AllI18nKeys;
|
||||
value?: number[];
|
||||
normal?: boolean;
|
||||
disable?: boolean;
|
||||
disableI18n?: AllI18nKeys;
|
||||
valueChange?: (color: number[]) => any;
|
||||
}
|
||||
|
||||
interface IColorInputState {
|
||||
isPickerVisible: boolean;
|
||||
}
|
||||
|
||||
class ColorInput extends Component<IColorInputProps, IColorInputState> {
|
||||
|
||||
public constructor(props: IColorInputProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
isPickerVisible: false
|
||||
}
|
||||
}
|
||||
|
||||
private pickerTarget = createRef<HTMLDivElement>();
|
||||
|
||||
private renderPicker() {
|
||||
return <Callout
|
||||
target={this.pickerTarget}
|
||||
directionalHint={DirectionalHint.topAutoEdge}
|
||||
onDismiss={() => {
|
||||
this.setState({
|
||||
isPickerVisible: false
|
||||
})
|
||||
}}
|
||||
>
|
||||
<div className="color-picker-root">
|
||||
<ColorPicker
|
||||
color={this.getColorString()}
|
||||
alphaType={"none"}
|
||||
onChange={(_, color) => {
|
||||
if (this.props.valueChange) {
|
||||
if (this.props.normal) {
|
||||
this.props.valueChange([
|
||||
color.r / 255,
|
||||
color.g / 255,
|
||||
color.b / 255,
|
||||
])
|
||||
} else {
|
||||
this.props.valueChange([
|
||||
color.r,
|
||||
color.g,
|
||||
color.b,
|
||||
])
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Callout>
|
||||
}
|
||||
|
||||
private renderErrorInput() {
|
||||
return <div className="error-box">
|
||||
{
|
||||
this.props.disableI18n ?
|
||||
<Localization i18nKey={this.props.disableI18n}/> :
|
||||
<span>{this.props.value}</span>
|
||||
}
|
||||
</div>;
|
||||
}
|
||||
|
||||
private renderColorInput() {
|
||||
return <>
|
||||
<div className="color-view">
|
||||
<div className="color-box" style={{
|
||||
backgroundColor: this.getColorString()
|
||||
}}/>
|
||||
</div>
|
||||
<div className="value-view">
|
||||
<div className="text-box">{this.getColorString(true)}</div>
|
||||
</div>
|
||||
</>;
|
||||
}
|
||||
|
||||
private getColorString(display?: boolean) {
|
||||
let color: number[] = this.props.value?.concat([]) ?? [0, 0, 0];
|
||||
if (this.props.normal) {
|
||||
color[0] = Math.round(color[0] * 255);
|
||||
color[1] = Math.round(color[1] * 255);
|
||||
color[2] = Math.round(color[2] * 255);
|
||||
}
|
||||
if (display) {
|
||||
return `rgb ( ${color[0] ?? 0}, ${color[1] ?? 0}, ${color[2] ?? 0} )`;
|
||||
} else {
|
||||
return `rgb(${color[0] ?? 0},${color[1] ?? 0},${color[2] ?? 0})`;
|
||||
}
|
||||
}
|
||||
|
||||
public render(): ReactNode {
|
||||
return <>
|
||||
<Theme className="color-input-root" fontLevel={FontLevel.normal}>
|
||||
<div className="input-intro">
|
||||
<Localization i18nKey={this.props.keyI18n}/>
|
||||
</div>
|
||||
<div
|
||||
className="root-content"
|
||||
ref={this.pickerTarget}
|
||||
style={{
|
||||
cursor: this.props.disable ? "not-allowed" : "pointer"
|
||||
}}
|
||||
onClick={() => {
|
||||
this.setState({
|
||||
isPickerVisible: !this.props.disable
|
||||
})
|
||||
}}
|
||||
>
|
||||
{ this.props.disable ? null : this.renderColorInput() }
|
||||
{ this.props.disable ? this.renderErrorInput() : null }
|
||||
</div>
|
||||
</Theme>
|
||||
|
||||
{this.state.isPickerVisible ? this.renderPicker(): null}
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
||||
export { ColorInput };
|
||||
@@ -39,7 +39,7 @@ div.details-list {
|
||||
div.light.details-list {
|
||||
|
||||
div.details-list-item:nth-child(2n-1) {
|
||||
background-color: rgba($lt-bg-color-lvl5-light, .4);
|
||||
background-color: rgba($lt-bg-color-lvl5-light, .3);
|
||||
}
|
||||
|
||||
div.details-list-item:hover {
|
||||
@@ -59,7 +59,7 @@ div.light.details-list {
|
||||
div.dark.details-list {
|
||||
|
||||
div.details-list-item:nth-child(2n-1) {
|
||||
background-color: rgba($lt-bg-color-lvl5-dark, .8);
|
||||
background-color: rgba($lt-bg-color-lvl5-dark, .4);
|
||||
}
|
||||
|
||||
div.details-list-item:hover {
|
||||
|
||||
Reference in New Issue
Block a user